Added ability to select multiple objects.
This commit is contained in:
parent
3de04ea80b
commit
c27a2d52f0
|
|
@ -68,6 +68,11 @@ class maybe:
|
||||||
self.edit.to_attrs = to_attrs
|
self.edit.to_attrs = to_attrs
|
||||||
return self.edit
|
return self.edit
|
||||||
|
|
||||||
|
svlgui.undo_stack = undo_stack
|
||||||
|
svlgui.edit = edit
|
||||||
|
svlgui.maybe = maybe
|
||||||
|
svlgui.clear = clear
|
||||||
|
|
||||||
def onLoadFrames(self):
|
def onLoadFrames(self):
|
||||||
'''for i in range(2000):
|
'''for i in range(2000):
|
||||||
if i%5==0:
|
if i%5==0:
|
||||||
|
|
@ -593,6 +598,9 @@ def undo(widget=None):
|
||||||
if e.from_attrs["layer"].currentselect==e.to_attrs["obj"]:
|
if e.from_attrs["layer"].currentselect==e.to_attrs["obj"]:
|
||||||
e.from_attrs["layer"].currentselect = None
|
e.from_attrs["layer"].currentselect = None
|
||||||
del e.from_attrs["layer"].frames[e.from_attrs["frame"]].objs[e.from_attrs["layer"].frames[e.from_attrs["frame"]].objs.index(e.to_attrs["obj"])]
|
del e.from_attrs["layer"].frames[e.from_attrs["frame"]].objs[e.from_attrs["layer"].frames[e.from_attrs["frame"]].objs.index(e.to_attrs["obj"])]
|
||||||
|
elif e.type=="text":
|
||||||
|
e.obj.text = e.from_attrs["text"]
|
||||||
|
e.obj.cursorpos = e.from_attrs["cursorpos"]
|
||||||
redo_stack.append(e)
|
redo_stack.append(e)
|
||||||
MainWindow.stage.draw()
|
MainWindow.stage.draw()
|
||||||
|
|
||||||
|
|
@ -615,6 +623,9 @@ def redo(widget=None):
|
||||||
e.obj.fillcolor = e.to_attrs["fillcolor"]
|
e.obj.fillcolor = e.to_attrs["fillcolor"]
|
||||||
elif e.type=="add_object":
|
elif e.type=="add_object":
|
||||||
e.to_attrs["layer"].frames[e.from_attrs["frame"]].objs.append(e.to_attrs["obj"])
|
e.to_attrs["layer"].frames[e.from_attrs["frame"]].objs.append(e.to_attrs["obj"])
|
||||||
|
elif e.type=="text":
|
||||||
|
e.obj.text = e.to_attrs["text"]
|
||||||
|
e.obj.cursorpos = e.to_attrs["cursorpos"]
|
||||||
undo_stack.append(e)
|
undo_stack.append(e)
|
||||||
MainWindow.stage.draw()
|
MainWindow.stage.draw()
|
||||||
|
|
||||||
|
|
|
||||||
92
svlgui.py
92
svlgui.py
|
|
@ -1848,6 +1848,20 @@ class Text (object):
|
||||||
else:
|
else:
|
||||||
self.text=self.text[:self.cursorpos]+str(key)+self.text[self.cursorpos:]
|
self.text=self.text[:self.cursorpos]+str(key)+self.text[self.cursorpos:]
|
||||||
self.cursorpos += 1
|
self.cursorpos += 1
|
||||||
|
if not key=="enter":
|
||||||
|
if len(undo_stack)>0:
|
||||||
|
if isinstance(undo_stack[-1], maybe):
|
||||||
|
if undo_stack[-1].edit.obj==self:
|
||||||
|
undo_stack[-1].edit.to_attrs={"text":self.text, "cursorpos":self.cursorpos}
|
||||||
|
else:
|
||||||
|
undo_stack.append(maybe("text", self, {"text":self.text, "cursorpos":self.cursorpos}))
|
||||||
|
else:
|
||||||
|
undo_stack.append(maybe("text", self, {"text":self.text, "cursorpos":self.cursorpos}))
|
||||||
|
else:
|
||||||
|
undo_stack.append(maybe("text", self, {"text":self.text, "cursorpos":self.cursorpos}))
|
||||||
|
else:
|
||||||
|
undo_stack[-1] = undo_stack[-1].complete({"text":self.text, "cursorpos":self.cursorpos})
|
||||||
|
clear(redo_stack)
|
||||||
pass
|
pass
|
||||||
def onKeyUp(self, self1, key):
|
def onKeyUp(self, self1, key):
|
||||||
pass
|
pass
|
||||||
|
|
@ -2116,9 +2130,9 @@ class Layer:
|
||||||
def getminy(self):
|
def getminy(self):
|
||||||
return min([i.miny for i in self.currentFrame()])
|
return min([i.miny for i in self.currentFrame()])
|
||||||
def getmaxx(self):
|
def getmaxx(self):
|
||||||
return max([i.maxx for i in self.currentFrame()])
|
return max([i.maxx+i.x for i in self.currentFrame()])
|
||||||
def getmaxy(self):
|
def getmaxy(self):
|
||||||
return max([i.maxy for i in self.currentFrame()])
|
return max([i.maxy+i.y for i in self.currentFrame()])
|
||||||
def onMouseDown(self, self1, x, y, button=1, clicks=1):
|
def onMouseDown(self, self1, x, y, button=1, clicks=1):
|
||||||
pass
|
pass
|
||||||
def onMouseDrag(self, self1, x, y, button=1, clicks=1):
|
def onMouseDrag(self, self1, x, y, button=1, clicks=1):
|
||||||
|
|
@ -2370,6 +2384,14 @@ class Group (object):
|
||||||
self.xscale = 1
|
self.xscale = 1
|
||||||
self.yscale = 1
|
self.yscale = 1
|
||||||
self.type = "Group"
|
self.type = "Group"
|
||||||
|
self.startx = 0
|
||||||
|
self.starty = 0
|
||||||
|
self.cx = 0
|
||||||
|
self.cy = 0
|
||||||
|
self.dragging = False
|
||||||
|
self.selecting = False
|
||||||
|
self.tempgroup = None
|
||||||
|
self.name = "g"+str(int(random.random()*10000))+str(SITER)
|
||||||
if "onload" in kwargs:
|
if "onload" in kwargs:
|
||||||
kwargs["onload"](self)
|
kwargs["onload"](self)
|
||||||
def draw(self,cr=None,transform=None,rect=None):
|
def draw(self,cr=None,transform=None,rect=None):
|
||||||
|
|
@ -2381,6 +2403,12 @@ class Group (object):
|
||||||
i.xscale = self.xscale
|
i.xscale = self.xscale
|
||||||
i.yscale = self.yscale
|
i.yscale = self.yscale
|
||||||
i.draw(cr,rect=rect)
|
i.draw(cr,rect=rect)
|
||||||
|
if self.dragging and self.selecting and MODE in (" ", "s"):
|
||||||
|
if SYSTEM=="osx":
|
||||||
|
cr.newpath()
|
||||||
|
cr.pencolor = Color([0,0,1]).pygui
|
||||||
|
cr.stroke_rect([sorted([self.startx,self.cx])[0], sorted([self.starty,self.cy])[0], \
|
||||||
|
sorted([self.startx,self.cx])[1], sorted([self.starty,self.cy])[1]])
|
||||||
def add(self, *args):
|
def add(self, *args):
|
||||||
self.activelayer.add(*args)
|
self.activelayer.add(*args)
|
||||||
def add_frame(self, populate):
|
def add_frame(self, populate):
|
||||||
|
|
@ -2437,26 +2465,50 @@ class Group (object):
|
||||||
test = False
|
test = False
|
||||||
for i in reversed(self.currentFrame()):
|
for i in reversed(self.currentFrame()):
|
||||||
if i.hitTest(x, y):
|
if i.hitTest(x, y):
|
||||||
|
print i.obj, "is hit"
|
||||||
if MODE in [" ", "s"]:
|
if MODE in [" ", "s"]:
|
||||||
self.activelayer.currentselect = i
|
self.activelayer.currentselect = i
|
||||||
test=True
|
test=True
|
||||||
|
print 'onmousedowning'
|
||||||
i._onMouseDown(x, y, button=button, clicks=clicks)
|
i._onMouseDown(x, y, button=button, clicks=clicks)
|
||||||
break
|
break
|
||||||
if not test:
|
if not test:
|
||||||
|
if self.tempgroup:
|
||||||
|
[self.currentFrame().append(i) for i in self.tempgroup.split()]
|
||||||
|
del self.currentFrame()[self.currentFrame().index(self.tempgroup)]
|
||||||
|
self.tempgroup = None
|
||||||
self.activelayer.currentselect = None
|
self.activelayer.currentselect = None
|
||||||
|
self.startx, self.starty = x, y
|
||||||
|
self.selecting = True
|
||||||
else:
|
else:
|
||||||
self.onMouseDown(self, x, y, button=button, clicks=clicks)
|
self.onMouseDown(self, x, y, button=button, clicks=clicks)
|
||||||
else:
|
else:
|
||||||
|
print "HEYY"
|
||||||
self.onMouseDown(self, x, y, button=button, clicks=clicks)
|
self.onMouseDown(self, x, y, button=button, clicks=clicks)
|
||||||
def onMouseDown(self, self1, x, y, button=1, clicks=1):
|
def onMouseDown(self, self1, x, y, button=1, clicks=1):
|
||||||
pass
|
pass
|
||||||
def _onMouseUp(self,x,y, button=1, clicks=1):
|
def _onMouseUp(self,x,y, button=1, clicks=1):
|
||||||
global SCALING
|
global SCALING
|
||||||
SCALING = False
|
SCALING = False
|
||||||
|
self.dragging = False
|
||||||
|
self.selecting = False
|
||||||
x, y = self.localtransform(x, y)
|
x, y = self.localtransform(x, y)
|
||||||
if self.activelayer.level and MODE in [" ", "s"]:
|
if self.activelayer.level and MODE in [" ", "s"]:
|
||||||
if self.activelayer.currentselect:
|
if self.activelayer.currentselect:
|
||||||
self.activelayer.currentselect._onMouseUp(x, y, button=button, clicks=clicks)
|
self.activelayer.currentselect._onMouseUp(x, y, button=button, clicks=clicks)
|
||||||
|
else:
|
||||||
|
objs = []
|
||||||
|
for i in reversed(self.currentFrame()):
|
||||||
|
if self.startx<i.x+i.minx<x or self.startx<i.x+i.maxx<x:
|
||||||
|
if self.starty<i.y+i.miny<y or self.starty<i.y+i.maxy<y:
|
||||||
|
objs.append(i)
|
||||||
|
del self.currentFrame()[self.currentFrame().index(i)]
|
||||||
|
print objs
|
||||||
|
tgroup = TemporaryGroup(skipl=True)
|
||||||
|
[tgroup.add(i.obj) for i in reversed(objs)]
|
||||||
|
self.add(tgroup)
|
||||||
|
self.activelayer.currentselect = tgroup
|
||||||
|
print [i.obj for i in self.currentFrame()]
|
||||||
else:
|
else:
|
||||||
self.onMouseUp(self, x, y, button=button, clicks=clicks)
|
self.onMouseUp(self, x, y, button=button, clicks=clicks)
|
||||||
def onMouseUp(self, self1, x, y, button=1, clicks=1):
|
def onMouseUp(self, self1, x, y, button=1, clicks=1):
|
||||||
|
|
@ -2472,6 +2524,8 @@ class Group (object):
|
||||||
pass
|
pass
|
||||||
def _onMouseDrag(self, x, y, button=1, clicks=1):
|
def _onMouseDrag(self, x, y, button=1, clicks=1):
|
||||||
x, y = self.localtransform(x, y)
|
x, y = self.localtransform(x, y)
|
||||||
|
self.cx, self.cy = x, y
|
||||||
|
self.dragging = True
|
||||||
if self.activelayer.level and MODE in [" ", "s"]:
|
if self.activelayer.level and MODE in [" ", "s"]:
|
||||||
if self.activelayer.currentselect:
|
if self.activelayer.currentselect:
|
||||||
self.activelayer.currentselect._onMouseDrag(x, y, button=button)
|
self.activelayer.currentselect._onMouseDrag(x, y, button=button)
|
||||||
|
|
@ -2503,7 +2557,7 @@ class Group (object):
|
||||||
def hitTest(self,x,y):
|
def hitTest(self,x,y):
|
||||||
for i in self.layers:
|
for i in self.layers:
|
||||||
for j in i.frames[0].objs:
|
for j in i.frames[0].objs:
|
||||||
if i.hitTest(x, y):
|
if j.hitTest(x, y):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
def print_sc(self):
|
def print_sc(self):
|
||||||
|
|
@ -2549,6 +2603,32 @@ class Group (object):
|
||||||
retval += self.name+"._layers["+str(i)+"]._frames["+str(j)+"].actions = \""+self.layers[i].frames[j].actions.replace("\n"," ").replace("\\","\\\\").replace("\"","\\\"")+"\"\n"
|
retval += self.name+"._layers["+str(i)+"]._frames["+str(j)+"].actions = \""+self.layers[i].frames[j].actions.replace("\n"," ").replace("\\","\\\\").replace("\"","\\\"")+"\"\n"
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
class TemporaryGroup(Group):
|
||||||
|
"""Created when selecting multiple items, for ease of use."""
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(TemporaryGroup, self).__init__(*args, **kwargs)
|
||||||
|
# def draw(self, cr=None, transform=None, rect=None):
|
||||||
|
# super(TemporaryGroup, self).draw(cr, transform, rect)
|
||||||
|
# print self.x, self.activelayer.x
|
||||||
|
# pass
|
||||||
|
def split(self):
|
||||||
|
return self.currentFrame()
|
||||||
|
pass
|
||||||
|
def onMouseDown(self, self1, x, y, button=1, clicks=1):
|
||||||
|
print "Hihihihihi"
|
||||||
|
if self1.hitTest(x, y):
|
||||||
|
self1.clicked = True
|
||||||
|
self1.initx,self1.inity = x-self1.x, y-self1.y
|
||||||
|
def onMouseDrag(self, self1, x, y, button=1, clicks=1):
|
||||||
|
self1.x = x-self1.initx
|
||||||
|
self1.y = y-self1.inity
|
||||||
|
def onMouseUp(self, self1, x, y, button=1, clicks=1):
|
||||||
|
self.clicked = False
|
||||||
|
# def hitTest(self, x, y):
|
||||||
|
# print self.x, self.y, x, y
|
||||||
|
# return True
|
||||||
|
|
||||||
|
|
||||||
def set_cursor(curs, widget=None):
|
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,
|
||||||
|
|
@ -2753,6 +2833,12 @@ class ColorSelectionWindow:
|
||||||
global FILLCOLOR
|
global FILLCOLOR
|
||||||
FILLCOLOR = Color(colors.colorArray(int(x/16))[int(y/16)])
|
FILLCOLOR = Color(colors.colorArray(int(x/16))[int(y/16)])
|
||||||
if root.descendItem().activelayer.currentselect:
|
if root.descendItem().activelayer.currentselect:
|
||||||
|
if not (root.descendItem().activelayer.currentselect.fillcolor.val == FILLCOLOR.val and root.descendItem().activelayer.currentselect.filled==True):
|
||||||
|
undo_stack.append(edit("fill", root.descendItem().activelayer.currentselect, \
|
||||||
|
{"filled":root.descendItem().activelayer.currentselect.filled, \
|
||||||
|
"fillcolor":root.descendItem().activelayer.currentselect.fillcolor},
|
||||||
|
{"filled":True, "fillcolor":svlgui.FILLCOLOR}))
|
||||||
|
clear(redo_stack)
|
||||||
root.descendItem().activelayer.currentselect.fillcolor = FILLCOLOR
|
root.descendItem().activelayer.currentselect.fillcolor = FILLCOLOR
|
||||||
root.descendItem().activelayer.currentselect.filled = True
|
root.descendItem().activelayer.currentselect.filled = True
|
||||||
root.descendItem().activelayer.currentselect.update()
|
root.descendItem().activelayer.currentselect.update()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue