printrun-src/printrun/gui/xybuttons.py

Wed, 20 Jan 2021 10:15:13 +0100

author
mdd
date
Wed, 20 Jan 2021 10:15:13 +0100
changeset 46
cce0af6351f0
parent 15
0bbb006204fc
permissions
-rw-r--r--

updated and added new files for printrun

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
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
26 DASHES = [4, 7]
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
27 # Brush and pen for grey overlay when mouse hovers over
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
28 HOVER_PEN_COLOR = wx.Colour(100, 100, 100, 172)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
29 HOVER_BRUSH_COLOR = wx.Colour(0, 0, 0, 128)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
30
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
31 class FocusCanvas(BufferedCanvas):
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
32 def __init__(self, *args, **kwds):
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
33 super().__init__(*args, **kwds)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
34 self.Bind(wx.EVT_SET_FOCUS, self.onFocus)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
35
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
36 def onFocus(self, evt):
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
37 self.Refresh()
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
38 evt.Skip()
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
39
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
40 def drawFocusRect(self, dc):
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
41 if self.HasFocus():
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
42 pen = wx.Pen(wx.BLACK, 1, wx.PENSTYLE_USER_DASH)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
43 pen.SetDashes(DASHES)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
44 dc.Pen = pen
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
45 dc.Brush = wx.Brush(wx.TRANSPARENT_BRUSH)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
46 dc.DrawRectangle(self.ClientRect)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
47
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
48 class XYButtons(FocusCanvas):
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
49 keypad_positions = {
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
50 0: (104, 99),
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
51 1: (86, 83),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
52 2: (68, 65),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
53 3: (53, 50)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
54 }
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
55 keypad_radius = 9
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
56 corner_size = (49, 49)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
57 corner_inset = (7, 13)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
58 label_overlay_positions = {
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
59 1: (145, 98.5, 9),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
60 2: (160.5, 83.5, 10.6),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
61 3: (178, 66, 13),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
62 4: (197.3, 46.3, 13.3)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
63 }
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
64 concentric_circle_radii = [0, 17, 45, 69, 94, 115]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
65 concentric_inset = 11
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
66 center = (124, 121)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
67 spacer = 7
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
68 imagename = "control_xy.png"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
69 corner_to_axis = {
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
70 -1: "center",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
71 0: "x",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
72 1: "z",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
73 2: "y",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
74 3: "all",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
75 }
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
76
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
77 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
78 self.bg_bmp = wx.Image(imagefile(self.imagename), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
79 self.keypad_bmp = wx.Image(imagefile("arrow_keys.png"), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
80 self.keypad_idx = -1
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
81 self.hovered_keypad = None
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
82 self.quadrant = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
83 self.concentric = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
84 self.corner = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
85 self.moveCallback = moveCallback
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
86 self.cornerCallback = cornerCallback
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
87 self.spacebarCallback = spacebarCallback
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
88 self.zCallback = zcallback
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
89 self.enabled = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
90 # Remember the last clicked buttons, so we can repeat when spacebar pressed
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
91 self.lastMove = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
92 self.lastCorner = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
93
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
94 self.bgcolor = wx.Colour()
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
95 self.bgcolor.Set(bgcolor)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
96 self.bgcolormask = wx.Colour(self.bgcolor.Red(), self.bgcolor.Green(), self.bgcolor.Blue(), 128)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
97
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
98 super().__init__(parent, ID, size=self.bg_bmp.GetSize())
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
99
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
100 self.bind_events()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
101
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
102 def bind_events(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
103 # Set up mouse and keyboard event capture
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
104 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
105 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDown)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
106 self.Bind(wx.EVT_MOTION, self.OnMotion)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
107 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
108 self.Bind(wx.EVT_CHAR_HOOK, self.OnKey)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
109 self.Bind(wx.EVT_KILL_FOCUS, self.onKillFocus)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
110
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
111 def onKillFocus(self, evt):
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
112 self.setKeypadIndex(-1)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
113 evt.Skip()
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
114
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
115 def disable(self):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
116 self.Enabled = self.enabled = False
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
117 self.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
118
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
119 def enable(self):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
120 self.Enabled = self.enabled = True
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
121 self.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
122
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
123 def repeatLast(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
124 if self.lastMove:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
125 self.moveCallback(*self.lastMove)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
126 if self.lastCorner:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
127 self.cornerCallback(self.corner_to_axis[self.lastCorner])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
128
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
129 def clearRepeat(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
130 self.lastMove = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
131 self.lastCorner = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
132
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
133 def distanceToLine(self, pos, x1, y1, x2, y2):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
134 xlen = x2 - x1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
135 ylen = y2 - y1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
136 pxlen = x1 - pos.x
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
137 pylen = y1 - pos.y
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
138 return abs(xlen * pylen - ylen * pxlen) / math.sqrt(xlen ** 2 + ylen ** 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
139
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
140 def distanceToPoint(self, x1, y1, x2, y2):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
141 return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
142
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
143 def cycleKeypadIndex(self, forward):
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
144 idx = self.keypad_idx + (1 if forward else -1)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
145 # do not really cycle to allow exiting of jog controls widget
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
146 return idx if idx < len(self.keypad_positions) else -1
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
147
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
148 def setKeypadIndex(self, idx):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
149 self.keypad_idx = idx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
150 self.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
151
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
152 def getMovement(self, event):
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
153 xdir = [1, 0, -1, 0, 0, 0][self.quadrant]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
154 ydir = [0, 1, 0, -1, 0, 0][self.quadrant]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
155 zdir = [0, 0, 0, 0, 1, -1][self.quadrant]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
156 magnitude = math.pow(10, self.concentric - 2)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
157 magnitude *= event.ShiftDown() and 2 or event.ControlDown() and 0.5 or 1
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
158
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
159 if zdir:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
160 magnitude = min(magnitude, 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
161 return (magnitude * xdir, magnitude * ydir, magnitude * zdir)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
162
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
163 def lookupConcentric(self, radius):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
164 idx = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
165 for r in self.concentric_circle_radii[1:]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
166 if radius < r:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
167 return idx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
168 idx += 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
169 return len(self.concentric_circle_radii)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
170
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
171 def getQuadrantConcentricFromPosition(self, pos):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
172 rel_x = pos[0] - self.center[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
173 rel_y = pos[1] - self.center[1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
174 if rel_x > rel_y and rel_x > -rel_y:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
175 quadrant = 0 # Right
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
176 elif rel_x <= rel_y and rel_x > -rel_y:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
177 quadrant = 3 # Down
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
178 elif rel_x > rel_y and rel_x < -rel_y:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
179 quadrant = 1 # Up
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
180 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
181 quadrant = 2 # Left
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
182
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
183 radius = math.sqrt(rel_x ** 2 + rel_y ** 2)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
184 idx = self.lookupConcentric(radius)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
185 return (quadrant, idx)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
186
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
187 def mouseOverKeypad(self, mpos):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
188 for idx, kpos in self.keypad_positions.items():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
189 radius = self.distanceToPoint(mpos[0], mpos[1], kpos[0], kpos[1])
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
190 if radius < XYButtons.keypad_radius:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
191 return idx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
192 return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
193
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
194 def drawPartialPie(self, gc, center, r1, r2, angle1, angle2):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
195 p1 = wx.Point(center.x + r1 * math.cos(angle1), center.y + r1 * math.sin(angle1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
196
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
197 path = gc.CreatePath()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
198 path.MoveToPoint(p1.x, p1.y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
199 path.AddArc(center.x, center.y, r1, angle1, angle2, True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
200 path.AddArc(center.x, center.y, r2, angle2, angle1, False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
201 path.AddLineToPoint(p1.x, p1.y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
202 gc.DrawPath(path)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
203
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
204 def highlightQuadrant(self, gc, quadrant, concentric):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
205 if not 0 <= quadrant <= 3:
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
206 return
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
207 assert(concentric >= 0 and concentric <= 4)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
208
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
209 inner_ring_radius = self.concentric_inset
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
210 # fudge = math.pi*0.002
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
211 fudge = -0.02
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
212 center = wx.Point(self.center[0], self.center[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
213 if quadrant == 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
214 a1, a2 = (-math.pi * 0.25, math.pi * 0.25)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
215 center.x += inner_ring_radius
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
216 elif quadrant == 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
217 a1, a2 = (math.pi * 1.25, math.pi * 1.75)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
218 center.y -= inner_ring_radius
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
219 elif quadrant == 2:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
220 a1, a2 = (math.pi * 0.75, math.pi * 1.25)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
221 center.x -= inner_ring_radius
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
222 elif quadrant == 3:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
223 a1, a2 = (math.pi * 0.25, math.pi * 0.75)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
224 center.y += inner_ring_radius
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
225
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
226 r1 = self.concentric_circle_radii[concentric]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
227 r2 = self.concentric_circle_radii[concentric + 1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
228
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
229 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
230
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
231 def drawCorner(self, gc, x, y, angle = 0.0):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
232 w, h = self.corner_size
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
233
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
234 gc.PushState()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
235 gc.Translate(x, y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
236 gc.Rotate(angle)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
237 path = gc.CreatePath()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
238 path.MoveToPoint(-w / 2, -h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
239 path.AddLineToPoint(w / 2, -h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
240 path.AddLineToPoint(w / 2, -h / 2 + h / 4)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
241 path.AddLineToPoint(w / 12, h / 12)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
242 path.AddLineToPoint(-w / 2 + w / 4, h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
243 path.AddLineToPoint(-w / 2, h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
244 path.AddLineToPoint(-w / 2, -h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
245 gc.DrawPath(path)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
246 gc.PopState()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
247
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
248 def highlightCorner(self, gc, corner = 0):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
249 w, h = self.corner_size
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
250 xinset, yinset = self.corner_inset
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
251 cx, cy = self.center
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
252 ww, wh = self.GetSize()
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
253
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
254 if corner == 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
255 x, y = (cx - ww / 2 + xinset + 1, cy - wh / 2 + yinset)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
256 self.drawCorner(gc, x + w / 2, y + h / 2, 0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
257 elif corner == 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
258 x, y = (cx + ww / 2 - xinset, cy - wh / 2 + yinset)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
259 self.drawCorner(gc, x - w / 2, y + h / 2, math.pi / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
260 elif corner == 2:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
261 x, y = (cx + ww / 2 - xinset, cy + wh / 2 - yinset - 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
262 self.drawCorner(gc, x - w / 2, y - h / 2, math.pi)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
263 elif corner == 3:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
264 x, y = (cx - ww / 2 + xinset + 1, cy + wh / 2 - yinset - 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
265 self.drawCorner(gc, x + w / 2, y - h / 2, math.pi * 3 / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
266
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
267 def drawCenteredDisc(self, gc, radius):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
268 cx, cy = self.center
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
269 gc.DrawEllipse(cx - radius, cy - radius, radius * 2, radius * 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
270
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
271 def draw(self, dc, w, h):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
272 dc.SetBackground(wx.Brush(self.bgcolor))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
273 dc.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
274 gc = wx.GraphicsContext.Create(dc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
275
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
276 if self.bg_bmp:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
277 w, h = (self.bg_bmp.GetWidth(), self.bg_bmp.GetHeight())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
278 gc.DrawBitmap(self.bg_bmp, 0, 0, w, h)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
279
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
280 if self.enabled and self.IsEnabled():
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
281 gc.SetPen(wx.Pen(HOVER_PEN_COLOR, 4))
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
282 gc.SetBrush(wx.Brush(HOVER_BRUSH_COLOR))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
283
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
284 if self.concentric is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
285 if self.concentric < len(self.concentric_circle_radii):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
286 if self.concentric == 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
287 self.drawCenteredDisc(gc, self.concentric_circle_radii[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
288 elif self.quadrant is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
289 self.highlightQuadrant(gc, self.quadrant, self.concentric)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
290 elif self.corner is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
291 self.highlightCorner(gc, self.corner)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
292
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
293 if self.keypad_idx >= 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
294 padw, padh = (self.keypad_bmp.GetWidth(), self.keypad_bmp.GetHeight())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
295 pos = self.keypad_positions[self.keypad_idx]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
296 pos = (pos[0] - padw / 2 - 3, pos[1] - padh / 2 - 3)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
297 gc.DrawBitmap(self.keypad_bmp, pos[0], pos[1], padw, padh)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
298
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
299 if self.hovered_keypad is not None and self.hovered_keypad != self.keypad_idx:
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
300 pos = self.keypad_positions[self.hovered_keypad]
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
301 r = XYButtons.keypad_radius
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
302 gc.DrawEllipse(pos[0]-r/2, pos[1]-r/2, r, r)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
303
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
304 # Draw label overlays
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
305 gc.SetPen(wx.Pen(wx.Colour(255, 255, 255, 128), 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
306 gc.SetBrush(wx.Brush(wx.Colour(255, 255, 255, 128 + 64)))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
307 for idx, kpos in self.label_overlay_positions.items():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
308 if idx != self.concentric:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
309 r = kpos[2]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
310 gc.DrawEllipse(kpos[0] - r, kpos[1] - r, r * 2, r * 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
311 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
312 gc.SetPen(wx.Pen(self.bgcolor, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
313 gc.SetBrush(wx.Brush(self.bgcolormask))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
314 gc.DrawRectangle(0, 0, w, h)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
315
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
316 self.drawFocusRect(dc)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
317
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
318 # Used to check exact position of keypad dots, should we ever resize the bg image
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
319 # for idx, kpos in self.label_overlay_positions.items():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
320 # dc.DrawCircle(kpos[0], kpos[1], kpos[2])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
321
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
322 # ------ #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
323 # Events #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
324 # ------ #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
325 def OnKey(self, evt):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
326 # print('XYButtons key', evt.GetKeyCode())
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
327 if not self.enabled:
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
328 evt.Skip()
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
329 return
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
330 key = evt.KeyCode
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
331 if self.keypad_idx >= 0:
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
332 if key == wx.WXK_TAB:
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
333 keypad = self.cycleKeypadIndex(not evt.ShiftDown())
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
334 self.setKeypadIndex(keypad)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
335 if keypad == -1:
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
336 # exit widget after largest step
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
337 # evt.Skip()
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
338 # On MS Windows if tab event is delivered,
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
339 # it is not handled
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
340 self.Navigate(not evt.ShiftDown())
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
341 return
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
342 elif key == wx.WXK_ESCAPE:
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
343 self.setKeypadIndex(-1)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
344 elif key == wx.WXK_UP:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
345 self.quadrant = 1
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
346 elif key == wx.WXK_DOWN:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
347 self.quadrant = 3
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
348 elif key == wx.WXK_LEFT:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
349 self.quadrant = 2
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
350 elif key == wx.WXK_RIGHT:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
351 self.quadrant = 0
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
352 elif key == wx.WXK_PAGEUP:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
353 self.quadrant = 4
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
354 elif key == wx.WXK_PAGEDOWN:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
355 self.quadrant = 5
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
356 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
357 evt.Skip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
358 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
359
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
360 self.concentric = self.keypad_idx + 1
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
361
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
362 if self.quadrant is not None:
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
363 x, y, z = self.getMovement(evt)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
364 if (x or y) and self.moveCallback:
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
365 self.moveCallback(x, y)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
366 if z and self.zCallback:
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
367 self.zCallback(z)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
368 self.Refresh()
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
369 elif key == wx.WXK_SPACE:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
370 self.spacebarCallback()
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
371 elif key == wx.WXK_TAB:
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
372 self.setKeypadIndex(len(self.keypad_positions)-1 if evt.ShiftDown() else 0)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
373 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
374 # handle arrows elsewhere
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
375 evt.Skip()
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
376
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
377 def OnMotion(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
378 if not self.enabled:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
379 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
380
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
381 oldcorner = self.corner
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
382 oldq, oldc = self.quadrant, self.concentric
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
383 old_hovered_keypad = self.hovered_keypad
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
384
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
385 mpos = event.GetPosition()
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
386 self.hovered_keypad = self.mouseOverKeypad(mpos)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
387 self.quadrant = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
388 self.concentric = None
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
389 if self.hovered_keypad is None:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
390 center = wx.Point(self.center[0], self.center[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
391 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
392 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
393 self.quadrant, self.concentric = self.getQuadrantConcentricFromPosition(mpos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
394
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
395 # If mouse hovers in space between quadrants, don't commit to a quadrant
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
396 if riseDist <= self.spacer or fallDist <= self.spacer:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
397 self.quadrant = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
398
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
399 cx, cy = self.center
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
400 if mpos.x < cx and mpos.y < cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
401 self.corner = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
402 if mpos.x >= cx and mpos.y < cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
403 self.corner = 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
404 if mpos.x >= cx and mpos.y >= cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
405 self.corner = 2
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
406 if mpos.x < cx and mpos.y >= cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
407 self.corner = 3
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
408
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
409 if oldq != self.quadrant or oldc != self.concentric or oldcorner != self.corner \
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
410 or old_hovered_keypad != self.hovered_keypad:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
411 self.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
412
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
413 def OnLeftDown(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
414 if not self.enabled:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
415 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
416
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
417 # Take focus when clicked so that arrow keys can control movement
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
418 self.SetFocus()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
419
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
420 mpos = event.GetPosition()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
421
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
422 idx = self.mouseOverKeypad(mpos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
423 if idx is None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
424 self.quadrant, self.concentric = self.getQuadrantConcentricFromPosition(mpos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
425 if self.concentric is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
426 if self.concentric < len(self.concentric_circle_radii):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
427 if self.concentric == 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
428 self.lastCorner = -1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
429 self.lastMove = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
430 self.cornerCallback(self.corner_to_axis[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
431 elif self.quadrant is not None:
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
432 x, y, z = self.getMovement(event)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
433 if self.moveCallback:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
434 self.lastMove = (x, y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
435 self.lastCorner = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
436 self.moveCallback(x, y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
437 elif self.corner is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
438 if self.cornerCallback:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
439 self.lastCorner = self.corner
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
440 self.lastMove = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
441 self.cornerCallback(self.corner_to_axis[self.corner])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
442 else:
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
443 self.setKeypadIndex(-1 if self.keypad_idx == idx else idx)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
444
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
445 def OnLeaveWindow(self, evt):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
446 self.quadrant = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
447 self.concentric = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
448 self.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
449
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
450 class XYButtonsMini(XYButtons):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
451 imagename = "control_mini.png"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
452 center = (57, 56.5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
453 concentric_circle_radii = [0, 30.3]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
454 corner_inset = (5, 5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
455 corner_size = (50, 50)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
456 outer_radius = 31
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
457 corner_to_axis = {
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
458 0: "x",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
459 1: "z",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
460 2: "y",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
461 3: "center",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
462 }
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
463
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
464 def bind_events(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
465 # Set up mouse and keyboard event capture
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
466 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
467 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDown)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
468 self.Bind(wx.EVT_MOTION, self.OnMotion)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
469 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
470
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
471 def OnMotion(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
472 if not self.enabled:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
473 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
474
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
475 oldcorner = self.corner
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
476 oldq, oldc = self.quadrant, self.concentric
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
477
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
478 mpos = event.GetPosition()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
479
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
480 self.quadrant, self.concentric = self.getQuadrantConcentricFromPosition(mpos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
481
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
482 cx, cy = XYButtonsMini.center
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
483 if mpos.x < cx and mpos.y < cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
484 self.corner = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
485 if mpos.x >= cx and mpos.y < cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
486 self.corner = 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
487 if mpos.x >= cx and mpos.y >= cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
488 self.corner = 2
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
489 if mpos.x < cx and mpos.y >= cy:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
490 self.corner = 3
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
491
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
492 if oldq != self.quadrant or oldc != self.concentric or oldcorner != self.corner:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
493 self.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
494
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
495 def OnLeftDown(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
496 if not self.enabled:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
497 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
498
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
499 # Take focus when clicked so that arrow keys can control movement
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
500 self.SetFocus()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
501
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
502 mpos = event.GetPosition()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
503
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
504 self.quadrant, self.concentric = self.getQuadrantConcentricFromPosition(mpos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
505 if self.concentric is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
506 if self.concentric < len(self.concentric_circle_radii):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
507 self.cornerCallback("all")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
508 elif self.corner is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
509 if self.cornerCallback:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
510 self.lastCorner = self.corner
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
511 self.lastMove = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
512 self.cornerCallback(self.corner_to_axis[self.corner])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
513
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
514 def drawCorner(self, gc, x, y, angle = 0.0):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
515 w, h = self.corner_size
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
516
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
517 gc.PushState()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
518 gc.Translate(x, y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
519 gc.Rotate(angle)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
520 path = gc.CreatePath()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
521 path.MoveToPoint(-w / 2, -h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
522 path.AddLineToPoint(w / 2, -h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
523 path.AddLineToPoint(w / 2, -h / 2 + h / 4)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
524 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
525 path.AddLineToPoint(-w / 2, h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
526 path.AddLineToPoint(-w / 2, -h / 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
527 gc.DrawPath(path)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
528 gc.PopState()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
529
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
530 def draw(self, dc, w, h):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
531 dc.SetBackground(wx.Brush(self.bgcolor))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
532 dc.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
533 gc = wx.GraphicsContext.Create(dc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
534
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
535 if self.bg_bmp:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
536 w, h = (self.bg_bmp.GetWidth(), self.bg_bmp.GetHeight())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
537 gc.DrawBitmap(self.bg_bmp, 0, 0, w, h)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
538
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
539 if self.enabled and self.IsEnabled():
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
540 gc.SetPen(wx.Pen(HOVER_PEN_COLOR, 4))
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
541 gc.SetBrush(wx.Brush(HOVER_BRUSH_COLOR))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
542
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
543 if self.concentric is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
544 if self.concentric < len(self.concentric_circle_radii):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
545 self.drawCenteredDisc(gc, self.concentric_circle_radii[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
546 elif self.corner is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
547 self.highlightCorner(gc, self.corner)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
548 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
549 gc.SetPen(wx.Pen(self.bgcolor, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
550 gc.SetBrush(wx.Brush(self.bgcolormask))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
551 gc.DrawRectangle(0, 0, w, h)

mercurial