Reply
Thread Tools
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#1
Hi,
I made a pygtk app, and want to use the +/- buttons to change the whole app font size (yeah, I'm becoming old quickly...). I know how to do that with pango in each widget, but I want to change ALL sizes at once.

Any help will be appreciated!
Thanks,
L.
 
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#2
No one?
I googled for this and was unable to find the answer...
 
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#3
My opinion is that every widget inherits its pango context from its container parent. I don't think it makes a copy. But if it does, I would just make a recursive call starting at the top level window.

Maybe use the gtk.Container.get_children() call

The pseudo code might look something like this:

Code:
window.changePango(window)

def changePango (self, child):
    if child is a container:
        for subChild in child.get_children():
            changePango (subChild)
    else:
        change the child's pango context
If a child doesn't make a copy, just change the toplevel window's pango context and then maybe call the toplevel window's check_resize().

Check gtk.Container for more info.
__________________
N9: Go white or go home

Last edited by daperl; 2009-06-09 at 19:28.
 

The Following 3 Users Say Thank You to daperl For This Useful Post:
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#4
Please note my edits. My first pseudo code was out-to-lunch.
__________________
N9: Go white or go home
 
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#5
Originally Posted by daperl View Post
Please note my edits. My first pseudo code was out-to-lunch.
Wow... I am surprised this is so hard. Anyway, I will only change some widget fonts. I changed Entry and TreeView, but was unable to change the font of a combolist or a menu. Certainly because of what you said about containers. But my problem is that, say, the combolist change all the time. How can I change the font of the whole list, even if it changes?

In fact, I changed the menu font and all its children and parents, without any success...

Thanks!
L.

Last edited by luis; 2009-06-10 at 03:06.
 
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#6
Originally Posted by daperl View Post
My opinion is that every widget inherits its pango context from its container parent. I don't think it makes a copy. But if it does, I would just make a recursive call starting at the top level window.

Maybe use the gtk.Container.get_children() call

The pseudo code might look something like this:

Code:
window.changePango(window)

def changePango (self, child):
    if child is a container:
        for subChild in child.get_children():
            changePango (subChild)
    else:
        change the child's pango context
If a child doesn't make a copy, just change the toplevel window's pango context and then maybe call the toplevel window's check_resize().

Check gtk.Container for more info.
Just a question: how do you check if a widget is a container?

Thanks,
L.
 
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#7
Originally Posted by luis View Post
Just a question: how do you check if a widget is a container?

Thanks,
L.
The appended script returned:
Code:
yes
yes
no
and it should be robust.

Code:
import gobject
import gtk

myContainer = gtk.Window()
if gobject.type_is_a(myContainer,gtk.Window):
  print 'yes'
else:
  print 'no'
if gobject.type_is_a(myContainer,gtk.Container):
  print 'yes'
else:
  print 'no'
if gobject.type_is_a(myContainer,gtk.Label):
  print 'yes'
else:
  print 'no'
__________________
N9: Go white or go home
 
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#8
Originally Posted by daperl View Post
The appended script returned:
Code:
yes
yes
no
and it should be robust.

Code:
import gobject
import gtk

myContainer = gtk.Window()
if gobject.type_is_a(myContainer,gtk.Window):
  print 'yes'
else:
  print 'no'
if gobject.type_is_a(myContainer,gtk.Container):
  print 'yes'
else:
  print 'no'
if gobject.type_is_a(myContainer,gtk.Label):
  print 'yes'
else:
  print 'no'
Yep! It worked.
However, I have a dialog box, and this changed the font of the "OK" button, but not the dialog text font...

Any clues?

Thanks once again!
L.
 
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#9
From the gtk.Dialog reference page:

Attributes

"vbox" Read A gtk.VBox that is the main container of the dialog - all the other widgets are packed in it.
"action_area" Read A gtk.HBox that contains the buttons of the dialog.
So, maybe you have to traverse these containers individually.

myDialog.vbox
myDialog.action_area
__________________
N9: Go white or go home
 
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#10
Originally Posted by daperl View Post
From the gtk.Dialog reference page:



So, maybe you have to traverse these containers individually.

myDialog.vbox
myDialog.action_area
Acutally, I have a gtk.messagedialog. I tried with vbox, action_area and label, and the actual dialog font stays the same. This is my code (that I call with self.changePango(dialog.label), self.changePango(dialog.vbox), self.changePango(dialog.action_area),
self.changePango(dialog)):

Code:
def changePango(self, child):
   if gobject.type_is_a(child,gtk.Container):
        for subChild in child.get_children():
            self.changePango(subChild)
   else:
   child.modify_font(pango.FontDescription("courier bold 60"))
What am I doing wrong??

Thanks again,

L.
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 12:07.