Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@walter-laptop.(none)>2010-01-31 22:26:36 (GMT)
committer Walter Bender <walter@walter-laptop.(none)>2010-01-31 22:26:36 (GMT)
commitdbdb9b37ae611fb3ef339907ace60cd1c2188699 (patch)
treef1fa6ff8f3b551328664aa6db6ab745ac4e4d0c7
parent643085fdce70b253c39a8664d62eb71bb58b92c0 (diff)
adding portfolio blocks
-rw-r--r--block.py57
-rw-r--r--constants.py47
-rwxr-xr-xsprite_factory.py27
-rw-r--r--sprites.py2
4 files changed, 92 insertions, 41 deletions
diff --git a/block.py b/block.py
index 168b56a..539cf4e 100644
--- a/block.py
+++ b/block.py
@@ -268,10 +268,14 @@ class Block:
self._make_flow_style_boolean(svg)
elif self.name in FLOW_STYLE_ELSE:
self._make_flow_style_else(svg)
- elif self.name in PORTFOLIO_STYLE:
- self._make_portfolio_style(svg)
- elif self.name in PORTFOLIO_STYLE_2PIX:
- self._make_portfolio_style_2pix(svg)
+ elif self.name in PORTFOLIO_STYLE_2x2:
+ self._make_portfolio_style_2x2(svg)
+ elif self.name in PORTFOLIO_STYLE_2x1:
+ self._make_portfolio_style_2x1(svg)
+ elif self.name in PORTFOLIO_STYLE_1x1:
+ self._make_portfolio_style_1x1(svg)
+ elif self.name in PORTFOLIO_STYLE_1x2:
+ self._make_portfolio_style_1x2(svg)
else:
self._make_basic_style(svg)
print ">>>>> I don't know how to create a %s block" % (self.name)
@@ -571,7 +575,7 @@ class Block:
self.svg.docks[4][1], ']']]
self._left, self._right = 2, self.svg.get_width()-self.svg.docks[1][0]
- def _make_portfolio_style(self, svg):
+ def _make_portfolio_style_2x2(self, svg):
self.svg.expand(25+self._dx+self._ex, 10+self._ey)
self.svg.set_slot(True)
self.svg.set_tab(True)
@@ -591,9 +595,9 @@ class Block:
self.svg.docks[2][1]],
['flow', False, self.svg.docks[3][0],
self.svg.docks[3][1]]]
- self._left, self._right = 2, self.svg.get_width()-self.svg.docks[1][0]
+ self._left, self._right = 2, self.svg.get_width()-2
- def _make_portfolio_style_2pix(self, svg):
+ def _make_portfolio_style_2x1(self, svg):
self.svg.expand(25+self._dx+self._ex, 10+self._ey)
self.svg.set_slot(True)
self.svg.set_tab(True)
@@ -609,7 +613,44 @@ class Block:
self.svg.docks[1][1]],
['flow', False, self.svg.docks[2][0],
self.svg.docks[2][1]]]
- self._left, self._right = 2, self.svg.get_width()-self.svg.docks[1][0]
+ self._left, self._right = 2, self.svg.get_width()-2
+
+ def _make_portfolio_style_1x2(self, svg):
+ self.svg.expand(self._dx+self._ex, 15+self._ey)
+ self.svg.set_slot(True)
+ self.svg.set_tab(True)
+ self.svg.set_innie([True, True, False, True])
+ self.svg.set_draw_innies(False)
+ self._make_portfolio(svg)
+ self.docks = [['flow', True, self.svg.docks[0][0],
+ self.svg.docks[0][1]],
+ ['string', False, self.svg.docks[4][0],
+ self.svg.docks[4][1]],
+ ['media', False, self.svg.docks[3][0],
+ self.svg.docks[3][1]],
+ ['media', False, self.svg.docks[2][0],
+ self.svg.docks[2][1]],
+ ['flow', False, self.svg.docks[1][0],
+ self.svg.docks[1][1]]]
+ self._left, self._right = 2, self.svg.get_width()-2
+
+
+ def _make_portfolio_style_1x1(self, svg):
+ self.svg.expand(self._dx+self._ex, 15+self._ey)
+ self.svg.set_slot(True)
+ self.svg.set_tab(True)
+ self.svg.set_innie([True, True])
+ self.svg.set_draw_innies(False)
+ self._make_portfolio(svg)
+ self.docks = [['flow', True, self.svg.docks[0][0],
+ self.svg.docks[0][1]],
+ ['string', False, self.svg.docks[3][0],
+ self.svg.docks[3][1]],
+ ['media', False, self.svg.docks[2][0],
+ self.svg.docks[2][1]],
+ ['flow', False, self.svg.docks[1][0],
+ self.svg.docks[1][1]]]
+ self._left, self._right = 2, self.svg.get_width()-2
def _make_basic_block(self, svg):
self.shapes.append(svg_str_to_pixbuf(self.svg.basic_block()))
diff --git a/constants.py b/constants.py
index 1566ecc..b1f2159 100644
--- a/constants.py
+++ b/constants.py
@@ -52,8 +52,8 @@ PALETTES = [['forward', 'back', 'clean', 'left', 'right', 'show',
['kbinput', 'push', 'printheap', 'keyboard', 'pop', 'clearheap',
'myfunc', 'nop', 'leftpos', 'toppos', 'width', 'rightpos',
'bottompos', 'height', 'turtle', 'print'],
- ['journal', 'audio', 'description', 'hideblocks', 'template7',
- 'template2', 'list'],
+ ['journal', 'audio', 'description', 'hideblocks', 'template1x1',
+ 'template1x2', 'template2x1', 'template2x2', 'list'],
['restore']]
#
@@ -76,7 +76,7 @@ SELECTED_COLOR = "#0000FF"
SELECTED_STROKE_WIDTH = 1.5
STANDARD_STROKE_WIDTH = 1.0
-PALETTE_SCALE = {'template7':1.0}
+PALETTE_SCALE = {'template2x2':1.0, 'template1x2':1.0}
#
@@ -109,10 +109,11 @@ FLOW_STYLE = ['forever', 'hspace']
FLOW_STYLE_1ARG = ['repeat']
FLOW_STYLE_BOOLEAN = ['if']
FLOW_STYLE_ELSE = ['ifelse']
-PORTFOLIO_STYLE = ['template7']
+PORTFOLIO_STYLE_2x2 = ['template2x2']
BULLET_STYLE = ['list']
-PORTFOLIO_STYLE_1PIX = ['template1']
-PORTFOLIO_STYLE_2PIX = ['template2', 'template6']
+PORTFOLIO_STYLE_1x1 = ['template1x1']
+PORTFOLIO_STYLE_2x1 = ['template2x1']
+PORTFOLIO_STYLE_1x2 = ['template1x2']
#
# blocks that are expandable
@@ -208,11 +209,10 @@ BLOCK_NAMES = {
'storeinbox1':[_('store in box 1')],
'storeinbox2':[_('store in box 2')],
'string':[_('text')],
- 'template1':[' '],
- 'template2':[' '],
- 'template3':[' '],
- 'template6':[' '],
- 'template7':[' '],
+ 'template1x1':[''],
+ 'template1x2':[''],
+ 'template2x1':[''],
+ 'template2x2':[''],
'textsize':[_('text size')],
'toppos':[_('top')],
'turtle':[_('turtle')],
@@ -304,10 +304,10 @@ PRIMITIVES = {
'storein':'storeinbox',
'storeinbox1':'storeinbox1',
'storeinbox2':'storeinbox2',
- 'template1':'tp1',
- 'template2':'tp2',
- 'template6':'tp6',
- 'template7':'tp7',
+ 'template1x1':'tp1',
+ 'template1x2':'tp6',
+ 'template2x1':'tp2',
+ 'template2x2':'tp7',
'textsize':'textsize',
'toppos':'toppos',
'turtle':'turtle',
@@ -354,10 +354,10 @@ DEFAULTS = {
'storeinbox2':[100],
'storein':[_('my box'),100],
'string':[_('text')],
- 'template1':[_('Title'), 'None'],
- 'template2':[_('Title'), 'None', 'None'],
- 'template6':[_('Title'), 'None', 'None'],
- 'template7':[_('Title'), 'None', 'None', 'None', 'None'],
+ 'template1x1':[_('Title'), 'None'],
+ 'template1x2':[_('Title'), 'None', 'None'],
+ 'template2x1':[_('Title'), 'None', 'None'],
+ 'template2x2':[_('Title'), 'None', 'None', 'None', 'None'],
'turtle':[1],
'wait':[1]}
@@ -365,8 +365,8 @@ DEFAULTS = {
# Blocks that can interchange strings and numbers for their arguments
#
STRING_OR_NUMBER_ARGS = ['plus2', 'equal', 'less', 'greater',
- 'template1', 'template2', 'template7',
- 'template4', 'template6', 'list', 'nop',
+ 'template1x1', 'template1x2', 'template2x1',
+ 'template2x2', 'list', 'nop',
'print', 'stack', 'hat']
CONTENT_ARGS = ['show', 'push', 'storein', 'storeinbox1', 'storeinbox2']
@@ -393,7 +393,10 @@ OLD_NAMES = {'product':'product2', 'storeinbox':'storein',
'division':'division2', 'plus':'plus2',
'remainder':'remainder2', 'identity':'identity2',
'division':'division2', 'if else':'if', 'audiooff':'audio',
- 'descriptionoff':'description','template3':'list'}
+ 'descriptionoff':'description','template3':'list',
+ 'template1':'template1x1', 'template2':'template2x1',
+ 'template6':'template1x2', 'template7':'template2x2',
+ 'template8':'template1x1' }
#
# 'dead key' Unicode dictionaries
diff --git a/sprite_factory.py b/sprite_factory.py
index ad40194..c3be33a 100755
--- a/sprite_factory.py
+++ b/sprite_factory.py
@@ -60,6 +60,7 @@ class SVG:
self._expand_x = 0
self._expand_y = 0
self._else = False
+ self._draw_innies = True
self._hide = False
self._show = False
self._fill = "#00FF00"
@@ -111,11 +112,11 @@ class SVG:
def basic_flow(self):
(x, y) = self._calculate_x_y()
svg = self._new_path(x, y)
- svg += self._rarc_to(1, -1)
+ svg += self._corner(1, -1)
svg += self._do_slot()
svg += self._rline_to(self._expand_x, 0)
xx = self._x
- svg += self._rarc_to(1, 1)
+ svg += self._corner(1, 1)
for i in range(len(self._innie)):
if self._innie[i] is True:
svg += self._do_innie()
@@ -129,7 +130,7 @@ class SVG:
else:
svg += self._rline_to(self._radius+self._slot_x, 0)
hh = self._x
- svg += self._rarc_to(1,1)
+ svg += self._corner(1, 1)
svg += self._rline_to(-self._radius,0)
if self._else:
svg += self._do_tab()
@@ -137,14 +138,14 @@ class SVG:
svg += self._do_tab()
svg += self._rline_to(-self._radius, 0)
svg += self._rline_to(0, self._expand_y)
- svg += self._rarc_to(-1, 1)
+ svg += self._corner(-1, 1)
svg += self._line_to(xx, self._y)
svg += self._rline_to(-self._expand_x, 0)
if self._tab:
svg += self._do_tab()
else:
svg += self._do_tail()
- svg += self._rarc_to(-1, -1)
+ svg += self._corner(-1, -1)
svg += self._rline_to(0, -self._expand_y)
if True in self._innie:
svg += self._line_to(x, self._radius+self._innie_y2+\
@@ -165,22 +166,22 @@ class SVG:
(x, y) = self._calculate_x_y()
x += self._innie_x1+self._innie_x2
svg = self._new_path(x, y)
- svg += self._rarc_to(1, -1)
+ svg += self._corner(1, -1)
svg += self._do_slot()
xx = self._x
svg += self._rline_to(self._expand_x, 0)
- svg += self._rarc_to(1, 1)
+ svg += self._corner(1, 1)
svg += self._rline_to(0, self._expand_y)
for i in range(len(self._innie)):
- if self._innie[i] is True and i > 0:
+ if self._innie[i] is True and i > 0 and self._draw_innies:
svg += self._do_innie()
svg += self._rline_to(0, 2*self._innie_y2+self._innie_spacer)
else:
svg += self._rline_to(0, 2*self._innie_y2+self._innie_spacer)
- svg += self._rarc_to(-1, 1)
+ svg += self._corner(-1, 1)
svg += self._line_to(xx, self._y)
svg += self._do_tab()
- svg += self._rarc_to(-1, -1)
+ svg += self._corner(-1, -1)
for i in range(len(self._innie)):
if self._innie[len(self._innie)-i-1] is True:
svg += self._rline_to(0, -2*self._innie_y2-self._innie_spacer)
@@ -330,6 +331,9 @@ class SVG:
#
# Utility methods
#
+ def set_draw_innies(self, flag=True):
+ self._draw_innies = flag
+
def set_hide(self, flag=False):
self._hide = flag
@@ -749,11 +753,12 @@ def generator(datapath):
svg0 = SVG()
f = open_file(datapath, "portfolio-test.svg")
svg0.set_scale(1)
- svg0.expand(25,10)
+ svg0.expand(25,15)
svg0.set_slot(True)
svg0.set_innie([True, True, False, True])
svg0.set_tab(True)
svg0.set_gradiant(True)
+ svg0.set_draw_innies(False)
svg_str = svg0.portfolio()
f.write(svg_str)
close_file(f)
diff --git a/sprites.py b/sprites.py
index e66a86d..9124494 100644
--- a/sprites.py
+++ b/sprites.py
@@ -283,6 +283,8 @@ class Sprite:
def draw_label(self):
my_width = self._width-self._margins[0]-self._margins[2]
+ if my_width < 0:
+ my_width = 0
my_height = self._height-self._margins[1]-self._margins[3]
for i in range(len(self.labels)):
pl = self._sprites.canvas.create_pango_layout(str(self.labels[i]))