Changes

Jump to navigation Jump to search
260 bytes removed ,  11:50, 10 June 2010
added a new section titled Modifying Abacus
Line 162: Line 162:     
== Modifying Abacus ==
 
== Modifying Abacus ==
Turtle Art is under the MIT license. You are free to use it and learn with it. You are also encourage to modify it to suit your needs or just for a further opportunity to learn.
+
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.
   −
Much of the motivation behind the Version 0.83 refactoring of the code was to make it easier for you to make changes. Most changes can be confined to two modules: taconstants.py and talogo.py. The former defines the blocks and palettes; the latter defines what code is executed by a block.
+
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.
   −
taconstants.py contains the constants that by-in-large determine the behavior of Turtle Art. Notably, the block palettes are defined below. If you want to add a new block to Turtle Art, it is generally a matter of modifying some tables below and then adding the primitive to talogo.py. For example, if we want to add a new turtle command, 'uturn', we'd make the following changes:
+
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)
   −
(1) We'd add 'uturn' to the PALETTES list of lists:
+
(2)  The _reset() method can be coded as follows.
 +
    def _reset(self, event, data=None):
 +
        """ Reset """
 +
        self.abacus.mode.reset_abacus()
   −
  PALETTES = [['forward', 'back', 'clean', 'left', 'right', 'show',
+
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.
              'seth', 'setxy', 'heading', 'xcor', 'ycor', 'setscale',
  −
              'arc', 'scale', 'left', 'top', 'right', 'bottom', 'uturn'],
  −
            ['penup','pendown', 'setpensize', 'fillscreen', 'pensize',...
     −
(2) Then we'd add it to one of the block-style definitions. Since it takes
+
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:
no arguments, we'd add it here:
+
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
   −
BASIC_STYLE = ['clean', 'penup', 'pendown', 'stack1', 'stack2', 'vspace',
  −
    'hideblocks', 'showblocks', 'clearheap', 'printheap', 'kbinput', 'uturn']
  −
  −
(3) Then we give it a name (Note the syntax _('string to be
  −
translated') used by the language-internationalization system; also
  −
note that the name is an array, as some blocks contain multiple
  −
strings.):
  −
  −
BLOCK_NAMES = {
  −
...
  −
    'uturn':[_('u-turn')],
  −
...
  −
              }
  −
  −
(4) and a help-menu entry:
  −
  −
HELP_STRINGS = {
  −
...
  −
    'uturn':_('change the heading of the turtle 180 degrees'),
  −
...
  −
              }
  −
  −
(5) Next, we need to define it as a primitive for the Logo command
  −
parser (generally just the same name):
      
==Discussion==
 
==Discussion==
4

edits

Navigation menu