~skykooler/swift-swf/quickly_trunk

« back to all changes in this revision

Viewing changes to bin/.svn/text-base/swift-swf.svn-base

  • Committer: Skyler Lehmkuhl
  • Date: 2011-06-28 05:37:42 UTC
  • Revision ID: skykooler@yahoo.com-20110628053742-270suf1c6tqbjlaf
Creating ubuntu package

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
import time
31
31
import imp
32
32
import imghdr
33
 
import gst
34
33
from PIL import Image
35
34
 
36
35
# optional Launchpad integration
923
922
        
924
923
def on_drag_data_received(widget, context, x, y, selection, target_type, timestamp):
925
924
        global pid
 
925
        global sep
926
926
        uri = selection.data.strip('\r\n\x00')
927
927
        uri_splitted = uri.split() # we may have more than one file dropped
928
928
        for uri in uri_splitted:
936
936
                        alert(path+" is not a valid image file!")
937
937
                else:
938
938
                        if not imghdr.what(path)=="png":
939
 
                                im.save("/tmp/swift"+str(pid)+"/"+path.split("/")[-1].split(".")[0]+".png")
940
 
                                path = "/tmp/swift"+str(pid)+"/"+path.split("/")[-1].split(".")[0]+".png"
 
939
                                im.save(os.environ["TEMP"]+sep+"swift"+str(pid)+sep+path.split(sep)[-1].split(".")[0]+".png")
 
940
                                path = os.environ["TEMP"]+sep+"swift"+str(pid)+sep+path.split(sep)[-1].split(".")[0]+".png"
941
941
                        f=path.split("/")[-1].split(".")
942
942
                        if f[0][0].isdigit():
943
943
                                alert("First character of filename is a digit!! Changing to \"i\".")
1819
1819
                #clean up code for saving application state should be added here
1820
1820
                #Delete any temp files so swift won't give an error on next boot
1821
1821
                global pid
1822
 
                os.system("rm /tmp/swift"+str(pid)+"/currentfile")
 
1822
                os.system("rm "+os.environ["TEMP"]+sep+"swift"+str(pid)+sep+"currentfile")
1823
1823
                gtk.main_quit()
1824
1824
        def save_dialog(self, widget, data=None):
1825
1825
                global path
1830
1830
                result = saver.run()
1831
1831
                #Filename includes path
1832
1832
                filename = saver.get_filename()
1833
 
                patharray = filename.split("/")
 
1833
                patharray = filename.split(sep)
1834
1834
                title = patharray.pop()
1835
1835
                titlearray = title.split(".")
1836
1836
                title = titlearray[0] #no extension
1837
1837
                path = ""
1838
1838
                for i in patharray:
1839
 
                        path = path+i+"/"
 
1839
                        path = path+i+sep
1840
1840
                
1841
1841
                
1842
1842
                saver.destroy()
1965
1965
                for i in patharray:
1966
1966
                        path = path+i+"/"
1967
1967
                try:
1968
 
                        ren = "/tmp/"+title+".tar.gz"
 
1968
                        ren = os.environ["TEMP"]+sep+title+".tar.gz"
1969
1969
                        shutil.copyfile(filename, ren)
1970
1970
                        tar = tarfile.open(ren, 'r:gz')
1971
1971
                        for item in tar:
1972
 
                                tar.extract(item, "/tmp/swift"+str(pid)+"/")
 
1972
                                tar.extract(item, os.environ["TEMP"]+sep+"swift"+str(pid)+sep)
1973
1973
                        os.system ("rm "+ren)
1974
1974
                except:
1975
1975
                        print "Error opening file."
1976
1976
                        alert("Error opening file!")
1977
1977
                        opener.destroy()
1978
1978
                        return 415
1979
 
                fc = open("/tmp/swift"+str(pid)+"/currentfile", "r")
 
1979
                fc = open(os.environ["TEMP"]+sep+"swift"+str(pid)+sep+"currentfile", "r")
1980
1980
                currentfilebase = []
1981
1981
                for i in fc:
1982
1982
                        currentfilebase.append(i)
