diff --git a/GUI/Generic/GCanvases.py b/GUI/Generic/GCanvases.py index a1dbab0..33fa893 100644 --- a/GUI/Generic/GCanvases.py +++ b/GUI/Generic/GCanvases.py @@ -42,7 +42,8 @@ class Canvas(Properties): self.textcolor = c def rmoveto(self, dx, dy): - x0, y0 = self._current_point() + x0, y0 = self._current_point + # x0, y0 = self._current_point() self.moveto(x0 + dx, y0 + dy) def rlineto(self, dx, dy): diff --git a/GUI/Gtk/Canvas.py b/GUI/Gtk/Canvas.py index e980a00..5344f5a 100644 --- a/GUI/Gtk/Canvas.py +++ b/GUI/Gtk/Canvas.py @@ -171,10 +171,9 @@ class Canvas(GCanvas, GCanvasPaths): #ctx.set_source_rgba(*self._state.fillcolor._rgba) if self.fillcolor.image: # surface = - ctx.set_source_pixbuf(self.fillcolor.image, 0, 0) ctx.save() - print (self.maxx-self.minx)*1.0/self.fillcolor.image.get_width() - self._gtk_ctx.scale((self.maxx-self.minx)*1.0/self.fillcolor.image.get_width(), 1) + ctx.scale((self.maxx-self.minx)*1.0/self.fillcolor.image.get_width(), (self.maxy-self.miny)*1.0/self.fillcolor.image.get_height()) + ctx.set_source_pixbuf(self.fillcolor.image, 0, 0) ctx.fill_preserve() ctx.restore() else: diff --git a/GUI/Win32/Canvas.py b/GUI/Win32/Canvas.py index ecdba0b..da9f328 100644 --- a/GUI/Win32/Canvas.py +++ b/GUI/Win32/Canvas.py @@ -5,6 +5,7 @@ #-------------------------------------------------------------------- from math import sin, cos, pi +import sys import win32con as wc, win32ui as ui, win32gui as gui from win32con import PS_SOLID, BS_SOLID, RGN_AND #from win32ui import CreatePen, CreateBrush @@ -119,7 +120,11 @@ class Canvas(GCanvas): def set_fillcolor(self, c): state = self._state state.fillcolor = c - state.win_fill_brush = gdip.SolidBrush(c._win_argb) + if self.fillcolor.image: + tb = gdip.TextureBrush(self.fillcolor.image) + state.win_fill_brush = tb + else: + state.win_fill_brush = gdip.SolidBrush(c._win_argb) def get_textcolor(self): return self._state.textcolor @@ -156,19 +161,41 @@ class Canvas(GCanvas): def newpath(self): self._win_path.Reset() + self.minx = sys.maxint + self.miny = sys.maxint + self.maxx = -sys.maxint/2 + self.maxy = -sys.maxint/2 def moveto(self, x, y): p = (x, y) + try: + self.minx = min(self.minx, x) + self.miny = min(self.miny, y) + self.maxx = max(self.maxx, x) + self.maxy = max(self.maxy, y) + except AttributeError: + self.minx = x + self.miny = y + self.maxx = x + self.maxy = y self._current_point = p self._win_path.StartFigure() def lineto(self, x, y): x0, y0 = self._current_point + self.minx = min(self.minx, x) + self.miny = min(self.miny, y) + self.maxx = max(self.maxx, x) + self.maxy = max(self.maxy, y) self._win_path.AddLine_4f(x0, y0, x, y) self._current_point = (x, y) def curveto(self, p1, p2, p3): p0 = self._current_point + self.minx = min(self.minx, p1[0], p2[0], p3[0]) + self.miny = min(self.miny, p1[1], p2[1], p3[1]) + self.maxx = max(self.maxx, p1[0], p2[0], p3[0]) + self.maxy = max(self.maxy, p1[1], p2[1], p3[1]) self._win_path.AddBezier_4p(p0, p1, p2, p3) self._current_point = p3 @@ -182,7 +209,13 @@ class Canvas(GCanvas): self._current_point = None def fill(self): - self._win_graphics.FillPath(self._state.win_fill_brush, self._win_path) + if self.fillcolor.image: + self.gsave() + self._win_graphics.Scale_2f((self.maxx-self.minx)*1.0/self.fillcolor.image.GetWidth(), (self.maxy-self.miny)*1.0/self.fillcolor.image.GetHeight()) + self._win_graphics.FillPath(self._state.win_fill_brush, self._win_path) + self.grestore() + else: + self._win_graphics.FillPath(self._state.win_fill_brush, self._win_path) def stroke(self): self._win_graphics.DrawPath(self._state.win_pen, self._win_path) diff --git a/GUI/Win32/Colors.py b/GUI/Win32/Colors.py index 0adabb6..c0fbdca 100644 --- a/GUI/Win32/Colors.py +++ b/GUI/Win32/Colors.py @@ -7,21 +7,25 @@ import win32con as wc, win32api as api from GUI import Color -def rgb(red, green, blue, alpha = 1.0): +def rgb(red, green, blue, alpha = 1.0, image = False, im = ''): color = Color() - color._red = red - color._green = green - color._blue = blue - color._alpha = alpha - color._win_color = ( - int(red * 255) | - int(green * 255) << 8 | - int(blue * 255) << 16) - color._win_argb = ( - int(blue * 255) | - int(green * 255) << 8 | - int(red * 255) << 16 | - int(alpha * 255) << 24) + color.image = image + if image: + color.image = im._win_image + else: + color._red = red + color._green = green + color._blue = blue + color._alpha = alpha + color._win_color = ( + int(red * 255) | + int(green * 255) << 8 | + int(blue * 255) << 16) + color._win_argb = ( + int(blue * 255) | + int(green * 255) << 8 | + int(red * 255) << 16 | + int(alpha * 255) << 24) return color selection_forecolor = Color._from_win_color( diff --git a/GUI/Win32/GDIPlus.py b/GUI/Win32/GDIPlus.py index 788bfa7..e2ac0ee 100644 --- a/GUI/Win32/GDIPlus.py +++ b/GUI/Win32/GDIPlus.py @@ -159,6 +159,21 @@ class SolidBrush(object): #-------------------------------------------------------------------- +class TextureBrush(object): + + def __init__(self, image): + ptr = c_void_p() + wg.GdipCreateTexture(image.ptr, 4, byref(ptr)) + self.ptr = ptr + + def __del__(self, wg = wg): + wg.GdipDeleteBrush(self.ptr) + + def __str__(self): + return "" + +#-------------------------------------------------------------------- + class Font(object): def __init__(self, family, size, style): diff --git a/README_INSTALL.txt b/README_INSTALL.txt index 9715627..15637b1 100644 --- a/README_INSTALL.txt +++ b/README_INSTALL.txt @@ -1,10 +1,10 @@ Building on Windows: - 1. In a CMD window, type: + 1. Uncomment the line at the beginning of lightningbeam.py that says "Uncomment to build on Windows" + 2. In a CMD window, type: c:\Python27\python.exe setup.py py2exe - 2. Copy the GUI folder from the root directory into dist\. - 3. The executable is in dist\lightningbeam.exe. You probably do need most of the DLL's, I haven't + 4. The executable is in dist\lightningbeam.exe. You probably do need most of the DLL's, I haven't gone through them yet. Building on Ubuntu/Debian: diff --git a/codeeditor.py b/codeeditor.py index eeca0c0..f30ce1d 100644 --- a/codeeditor.py +++ b/codeeditor.py @@ -83,12 +83,13 @@ class PyGUIFormatter(Formatter): class CodeEditor(ScrollableView): def __init__(self): ScrollableView.__init__(self) - self.text = "var a = {b:5, c:[3, 'df \\'']};\n_xscale\nif (this.hitTest(_root._xmouse, root._ymouse, false)) {\n\n\ttrace('hi');\n}" + self.text = "_root.onMouseDown = function () {\n\ttrace('Hi');\n};" self.font = Font('Courier', 16) self.selecting = False self.lexer = ActionScriptLexer() self.cursorpos = 0 self.scursorpos = 0 + self.selection = (0,0) self.formatter = PyGUIFormatter() # self.filter = NameHighlightFilter( self.filter = EverythingHighlightFilter( @@ -169,6 +170,7 @@ class CodeEditor(ScrollableView): except: pass self.scursorpos = self.cursorpos + self.selection = (self.cursorpos, self.cursorpos) if int(y/self.font.height): self.cursorpos+=1 self.invalidate_rect([0,0,self.extent[0],self.extent[1]]) @@ -183,6 +185,7 @@ class CodeEditor(ScrollableView): pass if int(y/self.font.height): self.cursorpos+=1 + self.selection = (min(self.cursorpos, self.scursorpos), max(self.cursorpos, self.scursorpos)) self.invalidate_rect([0,0,self.extent[0],self.extent[1]]) def key_down(self, event): keydict = {127:"backspace",63272:"delete",63232:"up_arrow",63233:"down_arrow", @@ -241,6 +244,8 @@ class CodeEditor(ScrollableView): else: self.text=self.text[:self.cursorpos]+str(key)+self.text[self.cursorpos:] self.cursorpos += 1 + self.scursorpos = self.cursorpos + self.selection = (self.cursorpos, self.cursorpos) self.invalidate_rect([0,0,self.extent[0],self.extent[1]]) class test(Application): def __init__(self): diff --git a/lightningbeam.py b/lightningbeam.py index 20b017b..551cd41 100755 --- a/lightningbeam.py +++ b/lightningbeam.py @@ -15,7 +15,7 @@ os.putenv("UBUNTU_MENUPROXY", "0") #import objc, AppKit, cPickle #Uncomment to build on Windows -#import ctypes, ctypes.wintypes, win32print +# import ctypes, ctypes.wintypes, win32print #SVLGUI - my custom GUI wrapper to abstract the GUI import svlgui @@ -49,6 +49,8 @@ global undo_stack global redo_stack undo_stack = [] redo_stack = [] +global preferences +preferences={} def clear(arr): arr.__delslice__(0,len(arr)) @@ -108,6 +110,7 @@ def onMouseDownGroup(self, x, y,button=1,clicks=1): if svlgui.MODE in [" ", "s"]: if self.hitTest(x, y): self.clicked = True + elif svlgui.MODE in ["r", "e", "p"]: if svlgui.MODE=="r": # 'c' stands for 'current' @@ -115,7 +118,19 @@ def onMouseDownGroup(self, x, y,button=1,clicks=1): elif svlgui.MODE=="e": self.cshape = ellipse(x, y, 0, 0) elif svlgui.MODE=="p": - self.cshape = shape(x, y) + # self.cshape = shape(x, y) + self.cshape = svlgui.Line(svlgui.Point(x, y),svlgui.Point(x,y)) + for i in self.lines: + if abs(self.cshape.endpoint1.x-i.endpoint1.x)<10 and abs(self.cshape.endpoint1.y-i.endpoint1.y)<10: + self.cshape.connection1 = i.endpoint1 + self.cshape.connection1.lines.add(self.cshape) + break + elif abs(self.cshape.endpoint1.x-i.endpoint2.x)<10 and abs(self.cshape.endpoint1.y-i.endpoint2.y)<10: + self.cshape.connection1 = i.endpoint2 + self.cshape.connection1.lines.add(self.cshape) + break + self.lines.append(self.cshape) + return #self.cshape.rotation = 5 self.cshape.initx,self.cshape.inity = x, y self.add(self.cshape) @@ -182,9 +197,18 @@ def onMouseUpGroup(self, x, y,button=1,clicks=1): undo_stack[-1] = undo_stack[-1].complete({"obj":cobj, "frame":self.activelayer.currentframe, "layer":self.activelayer}) clear(redo_stack) elif svlgui.MODE=="p": - print len(self.cshape.shapedata) + '''print len(self.cshape.shapedata) self.cshape.shapedata = misc_funcs.simplify_shape(self.cshape.shapedata, svlgui.PMODE.split()[-1],1) - print len(self.cshape.shapedata) + print len(self.cshape.shapedata)''' + for i in self.lines: + if abs(self.cshape.endpoint2.x-i.endpoint1.x)<10 and abs(self.cshape.endpoint2.y-i.endpoint1.y)<10: + self.cshape.connection2 = i.endpoint1 + self.cshape.connection2.lines.add(self.cshape) + break + elif abs(self.cshape.endpoint2.x-i.endpoint2.x)<10 and abs(self.cshape.endpoint2.y-i.endpoint2.y)<10: + self.cshape.connection2 = i.endpoint2 + self.cshape.connection2.lines.add(self.cshape) + break self.cshape = None MainWindow.stage.draw() def onMouseUpObj(self, x, y,button=1,clicks=1): @@ -243,7 +267,9 @@ def onMouseDragGroup(self, x, y,button=1,clicks=1): y=y-self.cshape.inity self.cshape.shapedata = [["M",x/2,0],["C",4*x/5,0,x,y/5,x,y/2],["C",x,4*y/5,4*x/5,y,x/2,y],["C",x/5,y,0,4*y/5,0,y/2],["C",0,y/5,x/5,0,x/2,0]] elif svlgui.MODE == "p": - self.cshape.shapedata.append(["L",x-self.cshape.initx,y-self.cshape.inity]) + # self.cshape.shapedata.append(["L",x-self.cshape.initx,y-self.cshape.inity]) + self.cshape.endpoint2.x = x + self.cshape.endpoint2.y = y def onMouseDragObj(self, x, y,button=1,clicks=1): if svlgui.MODE==" ": self.x = x-self.initx @@ -324,15 +350,19 @@ fps="+str(svlgui.FRAMERATE)+"\n"+"".join([i.print_sc() for i in svlgui.Library]) def run_file(self=None): global root print "RUNNING" + print svlgui.FILE.name root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions = MainWindow.scriptwindow.text - open(os.getenv('HOME')+"/test.sc", "w").write(create_sc(root)) + # open(os.getenv('HOME')+"/test.sc", "w").write(create_sc(root)) + open(svlgui.FILE.name+".sc", "w").write(create_sc(root)) # svlgui.execute("swfc/swfc_"+svlgui.PLATFORM+" "+os.getenv('HOME')+"/test.sc -o "+os.getenv('HOME')+"/test.swf") - x = os.system("swfc/swfc_"+svlgui.PLATFORM+" "+os.getenv('HOME')+"/test.sc -o "+os.getenv('HOME')+"/test.swf") + # x = os.system("swfc/swfc_"+svlgui.PLATFORM+" "+os.getenv('HOME')+"/test.sc -o "+os.getenv('HOME')+"/test.swf") + x = os.system("swfc"+svlgui.sep+"swfc_"+svlgui.PLATFORM+" "+svlgui.FILE.name+".sc -o "+svlgui.FILE.name+".swf") if sys.version_info < (2, 6): if x==5: # which is the error value returned when linking libjpeg fails if svlgui.alert("You appear to be missing libjpeg. Install it?", confirm=True): os.system("""osascript -e 'do shell script "mkdir -p /usr/local/lib; cp swfc/libjpeg.8.dylib /usr/local/lib" with administrator privileges'""") - x = os.system("swfc/swfc_"+svlgui.PLATFORM+" "+os.getenv('HOME')+"/test.sc -o "+os.getenv('HOME')+"/test.swf") + # x = os.system("swfc/swfc_"+svlgui.PLATFORM+" "+os.getenv('HOME')+"/test.sc -o "+os.getenv('HOME')+"/test.swf") + x = os.system("swfc/swfc_"+svlgui.PLATFORM+" "+svlgui.FILE.name+".sc -o "+svlgui.FILE.name+".swf") if x==5: svlgui.alert("Sorry, something has gone terribly wrong.") else: @@ -340,14 +370,42 @@ def run_file(self=None): #TODO: Make this cross-platform compatible if svlgui.PLATFORM=="win32": # Untested. - logloc = os.getenv('HOME')+"\\AppData\\Roaming\\Macromedia\\Flash Player\\Logs\\flashlog.txt" + logloc = os.path.expanduser("~")+"\\AppData\\Roaming\\Macromedia\\Flash Player\\Logs\\flashlog.txt" + if not os.path.exists(os.path.expanduser("~")+"\\flashplayerdebugger.exe"): + result = svlgui.alert("You do not have a Flash debugger installed. Install one?", confirm=True) + if not result: + svlgui.alert("Aborting.") + return + else: + svlgui.alert("The Flash Debugger will download when you click Ok.\nThis may take some time.") + urllib.urlretrieve("http://download.macromedia.com/pub/flashplayer/updaters/11/flashplayer_11_sa_debug.exe", os.path.expanduser("~")+"\\flashplayerdebugger.exe") + if not os.path.exists(os.path.expanduser('~')+'\\mm.cfg'): + with open(os.path.expanduser('~')+"/mm.cfg", "w") as mm: + mm.write("ErrorReportingEnable=1\nTraceOutputFileEnable=1") elif "linux" in svlgui.PLATFORM: + logloc = os.getenv('HOME')+"/.macromedia/Flash_Player/Logs/flashlog.txt" + if not os.path.exists('/usr/bin/flashplayerdebugger'): + if os.system('which gnash')==0: + if not 'use_gnash' in preferences: + if svlgui.alert("You have GNASH installed. Do you wish to use it instead of Adobe's flash player?", confirm=True): + use_gnash = True + return + else: + result = svlgui.alert("You do not have a Flash debugger installed. Install one?", confirm=True) + if not result: + svlgui.alert("Aborting.") + return + else: + svlgui.alert("The Flash Debugger will download when you click Ok.\nThis may take some time.") + if not "PPC" in svlgui.PLATFORM: + urllib.urlretrieve("http://fpdownload.macromedia.com/pub/flashplayer/updaters/11/flashplayer_11_sa_debug.i386.tar.gz", "fp.tar.gz") + os.system("tar -zxf fp.tar.gz") + os.system("gksudo mv flashplayerdebugger /usr/bin/") if not os.path.exists(os.getenv('HOME')+"/mm.cfg"): # By default, the Flash debugger on Linux does not log traces. # So, we create a configuration file to tell it to do so if the user hasn't already. with open(os.getenv('HOME')+"/mm.cfg", "w") as mm: mm.write("ErrorReportingEnable=1\nTraceOutputFileEnable=1") - logloc = os.getenv('HOME')+"/.macromedia/Flash_Player/Logs/flashlog.txt" elif svlgui.PLATFORM=="osx": logloc = os.getenv('HOME')+"/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt" if not os.path.exists('/Applications/Flash Player Debugger.app'): @@ -399,21 +457,31 @@ def run_file(self=None): outputtext.scroll_bottom() # this doesn't work except: pass - r = misc_funcs.RepeatTimer(0.02, updatetrace, args=[outputtext]) - print dir(outputwin.window) - r.daemon = True - r.start() + return True + if hasattr(svlgui, 'gobject'): + svlgui.gobject.timeout_add(20, updatetrace, outputtext) + else: + r = misc_funcs.RepeatTimer(0.02, updatetrace, args=[outputtext]) + r.daemon = True + r.start() if svlgui.PLATFORM=="osx": osx_flash_player_loc = "/Applications/Flash\ Player\ Debugger.app" - success = svlgui.execute("open -a "+osx_flash_player_loc+" "+os.getenv('HOME')+"/test.swf") + # success = svlgui.execute("open -a "+osx_flash_player_loc+" "+os.getenv('HOME')+"/test.swf") + success = svlgui.execute("open -a "+osx_flash_player_loc+" "+svlgui.FILE.name+".swf") if not success: svlgui.alert("Oops! Didn't work. I probably couldn't find your Flash debugger!") elif svlgui.PLATFORM=='win32': - win_flash_player_loc = "" - svlgui.execute('start '+win_flash_player_loc+" test.swf") + win_flash_player_loc = os.path.expanduser("~")+"\\flashplayerdebugger.exe" + # svlgui.execute('start '+win_flash_player_loc+" test.swf") + svlgui.execute('start '+win_flash_player_loc+" "+svlgui.FILE.name+".swf") elif svlgui.PLATFORM.startswith('linux'): - linux_flash_player_loc = "" - svlgui.execute("xdg-open "+linux_flash_player_loc+" "+os.getenv('HOME')+"/test.swf") + linux_flash_player_loc = "/usr/bin/flashplayerdebugger" + # if not svlgui.execute(linux_flash_player_loc+" "+os.getenv('HOME')+"/test.swf &"): + if not svlgui.execute(linux_flash_player_loc+" "+svlgui.FILE.name+".swf &"): + if '64' in svlgui.PLATFORM: + svlgui.alert("Flash debugger failed to launch! Try installing ia32-libs.") + elif '32' in svlgui.PLATFORM: + svlgui.alert("Flash debugger failed to launch! No idea why.") def create_html5(root): retval = "\n\