From 656cbb923b34adebceefa9ba1e8b10666d3939ff Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 26 Jun 2010 23:01:59 +0000 Subject: label and spinner factories --- (limited to 'AbacusActivity.py') diff --git a/AbacusActivity.py b/AbacusActivity.py index e775e96..2f925d4 100644 --- a/AbacusActivity.py +++ b/AbacusActivity.py @@ -46,10 +46,36 @@ def button_factory(icon_name, tooltip, callback, toolbar): my_button.set_tooltip(tooltip) my_button.props.sensitive = True my_button.connect('clicked', callback) - toolbar.insert(my_button, -1) + if hasattr(toolbar, 'insert'): # the main toolbar + toolbar.insert(my_button, -1) + else: # or a secondary toolbar + toolbar.props.page.insert(my_button, -1) my_button.show() return my_button +def label_factory(label, toolbar): + """ Factory for adding a label to a toolbar """ + my_label = gtk.Label(label) + my_label.set_line_wrap(True) + my_label.show() + _toolitem = gtk.ToolItem() + _toolitem.add(my_label) + toolbar.insert(_toolitem, -1) + _toolitem.show() + return my_label + +def spin_factory(default, min, max, callback, toolbar): + _spin_adj = gtk.Adjustment(default, min, max, 1, 32, 0) + my_spin = gtk.SpinButton(_spin_adj, 0, 0) + _spin_id = my_spin.connect('value-changed', callback) + my_spin.set_numeric(True) + my_spin.show() + _toolitem = gtk.ToolItem() + _toolitem.add(my_spin) + toolbar.insert(_toolitem, -1) + _toolitem.show() + return my_spin + # # Sugar activity # @@ -120,108 +146,30 @@ class AbacusActivity(activity.Activity): # The Customization submenu (roll your own) custom_toolbar = gtk.Toolbar() - self._rods_label = gtk.Label(_("Rods:")+" ") - self._rods_label.set_line_wrap(True) - self._rods_label.show() - self._rods_toolitem = gtk.ToolItem() - self._rods_toolitem.add(self._rods_label) - custom_toolbar.insert(self._rods_toolitem, -1) - self._rods_toolitem.show() - - self._rods_spin_adj = gtk.Adjustment(15, 1, 20, 1, 32, 0) - self._rods_spin = gtk.SpinButton(self._rods_spin_adj, 0, 0) - self._rods_spin_id = self._rods_spin.connect('value-changed', - self._rods_spin_cb) - self._rods_spin.set_numeric(True) - self._rods_spin.show() - self.tool_item_rods = gtk.ToolItem() - self.tool_item_rods.add(self._rods_spin) - custom_toolbar.insert(self.tool_item_rods, -1) - self.tool_item_rods.show() - - self._top_label = gtk.Label(" "+_("Top:")+" ") - self._top_label.set_line_wrap(True) - self._top_label.show() - self._top_toolitem = gtk.ToolItem() - self._top_toolitem.add(self._top_label) - custom_toolbar.insert(self._top_toolitem, -1) - self._top_toolitem.show() - - self._top_spin_adj = gtk.Adjustment(2, 0, 4, 1, 32, 0) - self._top_spin = gtk.SpinButton(self._top_spin_adj, 0, 0) - self._top_spin_id = self._top_spin.connect('value-changed', - self._top_spin_cb) - self._top_spin.set_numeric(True) - self._top_spin.show() - self.tool_item_top = gtk.ToolItem() - self.tool_item_top.add(self._top_spin) - custom_toolbar.insert(self.tool_item_top, -1) - self.tool_item_top.show() - - self._bottom_label = gtk.Label(" "+_("Bottom:")+" ") - self._bottom_label.set_line_wrap(True) - self._bottom_label.show() - self._bottom_toolitem = gtk.ToolItem() - self._bottom_toolitem.add(self._bottom_label) - custom_toolbar.insert(self._bottom_toolitem, -1) - self._bottom_toolitem.show() - - self._bottom_spin_adj = gtk.Adjustment(5, 1, 15, 1, 32, 0) - self._bottom_spin = gtk.SpinButton(self._bottom_spin_adj, 0, 0) - self._bottom_spin_id = self._bottom_spin.connect('value-changed', - self._bottom_spin_cb) - self._bottom_spin.set_numeric(True) - self._bottom_spin.show() - self.tool_item_bottom = gtk.ToolItem() - self.tool_item_bottom.add(self._bottom_spin) - custom_toolbar.insert(self.tool_item_bottom, -1) - self.tool_item_bottom.show() - - self._value_label = gtk.Label(" "+_("Factor:")+" ") - self._value_label.set_line_wrap(True) - self._value_label.show() - self._value_toolitem = gtk.ToolItem() - self._value_toolitem.add(self._value_label) - custom_toolbar.insert(self._value_toolitem, -1) - self._value_toolitem.show() - - self._value_spin_adj = gtk.Adjustment(5, 1, 20, 1, 32, 0) - self._value_spin = gtk.SpinButton(self._value_spin_adj, 0, 0) - self._value_spin_id = self._value_spin.connect('value-changed', - self._value_spin_cb) - self._value_spin.set_numeric(True) - self._value_spin.show() - self.tool_item_value = gtk.ToolItem() - self.tool_item_value.add(self._value_spin) - custom_toolbar.insert(self.tool_item_value, -1) - self.tool_item_value.show() - - self._base_label = gtk.Label(" "+_("Base:")+" ") - self._base_label.set_line_wrap(True) - self._base_label.show() - self._base_toolitem = gtk.ToolItem() - self._base_toolitem.add(self._base_label) - custom_toolbar.insert(self._base_toolitem, -1) - self._base_toolitem.show() - - self._base_spin_adj = gtk.Adjustment(10, 1, 20, 1, 32, 0) - self._base_spin = gtk.SpinButton(self._base_spin_adj, 0, 0) - self._base_spin_id = self._base_spin.connect('value-changed', - self._base_spin_cb) - self._base_spin.set_numeric(True) - self._base_spin.show() - self.tool_item_base = gtk.ToolItem() - self.tool_item_base.add(self._base_spin) - custom_toolbar.insert(self.tool_item_base, -1) - self.tool_item_base.show() + self._rods_label = label_factory(_("Rods:")+" ", custom_toolbar) + self._rods_spin = spin_factory(15, 1, 20, self._rods_spin_cb, + custom_toolbar) + + self._top_label = label_factory(_("Top:")+" ", custom_toolbar) + self._top_spin = spin_factory(2, 0, 4, self._top_spin_cb, + custom_toolbar) + + self._bottom_label = label_factory(_("Bottom:")+" ", custom_toolbar) + self._bottom_spin = spin_factory(5, 1, 20, self._bottom_spin_cb, + custom_toolbar) + + self._value_label = label_factory(_("Factor:")+" ", custom_toolbar) + self._value_spin = spin_factory(5, 1, 20, self._value_spin_cb, + custom_toolbar) + + self._base_label = label_factory(_("Base:")+" ", custom_toolbar) + self._base_spin = spin_factory(10, 1, 24, self._base_spin_cb, + custom_toolbar) + # Custom - self._custom = ToolButton( "new-game" ) - self._custom.set_tooltip(_('Custom')) - self._custom.props.sensitive = True - self._custom.connect('clicked', self._custom_cb) - custom_toolbar.insert(self._custom, -1) - self._custom.show() + self._custom = button_factory("new-game", _('Custom'), + self._custom_cb, custom_toolbar) custom_toolbar_button = ToolbarButton( page=custom_toolbar, -- cgit v0.9.1