View Single Post
rcull's Avatar
Posts: 299 | Thanked: 168 times | Joined on Jun 2006 @ Wales UK
#22
try this - it should work on both PC (F7/F8) and N8*0

Code:
#!/usr/bin/env python2.5

import gtk
from gtk import gdk

Has_hildon=False

try:
    import hildon,osso
    Has_hildon=True
except:
    pass


class fontsize():

    def on_key_press(self,widget,event,*args):
        if event.keyval == gtk.keysyms.F7: self.fsize += 1 #inc
        if event.keyval == gtk.keysyms.F8: self.fsize -= 1 #dec

        Settings=gtk.settings_get_for_screen(gdk.screen_get_default())
        Style=self.Style1 + str(self.fsize) + self.Style2
        gtk.rc_parse_string(self.Style1 + str(self.fsize) + self.Style2)
        gtk.rc_reset_styles(Settings)

    def Quit(self,n):
        gtk.main_quit()

    def __init__(self):
        self.fsize=12
        self.Style1=\
        """
        style "general-font"
        {
           font_name = "Sans """
        self.Style2=\
        """ "
        }
        widget_class "*" style "general-font" """
        gtk.rc_parse_string(self.Style1 + str(self.fsize) + self.Style2)

        if Has_hildon:
            self.program=hildon.Program()
            self.program.__init__()
            self.window = hildon.Window()
        else:
            self.window = gtk.Window()
            self.window.set_default_size(800,480)

        self.window.connect("delete_event",self.Quit)
        self.window.connect("key-press-event",self.on_key_press)
        self.Lab=gtk.Label("This text should change size ...")
        self.Box=gtk.VBox(True,0)
        self.CBox = gtk.combo_box_new_text()
        for f in ("Some Arbitary Text","Maemo Rules","N900 Rocks"):
            self.CBox.append_text(f)
        self.Btn=gtk.Button("Quit")
        self.Btn.connect("clicked",self.Quit)
        self.window.add(self.Box)
        self.Box.pack_start(self.Lab,False,False,0)        self.Box.pack_start(self.CBox,False,False,0)
        self.Box.pack_start(self.Btn,False,False,0)        self.window.show_all()

    def run(self):
        gtk.main()

if __name__ == "__main__":
    try:
        osso_context = osso.Context("net.nokia.fontsize","0.1",False)
    except Exception,e:
        if repr(e).find("NameError") == 0:
            pass
        else:
            print "Error when testing for osso"
    app=fontsize()
    app.run()
 

The Following 3 Users Say Thank You to rcull For This Useful Post: