diff options
author | Daniel Francis <francis@sugarlabs.org> | 2012-07-07 01:54:04 (GMT) |
---|---|---|
committer | Daniel Francis <francis@sugarlabs.org> | 2012-07-07 01:54:04 (GMT) |
commit | 61e7c8a2ba8082c534b80711b0e47118f88bc9a0 (patch) | |
tree | f0fb511158dbafe63ef706789f3ffd1ac6c85656 /toolbars.py | |
parent | a0ddb7c3f17632c56fb5766a5c8fc785cb23b985 (diff) |
Moving toolbars to a new file; re-ordering toolbars and code, updating some settings automatically
Diffstat (limited to 'toolbars.py')
-rw-r--r-- | toolbars.py | 239 |
1 files changed, 239 insertions, 0 deletions
diff --git a/toolbars.py b/toolbars.py new file mode 100644 index 0000000..5bd09d8 --- /dev/null +++ b/toolbars.py @@ -0,0 +1,239 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- +# +# Copyright 2012 S. Daniel Francis <francis@sugarlabs.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +from gettext import gettext as _ +import gobject +import gtk +from sugar.activity.widgets import ToolbarButton +from sugar.graphics.toolbarbox import ToolbarBox +from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.toggletoolbutton import ToggleToolButton +from sugar.graphics.radiotoolbutton import RadioToolButton +from sugar.graphics.colorbutton import ColorToolButton + + +class ViewToolbar(ToolbarButton): + __gsignals__ = {'zoom-in': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + tuple()), + 'zoom-out': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + tuple()), + 'zoom-reset': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + tuple())} + + def __init__(self): + ToolbarButton.__init__(self) + self.props.icon_name = 'toolbar-view' + self.toolbar = gtk.Toolbar() + self.props.page = self.toolbar + + self.setup_scale_range() + self.setup_zoom() + + def setup_zoom(self): + zoom_in_item = ToolButton('zoom-in') + zoom_in_item.props.tooltip = _('Zoom In') + zoom_in_item.connect('clicked', + lambda w: self.emit('zoom-in')) + zoom_in_item.show() + self.toolbar.insert(zoom_in_item, -1) + zoom_out_item = ToolButton('zoom-out') + zoom_out_item.props.tooltip = _('Zoom Out') + zoom_out_item.connect('clicked', + lambda w: self.emit('zoom-out')) + zoom_out_item.show() + self.toolbar.insert(zoom_out_item, -1) + zoom_reset_item = ToolButton('zoom-original') + zoom_reset_item.props.tooltip = _('Reset Zoom') + zoom_reset_item.connect('clicked', + lambda w: self.emit('zoom-reset')) + zoom_reset_item.show() + self.toolbar.insert(zoom_reset_item, -1) + + def setup_scale_range(self): + scale_range = ToolButton('cell-size') + scale_range.set_tooltip(_('Scale Range')) + range_palette = scale_range.get_palette() + self.setup_scale_range_palette(range_palette) + self.toolbar.insert(scale_range, -1) + scale_range.connect('clicked', + lambda w: range_palette.popup(immediate=True, + state=1)) + scale_range.show() + + def setup_scale_range_palette(self, palette): + scale_range_table = gtk.Table(4, 2, False) + x_min_label = gtk.Label(_('X min') + ' =') + self.x_min_entry = gtk.Entry() + self.x_min_entry.set_size_request(90, -1) + self.x_min_entry.set_alignment(0) + scale_range_table.attach(x_min_label, 0, 1, 0, 1, xpadding=5) + scale_range_table.attach(self.x_min_entry, 1, 2, 0, 1) + x_max_label = gtk.Label(_('X max') + ' =') + self.x_max_entry = gtk.Entry() + self.x_max_entry.set_size_request(90, -1) + self.x_max_entry.set_alignment(0) + scale_range_table.attach(x_max_label, 0, 1, 2, 3, xpadding=5) + scale_range_table.attach(self.x_max_entry, 1, 2, 2, 3) + + y_min_label = gtk.Label(_('Y min') + ' =') + self.y_min_entry = gtk.Entry() + self.y_min_entry.set_size_request(90, -1) + self.y_min_entry.set_alignment(0) + scale_range_table.attach(y_min_label, 2, 3, 0, 1, xpadding=5) + scale_range_table.attach(self.y_min_entry, 3, 4, 0, 1) + y_max_label = gtk.Label(_('Y max') + ' =') + self.y_max_entry = gtk.Entry() + self.y_max_entry.set_size_request(90, -1) + self.y_max_entry.set_alignment(0) + scale_range_table.attach(y_max_label, 2, 3, 2, 3, xpadding=5) + scale_range_table.attach(self.y_max_entry, 3, 4, 2, 3) + palette.set_content(scale_range_table) + scale_range_table.show_all() + + +class PreferencesToolbar(ToolbarButton): + __gsignals__ = {'connect-points': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + (gobject.TYPE_BOOLEAN,)), + 'decimal-scale': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + tuple()), + 'radian-scale': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + tuple()), + 'custom-scale': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + tuple())} + + def __init__(self): + ToolbarButton.__init__(self) + self.props.icon_name = 'preferences-system' + self.toolbar = gtk.Toolbar() + self.props.page = self.toolbar + self.setup_connect_points() + separator = gtk.SeparatorToolItem() + separator.show() + self.toolbar.insert(separator, -1) + self.setup_scale_style() + + def setup_connect_points(self): + connect_points_item = ToggleToolButton('connect-points') + connect_points_item.set_tooltip(_('Connect Points')) + connect_points_item.set_active(True) + connect_points_item.connect('toggled', + lambda w: self.emit('connect-points', + connect_points_item.get_active())) + connect_points_item.show() + self.toolbar.insert(connect_points_item, -1) + + def setup_scale_style(self): + decimal_item = RadioToolButton() + decimal_item.set_named_icon('decimal') + decimal_item.set_tooltip(_('Decimal Scale Style')) + decimal_item.connect('toggled', + lambda w: self.emit('decimal-scale')) + decimal_item.show() + self.toolbar.insert(decimal_item, -1) + radians_item = RadioToolButton() + radians_item.set_named_icon('radian') + radians_item.set_tooltip(_('Radians Scale Style')) + radians_item.set_group(decimal_item) + radians_item.connect('toggled', + lambda w: self.emit('radian-scale')) + radians_item.show() + self.toolbar.insert(radians_item, -1) + custom_item = RadioToolButton() + custom_item.set_named_icon('custom') + custom_item.set_tooltip(_('Custom Scale Style')) + custom_item.set_group(radians_item) + custom_item.connect('toggled', + lambda w: self.emit('custom-scale')) + custom_item.show() + scale_palette = custom_item.get_palette() + self.setup_scale_palette(scale_palette) + self.toolbar.insert(custom_item, -1) + + def setup_scale_palette(self, palette): + scale_table = gtk.Table(2, 2, False) + self.x_scale_entry = gtk.Entry() + self.x_scale_entry.set_size_request(90, -1) + self.y_scale_entry = gtk.Entry() + self.y_scale_entry.set_size_request(90, -1) + x_scale_label = gtk.Label(_('X scale')) + x_scale_label.set_alignment(0, .5) + y_scale_label = gtk.Label(_('Y scale')) + y_scale_label.set_alignment(0, .5) + scale_table.attach(x_scale_label, 0, 1, 0, 1, xpadding=5) + scale_table.attach(self.x_scale_entry, 1, 2, 0, 1) + scale_table.attach(y_scale_label, 0, 1, 1, 2, xpadding=5) + scale_table.attach(self.y_scale_entry, 1, 2, 1, 2) + palette.set_content(scale_table) + scale_table.show_all() + + +class GraphPlotterToolbarBox(ToolbarBox): + __gsignals__ = {'append-function': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + tuple()), + 'remove-function': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + tuple()), + 'color-updated': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + (gobject.TYPE_PYOBJECT,))} + + def __init__(self, activity_button, stop_button): + ToolbarBox.__init__(self) + self.toolbar.insert(activity_button, 0) + activity_button.show() + self.view_toolbar = ViewToolbar() + self.view_toolbar.show() + self.toolbar.insert(self.view_toolbar, -1) + self.settings_toolbar = PreferencesToolbar() + self.settings_toolbar.show() + self.toolbar.insert(self.settings_toolbar, -1) + add_function = ToolButton('gtk-add') + add_function.set_tooltip(_('Append Function')) + add_function.connect('clicked', lambda w: self.emit('append-function')) + add_function.show() + self.toolbar.insert(add_function, -1) + remove_function = ToolButton('gtk-remove') + remove_function.set_tooltip(_('Remove the selected function')) + remove_function.connect('clicked', + lambda w: self.emit('remove-function')) + remove_function.show() + self.toolbar.insert(remove_function, -1) + self.line_color_btn = ColorToolButton() + self.line_color_btn.set_title(_('Function color')) + self.line_color_btn.connect('notify::color', + lambda w, pspec: self.emit('color-updated', + w.get_color())) + self.line_color_btn.show_all() + self.toolbar.insert(self.line_color_btn, -1) + separator = gtk.SeparatorToolItem() + separator.set_draw(False) + separator.set_expand(True) + separator.show() + self.toolbar.insert(separator, -1) + self.toolbar.insert(stop_button, -1) + stop_button.show() |