Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TurtleArtActivity.py9
-rw-r--r--taexporthtml.py28
-rw-r--r--taexportlogo.py13
-rw-r--r--tautils.py8
-rw-r--r--tawindow.py34
5 files changed, 45 insertions, 47 deletions
diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py
index 8afbd9f..826d79f 100644
--- a/TurtleArtActivity.py
+++ b/TurtleArtActivity.py
@@ -59,8 +59,8 @@ import sys
import re
from constants import *
-from taexporthtml import *
-from taexportlogo import *
+from taexporthtml import save_html
+from taexportlogo import save_logo
from tautils import *
import tawindow
import talogo
@@ -245,10 +245,7 @@ class TurtleArtActivity(activity.Activity):
# Write the file to the instance directory of this activity's root.
file_path = os.path.join(datapath, filename)
-
- # FIXME: this was like this before refactoring, the save_pict
- # belongs to taproject (not tawindow)
- self.tw.save_pict(file_path)
+ save_picture(self.tw.canvas, file_path)
# Create a datastore object
dsobject = datastore.create()
diff --git a/taexporthtml.py b/taexporthtml.py
index 4c7f5d2..dc18174 100644
--- a/taexporthtml.py
+++ b/taexporthtml.py
@@ -18,13 +18,12 @@
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
-import tawindow
from sugar.activity import activity
from sugar.datastore import datastore
import os.path
import subprocess
from talogo import get_pixbuf_from_journal
-from tahoverhelp import *
+from tautils import data_to_string, save_picture
from gettext import gettext as _
def save_html(self, tw, embed_flag=True):
@@ -69,7 +68,7 @@ charset=UTF-8\">\n", ""),
self.html_glue['img'] = ("<img width=\"400\" height=\"300\" alt=\"Image\" src=\"data:image/png;base64,\n", " \"/>\n")
self.html_glue['img2'] = ("<img alt=\"Image\" src=\"data:image/png;base64,\n", " \"/>\n")
- bs = tawindow.blocks(tw)
+ bs = tw.just_blocks()
code = ""
self.imagecount = 0 # incremented for each image
slidecount = 0 # incremented for each template (slide)
@@ -101,17 +100,17 @@ charset=UTF-8\">\n", ""),
this_stack += d
show = 0
# process slide templates
- elif d == "tp1":
+ elif d == "t1x1":
tp1 = 1
- elif d == "tp2":
+ elif d == "t2x1":
tp2 = 1
- elif d == "tp3":
+ elif d == "list":
tp3 = 8
- elif d == 'tp8':
+ elif d == 't1x1a':
tp8 = 1
- elif d == "tp6":
+ elif d == "t1x2":
tp6 = 1
- elif d == "tp7":
+ elif d == "t2x2":
tp7 = 1
elif tp3 > 0: # bullets
if tp3 == 8: # title comes first
@@ -259,7 +258,7 @@ charset=UTF-8\">\n", ""),
if slidecount == 0:
# save a screen dump instead
filename = os.path.join(self.datapath, 'image.png')
- tawindow.save_pict(tw,filename)
+ save_picture(tw.canvas, filename)
# if the embed_images flag is True
# embed_images base64 into the html
if self.embed_images == True:
@@ -274,7 +273,8 @@ charset=UTF-8\">\n", ""),
self.html_glue['img'][1])
code += (self.html_glue['div'][0])
# get a json dump of the code
- code += (tawindow.save_string(tw,False))
+ code += data_to_string(tw.assemble_data_to_save(False, True))
+ code += data_to_string(tw.assemble_data_to_save(False, True))
code += (self.html_glue['div'][1])
code = self.html_glue['doctype'][0] + \
self.html_glue['html'][0] + \
@@ -292,9 +292,9 @@ charset=UTF-8\">\n", ""),
self.html_glue['html'][1]
return code
-def walk_stack(self, tw, spr):
- top = tawindow.find_top_block(spr)
- if spr == top:
+def walk_stack(self, tw, blk):
+ top = tw.find_top_block(blk)
+ if blk == top:
# only walk the stack if the block is the top block
return tw.lc.run_blocks(top, tw.block_list.list, False)
else:
diff --git a/taexportlogo.py b/taexportlogo.py
index 94e5016..d0207ee 100644
--- a/taexportlogo.py
+++ b/taexportlogo.py
@@ -18,7 +18,6 @@
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
-import tawindow
import math
try:
from sugar.datastore import datastore
@@ -87,7 +86,7 @@ make \"colors [ \
make \"shade 50 \r\
tasetshade :shade \r"
- bs = tawindow.blocks(tw)
+ bs = tw.just_blocks()
code = ""
# these flags are used to trigger the prepending of additional procedures
random = 0
@@ -166,7 +165,7 @@ tasetshade :shade \r"
refstack = 1
elif d == "box":
refbox = 1
- elif d == "storeinbox":
+ elif d == "storein":
namedbox = 1
elif d == "storeinbox1":
this_stack += "make \"box1"
@@ -265,7 +264,7 @@ tasetshade :shade \r"
elif d == "container":
if show == 1:
show = 2
- elif d == "minus":
+ elif d == "minus2":
this_stack == "taminus"
minus = 1
elif d == "hideblocks":
@@ -317,9 +316,9 @@ tasetshade :shade \r"
# print code
return code
-def walk_stack(self, tw, spr):
- top = tawindow.find_top_block(spr)
- if spr == top:
+def walk_stack(self, tw, blk):
+ top = tw.find_top_block(blk)
+ if blk == top:
# only walk the stack if the block is the top block
code = tw.lc.run_blocks(top, tw.block_list.list, False)
return code
diff --git a/tautils.py b/tautils.py
index 3cad9c8..0471421 100644
--- a/tautils.py
+++ b/tautils.py
@@ -131,3 +131,11 @@ def do_dialog(dialog, suffix, load_save_folder):
dialog.destroy()
return result, load_save_folder
+def save_picture(canvas, fname):
+ pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, canvas.width, \
+ canvas.height)
+ pixbuf.get_from_drawable(canvas.canvas.images[0],
+ canvas.canvas.images[0].get_colormap(),
+ 0, 0, 0, 0, canvas.width, canvas.height)
+ pixbuf.save(fname, 'png')
+
diff --git a/tawindow.py b/tawindow.py
index d8e954a..25ee306 100644
--- a/tawindow.py
+++ b/tawindow.py
@@ -201,7 +201,7 @@ class TurtleArtWindow():
Change the icon for user-defined blocks after Python code is loaded
"""
def set_userdefined(self):
- for blk in self._just_blocks():
+ for blk in self.just_blocks():
if blk.name == 'nop':
blk.spr.set_image(self.media_shapes['pythonon'], 1, 15, 8)
self.nop = 'pythonloaded'
@@ -211,12 +211,12 @@ class TurtleArtWindow():
"""
def hideshow_button(self):
if self.hide is False:
- for blk in self._just_blocks():
+ for blk in self.just_blocks():
blk.spr.set_layer(HIDE_LAYER)
self._hide_palette()
self.hide = True
else:
- for blk in self._just_blocks():
+ for blk in self.just_blocks():
blk.spr.set_layer(BLOCK_LAYER)
self.show_palette()
self.hide = False
@@ -264,14 +264,14 @@ class TurtleArtWindow():
if self.running_sugar:
self.activity.recenter()
# Look for a 'start' block
- for blk in self._just_blocks():
+ for blk in self.just_blocks():
if self._find_start_stack(blk):
self.step_time = time
print "running stack starting from %s" % (blk.name)
self._run_stack(blk)
return
# If there is no 'start' block, run stacks that aren't 'def action'
- for blk in self._just_blocks():
+ for blk in self.just_blocks():
if self._find_block_to_run(blk):
self.step_time = time
print "running stack starting from %s" % (blk.name)
@@ -487,7 +487,7 @@ class TurtleArtWindow():
"""
Find the top block in a stack.
"""
- def _find_top_block(self, blk):
+ def find_top_block(self, blk):
while blk.connections[0] is not None:
blk = blk.connections[0]
return blk
@@ -496,7 +496,7 @@ class TurtleArtWindow():
Find a stack with a 'start' block on top.
"""
def _find_start_stack(self, blk):
- top = self._find_top_block(blk)
+ top = self.find_top_block(blk)
if top.name == 'start':
return True
else:
@@ -1073,7 +1073,7 @@ class TurtleArtWindow():
my_block = self.drag_group[0]
d = 200
for my_dockn in range(len(my_block.docks)):
- for i, your_block in enumerate(self._just_blocks()):
+ for i, your_block in enumerate(self.just_blocks()):
# don't link to a block to which you're already connected
if your_block in self.drag_group:
continue
@@ -1168,8 +1168,8 @@ class TurtleArtWindow():
if blk is None:
return
self.lc.ag = None
- top = self._find_top_block(blk)
- self.lc.run_blocks(top, self._just_blocks(), True)
+ top = self.find_top_block(blk)
+ self.lc.run_blocks(top, self.just_blocks(), True)
gobject.idle_add(self.lc.doevalstep)
"""
@@ -1196,7 +1196,7 @@ class TurtleArtWindow():
"""
Filter out 'proto' blocks
"""
- def _just_blocks(self):
+ def just_blocks(self):
just_blocks_list = []
for b in self.block_list.list:
if b.type == 'block':
@@ -1205,12 +1205,6 @@ class TurtleArtWindow():
"""
- Macro
- """
- # TODO: load a 'macro' stack of blocks
-
-
- """
Make a new block.
"""
def _new_block(self, name, x, y):
@@ -1430,7 +1424,7 @@ class TurtleArtWindow():
"""
def new_project(self):
stop_logo(self)
- for b in self._just_blocks():
+ for b in self.just_blocks():
b.spr.hide()
self.canvas.clearscreen()
self.save_file_name = None
@@ -1662,9 +1656,9 @@ class TurtleArtWindow():
# TODO: if save_project is False: just the current stack
data = []
- for i, b in enumerate(self._just_blocks()):
+ for i, b in enumerate(self.just_blocks()):
b.id = i
- for b in self._just_blocks():
+ for b in self.just_blocks():
if b.name in CONTENT_BLOCKS:
if len(b.values)>0:
name = (b.name, b.values[0])