108
112
avbox.show() # make the vbox visible
109
113
alert.show() # make the alert itself visible
115
def alert_list(title, list):
116
#Launches an alert window with a given text.
118
def abutton_press_event(widget, event, radlist):
119
#Close when "Ok" is pressed
123
retval = radlist.index(i)
125
alert = gtk.Dialog() # make a new window for the alert
126
alert.set_position(gtk.WIN_POS_CENTER) # put it in the center of the screen
127
alert.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) # tell the WM that it is a dialog
128
alert.set_destroy_with_parent(True) # if someone closes SWIFT, we want the alert to close too
129
alert.set_modal(True) # alert should block input to SWIFT until acknowledged
130
alert.set_title(title) # call it what we want to
131
#alert.set_size_request(250, 100) # make it 250x100
132
#avbox = vbox = gtk.VBox(False, 0) # create a vertical box container
133
#alert.add(avbox) # add said container to the alert
137
radiobutton = gtk.RadioButton(radio, str(i))
139
radlist.append(radiobutton)
140
alert.vbox.pack_start(radiobutton, True, False, 0)
143
abutton = gtk.Button("OK") # new button with text "OK"
144
abutton.set_use_stock(True) # it is a stock button provided by GTK
145
abutton.set_size_request(50, -1) # we don't want it as wide as the whole alert
146
abutton.set_events(gtk.gdk.ALL_EVENTS_MASK); # capture clicks, keyboard, anything
147
abutton.connect("button_press_event", abutton_press_event, radlist) # but only listen to the clicks
148
abutton.show() # make button visible
149
ahbox = gtk.HBox(False, 10) # make a new hbox
150
ahbox.pack_start(abutton, True, False, 0) # put the button in it, but don't make it expand
151
alert.vbox.pack_start(ahbox, True, False, 0) # put the hbox in the vbox
152
ahbox.show() # make it visible
153
#avbox.show() # make the vbox visible
154
alert.show() # make the alert itself visible
111
158
def get_pixel_colour(i_x, i_y):
112
159
o_gdk_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 1, 1)
113
160
o_gdk_pixbuf.get_from_drawable(gtk.gdk.get_default_root_window(), gtk.gdk.colormap_get_system(), i_x, i_y, 0, 0, 1, 1)
303
348
cr.set_source_rgba(0.5,0.5,0.5,0.5)
305
352
def drawCurve(gc, drawable, points, filled=False, precision=20):
308
355
r = range(len(points)-2)
310
357
if i/2==int(math.ceil(i/2.0)):
358
s.append(i) #Very opaque function to fill s with all the even numbers in r
313
360
for j in range(precision):
314
361
k=1.0*(precision-j)
315
x=(ave(ave(points[i][0], points[i+1][0], k/precision), ave(points[i+1][0], points[i+2][0], k/precision), k/precision))
316
y=(ave(ave(points[i][1], points[i+1][1], k/precision), ave(points[i+1][1], points[i+2][1], k/precision), k/precision))
362
x=int(ave(ave(points[i][0], points[i+1][0], k/precision), ave(points[i+1][0], points[i+2][0], k/precision), k/precision))
363
y=int(ave(ave(points[i][1], points[i+1][1], k/precision), ave(points[i+1][1], points[i+2][1], k/precision), k/precision))
317
364
npoints.append((x, y))
318
365
if filled==False:
319
366
for i in range(len(npoints)-1):
328
375
cr.fill_preserve()
329
376
#cr.stroke_preserve()
377
def drawcrShape(cr, shapedata, filled=True):
380
cr.move_to(i[1], i[2])
382
cr.line_to(i[1], i[2])
384
cr.curve_to(i[1], i[2], i[3], i[4], i[5], i[6])
389
def drawShape(gc, drawable, shapedata, filled, precision=20):
393
for j in range(precision):
395
x=int(ave(ave(i[1], i[3], k/precision), ave(i[3], i[5], k/precision), k/precision))
396
y=int(ave(ave(i[2], i[4], k/precision), ave(i[4], i[6], k/precision), k/precision))
397
npoints.append((x, y))
399
npoints.append((i[1], i[2]))
402
for i in range(len(npoints)-1):
403
drawLine(gc, drawable, npoints[i][0], npoints[i][1], npoints[i+1][0], npoints[i+1][1])
406
drawable.draw_polygon(gc, 1, npoints)
408
drawable.draw_polygon(gc, 1, npoints)
330
409
def on_key_press(widget, event):
331
410
keyname = gtk.gdk.keyval_name(event.keyval)
365
443
cr.set_line_width(2)
366
444
ccol = currentcolor
369
pixmap=gtk.gdk.Pixmap(None, w, h, 24)
370
colormap=pixmap.get_colormap()
374
if objects[i].type=="box" or objects[i].type=="ellipse" or objects[i].type=="button":
375
gc = gtk.gdk.GC(pixmap, colormap.alloc_color(selectid[selectors.index(i)], True, True), colormap.alloc_color("#000000", True, True))
376
objects[i].draw(cr, gc, pixmap)
446
objects["root"].draw(cr, w, h, stage.get_toplevel().builder.get_object("drawingarea2"))
377
447
if currentframe[level] in currentfile["frames"][0]:
378
448
if not currentselect[level+1] == None:
379
449
if not currentfile["objects"][currentselect[level]].type=="button":
380
450
drawcrBox(cr, currentfile["frames"][currentfile["frames"][0].index(currentframe[level])+1][currentselect[level+1]]["x"]-1, currentfile["frames"][currentfile["frames"][0].index(currentframe[level])+1][currentselect[level+1]]["y"]-1, currentfile["objects"][currentselect[level+1]].width+2, currentfile["objects"][currentselect[level+1]].height+2, 0, [0.0,0.0, 1.0])
381
451
corners = [0, 0, currentfile["objects"][currentselect[level+1]].width+2, currentfile["objects"][currentselect[level+1]].height+2]
383
453
#implement drawcrBox(cr, etc.)
384
454
#gc = gtk.gdk.GC(pixmap, colormap.alloc_color(selectid[selectors.index(j)], True, True), colormap.alloc_color("#000000", True, True))
385
'''x = currentfile["frames"][currentfile["frames"][0].index(currentframe[level])+1][j]["x"]
386
y = currentfile["frames"][currentfile["frames"][0].index(currentframe[level])+1][j]["y"]
387
q = currentfile["objects"][currentselect[level]].frames["idle"]
389
if q[i][i].type=="box":
391
if q[i]["x"]<corners[0]:
392
corners[0]= q[i]["x"]
393
if q[i]["x"]+q[i][i].width>corners[1]:
394
corners[1]= q[i]["x"]+q[i][i].width
395
if q[i]["y"]<corners[2]:
396
corners[2] = q[i]["y"]
397
if q[i]["y"]+q[i][i].height>corners[3]:
398
corners[3] = q[i]["y"]+q[i][i].height
400
corners = [q[i]["x"], q[i]["x"]+q[i][i].width, q[i]["y"], q[i]["y"]+q[i][i].height]
401
drawcrBox(cr, corners[0]+x, corners[2]+y, corners[1]-corners[0], corners[3]-corners[2], 0, [0.0, 0.0, 1.0], 0)'''
402
455
cselname = stage.get_toplevel().builder.get_object("entry1").get_buffer()
403
456
cselname.set_text(str(currentselect[level+1]), 25)
404
457
if not currentselect[level+1]==None:
946
1010
inactive = False
947
1011
drawcrEllipse(cr, x, y, self.width, self.height, self.fill, rotate, [0, 0, 0, 0], inactive)
949
drawEllipse(gc, pixmap, x, y, self.width, self.height, 1, rotate)
1014
drawEllipse(gc, pixmap, x, y, self.width, self.height, 1, rotate)
1016
print "Drawing to offscreen buffer failed. Not a problem if you were exporting an image."
1018
def __init__(self, name, width=0, height=0, parent="root", fill="none"):
1022
self.height = height
1023
self.parent = parent
1024
self.fill = copy.deepcopy(fill)
1025
self.level = objects[parent].level+1
1028
def draw(self, cr, gc=None, pixmap=None, stage=None):
1029
#implement shape.draw()
1034
# x, y, rotate, keyframe=False,
1035
parent = objects[self.parent]
1036
if parent.type=="button":
1037
if not currentframe[self.level-1] in parent.frames[0]:
1038
currentframe[self.level-1]="idle"
1039
if currentframe[self.level-1] in parent.frames[0]:
1040
if self.name in parent.frames[parent.frames[0].index(currentframe[self.level-1])+1]:
1041
x = parent.frames[parent.frames[0].index(currentframe[self.level-1])+1][self.name]["x"]
1042
y = parent.frames[parent.frames[0].index(currentframe[self.level-1])+1][self.name]["y"]
1043
rotate = parent.frames[parent.frames[0].index(currentframe[self.level-1])+1][self.name]["rotate"]
1050
for i in range (0, currentframe[self.level-1]+1):
1051
if parent.frames[0][i]==currentframe[self.level-1]:
1054
elif parent.frames[0][i]<currentframe[self.level-1]:
1058
if self.name in parent.frames[biggest+1]:
1059
if len(parent.frames)>biggest+2 and self.name in parent.frames[biggest+2]["sort"]:
1060
f1 = parent.frames[biggest+1][self.name]
1061
f2 = parent.frames[biggest+2][self.name]
1062
fac = facx(parent.frames[0][biggest], parent.frames[0][biggest+1], currentframe[self.level-1])
1063
x = ave(f2["x"], f1["x"], fac)
1064
y = ave(f2["y"], f1["y"], fac)
1065
rotate = ave(f2["rotate"], f1["rotate"], fac)
1067
f1 = parent.frames[biggest+1][self.name]
1070
rotate = f1["rotate"]
1075
rotate = rotate+parent.rotate
1076
fill = copy.deepcopy(self.fill)
1077
if type(fill)==type([]):
1078
fill = hex2rgb(fill)
1079
if self.level<=level and not self.parent in currentselect:
1083
if type(fill)==type(()) or type(fill)==type([]):
1084
cr.set_source_rgb(fill[0], fill[1], fill[2])
1085
elif fill.startswith("#"):
1086
rgbfill = hex2rgb(fill)
1087
cr.set_source_rgb(rgbfill[0], rgbfill[1], rgbfill[2])
1089
fill = currentfile["colors"]["textures"][fill]
1090
if fill["type"]=="color":
1091
cr.set_source_rgb(fill["fill"][0], fill["fill"][1], fill["fill"][2])
1092
elif fill["type"]=="gradient":
1093
#make this use the gradient
1094
grad = gradient(fill["fill"])
1095
g = cairo.LinearGradient(x, y, x+width, y+height)
1096
for i in range(len(grad)):
1097
g.add_color_stop_rgba(grad[i][0], grad[i][1], grad[i][2], grad[i][3], grad[i][4])
1101
image = currentfile["colors"]["images"][fill["fill"]]
1102
surface = cairo.ImageSurface.create_from_png(image)
1103
pat = cairo.SurfacePattern(surface)
1104
matrix = cairo.Matrix(x0=-x, y0=-y)
1105
pat.set_matrix(matrix)
1107
drawcrShape(cr, self.shapedata, True)
1110
print "Drawing box..."
1111
drawShape(gc, pixmap, self.shapedata, 1)
1112
#drawEllipse(gc, pixmap, 20, 20, 300, 200, 1)
1114
print "Drawing to offscreen buffer failed. Not a problem if you were exporting an image."
1117
stage.window.draw_drawable(gc, pixmap, 0, 0, 0, 0, 500, 500)
951
1119
# Basic class for buttons.
952
def __init__(self, name, width=100, height=100, parent="root"):
1120
def __init__(self, name, width=100, height=100, parent="root", frames=[["idle"],{}]):
953
1121
self.width = width
954
1122
self.height = height
955
1123
self.name = name
956
1124
self.type = "button"
957
1125
self.parent = parent
958
1126
self.level = objects[parent].level+1
959
self.frames = [["idle"],{}]
960
def draw(self, cr, gc=None, pixmap=None):
1127
self.frames = copy.deepcopy(frames)
1128
def draw(self, cr, gc=None, pixmap=None, stage=None):
961
1129
global currentfile
962
1130
global currentframe
1182
def draw(self, cr, w, h, stage):
1184
if currentframe[0] in self.frames[0]:
1187
pixmap=gtk.gdk.Pixmap(None, w, h, 24)
1188
colormap=pixmap.get_colormap()
1189
for i in self.frames[self.frames[0].index(currentframe[0])+1]["sort"]:
1190
gc = gtk.gdk.GC(pixmap, colormap.alloc_color(selectid[selectors.index(i)], True, True), colormap.alloc_color("#000000", True, True))
1191
currentfile["objects"][i].draw(cr, gc, pixmap, stage)
1193
for i in range (0, currentframe[0]+1):
1194
if self.frames[0][i]==currentframe[0]:
1197
elif self.frames[0][i]<currentframe[0]:
1201
for i in self.frames[self.frames[0].index(biggest)+1]["sort"]:
1202
currentfile["objects"][i].draw(cr, None, None)
1204
return "{x = "+str(self.x)+", y = "+str(self.y)+"', rotate = '"+str(self.rotate)+"', level = "+str(self.level)+", frames = "+str(self.frames)+"}"
1012
1206
class SwiftSwfWindow(gtk.Window):
1013
1207
__gtype_name__ = "SwiftSwfWindow"
1017
1210
def AddLibItem(self, item):
1200
print path+title+".swift"
1203
1392
tar = tarfile.open(path+title+".swift", "w:gz")
1204
for i in currentfile["images"]:
1205
tar.add(currentfile["images"][i], i, False)
1206
a.write(str(currentfile))
1393
for i in currentfile["colors"]["images"]:
1394
tar.add(currentfile["colors"]["images"][i], currentfile["colors"]["images"][i].split("/")[-1], False)
1395
currentfilo = copy.deepcopy(currentfile)
1396
for i in currentfilo["colors"]["images"]:
1397
currentfilo["colors"]["images"][i] = currentfilo["colors"]["images"][i].split("/")[-1]
1398
currentfilo["objects"] = {}
1399
a.write(str(currentfilo))
1400
for i in currentfile["objects"]:
1401
j = currentfile["objects"][i]
1402
if j.type=="box" or j.type=="ellipse":
1403
a.write("\n"+j.type+"(\""+j.name+"\","+str(j.width)+","+str(j.height)+",\""+str(j.parent)+"\",\""+str(j.fill)+"\")")
1404
elif j.type=="button":
1405
a.write("\n"+j.type+"(\""+j.name+"\","+str(j.width)+","+str(j.height)+",\""+str(j.parent)+"\","+str(j.frames)+")")
1208
1407
tar.add(path+"currentfile", "currentfile", False)
1210
1409
os.system("rm "+path+"currentfile")
1412
self.save_dialog(widget)
1212
1413
elif title == "Untitled":
1415
self.save_file_as(widget, data)
1217
print "been there, done that."
1219
buff = self.builder.get_object("textview1").get_buffer()
1220
currentfile = str(buff).split("\n")
1221
currentfile[0] = ".flash filename=\""+title+".swf\""
1223
for i in currentfile:
1224
savestring = savestring+str(i)+"\n"
1417
tar = tarfile.open(path+title+".swift", "w:gz")
1418
for i in currentfile["colors"]["images"]:
1419
tar.add(currentfile["colors"]["images"][i], currentfile["colors"]["images"][i].split("/")[-1], False)
1420
currentfilo = copy.deepcopy(currentfile)
1421
for i in currentfilo["colors"]["images"]:
1422
currentfilo["colors"]["images"][i] = "\""+currentfilo["colors"]["images"][i].split("/")[-1]+"\""
1423
currentfilo["objects"] = {}
1424
#for i in currentfilo["colors"]["textures"]
1425
a.write(str(currentfilo))
1426
for i in currentfile["objects"]:
1427
j = currentfile["objects"][i]
1428
if j.type=="box" or j.type=="ellipse":
1429
a.write("\n"+j.type+"(\""+j.name+"\","+str(j.width)+","+str(j.height)+",\""+str(j.parent)+"\",\""+str(j.fill)+"\")")
1430
elif j.type=="button":
1431
a.write("\n"+j.type+"(\""+j.name+"\","+str(j.width)+","+str(j.height)+",\""+str(j.parent)+"\","+str(j.frames)+")")
1433
tar.add(path+"currentfile", "currentfile", False)
1435
os.system("rm "+path+"currentfile")
1436
#self.save_dialog(widget, data)
1230
1438
def open_file(self, widget, data=None):
1234
1442
global currentfile
1443
global currentselect
1235
1444
global selectors
1236
1445
global selectid
1237
1448
#run the open dialog
1238
1449
opener = OpenDialog.NewOpenDialog()
1239
1450
result = opener.run()
1264
1474
currentfilebase.append(i)
1265
1475
currentfile = eval (currentfilebase[0])
1476
objects = currentfile["objects"]
1477
objects["root"] = root()
1478
objects["root"].frames = currentfile["frames"]
1479
for i in range(1, len(currentfilebase)):
1480
obtemp = eval (currentfilebase[i])
1481
currentfile["objects"][obtemp.name] = obtemp
1482
currentselect = ["root", None]
1483
for i in currentfile["colors"]["images"]:
1484
currentfile["colors"]["images"][i] = "/tmp/"+currentfile["colors"]["images"][i]
1267
1487
self.set_title("Swift - "+title+".swift")
1268
1488
selectid=["#000000"]
1269
1489
selectors=[None]
1270
1490
for i in currentfile["objects"]:
1271
1491
self.AddLibItem([None, i, 1])
1272
if currentfile["objects"][i]["type"]=="box":
1492
if currentfile["objects"][i].type=="box":
1273
1493
#Ugly expression meaning add 1 to highest hex value
1274
1494
selectid.append("#01"+("%X" % (int(selectid[-1][3:7], 16)+1)).zfill(4))
1275
1495
selectors.append(i)
1276
elif currentfile["objects"][i]["type"]=="ellipse":
1496
elif currentfile["objects"][i].type=="ellipse":
1277
1497
selectid.append("#02"+("%X" % (int(selectid[-1][3:7], 16)+1)).zfill(4))
1278
1498
selectors.append(i)
1279
elif currentfile["objects"][i]["type"]=="curve":
1499
elif currentfile["objects"][i].type=="curve":
1280
1500
selectid.append("#03"+("%X" % (int(selectid[-1][3:7], 16)+1)).zfill(4))
1281
1501
selectors.append(i)
1302
#TODO:Finish open .sc script
1306
#run the open dialog
1307
opener = OpenscDialog.NewOpenscDialog()
1308
result = opener.run()
1310
filename = opener.get_filename()
1312
patharray = filename.split("/")
1313
title = patharray.pop()
1314
titlearray = title.split(".")
1315
title = titlearray[0]
1320
fc = open(filename, "r")
1324
currentfile = {"fileinfo":{}, "colors":{"gradients":{}, "textures":{}, "images":{}}, "objects":{}, "sprites":{}, "buttons":{}, "frames":[[]]}
1326
currentfilo.append(i)
1332
return (conv (splitlib (b, 0)[0]))
1338
for i in range (j, len(a)):
1344
if c == None or not c[1]>i:
1345
if not a[i] == ".end":
1346
if a[i]==".gradient" or a[i]==".outline" or a[i]==".sprite" or a[i]==".startclip" or a[i]==".button" or a[i]==".action:":
1350
elif a[i]==".frame":
1352
for k in range(int(a[i+1])+1):
1353
framelist.append([])
1354
framelist[int(a[i+1])]=f
1367
print type(i).__name__+" "+str(i)
1368
print "______________________________________________________________________"
1374
for i in range (len(b)):
1376
if not type(b[i]).__name__=="list" and b[i].startswith("."):
1394
#print "buf="+str(buf)
1407
currentfilo=convtext(join(currentfile))
1410
stage = self.builder.get_object("drawingarea1")
1412
stage.set_size_request(512, 512)
1413
colormap = stage.get_colormap()
1414
red = colormap.alloc_color('red', True, True)
1415
stagedraw = stage.window
1416
gc = stagedraw.new_gc(red)
1417
def exposevent(stage, event):
1418
for i in currentfilo:
1419
if currentfilo[i][0] == ".box":
1422
for j in currentfilo:
1423
if j == ".put" and currentfilo[j][0] == i:
1424
print currentfilo[j]
1425
nx = int(currentfilo[j][2].split("=")[1])
1426
ny = int(currentfilo[j][3].split("=")[1])
1428
colo = colormap.alloc_color(currentfilo[i][4].split("=")[1], True, True)
1429
gc.set_foreground(colo)
1430
drawBox(gc, stagedraw, nx, ny, int(currentfilo[i][2]), int(currentfilo[i][3]))
1431
stage.connect("expose-event", exposevent)
1432
#objname=self.builder.get_object("textview3").get_buffer()
1433
for i in currentfilo:
1434
if currentfilo[i][0] == ".box":
1437
image.set_from_file("../media/icon.png")
1439
self.AddLibItem([image, entry, "1"])
1440
#objname.set_text(entry)
1441
buff = self.builder.get_object("textview1").get_buffer()
1442
buff.set_text(str(currentfile))
1444
self.set_title("Swift - "+title+".swift")
1445
#close the dialog, and check whether to proceed
1447
if result != gtk.RESPONSE_OK:
1450
#get the record from CouchDB and extract the text
1453
#record = self.database.get_record(rec_id)
1454
#text = record["text"]
1457
1530
def new_file(self, widget=None, data=None):
1458
1531
global currentfile
1590
1659
fill = str(ob.fill)
1591
1660
output = output+".filled "+i+" outline="+i+"_outline fill="+fill+"\n"
1592
1661
elif ob.type=="button":
1593
alert("GOT TO MAKE CAIRO RENDER THIS TO A TEXTURE!!!!!!!!!!!!!!!")
1594
1662
idlefile = open("/tmp/idlefile"+i+".png", "w")
1595
1663
hoverfile = open("/tmp/hoverfile"+i+".png", "w")
1596
1664
pressedfile = open("/tmp/pressedfile"+i+".png", "w")
1597
1665
hitfile = open("/tmp/hitfile"+i+".png", "w")
1598
idlesurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 512, 512)
1599
hoversurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 512, 512)
1600
pressedsurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 512, 512)
1601
hitsurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 512, 512)
1666
idlesurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
1667
hoversurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
1668
pressedsurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
1669
hitsurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
1602
1670
idlecr = cairo.Context(idlesurf)
1603
1671
hovercr = cairo.Context(hoversurf)
1604
1672
pressedcr = cairo.Context(pressedsurf)
1605
1673
hitcr = cairo.Context(hitsurf)
1606
idle = currentfile["objects"][i].frames["idle"]
1607
if not "hover" in currentfile["objects"][i].frames:
1608
hover = currentfile["objects"][i].frames["idle"]
1610
currentfile["objects"][i].frames["hover"]
1611
if not "pressed" in currentfile["objects"][i].frames:
1612
pressed = currentfile["objects"][i].frames["idle"]
1614
pressed = currentfile["objects"][i].frames["pressed"]
1615
if not "hit" in currentfile["objects"][i].frames:
1616
hit = currentfile["objects"][i].frames["idle"]
1618
hit = currentfile["objects"][i].frames["hit"]
1674
idlecr.translate(-ob.x, -ob.y)
1675
hovercr.translate(-ob.x, -ob.y)
1676
pressedcr.translate(-ob.x, -ob.y)
1677
hitcr.translate(-ob.x, -ob.y)
1678
idle = ob.frames[ob.frames[0].index("idle")+1]
1679
if not "hover" in ob.frames[0]:
1680
hover = ob.frames[ob.frames[0].index("idle")+1]
1682
hover = ob.frames[ob.frames[0].index("hover")+1]
1683
if not "pressed" in ob.frames[0]:
1684
pressed = ob.frames[ob.frames[0].index("idle")+1]
1686
pressed = ob.frames[ob.frames[0].index("pressed")+1]
1687
if not "hit" in ob.frames[0]:
1688
hit = ob.frames[ob.frames[0].index("idle")+1]
1690
hit = ob.frames[ob.frames[0].index("hit")+1]
1621
idle[j][j].draw(idle[j]["x"], idle[j]["y"], idle[j]["rotate"], idlecr)
1692
idle[j][j].draw(idlecr, None, None)
1622
1693
for j in hover:
1623
hover[j][j].draw(hover[j]["x"], hover[j]["y"], hover[j]["rotate"], hovercr)
1694
hover[j][j].draw(hovercr, None, None)
1624
1695
for j in pressed:
1625
pressed[j][j].draw(pressed[j]["x"], pressed[j]["y"], pressed[j]["rotate"], pressedcr)
1696
pressed[j][j].draw(pressedcr, None, None)
1627
hit[j][j].draw(hit[j]["x"], hit[j]["y"], hit[j]["rotate"], hitcr)
1698
hit[j][j].draw(hitcr, None, None)
1629
1700
idlesurf.write_to_png(idlefile)
1630
1701
hoversurf.write_to_png(hoverfile)
1753
1837
image.set_from_file("../media/icon.png")
1755
1839
self.AddLibItem([image, entry, "1"])
1758
1840
importer.destroy()
1759
1842
def import_file_to_stage(self, widget, data=None):
1760
self.import_file(widget, data)
1843
stage = self.builder.get_object("drawingarea1")
1844
filename = self.import_file(widget, data)
1846
im = Image.open(filename)
1848
alert(filename+" is not a valid image file!")
1851
newname = filename.split("/")[-1].split(".")[0]
1852
if not newname in objects:
1853
# CHANGE THE PARENT TO BE THE APPROPRIATE OBJECT
1854
objects[newname] = box(newname, size[0], size[1], "root", newname)
1855
for i in range(1, len(objects[objects[newname].parent].frames)):
1856
objects[objects[newname].parent].frames[i]["sort"].append(newname)
1857
objects[objects[newname].parent].frames[i][newname] = {"x":0, "y":0, "rotate":0}
1859
objects[objects[newname].parent].frames[i][newname]["put"] = True
1860
selectid.append("#01"+("%X" % (int(selectid[-1][3:7], 16)+1)).zfill(4))
1861
selectors.append(newname)
1862
expostagevent(stage, "expose-event")
1864
alert("There is already an object called "+newname+" in the current project. I will just abandon this attempt because the alert window only has one button.")
1762
1866
def draw_rect(self, widget, data=None):
2491
2577
def export_image(self, widget, data=None):
2492
alert("Image export is not implemented yet. Wait for the beta!")
2581
savedial = SaveDialog.NewSaveDialog()
2582
result = savedial.run()
2583
filename = savedial.get_filename()
2585
whatodo = alert_list("What do do want to do?", ["Export current frame as PNG", "Pi!", "Export all frames as one PNG", "Export all frames as PNG sequence"])
2586
lastcf = copy.deepcopy(currentframe)
2589
if filename.split(".")[-1]=="png":
2591
png = open(filename, "w")
2592
surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 512, 512)
2593
cr = cairo.Context(surf)
2594
currentfile["objects"]["root"].draw(cr, 512, 512)
2595
surf.write_to_png(png)
2599
png = open(filename, "w")
2600
surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 512, 512)
2601
cr = cairo.Context(surf)
2602
for i in range(currentfile["objects"]["root"].frames[0][-1]):
2604
currentfile["objects"]["root"].draw(cr, 512, 512)
2605
surf.write_to_png(png)
2609
for i in range(currentfile["objects"]["root"].frames[0][-1]):
2610
filename1 = filename.split(".")
2611
filename1 = filename1[0]+str(i).zfill(3)+filename1[1]
2612
png = open(filename1, "w")
2613
surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 512, 512)
2614
cr = cairo.Context(surf)
2616
currentfile["objects"]["root"].draw(cr, 512, 512)
2617
surf.write_to_png(png)
2621
currentframe = lastcf
2493
2622
def export_video(self, widget, data=None):
2494
2623
alert("Video export is not implemented yet. Wait for the beta!")
2495
2624
def export_pdf(self, widget, data=None):
2647
2774
alert("Not complete")
2648
2775
dialog = DocumentDialog.NewDocumentDialog()
2649
2776
result = dialog.run()
2777
def console(self, widget, data="None"):
2778
Credits = "Everything © 2011 Skyler Lehmkuhl."
2781
for i in consoledir:
2782
locals()[i] = consoledir[i]
2784
a = b.split("/")[-1].split(".")[0]
2786
globals()[a] = __import__(b)
2788
globals()[a] = imp.load_source(a, b)
2789
return "Imported "+a
2795
global currentselect
2796
self.__cf = currentfile
2797
self.__id = selectid
2798
self.__cc = currentcolor
2799
self.__cs = currentselect
2800
def addBox(self, x, y, w, h):
2804
if type(currentcolor)==type([]):
2805
newcolor = "rgb"+rgb2hex(self.__cc[0], self.__cc[1], self.__cc[2])[1:]
2806
self.__cf["colors"]["textures"][newcolor]={"type":"color", "fill":[self.__cc[0], self.__cc[1], self.__cc[2]]}
2807
self.__cf["objects"]["b"+str(biter)]=box("b"+str(biter), w, h, self.__cs[level], newcolor)
2809
self.__cf["objects"]["b"+str(biter)]=box("b"+str(biter), w, h, self.__cs[level], self.__cc)
2810
self.__id.append("#01"+("%X" % (int(self.__id[-1][3:7], 16)+1)).zfill(4))
2811
selectors.append("b"+str(biter))
2812
for i in range(self.__cf["frames"][0].index(currentframe[level]), len(self.__cf["frames"][0])):
2813
self.__cf["frames"][i+1]["b"+str(biter)]={"put":True, "x":x, "y":y, "rotate":0}
2814
self.__cf["frames"][i+1]["sort"].append("b"+str(biter))
2816
return "Added new box."
2817
def addEllipse(self, x, y, w, h):
2821
if type(currentcolor)==type([]):
2822
newcolor = "rgb"+rgb2hex(self.__cc[0], self.__cc[1], self.__cc[2])[1:]
2823
self.__cf["colors"]["textures"][newcolor]={"type":"color", "fill":[self.__cc[0], self.__cc[1], self.__cc[2]]}
2824
self.__cf["objects"]["e"+str(eiter)]=ellipse("e"+str(eiter), w, h, self.__cs[level], newcolor)
2826
self.__cf["objects"]["e"+str(eiter)]=ellipse("e"+str(eiter), w, h, self.__cs[level], self.__cc)
2827
self.__id.append("#01"+("%X" % (int(self.__id[-1][3:7], 16)+1)).zfill(4))
2828
selectors.append("e"+str(eiter))
2829
for i in range(self.__cf["frames"][0].index(currentframe[level]), len(self.__cf["frames"][0])):
2830
self.__cf["frames"][i+1]["e"+str(eiter)]={"put":True, "x":x, "y":y, "rotate":0}
2831
self.__cf["frames"][i+1]["sort"].append("e"+str(eiter))
2833
return "Added new ellipse."
2835
expostagevent(window.builder.get_object("drawingarea1"), "expose-event")
2836
return "Redrawing stage."
2851
global currentselect
2865
global SWIFT_VERSION
2868
locals()["currentfile"] = currentfile
2869
locals()["currentframe"] = currentframe
2870
locals()["path"] = path
2871
locals()["title"] = title
2872
locals()["mode"] = mode
2873
locals()["clicked"] = clicked
2874
locals()["drawitems"] = drawitems
2875
locals()["biter"] = biter
2876
locals()["eiter"] = eiter
2877
locals()["citer"] = citer
2878
locals()["fiter"] = fiter
2879
locals()["step"] = step
2880
locals()["currentcurve"] = currentcurve
2881
locals()["currentselect"] = currentselect
2882
locals()["currentcolor"] = currentcolor
2883
locals()["selectid"] = selectid
2884
locals()["source_id"] = source_id
2885
locals()["selectors"] = selectors
2886
locals()["undostack"] = undostack
2887
locals()["redostack"] = redostack
2888
locals()["doubleclick"] = doubleclick
2889
locals()["outputwin"] = outputwin
2890
locals()["level"] = level
2891
locals()["outbox"] = outbox
2892
locals()["outbuffer"] = outbuffer
2893
locals()["objects"] = objects
2894
locals()["tnum"] = tnum
2895
locals()["SWIFT_VERSION"] = SWIFT_VERSION
2896
locals()["SWIFT_COMPAT"] = SWIFT_COMPAT
2897
window.builder.get_object("checkbutton1").set_visible(True)
2898
print "ROOTROOTROOTROOT"
2900
def __init__(self, window):
2901
self.terminal = sys.stdout
2902
self.buffer = window.builder.get_object("textview3").get_buffer()
2903
self.type = "writer"
2904
def write(self, message):
2905
self.terminal.write(message)
2906
self.buffer.set_text(self.buffer.get_text(self.buffer.get_start_iter(), self.buffer.get_end_iter())+message)
2907
def help(func=None):
2909
return "Current commands are: \"help()\", \"Credits\", \"set()\", \"load()\" and if you know what you are doing, \"swiftroot()\"\nOr type help(\"function\") to get information about that function."
2910
elif func=="Credits" or func==Credits:
2911
return "Credits is not a function. Just type Credits (no parentheses)."
2912
elif func=="set" or func=="set()":
2913
return "set() sets a variable to a value. Use it instead of an equals sign.\nYou chould enclose the variable name in quotes, i.e. set(\"foo\", 5)."
2914
elif func=="sw" or func=="sw()":
2915
return "sw is the class used to access Swift. Its usage is:\n\tsw().function(arguments)\n\nHere is a list of functions:\n\taddBox(x, y, width, height)\n\taddEllipse(x, y, width, height)\n\tredraw()"
2916
elif func=="load" or func=="load()":
2917
return "load() is the function used to load custom modules. This allows you to write scripts to do useful things in SWIFT, or just cool things like fractals.\nUseage:\n\tload(\"/path/to/module.py\")"
2918
elif func=="function":
2919
return "No, I meant you type a quote, then the name of the function, then another quote. Like this:\n\thelp(\"set\")"
2920
def set(arg1, arg2):
2922
return "You must put quotes around the first argument!"
2927
consoledir[arg1] = arg2
2932
return "Be warned, this will give you complete access to all internal variables in SWIFT. DO NOT do this unless you have read the source code (or seriously don't care about the current file!)!!!\nIf you didn't want to become root, type set(SWIFT_ROOT, False)"
2934
if window.builder.get_object("checkbutton1").get_active():
2936
stype = sys.stdout.type
2938
sys.stdout = STDOUTWRITER(window)
2940
stype = sys.stderr.type
2942
sys.stderr = STDOUTWRITER(window)
2943
exec widget.get_text() in globals(), locals()
2946
window.builder.get_object("textview3").get_buffer().set_text(window.builder.get_object("textview3").get_buffer().get_text(window.builder.get_object("textview3").get_buffer().get_start_iter(), window.builder.get_object("textview3").get_buffer().get_end_iter())+"\n"+str(eval(widget.get_text())))
2947
except NameError as n:
2949
consoledir[i[6:-16]]=None
2951
window.builder.get_object("textview3").get_buffer().set_text(window.builder.get_object("textview3").get_buffer().get_text(window.builder.get_object("textview3").get_buffer().get_start_iter(), window.builder.get_object("textview3").get_buffer().get_end_iter())+"\n"+str(eval(widget.get_text())))
2952
except Exception as e:
2953
window.builder.get_object("textview3").get_buffer().set_text(window.builder.get_object("textview3").get_buffer().get_text(window.builder.get_object("textview3").get_buffer().get_start_iter(), window.builder.get_object("textview3").get_buffer().get_end_iter())+"\n"+str(e))
2954
window.builder.get_object("textview3").set_wrap_mode(gtk.WRAP_CHAR)
2955
window.builder.get_object("textview3").scroll_mark_onscreen(window.builder.get_object("textview3").get_buffer().get_insert())
2652
2960
def NewSwiftSwfWindow():
2705
3024
objects = {"root":theoneroot}
2706
3025
b0 = box("b0", 256, 256, "root", "t2")
2707
3026
e0 = ellipse("e0", 300, 100, "root", "turquoise")
2708
currentfile = {"fileinfo":{"fps":25, "bbox":[500, 500, 0, 0]}, "colors":{"gradients":{"gr1":[[0.0, 0.0, 0.0, 1.0, 1], [0.5, 0.0, 1.0, 0.0, 1], [1.0, 1.0, 0.0, 0.0, 1]]}, "textures":{"t1":{"type":"gradient", "fill":"gr1"}, "t2":{"type":"image", "fill":"i1"}, "turquoise":{"type":"color", "fill":[0.0, 1.0, 1.0]}}, "images":{"i1":"/usr/share/swift-swf/media/icon.png"}}, "objects":{"b0":b0, "e0":e0}, "sprites":{}, "buttons":{}, "actions":[""], "frames":[[0], {"sort":["b0", "e0"], "b0":{"put":True, "x":100, "y":100, "rotate":0}, "e0":{"put":True, "x":200, "y":300, "rotate":-0.5}}]}
3027
s0 = shape("s0", 280, 280, "root", "turquoise")
3028
s0.shapedata = [["M", 20, 20], ["L", 300, 20], ["L", 300, 300], ["C", 20, 300, 300, 20, 20, 20]]
3029
currentfile = {"fileinfo":{"fps":25, "bbox":[500, 500, 0, 0]}, "colors":{"gradients":{"gr1":[[0.0, 0.0, 0.0, 1.0, 1], [0.5, 0.0, 1.0, 0.0, 1], [1.0, 1.0, 0.0, 0.0, 1]]}, "textures":{"t1":{"type":"gradient", "fill":"gr1"}, "t2":{"type":"image", "fill":"i1"}, "turquoise":{"type":"color", "fill":[0.0, 1.0, 1.0]}}, "images":{"i1":"/usr/share/swift-swf/media/icon.png"}}, "objects":{"b0":b0, "e0":e0, "s0":s0}, "sprites":{}, "buttons":{}, "actions":[""], "frames":[[0], {"sort":["s0", "b0", "e0"], "s0":{"put":True, "x":20, "y":20, "rotate":0}, "b0":{"put":True, "x":100, "y":100, "rotate":0}, "e0":{"put":True, "x":200, "y":300, "rotate":-0.5}}]}
2709
3030
objects = currentfile["objects"]
2710
3031
objects["root"] = theoneroot
2711
3032
objects["root"].frames = currentfile["frames"]