Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt
diff options
context:
space:
mode:
Diffstat (limited to 'TurtleArt')
-rw-r--r--TurtleArt/tabasics.py2
-rw-r--r--TurtleArt/tablock.py42
-rw-r--r--TurtleArt/taconstants.py36
-rw-r--r--TurtleArt/talogo.py9
-rw-r--r--TurtleArt/tapalette.py97
-rw-r--r--TurtleArt/tautils.py38
-rw-r--r--TurtleArt/tawindow.py171
7 files changed, 204 insertions, 191 deletions
diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py
index e9d01e9..97b80f7 100644
--- a/TurtleArt/tabasics.py
+++ b/TurtleArt/tabasics.py
@@ -154,7 +154,7 @@ turtle'))
default=90,
help_string=_('turns turtle counterclockwise (angle \
in degrees)'))
- self.tw.lc.def_prim('right', 1,
+ self.tw.lc.def_prim('left', 1,
lambda self, x: primitive_dictionary['right'](-x))
palette.add_block('right',
diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py
index 3f4e839..2b485d8 100644
--- a/TurtleArt/tablock.py
+++ b/TurtleArt/tablock.py
@@ -23,10 +23,10 @@ import gtk
from gettext import gettext as _
-from taconstants import EXPANDABLE, EXPANDABLE_BLOCKS, EXPANDABLE_ARGS, \
- PRIMITIVES, OLD_NAMES, BLOCK_SCALE, BLOCK_NAMES, CONTENT_BLOCKS, \
- PALETTES, COLORS, BLOCK_STYLES, STANDARD_STROKE_WIDTH, BOX_COLORS, \
- GRADIENT_COLOR, CONSTANTS
+from taconstants import CONSTANTS, EXPANDABLE, EXPANDABLE_ARGS, OLD_NAMES, \
+ STANDARD_STROKE_WIDTH, BLOCK_SCALE, BOX_COLORS, GRADIENT_COLOR
+from tapalette import palette_blocks, block_colors, expandable_blocks, \
+ content_blocks, block_names, block_primitives, block_styles
from tasprite_factory import SVG, svg_str_to_pixbuf
import sprites
@@ -202,8 +202,8 @@ class Block:
break
self._new_block_from_factory(sprite_list, x, y, copy_block)
- if name in PRIMITIVES:
- self.primitive = PRIMITIVES[self.name]
+ if name in block_primitives:
+ self.primitive = block_primitives[self.name]
self.block_list.append_to_list(self)
@@ -211,7 +211,7 @@ class Block:
""" Can this block be expanded? """
if self.name in EXPANDABLE:
return True
- if self.name in EXPANDABLE_BLOCKS:
+ if self.name in expandable_blocks:
return True
if self.name in EXPANDABLE_ARGS:
return True
@@ -221,7 +221,7 @@ class Block:
""" Is it safe to clone this block? """
if self.expandable():
return False
- if self.name in BLOCK_STYLES['box-style']:
+ if self.name in block_styles['box-style']:
return False
if self.name in ['sandwichtop', 'sandwichtop_no_label']:
return False
@@ -404,11 +404,11 @@ class Block:
else:
self._set_labels(i, str(v))
elif self.type == 'block' and self.name in CONSTANTS:
- self._set_labels(0, BLOCK_NAMES[self.name][0] + ' = ' + \
+ self._set_labels(0, block_names[self.name][0] + ' = ' + \
str(CONSTANTS[self.name]))
- elif self.name in BLOCK_NAMES:
- for i, n in enumerate(BLOCK_NAMES[self.name]):
+ elif self.name in block_names:
+ for i, n in enumerate(block_names[self.name]):
self._set_labels(i, n)
if copy_block is None:
@@ -420,21 +420,21 @@ class Block:
self.svg.margins[2], self.svg.margins[3])
def _set_label_attributes(self):
- if self.name in CONTENT_BLOCKS:
+ if self.name in content_blocks:
n = len(self.values)
if n == 0:
n = 1 # Force a scale to be set, even if there is no value.
else:
- if self.name in BLOCK_NAMES:
- n = len(BLOCK_NAMES[self.name])
+ if self.name in block_names:
+ n = len(block_names[self.name])
else:
debug_output('WARNING: unknown block name %s' % (self.name))
n = 0
for i in range(n):
- if self.name in BLOCK_STYLES['compare-porch-style']:
+ if self.name in block_styles['compare-porch-style']:
self.spr.set_label_attributes(int(self._font_size[0] + 0.5),
True, 'center', 'bottom', i)
- elif self.name in BLOCK_STYLES['number-style-porch']:
+ elif self.name in block_styles['number-style-porch']:
self.spr.set_label_attributes(int(self._font_size[0] + 0.5),
True, 'right', 'bottom', i)
elif i == 1: # top
@@ -457,8 +457,8 @@ class Block:
self._bottom = 0
self.svg.set_stroke_width(STANDARD_STROKE_WIDTH)
self.svg.clear_docks()
- for k in BLOCK_STYLES.keys():
- if self.name in BLOCK_STYLES[k]:
+ for k in block_styles.keys():
+ if self.name in block_styles[k]:
if type(self.block_methods[k]) == type([]):
self.block_methods[k][0](svg, self.block_methods[k][1],
self.block_methods[k][2])
@@ -470,9 +470,9 @@ class Block:
if self.name in BOX_COLORS:
self.colors = BOX_COLORS[self.name]
else:
- for p in range(len(PALETTES)):
- if self.name in PALETTES[p]:
- self.colors = COLORS[p]
+ for p in range(len(palette_blocks)):
+ if self.name in palette_blocks[p]:
+ self.colors = block_colors[p]
self.svg.set_colors(self.colors)
def _make_basic_style(self, svg, extend_x=0, extend_y=0):
diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py
index 53e628a..7138f84 100644
--- a/TurtleArt/taconstants.py
+++ b/TurtleArt/taconstants.py
@@ -35,14 +35,6 @@ TAB_LAYER = 710
STATUS_LAYER = 900
TOP_LAYER = 1000
-#
-# Block-palette categories
-#
-
-PALETTE_NAMES = []
-PALETTES = []
-COLORS = []
-
# Special-case some block colors
BOX_COLORS = {'red': ["#FF0000", "#A00000"],
'orange': ["#FFD000", "#AA8000"],
@@ -133,8 +125,6 @@ EXPANDABLE_STYLE = ['boolean-style', 'compare-porch-style', 'compare-style',
EXPANDABLE = ['vspace', 'hspace', 'identity2']
-EXPANDABLE_BLOCKS = []
-
EXPANDABLE_ARGS = ['list', 'myfunc1arg', 'myfunc2arg',
'myfunc3arg', 'userdefined', 'userdefined2args',
'userdefined3args']
@@ -149,12 +139,6 @@ COLLAPSIBLE = ['sandwichbottom', 'sandwichcollapsed']
OLD_DOCK = ['and', 'or', 'plus', 'minus', 'division', 'product', 'remainder']
#
-# Blocks that contain media
-#
-CONTENT_BLOCKS = ['number', 'string', 'description', 'audio', 'video',
- 'journal']
-
-#
# These blocks get a special skin
#
BLOCKS_WITH_SKIN = ['journal', 'audio', 'description', 'nop', 'userdefined',
@@ -172,21 +156,6 @@ CONSTANTS = {'leftpos': None, 'toppos': None, 'rightpos': None,
'topy': None, 'rightx': None, 'bottomy': None}
#
-# Block-name dictionary used for labels
-#
-BLOCK_NAMES = {}
-
-#
-# Logo primitives
-#
-PRIMITIVES = {}
-
-#
-# block default values
-#
-DEFAULTS = {}
-
-#
# Blocks that can interchange strings and numbers for their arguments
#
STRING_OR_NUMBER_ARGS = ['plus2', 'equal2', 'less2', 'greater2', 'box',
@@ -262,11 +231,6 @@ TEMPLATES = {'t1x1': (0.5, 0.5, 0.0625, 0.125, 1.05, 0),
'insertimage': (0.333, 0.333)}
#
-# Names for blocks without names for popup help
-#
-SPECIAL_NAMES = {}
-
-#
# Help messages
#
HELP_STRINGS = {
diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py
index a623211..3b537b6 100644
--- a/TurtleArt/talogo.py
+++ b/TurtleArt/talogo.py
@@ -27,8 +27,8 @@ from time import time
from operator import isNumberType
from UserDict import UserDict
-from taconstants import TAB_LAYER, DEFAULT_SCALE, BLOCK_NAMES, \
- PREFIX_DICTIONARY
+from taconstants import TAB_LAYER, DEFAULT_SCALE, PREFIX_DICTIONARY
+from tapalette import block_names, value_blocks
from tautils import get_pixbuf_from_journal, convert, data_from_file, \
text_media_type, round_int, debug_output
@@ -36,7 +36,6 @@ from util.RtfParser import RtfTextOnly
from gettext import gettext as _
-value_blocks = [] # blocks whose labels are updated get added here
media_blocks_dictionary = {} # new media blocks get added here
primitive_dictionary = {} # new block primitives get added here
@@ -528,7 +527,7 @@ class LogoCode:
return
if value is None:
for block in self.value_blocks_to_update[name]:
- block.spr.set_label(BLOCK_NAMES[name][0])
+ block.spr.set_label(block_names[name][0])
block.resize()
elif self.update_values:
if type(value) == float:
@@ -537,7 +536,7 @@ class LogoCode:
else:
valstring = str(value)
for block in self.value_blocks_to_update[name]:
- block.spr.set_label(BLOCK_NAMES[name][0] + ' = ' + valstring)
+ block.spr.set_label(block_names[name][0] + ' = ' + valstring)
block.resize()
def push_file_data_to_heap(self, dsobject):
diff --git a/TurtleArt/tapalette.py b/TurtleArt/tapalette.py
index 4f84da3..ada0040 100644
--- a/TurtleArt/tapalette.py
+++ b/TurtleArt/tapalette.py
@@ -19,10 +19,57 @@
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
-from taconstants import BLOCK_STYLES, BLOCK_NAMES, HELP_STRINGS, PALETTES, \
- PALETTE_NAMES, CONTENT_BLOCKS, PRIMITIVES, DEFAULTS, SPECIAL_NAMES, \
- COLORS, EXPANDABLE_STYLE, EXPANDABLE_BLOCKS
-from talogo import value_blocks
+palette_names = []
+palette_blocks = []
+block_colors = []
+expandable_blocks = []
+block_names = {}
+block_primitives = {}
+default_values = {}
+special_names = {} # Names for blocks without names for popup help
+content_blocks = ['number', 'string', 'description', 'audio', 'video',
+ 'journal']
+value_blocks = [] # blocks whose labels are updated get added here
+block_styles = {'basic-style-head': [],
+ 'basic-style-head-1arg': [],
+ 'basic-style-tail': [],
+ 'basic-style': [],
+ 'basic-style-extended-vertical': [],
+ 'invisible': [],
+ 'basic-style-extended': [],
+ 'basic-style-1arg': [],
+ 'basic-style-var-arg': [],
+ 'bullet-style': [],
+ 'basic-style-2arg': [],
+ 'box-style': [],
+ 'box-style-media': [],
+ 'number-style': [],
+ 'number-style-var-arg': [],
+ 'number-style-block': [],
+ 'number-style-porch': [],
+ 'number-style-1arg': [],
+ 'number-style-1strarg': [],
+ 'compare-style': [],
+ 'compare-porch-style': [],
+ 'boolean-style': [],
+ 'not-style': [],
+ 'flow-style': [],
+ 'flow-style-tail': [],
+ 'flow-style-1arg': [],
+ 'flow-style-boolean': [],
+ 'flow-style-while': [],
+ 'flow-style-else': [],
+ 'collapsible-top': [],
+ 'collapsible-top-no-arm': [],
+ 'collapsible-top-no-label': [],
+ 'collapsible-top-no-arm-no-label': [],
+ 'collapsible-bottom': [],
+ 'portfolio-style-2x2': [],
+ 'portfolio-style-1x1': [],
+ 'portfolio-style-2x1': [],
+ 'portfolio-style-1x2': []}
+
+from taconstants import HELP_STRINGS, EXPANDABLE_STYLE
from tautils import debug_output
@@ -41,24 +88,24 @@ class Palette():
return
# Insert new palette just before the trash
- if 'trash' in PALETTE_NAMES:
- i = PALETTE_NAMES.index('trash')
+ if 'trash' in palette_names:
+ i = palette_names.index('trash')
else:
- i = len(PALETTE_NAMES)
+ i = len(palette_names)
if position is not None and type(position) is int and position < i:
i = position
- if self._name not in PALETTE_NAMES:
- PALETTE_NAMES.insert(i, self._name)
- PALETTES.insert(i, [])
- COLORS.insert(i, self._colors)
+ if self._name not in palette_names:
+ palette_names.insert(i, self._name)
+ palette_blocks.insert(i, [])
+ block_colors.insert(i, self._colors)
else:
# debug_output('Palette %s already defined' % (self._name))
return
# Special name entry is needed for help hover mechanism
- SPECIAL_NAMES[self._name] = self._special_name
+ special_names[self._name] = self._special_name
if self._help is not None:
HELP_STRINGS[self._name] = self._help
else:
@@ -133,18 +180,18 @@ class Block():
debug_output('You must specify a style for your block')
return
else:
- BLOCK_STYLES[self._style].append(self._name)
+ block_styles[self._style].append(self._name)
if self._label is not None:
- BLOCK_NAMES[self._name] = self._label
+ block_names[self._name] = self._label
if self._palette is not None:
- i = PALETTE_NAMES.index(self._palette)
+ i = palette_names.index(self._palette)
if position is not None and type(position) is int and \
- position < len(PALETTES[i]):
- PALETTES[i].insert(position, self._name)
+ position < len(palette_blocks[i]):
+ palette_blocks[i].insert(position, self._name)
else:
- PALETTES[i].append(self._name)
+ palette_blocks[i].append(self._name)
if position is not None:
debug_output('Ignoring position (%s)' % (str(position)))
@@ -157,19 +204,19 @@ class Block():
value_blocks.append(self._name)
if self._content_block:
- CONTENT_BLOCKS.append(self._name)
+ content_blocks.append(self._name)
if self._prim_name is not None:
- PRIMITIVES[self._name] = self._prim_name
+ block_primitives[self._name] = self._prim_name
if self._default is not None:
- DEFAULTS[self._name] = self._default
+ default_values[self._name] = self._default
if self._special_name is not None:
- SPECIAL_NAMES[self._name] = self._special_name
+ special_names[self._name] = self._special_name
if self._style in EXPANDABLE_STYLE:
- EXPANDABLE_BLOCKS.append(self._name)
+ expandable_blocks.append(self._name)
def set_value_block(self, value=True):
self._value_block = value
@@ -178,7 +225,7 @@ class Block():
self._content_block = value
def set_palette(self, palette):
- if not palette in PALETTE_NAMES:
+ if not palette in palette_names:
debug_output('Could not find palette %s' % (palette))
else:
self._palette = palette
@@ -202,7 +249,7 @@ class Block():
self._default = [default]
def set_style(self, style):
- if style not in BLOCK_STYLES:
+ if style not in block_styles:
debug_output('Unknown style: %s' % (style))
else:
self._style = style
diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py
index 845d792..eb12747 100644
--- a/TurtleArt/tautils.py
+++ b/TurtleArt/tautils.py
@@ -38,9 +38,8 @@ except (ImportError, AttributeError):
except:
OLD_SUGAR_SYSTEM = True
-from taconstants import STRING_OR_NUMBER_ARGS, HIDE_LAYER, CONTENT_ARGS, \
- COLLAPSIBLE, BLOCK_LAYER, CONTENT_BLOCKS, HIT_HIDE, \
- HIT_SHOW, XO1, XO15, UNKNOWN
+from taconstants import HIDE_LAYER, COLLAPSIBLE, BLOCK_LAYER, HIT_HIDE, \
+ HIT_SHOW, XO1, XO15, UNKNOWN
from StringIO import StringIO
import os.path
from gettext import gettext as _
@@ -640,39 +639,6 @@ def neg_arg(value):
return False
-def dock_dx_dy(block1, dock1n, block2, dock2n):
- """ Find the distance between the dock points of two blocks. """
- _dock1 = block1.docks[dock1n]
- _dock2 = block2.docks[dock2n]
- _d1type, _d1dir, _d1x, _d1y = _dock1[0:4]
- _d2type, _d2dir, _d2x, _d2y = _dock2[0:4]
- if block1 == block2:
- return (100, 100)
- if _d1dir == _d2dir:
- return (100, 100)
- if (_d2type is not 'number') or (dock2n is not 0):
- if block1.connections is not None and \
- dock1n < len(block1.connections) and \
- block1.connections[dock1n] is not None:
- return (100, 100)
- if block2.connections is not None and \
- dock2n < len(block2.connections) and \
- block2.connections[dock2n] is not None:
- return (100, 100)
- if _d1type != _d2type:
- if block1.name in STRING_OR_NUMBER_ARGS:
- if _d2type == 'number' or _d2type == 'string':
- pass
- elif block1.name in CONTENT_ARGS:
- if _d2type in CONTENT_BLOCKS:
- pass
- else:
- return (100, 100)
- (_b1x, _b1y) = block1.spr.get_xy()
- (_b2x, _b2y) = block2.spr.get_xy()
- return ((_b1x + _d1x) - (_b2x + _d2x), (_b1y + _d1y) - (_b2y + _d2y))
-
-
def journal_check(blk1, blk2, dock1, dock2):
""" Dock blocks only if arg is Journal block """
if blk1 == None or blk2 == None:
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index fa16268..28a8def 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -51,14 +51,16 @@ except ImportError:
pass
from taconstants import HORIZONTAL_PALETTE, VERTICAL_PALETTE, BLOCK_SCALE, \
- PALETTE_NAMES, TITLEXY, MEDIA_SHAPES, STATUS_SHAPES, OVERLAY_SHAPES, \
+ MEDIA_SHAPES, STATUS_SHAPES, OVERLAY_SHAPES, STRING_OR_NUMBER_ARGS, \
TOOLBAR_SHAPES, TAB_LAYER, RETURN, OVERLAY_LAYER, CATEGORY_LAYER, \
- BLOCKS_WITH_SKIN, ICON_SIZE, PALETTES, PALETTE_SCALE, PALETTE_WIDTH, \
- MACROS, TOP_LAYER, BLOCK_LAYER, CONTENT_BLOCKS, DEFAULTS, SPECIAL_NAMES, \
+ BLOCKS_WITH_SKIN, ICON_SIZE, PALETTE_SCALE, PALETTE_WIDTH, \
+ MACROS, TOP_LAYER, BLOCK_LAYER, OLD_NAMES, DEFAULT_TURTLE, TURTLE_LAYER, \
HELP_STRINGS, CURSOR, EXPANDABLE, COLLAPSIBLE, DEAD_DICTS, DEAD_KEYS, \
TEMPLATES, PYTHON_SKIN, PALETTE_HEIGHT, STATUS_LAYER, OLD_DOCK, \
- OLD_NAMES, BLOCK_NAMES, DEFAULT_TURTLE, TURTLE_LAYER, EXPANDABLE_BLOCKS, \
- EXPANDABLE_ARGS, CONSTANTS, XO1, XO15, UNKNOWN, BLOCK_STYLES
+ EXPANDABLE_ARGS, CONSTANTS, XO1, XO15, UNKNOWN, TITLEXY, \
+ CONTENT_ARGS
+from tapalette import palette_names, palette_blocks, expandable_blocks, \
+ block_names, content_blocks, default_values, special_names, block_styles
from talogo import LogoCode
from tacanvas import TurtleGraphics
from tablock import Blocks, Block
@@ -70,7 +72,7 @@ from tautils import magnitude, get_load_name, get_save_name, data_from_file, \
find_sandwich_top, find_sandwich_bottom, restore_stack, collapse_stack, \
collapsed, collapsible, hide_button_hit, show_button_hit, chooser, \
arithmetic_check, xy, find_block_to_run, find_top_block, journal_check, \
- find_group, find_blk_below, dock_dx_dy, data_to_string, find_start_stack, \
+ find_group, find_blk_below, data_to_string, find_start_stack, \
get_hardware, debug_output, error_output
from tasprite_factory import SVG, svg_str_to_pixbuf, svg_from_file
from sprites import Sprites, Sprite
@@ -503,7 +505,7 @@ class TurtleArtWindow():
self.show_palette()
if self.activity is not None and self.activity.new_sugar_system:
self.activity.palette_buttons[0].set_icon(
- PALETTE_NAMES[0] + 'on')
+ palette_names[0] + 'on')
self.hide = False
if self.running_sugar:
self.activity.recenter()
@@ -600,7 +602,7 @@ class TurtleArtWindow():
# Create the selectors
svg = SVG()
x, y = 50, 0
- for i, name in enumerate(PALETTE_NAMES):
+ for i, name in enumerate(palette_names):
try:
a = svg_str_to_pixbuf(svg_from_file(
'%s/icons/%soff.svg' % (self.path, name)))
@@ -636,11 +638,11 @@ class TurtleArtWindow():
if self.palette_sprs == []:
# Create the empty palettes
if len(self.palettes) == 0:
- for i in range(len(PALETTES)):
+ for i in range(len(palette_blocks)):
self.palettes.append([])
# Create empty palette backgrounds
- for i in PALETTE_NAMES:
+ for i in palette_names:
self.palette_sprs.append([None, None])
# Create the palette orientation button
@@ -678,7 +680,7 @@ class TurtleArtWindow():
self.selected_selector = self.selectors[n]
# Make sure all of the selectors are visible.
self.selectors[n].set_shape(self.selector_shapes[n][1])
- for i in range(len(PALETTES)):
+ for i in range(len(palette_blocks)):
self.selectors[i].set_layer(TAB_LAYER)
# Show the palette with the current orientation.
@@ -687,14 +689,14 @@ class TurtleArtWindow():
if self.palettes[n] == []:
# Create 'proto' blocks for each palette entry
- for i, name in enumerate(PALETTES[n]):
+ for i, name in enumerate(palette_blocks[n]):
self.palettes[n].append(Block(self.block_list,
self.sprite_list, name, 0, 0, 'proto', [], PALETTE_SCALE))
self.palettes[n][i].spr.set_layer(TAB_LAYER)
self.palettes[n][i].unhighlight()
# Some proto blocks get a skin.
- if name in BLOCK_STYLES['box-style-media']:
+ if name in block_styles['box-style-media']:
self._proto_skin(name + 'small', n, i)
elif name[:8] == 'template':
self._proto_skin(name[8:], n, i)
@@ -706,7 +708,7 @@ class TurtleArtWindow():
self._layout_palette(n)
for blk in self.palettes[n]:
blk.spr.set_layer(TAB_LAYER)
- if n == PALETTE_NAMES.index('trash'):
+ if n == palette_names.index('trash'):
for blk in self.trash_stack:
for gblk in find_group(blk):
if gblk.status != 'collapsed':
@@ -717,11 +719,11 @@ class TurtleArtWindow():
self._hide_previous_palette()
if self.activity is None or not self.activity.new_sugar_system:
# Hide the selectors
- for i in range(len(PALETTES)):
+ for i in range(len(palette_blocks)):
self.selectors[i].hide()
elif self.selected_palette is not None:
self.activity.palette_buttons[self.selected_palette].set_icon(
- PALETTE_NAMES[self.selected_palette] + 'off')
+ palette_names[self.selected_palette] + 'off')
self.selected_palette = None
self.previous_palette = None
@@ -729,7 +731,7 @@ class TurtleArtWindow():
""" Hide just the previously viewed toolbar palette """
# Hide previous palette
if self.previous_palette is not None:
- for i in range(len(PALETTES[self.previous_palette])):
+ for i in range(len(palette_blocks[self.previous_palette])):
self.palettes[self.previous_palette][i].spr.hide()
self.palette_sprs[self.previous_palette][
self.orientation].hide()
@@ -739,8 +741,8 @@ class TurtleArtWindow():
elif self.previous_palette is not None and \
self.previous_palette != self.selected_palette:
self.activity.palette_buttons[self.previous_palette].set_icon(
- PALETTE_NAMES[self.previous_palette] + 'off')
- if self.previous_palette == PALETTE_NAMES.index('trash'):
+ palette_names[self.previous_palette] + 'off')
+ if self.previous_palette == palette_names.index('trash'):
for blk in self.trash_stack:
for gblk in find_group(blk):
gblk.spr.hide()
@@ -806,7 +808,7 @@ class TurtleArtWindow():
_x, _y = 20, self.toolbar_offset + 5
_x, _y, _max = self._horizontal_layout(_x, _y,
self.palettes[n])
- if n == PALETTE_NAMES.index('trash'):
+ if n == palette_names.index('trash'):
_x, _y, _max = self._horizontal_layout(_x + _max, _y,
self.trash_stack)
_w = _x + _max + 25
@@ -816,7 +818,7 @@ class TurtleArtWindow():
self.sprite_list, 0, self.toolbar_offset,
svg_str_to_pixbuf(svg.palette(_w, PALETTE_HEIGHT)))
self.palette_sprs[n][self.orientation].type = 'category'
- if n == PALETTE_NAMES.index('trash'):
+ if n == palette_names.index('trash'):
svg = SVG()
self.palette_sprs[n][self.orientation].set_shape(
svg_str_to_pixbuf(svg.palette(_w, PALETTE_HEIGHT)))
@@ -824,7 +826,7 @@ class TurtleArtWindow():
else:
_x, _y = 5, self.toolbar_offset + 15
_x, _y, _max = self._vertical_layout(_x, _y, self.palettes[n])
- if n == PALETTE_NAMES.index('trash'):
+ if n == palette_names.index('trash'):
_x, _y, _max = self._vertical_layout(_x, _y + _max,
self.trash_stack)
_h = _y + _max + 25 - self.toolbar_offset
@@ -834,7 +836,7 @@ class TurtleArtWindow():
Sprite(self.sprite_list, 0, self.toolbar_offset,
svg_str_to_pixbuf(svg.palette(PALETTE_WIDTH, _h)))
self.palette_sprs[n][self.orientation].type = 'category'
- if n == PALETTE_NAMES.index('trash'):
+ if n == palette_names.index('trash'):
svg = SVG()
self.palette_sprs[n][self.orientation].set_shape(
svg_str_to_pixbuf(svg.palette(PALETTE_WIDTH, _h)))
@@ -943,7 +945,7 @@ class TurtleArtWindow():
elif spr.type == 'palette':
if spr.name == _('next'):
i = self.selected_palette + 1
- if i == len(PALETTE_NAMES):
+ if i == len(palette_names):
i = 0
if self.activity is None or \
not self.activity.new_sugar_system:
@@ -952,9 +954,9 @@ class TurtleArtWindow():
if self.selected_palette is not None:
self.activity.palette_buttons[
self.selected_palette].set_icon(
- PALETTE_NAMES[self.selected_palette] + 'off')
+ palette_names[self.selected_palette] + 'off')
self.activity.palette_buttons[i].set_icon(
- PALETTE_NAMES[i] + 'on')
+ palette_names[i] + 'on')
self.show_palette(i)
else:
self.orientation = 1 - self.orientation
@@ -1031,8 +1033,8 @@ class TurtleArtWindow():
if gblk.name in BLOCKS_WITH_SKIN:
self._resize_skin(gblk)
- # self.show_palette(PALETTE_NAMES.index('trash'))
- if self.selected_palette != PALETTE_NAMES.index('trash'):
+ # self.show_palette(palette_names.index('trash'))
+ if self.selected_palette != palette_names.index('trash'):
for gblk in group:
gblk.spr.hide()
@@ -1084,8 +1086,8 @@ class TurtleArtWindow():
def _in_the_trash(self, x, y):
""" Is x, y over the trash can? """
"""
- if self.selected_palette == PALETTE_NAMES.index('trash') and \
- self.palette_sprs[PALETTE_NAMES.index('trash')][self.orientation].hit((x, y)):
+ if self.selected_palette == palette_names.index('trash') and \
+ self.palette_sprs[palette_names.index('trash')][self.orientation].hit((x, y)):
return True
"""
if self.selected_palette is not None and \
@@ -1121,9 +1123,9 @@ class TurtleArtWindow():
""" Make a new block. """
x_pos = x - 20
y_pos = y - 20
- if name in CONTENT_BLOCKS:
+ if name in content_blocks:
if defaults == None:
- defaults = DEFAULTS[name]
+ defaults = default_values[name]
newblk = Block(self.block_list, self.sprite_list, name, x_pos,
y_pos, 'block', defaults, self.block_scale)
else:
@@ -1136,16 +1138,16 @@ class TurtleArtWindow():
self._block_skin('pythonon', newblk)
else:
self._block_skin('pythonoff', newblk)
- elif name in BLOCK_STYLES['box-style-media']:
+ elif name in block_styles['box-style-media']:
self._block_skin(name + 'off', newblk)
newspr = newblk.spr
newspr.set_layer(TOP_LAYER)
self.drag_pos = 20, 20
newblk.connections = [None] * len(newblk.docks)
- if newblk.name in DEFAULTS:
+ if newblk.name in default_values:
if defaults == None:
- defaults = DEFAULTS[newblk.name]
+ defaults = default_values[newblk.name]
for i, argvalue in enumerate(defaults):
# skip the first dock position since it is always a connector
dock = newblk.docks[i + 1]
@@ -1163,7 +1165,7 @@ class TurtleArtWindow():
argname = argvalue
(sx, sy) = newspr.get_xy()
if argname is not None:
- if argname in CONTENT_BLOCKS:
+ if argname in content_blocks:
argblk = Block(self.block_list, self.sprite_list,
argname, 0, 0, 'block', [argvalue],
self.block_scale)
@@ -1227,7 +1229,7 @@ class TurtleArtWindow():
else:
cons.append(blocks[c])
# If the boolean op was connected, readjust the plumbing.
- if blocks[i].name in BLOCK_STYLES['boolean-style']:
+ if blocks[i].name in block_styles['boolean-style']:
if block_data[i][4][0] is not None:
c = block_data[i][4][0]
cons[0] = blocks[block_data[c][4][0]]
@@ -1449,10 +1451,10 @@ class TurtleArtWindow():
def _do_show_popup(self, block_name):
""" Fetch the help text and display it. """
- if block_name in SPECIAL_NAMES:
- block_name_s = SPECIAL_NAMES[block_name]
- elif block_name in BLOCK_NAMES:
- block_name_s = BLOCK_NAMES[block_name][0]
+ if block_name in special_names:
+ block_name_s = special_names[block_name]
+ elif block_name in block_names:
+ block_name_s = block_names[block_name][0]
elif block_name in TOOLBAR_SHAPES:
block_name_s = ''
else:
@@ -1563,7 +1565,7 @@ class TurtleArtWindow():
self.saved_string = blk.spr.labels[0]
blk.spr.labels[0] += CURSOR
- elif blk.name in BLOCK_STYLES['box-style-media'] and \
+ elif blk.name in block_styles['box-style-media'] and \
blk.name != 'camera':
# TODO: isolate reference to camera
self._import_from_journal(self.selected_blk)
@@ -1597,7 +1599,7 @@ class TurtleArtWindow():
gblk.spr.move_relative((0, dy * blk.scale))
grow_stack_arm(find_sandwich_top(blk))
- elif blk.name in EXPANDABLE_BLOCKS:
+ elif blk.name in expandable_blocks:
# Connection may be lost during expansion, so store it...
blk0 = blk.connections[0]
if blk0 is not None:
@@ -1655,7 +1657,8 @@ class TurtleArtWindow():
gblk.spr.move_relative((0, dy))
blk.connections.append(blk.connections[n - 1])
argname = blk.docks[n - 1][0]
- argvalue = DEFAULTS[blk.name][len(DEFAULTS[blk.name]) - 1]
+ argvalue = default_values[blk.name][len(
+ default_values[blk.name]) - 1]
argblk = Block(self.block_list, self.sprite_list, argname,
0, 0, 'block', [argvalue], self.block_scale)
argdock = argblk.docks[0]
@@ -1666,7 +1669,7 @@ class TurtleArtWindow():
argblk.spr.set_layer(TOP_LAYER)
argblk.connections = [blk, None]
blk.connections[n - 1] = argblk
- if blk.name in BLOCK_STYLES['number-style-var-arg']:
+ if blk.name in block_styles['number-style-var-arg']:
self._cascade_expandable(blk)
grow_stack_arm(find_sandwich_top(blk))
elif blk.name in PYTHON_SKIN:
@@ -1707,18 +1710,18 @@ class TurtleArtWindow():
for gblk in find_group(blk):
if gblk not in group:
gblk.spr.move_relative((0, dy * blk.scale))
- if blk.name in BLOCK_STYLES['compare-style']:
+ if blk.name in block_styles['compare-style']:
for gblk in find_group(blk):
gblk.spr.move_relative((0, -dy * blk.scale))
def _number_style(self, name):
- if name in BLOCK_STYLES['number-style']:
+ if name in block_styles['number-style']:
return True
- if name in BLOCK_STYLES['number-style-porch']:
+ if name in block_styles['number-style-porch']:
return True
- if name in BLOCK_STYLES['number-style-block']:
+ if name in block_styles['number-style-block']:
return True
- if name in BLOCK_STYLES['number-style-var-arg']:
+ if name in block_styles['number-style-var-arg']:
return True
return False
@@ -1727,7 +1730,7 @@ class TurtleArtWindow():
while self._number_style(blk.name):
if blk.connections[0] is None:
break
- if blk.connections[0].name in EXPANDABLE_BLOCKS:
+ if blk.connections[0].name in expandable_blocks:
if blk.connections[0].connections.index(blk) != 1:
break
blk = blk.connections[0]
@@ -1744,7 +1747,7 @@ class TurtleArtWindow():
for gblk in find_group(blk):
if gblk not in group:
gblk.spr.move_relative((0, dy * blk.scale))
- if blk.name in BLOCK_STYLES['compare-style']:
+ if blk.name in block_styles['compare-style']:
for gblk in find_group(blk):
gblk.spr.move_relative((0, -dy * blk.scale))
else:
@@ -1836,17 +1839,17 @@ class TurtleArtWindow():
selected_block.connections[best_selected_block_dockn] = \
best_destination
- if best_destination.name in BLOCK_STYLES['boolean-style']:
+ if best_destination.name in block_styles['boolean-style']:
if best_destination_dockn == 2 and \
- selected_block.name in BLOCK_STYLES['compare-style']:
+ selected_block.name in block_styles['compare-style']:
dy = selected_block.ey - best_destination.ey
best_destination.expand_in_y(dy)
self._expand_boolean(best_destination, selected_block, dy)
- elif best_destination.name in EXPANDABLE_BLOCKS and \
+ elif best_destination.name in expandable_blocks and \
best_destination_dockn == 1:
dy = 0
- if (selected_block.name in EXPANDABLE_BLOCKS or
- selected_block.name in BLOCK_STYLES[
+ if (selected_block.name in expandable_blocks or
+ selected_block.name in block_styles[
'number-style-var-arg']):
if selected_block.name == 'myfunc2arg':
dy = 40 + selected_block.ey - best_destination.ey
@@ -1875,12 +1878,12 @@ class TurtleArtWindow():
c = blk2.connections.index(blk)
blk2.connections[c] = None
- if blk2.name in BLOCK_STYLES['boolean-style']:
+ if blk2.name in block_styles['boolean-style']:
if c == 2 and blk2.ey > 0:
dy = -blk2.ey
blk2.expand_in_y(dy)
self._expand_boolean(blk2, blk, dy)
- elif blk2.name in EXPANDABLE_BLOCKS and c == 1:
+ elif blk2.name in expandable_blocks and c == 1:
if blk2.ey > 0:
dy = blk2.reset_y()
if dy != 0:
@@ -2433,7 +2436,7 @@ class TurtleArtWindow():
btype, value = btype
elif type(btype) == list:
btype, value = btype[0], btype[1]
- if btype in CONTENT_BLOCKS or btype in COLLAPSIBLE:
+ if btype in content_blocks or btype in COLLAPSIBLE:
if btype == 'number':
try:
values = [round_int(value)]
@@ -2462,7 +2465,7 @@ class TurtleArtWindow():
'block', values, self.block_scale)
# Some blocks get transformed.
- if btype in BLOCK_STYLES['basic-style-var-arg'] and value is not None:
+ if btype in block_styles['basic-style-var-arg'] and value is not None:
# Is there code stored in this userdefined block?
if value > 0: # catch deprecated format (#2501)
self.python_code = None
@@ -2489,9 +2492,9 @@ class TurtleArtWindow():
elif btype == 'start': # block size is saved in start block
if value is not None:
self.block_scale = value
- elif btype in EXPANDABLE or btype in EXPANDABLE_BLOCKS or \
+ elif btype in EXPANDABLE or btype in expandable_blocks or \
btype in EXPANDABLE_ARGS or btype == 'nop':
- if btype == 'vspace' or btype in EXPANDABLE_BLOCKS:
+ if btype == 'vspace' or btype in expandable_blocks:
if value is not None:
blk.expand_in_y(value)
elif btype == 'hspace' or btype == 'identity2':
@@ -2510,7 +2513,7 @@ class TurtleArtWindow():
self._block_skin('pythonon', blk)
else:
self._block_skin('pythonoff', blk)
- elif btype in BLOCK_STYLES['box-style-media'] and blk.spr is not None:
+ elif btype in block_styles['box-style-media'] and blk.spr is not None:
# TODO: isolate reference to camera
if len(blk.values) == 0 or blk.values[0] == 'None' or \
blk.values[0] is None or btype == 'camera':
@@ -2602,15 +2605,15 @@ class TurtleArtWindow():
for _i, _blk in enumerate(_blks):
_blk.id = _i
for _blk in _blks:
- if _blk.name in CONTENT_BLOCKS or _blk.name in COLLAPSIBLE:
+ if _blk.name in content_blocks or _blk.name in COLLAPSIBLE:
if len(_blk.values) > 0:
_name = (_blk.name, _blk.values[0])
else:
_name = (_blk.name)
- elif _blk.name in BLOCK_STYLES['basic-style-var-arg'] and \
+ elif _blk.name in block_styles['basic-style-var-arg'] and \
len(_blk.values) > 0:
_name = (_blk.name, _blk.values[0])
- elif _blk.name in EXPANDABLE or _blk.name in EXPANDABLE_BLOCKS or\
+ elif _blk.name in EXPANDABLE or _blk.name in expandable_blocks or\
_blk.name in EXPANDABLE_ARGS:
_ex, _ey = _blk.get_expand_x_y()
if _ex > 0:
@@ -2862,3 +2865,37 @@ class TurtleArtWindow():
w, h = self._calc_w_h('descriptionoff', blk.spr)
x, y = self._calc_image_offset('descriptionoff', blk.spr, w, h)
blk.scale_image(x, y, w, h)
+
+
+def dock_dx_dy(block1, dock1n, block2, dock2n):
+ """ Find the distance between the dock points of two blocks. """
+ _dock1 = block1.docks[dock1n]
+ _dock2 = block2.docks[dock2n]
+ _d1type, _d1dir, _d1x, _d1y = _dock1[0:4]
+ _d2type, _d2dir, _d2x, _d2y = _dock2[0:4]
+ if block1 == block2:
+ return (100, 100)
+ if _d1dir == _d2dir:
+ return (100, 100)
+ if (_d2type is not 'number') or (dock2n is not 0):
+ if block1.connections is not None and \
+ dock1n < len(block1.connections) and \
+ block1.connections[dock1n] is not None:
+ return (100, 100)
+ if block2.connections is not None and \
+ dock2n < len(block2.connections) and \
+ block2.connections[dock2n] is not None:
+ return (100, 100)
+ if _d1type != _d2type:
+ if block1.name in STRING_OR_NUMBER_ARGS:
+ if _d2type == 'number' or _d2type == 'string':
+ pass
+ elif block1.name in CONTENT_ARGS:
+ if _d2type in content_blocks:
+ pass
+ else:
+ return (100, 100)
+ (_b1x, _b1y) = block1.spr.get_xy()
+ (_b2x, _b2y) = block2.spr.get_xy()
+ return ((_b1x + _d1x) - (_b2x + _d2x), (_b1y + _d1y) - (_b2y + _d2y))
+