Commit e37b08ff authored by kliment's avatar kliment

Merge pull request #22 from k-eex/master

mousewheel zooming in gviz window
parents 4229d449 dc9cd711
...@@ -10,6 +10,8 @@ class window(wx.Frame): ...@@ -10,6 +10,8 @@ class window(wx.Frame):
#print time.time()-s #print time.time()-s
self.p.Bind(wx.EVT_KEY_DOWN,self.key) self.p.Bind(wx.EVT_KEY_DOWN,self.key)
self.Bind(wx.EVT_KEY_DOWN,self.key) self.Bind(wx.EVT_KEY_DOWN,self.key)
self.p.Bind(wx.EVT_MOUSEWHEEL,self.zoom)
self.Bind(wx.EVT_MOUSEWHEEL,self.zoom)
def key(self, event): def key(self, event):
x=event.GetKeyCode() x=event.GetKeyCode()
...@@ -20,6 +22,14 @@ class window(wx.Frame): ...@@ -20,6 +22,14 @@ class window(wx.Frame):
self.p.layerdown() self.p.layerdown()
#print p.lines.keys() #print p.lines.keys()
def zoom(self, event):
z=event.GetWheelRotation()
if event.ShiftDown():
if z > 0: self.p.layerdown()
elif z < 0: self.p.layerup()
else:
if z > 0: self.p.zoom(event.GetX(),event.GetY(),1.2)
elif z < 0: self.p.zoom(event.GetX(),event.GetY(),1/1.2)
class gviz(wx.Panel): class gviz(wx.Panel):
def __init__(self,parent,size=(200,200),bedsize=(200,200)): def __init__(self,parent,size=(200,200),bedsize=(200,200)):
...@@ -34,6 +44,7 @@ class gviz(wx.Panel): ...@@ -34,6 +44,7 @@ class gviz(wx.Panel):
self.layers=[] self.layers=[]
self.layerindex=0 self.layerindex=0
self.scale=[min(float(size[0])/bedsize[0],float(size[1])/bedsize[1])]*2 self.scale=[min(float(size[0])/bedsize[0],float(size[1])/bedsize[1])]*2
self.translate=[0.0, 0.0]
self.mainpen=wx.Pen(wx.Colour(0,0,0)) self.mainpen=wx.Pen(wx.Colour(0,0,0))
self.hlpen=wx.Pen(wx.Colour(200,50,50)) self.hlpen=wx.Pen(wx.Colour(200,50,50))
self.fades=[wx.Pen(wx.Colour(150+20*i,150+20*i,150+20*i)) for i in xrange(6)] self.fades=[wx.Pen(wx.Colour(150+20*i,150+20*i,150+20*i)) for i in xrange(6)]
...@@ -67,6 +78,11 @@ class gviz(wx.Panel): ...@@ -67,6 +78,11 @@ class gviz(wx.Panel):
except: except:
pass pass
def zoom(self,x,y,factor):
self.scale = [s * factor for s in self.scale]
self.translate = [ x - (x-self.translate[0]) * factor,
y - (y-self.translate[1]) * factor]
self.Refresh()
def paint(self,event): def paint(self,event):
dc=wx.PaintDC(self) dc=wx.PaintDC(self)
...@@ -78,21 +94,26 @@ class gviz(wx.Panel): ...@@ -78,21 +94,26 @@ class gviz(wx.Panel):
dc.SetBrush(wx.Brush((0,255,0))) dc.SetBrush(wx.Brush((0,255,0)))
if len(self.layers): if len(self.layers):
dc.DrawRectangle(self.size[0]-14,(1.0-(1.0*(self.layerindex+1))/len(self.layers))*self.size[1],13,self.size[1]-1) dc.DrawRectangle(self.size[0]-14,(1.0-(1.0*(self.layerindex+1))/len(self.layers))*self.size[1],13,self.size[1]-1)
def scaler(x):
return (self.scale[0]*x[0]+self.translate[0],
self.scale[1]*x[1]+self.translate[1],
self.scale[0]*x[2]+self.translate[0],
self.scale[1]*x[3]+self.translate[1],)
if self.showall: if self.showall:
l=[] l=[]
for i in self.layers: for i in self.layers:
dc.DrawLineList(l,self.fades[0]) dc.DrawLineList(l,self.fades[0])
l=map(lambda x:(self.scale[0]*x[0],self.scale[1]*x[1],self.scale[0]*x[2],self.scale[1]*x[3],) ,self.lines[i]) l=map(scaler,self.lines[i])
dc.DrawLineList(l,self.pens[i]) dc.DrawLineList(l,self.pens[i])
return return
if self.layerindex<len(self.layers) and self.layers[self.layerindex] in self.lines.keys(): if self.layerindex<len(self.layers) and self.layers[self.layerindex] in self.lines.keys():
for i in range(min(self.layerindex,6))[-6:]: for i in range(min(self.layerindex,6))[-6:]:
#print i, self.layerindex, self.layerindex-i #print i, self.layerindex, self.layerindex-i
l=map(lambda x:(self.scale[0]*x[0],self.scale[1]*x[1],self.scale[0]*x[2],self.scale[1]*x[3],) ,self.lines[self.layers[self.layerindex-i-1]]) l=map(scaler,self.lines[self.layers[self.layerindex-i-1]])
dc.DrawLineList(l,self.fades[i]) dc.DrawLineList(l,self.fades[i])
l=map(lambda x:(self.scale[0]*x[0],self.scale[1]*x[1],self.scale[0]*x[2],self.scale[1]*x[3],) ,self.lines[self.layers[self.layerindex]]) l=map(scaler,self.lines[self.layers[self.layerindex]])
dc.DrawLineList(l,self.pens[self.layers[self.layerindex]]) dc.DrawLineList(l,self.pens[self.layers[self.layerindex]])
l=map(lambda x:(self.scale[0]*x[0],self.scale[1]*x[1],self.scale[0]*x[2],self.scale[1]*x[3],) ,self.hilight) l=map(scaler,self.hilight)
dc.DrawLineList(l,self.hlpen) dc.DrawLineList(l,self.hlpen)
del dc del dc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment