[Sugar-devel] [HELP] Shell port to GTK3+: Removing hardcoded styles-- facing issue

Sascha Silbe silbe at activitycentral.com
Fri Aug 10 08:44:35 EDT 2012


Kartik Kumar <kartik.peri at gmail.com> writes:

> Then I made changes to aboutcomputer/view.py to load the CSS: (changes are
> highlighted in bold):

Diffs are usually easier to read, especially in MUAs that don't render
font attributes for HTML mails. If you want all of the previous code to
be included in the diff, you can just give a sufficiently larger number
to the -U option of git diff. I'll include an example below.


> from sugar.graphics import style

The "sugar" Python package is provided by the pyGTK + GTK2 based sugar-toolkit
package. If you want to use gobject introspection + GTK3, you need to
use the "sugar3" Python package which is provided by the
sugar-toolkit-gtk3 package.


>     if USE_LOCAL_CSS:
>         css_provider = GTK.CssProvider()
>         css_provcss_provider.load_from_path('sugar-theme.css')
>         context = GTK.StyleContext()
>         context.add_provider_for_screen(screen, css_provider,
>         GTK.STYLE_PROVIDER_PRIORITY_USER)*

Where does screen get defined? Do we need to load the theme from inside
each widget or can we do it once for an entire process?


sascha.silbe at twin:~/sugar-jhbuild/source/sugar$ git diff -U13
diff --git i/extensions/cpsection/aboutcomputer/view.py w/extensions/cpsection/aboutcomputer/view.py
index 6b16005..b011b37 100644
--- i/extensions/cpsection/aboutcomputer/view.py
+++ w/extensions/cpsection/aboutcomputer/view.py
@@ -8,59 +8,70 @@
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
 from gettext import gettext as _
 
-import gtk
+#import gtk
+from gi.repository import GTK
 
 from sugar.graphics import style
 
 from jarabe import config
 from jarabe.controlpanel.sectionview import SectionView
 
 
+USE_LOCAL_CSS = True
+
+
 class AboutComputer(SectionView):
     def __init__(self, model, alerts=None):
         SectionView.__init__(self)
 
         self._model = model
 
         self.set_border_width(style.DEFAULT_SPACING * 2)
         self.set_spacing(style.DEFAULT_SPACING)
 
         self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
 
         scrollwindow = gtk.ScrolledWindow()
         scrollwindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
         self.pack_start(scrollwindow, expand=True)
         scrollwindow.show()
 
         self._vbox = gtk.VBox()
         scrollwindow.add_with_viewport(self._vbox)
         self._vbox.show()
 
         self._setup_identity()
 
         self._setup_software()
         self._setup_copyright()
 
+        if USE_LOCAL_CSS:
+            css_provider = GTK.CssProvider()
+            css_provcss_provider.load_from_path('sugar-theme.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()
         self._vbox.pack_start(separator_identity, expand=False)
         separator_identity.show()
 
         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.set_border_width(style.DEFAULT_SPACING * 2)
         vbox_identity.set_spacing(style.DEFAULT_SPACING)
 

Sascha
-- 
http://sascha.silbe.org/
http://www.infra-silbe.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20120810/4b155c73/attachment-0001.pgp>


More information about the Sugar-devel mailing list