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-30 16:24:59 (GMT)
committer Walter Bender <walter@walter-laptop.(none)>2010-01-30 16:24:59 (GMT)
commitf4ffd999eae8a705174621f6fd0775446f2113fc (patch)
tree620988533b12da4eb7c558f75b5eae447241188c
parentdc624507fa51e34269a751da14a1805b266f2ff2 (diff)
cleaning up multimedia code
-rw-r--r--block.py9
-rw-r--r--talogo.py47
-rw-r--r--taproject.py51
3 files changed, 53 insertions, 54 deletions
diff --git a/block.py b/block.py
index f7eb05b..f6f2a09 100644
--- a/block.py
+++ b/block.py
@@ -118,10 +118,11 @@ class Block:
# make sure the label fits
lw = self.spr.label_width()
lwh = self.spr.label_area_dimensions()
- if lw > lwh[0]:
- self._dx = (lw-lwh[0])
- self._make_block(self.svg)
- self.spr.set_shape(self.shapes[0])
+ self._dx = (lw-lwh[0])
+ if self._dx < 0:
+ self._dx = 0
+ self._make_block(self.svg)
+ self.spr.set_shape(self.shapes[0])
# We may want to rescale blocks as well.
def rescale(self, scale):
diff --git a/talogo.py b/talogo.py
index b93e9d8..454a577 100644
--- a/talogo.py
+++ b/talogo.py
@@ -171,7 +171,7 @@ def setup_cmd(lc, str):
def start_eval(lc, list):
icall(lc, evline, list); yield True
- if hasattr(lc.tw,"activity"):
+ if lc.tw.running_sugar():
lc.tw.activity.stop_button.set_icon("stopitoff")
yield False
@@ -457,7 +457,7 @@ def identity(x):
# recenter the canvas when the start block is clicked
def start_stack(lc):
- if hasattr(lc.tw,'activity'):
+ if lc.tw.running_sugar():
lc.tw.activity.recenter()
def lcNew(tw):
@@ -672,30 +672,29 @@ def callmyfunc(lc, f, x):
def show_picture(lc, media, x, y, w, h):
if media == "" or media[6:] == "":
- # raise logoerror("#nomedia")
pass
elif media[6:] is not "None":
- try:
- dsobject = datastore.get(media[6:])
- except:
- raise logoerror("#nomedia")
- # check to see if it is a movie
- # print dsobject.file_path
- # print "object has file suffix of: " + dsobject.file_path[-4:]
- if dsobject.file_path[-4:] == '.ogv' or \
- dsobject.file_path[-4:] == '.vob' or \
- dsobject.file_path[-4:] == '.mp4' or \
- dsobject.file_path[-4:] == '.wmv' or \
- dsobject.file_path[-4:] == '.mov':
- # print "playing movie x:" + str(x) + " y:" + str(y) + " w:" + \
- # str(w) + " h:" + str(h)
- play_dsobject(lc, dsobject, int(x), int(y), int(w), int(h))
+ if lc.tw.running_sugar():
+ try:
+ dsobject = datastore.get(media[6:])
+ except:
+ raise logoerror("#nomedia")
+ # Check to see if it is a movie
+ if dsobject.file_path[-4:] == '.ogv' or \
+ dsobject.file_path[-4:] == '.vob' or \
+ dsobject.file_path[-4:] == '.mp4' or \
+ dsobject.file_path[-4:] == '.wmv' or \
+ dsobject.file_path[-4:] == '.mov':
+ play_dsobject(lc, dsobject, int(x), int(y), int(w), int(h))
+ else:
+ pixbuf = get_pixbuf_from_journal(dsobject, int(w), int(h))
+ dsobject.destroy()
else:
- pixbuf = get_pixbuf_from_journal(dsobject, int(w), int(h))
- if pixbuf is not None:
- lc.tw.canvas.draw_pixbuf(pixbuf, 0, 0, int(x), int(y),
- int(w), int(h))
- dsobject.destroy()
+ pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(media[6:],
+ int(w), int(h))
+ if pixbuf is not None:
+ lc.tw.canvas.draw_pixbuf(pixbuf, 0, 0, int(x), int(y),
+ int(w), int(h))
def get_pixbuf_from_journal(dsobject,w,h):
try:
@@ -996,7 +995,7 @@ def hideblocks(lc):
# TODO: how do we do this with the new toolbar?
#for i in lc.tw.selbuttons:
# hide(i)
- if hasattr(lc.tw,"activity"):
+ if lc.tw.running_sugar():
lc.tw.activity.do_hide()
def doevalstep(lc):
diff --git a/taproject.py b/taproject.py
index 58eee81..f8f4575 100644
--- a/taproject.py
+++ b/taproject.py
@@ -52,11 +52,6 @@ import sprites
from constants import *
from gettext import gettext as _
-nolabel = ['audiooff', 'descriptionoff', 'journal']
-shape_dict = {'journal':'texton', \
- 'descriptionoff':'decson', \
- 'audiooff':'audioon'}
-
def new_project(tw):
stop_logo(tw)
for b in tw._just_blocks():
@@ -170,9 +165,8 @@ def read_data(tw, data):
c.spr.move((nx, ny))
def load_block(tw, b):
- # TODO: optionally read blocks without x, y
# A block is saved as: (i, (btype, value), x, y, (c0,... cn))
- media = None
+ # The x,y position is saved/loaded for backward compatibility reasons only
btype, value = b[1], None
if type(btype) == type((1,2)):
btype, value = btype
@@ -187,28 +181,33 @@ def load_block(tw, b):
else:
values = []
- if btype == 'journal' or btype == 'audiooff' or btype == 'descriptionoff':
- media = value
- label = None
blk = block.Block(tw.block_list, tw.sprite_list,
btype, b[2]+tw.canvas.cx,
b[3]+tw.canvas.cy, 'block', values)
- if media is not None and media not in nolabel:
- try:
- dsobject = datastore.get(media)
- blk.value[0] = dsobject.object_id
- # TODO: handle media icons
- # setimage(spr, tw.media_shapes[shape_dict[spr.proto.name]])
- if blk.name == 'journal':
- '''
- pixbuf = get_pixbuf_from_journal(dsobject,
- spr.width,spr.height)
- if pixbuf is not None:
- setimage(spr, pixbuf)
- '''
- dsobject.destroy()
- except:
- print "couldn't open dsobject (%s)" % (blk.values[0])
+
+ if btype in BOX_STYLE_MEDIA and blk.values[0] is not None:
+ if tw.running_sugar():
+ try:
+ dsobject = datastore.get(blk.values[0])
+ blk.spr.set_image(tw.media_shapes[shape_dict[btype+'on']],
+ 1, 17, 2)
+ if blk.name == 'journal':
+ pixbuf = get_pixbuf_from_journal(dsobject, 80, 60)
+ if pixbuf is not None:
+ blk.spr.set_image(pixbuf, 1, 17, 2)
+ dsobject.destroy()
+ except:
+ print "couldn't open dsobject (%s)" % (blk.values[0])
+ else:
+ pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(blk.values[0], 80, 60)
+ if pixbuf is not None:
+ blk.spr.set_image(pixbuf, 1, 17, 2)
+ else:
+ blk.spr.set_image(self.media_shapes['journalon'], 1, 17, 2)
+ print "couldn't open media object (%s)" % (blk.values[0])
+ blk.spr.set_label(' ')
+ blk.resize()
+
blk.spr.set_layer(BLOCK_LAYER)
return blk