maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Pygtk: how to change the whole app font size (https://talk.maemo.org/showthread.php?t=29414)

luis 2009-06-07 19:48

Pygtk: how to change the whole app font size
 
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.

luis 2009-06-09 17:14

Re: Pygtk: how to change the whole app font size
 
No one?
I googled for this and was unable to find the answer... :(

daperl 2009-06-09 19:21

Re: Pygtk: how to change the whole app font size
 
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.

daperl 2009-06-09 19:29

Re: Pygtk: how to change the whole app font size
 
Please note my edits. My first pseudo code was out-to-lunch.

luis 2009-06-10 03:01

Re: Pygtk: how to change the whole app font size
 
Quote:

Originally Posted by daperl (Post 295033)
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.

luis 2009-08-28 21:58

Re: Pygtk: how to change the whole app font size
 
Quote:

Originally Posted by daperl (Post 295029)
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 2009-08-28 23:38

Re: Pygtk: how to change the whole app font size
 
Quote:

Originally Posted by luis (Post 317582)
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'


luis 2009-08-29 01:41

Re: Pygtk: how to change the whole app font size
 
Quote:

Originally Posted by daperl (Post 317641)
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 2009-08-29 03:24

Re: Pygtk: how to change the whole app font size
 
From the gtk.Dialog reference page:

Quote:

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

luis 2009-08-31 20:26

Re: Pygtk: how to change the whole app font size
 
Quote:

Originally Posted by daperl (Post 317740)
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.


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

vBulletin® Version 3.8.8