Activities/Abacus: Difference between revisions
added a new section titled Modifying Abacus |
|||
| Line 162: | Line 162: | ||
== Modifying Abacus == | == Modifying Abacus == | ||
Abacus is under GNU license. You are free to use it and learn with it. You are also encouraged to modify it to suit your needs or just for a further opportunity to learn. | |||
Most changes can be confined to two modules: abacus.py and abacus_window.py. The former defines the menu to work from fedora; the latter defines what code is executed by each type of abacus. | |||
For instance, to add a menu item such as 'Reset' you would do the following in abacus.py: | |||
(1) into the menu items list add | |||
menu_items = gtk.MenuItem(_("Reset")) | |||
menu.append(menu_items) | |||
menu_items.connect("activate", self._reset) | |||
( | (2) The _reset() method can be coded as follows. | ||
def _reset(self, event, data=None): | |||
""" Reset """ | |||
self.abacus.mode.reset_abacus() | |||
This will complete the changes in the abacus.py. The method reset_abacus() will have to be defined for each abacus in the abacus_window.py. This can be done by creating that method in the Generic class used by all the varieties of abacus. The method may have to be overridden in some abacus subclasses for customization reasons. For instance, reset_abacus was defined in AbacusGeneric class and then overridden in Schety. | |||
(2) | If the changes involve modifying the graphics, then other methods may need to be modified as well. For instance, in order to introduce a reset button that can be clicked to reset the bead positions to the beginning, the following methods had to be modified -- all in abacus_window.py: | ||
1) in the class Abacus, methods _button_press_cb() to activate reset button, | |||
2) in the class AbacusGeneric, method create() to create the graphics for reset button, | |||
3) methods hide() and show() to make the button visible | |||
==Discussion== | ==Discussion== | ||