From c15ec94388b4aa280797de783dbffaa8547b33d4 Mon Sep 17 00:00:00 2001 From: Aneesh Dogra Date: Fri, 21 Dec 2012 00:11:46 +0000 Subject: Add a toggle button to set/unset the timer and a label to show the no of seconds elpased. --- diff --git a/GNUChessActivity.py b/GNUChessActivity.py index b0d677f..bfdaaaf 100644 --- a/GNUChessActivity.py +++ b/GNUChessActivity.py @@ -26,7 +26,7 @@ from sugar3.graphics.icon import Icon from sugar3.graphics.xocolor import XoColor from toolbar_utils import button_factory, label_factory, separator_factory, \ - radio_factory, entry_factory + radio_factory, entry_factory, toggle_factory from utils import json_load, json_dump, get_hardware, \ pixbuf_to_base64, base64_to_pixbuf @@ -276,9 +276,18 @@ class GNUChessActivity(activity.Activity): group=self.robot_button, tooltip=_('Play against a person')) - separator_factory(self.adjust_toolbar, False, False) + separator_factory(self.adjust_toolbar, False, True) + + self.timer_off_button = toggle_factory('human', + self._toggle_timer, + self.adjust_toolbar, + tooltip=_('Toggle Timer')) - self.opponent = label_factory(self.adjust_toolbar, '') + self.timer = entry_factory('0', + self.adjust_toolbar, + tooltip=_("Timer (no of seconds)"), + max=4) + self.timer.hide() self.robot_button.set_active(True) @@ -466,6 +475,9 @@ class GNUChessActivity(activity.Activity): self._gnuchess.reskin_from_file(piece, file_path) return + def _toggle_timer(self, widget): + self.timer.show() + def _reskin_cb(self, button, piece): object_id, file_path = self._choose_skin() if file_path is not None: diff --git a/toolbar_utils.py b/toolbar_utils.py index 72f7100..9eb5762 100644 --- a/toolbar_utils.py +++ b/toolbar_utils.py @@ -18,6 +18,7 @@ from sugar3.graphics.radiotoolbutton import RadioToolButton from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics.combobox import ComboBox from sugar3.graphics.toolcombobox import ToolComboBox +from sugar3.graphics.toggletoolbutton import ToggleToolButton def combo_factory(combo_array, toolbar, callback, cb_arg=None, @@ -120,6 +121,18 @@ def label_factory(toolbar, label_text, width=None): toolitem.show() return label +def toggle_factory(icon_name, callback, toolbar, tooltip=None): + ''' add a toggle button to a toolbar''' + + t_button = ToggleToolButton(icon_name) + t_button.connect('toggled', callback) + if tooltip: + t_button.set_tooltip(tooltip) + if hasattr(toolbar, 'insert'): # the main toolbar + toolbar.insert(t_button, -1) + else: # or a secondary toolbar + toolbar.props.page.insert(t_button, -1) + t_button.show() def separator_factory(toolbar, expand=False, visible=True): ''' add a separator to a toolbar ''' -- cgit v0.9.1