[Sugar-devel] [PATCH] Removal of hardcoded styles- Referring to CSS file in sugar-artwork
Kartik Kumar
kartik.peri at gmail.com
Sun Aug 12 14:35:11 EDT 2012
Hi, regarding the task of removal of hardcoded styles, I have done few
changes:
* imported Gtk, Gdk and Gobject
* repalaced gtk with Gtk
* referring to CSS 'gtk-widgets-100.css' within css_provider's
load_from_file method. I assume 'gtk-widgets-100.css' is generated by the
'gtk-widgets.css.em' (Please correct me if I am wrong here)
I would like to understand- How shell is applying styles loaded using
css_provider in the gtk3 example here :
http://wiki.sugarlabs.org/go/Features/GTK3/Theme since 'context' isn't used
anywhere with gtk widgets?
Am I heading in the right direction? Feedback is appreciated!
Please let me know for any concern.
Signed-off-by: Kartik Perisetla <kartik.peri at gmail.com>
---
extensions/cpsection/aboutcomputer/view.py | 97
++++++++++++++++------------
1 file changed, 55 insertions(+), 42 deletions(-)
diff --git a/extensions/cpsection/aboutcomputer/view.py
b/extensions/cpsection/aboutcomputer/view.py
index 6d59102..b565263 100644
--- a/extensions/cpsection/aboutcomputer/view.py
+++ b/extensions/cpsection/aboutcomputer/view.py
@@ -18,13 +18,16 @@
from gettext import gettext as _
-import gtk
-
from sugar.graphics import style
from jarabe import config
from jarabe.controlpanel.sectionview import SectionView
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import GObject
+
+USE_LOCAL_CSS = True
class AboutComputer(SectionView):
def __init__(self, model, alerts=None):
@@ -35,14 +38,14 @@ class AboutComputer(SectionView):
self.set_border_width(style.DEFAULT_SPACING * 2)
self.set_spacing(style.DEFAULT_SPACING)
- self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
+ self._group = Gtk.SizeGroup(Gtk.SIZE_GROUP_HORIZONTAL)
- scrollwindow = gtk.ScrolledWindow()
- scrollwindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ scrollwindow = Gtk.ScrolledWindow()
+ scrollwindow.set_policy(Gtk.POLICY_NEVER, Gtk.POLICY_AUTOMATIC)
self.pack_start(scrollwindow, expand=True)
scrollwindow.show()
- self._vbox = gtk.VBox()
+ self._vbox = Gtk.VBox()
scrollwindow.add_with_viewport(self._vbox)
self._vbox.show()
@@ -50,29 +53,39 @@ class AboutComputer(SectionView):
self._setup_software()
self._setup_copyright()
+
+ screen = Gdk.Screen.get_default()
+ if USE_LOCAL_CSS:
+ css_provider = Gtk.CssProvider()
+ css_provider.load_from_path('gtk-widgets-100.css')
+
+ context = Gtk.StyleContext()
+ context.add_provider_for_screen(screen, css_provider,
+ Gtk.STYLE_PROVIDER_PRIORITY_USER)
+
def _setup_identity(self):
- separator_identity = gtk.HSeparator()
+ separator_identity = Gtk.HSeparator()
self._vbox.pack_start(separator_identity, expand=False)
separator_identity.show()
- label_identity = gtk.Label(_('Identity'))
+ label_identity = Gtk.Label(_('Identity'))
label_identity.set_alignment(0, 0)
self._vbox.pack_start(label_identity, expand=False)
label_identity.show()
- vbox_identity = gtk.VBox()
+ vbox_identity = Gtk.VBox()
vbox_identity.set_border_width(style.DEFAULT_SPACING * 2)
vbox_identity.set_spacing(style.DEFAULT_SPACING)
- box_identity = gtk.HBox(spacing=style.DEFAULT_SPACING)
- label_serial = gtk.Label(_('Serial Number:'))
+ box_identity = Gtk.HBox(spacing=style.DEFAULT_SPACING)
+ label_serial = Gtk.Label(_('Serial Number:'))
label_serial.set_alignment(1, 0)
- label_serial.modify_fg(gtk.STATE_NORMAL,
- style.COLOR_SELECTION_GREY.get_gdk_color())
+ #label_serial.modify_fg(Gtk.STATE_NORMAL, at selection_grey)
+
box_identity.pack_start(label_serial, expand=False)
self._group.add_widget(label_serial)
label_serial.show()
- label_serial_no = gtk.Label(self._model.get_serial_number())
+ label_serial_no = Gtk.Label(self._model.get_serial_number())
label_serial_no.set_alignment(0, 0)
box_identity.pack_start(label_serial_no, expand=False)
label_serial_no.show()
@@ -83,73 +96,73 @@ class AboutComputer(SectionView):
vbox_identity.show()
def _setup_software(self):
- separator_software = gtk.HSeparator()
+ separator_software = Gtk.HSeparator()
self._vbox.pack_start(separator_software, expand=False)
separator_software.show()
- label_software = gtk.Label(_('Software'))
+ label_software = Gtk.Label(_('Software'))
label_software.set_alignment(0, 0)
self._vbox.pack_start(label_software, expand=False)
label_software.show()
- box_software = gtk.VBox()
+ box_software = Gtk.VBox()
box_software.set_border_width(style.DEFAULT_SPACING * 2)
box_software.set_spacing(style.DEFAULT_SPACING)
- box_build = gtk.HBox(spacing=style.DEFAULT_SPACING)
- label_build = gtk.Label(_('Build:'))
+ box_build = Gtk.HBox(spacing=style.DEFAULT_SPACING)
+ label_build = Gtk.Label(_('Build:'))
label_build.set_alignment(1, 0)
- label_build.modify_fg(gtk.STATE_NORMAL,
+ label_build.modify_fg(Gtk.STATE_NORMAL,
style.COLOR_SELECTION_GREY.get_gdk_color())
box_build.pack_start(label_build, expand=False)
self._group.add_widget(label_build)
label_build.show()
- label_build_no = gtk.Label(self._model.get_build_number())
+ label_build_no = Gtk.Label(self._model.get_build_number())
label_build_no.set_alignment(0, 0)
box_build.pack_start(label_build_no, expand=False)
label_build_no.show()
box_software.pack_start(box_build, expand=False)
box_build.show()
- box_sugar = gtk.HBox(spacing=style.DEFAULT_SPACING)
- label_sugar = gtk.Label(_('Sugar:'))
+ box_sugar = Gtk.HBox(spacing=style.DEFAULT_SPACING)
+ label_sugar = Gtk.Label(_('Sugar:'))
label_sugar.set_alignment(1, 0)
- label_sugar.modify_fg(gtk.STATE_NORMAL,
+ label_sugar.modify_fg(Gtk.STATE_NORMAL,
style.COLOR_SELECTION_GREY.get_gdk_color())
box_sugar.pack_start(label_sugar, expand=False)
self._group.add_widget(label_sugar)
label_sugar.show()
- label_sugar_ver = gtk.Label(config.version)
+ label_sugar_ver = Gtk.Label(config.version)
label_sugar_ver.set_alignment(0, 0)
box_sugar.pack_start(label_sugar_ver, expand=False)
label_sugar_ver.show()
box_software.pack_start(box_sugar, expand=False)
box_sugar.show()
- box_firmware = gtk.HBox(spacing=style.DEFAULT_SPACING)
- label_firmware = gtk.Label(_('Firmware:'))
+ box_firmware = Gtk.HBox(spacing=style.DEFAULT_SPACING)
+ label_firmware = Gtk.Label(_('Firmware:'))
label_firmware.set_alignment(1, 0)
- label_firmware.modify_fg(gtk.STATE_NORMAL,
+ label_firmware.modify_fg(Gtk.STATE_NORMAL,
style.COLOR_SELECTION_GREY.get_gdk_color())
box_firmware.pack_start(label_firmware, expand=False)
self._group.add_widget(label_firmware)
label_firmware.show()
- label_firmware_no = gtk.Label(self._model.get_firmware_number())
+ label_firmware_no = Gtk.Label(self._model.get_firmware_number())
label_firmware_no.set_alignment(0, 0)
box_firmware.pack_start(label_firmware_no, expand=False)
label_firmware_no.show()
box_software.pack_start(box_firmware, expand=False)
box_firmware.show()
- box_wireless_fw = gtk.HBox(spacing=style.DEFAULT_SPACING)
- label_wireless_fw = gtk.Label(_('Wireless Firmware:'))
+ box_wireless_fw = Gtk.HBox(spacing=style.DEFAULT_SPACING)
+ label_wireless_fw = Gtk.Label(_('Wireless Firmware:'))
label_wireless_fw.set_alignment(1, 0)
- label_wireless_fw.modify_fg(gtk.STATE_NORMAL,
+ label_wireless_fw.modify_fg(Gtk.STATE_NORMAL,
style.COLOR_SELECTION_GREY.get_gdk_color())
box_wireless_fw.pack_start(label_wireless_fw, expand=False)
self._group.add_widget(label_wireless_fw)
label_wireless_fw.show()
wireless_fw_no = self._model.get_wireless_firmware()
- label_wireless_fw_no = gtk.Label(wireless_fw_no)
+ label_wireless_fw_no = Gtk.Label(wireless_fw_no)
label_wireless_fw_no.set_alignment(0, 0)
box_wireless_fw.pack_start(label_wireless_fw_no, expand=False)
label_wireless_fw_no.show()
@@ -160,24 +173,24 @@ class AboutComputer(SectionView):
box_software.show()
def _setup_copyright(self):
- separator_copyright = gtk.HSeparator()
+ separator_copyright = Gtk.HSeparator()
self._vbox.pack_start(separator_copyright, expand=False)
separator_copyright.show()
- label_copyright = gtk.Label(_('Copyright and License'))
+ label_copyright = Gtk.Label(_('Copyright and License'))
label_copyright.set_alignment(0, 0)
self._vbox.pack_start(label_copyright, expand=False)
label_copyright.show()
- vbox_copyright = gtk.VBox()
+ vbox_copyright = Gtk.VBox()
vbox_copyright.set_border_width(style.DEFAULT_SPACING * 2)
vbox_copyright.set_spacing(style.DEFAULT_SPACING)
copyright_text = '© 2006-2012 One Laptop per Child Association
Inc,' \
' Sugar Labs Inc, Red Hat Inc, Collabora Ltd and'
\
' Contributors.'
- label_copyright = gtk.Label(copyright_text)
+ label_copyright = Gtk.Label(copyright_text)
label_copyright.set_alignment(0, 0)
- label_copyright.set_size_request(gtk.gdk.screen_width() / 2, -1)
+ label_copyright.set_size_request(Gtk.gdk.screen_width() / 2, -1)
label_copyright.set_line_wrap(True)
label_copyright.show()
vbox_copyright.pack_start(label_copyright, expand=False)
@@ -187,14 +200,14 @@ class AboutComputer(SectionView):
' GNU General Public License, and you are welcome to'
' change it and/or distribute copies of it under'
' certain conditions described therein.')
- label_info = gtk.Label(info_text)
+ label_info = Gtk.Label(info_text)
label_info.set_alignment(0, 0)
label_info.set_line_wrap(True)
- label_info.set_size_request(gtk.gdk.screen_width() / 2, -1)
+ label_info.set_size_request(Gtk.gdk.screen_width() / 2, -1)
label_info.show()
vbox_copyright.pack_start(label_info, expand=False)
- expander = gtk.Expander(_('Full license:'))
+ expander = Gtk.Expander(_('Full license:'))
expander.connect('notify::expanded', self.license_expander_cb)
expander.show()
vbox_copyright.pack_start(expander, expand=True)
@@ -206,7 +219,7 @@ class AboutComputer(SectionView):
# load/destroy the license viewer on-demand, to avoid storing the
# GPL in memory at all times
if expander.get_expanded():
- view_license = gtk.TextView()
+ view_license = Gtk.TextView()
view_license.set_editable(False)
view_license.get_buffer().set_text(self._model.get_license())
view_license.show()
--
1.7.10.4
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20120813/c76f77ed/attachment.html>
More information about the Sugar-devel
mailing list