Toolbaritem ?update? hinzugef?gt

This commit is contained in:
gotik 2012-04-20 01:46:08 +02:00
parent 6ba8e52815
commit 355303daf1

View file

@ -13,6 +13,7 @@ UI_INFO = """
<ui> <ui>
<toolbar name='ToolBar'> <toolbar name='ToolBar'>
<toolitem action='Connect' /> <toolitem action='Connect' />
<toolitem action='Update' />
</toolbar> </toolbar>
</ui> </ui>
""" """
@ -39,8 +40,11 @@ class MCGGtk(Gtk.Window):
self.add_accel_group(accel_group) self.add_accel_group(accel_group)
ui_manager.insert_action_group(action_group) ui_manager.insert_action_group(action_group)
self._action_connect = Gtk.Action("Connect", "_Connect", "Connect to server", Gtk.STOCK_DISCONNECT) self._action_connect = Gtk.Action("Connect", "_Connect", "Connect to server", Gtk.STOCK_DISCONNECT)
self._action_connect.connect("activate", self.on_toolbar_connect) self._action_connect.connect("activate", self.toolbar_callback)
action_group.add_action_with_accel(self._action_connect, None) action_group.add_action_with_accel(self._action_connect, None)
self._action_update = Gtk.Action("Update", "_Update", "Update library", Gtk.STOCK_REFRESH)
self._action_update.connect("activate", self.toolbar_callback)
action_group.add_action_with_accel(self._action_update, None)
# Toolbar # Toolbar
toolbar = ui_manager.get_widget("/ToolBar") toolbar = ui_manager.get_widget("/ToolBar")
toolbar_context = toolbar.get_style_context() toolbar_context = toolbar.get_style_context()
@ -97,11 +101,14 @@ class MCGGtk(Gtk.Window):
self._update() self._update()
def on_toolbar_connect(self, widget): def toolbar_callback(self, widget):
if self._mcg.is_connected(): if widget == self._action_connect:
self._mcg.disconnect() if self._mcg.is_connected():
else: self._mcg.disconnect()
self._mcg.connect() else:
self._mcg.connect()
elif widget == self._action_update:
self._update()
def on_resize(self, widget, allocation): def on_resize(self, widget, allocation):
@ -182,6 +189,6 @@ if __name__ == "__main__":
mcgg.show_all() mcgg.show_all()
try: try:
Gtk.main() Gtk.main()
except KeyboardInterrupt: except (KeyboardInterrupt, SystemExit):
pass pass