New release.
[zeroinstall.git] / combo_compat.py
blobde93ab757c84c4f492cb0ebece3f4b59514fbea7
1 import gtk, gobject
3 class Action(gobject.GObject):
4 __proxy = None
5 __sensitive = True
7 __gproperties__ = {
8 'sensitive' : (gobject.TYPE_BOOLEAN, # type
9 'sensitive', # nick name
10 'sensitive', # description
11 True, # default value
12 gobject.PARAM_READWRITE) # flags
15 __gsignals__ = {
16 'activate' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
19 def __init__(self, name, label, tooltip, stock_id):
20 gobject.GObject.__init__(self)
22 def do_get_property(self, property):
23 return getattr(self, property.name)
25 def do_set_property(self, property, value):
26 return setattr(self, property.name, value)
28 def connect_proxy(self, widget):
29 assert self.__proxy is None
30 self.__proxy = widget
31 self.sensitive = self.__sensitive
32 widget.connect('clicked', lambda w: self.emit('activate'))
34 def set_sensitive(self, value):
35 if self.__proxy:
36 self.__proxy.set_sensitive(value)
37 self.__sensitive = value
39 sensitive = property(lambda self: self.__sensitive, set_sensitive)
41 gobject.type_register(Action)
43 class ComboText(gtk.OptionMenu):
44 def __init__(self):
45 gtk.OptionMenu.__init__(self)
46 self.__menu = gtk.Menu()
47 self.__model = []
48 self.set_menu(self.__menu)
50 def append_text(self, text):
51 item = gtk.MenuItem(text)
52 self.__model.append([text])
53 self.__menu.append(item)
55 def set_active(self, i):
56 self.set_history(i)
58 def get_active(self):
59 return self.get_history()
61 def get_model(self):
62 return self.__model
64 def combo_box_new_text():
65 return ComboText()
67 gtk.combo_box_new_text = combo_box_new_text
68 gtk.Action = Action