Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAneesh Dogra <lionaneesh@gmail.com>2012-12-21 16:55:38 (GMT)
committer Aneesh Dogra <lionaneesh@gmail.com>2012-12-21 16:55:38 (GMT)
commit90bf540929e81316fc9fdc08d3cdae8eb1e00cf5 (patch)
treef3ea3f9e37182abb779dd67399140cd0de140c4b
parent67f4fe50bef0cf9b5077cfe7fd492ae7ecf6a7e4 (diff)
Use a ComboBoxText to set timer.
-rw-r--r--GNUChessActivity.py55
-rw-r--r--chess.py6
2 files changed, 26 insertions, 35 deletions
diff --git a/GNUChessActivity.py b/GNUChessActivity.py
index 9d54e0e..43976d3 100644
--- a/GNUChessActivity.py
+++ b/GNUChessActivity.py
@@ -27,7 +27,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, toggle_factory
+ radio_factory, entry_factory, combo_factory
from utils import json_load, json_dump, get_hardware, \
pixbuf_to_base64, base64_to_pixbuf
@@ -286,21 +286,23 @@ class GNUChessActivity(activity.Activity):
separator_factory(self.adjust_toolbar, False, True)
- self.timer_off_button = toggle_factory('human',
- self._toggle_timer,
- self.adjust_toolbar,
- tooltip=_('Toggle Timer'))
-
- self.timer = Gtk.Entry()
- self.timer.set_sensitive(False)
- self.timer.set_text('0')
- self.timer.set_max_length(4)
- self.timer.set_tooltip_text(_("Timer (no of seconds)"))
- self.timer.connect('changed', self.save_time)
+ time_list = [_('Disabled'),
+ _('Lightning: 30 seconds'),
+ _('Blitz: 3 minutes'),
+ _('Tournament: 10 minutes')]
+ self.timer = Gtk.ComboBoxText()
+ for t in time_list:
+ self.timer.append_text(t)
+ self.timer.set_tooltip_text(_('Timer'))
+ self.timer.set_active(0)
+ self.timer.connect("changed", self.set_timer_cb)
+
toolitem = Gtk.ToolItem()
toolitem.add(self.timer)
self.adjust_toolbar.insert(toolitem, -1)
- toolitem.show_all()
+ toolitem.show()
+ self.timer.show()
+ self.timer.set_sensitive(True)
self.robot_button.set_active(True)
@@ -401,16 +403,6 @@ class GNUChessActivity(activity.Activity):
cb_arg='black_king',
tooltip=_('Black King'))
- def save_time(self, widget):
- # If time_interval is invalid and we really need to change it
- if self.time_interval == None:
- if self.timer.get_text().isdigit() and \
- (int(self.timer.get_text()) >= 1):
- a = self.timer.get_text()
- self.time_interval = copy.copy(int(a))
- else:
- self.timer.set_text('0')
-
def do_default_skin_cb(self, button=None):
self._gnuchess.reskin_from_file('black_king',
'%s/icons/black-king.svg' % (activity.get_bundle_path()))
@@ -498,13 +490,15 @@ class GNUChessActivity(activity.Activity):
self._gnuchess.reskin_from_file(piece, file_path)
return
- def _toggle_timer(self, widget):
- if widget.get_active():
- self.timer.set_sensitive(True)
- else:
- self.timer.set_sensitive(False)
- self.timer.set_text('0')
- self.time_interval = None
+ def set_timer_cb(self, widget):
+ if widget.get_active() > 0:
+ timer_type = widget.get_active_text()
+ if timer_type == _('Lightning: 30 seconds'):
+ self.time_interval = 30
+ elif timer_type == _('Blitz: 3 minutes'):
+ self.time_interval = 3 * 60
+ elif timer_type == _('Tournament: 10 minutes'):
+ self.time_interval = 10 * 60
def _reskin_cb(self, button, piece):
object_id, file_path = self._choose_skin()
@@ -942,7 +936,6 @@ params=%r state=%d' % (id, initiator, type, service, params, state))
def stopwatch(self, time, alert_callback):
if self.stopwatch_running:
self.stopwatch_timer.cancel()
- self.timer.set_text(str(self.time_interval))
time = self.time_interval
self.stopwatch_timer = threading.Timer(time, alert_callback)
self.stopwatch_running = True
diff --git a/chess.py b/chess.py
index d09f9cb..c7957b5 100644
--- a/chess.py
+++ b/chess.py
@@ -133,8 +133,6 @@ class Gnuchess():
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
- self._activity.timer.set_sensitive(False)
-
if my_move == HINT:
level = 'hard\nbook on\n' # may as well get a good hint
elif self._activity.playing_mode == 'easy':
@@ -261,8 +259,7 @@ class Gnuchess():
self._flash_tile([self._xy_to_file_and_rank(
self.black[4].get_xy())])
else:
- if self._activity.timer.get_text().isdigit() and \
- (self._activity.time_interval >= 2):
+ if self._activity.time_interval != None:
self._activity.stopwatch(self._activity.time_interval,
self._activity.alert_time)
@@ -432,6 +429,7 @@ class Gnuchess():
self._dragpos = [x, y]
self._total_drag[0] += dx
self._total_drag[1] += dy
+ self._activity.timer.set_sensitive(False)
return True
def _button_release_cb(self, win, event):