printrun-src/printrun/gui/xybuttons.py

Fri, 03 Jun 2016 21:14:09 +0200

author
mbayer
date
Fri, 03 Jun 2016 21:14:09 +0200
changeset 19
234037fbca4b
parent 15
0bbb006204fc
child 46
cce0af6351f0
permissions
-rw-r--r--

Bugfixing, Added M400 magic

15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1 # This file is part of the Printrun suite.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
3 # Printrun is free software: you can redistribute it and/or modify
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
6 # (at your option) any later version.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
7 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
8 # Printrun is distributed in the hope that it will be useful,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
11 # GNU General Public License for more details.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
12 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
16 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
17 import math
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
18 from .bufferedcanvas import BufferedCanvas
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
19 from printrun.utils import imagefile
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
20
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
21 def sign(n):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
22 if n < 0: return -1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
23 elif n > 0: return 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
24 else: return 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
25
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
26 class XYButtons(BufferedCanvas):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
27 keypad_positions = {
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
28 0: (106, 100),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
29 1: (86, 83),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
30 2: (68, 65),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
31 3: (53, 50)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
32 }
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
33 corner_size = (49, 49)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
34 corner_inset = (7, 13)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
35 label_overlay_positions = {
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
36 1: (145, 98.5, 9),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
37 2: (160.5, 83.5, 10.6),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
38 3: (178, 66, 13),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
39 4: (197.3, 46.3, 13.3)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
40 }
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
41 concentric_circle_radii = [0, 17, 45, 69, 94, 115]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
42 concentric_inset = 11
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
43 center = (124, 121)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
44 spacer = 7
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
45 imagename = "control_xy.png"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
46 corner_to_axis = {
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
47 -1: "center",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
48 0: "x",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
49 1: "z",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
50 2: "y",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
51 3: "all",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
52 }
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
53
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
54 def __init__(self, parent, moveCallback = None, cornerCallback = None, spacebarCallback = None, bgcolor = "#FFFFFF", ID=-1, zcallback=None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
55 self.bg_bmp = wx.Image(imagefile(self.imagename), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
56 self.keypad_bmp = wx.Image(imagefile("arrow_keys.png"), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
57 self.keypad_idx = -1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
58 self.quadrant = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
59 self.concentric = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
60 self.corner = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
61 self.moveCallback = moveCallback
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
62 self.cornerCallback = cornerCallback
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
63 self.spacebarCallback = spacebarCallback
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
64 self.zCallback = zcallback
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
65 self.enabled = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
66 # Remember the last clicked buttons, so we can repeat when spacebar pressed
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
67 self.lastMove = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
68 self.lastCorner = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
69
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
70 self.bgcolor = wx.Colour()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
71 self.bgcolor.SetFromName(bgcolor)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
72 self.bgcolormask = wx.Colour(self.bgcolor.Red(), self.bgcolor.Green(), self.bgcolor.Blue(), 128)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
73
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
74 BufferedCanvas.__init__(self, parent, ID, size=self.bg_bmp.GetSize())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
75
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
76 self.bind_events()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
77
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
78 def bind_events(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
79 # Set up mouse and keyboard event capture
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
80 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
81 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDown)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
82 self.Bind(wx.EVT_MOTION, self.OnMotion)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
83 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
84 self.Bind(wx.EVT_KEY_UP, self.OnKey)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
85 wx.GetTopLevelParent(self).Bind(wx.EVT_CHAR_HOOK, self.OnTopLevelKey)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
86
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
87 def disable(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
88 self.enabled = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
89 self.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
90
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
91 def enable(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
92 self.enabled = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
93 self.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
94
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
95 def repeatLast(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
96 if self.lastMove:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
97 self.moveCallback(*self.lastMove)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
98 if self.lastCorner:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
99 self.cornerCallback(self.corner_to_axis[self.lastCorner])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
100
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
101 def clearRepeat(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
102 self.lastMove = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
103 self.lastCorner = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
104
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
105 def distanceToLine(self, pos, x1, y1, x2, y2):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
106 xlen = x2 - x1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
107 ylen = y2 - y1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
108 pxlen = x1 - pos.x
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
109 pylen = y1 - pos.y
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
110 return abs(xlen * pylen - ylen * pxlen) / math.sqrt(xlen ** 2 + ylen ** 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
111
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
112 def distanceToPoint(self, x1, y1, x2, y2):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
113 return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
114
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
115 def cycleKeypadIndex(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
116 idx = self.keypad_idx + 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
117 if idx > 2: idx = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
118 return idx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
119
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
120 def setKeypadIndex(self, idx):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
121 self.keypad_idx = idx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
122 self.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
123
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
124 def getMovement(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
125 xdir = [1, 0, -1, 0, 0, 0][self.quadrant]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
126 ydir = [0, 1, 0, -1, 0, 0][self.quadrant]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
127 zdir = [0, 0, 0, 0, 1, -1][self.quadrant]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
128 magnitude = math.pow(10, self.concentric - 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
129 if not zdir == 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
130 magnitude = min(magnitude, 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
131 return (magnitude * xdir, magnitude * ydir, magnitude * zdir)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
132
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
133 def lookupConcentric(self, radius):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
134 idx = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
135 for r in self.concentric_circle_radii[1:]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
136 if radius < r:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
137 return idx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
138 idx += 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
139 return len(self.concentric_circle_radii)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
140
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
141 def getQuadrantConcentricFromPosition(self, pos):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
142 rel_x = pos[0] - self.center[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
143 rel_y = pos[1] - self.center[1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
144 radius = math.sqrt(rel_x ** 2 + rel_y ** 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
145 if rel_x > rel_y and rel_x > -rel_y:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
146 quadrant = 0 # Right
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
147 elif rel_x <= rel_y and rel_x > -rel_y:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
148 quadrant = 3 # Down
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
149 elif rel_x > rel_y and rel_x < -rel_y:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
150 quadrant = 1 # Up
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
151 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
152 quadrant = 2 # Left
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
153
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
154 idx = self.lookupConcentric(radius)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
155 return (quadrant, idx)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
156
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
157 def mouseOverKeypad(self, mpos):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
158 for idx, kpos in self.keypad_positions.items():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
159 radius = self.distanceToPoint(mpos[0], mpos[1], kpos[0], kpos[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
160 if radius < 9:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
161 return idx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
162 return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
163
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
164 def drawPartialPie(self, gc, center, r1, r2, angle1, angle2):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
165 p1 = wx.Point(center.x + r1 * math.cos(angle1), center.y + r1 * math.sin(angle1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
166
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
167 path = gc.CreatePath()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
168 path.MoveToPoint(p1.x, p1.y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
169 path.AddArc(center.x, center.y, r1, angle1, angle2, True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
170 path.AddArc(center.x, center.y, r2, angle2, angle1, False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
171 path.AddLineToPoint(p1.x, p1.y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
172 gc.DrawPath(path)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
173
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
174 def highlightQuadrant(self, gc, quadrant, concentric):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
175 assert(quadrant >= 0 and quadrant <= 3)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
176 assert(concentric >= 0 and concentric <= 4)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
177
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
178 inner_ring_radius = self.concentric_inset
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
179 # fudge = math.pi*0.002
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
180 fudge = -0.02
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
181 center = wx.Point(self.center[0], self.center[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
182 if quadrant == 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
183 a1, a2 = (-math.pi * 0.25, math.pi * 0.25)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
184 center.x += inner_ring_radius
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
185 elif quadrant == 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
186 a1, a2 = (math.pi * 1.25, math.pi * 1.75)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
187 center.y -= inner_ring_radius
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
188 elif quadrant == 2:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
189 a1, a2 = (math.pi * 0.75, math.pi * 1.25)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
190 center.x -= inner_ring_radius
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
191 elif quadrant == 3:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
192 a1, a2 = (math.pi * 0.25, math.pi * 0.75)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
193 center.y += inner_ring_radius
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
194
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
195 r1 = self.concentric_circle_radii[concentric]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
196 r2 = self.concentric_circle_radii[concentric + 1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
197
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
198 self.drawPartialPie(gc, center, r1 - inner_ring_radius, r2 - inner_ring_radius, a1 + fudge, a2 - fudge)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
199
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
200 def drawCorner(self, gc, x, y, angle = 0.0):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
201 w, h = self.corner_size
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
202
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
203 gc.PushState()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
204 gc.Translate(x, y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
205 gc.Rotate(angle)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
206 path = gc.CreatePath()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
207 path.MoveToPoint(-w / 2, -h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
208 path.AddLineToPoint(w / 2, -h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
209 path.AddLineToPoint(w / 2, -h / 2 + h / 4)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
210 path.AddLineToPoint(w / 12, h / 12)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
211 path.AddLineToPoint(-w / 2 + w / 4, h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
212 path.AddLineToPoint(-w / 2, h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
213 path.AddLineToPoint(-w / 2, -h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
214 gc.DrawPath(path)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
215 gc.PopState()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
216
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
217 def highlightCorner(self, gc, corner = 0):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
218 w, h = self.corner_size
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
219 xinset, yinset = self.corner_inset
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
220 cx, cy = self.center
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
221 ww, wh = self.GetSizeTuple()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
222
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
223 if corner == 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
224 x, y = (cx - ww / 2 + xinset + 1, cy - wh / 2 + yinset)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
225 self.drawCorner(gc, x + w / 2, y + h / 2, 0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
226 elif corner == 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
227 x, y = (cx + ww / 2 - xinset, cy - wh / 2 + yinset)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
228 self.drawCorner(gc, x - w / 2, y + h / 2, math.pi / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
229 elif corner == 2:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
230 x, y = (cx + ww / 2 - xinset, cy + wh / 2 - yinset - 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
231 self.drawCorner(gc, x - w / 2, y - h / 2, math.pi)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
232 elif corner == 3:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
233 x, y = (cx - ww / 2 + xinset + 1, cy + wh / 2 - yinset - 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
234 self.drawCorner(gc, x + w / 2, y - h / 2, math.pi * 3 / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
235
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
236 def drawCenteredDisc(self, gc, radius):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
237 cx, cy = self.center
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
238 gc.DrawEllipse(cx - radius, cy - radius, radius * 2, radius * 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
239
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
240 def draw(self, dc, w, h):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
241 dc.SetBackground(wx.Brush(self.bgcolor))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
242 dc.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
243 gc = wx.GraphicsContext.Create(dc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
244
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
245 if self.bg_bmp:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
246 w, h = (self.bg_bmp.GetWidth(), self.bg_bmp.GetHeight())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
247 gc.DrawBitmap(self.bg_bmp, 0, 0, w, h)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
248
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
249 if self.enabled and self.IsEnabled():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
250 # Brush and pen for grey overlay when mouse hovers over
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
251 gc.SetPen(wx.Pen(wx.Colour(100, 100, 100, 172), 4))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
252 gc.SetBrush(wx.Brush(wx.Colour(0, 0, 0, 128)))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
253
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
254 if self.concentric is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
255 if self.concentric < len(self.concentric_circle_radii):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
256 if self.concentric == 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
257 self.drawCenteredDisc(gc, self.concentric_circle_radii[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
258 elif self.quadrant is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
259 self.highlightQuadrant(gc, self.quadrant, self.concentric)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
260 elif self.corner is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
261 self.highlightCorner(gc, self.corner)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
262
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
263 if self.keypad_idx >= 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
264 padw, padh = (self.keypad_bmp.GetWidth(), self.keypad_bmp.GetHeight())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
265 pos = self.keypad_positions[self.keypad_idx]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
266 pos = (pos[0] - padw / 2 - 3, pos[1] - padh / 2 - 3)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
267 gc.DrawBitmap(self.keypad_bmp, pos[0], pos[1], padw, padh)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
268
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
269 # Draw label overlays
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
270 gc.SetPen(wx.Pen(wx.Colour(255, 255, 255, 128), 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
271 gc.SetBrush(wx.Brush(wx.Colour(255, 255, 255, 128 + 64)))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
272 for idx, kpos in self.label_overlay_positions.items():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
273 if idx != self.concentric:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
274 r = kpos[2]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
275 gc.DrawEllipse(kpos[0] - r, kpos[1] - r, r * 2, r * 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
276 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
277 gc.SetPen(wx.Pen(self.bgcolor, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
278 gc.SetBrush(wx.Brush(self.bgcolormask))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
279 gc.DrawRectangle(0, 0, w, h)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
280 # Used to check exact position of keypad dots, should we ever resize the bg image
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
281 # for idx, kpos in self.label_overlay_positions.items():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
282 # dc.DrawCircle(kpos[0], kpos[1], kpos[2])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
283
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
284 # ------ #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
285 # Events #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
286 # ------ #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
287 def OnTopLevelKey(self, evt):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
288 # Let user press escape on any control, and return focus here
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
289 if evt.GetKeyCode() == wx.WXK_ESCAPE:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
290 self.SetFocus()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
291 evt.Skip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
292
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
293 def OnKey(self, evt):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
294 if not self.enabled:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
295 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
296 if self.keypad_idx >= 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
297 if evt.GetKeyCode() == wx.WXK_TAB:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
298 self.setKeypadIndex(self.cycleKeypadIndex())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
299 elif evt.GetKeyCode() == wx.WXK_UP:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
300 self.quadrant = 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
301 elif evt.GetKeyCode() == wx.WXK_DOWN:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
302 self.quadrant = 3
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
303 elif evt.GetKeyCode() == wx.WXK_LEFT:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
304 self.quadrant = 2
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
305 elif evt.GetKeyCode() == wx.WXK_RIGHT:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
306 self.quadrant = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
307 elif evt.GetKeyCode() == wx.WXK_PAGEUP:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
308 self.quadrant = 4
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
309 elif evt.GetKeyCode() == wx.WXK_PAGEDOWN:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
310 self.quadrant = 5
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
311 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
312 evt.Skip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
313 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
314
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
315 self.concentric = self.keypad_idx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
316 x, y, z = self.getMovement()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
317
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
318 if x != 0 or y != 0 and self.moveCallback:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
319 self.moveCallback(x, y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
320 if z != 0 and self.zCallback:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
321 self.zCallback(z)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
322 elif evt.GetKeyCode() == wx.WXK_SPACE:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
323 self.spacebarCallback()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
324
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
325 def OnMotion(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
326 if not self.enabled:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
327 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
328
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
329 oldcorner = self.corner
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
330 oldq, oldc = self.quadrant, self.concentric
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
331
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
332 mpos = event.GetPosition()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
333 idx = self.mouseOverKeypad(mpos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
334 self.quadrant = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
335 self.concentric = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
336 if idx is None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
337 center = wx.Point(self.center[0], self.center[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
338 riseDist = self.distanceToLine(mpos, center.x - 1, center.y - 1, center.x + 1, center.y + 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
339 fallDist = self.distanceToLine(mpos, center.x - 1, center.y + 1, center.x + 1, center.y - 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
340 self.quadrant, self.concentric = self.getQuadrantConcentricFromPosition(mpos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
341
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
342 # If mouse hovers in space between quadrants, don't commit to a quadrant
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
343 if riseDist <= self.spacer or fallDist <= self.spacer:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
344 self.quadrant = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
345
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
346 cx, cy = self.center
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
347 if mpos.x < cx and mpos.y < cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
348 self.corner = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
349 if mpos.x >= cx and mpos.y < cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
350 self.corner = 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
351 if mpos.x >= cx and mpos.y >= cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
352 self.corner = 2
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
353 if mpos.x < cx and mpos.y >= cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
354 self.corner = 3
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
355
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
356 if oldq != self.quadrant or oldc != self.concentric or oldcorner != self.corner:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
357 self.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
358
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
359 def OnLeftDown(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
360 if not self.enabled:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
361 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
362
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
363 # Take focus when clicked so that arrow keys can control movement
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
364 self.SetFocus()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
365
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
366 mpos = event.GetPosition()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
367
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
368 idx = self.mouseOverKeypad(mpos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
369 if idx is None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
370 self.quadrant, self.concentric = self.getQuadrantConcentricFromPosition(mpos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
371 if self.concentric is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
372 if self.concentric < len(self.concentric_circle_radii):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
373 if self.concentric == 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
374 self.lastCorner = -1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
375 self.lastMove = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
376 self.cornerCallback(self.corner_to_axis[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
377 elif self.quadrant is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
378 x, y, z = self.getMovement()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
379 if self.moveCallback:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
380 self.lastMove = (x, y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
381 self.lastCorner = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
382 self.moveCallback(x, y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
383 elif self.corner is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
384 if self.cornerCallback:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
385 self.lastCorner = self.corner
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
386 self.lastMove = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
387 self.cornerCallback(self.corner_to_axis[self.corner])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
388 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
389 if self.keypad_idx == idx:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
390 self.setKeypadIndex(-1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
391 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
392 self.setKeypadIndex(idx)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
393
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
394 def OnLeaveWindow(self, evt):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
395 self.quadrant = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
396 self.concentric = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
397 self.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
398
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
399 class XYButtonsMini(XYButtons):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
400 imagename = "control_mini.png"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
401 center = (57, 56.5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
402 concentric_circle_radii = [0, 30.3]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
403 corner_inset = (5, 5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
404 corner_size = (50, 50)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
405 outer_radius = 31
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
406 corner_to_axis = {
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
407 0: "x",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
408 1: "z",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
409 2: "y",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
410 3: "center",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
411 }
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
412
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
413 def bind_events(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
414 # Set up mouse and keyboard event capture
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
415 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
416 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDown)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
417 self.Bind(wx.EVT_MOTION, self.OnMotion)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
418 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
419
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
420 def OnMotion(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
421 if not self.enabled:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
422 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
423
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
424 oldcorner = self.corner
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
425 oldq, oldc = self.quadrant, self.concentric
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
426
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
427 mpos = event.GetPosition()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
428
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
429 self.quadrant, self.concentric = self.getQuadrantConcentricFromPosition(mpos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
430
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
431 cx, cy = XYButtonsMini.center
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
432 if mpos.x < cx and mpos.y < cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
433 self.corner = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
434 if mpos.x >= cx and mpos.y < cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
435 self.corner = 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
436 if mpos.x >= cx and mpos.y >= cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
437 self.corner = 2
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
438 if mpos.x < cx and mpos.y >= cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
439 self.corner = 3
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
440
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
441 if oldq != self.quadrant or oldc != self.concentric or oldcorner != self.corner:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
442 self.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
443
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
444 def OnLeftDown(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
445 if not self.enabled:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
446 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
447
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
448 # Take focus when clicked so that arrow keys can control movement
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
449 self.SetFocus()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
450
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
451 mpos = event.GetPosition()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
452
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
453 self.quadrant, self.concentric = self.getQuadrantConcentricFromPosition(mpos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
454 if self.concentric is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
455 if self.concentric < len(self.concentric_circle_radii):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
456 self.cornerCallback("all")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
457 elif self.corner is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
458 if self.cornerCallback:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
459 self.lastCorner = self.corner
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
460 self.lastMove = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
461 self.cornerCallback(self.corner_to_axis[self.corner])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
462
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
463 def drawCorner(self, gc, x, y, angle = 0.0):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
464 w, h = self.corner_size
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
465
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
466 gc.PushState()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
467 gc.Translate(x, y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
468 gc.Rotate(angle)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
469 path = gc.CreatePath()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
470 path.MoveToPoint(-w / 2, -h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
471 path.AddLineToPoint(w / 2, -h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
472 path.AddLineToPoint(w / 2, -h / 2 + h / 4)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
473 path.AddArc(w / 2, h / 2, self.outer_radius, 3 * math.pi / 2, math.pi, False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
474 path.AddLineToPoint(-w / 2, h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
475 path.AddLineToPoint(-w / 2, -h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
476 gc.DrawPath(path)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
477 gc.PopState()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
478
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
479 def draw(self, dc, w, h):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
480 dc.SetBackground(wx.Brush(self.bgcolor))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
481 dc.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
482 gc = wx.GraphicsContext.Create(dc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
483
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
484 if self.bg_bmp:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
485 w, h = (self.bg_bmp.GetWidth(), self.bg_bmp.GetHeight())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
486 gc.DrawBitmap(self.bg_bmp, 0, 0, w, h)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
487
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
488 if self.enabled and self.IsEnabled():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
489 # Brush and pen for grey overlay when mouse hovers over
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
490 gc.SetPen(wx.Pen(wx.Colour(100, 100, 100, 172), 4))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
491 gc.SetBrush(wx.Brush(wx.Colour(0, 0, 0, 128)))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
492
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
493 if self.concentric is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
494 if self.concentric < len(self.concentric_circle_radii):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
495 self.drawCenteredDisc(gc, self.concentric_circle_radii[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
496 elif self.corner is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
497 self.highlightCorner(gc, self.corner)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
498 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
499 gc.SetPen(wx.Pen(self.bgcolor, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
500 gc.SetBrush(wx.Brush(self.bgcolormask))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
501 gc.DrawRectangle(0, 0, w, h)

mercurial