Merge branch 'spacebar' of https://github.com/canadaduane/Printrun into experimental

master
Kliment Yanev 2012-05-03 09:53:09 +02:00
commit f10d6c06e6
3 changed files with 43 additions and 5 deletions

View File

@ -579,7 +579,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
szbuttons=wx.GridBagSizer() szbuttons=wx.GridBagSizer()
self.xyb = XYButtons(self.panel, self.moveXY, self.homeButtonClicked) self.xyb = XYButtons(self.panel, self.moveXY, self.homeButtonClicked, self.spacebarAction)
szbuttons.Add(self.xyb,pos=(0,1),flag=wx.ALIGN_CENTER) szbuttons.Add(self.xyb,pos=(0,1),flag=wx.ALIGN_CENTER)
self.zb = ZButtons(self.panel, self.moveZ) self.zb = ZButtons(self.panel, self.moveZ)
szbuttons.Add(self.zb,pos=(0,2),flag=wx.ALIGN_CENTER) szbuttons.Add(self.zb,pos=(0,2),flag=wx.ALIGN_CENTER)
@ -748,7 +748,6 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
#uts.Layout() #uts.Layout()
self.cbuttons_reload() self.cbuttons_reload()
def plate(self,e): def plate(self,e):
import plater import plater
print "plate function activated" print "plate function activated"
@ -1119,16 +1118,26 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.onecmd('home Z') self.onecmd('home Z')
if corner == 3: # lower-left if corner == 3: # lower-left
self.onecmd('home') 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): def moveXY(self, x, y):
if x != 0: if x != 0:
self.onecmd('move X %s' % x) self.onecmd('move X %s' % x)
if y != 0: if y != 0:
self.onecmd('move Y %s' % y) 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): def moveZ(self, z):
if z != 0: if z != 0:
self.onecmd('move Z %s' % z) 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): def procbutton(self,e):
try: try:

View File

@ -47,7 +47,7 @@ class XYButtons(BufferedCanvas):
center = (124, 121) center = (124, 121)
spacer = 7 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.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_bmp = wx.Image(imagefile("arrow_keys.png"),wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.keypad_idx = -1 self.keypad_idx = -1
@ -56,7 +56,11 @@ class XYButtons(BufferedCanvas):
self.corner = None self.corner = None
self.moveCallback = moveCallback self.moveCallback = moveCallback
self.cornerCallback = cornerCallback self.cornerCallback = cornerCallback
self.spacebarCallback = spacebarCallback
self.enabled = False 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) BufferedCanvas.__init__(self, parent, ID)
self.SetSize(self.bg_bmp.GetSize()) self.SetSize(self.bg_bmp.GetSize())
@ -76,7 +80,17 @@ class XYButtons(BufferedCanvas):
def enable(self): def enable(self):
self.enabled = True self.enabled = True
self.update() 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): def distanceToLine(self, pos, x1, y1, x2, y2):
xlen = x2 - x1 xlen = x2 - x1
ylen = y2 - y1 ylen = y2 - y1
@ -273,8 +287,6 @@ class XYButtons(BufferedCanvas):
self.quadrant = 2 self.quadrant = 2
elif evt.GetKeyCode() == wx.WXK_RIGHT: elif evt.GetKeyCode() == wx.WXK_RIGHT:
self.quadrant = 0 self.quadrant = 0
elif evt.GetKeyCode() == wx.WXK_SPACE:
pass
else: else:
evt.Skip() evt.Skip()
return return
@ -283,6 +295,9 @@ class XYButtons(BufferedCanvas):
self.concentric = self.keypad_idx self.concentric = self.keypad_idx
x, y = self.getMovement() x, y = self.getMovement()
self.moveCallback(x, y) self.moveCallback(x, y)
elif evt.GetKeyCode() == wx.WXK_SPACE:
self.spacebarCallback()
def OnMotion(self, event): def OnMotion(self, event):
if not self.enabled: if not self.enabled:
@ -335,9 +350,13 @@ class XYButtons(BufferedCanvas):
if self.quadrant != None: if self.quadrant != None:
x, y = self.getMovement() x, y = self.getMovement()
if self.moveCallback: if self.moveCallback:
self.lastMove = (x, y)
self.lastCorner = None
self.moveCallback(x, y) self.moveCallback(x, y)
elif self.corner != None: elif self.corner != None:
if self.cornerCallback: if self.cornerCallback:
self.lastCorner = self.corner
self.lastMove = None
self.cornerCallback(self.corner) self.cornerCallback(self.corner)
else: else:
if self.keypad_idx == idx: if self.keypad_idx == idx:

View File

@ -46,6 +46,8 @@ class ZButtons(BufferedCanvas):
self.orderOfMagnitudeIdx = 0 # 0 means '1', 1 means '10', 2 means '100', etc. self.orderOfMagnitudeIdx = 0 # 0 means '1', 1 means '10', 2 means '100', etc.
self.moveCallback = moveCallback self.moveCallback = moveCallback
self.enabled = False self.enabled = False
# Remember the last clicked value, so we can repeat when spacebar pressed
self.lastValue = None
BufferedCanvas.__init__(self, parent, ID) BufferedCanvas.__init__(self, parent, ID)
@ -65,6 +67,13 @@ class ZButtons(BufferedCanvas):
self.enabled = True self.enabled = True
self.update() self.update()
def repeatLast(self):
if self.lastValue:
self.moveCallback(self.lastValue)
def clearRepeat(self):
self.lastValue = None
def lookupRange(self, ydist): def lookupRange(self, ydist):
idx = -1 idx = -1
for d in ZButtons.button_ydistances: for d in ZButtons.button_ydistances:
@ -143,6 +152,7 @@ class ZButtons(BufferedCanvas):
if r >= 0: if r >= 0:
value = math.pow(10, self.orderOfMagnitudeIdx) * math.pow(10, r - 1) * d value = math.pow(10, self.orderOfMagnitudeIdx) * math.pow(10, r - 1) * d
if self.moveCallback: if self.moveCallback:
self.lastValue = value
self.moveCallback(value) self.moveCallback(value)
def OnLeaveWindow(self, evt): def OnLeaveWindow(self, evt):