1990
1990
                        currentfile["objects"][obtemp.name] = obtemp
1991
1991
                currentselect = ["root", None]
1992
1992
                for i in currentfile["colors"]["images"]:
1993
 
                        currentfile["colors"]["images"][i] = "/tmp/swift"+str(pid)+"/"+currentfile["colors"]["images"][i]
 
1993
                        currentfile["colors"]["images"][i] = os.environ["TEMP"]+sep+"swift"+str(pid)+sep+currentfile["colors"]["images"][i]
1994
1994
                level = 0
1995
1995
                fc.close()
1996
1996
                self.set_title("Swift - "+title+".swift")
2053
2053
                global doubleclick
2054
2054
                global level
2055
2055
                global objects
 
2056
                global sep
 
2057
                sep = os.sep
2056
2058
                level = 0
2057
2059
                title = "Untitled"
2058
2060
                currentfile = {"fileinfo":{"filename":"Untitled.swf", "bbox":[500, 500, 0, 0], "fps":50}, "colors":{"gradients":{}, "textures":{}, "images":{}}, "objects":{}, "sprites":{}, "buttons":{}, "actions":[""], "sounds":{}, "frames":[[0], {"sort":[], "sounds":[]}]}
2070
2072
                fiter = 0
2071
2073
                citer = 0
2072
2074
                step = 0
2073
 
                path = "/home/"+os.getlogin()+"/Desktop/"
 
2075
                path = os.environ["HOME"]+sep+"Desktop"+sep
2074
2076
                clicked = False
2075
2077
                doubleclick = False
2076
2078
                selectid=["#000000"]
2180
2182
                for i in currentfile["objects"]:
2181
2183
                        ob = currentfile["objects"][i]  
2182
2184
                        if ob.type=="button":
2183
 
                                idlefile = open("/tmp/idlefile"+i+".png", "w")
2184
 
                                hoverfile = open("/tmp/hoverfile"+i+".png", "w")
2185
 
                                pressedfile = open("/tmp/pressedfile"+i+".png", "w")
2186
 
                                hitfile = open("/tmp/hitfile"+i+".png", "w")
 
2185
                                idlefile = open(os.environ["TEMP"]+sep+"idlefile"+i+".png", "w")
 
2186
                                hoverfile = open(os.environ["TEMP"]+sep+"hoverfile"+i+".png", "w")
 
2187
                                pressedfile = open(os.environ["TEMP"]+sep+"pressedfile"+i+".png", "w")
 
2188
                                hitfile = open(os.environ["TEMP"]+sep+"hitfile"+i+".png", "w")
2187
2189
                                idlesurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
2188
2190
                                hoversurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
2189
2191
                                pressedsurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
2230
2232
                                hoverfile.close()
2231
2233
                                pressedfile.close()
2232
2234
                                hitfile.close()
2233
 
                                output = output+".png idle"+i+" \"/tmp/idlefile"+i+".png\"\n"
2234
 
                                output = output+".png hover"+i+" \"/tmp/hoverfile"+i+".png\"\n"
2235
 
                                output = output+".png pressed"+i+" \"/tmp/pressedfile"+i+".png\"\n"
2236
 
                                output = output+".png hit"+i+" \"/tmp/hitfile"+i+".png\"\n"
 
2235
                                output = output+".png idle"+i+" \""+os.environ["TEMP"]+sep+"idlefile"+i+".png\"\n"
 
2236
                                output = output+".png hover"+i+" \""+os.environ["TEMP"]+sep+"hoverfile"+i+".png\"\n"
 
2237
                                output = output+".png pressed"+i+" \""+os.environ["TEMP"]+sep+"pressedfile"+i+".png\"\n"
 
2238
                                output = output+".png hit"+i+" \""+os.environ["TEMP"]+sep+"hitfile"+i+".png\"\n"
2237
2239
                                output = output+".button "+i+"\n.show idle"+i+" as=idle\n"+"\n.show hover"+i+" as=hover\n"+"\n.show pressed"+i+" as=pressed\n.show hit"+i+" as=area\n"+".end\n"
