Commit 6071c429 authored by Duane Johnson's avatar Duane Johnson

Add ability to repeat last movement command with the spacebar

parent d731aaf9
......@@ -579,7 +579,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
#lls.Add((200,375))
self.xyb = XYButtons(self.panel, self.moveXY, self.homeButtonClicked)
self.xyb = XYButtons(self.panel, self.moveXY, self.homeButtonClicked, self.spacebarAction)
lls.Add(self.xyb, pos=(2,0), span=(1,6), flag=wx.ALIGN_CENTER)
self.zb = ZButtons(self.panel, self.moveZ)
lls.Add(self.zb, pos=(2,7), span=(1,2), flag=wx.ALIGN_CENTER)
......@@ -741,7 +741,6 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
#uts.Layout()
self.cbuttons_reload()
def plate(self,e):
import plater
print "plate function activated"
......@@ -1117,16 +1116,26 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.onecmd('home Z')
if corner == 3: # lower-left
self.onecmd('home')
# When user clicks on the XY control, the Z control no longer gets spacebar/repeat signals
self.zb.clearRepeat()
def moveXY(self, x, y):
if x != 0:
self.onecmd('move X %s' % x)
if y != 0:
self.onecmd('move Y %s' % y)
# When user clicks on the XY control, the Z control no longer gets spacebar/repeat signals
self.zb.clearRepeat()
def moveZ(self, z):
if z != 0:
self.onecmd('move Z %s' % z)
# When user clicks on the Z control, the XY control no longer gets spacebar/repeat signals
self.xyb.clearRepeat()
def spacebarAction(self):
self.zb.repeatLast()
self.xyb.repeatLast()
def procbutton(self,e):
try:
......
......@@ -47,7 +47,7 @@ class XYButtons(BufferedCanvas):
center = (124, 121)
spacer = 7
def __init__(self, parent, moveCallback=None, cornerCallback=None, ID=-1):
def __init__(self, parent, moveCallback=None, cornerCallback=None, spacebarCallback=None, ID=-1):
self.bg_bmp = wx.Image(imagefile("control_xy.png"),wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.keypad_bmp = wx.Image(imagefile("arrow_keys.png"),wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.keypad_idx = -1
......@@ -56,7 +56,11 @@ class XYButtons(BufferedCanvas):
self.corner = None
self.moveCallback = moveCallback
self.cornerCallback = cornerCallback
self.spacebarCallback = spacebarCallback
self.enabled = False
# Remember the last clicked buttons, so we can repeat when spacebar pressed
self.lastMove = None
self.lastCorner = None
BufferedCanvas.__init__(self, parent, ID)
self.SetSize(self.bg_bmp.GetSize())
......@@ -76,7 +80,17 @@ class XYButtons(BufferedCanvas):
def enable(self):
self.enabled = True
self.update()
def repeatLast(self):
if self.lastMove:
self.moveCallback(*self.lastMove)
if self.lastCorner:
self.cornerCallback(self.lastCorner)
def clearRepeat(self):
self.lastMove = None
self.lastCorner = None
def distanceToLine(self, pos, x1, y1, x2, y2):
xlen = x2 - x1
ylen = y2 - y1
......@@ -273,8 +287,6 @@ class XYButtons(BufferedCanvas):
self.quadrant = 2
elif evt.GetKeyCode() == wx.WXK_RIGHT:
self.quadrant = 0
elif evt.GetKeyCode() == wx.WXK_SPACE:
pass
else:
evt.Skip()
return
......@@ -283,6 +295,9 @@ class XYButtons(BufferedCanvas):
self.concentric = self.keypad_idx
x, y = self.getMovement()
self.moveCallback(x, y)
elif evt.GetKeyCode() == wx.WXK_SPACE:
self.spacebarCallback()
def OnMotion(self, event):
if not self.enabled:
......@@ -335,9 +350,13 @@ class XYButtons(BufferedCanvas):
if self.quadrant != None:
x, y = self.getMovement()
if self.moveCallback:
self.lastMove = (x, y)
self.lastCorner = None
self.moveCallback(x, y)
elif self.corner != None:
if self.cornerCallback:
self.lastCorner = self.corner
self.lastMove = None
self.cornerCallback(self.corner)
else:
if self.keypad_idx == idx:
......
......@@ -46,6 +46,8 @@ class ZButtons(BufferedCanvas):
self.orderOfMagnitudeIdx = 0 # 0 means '1', 1 means '10', 2 means '100', etc.
self.moveCallback = moveCallback
self.enabled = False
# Remember the last clicked value, so we can repeat when spacebar pressed
self.lastValue = None
BufferedCanvas.__init__(self, parent, ID)
......@@ -65,6 +67,13 @@ class ZButtons(BufferedCanvas):
self.enabled = True
self.update()
def repeatLast(self):
if self.lastValue:
self.moveCallback(self.lastValue)
def clearRepeat(self):
self.lastValue = None
def lookupRange(self, ydist):
idx = -1
for d in ZButtons.button_ydistances:
......@@ -143,6 +152,7 @@ class ZButtons(BufferedCanvas):
if r >= 0:
value = math.pow(10, self.orderOfMagnitudeIdx) * math.pow(10, r - 1) * d
if self.moveCallback:
self.lastValue = value
self.moveCallback(value)
def OnLeaveWindow(self, evt):
......
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