Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TurtleArt/tablock.py10
-rw-r--r--TurtleArt/tapalette.py1
-rwxr-xr-xTurtleArt/tasprite_factory.py61
-rw-r--r--plugins/turtle_blocks_extras/turtle_blocks_extras.py21
4 files changed, 69 insertions, 24 deletions
diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py
index 53c3e5c..2ead410 100644
--- a/TurtleArt/tablock.py
+++ b/TurtleArt/tablock.py
@@ -178,6 +178,7 @@ class Block:
'compare-porch-style': self._make_compare_porch_style,
'boolean-style': self._make_boolean_style,
'not-style': self._make_not_style,
+ 'boolean-block-style': self._make_boolean_block_style,
'clamp-style': self._make_clamp_style,
'clamp-style-collapsible': self._make_clamp_style_collapsible,
'clamp-style-collapsed': self._make_clamp_style_collapsed,
@@ -871,12 +872,19 @@ class Block:
def _make_not_style(self, svg):
self.svg.expand(15 + self.dx + self.ex, self.ey)
- self._make_block_graphics(svg, self.svg.boolean_not)
+ self._make_block_graphics(svg, self.svg.boolean_not, arg=False)
self.docks = [['bool', True, self.svg.docks[0][0],
self.svg.docks[0][1]],
['bool', False, self.svg.docks[1][0],
self.svg.docks[1][1]]]
+ def _make_boolean_block_style(self, svg):
+ self.svg.expand(15 + self.dx + self.ex, self.ey)
+ self._make_block_graphics(svg, self.svg.boolean_not, arg=True)
+ self.docks = [['bool', True, self.svg.docks[0][0],
+ self.svg.docks[0][1]],
+ ['unavailable', False, 0, 0]]
+
def _make_clamp_style(self, svg, extend_x=0, extend_y=4):
self.svg.expand(self.dx + self.ex + extend_x, self.ey + extend_y)
self.svg.set_slot(True)
diff --git a/TurtleArt/tapalette.py b/TurtleArt/tapalette.py
index 7a44763..d2ee6bb 100644
--- a/TurtleArt/tapalette.py
+++ b/TurtleArt/tapalette.py
@@ -62,6 +62,7 @@ block_styles = {'basic-style': [],
'compare-porch-style': [],
'boolean-style': [],
'not-style': [],
+ 'boolean-block-style': [],
'flow-style-tail': [],
'clamp-style': [],
'clamp-style-collapsible': [],
diff --git a/TurtleArt/tasprite_factory.py b/TurtleArt/tasprite_factory.py
index 2c403b6..0cbe1cf 100755
--- a/TurtleArt/tasprite_factory.py
+++ b/TurtleArt/tasprite_factory.py
@@ -334,26 +334,43 @@ class SVG:
self.margins[3] = int(self._stroke_width * self._scale)
return self.header() + svg
- def boolean_not(self):
- ''' Booleans are in a class of their own '''
+ def boolean_not(self, notnot):
+ ''' Booleans are in a class of their own: not and not not '''
self.reset_min_max()
- svg = self._start_boolean(self._stroke_width / 2.0, self._radius * \
- 2.0 + self._stroke_width / 2.0)
+ if not notnot:
+ svg = self._start_boolean(
+ self._stroke_width / 2.0,
+ self._radius * 2.0 + self._stroke_width / 2.0)
+ else:
+ svg = self._start_boolean(
+ self._stroke_width / 2.0,
+ self._radius + self._stroke_width / 2.0)
svg += self._rline_to(0, -self._stroke_width)
- svg += self._rarc_to(1, -1)
+ if not notnot:
+ svg += self._rarc_to(1, -1)
svg += self._rline_to(self._radius / 2.0 + self._expand_x, 0)
xx = self._x
- svg += self._rline_to(0, self._radius / 2.0)
- svg += self._do_boolean()
- svg += self._rline_to(0, self._radius / 2.0)
+ if not notnot:
+ svg += self._rline_to(0, self._radius / 2.0)
+ svg += self._do_boolean()
+ svg += self._rline_to(0, self._radius / 2.0)
+ else:
+ svg += self._rline_to(0, self._radius * 2)
svg += self.line_to(xx, self._y)
- svg += self._rline_to(-self._expand_x, 0)
- svg += self._end_boolean()
- self.margins[0] = int((self._radius + self._stroke_width + 0.5) * \
- self._scale)
+ if not notnot:
+ svg += self._rline_to(-self._expand_x, 0)
+ else:
+ svg += self._rline_to(-self._radius / 2.0 - self._expand_x, 0)
+ svg += self._end_boolean(notnot)
+ if notnot:
+ self.margins[0] = int((self._radius + self._stroke_width + 0.5) * \
+ self._scale)
+ self.margins[2] = int((self._radius + self._stroke_width + 0.5) * \
+ self._scale)
+ else:
+ self.margins[0] = int((self._stroke_width + 0.5) * self._scale)
+ self.margins[2] = int((self._stroke_width + 0.5) * self._scale)
self.margins[1] = int(self._stroke_width * self._scale)
- self.margins[2] = int((self._radius + self._stroke_width + 0.5) * \
- self._scale)
self.margins[3] = int(self._stroke_width * self._scale)
return self.header() + svg
@@ -1105,8 +1122,11 @@ class SVG:
svg = self._rarc_to(-1, 1, 90, 0, 0) + self._rarc_to(1, 1, 90, 0, 0)
return svg
- def _end_boolean(self):
- svg = self._rline_to(-self._radius * 1.5, 0)
+ def _end_boolean(self, notnot=False):
+ if not notnot:
+ svg = self._rline_to(-self._radius * 1.5, 0)
+ else:
+ svg = ''
svg += self._rline_to(0, -self._stroke_width)
svg += self._rline_to(-self._stroke_width, 0)
self._radius -= self._stroke_width
@@ -1178,13 +1198,10 @@ def close_file(f):
def generator(datapath):
svg0 = SVG()
- f = open_file(datapath, "clamp.svg")
+ f = open_file(datapath, "true.svg")
svg0.set_scale(2)
- svg0.set_arm(True)
- svg0.expand(0, 0, 0, 21)
- svg0.set_collapsible(True)
- svg0.set_hide(True)
- svg_str = svg0.clamp()
+ svg0.expand(30, 0, 0, 0)
+ svg_str = svg0.boolean_not(True)
f.write(svg_str)
close_file(f)
diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
index 92f9c26..f3b0d8f 100644
--- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py
+++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
@@ -108,7 +108,7 @@ class Turtle_blocks_extras(Plugin):
boolean operators from Numbers palette'))
# internally expanded macro
- palette.add_block('until',
+ palette.add_block('until',
style='clamp-style-boolean',
label=_('until'),
prim_name='until',
@@ -331,6 +331,7 @@ amplitude, and duration (in seconds)'))
primitive_dictionary['mousebutton'] = self._prim_mouse_button
palette.add_block('mousebutton',
+ hidden=True,
style='box-style',
label=_('button down'),
prim_name='mousebutton',
@@ -340,6 +341,17 @@ pressed'))
self.tw.lc.def_prim('mousebutton', 0,
lambda self: primitive_dictionary['mousebutton']())
+ primitive_dictionary['mousebutton2'] = self._prim_mouse_button_bool
+ palette.add_block('mousebutton2',
+ style='boolean-block-style',
+ label=_('button down'),
+ prim_name='mousebutton2',
+ value_block=True,
+ help_string=_('returns True if mouse button is \
+pressed'))
+ self.tw.lc.def_prim('mousebutton2', 0,
+ lambda self: primitive_dictionary['mousebutton2']())
+
palette.add_block('mousex',
style='box-style',
label=_('mouse x'),
@@ -1320,6 +1332,13 @@ bullets'))
else:
return 0
+ def _prim_mouse_button_bool(self):
+ """ Return True if mouse button is pressed """
+ if self.tw.mouse_flag == 1:
+ return True
+ else:
+ return False
+
def _prim_see(self):
""" Read r, g, b from the canvas and return a corresponding palette
color """