2238
2240
 
2239
2241
                        elif ob.type=="movieclip":
2378
2380
                        filetype="unknown"
2379
2381
                if filetype=="image":
2380
2382
                        if not imghdr.what(filename)=="png":
2381
 
                                Image.open(filename).save("/tmp/swift"+str(pid)+"/"+f[0]+".png")
2382
 
                                filename = "/tmp/swift"+str(pid)+"/"+filename.split("/")[-1].split(".")[0]+".png"
 
2383
                                Image.open(filename).save(os.environ["TEMP"]+sep+"swift"+str(pid)+"/"+f[0]+".png")
 
2384
                                filename = os.environ["TEMP"]+sep+"swift"+str(pid)+"/"+filename.split("/")[-1].split(".")[0]+".png"
2383
2385
                elif filetype=="sound":
2384
 
                        print "gst-launch -v filesrc location='"+filename+"' ! decodebin ! audioconvert ! audioresample ! wavenc ! filesink location='/tmp/swift"+str(pid)+"/"+f[0]+".wav'"
2385
 
                        os.system("gst-launch -v filesrc location='"+filename+"' ! decodebin ! audioconvert ! audioresample ! wavenc ! filesink location='/tmp/swift"+str(pid)+"/"+f[0]+".wav'")
2386
 
                        filename = "/tmp/swift"+str(pid)+"/"+f[0]+".wav"
 
2386
                        os.system("mplayer -nolirc '"+filename+"' -ao pcm:file='/tmp/swift"+str(pid)+"/"+f[0]+".wav' -vc dummy -aid 1 -vo null")
 
2387
                        filename = os.environ["TEMP"]+sep+"swift"+str(pid)+"/"+f[0]+".wav"
2387
2388
                        
2388
2389
                        
2389
2390
                        
2715
2716
                                        if not i in sounds:
2716
2717
                                                sounds[i] = mplayer.MPlayer()
2717
2718
                                                sounds[i].command("loadfile", currentfile["sounds"][i])
2718
 
                                                '''sounds[i] = gst.element_factory_make("playbin2", i)
2719
 
                                                sounds[i].set_property("uri", "file://"+currentfile["sounds"][i])
2720
 
                                                sounds[i].set_state(gst.STATE_PLAYING)'''
2721
2719
                        if (playing==True or data==None) and currentframe[level]<objects[currentselect[level]].frames[0][-1]:
2722
2720
                                source_id = gobject.timeout_add(1000/currentfile["fileinfo"]["fps"], self.play_frames, widget, True)
2723
2721
                                currentframe[level]+=1
2727
2725
                        else:
2728
2726
                                playing=False
2729
2727
                                for i in sounds:
2730
 
                                        #sounds[i].set_state(gst.STATE_NULL)
2731
2728
                                        sounds[i].command("quit")
2732
2729
                                        del sounds[i]
2733
2730
        def next_frame(self, widget, data=None):
3187
3184
                for i in currentfile["objects"]:
3188
3185
                        ob = currentfile["objects"][i]  
3189
3186
                        if ob.type=="button":
3190
 
                                idlefile = open("/tmp/idlefile"+i+".png", "w")
3191
 
                                hoverfile = open("/tmp/hoverfile"+i+".png", "w")
3192
 
                                pressedfile = open("/tmp/pressedfile"+i+".png", "w")
3193
 
                                hitfile = open("/tmp/hitfile"+i+".png", "w")
 
3187
                                idlefile = open(os.environ["TEMP"]+sep+"idlefile"+i+".png", "w")
 
3188
                                hoverfile = open(os.environ["TEMP"]+sep+"hoverfile"+i+".png", "w")
 
3189
                                pressedfile = open(os.environ["TEMP"]+sep+"pressedfile"+i+".png", "w")
 
3190
                                hitfile = open(os.environ["TEMP"]+sep+"hitfile"+i+".png", "w")
3194
3191
                                idlesurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
3195
3192
                                hoversurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
3196
3193
                                pressedsurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
3237
3234
                                hoverfile.close()
