Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/dialogs.py
diff options
context:
space:
mode:
Diffstat (limited to 'dialogs.py')
-rw-r--r--dialogs.py147
1 files changed, 147 insertions, 0 deletions
diff --git a/dialogs.py b/dialogs.py
new file mode 100644
index 0000000..f788f18
--- /dev/null
+++ b/dialogs.py
@@ -0,0 +1,147 @@
+# -*- coding: utf-8 -*-
+
+# From Ingenium Machina by Gonzalo Odiard and Manuel QuiƱones
+
+# 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)
+ 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:
+ sep = gtk.SeparatorToolItem()
+ sep.set_draw(False)
+ self._add_widget(sep)
+ 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 ScoreDialog(_DialogWindow):
+
+ __gtype_name__ = 'ScoreDialog'
+
+ def __init__(self, scores):
+
+ super(ScoreDialog, self).__init__("score", _('Score'))
+
+ scrollwin = gtk.ScrolledWindow()
+ scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ self.content_vbox.pack_start(scrollwin)
+
+ liststore = gtk.ListStore(str, str)
+ treeview = gtk.TreeView(liststore)
+
+ date_cell = gtk.CellRendererText()
+ date_column = gtk.TreeViewColumn(_("Date and Time"))
+ date_column.pack_start(date_cell)
+ date_column.set_attributes(date_cell, text=1)
+ treeview.append_column(date_column)
+
+ time_cell = gtk.CellRendererText()
+ time_column = gtk.TreeViewColumn(_("Score"))
+
+ time_column.pack_start(time_cell)
+ time_column.set_attributes(time_cell, text=0)
+
+ treeview.append_column(time_column)
+
+ scores.sort()
+
+ for i in scores:
+ score, date = i.split(",")
+ liststore.append([score, date])
+
+ scrollwin.add_with_viewport(treeview)