[Ava Arachne Jarvis - Wed, 15 Jan 2003 05:25:54 AM CST]
> I'm attaching a version of the program that I stripped down to about 50
> lines.  Instruction for running this:

It would help if I attached the program. Heh.  Sorry.


-- 
| BOFH excuse #105:
|
| UPS interrupted the server's power
#!/usr/bin/python
import pygtk
pygtk.require('2.0')
import gtk, sys, string

class ColorWidget(gtk.Button):
    def __init__(self, stylebox):
        gtk.Button.__init__(self)
        self.stylebox = stylebox
        self.color = gtk.gdk.color_parse('white')
        self.set_size_request(30, 30)
        self.connect("clicked", self.setColor)

    def setBackground(self, gdkcolor = None):
        if gdkcolor: 
            self.color = gdkcolor
            for state in [gtk.STATE_ACTIVE, gtk.STATE_NORMAL, 
                          gtk.STATE_PRELIGHT, gtk.STATE_SELECTED]: 
                self.modify_bg(state, self.color)

    def setColor(self, w):
        print '__dict__:', self.__dict__
        self.setBackground(self.stylebox.getColor(self.color))

class StyleBox(gtk.Window):
    def __init__(self, numwidgets = 10):
        gtk.Window.__init__(self)
        self.connect("destroy", lambda w: gtk.main_quit())

        self.cdg = gtk.ColorSelectionDialog('Select Color')
        self.notebook = gtk.Notebook()
        self.notebook.set_show_tabs(0)
        self.add(self.notebook)

        for i in range(0, numwidgets): 
            self.createTestPanel()

    def getColor(self, prev_color = None):
        if prev_color: self.cdg.colorsel.set_current_color(prev_color)
        color = None
        if self.cdg.run() == gtk.RESPONSE_OK:
            color = self.cdg.colorsel.get_current_color()
        self.cdg.hide()
        return color
    
    def createTestPanel(self):
        panel = gtk.Frame()
        self.notebook.append_page(panel, gtk.Label('Test'))
        panel.add(ColorWidget(self))

s = StyleBox(string.atoi(sys.argv[1]))
s.show_all()
gtk.main()

Reply via email to