diff options
author | Walter Bender <walter.bender@gmail.com> | 2012-02-06 20:09:43 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2012-02-06 20:09:43 (GMT) |
commit | 39edf306f74a9a01dc5533a720741b3c708dde81 (patch) | |
tree | 7771a55f184d3baabcb08b33eb6da266fd682459 | |
parent | d78666b3fde753c5f0db0e0d65f85f351dbf8ba8 (diff) |
adding more modes/custom mode
-rw-r--r-- | YupanaActivity.py | 87 | ||||
-rw-r--r-- | icons/fibanocci.svg | 88 | ||||
-rw-r--r-- | yupana.py | 73 |
3 files changed, 239 insertions, 9 deletions
diff --git a/YupanaActivity.py b/YupanaActivity.py index 1d811bd..f697bfc 100644 --- a/YupanaActivity.py +++ b/YupanaActivity.py @@ -26,7 +26,7 @@ if _have_toolbox: from sugar.graphics.toolbarbox import ToolbarButton from toolbar_utils import button_factory, label_factory, separator_factory, \ - radio_factory + radio_factory, entry_factory from utils import json_load, json_dump import telepathy @@ -82,7 +82,11 @@ class YupanaActivity(activity.Activity): if 'dotlist' in self.metadata: self._restore() else: - self._yupana.new_yupana() + self._yupana.new_yupana(mode='ten') + + self._make_custom_toolbar() + if self._reload_custom: + self._custom_cb() def _setup_toolbars(self, have_toolbox): """ Setup the toolbars. """ @@ -90,6 +94,7 @@ class YupanaActivity(activity.Activity): self.max_participants = 4 yupana_toolbar = gtk.Toolbar() + self.custom_toolbar = gtk.Toolbar() if have_toolbox: toolbox = ToolbarBox() @@ -106,6 +111,13 @@ class YupanaActivity(activity.Activity): toolbox.toolbar.insert(yupana_toolbar_button, -1) yupana_toolbar_button.show() + custom_toolbar_button = ToolbarButton( + label=_("Custom"), page=self.custom_toolbar, + icon_name='view-source') + self.custom_toolbar.show() + toolbox.toolbar.insert(custom_toolbar_button, -1) + custom_toolbar_button.show() + self.set_toolbar_box(toolbox) toolbox.show() self.toolbar = toolbox.toolbar @@ -115,6 +127,7 @@ class YupanaActivity(activity.Activity): toolbox = activity.ActivityToolbox(self) self.set_toolbox(toolbox) toolbox.add_toolbar(_('Yupana'), yupana_toolbar) + toolbox.add_toolbar(_('Custom'), self.custom_toolbar) toolbox.show() toolbox.set_current_toolbar(1) self.toolbar = yupana_toolbar @@ -137,6 +150,14 @@ class YupanaActivity(activity.Activity): 'factor', yupana_toolbar, self._factor_cb, tooltip=_('prime-factor mode'), group=self.ten_button) + self.fibanocci_button = radio_factory( + 'fibanocci', yupana_toolbar, self._fibanocci_cb, + tooltip=_('fibanocci mode'), + group=self.ten_button) + self.custom_button = radio_factory( + 'view-source', yupana_toolbar, self._custom_cb, + tooltip=_('custom mode'), + group=self.ten_button) separator_factory(self.toolbar, False, False) self.status = label_factory(self.toolbar, '') @@ -151,6 +172,30 @@ class YupanaActivity(activity.Activity): toolbox.toolbar.insert(stop_button, -1) stop_button.show() + def _make_custom_toolbar(self): + self.ones = entry_factory(str(self._yupana.custom[0]), + self.custom_toolbar, + tooltip=_('one row')) + self.twos = entry_factory(str(self._yupana.custom[1]), + self.custom_toolbar, + tooltip=_('two row')) + self.threes = entry_factory(str(self._yupana.custom[2]), + self.custom_toolbar, + tooltip=_('three row')) + self.fives = entry_factory(str(self._yupana.custom[3]), + self.custom_toolbar, + tooltip=_('five row')) + + separator_factory(self.custom_toolbar, False, True) + self.base = entry_factory(str(self._yupana.custom[4]), + self.custom_toolbar, + tooltip=_('base')) + + separator_factory(self.custom_toolbar, False, True) + button_factory('view-refresh', self.custom_toolbar, self._custom_cb, + tooltip=_('Reload custom values.')) + + def _new_yupana_cb(self, button=None): ''' Start a new yupana. ''' self._yupana.new_yupana() @@ -158,22 +203,40 @@ class YupanaActivity(activity.Activity): def _ten_cb(self, button=None): self._yupana.new_yupana(mode='ten') self.status.set_label(_('decimal mode')) - return def _twenty_cb(self, button=None): self._yupana.new_yupana(mode='twenty') self.status.set_label(_('base-twenty mode')) - return def _factor_cb(self, button=None): self._yupana.new_yupana(mode='factor') self.status.set_label(_('prime-factor mode')) - return + + def _fibanocci_cb(self, button=None): + self._yupana.new_yupana(mode='fibanocci') + self.status.set_label(_('fibanocci mode')) + + def _custom_cb(self, button=None): + if hasattr(self, 'ones'): + self._yupana.custom[0] = self.ones.get_text() + self._yupana.custom[1] = self.twos.get_text() + self._yupana.custom[2] = self.threes.get_text() + self._yupana.custom[3] = self.fives.get_text() + self._yupana.custom[4] = self.base.get_text() + self._reload_custom = False + else: + self._reload_custom = True + self._yupana.new_yupana(mode='custom') + self.status.set_label(_('custom mode')) def write_file(self, file_path): """ Write the grid status to the Journal """ [mode, dot_list] = self._yupana.save_yupana() self.metadata['mode'] = mode + self.metadata['custom'] = '' + for i in range(5): + self.metadata['custom'] += str(self._yupana.custom[i]) + self.metadata['custom'] += ' ' self.metadata['dotlist'] = '' for dot in dot_list: self.metadata['dotlist'] += str(dot) @@ -182,13 +245,21 @@ class YupanaActivity(activity.Activity): def _restore(self): """ Restore the yupana state from metadata """ + if 'custom' in self.metadata: + values = self.metadata['custom'].split() + for i in range(5): + self._yupana.custom[i] = int(values[i]) if 'mode' in self.metadata: if self.metadata['mode'] == 'ten': - self._ten_cb() + self.ten_button.set_active(True) elif self.metadata['mode'] == 'twenty': - self._twenty_cb() + self.twenty_button.set_active(True) + elif self.metadata['mode'] == 'factor': + self.factor_button.set_active(True) + elif self.metadata['mode'] == 'fibanocci': + self.fibanocci_button.set_active(True) else: - self._factor_cb() + self.custom_button.set_active(True) if 'dotlist' in self.metadata: dot_list = [] dots = self.metadata['dotlist'].split() diff --git a/icons/fibanocci.svg b/icons/fibanocci.svg new file mode 100644 index 0000000..da535f1 --- /dev/null +++ b/icons/fibanocci.svg @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.1" + width="55.125" + height="55" + viewBox="0 0 55.125 55" + id="Layer_1" + xml:space="preserve"><metadata + id="metadata19"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs + id="defs25"> + + + + + + + + + + + + + + + + + + +</defs> + + + + + + + + + +<text + x="10.511383" + y="22.550398" + id="text2837" + xml:space="preserve" + style="font-size:40px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"><tspan + x="10.511383" + y="22.550398" + id="tspan2839" + style="font-size:18px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;fill:#ffffff;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans">1</tspan></text> +<text + x="32.827484" + y="22.66905" + id="text2837-9" + xml:space="preserve" + style="font-size:40px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"><tspan + x="32.827484" + y="22.66905" + id="tspan2839-9" + style="font-size:18px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;fill:#ffffff;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans">2</tspan></text> +<text + x="11.117828" + y="45.435444" + id="text2837-99" + xml:space="preserve" + style="font-size:40px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"><tspan + x="11.117828" + y="45.435444" + id="tspan2839-7" + style="font-size:18px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;fill:#ffffff;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans">5</tspan></text> +<text + x="26.793793" + y="45.316792" + id="text2837-5" + xml:space="preserve" + style="font-size:40px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"><tspan + x="26.793793" + y="45.316792" + id="tspan2839-3" + style="font-size:18px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;fill:#ffffff;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans">20</tspan></text> +</svg>
\ No newline at end of file @@ -62,6 +62,7 @@ class Yupana(): self.we_are_sharing = False self._sum = 0 self._mode = 'ten' + self.custom = [1, 1, 1, 1, 10] # Generate the sprites we'll need... self._sprites = Sprites(self._canvas) @@ -80,6 +81,7 @@ class Yupana(): Sprite(self._sprites, x, y, self._new_dot(self._colors[0]))) self._dots[-1].type = 0 # not set + self._dots[-1].set_label_color('white') x += self._dot_size + self._space x = int((p * self._width / 6.) + self._dot_size / 2.) + self._space y -= self._dot_size + self._space @@ -88,6 +90,7 @@ class Yupana(): Sprite(self._sprites, x, y, self._new_dot(self._colors[0]))) self._dots[-1].type = 0 # not set + self._dots[-1].set_label_color('white') x += self._dot_size + self._space y -= self._dot_size @@ -100,6 +103,7 @@ class Yupana(): Sprite(self._sprites, x, y, self._new_dot(self._colors[0]))) self._dots[-1].type = 0 # not set + self._dots[-1].set_label_color('white') x += self._dot_size + self._space x = int((p * self._width / 6.) + self._dot_size) + self._space y -= self._dot_size + self._space @@ -108,6 +112,7 @@ class Yupana(): Sprite(self._sprites, x, y, self._new_dot(self._colors[0]))) self._dots[-1].type = 0 # not set + self._dots[-1].set_label_color('white') x += self._dot_size + self._space y -= self._dot_size @@ -120,6 +125,7 @@ class Yupana(): Sprite(self._sprites, x, y, self._new_dot(self._colors[0]))) self._dots[-1].type = 0 # not set + self._dots[-1].set_label_color('white') x += self._dot_size + self._space y -= self._dot_size @@ -132,6 +138,7 @@ class Yupana(): Sprite(self._sprites, x, y, self._new_dot(self._colors[0]))) self._dots[-1].type = 0 # not set + self._dots[-1].set_label_color('white') x += self._dot_size + self._space y -= self._dot_size @@ -168,6 +175,51 @@ class Yupana(): if mode is not None: self._mode = mode + o = (SIX - 1) * (TEN + 1) # only label units + if mode == 'ten': + for i in range(TEN + 1): + self._dots[o + i].set_label('1') + self._dots[o - 1].set_label('10') + elif mode == 'twenty': + for i in range(TEN + 1): + if i in [7, 10]: + self._dots[o + i].set_label('1') + else: + self._dots[o + i].set_label('2') + self._dots[o - 1].set_label('20') + elif mode == 'factor': + for i in range(TEN + 1): + if i in [10]: + self._dots[o + i].set_label('1') + elif i in [8, 9]: + self._dots[o + i].set_label('2') + elif i in [5, 6, 7]: + self._dots[o + i].set_label('3') + else: + self._dots[o + i].set_label('5') + self._dots[o - 1].set_label('10') + elif mode == 'fibanocci': + for i in range(TEN + 1): + if i in [10]: + self._dots[o + i].set_label('1') + elif i in [8, 9]: + self._dots[o + i].set_label('2') + elif i in [5, 6, 7]: + self._dots[o + i].set_label('5') + else: + self._dots[o + i].set_label('20') + self._dots[o - 1].set_label('60') + else: # custom + for i in range(TEN + 1): + if i in [10]: + self._dots[o + i].set_label(str(self.custom[0])) + elif i in [8, 9]: + self._dots[o + i].set_label(str(self.custom[1])) + elif i in [5, 6, 7]: + self._dots[o + i].set_label(str(self.custom[2])) + else: + self._dots[o + i].set_label(str(self.custom[3])) + self._dots[o - 1].set_label(str(self.custom[4])) if self.we_are_sharing: _logger.debug('sending a new yupana') @@ -232,7 +284,7 @@ class Yupana(): return 20 ** e else: return (20 ** e) * 2 - else: # factor mode + elif self._mode == 'factor': if m in [10]: return 10 ** e elif m in [8, 9]: @@ -241,6 +293,25 @@ class Yupana(): return (10 ** e) * 3 else: return (10 ** e) * 5 + elif self._mode == 'fibanocci': + if m in [10]: + return 60 ** e + elif m in [8, 9]: + return (60 ** e) * 2 + elif m in [5, 6, 7]: + return (60 ** e) * 5 + else: + return (60 ** e) * 20 + else: # custom + if m in [10]: + return (self.custom[4] ** e) * self.custom[0] + elif m in [8, 9]: + return (self.custom[4] ** e) * self.custom[1] + elif m in [5, 6, 7]: + return (self.custom[4] ** e) * self.custom[2] + else: + return (self.custom[4] ** e) * self.custom[3] + def remote_button_press(self, dot, color): ''' Receive a button press from a sharer ''' |