Activities/Abacus: Difference between revisions
| Line 164: | Line 164: | ||
Abacus is under GPL 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. | Abacus is under GPL 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 | Most changes can be confined to three modules: <code>AbacusActivity.py</code>, <code>abacus.py</code> and <code>abacus_window.py</code>. The former define the Sugar and GNOME toolbars; 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 <code>abacus.py</code>: | For instance, to add a menu item such as 'Reset' you would do the following in <code>abacus.py</code>: | ||
* Add these lines to the menu items list: | |||
menu_items = gtk.MenuItem(_("Reset")) | menu_items = gtk.MenuItem(_("Reset")) | ||
menu.append(menu_items) | menu.append(menu_items) | ||
menu_items.connect("activate", self._reset) | menu_items.connect("activate", self._reset) | ||
* The _reset() method is trivial: | |||
def _reset(self, event, data=None): | def _reset(self, event, data=None): | ||
""" Reset """ | """ Reset """ | ||
self.abacus.mode.reset_abacus() | self.abacus.mode.reset_abacus() | ||
This will complete the changes in the <code>abacus.py</code>. | Similarly, you can add another button to the Sugar toolbar in <code>AbacusActivity.py</code>: | ||
* Add these lines to the toolbar block: | |||
# Reset the beads on the abacus to the initial cleared position | |||
self.reset_button = ToolButton( "reset" ) | |||
self.reset_button.set_tooltip(_('Reset')) | |||
self.reset_button.props.sensitive = True | |||
self.reset_button.connect('clicked', self._reset_button_cb) | |||
toolbar_box.toolbar.insert(self.reset_button, -1) | |||
self.reset_button.show() | |||
* The _reset_button_cb() method is trivial: | |||
def _reset_button_cb(self, event, data=None): | |||
""" Reset the beads on the abacus to the initial cleared position """ | |||
self.abacus.mode.reset_abacus() | |||
* You'll have to create an icon for the button (<code>reset.svg</code>) and put it into the <code>icon</code> subdirectory of the bundle. | |||
This will complete the changes in the <code>abacus.py</code>. The method <code>reset_abacus()</code> will have to be defined for each abacus in the <code>abacus_window.py</code>. This can be done by creating that method in the <code>AbacusGeneric</code> class used by all the varieties of abacus. The method may have to be overridden in some abacus subclasses for customization reasons. For instance, <code>reset_abacus()</code> was defined in <code>AbacusGeneric</code> class and then overridden in <code>Schety</code>. | |||
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 <code>abacus_window.py</code>: | 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 <code>abacus_window.py</code>: | ||