This is how I set styles and switch between styles at runtime.

Let's say we want to put white text on a black background.  We first have to
define the styles in a "style rc" file.  (See testgtkrc in the testgtk example
of the pygtk distribution.)

-----------8<-----------
style "button_style"

  bg[NORMAL] = { 0, 0, 0 }
  bg[PRELIGHT] = { 0, 0, 0 }
  bg[ACTIVE] = { 0, 0, 0 }


style "label_style"

  font = "-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-*-*"
  fg[NORMAL] = { 1.0, 1.0, 1.0 }
  fg[PRELIGHT] = { 1.0, 1.0, 1.0 }
  fg[ACTIVE] = { 1.0, 1.0, 1.0 }
-----------8<-----------

Next, we make the widgets and use the "rc_parse_string" method.  But make the
label a separate widget, and add it to the button.  For some reason defining the
label with GtkButton('Label Name') is unreliable for switching styles at
runtime.

-----------8<-----------
button = GtkButton()
rc_parse_string('widget "*button*" style "button_style"')
button.set_name('button')
...

label = GtkLabel('I am a label!')
rc_parse_string('widget "*label*" style "label_style"')
label.set_name('label')
button.add(label)
-----------8<-----------

At any other point in our program, we can change the styles to others defined in
the style rc.

-----------8<-----------
rc_parse_string('widget "*button*" style "button_style2"')
button.set_name('button')

rc_parse_string('widget "*label*" style "label_style2"')
button.set_name('label')
-----------8<-----------
     
Maybe this isn't orthodox, but it works.  BTW, for switching styles, it works
best to use "set_name" AFTER rc_parse_string, rather than before.

If anyone sees something wrong in the way I am doing this, that might explain
why labels have to be separate widgets and why set_name is used after
rc_parse_string, please let me know.


Jeff


[EMAIL PROTECTED] wrote:
> 
> J.W. Bizzaro discourseth:
> > Can you describe the problem with using light text on a dark background?  I am
> > doing this now and have no problems.
> 
> I'm probably doing it totally wrong. :|
> 
> Could I see your code..or a `hello world' of dark styles?
> 
> Many Thanks,
> 
> Eric
> To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]

-- 
J.W. Bizzaro                  mailto:[EMAIL PROTECTED]
Boston College Chemistry      http://www.uml.edu/Dept/Chem/Bizzaro/
--
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]

Reply via email to