diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2012-03-17 22:59:53 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-03-17 22:59:53 (GMT) |
commit | c92b89948ddd1ce7dbaf475be3e1a686592ad00d (patch) | |
tree | 90196691be754c9e59abe883fc525281d75bd8f5 /dialogs.py | |
parent | 92b7a45e49aa07852383f01e59dec134c8903156 (diff) |
Refactor dialogs
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'dialogs.py')
-rw-r--r-- | dialogs.py | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/dialogs.py b/dialogs.py new file mode 100644 index 0000000..5ddfd50 --- /dev/null +++ b/dialogs.py @@ -0,0 +1,112 @@ +# +# 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 2 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 St, Fifth Floor, Boston, MA 02110-1301 USA + +from gettext import gettext as _ + +import gobject +import gtk + +from sugar.graphics import style +from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.icon import Icon + + +class _DialogWindow(gtk.Window): + + # A base class for a modal dialog window. + + def __init__(self, icon_name, title): + super(_DialogWindow, self).__init__() + + self.set_border_width(style.LINE_WIDTH) + offset = style.GRID_CELL_SIZE + width = gtk.gdk.screen_width() - style.GRID_CELL_SIZE * 2 + height = gtk.gdk.screen_height() - style.GRID_CELL_SIZE * 2 + self.set_size_request(width, height) + self.set_position(gtk.WIN_POS_CENTER_ALWAYS) + self.set_decorated(False) + self.set_resizable(False) + self.set_modal(True) + + vbox = gtk.VBox() + self.add(vbox) + + toolbar = _DialogToolbar(icon_name, title) + toolbar.connect('stop-clicked', self._stop_clicked_cb) + vbox.pack_start(toolbar, False) + + self.content_vbox = gtk.VBox() + self.content_vbox.set_border_width(style.DEFAULT_SPACING) + vbox.add(self.content_vbox) + + self.connect('realize', self._realize_cb) + + def _stop_clicked_cb(self, source): + self.destroy() + + def _realize_cb(self, source): + self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) + self.window.set_accept_focus(True) + + +class _DialogToolbar(gtk.Toolbar): + + # Displays a dialog window's toolbar, with title, icon, and close box. + + __gsignals__ = { + 'stop-clicked': (gobject.SIGNAL_RUN_LAST, None, ()), + } + + def __init__(self, icon_name, title): + super(_DialogToolbar, self).__init__() + + if icon_name is not None: + icon = Icon() + icon.set_from_icon_name(icon_name, gtk.ICON_SIZE_LARGE_TOOLBAR) + self._add_widget(icon) + + self._add_separator() + + label = gtk.Label(title) + self._add_widget(label) + + self._add_separator(expand=True) + + stop = ToolButton(icon_name='dialog-cancel') + stop.set_tooltip(_('Done')) + stop.connect('clicked', self._stop_clicked_cb) + self.add(stop) + + def _add_separator(self, expand=False): + separator = gtk.SeparatorToolItem() + separator.set_expand(expand) + separator.set_draw(False) + self.add(separator) + + def _add_widget(self, widget): + tool_item = gtk.ToolItem() + tool_item.add(widget) + self.add(tool_item) + + def _stop_clicked_cb(self, button): + self.emit('stop-clicked') + + +class ResourceDialog(_DialogWindow): + + __gtype_name__ = 'ResourceDialog' + + def __init__(self, model, resource_id): + super(ResourceDialog, self).__init__(None, 'Show resource') |