Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/toolbar_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'toolbar_utils.py')
-rw-r--r--toolbar_utils.py155
1 files changed, 44 insertions, 111 deletions
diff --git a/toolbar_utils.py b/toolbar_utils.py
index 94e6883..607bf22 100644
--- a/toolbar_utils.py
+++ b/toolbar_utils.py
@@ -11,70 +11,25 @@
# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
-import gtk
+from gi.repository import Gtk
-from sugar.graphics.radiotoolbutton import RadioToolButton
-from sugar.graphics.toolbutton import ToolButton
-from sugar.graphics.combobox import ComboBox
-from sugar.graphics.toolcombobox import ToolComboBox
-
-
-def combo_factory(combo_array, toolbar, callback, cb_arg=None,
- tooltip=None, default=None):
- '''Factory for making a toolbar combo box'''
- combo = ComboBox()
- if tooltip is not None and hasattr(combo, 'set_tooltip_text'):
- combo.set_tooltip_text(tooltip)
- if cb_arg is not None:
- combo.connect('changed', callback, cb_arg)
- else:
- combo.connect('changed', callback)
- for i, selection in enumerate(combo_array):
- combo.append_item(i, selection, None)
- combo.show()
- toolitem = gtk.ToolItem()
- toolitem.add(combo)
- if hasattr(toolbar, 'insert'): # the main toolbar
- toolbar.insert(toolitem, -1)
- else: # or a secondary toolbar
- toolbar.props.page.insert(toolitem, -1)
- toolitem.show()
- if default is not None:
- combo.set_active(combo_array.index(default))
- return combo
-
-
-def entry_factory(default_string, toolbar, tooltip=None, max=3):
- ''' Factory for adding a text box to a toolbar '''
- entry = gtk.Entry()
- entry.set_text(default_string)
- if tooltip is not None and hasattr(entry, 'set_tooltip_text'):
- entry.set_tooltip_text(tooltip)
- entry.set_width_chars(max)
- entry.show()
- toolitem = gtk.ToolItem()
- toolitem.add(entry)
- if hasattr(toolbar, 'insert'): # the main toolbar
- toolbar.insert(toolitem, -1)
- else: # or a secondary toolbar
- toolbar.props.page.insert(toolitem, -1)
- toolitem.show()
- return entry
+from sugar3.graphics.toolbutton import ToolButton
+from sugar3.graphics.radiotoolbutton import RadioToolButton
def button_factory(icon_name, toolbar, callback, cb_arg=None, tooltip=None,
- accelerator=None):
- '''Factory for making tooplbar buttons'''
+ accelerator=None):
+ ''' Factory for making toolbar buttons '''
button = ToolButton(icon_name)
if tooltip is not None:
button.set_tooltip(tooltip)
button.props.sensitive = True
if accelerator is not None:
button.props.accelerator = accelerator
- if cb_arg is not None:
- button.connect('clicked', callback, cb_arg)
- else:
+ if cb_arg is None:
button.connect('clicked', callback)
+ else:
+ button.connect('clicked', callback, cb_arg)
if hasattr(toolbar, 'insert'): # the main toolbar
toolbar.insert(button, -1)
else: # or a secondary toolbar
@@ -83,82 +38,60 @@ def button_factory(icon_name, toolbar, callback, cb_arg=None, tooltip=None,
return button
-def radio_factory(name, toolbar, callback, cb_arg=None, tooltip=None,
- group=None):
+def radio_factory(icon_name, toolbar, callback, cb_arg=None,
+ tooltip=None, group=None):
''' Add a radio button to a toolbar '''
button = RadioToolButton(group=group)
- button.set_named_icon(name)
- if callback is not None:
- if cb_arg is None:
- button.connect('clicked', callback)
- else:
- button.connect('clicked', callback, cb_arg)
- if hasattr(toolbar, 'insert'): # Add button to the main toolbar...
+ button.set_icon_name(icon_name)
+ if tooltip is not None:
+ button.set_tooltip(tooltip)
+ if cb_arg is None:
+ button.connect('clicked', callback)
+ else:
+ button.connect('clicked', callback, cb_arg)
+ if hasattr(toolbar, 'insert'): # the main toolbar
toolbar.insert(button, -1)
- else: # ...or a secondary toolbar.
+ else: # or a secondary toolbar
toolbar.props.page.insert(button, -1)
button.show()
- if tooltip is not None:
- button.set_tooltip(tooltip)
return button
-def label_factory(toolbar, label_text, width=None):
+def label_factory(label_text, toolbar):
''' Factory for adding a label to a toolbar '''
- label = gtk.Label(label_text)
+ label = Gtk.Label(label=label_text)
label.set_line_wrap(True)
- if width is not None:
- label.set_size_request(width, -1) # doesn't work on XOs
label.show()
- toolitem = gtk.ToolItem()
+ toolitem = Gtk.ToolItem()
toolitem.add(label)
- if hasattr(toolbar, 'insert'): # the main toolbar
- toolbar.insert(toolitem, -1)
- else: # or a secondary toolbar
- toolbar.props.page.insert(toolitem, -1)
+ toolbar.insert(toolitem, -1)
toolitem.show()
return label
-def separator_factory(toolbar, expand=False, visible=True):
- ''' add a separator to a toolbar '''
- separator = gtk.SeparatorToolItem()
- separator.props.draw = visible
- separator.set_expand(expand)
- if hasattr(toolbar, 'insert'): # the main toolbar
- toolbar.insert(separator, -1)
- else: # or a secondary toolbar
- toolbar.props.page.insert(separator, -1)
- separator.show()
-
-
-def image_factory(image, toolbar, tooltip=None):
- ''' Add an image to the toolbar '''
- img = gtk.Image()
- img.set_from_pixbuf(image)
- img_tool = gtk.ToolItem()
- img_tool.add(img)
- if tooltip is not None:
- img.set_tooltip_text(tooltip)
- if hasattr(toolbar, 'insert'): # the main toolbar
- toolbar.insert(img_tool, -1)
- else: # or a secondary toolbar
- toolbar.props.page.insert(img_tool, -1)
- img_tool.show()
- return img
-
-
-def spin_factory(default, min, max, callback, toolbar):
- spin_adj = gtk.Adjustment(default, min, max, 1, 32, 0)
- spin = gtk.SpinButton(spin_adj, 0, 0)
- spin_id = spin.connect('value-changed', callback)
+def spin_factory(default, min_value, max_value, callback, toolbar):
+ ''' Factory for making toolbar value spinners '''
+ spin_adj = Gtk.Adjustment(default, min_value, max_value, 1, 32, 0)
+ spin = Gtk.SpinButton()
+ spin.set_adjustment(spin_adj)
+ spin.connect('value-changed', callback)
spin.set_numeric(True)
spin.show()
- toolitem = gtk.ToolItem()
+ toolitem = Gtk.ToolItem()
toolitem.add(spin)
- if hasattr(toolbar, 'insert'): # the main toolbar
+ if toolbar is not None:
toolbar.insert(toolitem, -1)
+ toolitem.show()
+ return spin
else:
- toolbar.props.page.insert(toolitem, -1)
- toolitem.show()
- return spin
+ toolitem.show()
+ return spin, toolitem
+
+
+def separator_factory(toolbar, expand=False, visible=True):
+ ''' Add a separator to a toolbar '''
+ separator = Gtk.SeparatorToolItem()
+ separator.props.draw = visible
+ separator.set_expand(expand)
+ toolbar.insert(separator, -1)
+ separator.show()