クリック時にToolItemウィジェットを表示するpygtkでToolButtonウィジェットを作成したい..ウィジェットのすべてのクラスを含むファイル(widgets.pyなど)と、これらのウィジェットをインスタンス化する別のファイル(demo.pyなど)があります。ツールバーに挿入されました。
デモ.py
class Demo(activity.Activity):
def __init__(self,activity):
toolbar_box = ToolbarBox()
self.set_toolbar_box(toolbar_box)
toolbar_box.toolbar.insert(MathButton(self), -1)
toolbar_box.toolbar.insert(MathStartTitleEntry(self), -1)
toolbar_box.show_all()
Widgets.py
class MathButton(ToolButton):
def __init__(self,activity, **kwargs):
ToolButton.__init__(self,'add',**kwargs)
self.props.tooltip = _('Start Maths Game')
self.connect('clicked', self.mathfun, activity)
def mathfun(self, button, activity):
activity.close()
class MathStartTitleEntry(gtk.ToolItem):
def __init__(self,activity, **kwargs):
gtk.ToolItem.__init__(self)
self.entry = gtk.Entry(**kwargs)
self.entry.set_size_request(int(gtk.gdk.screen_width() / 9),-1)
self.entry.set_text("Start ")
self.entry.set_property("editable", False)
self.entry.unset_flags(gtk.CAN_FOCUS)
self.entry.show()
self.add(self.entry)