3238
3235
                                pressedfile.close()
3239
3236
                                hitfile.close()
3240
 
                                output = output+".png idle"+i+" \"/tmp/idlefile"+i+".png\"\n"
3241
 
                                output = output+".png hover"+i+" \"/tmp/hoverfile"+i+".png\"\n"
3242
 
                                output = output+".png pressed"+i+" \"/tmp/pressedfile"+i+".png\"\n"
3243
 
                                output = output+".png hit"+i+" \"/tmp/hitfile"+i+".png\"\n"
 
3237
                                output = output+".png idle"+i+" \""+os.environ["TEMP"]+sep+"idlefile"+i+".png\"\n"
 
3238
                                output = output+".png hover"+i+" \""+os.environ["TEMP"]+sep+"hoverfile"+i+".png\"\n"
 
3239
                                output = output+".png pressed"+i+" \""+os.environ["TEMP"]+sep+"pressedfile"+i+".png\"\n"
 
3240
                                output = output+".png hit"+i+" \""+os.environ["TEMP"]+sep+"hitfile"+i+".png\"\n"
3244
3241
                                output = output+".button "+i+"\n.show idle"+i+" as=idle\n"+"\n.show hover"+i+" as=hover\n"+"\n.show pressed"+i+" as=pressed\n.show hit"+i+" as=area\n"+".end\n"
3245
3242
 
3246
3243
                        elif ob.type=="movieclip":
3841
3838
                for i in currentfile["objects"]:
3842
3839
                        ob = currentfile["objects"][i]  
3843
3840
                        if ob.type=="button":
3844
 
                                idlefile = open("/tmp/idlefile"+i+".png", "w")
3845
 
                                hoverfile = open("/tmp/hoverfile"+i+".png", "w")
3846
 
                                pressedfile = open("/tmp/pressedfile"+i+".png", "w")
3847
 
                                hitfile = open("/tmp/hitfile"+i+".png", "w")
 
3841
                                idlefile = open(os.environ["TEMP"]+sep+"idlefile"+i+".png", "w")
 
3842
                                hoverfile = open(os.environ["TEMP"]+sep+"hoverfile"+i+".png", "w")
 
3843
                                pressedfile = open(os.environ["TEMP"]+sep+"pressedfile"+i+".png", "w")
 
3844
                                hitfile = open(os.environ["TEMP"]+sep+"hitfile"+i+".png", "w")
3848
3845
                                idlesurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
3849
3846
                                hoversurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
3850
3847
                                pressedsurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ob.width, ob.height)
3891
3888
                                hoverfile.close()
3892
3889
                                pressedfile.close()
3893
3890
                                hitfile.close()
3894
 
                                output = output+".png idle"+i+" \"/tmp/idlefile"+i+".png\"\n"
3895
 
                                output = output+".png hover"+i+" \"/tmp/hoverfile"+i+".png\"\n"
3896
 
                                output = output+".png pressed"+i+" \"/tmp/pressedfile"+i+".png\"\n"
3897
 
                                output = output+".png hit"+i+" \"/tmp/hitfile"+i+".png\"\n"
 
3891
                                output = output+".png idle"+i+" \""+os.environ["TEMP"]+sep+"idlefile"+i+".png\"\n"
 
3892
                                output = output+".png hover"+i+" \""+os.environ["TEMP"]+sep+"hoverfile"+i+".png\"\n"
 
3893
                                output = output+".png pressed"+i+" \""+os.environ["TEMP"]+sep+"pressedfile"+i+".png\"\n"
 
3894
                                output = output+".png hit"+i+" \""+os.environ["TEMP"]+sep+"hitfile"+i+".png\"\n"
3898
3895
                                output = output+".button "+i+"\n.show idle"+i+" as=idle\n"+"\n.show hover"+i+" as=hover\n"+"\n.show pressed"+i+" as=pressed\n.show hit"+i+" as=area\n"+".end\n"
3899
3896
 
3900
3897
                        elif ob.type=="movieclip":
4184
4181
        global lastinput
4185
4182
        global playing
