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
|
||||
# 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
|
||||
#import objc, AppKit, cPickle
|
||||
|
|
@ -312,18 +312,37 @@ def new_file(widget=None):
|
|||
def open_file(widget=None):
|
||||
global root
|
||||
MainWindow.stage.delete(root)
|
||||
thefile = svlgui.file_dialog("open").open("rb")
|
||||
root = pickle.load(thefile)
|
||||
thetarfile = tarfile.open(fileobj=svlgui.file_dialog("open").open("rb"),mode="r:gz")
|
||||
basefile = thetarfile.extractfile("basefile")
|
||||
root, svlgui.Library = pickle.load(basefile)
|
||||
MainWindow.stage.add(root, 0, 0)
|
||||
MainWindow.stage.draw()
|
||||
MainWindow.timelinebox.root = root
|
||||
MainWindow.timelinebox.draw()
|
||||
thetarfile.close()
|
||||
def open_sc_file(widget=None):
|
||||
pass
|
||||
def save_file(widget=None):
|
||||
thefile = svlgui.file_dialog("save").open("w")
|
||||
pickle.dump(root, thefile)
|
||||
print thefile
|
||||
data = pickle.dumps((root,svlgui.Library))
|
||||
tarinfo = tarfile.TarInfo('basefile')
|
||||
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):
|
||||
pass
|
||||
def import_to_stage(widget=None):
|
||||
|
|
@ -430,7 +449,7 @@ svlgui.menufuncs([["File",
|
|||
("Add Layer",add_layer,"<Shift><Control>N"),
|
||||
("Delete Layer",delete_layer,"<Shift><Control>Delete")],
|
||||
["Import",
|
||||
("Import to Stage",import_to_stage),
|
||||
("Import to Stage",import_to_stage,"/I"),
|
||||
("Import to Library",import_to_library)],
|
||||
["Export",
|
||||
"Export .swf",
|
||||
|
|
|
|||
31
svlgui.py
31
svlgui.py
|
|
@ -150,6 +150,7 @@ if sys.platform=="linux2":
|
|||
### TESTING - gtk should be Linux platform, at least for now ####
|
||||
#'''
|
||||
import pickle
|
||||
import tarfile
|
||||
import GUI # Using PyGUI. Experimental.
|
||||
from GUI import Window as OSXWindow, Button as OSXButton, Image as OSXImage
|
||||
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
|
||||
#app = GUI.application()
|
||||
SYSTEM="osx"
|
||||
TEMPDIR = "/tmp"
|
||||
'''
|
||||
SYSTEM="html"
|
||||
ids = {}
|
||||
|
|
@ -171,6 +173,7 @@ if sys.platform=="linux2":
|
|||
elif sys.platform=="win32":
|
||||
PLATFORM="win32"
|
||||
import pickle
|
||||
import tarfile
|
||||
import misc_funcs
|
||||
import GUI # Using PyGUI. Experimental.
|
||||
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.Geometry import offset_rect, rect_sized
|
||||
SYSTEM="osx"
|
||||
TEMPDIR="C:\\Windows\\Temp"
|
||||
sep = "\\"
|
||||
elif sys.platform=="linux-armv6l":
|
||||
import android
|
||||
import tarfile
|
||||
droid = android.Android()
|
||||
SYSTEM="android"
|
||||
TEMPDIR="/tmp" # TODO:FIXTHIS
|
||||
tb = ""
|
||||
sep = "/"
|
||||
print str(sys.platform)
|
||||
|
|
@ -195,6 +201,7 @@ elif sys.platform=="darwin":
|
|||
PLATFORM="osx"
|
||||
import pickle
|
||||
import misc_funcs
|
||||
import tarfile
|
||||
import GUI # Using PyGUI. Experimental.
|
||||
from GUI import Window as OSXWindow, Button as OSXButton, Image as OSXImage
|
||||
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
|
||||
#app = GUI.application()
|
||||
SYSTEM="osx"
|
||||
TEMPDIR="/tmp"
|
||||
sep = "/"
|
||||
|
||||
FILE = tarfile.open(name=TEMPDIR+"/Untitled",mode="w:gz")
|
||||
FILE.close()
|
||||
|
||||
__windowlist__=[]
|
||||
|
||||
if SYSTEM=="osx":
|
||||
|
|
@ -874,6 +885,11 @@ class TextEntry(Widget):
|
|||
text = property(get_text, set_text)
|
||||
|
||||
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):
|
||||
if not skipl:
|
||||
global Library
|
||||
|
|
@ -1226,6 +1242,10 @@ class Shape (object):
|
|||
return retval
|
||||
|
||||
class framewrapper (object):
|
||||
#def __getstate__(self):
|
||||
# dict = self.__dict__.copy()
|
||||
# dict['parent'] = None
|
||||
# return dict
|
||||
#Wraps object per-frame. Allows for changes in position, rotation, scale.
|
||||
def __init__(self, obj, x, y, rot, scalex, scaley, parent=None):
|
||||
self.obj = obj
|
||||
|
|
@ -1290,6 +1310,12 @@ class framewrapper (object):
|
|||
|
||||
|
||||
class frame:
|
||||
def __reduce__(self):
|
||||
badvars = (self.parent,self.group)
|
||||
self.parent = None
|
||||
ret = pickle.dumps(self)
|
||||
self.parent, self.group = badvars
|
||||
return ret
|
||||
def __init__(self,parent,duplicate=None):
|
||||
self.objs = []
|
||||
self.currentselect=None
|
||||
|
|
@ -2190,10 +2216,10 @@ class FramesCanvas(Canvas):
|
|||
cr.newpath()
|
||||
cr.rect([i*16,k*32,i*16+16,k*32+32])
|
||||
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()
|
||||
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()
|
||||
print i
|
||||
else:
|
||||
|
|
@ -2226,6 +2252,7 @@ def main():
|
|||
|
||||
def quit():
|
||||
#Self-descriptive
|
||||
FILE.close()
|
||||
if SYSTEM=="gtk":
|
||||
gtk.main_quit()
|
||||
elif SYSTEM=="android":
|
||||
|
|
|
|||
Loading…
Reference in New Issue