Added basic text
This commit is contained in:
parent
d0adf42b5f
commit
284a77b10f
|
|
@ -69,6 +69,7 @@ def onMouseDownGroup(self, x, y):
|
||||||
self.clicked = True
|
self.clicked = True
|
||||||
elif svlgui.MODE in ["r", "e", "p"]:
|
elif svlgui.MODE in ["r", "e", "p"]:
|
||||||
if svlgui.MODE=="r":
|
if svlgui.MODE=="r":
|
||||||
|
#I can't remember what the 'c' stands for...
|
||||||
self.cshape = box(x, y, 0, 0)
|
self.cshape = box(x, y, 0, 0)
|
||||||
elif svlgui.MODE=="e":
|
elif svlgui.MODE=="e":
|
||||||
self.cshape = ellipse(x, y, 0, 0)
|
self.cshape = ellipse(x, y, 0, 0)
|
||||||
|
|
@ -84,6 +85,13 @@ def onMouseDownGroup(self, x, y):
|
||||||
self.cshape.onKeyDown = onKeyDownObj
|
self.cshape.onKeyDown = onKeyDownObj
|
||||||
self.clicked = True
|
self.clicked = True
|
||||||
MainWindow.scriptwindow.text = self.activelayer.frames[self.activelayer.currentframe].actions
|
MainWindow.scriptwindow.text = self.activelayer.frames[self.activelayer.currentframe].actions
|
||||||
|
elif svlgui.MODE in ["t"]:
|
||||||
|
self.ctext = svlgui.Text("Mimimi",x,y)
|
||||||
|
self.ctext.onMouseDown = onMouseDownText
|
||||||
|
self.ctext.onMouseDrag = onMouseDragText
|
||||||
|
self.ctext.onMouseUp = onMouseUpText
|
||||||
|
self.add(self.ctext)
|
||||||
|
self.ctext = None
|
||||||
def onMouseDownObj(self, x, y):
|
def onMouseDownObj(self, x, y):
|
||||||
MainWindow.scriptwindow.text = root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions
|
MainWindow.scriptwindow.text = root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions
|
||||||
self.clicked = True
|
self.clicked = True
|
||||||
|
|
@ -91,6 +99,11 @@ def onMouseDownObj(self, x, y):
|
||||||
if svlgui.MODE == "b":
|
if svlgui.MODE == "b":
|
||||||
self.filled = True
|
self.filled = True
|
||||||
self.fillcolor = svlgui.FILLCOLOR
|
self.fillcolor = svlgui.FILLCOLOR
|
||||||
|
def onMouseDownText(self,x,y):
|
||||||
|
MainWindow.scriptwindow.text = root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions
|
||||||
|
self.clicked = True
|
||||||
|
self.initx, self.inity = x-self.x, y-self.y
|
||||||
|
#svlgui.alert('235')
|
||||||
def onMouseDownFrame(self, x, y):
|
def onMouseDownFrame(self, x, y):
|
||||||
pass
|
pass
|
||||||
def onMouseUpGroup(self, x, y):
|
def onMouseUpGroup(self, x, y):
|
||||||
|
|
@ -105,6 +118,8 @@ def onMouseUpGroup(self, x, y):
|
||||||
MainWindow.stage.draw()
|
MainWindow.stage.draw()
|
||||||
def onMouseUpObj(self, x, y):
|
def onMouseUpObj(self, x, y):
|
||||||
self.clicked = False
|
self.clicked = False
|
||||||
|
def onMouseUpText(self, x, y):
|
||||||
|
self.clicked = False
|
||||||
def onMouseMoveGroup(self, x, y):
|
def onMouseMoveGroup(self, x, y):
|
||||||
pass
|
pass
|
||||||
#This is for testing rotation. Comment out before any commit!
|
#This is for testing rotation. Comment out before any commit!
|
||||||
|
|
@ -130,18 +145,26 @@ def onMouseDragGroup(self, x, y):
|
||||||
def onMouseDragObj(self, x, y):
|
def onMouseDragObj(self, x, y):
|
||||||
self.x = x-self.initx
|
self.x = x-self.initx
|
||||||
self.y = y-self.inity
|
self.y = y-self.inity
|
||||||
|
def onMouseDragText(self, x, y):
|
||||||
|
self.x = x-self.initx
|
||||||
|
self.y = y-self.inity
|
||||||
|
|
||||||
def onKeyDownGroup(self, key):
|
def onKeyDownGroup(self, key):
|
||||||
pass
|
if not svlgui.EDITING:
|
||||||
if key in [" ", "s", "r", "e", "b", "p"]:
|
if key in [" ", "s", "r", "e", "b", "p"]:
|
||||||
svlgui.MODE=key
|
svlgui.MODE=key
|
||||||
svlgui.set_cursor({" ":"arrow","s":"arrow","r":"crosshair","e":"crosshair",
|
svlgui.set_cursor({" ":"arrow","s":"arrow","r":"crosshair","e":"crosshair",
|
||||||
"b":"arrow","p":"arrow"}[key], MainWindow.stage)
|
"b":"arrow","p":"arrow"}[key], MainWindow.stage)
|
||||||
misc_funcs.update_tooloptions()
|
misc_funcs.update_tooloptions()
|
||||||
elif key=="F6":
|
elif key=="F6":
|
||||||
add_keyframe()
|
add_keyframe()
|
||||||
elif key=="F8":
|
elif key=="F8":
|
||||||
convert_to_symbol()
|
convert_to_symbol()
|
||||||
|
else:
|
||||||
|
if not key=="escape":
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
svlgui.EDITING=False
|
||||||
def onKeyDownObj(self, key):
|
def onKeyDownObj(self, key):
|
||||||
if key in ("delete", "backspace"):
|
if key in ("delete", "backspace"):
|
||||||
del self.parent[self.parent.index(self)] # Need to clean up deletion
|
del self.parent[self.parent.index(self)] # Need to clean up deletion
|
||||||
|
|
|
||||||
125
svlgui.py
125
svlgui.py
|
|
@ -46,6 +46,8 @@ FOCUS = None
|
||||||
#Options for export
|
#Options for export
|
||||||
EXPORT_OPTS = {"swf":False,"html5":False,"basehtml":False,"fallback":False,"pack":False}
|
EXPORT_OPTS = {"swf":False,"html5":False,"basehtml":False,"fallback":False,"pack":False}
|
||||||
|
|
||||||
|
#Editing - whether the user is editing text
|
||||||
|
EDITING = True
|
||||||
|
|
||||||
#Library. Contatins all objects whether displayed or not.
|
#Library. Contatins all objects whether displayed or not.
|
||||||
Library = []
|
Library = []
|
||||||
|
|
@ -125,7 +127,8 @@ def hex2rgb(hex):
|
||||||
|
|
||||||
|
|
||||||
LINECOLOR = Color("#990099")
|
LINECOLOR = Color("#990099")
|
||||||
FILLCOLOR = Color("#000000")
|
FILLCOLOR = Color("#00FF00")
|
||||||
|
TEXTCOLOR = Color("#000000")
|
||||||
|
|
||||||
#Magic. Detect platform and select appropriate toolkit. To be used throughout code.
|
#Magic. Detect platform and select appropriate toolkit. To be used throughout code.
|
||||||
if sys.platform=="linux2":
|
if sys.platform=="linux2":
|
||||||
|
|
@ -216,6 +219,10 @@ elif sys.platform=="darwin":
|
||||||
from GUI.StdButtons import DefaultButton, CancelButton
|
from GUI.StdButtons import DefaultButton, CancelButton
|
||||||
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
|
||||||
|
import Cocoa
|
||||||
|
SYSTEM_FONTS = list(Cocoa.NSFontManager.sharedFontManager().availableFontFamilies())
|
||||||
|
FONT_PATH = "/Library/Fonts/"
|
||||||
|
FONT = u'Times New Roman'
|
||||||
#app = GUI.application()
|
#app = GUI.application()
|
||||||
SYSTEM="osx"
|
SYSTEM="osx"
|
||||||
TEMPDIR="/tmp"
|
TEMPDIR="/tmp"
|
||||||
|
|
@ -762,7 +769,7 @@ class Canvas(Widget):
|
||||||
keydict = {127:"backspace",63272:"delete",63232:"up_arrow",63233:"down_arrow",
|
keydict = {127:"backspace",63272:"delete",63232:"up_arrow",63233:"down_arrow",
|
||||||
63235:"right_arrow",63234:"left_arrow",13:"enter",9:"tab",
|
63235:"right_arrow",63234:"left_arrow",13:"enter",9:"tab",
|
||||||
63236:"F1",63237:"F2",63238:"F3",63239:"F4",63240:"F5",
|
63236:"F1",63237:"F2",63238:"F3",63239:"F4",63240:"F5",
|
||||||
63241:"F6",63242:"F7",63243:"F8",}
|
63241:"F6",63242:"F7",63243:"F8",27:"escape"}
|
||||||
if not event.unichars=='':
|
if not event.unichars=='':
|
||||||
if ord(event.unichars) in keydict:
|
if ord(event.unichars) in keydict:
|
||||||
key = keydict[ord(event.unichars)]
|
key = keydict[ord(event.unichars)]
|
||||||
|
|
@ -1251,6 +1258,116 @@ class Shape (object):
|
||||||
retval += self.name+".filled = "+str(self.filled).lower()+";\n"
|
retval += self.name+".filled = "+str(self.filled).lower()+";\n"
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
class Text (object):
|
||||||
|
def __init__(self,text="",x=0,y=0):
|
||||||
|
global SITER
|
||||||
|
global Library
|
||||||
|
Library.append(self)
|
||||||
|
self.text = text
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.rotation = 0
|
||||||
|
self.xscale = 1
|
||||||
|
self.yscale = 1
|
||||||
|
self.fill = TEXTCOLOR
|
||||||
|
self.font = Font(FONT,24)
|
||||||
|
self.dynamic = False
|
||||||
|
self.variable = None
|
||||||
|
self.password = False
|
||||||
|
self.wordwrap = False
|
||||||
|
self.multiline = False
|
||||||
|
self.html = False
|
||||||
|
self.editable = False
|
||||||
|
self.selectable = True
|
||||||
|
self.border = False
|
||||||
|
self.width = self.font.width(self.text)
|
||||||
|
self.height = self.font.height
|
||||||
|
self.type="Text"
|
||||||
|
self.name = "t"+str(int(random.random()*10000))+str(SITER)
|
||||||
|
SITER+=1
|
||||||
|
def draw(self,cr=None,parent=None,rect=None):
|
||||||
|
if SYSTEM=="osx":
|
||||||
|
cr.font = self.font
|
||||||
|
cr.textcolor = self.fill.pygui
|
||||||
|
cr.gsave()
|
||||||
|
#cr.moveto(self.x,self.y)
|
||||||
|
if sep=="\\":
|
||||||
|
# Very ugly hack for Windows. :(
|
||||||
|
# Windows doesn't respect coordinate transformations
|
||||||
|
# with respect to translation, so we have to do this
|
||||||
|
# bit ourselves.
|
||||||
|
|
||||||
|
# Rotation in radians
|
||||||
|
radrot = parent.group.rotation*math.pi/180
|
||||||
|
# Coordinate transform: multiplication by a rotation matrix
|
||||||
|
cr.translate(self.x*math.cos(radrot)-self.y*math.sin(radrot), self.x*math.sin(radrot)+self.y*math.cos(radrot))
|
||||||
|
else:
|
||||||
|
cr.translate(self.x,self.y)
|
||||||
|
cr.newpath()
|
||||||
|
cr.moveto(0,0)
|
||||||
|
cr.show_text(self.text)
|
||||||
|
cr.grestore()
|
||||||
|
def hitTest(self, x, y):
|
||||||
|
self.width = self.font.width(self.text)
|
||||||
|
self.height = self.font.height
|
||||||
|
if 0<x<self.width and -self.height<y<0:
|
||||||
|
return True
|
||||||
|
def getminx(self):
|
||||||
|
return 0
|
||||||
|
def getminy(self):
|
||||||
|
return -self.height
|
||||||
|
def getmaxx(self):
|
||||||
|
return self.width
|
||||||
|
def getmaxy(self):
|
||||||
|
return 0
|
||||||
|
minx = property(getminx)
|
||||||
|
miny = property(getminy)
|
||||||
|
maxx = property(getmaxx)
|
||||||
|
maxy = property(getmaxy)
|
||||||
|
def onMouseDown(self, self1, x, y):
|
||||||
|
pass
|
||||||
|
def onMouseDrag(self, self1, x, y):
|
||||||
|
pass
|
||||||
|
def onMouseUp(self, self1, x, y):
|
||||||
|
pass
|
||||||
|
def onMouseMove(self, self1, x, y):
|
||||||
|
pass
|
||||||
|
def onKeyDown(self, self1, key):
|
||||||
|
pass
|
||||||
|
def onKeyUp(self, self1, key):
|
||||||
|
pass
|
||||||
|
def print_sc(self):
|
||||||
|
retval = ".font "+''.join(self.font.family.split(' '))+self.name+" filename=\""\
|
||||||
|
+FONT_PATH+self.font.family+".ttf\"\n"
|
||||||
|
if self.dynamic:
|
||||||
|
retval+=".edittext "+self.name+" width="+str(self.width)+" height="+str(self.height)\
|
||||||
|
+" font="+''.join(self.font.family.split(' '))+self.name+" text=\""+self.text\
|
||||||
|
+"\" color="+self.fill.rgb+" size="+str(self.font.size)+"pt"
|
||||||
|
if self.variable:
|
||||||
|
retval+=" variable="+self.variable
|
||||||
|
if self.password:
|
||||||
|
retval+=" password"
|
||||||
|
if self.wordwrap:
|
||||||
|
retval+=" wordwrap"
|
||||||
|
if self.multiline:
|
||||||
|
retval+=" multiline"
|
||||||
|
if self.html:
|
||||||
|
retval+=" html"
|
||||||
|
if self.border:
|
||||||
|
retval+=" border"
|
||||||
|
if self.editable:
|
||||||
|
retval+="\n"
|
||||||
|
if not self.selectable:
|
||||||
|
retval+=" noselect"
|
||||||
|
else:
|
||||||
|
retval+=" readonly\n"
|
||||||
|
else:
|
||||||
|
retval+=".text "+self.name+" font="+''.join(self.font.family.split(' '))+self.name\
|
||||||
|
+" text=\""+self.text+"\" color="+self.fill.rgb+" size="+str(self.font.size)\
|
||||||
|
+"pt\n"
|
||||||
|
return retval
|
||||||
|
|
||||||
|
|
||||||
class framewrapper (object):
|
class framewrapper (object):
|
||||||
#def __getstate__(self):
|
#def __getstate__(self):
|
||||||
# dict = self.__dict__.copy()
|
# dict = self.__dict__.copy()
|
||||||
|
|
@ -1358,7 +1475,6 @@ class frame:
|
||||||
tb+="cr.stroke()\n"
|
tb+="cr.stroke()\n"
|
||||||
tb+="cr.restore()\n"
|
tb+="cr.restore()\n"
|
||||||
elif SYSTEM=="osx":
|
elif SYSTEM=="osx":
|
||||||
pass
|
|
||||||
self.group = group
|
self.group = group
|
||||||
cr.gsave()
|
cr.gsave()
|
||||||
cr.rotate(group.rotation)
|
cr.rotate(group.rotation)
|
||||||
|
|
@ -1842,7 +1958,8 @@ def set_cursor(curs, widget=None):
|
||||||
if SYSTEM == "osx":
|
if SYSTEM == "osx":
|
||||||
cursdict = {"arrow":StdCursors.arrow, "ibeam":StdCursors.ibeam,
|
cursdict = {"arrow":StdCursors.arrow, "ibeam":StdCursors.ibeam,
|
||||||
"crosshair":StdCursors.crosshair, "fist":StdCursors.fist,
|
"crosshair":StdCursors.crosshair, "fist":StdCursors.fist,
|
||||||
"hand":StdCursors.hand, "finger":StdCursors.finger, "invisible":StdCursors.invisible}
|
"hand":StdCursors.hand, "finger":StdCursors.finger,
|
||||||
|
"invisible":StdCursors.invisible, "text":StdCursors.ibeam}
|
||||||
if curs in cursdict:
|
if curs in cursdict:
|
||||||
if widget:
|
if widget:
|
||||||
widget._int().cursor = cursdict[curs]
|
widget._int().cursor = cursdict[curs]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue