summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-10-10 23:51:14 (GMT)
committerWalter Bender <walter.bender@gmail.com>2011-10-10 23:51:14 (GMT)
commit70340f820f0465a44591409b89588c5bf773a2b2 (patch)
tree7392d67863f3281d6062568beb44ea1a92ec8ebb
parent400317104555c04d7ddf8c532680580552310a90 (diff)
downloadabacus-gtk3-70340f820f0465a44591409b89588c5bf773a2b2.tar.gz
abacus-gtk3-70340f820f0465a44591409b89588c5bf773a2b2.tar.xz
lots of cleaning up
-rw-r--r--AbacusActivity.py375
-rw-r--r--abacus_window.py115
2 files changed, 255 insertions, 235 deletions
diff --git a/AbacusActivity.py b/AbacusActivity.py
index 0a696f0..d30fb46 100644
--- a/AbacusActivity.py
+++ b/AbacusActivity.py
@@ -18,7 +18,7 @@ import gobject
import sugar
from sugar.activity import activity
-try: # 0.86+ toolbar widgets
+try: # 0.86+ toolbar widgets
from sugar.graphics.toolbarbox import ToolbarBox
HAS_TOOLBARBOX = True
except ImportError:
@@ -29,6 +29,7 @@ if HAS_TOOLBARBOX:
from sugar.activity.widgets import StopButton
from sugar.graphics.toolbarbox import ToolbarButton
from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics.radiotoolbutton import RadioToolButton
from sugar.graphics.menuitem import MenuItem
from sugar.graphics.icon import Icon
from sugar.datastore import datastore
@@ -37,68 +38,91 @@ from gettext import gettext as _
import locale
import logging
-_logger = logging.getLogger("abacus-activity")
+_logger = logging.getLogger('abacus-activity')
from abacus_window import Abacus, Custom, Suanpan, Soroban, Schety,\
Nepohualtzintzin, Binary, Hex, Decimal, Fractions,\
Caacupe, Cuisenaire
-def _button_factory(icon_name, tooltip, callback, toolbar,
+def _button_factory(icon_name, toolbar, callback, cb_arg=None, tooltip=None,
accelerator=None):
- """Factory for making toolbar buttons"""
- my_button = ToolButton( icon_name )
- my_button.set_tooltip(tooltip)
- my_button.props.sensitive = True
+ '''Factory for making toolbar buttons'''
+ button = ToolButton(icon_name)
+ if tooltip is not None:
+ button.set_tooltip(tooltip)
+ button.props.sensitive = True
if accelerator is not None:
- my_button.props.accelerator = accelerator
- my_button.connect('clicked', callback)
+ button.props.accelerator = accelerator
+ if cb_arg is None:
+ button.connect('clicked', callback)
+ else:
+ button.connect('clicked', cb_arg)
if hasattr(toolbar, 'insert'): # the main toolbar
- toolbar.insert(my_button, -1)
+ toolbar.insert(button, -1)
else: # or a secondary toolbar
- toolbar.props.page.insert(my_button, -1)
- my_button.show()
- return my_button
+ toolbar.props.page.insert(button, -1)
+ button.show()
+ return button
+
+
+def _radio_factory(icon_name, toolbar, callback, cb_arg=None,
+ tooltip=None, group=None):
+ ''' Add a radio button to a toolbar '''
+ button = RadioToolButton(group=group)
+ button.set_named_icon(icon_name)
+ if tooltip is not None:
+ button.set_tooltip(tooltip)
+ if cb_arg is None:
+ button.connect('clicked', callback)
+ else:
+ button.connect('clicked', callback, cb_arg)
+ if hasattr(toolbar, 'insert'): # the main toolbar
+ toolbar.insert(button, -1)
+ else: # or a secondary toolbar
+ toolbar.props.page.insert(button, -1)
+ button.show()
+ return button
-def _label_factory(label, toolbar):
- """ Factory for adding a label to a toolbar """
- my_label = gtk.Label(label)
- my_label.set_line_wrap(True)
- my_label.show()
- _toolitem = gtk.ToolItem()
- _toolitem.add(my_label)
- toolbar.insert(_toolitem, -1)
- _toolitem.show()
- return my_label
+def _label_factory(label_text, toolbar):
+ ''' Factory for adding a label to a toolbar '''
+ label = gtk.Label(label_text)
+ label.set_line_wrap(True)
+ label.show()
+ toolitem = gtk.ToolItem()
+ toolitem.add(label)
+ toolbar.insert(toolitem, -1)
+ toolitem.show()
+ return label
def _spin_factory(default, min, max, callback, toolbar):
- _spin_adj = gtk.Adjustment(default, min, max, 1, 32, 0)
- my_spin = gtk.SpinButton(_spin_adj, 0, 0)
- _spin_id = my_spin.connect('value-changed', callback)
- my_spin.set_numeric(True)
- my_spin.show()
- _toolitem = gtk.ToolItem()
- _toolitem.add(my_spin)
- toolbar.insert(_toolitem, -1)
- _toolitem.show()
- return my_spin
+ spin_adj = gtk.Adjustment(default, min, max, 1, 32, 0)
+ spin = gtk.SpinButton(spin_adj, 0, 0)
+ spin_id = spin.connect('value-changed', callback)
+ spin.set_numeric(True)
+ spin.show()
+ toolitem = gtk.ToolItem()
+ toolitem.add(spin)
+ toolbar.insert(toolitem, -1)
+ toolitem.show()
+ return spin
def _separator_factory(toolbar, expand=False, visible=True):
- """ add a separator to a toolbar """
- _separator = gtk.SeparatorToolItem()
- _separator.props.draw = visible
- _separator.set_expand(expand)
- toolbar.insert(_separator, -1)
- _separator.show()
+ ''' add a separator to a toolbar '''
+ separator = gtk.SeparatorToolItem()
+ separator.props.draw = visible
+ separator.set_expand(expand)
+ toolbar.insert(separator, -1)
+ separator.show()
class AbacusActivity(activity.Activity):
def __init__(self, handle):
- """ Initiate activity. """
+ ''' Initiate activity. '''
super(AbacusActivity, self).__init__(handle)
# no sharing
@@ -139,8 +163,8 @@ class AbacusActivity(activity.Activity):
_separator_factory(toolbox.toolbar, False, True)
- _button_factory("edit-delete", _('Reset'),
- self._reset_cb, toolbox.toolbar)
+ _button_factory('edit-delete', toolbox.toolbar,
+ self._reset_cb, tooltip=_('Reset'))
_separator_factory(toolbox.toolbar, True, False)
@@ -161,8 +185,8 @@ class AbacusActivity(activity.Activity):
toolbox.add_toolbar( _('Custom'), custom_toolbar )
toolbox.add_toolbar(_('Edit'), edit_toolbar)
- _button_factory("edit-delete", _('Reset'),
- self._reset_cb, edit_toolbar)
+ _button_factory('edit-delete', edit_toolbar,
+ self._reset_cb, tooltip=_('Reset'))
_separator_factory(edit_toolbar, False, True)
@@ -170,88 +194,108 @@ class AbacusActivity(activity.Activity):
# no sharing
if hasattr(toolbox, 'share'):
- toolbox.share.hide()
+ toolbox.share.hide()
elif hasattr(toolbox, 'props'):
toolbox.props.visible = False
# TRANS: simple decimal abacus
- self.decimal = _button_factory("decimal-off", _('Decimal'),
- self._decimal_cb, abacus_toolbar)
+ self.decimal = _radio_factory('decimal', abacus_toolbar,
+ self._radio_cb, cb_arg='decimal',
+ tooltip=_('Decimal'),
+ group=None)
# TRANS: http://en.wikipedia.org/wiki/Soroban (Japanese abacus)
- self.japanese = _button_factory("soroban-off", _('Soroban'),
- self._japanese_cb, abacus_toolbar)
+ self.japanese = _radio_factory('soroban', abacus_toolbar,
+ self._radio_cb, cb_arg='japanese',
+ tooltip=_('Soroban'),
+ group=self.decimal)
# TRANS: http://en.wikipedia.org/wiki/Suanpan (Chinese abacus)
- self.chinese = _button_factory("suanpan-on", _('Suanpan'),
- self._chinese_cb, abacus_toolbar)
+ self.chinese = _radio_factory('suanpan', abacus_toolbar,
+ self._radio_cb, cb_arg='chinese',
+ tooltip=_('Suanpan'),
+ group=self.decimal)
_separator_factory(abacus_toolbar)
- self.mayan = _button_factory("nepohualtzintzin-off",
# TRANS: http://en.wikipedia.org/wiki/Abacus#Native_American_abaci
- _('Nepohualtzintzin'),
- self._mayan_cb, abacus_toolbar)
+ self.mayan = _radio_factory('nepohualtzintzin', abacus_toolbar,
+ self._radio_cb, cb_arg='mayan',
+ tooltip=_('Nepohualtzintzin'),
+ group=self.decimal)
# TRANS: hexidecimal abacus
- self.hex = _button_factory("hexadecimal-off", _('Hexadecimal'),
- self._hex_cb, abacus_toolbar)
+ self.hex = _radio_factory('hexadecimal', abacus_toolbar,
+ self._radio_cb, cb_arg='hex',
+ tooltip=_('Hexadecimal'),
+ group=self.decimal)
# TRANS: binary abacus
- self.binary = _button_factory("binary-off", _('Binary'),
- self._binary_cb, abacus_toolbar)
+ self.binary = _radio_factory('binary', abacus_toolbar,
+ self._radio_cb, cb_arg='binary',
+ tooltip=_('Binary'),
+ group=self.decimal)
_separator_factory(abacus_toolbar)
# TRANS: http://en.wikipedia.org/wiki/Abacus#Russian_abacus
- self.russian = _button_factory("schety-off", _('Schety'),
- self._russian_cb, abacus_toolbar)
+ self.russian = _radio_factory('schety', abacus_toolbar,
+ self._radio_cb, cb_arg='russian',
+ tooltip=_('Schety'),
+ group=self.decimal)
# TRANS: abacus for adding fractions
- self.fraction = _button_factory("fraction-off", _('Fraction'),
- self._fraction_cb, abacus_toolbar)
+ self.fraction = _radio_factory('fraction', abacus_toolbar,
+ self._radio_cb, cb_arg='fraction',
+ tooltip=_('Fraction'),
+ group=self.decimal)
# TRANS: Abacus invented by teachers in Caacupé, Paraguay
- self.caacupe = _button_factory("caacupe-off", _('Caacupé'),
- self._caacupe_cb, abacus_toolbar)
+ self.caacupe = _radio_factory('caacupe', abacus_toolbar,
+ self._radio_cb, cb_arg='caacupe',
+ tooltip=_('Caacupé'),
+ group=self.decimal)
_separator_factory(abacus_toolbar)
# TRANS: Cuisenaire Rods
- self.cuisenaire = _button_factory("cuisenaire-off", _('Rods'),
- self._cuisenaire_cb, abacus_toolbar)
+ self.cuisenaire = _radio_factory('cuisenaire', abacus_toolbar,
+ self._radio_cb,
+ cb_arg='cuisenaire',
+ tooltip=_('Rods'), group=self.decimal)
# TRANS: Number of rods on the abacus
- self._rods_label = _label_factory(_("Rods:")+" ", custom_toolbar)
+ self._rods_label = _label_factory(_('Rods:') + ' ', custom_toolbar)
self._rods_spin = _spin_factory(15, 1, 20, self._rods_spin_cb,
custom_toolbar)
# TRANS: Number of beads in the top section of the abacus
- self._top_label = _label_factory(_("Top:")+" ", custom_toolbar)
+ self._top_label = _label_factory(_('Top:') + ' ', custom_toolbar)
self._top_spin = _spin_factory(2, 0, 4, self._top_spin_cb,
custom_toolbar)
# TRANS: Number of beads in the bottom section of the abacus
- self._bottom_label = _label_factory(_("Bottom:")+" ",
+ self._bottom_label = _label_factory(_('Bottom:') + ' ',
custom_toolbar)
self._bottom_spin = _spin_factory(5, 1, 20, self._bottom_spin_cb,
custom_toolbar)
# TRANS: Scale factor between bottom and top beads
- self._value_label = _label_factory(_("Factor:")+" ", custom_toolbar)
+ self._value_label = _label_factory(_('Factor:') + ' ', custom_toolbar)
self._value_spin = _spin_factory(5, 1, 20, self._value_spin_cb,
custom_toolbar)
# TRANS: Scale factor between rods
- self._base_label = _label_factory(_("Base:")+" ", custom_toolbar)
+ self._base_label = _label_factory(_('Base:') + ' ', custom_toolbar)
self._base_spin = _spin_factory(10, 1, 24, self._base_spin_cb,
custom_toolbar)
_separator_factory(custom_toolbar, False, False)
- self.custom = _button_factory("new-abacus", _('Custom'),
- self._custom_cb, custom_toolbar)
+ self.custom = _button_factory('new-abacus', custom_toolbar,
+ self._custom_cb,
+ tooltip=_('Custom'))
- copy = _button_factory('edit-copy', _('Copy'), self._copy_cb,
- edit_toolbar, accelerator='<Ctrl>c')
- paste = _button_factory('edit-paste', _('Paste'), self._paste_cb,
- edit_toolbar, accelerator='<Ctrl>v')
+ copy = _button_factory('edit-copy', edit_toolbar, self._copy_cb,
+ tooltip=_('Copy'), accelerator='<Ctrl>c')
+ paste = _button_factory('edit-paste', edit_toolbar, self._paste_cb,
+ tooltip=_('Paste'), accelerator='<Ctrl>v')
self.toolbox.show()
@@ -259,6 +303,8 @@ class AbacusActivity(activity.Activity):
# start with abacus toolbar expanded
abacus_toolbar_button.set_expanded(True)
+ self.chinese.set_active(True)
+
# Create a canvas
canvas = gtk.DrawingArea()
canvas.set_size_request(gtk.gdk.screen_width(),
@@ -282,83 +328,45 @@ class AbacusActivity(activity.Activity):
if 'base' in self.metadata:
self._base_spin.set_value(int(self.metadata['base']))
if 'abacus' in self.metadata:
+ # Default is Chinese
_logger.debug('restoring %s', self.metadata['abacus'])
- if self.metadata['abacus'] == 'suanpan':
- self._chinese_cb()
- elif self.metadata['abacus'] == 'soroban':
- self._japanese_cb()
+ if self.metadata['abacus'] == 'soroban':
+ self._select_abacus('japanese')
elif self.metadata['abacus'] == 'schety':
- self._russian_cb()
+ self._select_abacus('russian')
elif self.metadata['abacus'] == 'nepohualtzintzin':
- self._mayan_cb()
+ self._select_abacus('mayan')
elif self.metadata['abacus'] == 'binary':
- self._binary_cb()
+ self._select_abacus('binary')
elif self.metadata['abacus'] == 'hexadecimal':
- self._hex_cb()
+ self._select_abacus('hex')
elif self.metadata['abacus'] == 'fraction':
- self._fraction_cb()
+ self._select_abacus('fraction')
elif self.metadata['abacus'] == 'caacupe':
- self._caacupe_cb()
+ self._select_abacus('caacupe')
elif self.metadata['abacus'] == 'cuisenaire':
- self._cuisenaire_cb()
+ self._select_abacus('cuisenaire')
elif self.metadata['abacus'] == 'decimal':
- self._decimal_cb()
+ self._select_abacus('decimal')
elif self.metadata['abacus'] == 'custom':
self._custom_cb()
- else:
- self._chinese_cb()
if 'value' in self.metadata:
_logger.debug('restoring value %s', self.metadata['value'])
self.abacus.mode.set_value(self.metadata['value'])
self.abacus.mode.label(self.abacus.generate_label())
- def _all_off(self):
- """ Set all icons to 'off' and hide all of the abacuses """
- self.chinese.set_icon("suanpan-off")
- self.japanese.set_icon("soroban-off")
- self.russian.set_icon("schety-off")
- self.mayan.set_icon("nepohualtzintzin-off")
- self.binary.set_icon("binary-off")
- self.hex.set_icon("hexadecimal-off")
- self.fraction.set_icon("fraction-off")
- self.caacupe.set_icon("caacupe-off")
- self.cuisenaire.set_icon("cuisenaire-off")
- self.decimal.set_icon("decimal-off")
- if self.abacus.chinese is not None:
- self.abacus.chinese.hide()
- if self.abacus.japanese is not None:
- self.abacus.japanese.hide()
- if self.abacus.russian is not None:
- self.abacus.russian.hide()
- if self.abacus.mayan is not None:
- self.abacus.mayan.hide()
- if self.abacus.binary is not None:
- self.abacus.binary.hide()
- if self.abacus.hex is not None:
- self.abacus.hex.hide()
- if self.abacus.fraction is not None:
- self.abacus.fraction.hide()
- if self.abacus.decimal is not None:
- self.abacus.decimal.hide()
- if self.abacus.caacupe is not None:
- self.abacus.caacupe.hide()
- if self.abacus.cuisenaire is not None:
- self.abacus.cuisenaire.hide()
- if self.abacus.custom is not None:
- self.abacus.custom.hide()
+ def _radio_cb(self, button, abacus):
+ self._select_abacus(abacus)
def _reset_cb(self, button=None):
self.abacus.mode.reset_abacus()
self.abacus.mode.label(self.abacus.generate_label())
- def _select_abacus(self, button, icon, abacus):
- """ Display the selected abacus; hide the others """
- self._all_off()
- if button is not None:
- button.set_icon(icon)
- self.abacus.mode = abacus
- self.abacus.mode.show()
- _logger.debug("Setting mode to %s" % (self.abacus.mode.name))
+ def _select_abacus(self, abacus):
+ ''' Display the selected abacus; hide the others '''
+ if not hasattr(self, 'abacus'):
+ return
+ self.abacus.select_abacus(abacus)
def _rods_spin_cb(self, button=None):
return
@@ -376,7 +384,7 @@ class AbacusActivity(activity.Activity):
return
def _custom_cb(self, button=None):
- """ Display the custom abacus; hide the others """
+ ''' Display the custom abacus; hide the others '''
value = float(self.abacus.mode.value(count_beads=False))
if self.abacus.custom is not None:
self.abacus.custom.hide()
@@ -386,101 +394,13 @@ class AbacusActivity(activity.Activity):
self._bottom_spin.get_value_as_int(),
self._value_spin.get_value_as_int(),
self._base_spin.get_value_as_int())
- self._select_abacus(None, None, self.abacus.custom)
+ self._select_abacus(self.abacus.custom)
self.abacus.mode.reset_abacus()
self.abacus.mode.set_value_from_number(value)
self.abacus.mode.label(self.abacus.generate_label())
- def _chinese_cb(self, button=None):
- """ Display the suanpan; hide the others """
- value = float(self.abacus.mode.value(count_beads=False))
- if self.abacus.chinese is None:
- self.abacus.chinese = Suanpan(self.abacus)
- self._select_abacus(self.chinese, self.abacus.chinese.name+"-on",
- self.abacus.chinese)
- self.abacus.mode.set_value_from_number(value)
- self.abacus.mode.label(self.abacus.generate_label())
-
- def _japanese_cb(self, button=None):
- """ Display the soroban; hide the others """
- value = float(self.abacus.mode.value(count_beads=False))
- if self.abacus.japanese is None:
- self.abacus.japanese = Soroban(self.abacus)
- self._select_abacus(self.japanese, self.abacus.japanese.name+"-on",
- self.abacus.japanese)
- self.abacus.mode.set_value_from_number(value)
- self.abacus.mode.label(self.abacus.generate_label())
-
- def _russian_cb(self, button=None):
- """ Display the schety; hide the others """
- if self.abacus.russian is None:
- self.abacus.russian = Schety(self.abacus)
- self._select_abacus(self.russian, self.abacus.russian.name+"-on",
- self.abacus.russian)
-
- def _mayan_cb(self, button=None):
- """ Display the nepohualtzintzin; hide the others """
- value = float(self.abacus.mode.value(count_beads=False))
- if self.abacus.mayan is None:
- self.abacus.mayan = Nepohualtzintzin(self.abacus)
- self._select_abacus(self.mayan, self.abacus.mayan.name+"-on",
- self.abacus.mayan)
- self.abacus.mode.set_value_from_number(value)
- self.abacus.mode.label(self.abacus.generate_label())
-
- def _binary_cb(self, button=None):
- """ Display the binary; hide the others """
- value = float(self.abacus.mode.value(count_beads=False))
- if self.abacus.binary is None:
- self.abacus.binary = Binary(self.abacus)
- self._select_abacus(self.binary, self.abacus.binary.name+"-on",
- self.abacus.binary)
- self.abacus.mode.set_value_from_number(value)
- self.abacus.mode.label(self.abacus.generate_label())
-
- def _hex_cb(self, button=None):
- """ Display the hex; hide the others """
- value = float(self.abacus.mode.value(count_beads=False))
- if self.abacus.hex is None:
- self.abacus.hex = Hex(self.abacus)
- self._select_abacus(self.hex, self.abacus.hex.name+"-on",
- self.abacus.hex)
- self.abacus.mode.set_value_from_number(value)
- self.abacus.mode.label(self.abacus.generate_label())
-
- def _decimal_cb(self, button=None):
- """ Display the decimal; hide the others """
- value = float(self.abacus.mode.value(count_beads=False))
- if self.abacus.decimal is None:
- self.abacus.decimal = Decimal(self.abacus)
- self._select_abacus(self.decimal, self.abacus.decimal.name+"-on",
- self.abacus.decimal)
- self.abacus.mode.set_value_from_number(value)
- self.abacus.mode.label(self.abacus.generate_label())
-
- def _fraction_cb(self, button=None):
- """ Display the fraction; hide the others """
- if self.abacus.fraction is None:
- self.abacus.fraction = Fractions(self.abacus)
- self._select_abacus(self.fraction, self.abacus.fraction.name+"-on",
- self.abacus.fraction)
-
- def _caacupe_cb(self, button=None):
- """ Display the Caacupe; hide the others """
- if self.abacus.caacupe is None:
- self.abacus.caacupe = Caacupe(self.abacus)
- self._select_abacus(self.caacupe, self.abacus.caacupe.name+"-on",
- self.abacus.caacupe)
-
- def _cuisenaire_cb(self, button=None):
- """ Display Cuisenaire-like rods; hide the others """
- if self.abacus.cuisenaire is None:
- self.abacus.cuisenaire = Cuisenaire(self.abacus)
- self._select_abacus(self.cuisenaire, self.abacus.cuisenaire.name+"-on",
- self.abacus.cuisenaire)
-
def _copy_cb(self, arg=None):
- """ Copy a number to the clipboard from the active abacus. """
+ ''' Copy a number to the clipboard from the active abacus. '''
clipBoard = gtk.Clipboard()
text = self.abacus.generate_label(sum_only=True)
if text is not None:
@@ -488,7 +408,7 @@ class AbacusActivity(activity.Activity):
return
def _paste_cb(self, arg=None):
- """ Paste a number from the clipboard to the active abacus. """
+ ''' Paste a number from the clipboard to the active abacus. '''
clipBoard = gtk.Clipboard()
text = clipBoard.wait_for_text()
if text is not None:
@@ -501,8 +421,8 @@ class AbacusActivity(activity.Activity):
return
def write_file(self, file_path):
- """ Write the bead positions to the Journal """
- _logger.debug("Saving current abacus to Journal: %s %s" % (
+ ''' Write the bead positions to the Journal '''
+ _logger.debug('Saving current abacus to Journal: %s %s' % (
self.abacus.mode.name, self.abacus.mode.value(True)))
self.metadata['abacus'] = self.abacus.mode.name
self.metadata['value'] = self.abacus.mode.value(True)
@@ -511,4 +431,3 @@ class AbacusActivity(activity.Activity):
self.metadata['bottom'] = str(self._bottom_spin.get_value_as_int())
self.metadata['factor'] = str(self._value_spin.get_value_as_int())
self.metadata['base'] = str(self._base_spin.get_value_as_int())
-
diff --git a/abacus_window.py b/abacus_window.py
index 580d89b..e205d68 100644
--- a/abacus_window.py
+++ b/abacus_window.py
@@ -621,7 +621,6 @@ class Abacus():
_svg_str_to_pixbuf(background_svg))
background.set_layer(1)
- self.chinese = Suanpan(self)
self.japanese = None
self.russian = None
self.mayan = None
@@ -633,8 +632,60 @@ class Abacus():
self.cuisenaire = None
self.custom = None
- self.chinese.show()
+ self.chinese = Suanpan(self)
self.mode = self.chinese
+ self.mode.show()
+
+ def select_abacus(self, abacus):
+ self.mode.hide()
+ value = int(float(self.mode.value()))
+ if abacus == 'chinese':
+ if self.chinese is None:
+ self.chinese = Suanpan(self)
+ self.mode = self.chinese
+ elif abacus == 'japanese':
+ if self.japanese is None:
+ self.japanese = Soroban(self)
+ self.mode = self.japanese
+ elif abacus == 'decimal':
+ if self.decimal is None:
+ self.decimal = Decimal(self)
+ self.mode = self.decimal
+ elif abacus == 'mayan':
+ if self.mayan is None:
+ self.mayan = Nepohualtzintzin(self)
+ self.mode = self.mayan
+ elif abacus == 'hex':
+ if self.hex is None:
+ self.hex = Hex(self)
+ self.mode = self.hex
+ elif abacus == 'binary':
+ if self.binary is None:
+ self.binary = Binary(self)
+ self.mode = self.binary
+ elif abacus == 'custom':
+ if self.custom is None:
+ self.custom = Custom(self)
+ self.mode = self.custom
+ elif abacus == 'russian':
+ if self.russian is None:
+ self.russian = Schety(self)
+ self.mode = self.russian
+ elif abacus == 'fraction':
+ if self.fraction is None:
+ self.fraction = Fractions(self)
+ self.mode = self.fraction
+ elif abacus == 'caacupe':
+ if self.caacupe is None:
+ self.caacupe = Caacupe(self)
+ self.mode = self.caacupe
+ elif abacus == 'cuisenaire':
+ if self.cuisenaire is None:
+ self.cuisenaire = Cuisenaire(self)
+ self.mode = self.cuisenaire
+ self.mode.set_value_from_number(value)
+ self.mode.show()
+ _logger.debug('Setting mode to %s' % (self.mode.name))
def _button_press_cb(self, win, event):
''' Callback to handle the button presses '''
@@ -975,18 +1026,15 @@ class AbacusGeneric():
def set_value(self, string):
''' Set abacus to value in string '''
- _logger.debug('restoring %s: [%s]' % (self.name, string))
-
value = string.split()
# Move the beads to correspond to column values.
try:
for i, rod in enumerate(self.rods):
- _logger.debug('setting rod %d to value %d', i, value[i])
rod.set_value(int(value[i]))
except IndexError:
_logger.debug('bad saved string length %s (%d != 2 * %d)',
string, len(string), self.num_rods)
- except TypeError:
+ except ValueError:
_logger.debug('bad saved string type %s (%s)',
string, str(value[i]))
@@ -1038,7 +1086,6 @@ class AbacusGeneric():
def label(self, string):
''' Label the crossbar with the string. (Used with self.value) '''
self.bar.set_label(string)
- return
def move_mark(self, dx):
''' Move indicator horizontally across the top of the frame. '''
@@ -1083,6 +1130,12 @@ class Custom(AbacusGeneric):
class Nepohualtzintzin(AbacusGeneric):
''' A Mayan abacus '''
+ def __init__(self, abacus):
+ ''' Specify parameters that define the abacus '''
+ self.abacus = abacus
+ self.set_parameters()
+ self.create()
+
def set_parameters(self):
''' Specify parameters that define the abacus '''
self.name = 'nepohualtzintzin'
@@ -1096,6 +1149,12 @@ class Nepohualtzintzin(AbacusGeneric):
class Suanpan(AbacusGeneric):
''' A Chinese abacus '''
+ def __init__(self, abacus):
+ ''' Specify parameters that define the abacus '''
+ self.abacus = abacus
+ self.set_parameters()
+ self.create()
+
def set_parameters(self):
''' Create a Chinese abacus: 15 by (5,2). '''
self.name = 'suanpan'
@@ -1152,6 +1211,12 @@ class Soroban(AbacusGeneric):
class Hex(AbacusGeneric):
''' A hexadecimal abacus '''
+ def __init__(self, abacus):
+ ''' Specify parameters that define the abacus '''
+ self.abacus = abacus
+ self.set_parameters()
+ self.create()
+
def set_parameters(self):
''' create a hexadecimal abacus: 15 by (7,1) '''
self.name = 'hexadecimal'
@@ -1165,6 +1230,12 @@ class Hex(AbacusGeneric):
class Decimal(AbacusGeneric):
''' A decimal abacus '''
+ def __init__(self, abacus):
+ ''' Specify parameters that define the abacus '''
+ self.abacus = abacus
+ self.set_parameters()
+ self.create()
+
def set_parameters(self):
''' create a decimal abacus: 10 by (10,0) '''
self.name = 'decimal'
@@ -1202,6 +1273,12 @@ class Decimal(AbacusGeneric):
class Binary(AbacusGeneric):
''' A binary abacus '''
+ def __init__(self, abacus):
+ ''' Specify parameters that define the abacus '''
+ self.abacus = abacus
+ self.set_parameters()
+ self.create()
+
def set_parameters(self):
''' create a Binary abacus: 15 by (1,0) '''
self.name = 'binary'
@@ -1215,6 +1292,12 @@ class Binary(AbacusGeneric):
class Schety(AbacusGeneric):
''' A Russian abacus '''
+ def __init__(self, abacus):
+ ''' Specify parameters that define the abacus '''
+ self.abacus = abacus
+ self.set_parameters()
+ self.create()
+
def set_parameters(self):
''' Create a Russian abacus: 15 by 10 (with one rod of 4 beads). '''
self.name = 'schety'
@@ -1255,6 +1338,12 @@ class Schety(AbacusGeneric):
class Fractions(Schety):
''' Inherit from Russian abacus. '''
+ def __init__(self, abacus):
+ ''' Specify parameters that define the abacus '''
+ self.abacus = abacus
+ self.set_parameters()
+ self.create()
+
def set_parameters(self):
''' Create an abacus with fractions: 15 by 10 (with 1/2, 1/3. 1/4,
1/5, 1/6, 1/8, 1/9, 1/10, 1/12). '''
@@ -1300,6 +1389,12 @@ class Fractions(Schety):
class Caacupe(Fractions):
''' Inherit from Fraction abacus. '''
+ def __init__(self, abacus):
+ ''' Specify parameters that define the abacus '''
+ self.abacus = abacus
+ self.set_parameters()
+ self.create()
+
def set_parameters(self):
''' Create an abacus with fractions: 15 by 10 (with 1/2, 1/3. 1/4,
1/5, 1/6, 1/8, 1/9, 1/10, 1/12). '''
@@ -1345,6 +1440,12 @@ class Caacupe(Fractions):
class Cuisenaire(Caacupe):
''' Inherit from Caacupe abacus. '''
+ def __init__(self, abacus):
+ ''' Specify parameters that define the abacus '''
+ self.abacus = abacus
+ self.set_parameters()
+ self.create()
+
def set_parameters(self):
''' Create an abacus with fractions: 10 by 10 (with 1/1, 1/2, 1/3. 1/4,
1/5, 1/6, 1/7, 1/8, 1/9, 1/10). '''