python - In pygtk, how can I combine font selection and color selection dialogs in one dialog? -
i'm using pygtk , searches best way combine font , color dialogs in one, pythonic way ?
you must change 'base' , 'text' parts of widget's style. can edit 'foreground' property. useful shorthand methods change style properties inherited gtk.widget are:
widget.modify_fg(state, color) widget.modify_bg(state, color) widget.modify_base(state, color) widget.modify_text(state, color)
windowless widgets such gtk.label, gtk.button, gtk.paned, gtk.frame, etc, (see faq 3.5) despite inheriting gtk.widget don't allow changing background , base color properties don't exist them. if want them need insert widget inside gtk.eventbox adds properties. example:
import gtk window = gtk.window(gtk.window_toplevel) window.connect("destroy", gtk.mainquit) label = gtk.label("one, two, testing...") eb = gtk.eventbox() eb.add(label) eb.modify_bg(gtk.state_normal, gtk.gdk.color_parse("blue")) window.add(eb) window.show_all() gtk.main()
also suggest read gtk.gdk.window — on-screen display areas in target window system.
by other hand, pygtk have dialogs change colors , change or select fonts.
example 1 : change fonts
import gtk import pango class pyapp(gtk.window): def __init__(self): gtk.window.__init__(self) self.set_size_request(300, 150) self.set_position(gtk.win_pos_center) self.connect("destroy", gtk.main_quit) self.set_title("font selection dialog") self.label = gtk.label("the victory on love flight.") button = gtk.button("select font") button.connect("clicked", self.on_clicked) fix = gtk.fixed() fix.put(button, 100, 30) fix.put(self.label, 30, 90) self.add(fix) self.show_all() def on_clicked(self, widget): fdia = gtk.fontselectiondialog("select font name") response = fdia.run() if response == gtk.response_ok: font_desc = pango.fontdescription(fdia.get_font_name()) if font_desc: self.label.modify_font(font_desc) fdia.destroy() pyapp() gtk.main()
example 2:change color of label
import gtk class pyapp(gtk.window): def __init__(self): super(pyapp, self).__init__() self.set_size_request(300, 150) self.set_position(gtk.win_pos_center) self.connect("destroy", gtk.main_quit) self.set_title("color selection dialog") self.label = gtk.label("the victory on love flight.") button = gtk.button("select color") button.connect("clicked", self.on_clicked) fix = gtk.fixed() fix.put(button, 100, 30) fix.put(self.label, 30, 90) self.add(fix) self.show_all() def on_clicked(self, widget): cdia = gtk.colorselectiondialog("select color") response = cdia.run() if response == gtk.response_ok: colorsel = cdia.colorsel color = colorsel.get_current_color() self.label.modify_fg(gtk.state_normal, color) cdia.destroy() pyapp() gtk.main()
hope can helps.