Save reworked to use .tar.gz files - to pack resources
This commit is contained in:
parent
d2a1640a6b
commit
77a18d15c4
|
|
@ -0,0 +1,7 @@
|
||||||
|
Roadmap
|
||||||
|
|
||||||
|
✓ Images
|
||||||
|
|
||||||
|
- Drawing
|
||||||
|
- Line width
|
||||||
|
- Better paint bucket (separate object)
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
# © 2012 Skyler Lehmkuhl
|
# © 2012 Skyler Lehmkuhl
|
||||||
# Released under the GPLv3. For more information, see gpl.txt.
|
# Released under the GPLv3. For more information, see gpl.txt.
|
||||||
|
|
||||||
import os, shutil
|
import os, shutil, tarfile, tempfile, StringIO
|
||||||
|
|
||||||
#Uncomment to build on OS X
|
#Uncomment to build on OS X
|
||||||
#import objc, AppKit, cPickle
|
#import objc, AppKit, cPickle
|
||||||
|
|
@ -312,18 +312,37 @@ def new_file(widget=None):
|
||||||
def open_file(widget=None):
|
def open_file(widget=None):
|
||||||
global root
|
global root
|
||||||
MainWindow.stage.delete(root)
|
MainWindow.stage.delete(root)
|
||||||
thefile = svlgui.file_dialog("open").open("rb")
|
thetarfile = tarfile.open(fileobj=svlgui.file_dialog("open").open("rb"),mode="r:gz")
|
||||||
root = pickle.load(thefile)
|
basefile = thetarfile.extractfile("basefile")
|
||||||
|
root, svlgui.Library = pickle.load(basefile)
|
||||||
MainWindow.stage.add(root, 0, 0)
|
MainWindow.stage.add(root, 0, 0)
|
||||||
MainWindow.stage.draw()
|
MainWindow.stage.draw()
|
||||||
MainWindow.timelinebox.root = root
|
MainWindow.timelinebox.root = root
|
||||||
MainWindow.timelinebox.draw()
|
MainWindow.timelinebox.draw()
|
||||||
|
thetarfile.close()
|
||||||
def open_sc_file(widget=None):
|
def open_sc_file(widget=None):
|
||||||
pass
|
pass
|
||||||
def save_file(widget=None):
|
def save_file(widget=None):
|
||||||
thefile = svlgui.file_dialog("save").open("w")
|
data = pickle.dumps((root,svlgui.Library))
|
||||||
pickle.dump(root, thefile)
|
tarinfo = tarfile.TarInfo('basefile')
|
||||||
print thefile
|
tarinfo.size = len(data)
|
||||||
|
if svlgui.FILE.name.startswith(svlgui.TEMPDIR):
|
||||||
|
thetarfile = tarfile.open(fileobj=svlgui.file_dialog("save").open('wb'),mode="w:gz")
|
||||||
|
print thetarfile.name
|
||||||
|
else:
|
||||||
|
thetarfile = tarfile.open(svlgui.FILE.name,mode="w:gz")
|
||||||
|
thetarfile.addfile(tarinfo, StringIO.StringIO(data))
|
||||||
|
#Save the path so we can come back here
|
||||||
|
lastpath = os.path.abspath(".")
|
||||||
|
for i in svlgui.Library:
|
||||||
|
if i.type=="Image":
|
||||||
|
os.chdir(os.sep.join(i.path.split(os.sep)[:-1]))
|
||||||
|
i.path = i.path.split(os.sep)[-1]
|
||||||
|
thetarfile.add(i.path.split(os.sep)[-1])
|
||||||
|
os.chdir(lastpath)
|
||||||
|
thetarfile.close()
|
||||||
|
svlgui.FILE = thetarfile
|
||||||
|
#thetarfile.close()
|
||||||
def save_file_as(widget=None):
|
def save_file_as(widget=None):
|
||||||
pass
|
pass
|
||||||
def import_to_stage(widget=None):
|
def import_to_stage(widget=None):
|
||||||
|
|
@ -430,7 +449,7 @@ svlgui.menufuncs([["File",
|
||||||
("Add Layer",add_layer,"<Shift><Control>N"),
|
("Add Layer",add_layer,"<Shift><Control>N"),
|
||||||
("Delete Layer",delete_layer,"<Shift><Control>Delete")],
|
("Delete Layer",delete_layer,"<Shift><Control>Delete")],
|
||||||
["Import",
|
["Import",
|
||||||
("Import to Stage",import_to_stage),
|
("Import to Stage",import_to_stage,"/I"),
|
||||||
("Import to Library",import_to_library)],
|
("Import to Library",import_to_library)],
|
||||||
["Export",
|
["Export",
|
||||||
"Export .swf",
|
"Export .swf",
|
||||||
|
|
|
||||||
121
svlgui.py
121
svlgui.py
|
|
@ -150,6 +150,7 @@ if sys.platform=="linux2":
|
||||||
### TESTING - gtk should be Linux platform, at least for now ####
|
### TESTING - gtk should be Linux platform, at least for now ####
|
||||||
#'''
|
#'''
|
||||||
import pickle
|
import pickle
|
||||||
|
import tarfile
|
||||||
import GUI # Using PyGUI. Experimental.
|
import GUI # Using PyGUI. Experimental.
|
||||||
from GUI import Window as OSXWindow, Button as OSXButton, Image as OSXImage
|
from GUI import Window as OSXWindow, Button as OSXButton, Image as OSXImage
|
||||||
from GUI import Frame as OSXFrame, Color as OSXColor, Grid as OSXGrid
|
from GUI import Frame as OSXFrame, Color as OSXColor, Grid as OSXGrid
|
||||||
|
|
@ -162,6 +163,7 @@ if sys.platform=="linux2":
|
||||||
from GUI.Geometry import offset_rect, rect_sized
|
from GUI.Geometry import offset_rect, rect_sized
|
||||||
#app = GUI.application()
|
#app = GUI.application()
|
||||||
SYSTEM="osx"
|
SYSTEM="osx"
|
||||||
|
TEMPDIR = "/tmp"
|
||||||
'''
|
'''
|
||||||
SYSTEM="html"
|
SYSTEM="html"
|
||||||
ids = {}
|
ids = {}
|
||||||
|
|
@ -171,6 +173,7 @@ if sys.platform=="linux2":
|
||||||
elif sys.platform=="win32":
|
elif sys.platform=="win32":
|
||||||
PLATFORM="win32"
|
PLATFORM="win32"
|
||||||
import pickle
|
import pickle
|
||||||
|
import tarfile
|
||||||
import misc_funcs
|
import misc_funcs
|
||||||
import GUI # Using PyGUI. Experimental.
|
import GUI # Using PyGUI. Experimental.
|
||||||
from GUI import Window as OSXWindow, Button as OSXButton, Image as OSXImage
|
from GUI import Window as OSXWindow, Button as OSXButton, Image as OSXImage
|
||||||
|
|
@ -183,11 +186,14 @@ elif sys.platform=="win32":
|
||||||
from GUI.Files import FileType
|
from GUI.Files import FileType
|
||||||
from GUI.Geometry import offset_rect, rect_sized
|
from GUI.Geometry import offset_rect, rect_sized
|
||||||
SYSTEM="osx"
|
SYSTEM="osx"
|
||||||
|
TEMPDIR="C:\\Windows\\Temp"
|
||||||
sep = "\\"
|
sep = "\\"
|
||||||
elif sys.platform=="linux-armv6l":
|
elif sys.platform=="linux-armv6l":
|
||||||
import android
|
import android
|
||||||
|
import tarfile
|
||||||
droid = android.Android()
|
droid = android.Android()
|
||||||
SYSTEM="android"
|
SYSTEM="android"
|
||||||
|
TEMPDIR="/tmp" # TODO:FIXTHIS
|
||||||
tb = ""
|
tb = ""
|
||||||
sep = "/"
|
sep = "/"
|
||||||
print str(sys.platform)
|
print str(sys.platform)
|
||||||
|
|
@ -195,6 +201,7 @@ elif sys.platform=="darwin":
|
||||||
PLATFORM="osx"
|
PLATFORM="osx"
|
||||||
import pickle
|
import pickle
|
||||||
import misc_funcs
|
import misc_funcs
|
||||||
|
import tarfile
|
||||||
import GUI # Using PyGUI. Experimental.
|
import GUI # Using PyGUI. Experimental.
|
||||||
from GUI import Window as OSXWindow, Button as OSXButton, Image as OSXImage
|
from GUI import Window as OSXWindow, Button as OSXButton, Image as OSXImage
|
||||||
from GUI import Frame as OSXFrame, Color as OSXColor, Grid as OSXGrid
|
from GUI import Frame as OSXFrame, Color as OSXColor, Grid as OSXGrid
|
||||||
|
|
@ -207,8 +214,12 @@ elif sys.platform=="darwin":
|
||||||
from GUI.Geometry import offset_rect, rect_sized
|
from GUI.Geometry import offset_rect, rect_sized
|
||||||
#app = GUI.application()
|
#app = GUI.application()
|
||||||
SYSTEM="osx"
|
SYSTEM="osx"
|
||||||
|
TEMPDIR="/tmp"
|
||||||
sep = "/"
|
sep = "/"
|
||||||
|
|
||||||
|
FILE = tarfile.open(name=TEMPDIR+"/Untitled",mode="w:gz")
|
||||||
|
FILE.close()
|
||||||
|
|
||||||
__windowlist__=[]
|
__windowlist__=[]
|
||||||
|
|
||||||
if SYSTEM=="osx":
|
if SYSTEM=="osx":
|
||||||
|
|
@ -874,6 +885,11 @@ class TextEntry(Widget):
|
||||||
text = property(get_text, set_text)
|
text = property(get_text, set_text)
|
||||||
|
|
||||||
class Image(object):
|
class Image(object):
|
||||||
|
def __getstate__(self):
|
||||||
|
dict = self.__dict__.copy()
|
||||||
|
print dict
|
||||||
|
dict['image'] = None
|
||||||
|
return dict
|
||||||
def __init__(self,image,x=0,y=0,animated=False,canvas=None,htiles=1,vtiles=1,skipl=False):
|
def __init__(self,image,x=0,y=0,animated=False,canvas=None,htiles=1,vtiles=1,skipl=False):
|
||||||
if not skipl:
|
if not skipl:
|
||||||
global Library
|
global Library
|
||||||
|
|
@ -1226,27 +1242,31 @@ class Shape (object):
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
class framewrapper (object):
|
class framewrapper (object):
|
||||||
#Wraps object per-frame. Allows for changes in position, rotation, scale.
|
#def __getstate__(self):
|
||||||
def __init__(self, obj, x, y, rot, scalex, scaley, parent=None):
|
# dict = self.__dict__.copy()
|
||||||
self.obj = obj
|
# dict['parent'] = None
|
||||||
self.x = obj.x = x
|
# return dict
|
||||||
self.y = obj.y = y
|
#Wraps object per-frame. Allows for changes in position, rotation, scale.
|
||||||
self.rot = obj.rot = rot
|
def __init__(self, obj, x, y, rot, scalex, scaley, parent=None):
|
||||||
self.scalex = obj.scalex = scalex
|
self.obj = obj
|
||||||
self.scaley = obj.scaley = scaley
|
self.x = obj.x = x
|
||||||
self.level = False # don't try to descend into a framewrapper
|
self.y = obj.y = y
|
||||||
self.type = obj.__class__.__name__
|
self.rot = obj.rot = rot
|
||||||
if obj.__class__.__name__=="Shape":
|
self.scalex = obj.scalex = scalex
|
||||||
self.filled = obj.filled
|
self.scaley = obj.scaley = scaley
|
||||||
self.linecolor = obj.linecolor
|
self.level = False # don't try to descend into a framewrapper
|
||||||
self.fillcolor = obj.fillcolor
|
self.type = obj.__class__.__name__
|
||||||
self.name = obj.name
|
if obj.__class__.__name__=="Shape":
|
||||||
self.parent = parent
|
self.filled = obj.filled
|
||||||
def draw(self,cr,transform):
|
self.linecolor = obj.linecolor
|
||||||
|
self.fillcolor = obj.fillcolor
|
||||||
|
self.name = obj.name
|
||||||
|
self.parent = parent
|
||||||
|
def draw(self,cr,transform):
|
||||||
pass
|
pass
|
||||||
self.update()
|
self.update()
|
||||||
self.obj.draw(cr,transform)
|
self.obj.draw(cr,transform)
|
||||||
def update(self):
|
def update(self):
|
||||||
self.obj.x = self.x
|
self.obj.x = self.x
|
||||||
self.obj.y = self.y
|
self.obj.y = self.y
|
||||||
self.obj.rot = self.rot
|
self.obj.rot = self.rot
|
||||||
|
|
@ -1256,49 +1276,55 @@ class framewrapper (object):
|
||||||
self.obj.filled = self.filled
|
self.obj.filled = self.filled
|
||||||
self.obj.linecolor = self.linecolor
|
self.obj.linecolor = self.linecolor
|
||||||
self.obj.fillcolor = self.fillcolor
|
self.obj.fillcolor = self.fillcolor
|
||||||
def _onMouseDown(self, x, y):
|
def _onMouseDown(self, x, y):
|
||||||
self.obj.onMouseDown(self,x, y)
|
self.obj.onMouseDown(self,x, y)
|
||||||
def _onMouseUp(self, x, y):
|
def _onMouseUp(self, x, y):
|
||||||
self.obj.onMouseUp(self,x, y)
|
self.obj.onMouseUp(self,x, y)
|
||||||
def _onMouseMove(self, x, y):
|
def _onMouseMove(self, x, y):
|
||||||
self.obj.onMouseMove(self, x, y)
|
self.obj.onMouseMove(self, x, y)
|
||||||
def _onMouseDrag(self, x, y):
|
def _onMouseDrag(self, x, y):
|
||||||
self.obj.onMouseDrag(self, x, y)
|
self.obj.onMouseDrag(self, x, y)
|
||||||
def _onKeyDown(self, key):
|
def _onKeyDown(self, key):
|
||||||
self.obj.onKeyDown(self, key)
|
self.obj.onKeyDown(self, key)
|
||||||
def _onKeyUp(self, key):
|
def _onKeyUp(self, key):
|
||||||
self.obj.onKeyUp(self, key)
|
self.obj.onKeyUp(self, key)
|
||||||
def getminx(self):
|
def getminx(self):
|
||||||
return self.obj.minx+self.x
|
return self.obj.minx+self.x
|
||||||
def getminy(self):
|
def getminy(self):
|
||||||
return self.obj.miny+self.y
|
return self.obj.miny+self.y
|
||||||
def getmaxx(self):
|
def getmaxx(self):
|
||||||
return self.obj.maxx
|
return self.obj.maxx
|
||||||
def getmaxy(self):
|
def getmaxy(self):
|
||||||
return self.obj.maxy
|
return self.obj.maxy
|
||||||
minx = property(getminx)
|
minx = property(getminx)
|
||||||
miny = property(getminy)
|
miny = property(getminy)
|
||||||
maxx = property(getmaxx)
|
maxx = property(getmaxx)
|
||||||
maxy = property(getmaxy)
|
maxy = property(getmaxy)
|
||||||
def hitTest(self, x, y):
|
def hitTest(self, x, y):
|
||||||
x,y = self.transformcoords(x,y)
|
x,y = self.transformcoords(x,y)
|
||||||
return self.obj.hitTest(x, y)
|
return self.obj.hitTest(x, y)
|
||||||
def transformcoords(self,x,y):
|
def transformcoords(self,x,y):
|
||||||
x = x-self.x
|
x = x-self.x
|
||||||
y = y-self.y
|
y = y-self.y
|
||||||
return x,y
|
return x,y
|
||||||
|
|
||||||
|
|
||||||
class frame:
|
class frame:
|
||||||
def __init__(self,parent,duplicate=None):
|
def __reduce__(self):
|
||||||
self.objs = []
|
badvars = (self.parent,self.group)
|
||||||
self.currentselect=None
|
self.parent = None
|
||||||
self.type="Group"
|
ret = pickle.dumps(self)
|
||||||
self.parent = parent
|
self.parent, self.group = badvars
|
||||||
self.actions = ''
|
return ret
|
||||||
def add(self, obj, x, y, rot=0, scalex=0, scaley=0):
|
def __init__(self,parent,duplicate=None):
|
||||||
|
self.objs = []
|
||||||
|
self.currentselect=None
|
||||||
|
self.type="Group"
|
||||||
|
self.parent = parent
|
||||||
|
self.actions = ''
|
||||||
|
def add(self, obj, x, y, rot=0, scalex=0, scaley=0):
|
||||||
self.objs.append(framewrapper(obj, x, y, rot, scalex, scaley, self.objs))
|
self.objs.append(framewrapper(obj, x, y, rot, scalex, scaley, self.objs))
|
||||||
def play(self, group, cr, currentselect,transform,rect):
|
def play(self, group, cr, currentselect,transform,rect):
|
||||||
if SYSTEM=="gtk":
|
if SYSTEM=="gtk":
|
||||||
cr.save()
|
cr.save()
|
||||||
cr.translate(group.x,group.y)
|
cr.translate(group.x,group.y)
|
||||||
|
|
@ -1355,17 +1381,17 @@ class frame:
|
||||||
tb+="cr.stroke()\n"
|
tb+="cr.stroke()\n"
|
||||||
tb+="cr.restore()\n"
|
tb+="cr.restore()\n"
|
||||||
jscommunicate(tb)
|
jscommunicate(tb)
|
||||||
def localtransform(self,x,y):
|
def localtransform(self,x,y):
|
||||||
radrot = self.group.rotation*math.pi/180.0
|
radrot = self.group.rotation*math.pi/180.0
|
||||||
nx = x*math.cos(-radrot)-y*math.sin(-radrot)-self.group.x
|
nx = x*math.cos(-radrot)-y*math.sin(-radrot)-self.group.x
|
||||||
ny = x*math.sin(-radrot)+y*math.cos(-radrot)-self.group.y
|
ny = x*math.sin(-radrot)+y*math.cos(-radrot)-self.group.y
|
||||||
return nx, ny
|
return nx, ny
|
||||||
def revlocaltransform(self,x,y):
|
def revlocaltransform(self,x,y):
|
||||||
radrot = self.group.rotation*math.pi/180.0
|
radrot = self.group.rotation*math.pi/180.0
|
||||||
nx = x*math.cos(radrot)-y*math.sin(radrot)-self.group.x
|
nx = x*math.cos(radrot)-y*math.sin(radrot)-self.group.x
|
||||||
ny = x*math.sin(radrot)+y*math.cos(radrot)-self.group.y
|
ny = x*math.sin(radrot)+y*math.cos(radrot)-self.group.y
|
||||||
return nx, ny
|
return nx, ny
|
||||||
def print_sc(self):
|
def print_sc(self):
|
||||||
retval = ""
|
retval = ""
|
||||||
if self==self.parent.frames[0]:
|
if self==self.parent.frames[0]:
|
||||||
for i in self.objs:
|
for i in self.objs:
|
||||||
|
|
@ -2190,10 +2216,10 @@ class FramesCanvas(Canvas):
|
||||||
cr.newpath()
|
cr.newpath()
|
||||||
cr.rect([i*16,k*32,i*16+16,k*32+32])
|
cr.rect([i*16,k*32,i*16+16,k*32+32])
|
||||||
if self.root.descendItem().activeframe==i:
|
if self.root.descendItem().activeframe==i:
|
||||||
cr.fillcolor = Color([0.2,0.2,0.2]).pygui
|
cr.fillcolor = Color([0.5,0.5,0.5]).pygui
|
||||||
cr.fill()
|
cr.fill()
|
||||||
elif i%5==0:
|
elif i%5==0:
|
||||||
cr.fillcolor = Color([0.5,0.5,0.5]).pygui
|
cr.fillcolor = Color([0.8,0.8,0.8]).pygui
|
||||||
cr.fill()
|
cr.fill()
|
||||||
print i
|
print i
|
||||||
else:
|
else:
|
||||||
|
|
@ -2226,6 +2252,7 @@ def main():
|
||||||
|
|
||||||
def quit():
|
def quit():
|
||||||
#Self-descriptive
|
#Self-descriptive
|
||||||
|
FILE.close()
|
||||||
if SYSTEM=="gtk":
|
if SYSTEM=="gtk":
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
elif SYSTEM=="android":
|
elif SYSTEM=="android":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue