Commit 540faffe authored by Duane Johnson's avatar Duane Johnson

XY and Z control panels working side by side

parent 69c639e6
images/control_xy.png

41.9 KB | W: | H:

images/control_xy.png

44.1 KB | W: | H:

images/control_xy.png
images/control_xy.png
images/control_xy.png
images/control_xy.png
  • 2-up
  • Swipe
  • Onion skin
images/control_z.png

11.9 KB | W: | H:

images/control_z.png

9.43 KB | W: | H:

images/control_z.png
images/control_z.png
images/control_z.png
images/control_z.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -4,13 +4,99 @@ from bufferedcanvas import *
def imagefile(filename):
return os.path.join(os.path.dirname(__file__), "images", filename)
def sign(n):
if n < 0: return -1
elif n > 0: return 1
else: return 0
class ZButtons(BufferedCanvas):
button_ydistances = [16, 46, 80, 118]
center = (36, 147)
def __init__(self, parent, ID=-1):
self.bg_bmp = wx.Image(imagefile("control_z.png"),wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.range = None
self.direction = None
self.orderOfMagnitudeIdx = 0 # 0 means '1', 1 means '10', 2 means '100', etc.
BufferedCanvas.__init__(self, parent, ID)
self.SetSize(wx.Size(71, 297))
# Set up mouse and keyboard event capture
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDown)
self.Bind(wx.EVT_MOTION, self.OnMotion)
def lookupRange(self, ydist):
idx = -1
for d in ZButtons.button_ydistances:
if ydist < d:
return idx
idx += 1
return None
def highlight(self, dc, rng, dir):
assert(rng >= -1 and rng <= 2)
assert(dir >= -1 and dir <= 1)
fudge = 10
x = 0 + fudge
w = 72 - fudge*2
if rng == -1:
y = ZButtons.center[1] - ZButtons.button_ydistances[0]
h = ZButtons.button_ydistances[0] * 2
else:
k = 1 if dir > 0 else 0
y = ZButtons.center[1] - (dir * ZButtons.button_ydistances[rng+k])
h = ZButtons.button_ydistances[rng+1] - ZButtons.button_ydistances[rng]
dc.DrawRectangle(x, y, w, h)
# self.drawPartialPie(dc, center, r1-inner_ring_radius, r2-inner_ring_radius, a1+fudge, a2-fudge)
def getRangeDir(self, pos):
ydelta = ZButtons.center[1] - pos[1]
return (self.lookupRange(abs(ydelta)), sign(ydelta))
def OnMotion(self, event):
oldr, oldd = self.range, self.direction
mpos = event.GetPosition()
self.range, self.direction = self.getRangeDir(mpos)
if oldr != self.range or oldd != self.direction:
self.update()
def OnLeftDown(self, event):
mpos = event.GetPosition()
r, d = self.getRangeDir(mpos)
if r >= 0:
value = math.pow(10, self.orderOfMagnitudeIdx) * math.pow(10, r - 1) * d
print 'z', value
else:
print 'Z home'
def draw(self, dc):
dc.Clear()
# center = wx.Point(XYButtons.center[0], XYButtons.center[1])
dc.SetPen(wx.Pen(wx.Colour(100,100,100,172), 4))
dc.SetBrush(wx.Brush(wx.Colour(0,0,0,128)))
dc.DrawBitmap(self.bg_bmp, 0, 0)
if self.range != None and self.direction != None:
self.highlight(dc, self.range, self.direction)
return True
class XYButtons(BufferedCanvas):
keypad_positions = {
0: (102, 109),
1: (78, 86),
2: (49, 58)
}
concentric_circle_radii = [19, 45, 81, 120]
concentric_circle_radii = [17, 45, 83, 122]
center = (146, 149)
distance = [
# Order of Magnitude 0 (i.e. 0.1, 1, 10)
......@@ -41,12 +127,14 @@ class XYButtons(BufferedCanvas):
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 = 0
self.orderOfMagnitude = 0
self.orderOfMagnitudeIdx = 0
self.quadrant = None
self.concentric = None
BufferedCanvas.__init__(self, parent, ID)
self.SetSize(wx.Size(297, 297))
# Set up mouse and keyboard event capture
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDown)
......@@ -115,7 +203,7 @@ class XYButtons(BufferedCanvas):
idx = self.mouseOverKeypad(mpos)
if idx != None:
self.quadrant = None
self.concentric = None
self.concentric = -1
else:
self.quadrant, self.concentric = self.getQuadrantConcentricFromPosition(mpos)
......@@ -132,9 +220,9 @@ class XYButtons(BufferedCanvas):
quadrant, concentric = self.getQuadrantConcentricFromPosition(mpos)
# print 'click:', mpos, quadrant, concentric
if concentric == -1:
print 'center button'
print 'XY home'
elif quadrant != None and concentric != None:
dist = XYButtons.distance[self.orderOfMagnitude][quadrant][concentric]
dist = XYButtons.distance[self.orderOfMagnitudeIdx][quadrant][concentric]
print 'x', dist[0], 'y', dist[1]
def drawPartialPie(self, dc, center, r1, r2, angle1, angle2):
......@@ -186,33 +274,36 @@ class XYButtons(BufferedCanvas):
self.drawPartialPie(dc, center, r1-inner_ring_radius, r2-inner_ring_radius, a1+fudge, a2-fudge)
def draw(self, dc):
# print 'draw called'
dc.Clear()
center = wx.Point(XYButtons.center[0], XYButtons.center[1])
start = wx.Point(50, 0)
end = wx.Point(0, 50)
dc.SetPen(wx.Pen(wx.Colour(100,100,100,172), 4))
dc.SetBrush(wx.Brush(wx.Colour(0,0,0,128)))
dc.DrawBitmap(self.bg_bmp, 0, 0)
# dc.DrawArc(50, 0, 0, 50, XYButtons.center[0], XYButtons.center[1])
# self.drawPartialPie(dc, center, 19, 44, -math.pi/4, math.pi/4)
if self.concentric == -1:
pass
inner_ring_radius = XYButtons.concentric_circle_radii[0]
dc.DrawCircle(XYButtons.center[0], XYButtons.center[1], inner_ring_radius+2)
elif self.quadrant != None and self.concentric != None:
self.highlightQuadrant(dc, self.quadrant, self.concentric)
pos = XYButtons.keypad_positions[self.keypad_idx]
dc.DrawBitmap(self.keypad_bmp, pos[0], pos[1])
# dc.DrawArcPoint(start, end, center)
return True
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(800, 600))
sizer = wx.BoxSizer()
self.xy = XYButtons(self)
sizer.Add(self.xy)
self.z = ZButtons(self)
sizer.Add(self.z)
self.SetSizer(sizer)
class MyApp(wx.App):
......
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