Reply
Thread Tools
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#21
Originally Posted by rcull View Post
At the risk of being too simplistic - whats wrong with this:-
Yes, it seems to work too, but has the same problems with the row lines having unchanged height. Moreover, I was unable to make your code work with the hardware keys. It works inside the main program (at initialization), but does not change the font sizes with the keys.

Thanks,
L.
 
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:
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#23
Wow... getting even more complicate...
I will test this.

Thanks!
L.
 
rcull's Avatar
Posts: 299 | Thanked: 168 times | Joined on Jun 2006 @ Wales UK
#24
luis

This is not as complicated as it may look. It is still just gtk.rc_parse_string(), There is also the link to F7/F8 but the rest is really just a wrapper ( just copy/paste/chmod/run ) designed to test it.

I do think that if you were changing font size using daperls method and the container was not growing in size to accomodate it then you must be restricting it somehow. Are
you using set_default_size or set_size_request at all ?

Rick
 

The Following User Says Thank You to rcull For This Useful Post:
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#25
Thanks Rick, that's a clean and elegant solution. It's the right solution. Theme-level changes are certainly the way to go. Luis, I think this is the solution you've been looking for since early June. Thanks again Rick, it works great.
__________________
N9: Go white or go home

Last edited by daperl; 2009-09-10 at 21:19.
 
rcull's Avatar
Posts: 299 | Thanked: 168 times | Joined on Jun 2006 @ Wales UK
#26
Your welcome. Its nice to be able to contribute occasionally

Rick
 

The Following User Says Thank You to rcull For This Useful Post:
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#27
Yes, it worked! Great.
I have one doubt, though: How can I use two types of fonts in the same app?

Thanks a lot!!
L.

Last edited by luis; 2009-09-15 at 00:56.
 
rcull's Avatar
Posts: 299 | Thanked: 168 times | Joined on Jun 2006 @ Wales UK
#28
luis
You will need to read up on gtkrc but you are not restricted to one style ie.

Style="""
style "button-font"
{
font_name = "Sans 18"
}
style "entry-font"
{
font_name = "pango_font_description"
}
class "GTKButton" style "button-font"
class "GtkEntry" style "entry-font" """

gtk.rc_parse_string(Style)


Rick
 

The Following 2 Users Say Thank You to rcull For This Useful Post:
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#29
Originally Posted by rcull View Post
luis
You will need to read up on gtkrc but you are not restricted to one style ie.

Rick
Great, this is everything I needed.

Thanks!!!!!!!
L.
 
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#30
Just for the record, this is what I did.
I created a function with the following code:
Code:
    def makefont(self):
        Settings=gtk.settings_get_for_screen(gdk.screen_get_default())

        gtk.rc_parse_string("""
                style "general-font"
                {
                    font_name = "Sans """+str(self.font)+""" "
                }
                style "out-font"
                {
                    font_name = "Sans """+str(self.font+6)+""" "
                }
                style "label-font"
                {
                    font_name = "Sans bold """+str(self.font-4)+""" "
                }
                class "*" style "general-font"
                class "GtkTreeView" style "out-font"
                class "GtkLabel" style "label-font"
                """)

        gtk.rc_reset_styles(Settings)
and I call this function at the initialization of the program, and each time the variable self.font changes.

The only strange thing is that the GtkLabel works fine in the PC, but not on the N800: the label of the buttons remain unchanged, although the labels on the dialogs change. It seems that the gtk.ToggleButton is implemented differently in the different pythons.

Thanks for all your help!
L.
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 03:32.