4186
4183
        global sounds
 
4184
        global sep
4187
4185
        #specify the current version and what version files it can still open
4188
4186
        SWIFT_VERSION = "1.0-alpha4"
4189
4187
        SWIFT_COMPAT = ["1.0-alpha4"]
4223
4221
        objects["root"].frames = currentfile["frames"]
4224
4222
        objects["root"].actions = currentfile["actions"]
4225
4223
        currentselect = ["root", None]
4226
 
        path = "/home/"+os.getlogin()+"/Desktop/"
 
4224
        try:
 
4225
                path = os.environ["HOME"]+sep+"Desktop"+sep
 
4226
        except KeyError:
 
4227
                path = os.environ["HOMEPATH"]+sep+"Desktop"+sep
4227
4228
        title = "Untitled"
4228
4229
        clicked = False
4229
4230
        middleclick = False
4245
4246
        return window
4246
4247
 
4247
4248
if __name__ == "__main__":
 
4249
        if not "TEMP" in os.environ:
 
4250
                os.environ["TEMP"]="/tmp"
4248
4251
        global pid
 
4252
        global sep
4249
4253
        pid = os.getpid()
 
4254
        sep = os.sep
4250
4255
        TARGET_TYPE_URI_LIST = 80
4251
4256
        dnd_list = [ ( 'text/uri-list', 0, TARGET_TYPE_URI_LIST ) ]
4252
4257
        #support for command line options
4262
4267
                logging.debug('logging enabled')        
4263
4268
 
4264
4269
        #run the application
4265
 
        if not "currentfile" in os.listdir("/tmp"):
 
4270
        if not "currentfile" in os.listdir(os.environ["TEMP"]):
4266
4271
                window = NewSwiftSwfWindow()
4267
4272
                window.show()
4268
4273
        
4326
4331
                hadj.set_value(500)
4327
4332
                vadj = sw.get_vadjustment()
4328
4333
                vadj.set_value(500)
4329
 
                os.mkdir("/tmp/swift"+str(pid))
 
4334
                os.mkdir(os.environ["TEMP"]+sep+"swift"+str(pid))
4330
4335
                if len(args)>0:
4331
4336
                        patharray = args[0].split("/")
4332
4337
                        title = patharray.pop()
4336
4341
                        for i in patharray:
4337
4342
                                path = path+i+"/"
4338
4343
                        try:
4339
 
                                ren = "/tmp/"+title+".tar.gz"
 
4344
                                ren = os.environ["TEMP"]+sep+""+title+".tar.gz"
4340
4345
                                shutil.copyfile(args[0], ren)
4341
4346
                                tar = tarfile.open(ren, 'r:gz')
4342
4347
                                for item in tar:
4343
 
                                        tar.extract(item, "/tmp/swift"+str(pid))
 
4348
                                        tar.extract(item, os.environ["TEMP"]+sep+"swift"+str(pid))
4344
4349
                                os.system ("rm "+ren)
4345
4350
                        except:
4346
4351
                                print "Error opening file."
4347
4352
                                alert("Error opening file!", True)
4348
 
                        fc = open("/tmp/swift"+str(pid)+"/currentfile", "r")
 
4353
                        fc = open(os.environ["TEMP"]+sep+"swift"+str(pid)+"/currentfile", "r")
4349
4354
                        currentfilebase = []
4350
4355
                        for i in fc:
4351
4356
                                currentfilebase.append(i)
4358
4363
                                currentfile["objects"][obtemp.name] = obtemp
4359
4364
                        currentselect = ["root", None]
4360
4365
                        for i in currentfile["colors"]["images"]:
4361
 
                                currentfile["colors"]["images"][i] = "/tmp/swift"+str(pid)+"/"+currentfile["colors"]["images"][i]
 
4366
                                currentfile["colors"]["images"][i] = os.environ["TEMP"]+sep+"swift"+str(pid)+"/"+currentfile["colors"]["images"][i]
4362
4367
                        level = 0
4363
4368
                        fc.close()
4364
4369
                        window.set_title("Swift - "+title+".swift")