Commit 05ee1da7 authored by Guillaume Seguin's avatar Guillaume Seguin

Add keypress handling to gcview

parent a2dded25
...@@ -254,6 +254,7 @@ class GcodeViewPanel(wxGLPanel): ...@@ -254,6 +254,7 @@ class GcodeViewPanel(wxGLPanel):
self.rot = 0 self.rot = 0
self.canvas.Bind(wx.EVT_MOUSE_EVENTS, self.move) self.canvas.Bind(wx.EVT_MOUSE_EVENTS, self.move)
self.canvas.Bind(wx.EVT_LEFT_DCLICK, self.double) self.canvas.Bind(wx.EVT_LEFT_DCLICK, self.double)
self.canvas.Bind(wx.EVT_KEY_DOWN, self.keypress)
self.initialized = 0 self.initialized = 0
self.canvas.Bind(wx.EVT_MOUSEWHEEL, self.wheel) self.canvas.Bind(wx.EVT_MOUSEWHEEL, self.wheel)
self.parent = parent self.parent = parent
...@@ -317,6 +318,10 @@ class GcodeViewPanel(wxGLPanel): ...@@ -317,6 +318,10 @@ class GcodeViewPanel(wxGLPanel):
LMB: rotate viewport LMB: rotate viewport
RMB: move viewport RMB: move viewport
""" """
if event.Entering():
self.canvas.SetFocus()
event.Skip()
return
if event.Dragging() and event.LeftIsDown(): if event.Dragging() and event.LeftIsDown():
if self.initpos == None: if self.initpos == None:
self.initpos = event.GetPositionTuple() self.initpos = event.GetPositionTuple()
...@@ -375,35 +380,30 @@ class GcodeViewPanel(wxGLPanel): ...@@ -375,35 +380,30 @@ class GcodeViewPanel(wxGLPanel):
self.rot = 1 self.rot = 1
self.initpos = None self.initpos = None
else: else:
event.Skip()
return return
event.Skip()
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
def wheel(self, event): def layerup(self):
"""react to mouse wheel actions:
without shift: set max layer
with shift: zoom viewport
"""
z = event.GetWheelRotation()
angle = 10
if event.ShiftDown():
if not self.parent.model: if not self.parent.model:
return return
if z > 0:
max_layers = self.parent.model.max_layers max_layers = self.parent.model.max_layers
current_layer = self.parent.model.num_layers_to_draw current_layer = self.parent.model.num_layers_to_draw
new_layer = min(max_layers, current_layer + 1) new_layer = min(max_layers, current_layer + 1)
self.parent.model.num_layers_to_draw = new_layer self.parent.model.num_layers_to_draw = new_layer
else: wx.CallAfter(self.Refresh)
def layerdown(self):
if not self.parent.model:
return
current_layer = self.parent.model.num_layers_to_draw current_layer = self.parent.model.num_layers_to_draw
new_layer = max(1, current_layer - 1) new_layer = max(1, current_layer - 1)
self.parent.model.num_layers_to_draw = new_layer self.parent.model.num_layers_to_draw = new_layer
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
return
if z > 0:
self.transv[2] += angle
else:
self.transv[2] -= angle
def zoom(self, dist):
self.transv[2] += dist
glLoadIdentity() glLoadIdentity()
glTranslatef(*self.transv) glTranslatef(*self.transv)
if self.rot: if self.rot:
...@@ -412,33 +412,45 @@ class GcodeViewPanel(wxGLPanel): ...@@ -412,33 +412,45 @@ class GcodeViewPanel(wxGLPanel):
self.rot = 1 self.rot = 1
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
def wheel(self, event):
"""react to mouse wheel actions:
without shift: set max layer
with shift: zoom viewport
"""
z = event.GetWheelRotation()
dist = 10
if event.ShiftDown():
if not self.parent.model:
return
if z > 0:
self.layerup()
else:
self.layerdown()
return
if z > 0:
self.zoom(dist)
else:
self.zoom(-dist)
def keypress(self, event): def keypress(self, event):
"""gets keypress events and moves/rotates acive shape""" """gets keypress events and moves/rotates acive shape"""
keycode = event.GetKeyCode() keycode = event.GetKeyCode()
print keycode step = 10
step = 5
angle = 18
if event.ControlDown(): if event.ControlDown():
step = 1 step = 3
angle = 1 kup = [85, 315] # Up keys
#h kdo = [68, 317] # Down Keys
if keycode == 72: kzi = [wx.WXK_PAGEDOWN, 388, 316, 61] # Zoom In Keys
self.move_shape((-step, 0)) kzo = [wx.WXK_PAGEUP, 390, 314, 45] # Zoom Out Keys
#l x = event.GetKeyCode()
if keycode == 76: if x in kup:
self.move_shape((step, 0)) self.layerup()
#j if x in kdo:
if keycode == 75: self.layerdown()
self.move_shape((0, step)) if x in kzi:
#k self.zoom(step)
if keycode == 74: if x in kzo:
self.move_shape((0, -step)) self.zoom(-step)
#[
if keycode == 91:
self.rotate_shape(-angle)
#]
if keycode == 93:
self.rotate_shape(angle)
event.Skip() event.Skip()
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
...@@ -489,18 +501,6 @@ class GcodeViewFrame(wx.Frame): ...@@ -489,18 +501,6 @@ class GcodeViewFrame(wx.Frame):
self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] - 1)) self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] - 1))
self.Refresh() self.Refresh()
def setlayerindex(self, z):
model = self.objects[-1].model
if not model:
return
mlk = sorted(m.gc.layers.keys())
if z > 0 and self.modelindex < len(mlk) - 1:
self.modelindex += 1
if z < 0 and self.modelindex > 0:
self.modelindex -= 1
m.curlayer = mlk[self.modelindex]
wx.CallAfter(self.SetTitle, "Gcode view, shift to move. Layer %d, Z = %f" % (self.modelindex, m.curlayer))
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
app = wx.App(redirect = False) app = wx.App(redirect = False)
......
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