2006-06-01 00:01:24 +02:00
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
import sugar.env
|
|
|
|
|
|
|
|
class AddressEntry(gtk.HBox):
|
|
|
|
def __init__(self, callback):
|
|
|
|
gtk.HBox.__init__(self)
|
|
|
|
|
|
|
|
self.callback = callback
|
|
|
|
self.folded = True
|
|
|
|
|
|
|
|
label = gtk.Label("Open")
|
|
|
|
self.pack_start(label, False)
|
|
|
|
label.show()
|
|
|
|
|
|
|
|
self.button = gtk.Button()
|
|
|
|
self.button.set_relief(gtk.RELIEF_NONE)
|
|
|
|
self.button.connect("clicked", self.__button_clicked_cb)
|
|
|
|
self.pack_start(self.button, False)
|
|
|
|
self.button.show()
|
|
|
|
|
|
|
|
self.entry = gtk.Entry()
|
|
|
|
self.entry.connect("activate", self.__activate_cb)
|
|
|
|
self.pack_start(self.entry, False)
|
|
|
|
self.entry.show()
|
|
|
|
|
|
|
|
self._update_folded_state()
|
|
|
|
|
|
|
|
def _update_folded_state(self):
|
|
|
|
if self.folded:
|
|
|
|
image = gtk.Image()
|
2006-06-07 22:08:14 +02:00
|
|
|
image.set_from_icon_name('expand', gtk.ICON_SIZE_SMALL_TOOLBAR)
|
2006-06-01 00:01:24 +02:00
|
|
|
self.button.set_image(image)
|
|
|
|
image.show()
|
|
|
|
|
|
|
|
self.entry.hide()
|
|
|
|
else:
|
|
|
|
image = gtk.Image()
|
2006-06-07 22:08:14 +02:00
|
|
|
image.set_from_icon_name('unexpand', gtk.ICON_SIZE_SMALL_TOOLBAR)
|
2006-06-01 00:01:24 +02:00
|
|
|
self.button.set_image(image)
|
|
|
|
image.show()
|
|
|
|
|
|
|
|
self.entry.show()
|
|
|
|
self.entry.grab_focus()
|
|
|
|
|
|
|
|
def get_folded(self):
|
|
|
|
return self.folded
|
|
|
|
|
|
|
|
def set_folded(self, folded):
|
|
|
|
self.folded = folded
|
|
|
|
self._update_folded_state()
|
|
|
|
|
|
|
|
def __button_clicked_cb(self, button):
|
|
|
|
self.set_folded(not self.get_folded())
|
|
|
|
|
|
|
|
def __activate_cb(self, entry):
|
|
|
|
self.callback(entry.get_text())
|
|
|
|
self.set_folded(True)
|
|
|
|
|
|
|
|
class AddressItem(gtk.ToolItem):
|
|
|
|
def __init__(self, callback):
|
|
|
|
gtk.ToolItem.__init__(self)
|
|
|
|
|
|
|
|
address_entry = AddressEntry(callback)
|
|
|
|
self.add(address_entry)
|
|
|
|
address_entry.show()
|