Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 152 lines (124 sloc) 5.13 kB
34ede75 @alexrj Full GPLv3 notice
alexrj authored
1 # This file is part of the Printrun suite.
2 #
3 # Printrun is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # Printrun is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
15
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
16 import wx, os, math
17 from bufferedcanvas import *
18
19 def imagefile(filename):
8a4bdc9 @kliment Fix path handling when frozen (__file__ should be avoided in the futu…
authored
20 if os.path.exists(os.path.join(os.path.dirname(__file__), "images", filename)):
21 return os.path.join(os.path.dirname(__file__), "images", filename)
22 else:
23 return os.path.join(os.path.split(os.path.split(__file__)[0])[0], "images", filename)
24
25
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
26
27 def sign(n):
28 if n < 0: return -1
29 elif n > 0: return 1
30 else: return 0
31
32 class ZButtons(BufferedCanvas):
5940067 @chicagoduane Remove ability to click on Z +/- 100
chicagoduane authored
33 button_ydistances = [7, 30, 55, 83] # ,112
7c310d7 @chicagoduane Shrunk XY and Z controls. Added Home buttons. Added enable/disable.
chicagoduane authored
34 center = (30, 118)
b3658bf @chicagoduane Added visual indication to highlight XY and Z increment values on mou…
chicagoduane authored
35 label_overlay_positions = {
36 0: (1, 18, 11),
37 1: (1, 41, 13),
38 2: (1, 67, 15),
39 3: None
40 }
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
41
f4d18e4 @chicagoduane Fixed keypad toggle for XY controls. Defaults to off.
chicagoduane authored
42 def __init__(self, parent, moveCallback=None, ID=-1):
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
43 self.bg_bmp = wx.Image(imagefile("control_z.png"),wx.BITMAP_TYPE_PNG).ConvertToBitmap()
44 self.range = None
45 self.direction = None
46 self.orderOfMagnitudeIdx = 0 # 0 means '1', 1 means '10', 2 means '100', etc.
47 self.moveCallback = moveCallback
7c310d7 @chicagoduane Shrunk XY and Z controls. Added Home buttons. Added enable/disable.
chicagoduane authored
48 self.enabled = False
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
49
50 BufferedCanvas.__init__(self, parent, ID)
51
7c310d7 @chicagoduane Shrunk XY and Z controls. Added Home buttons. Added enable/disable.
chicagoduane authored
52 self.SetSize(wx.Size(59, 244))
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
53
54 # Set up mouse and keyboard event capture
55 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
56 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDown)
57 self.Bind(wx.EVT_MOTION, self.OnMotion)
261a09c @chicagoduane Fixed that the background was repainted as white instead of transparent
chicagoduane authored
58 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
59
7c310d7 @chicagoduane Shrunk XY and Z controls. Added Home buttons. Added enable/disable.
chicagoduane authored
60 def disable(self):
61 self.enabled = False
08d4abb @chicagoduane Fix that enable/disable does not immediately redraw. Fix that buttons…
chicagoduane authored
62 self.update()
7c310d7 @chicagoduane Shrunk XY and Z controls. Added Home buttons. Added enable/disable.
chicagoduane authored
63
64 def enable(self):
65 self.enabled = True
08d4abb @chicagoduane Fix that enable/disable does not immediately redraw. Fix that buttons…
chicagoduane authored
66 self.update()
7c310d7 @chicagoduane Shrunk XY and Z controls. Added Home buttons. Added enable/disable.
chicagoduane authored
67
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
68 def lookupRange(self, ydist):
69 idx = -1
70 for d in ZButtons.button_ydistances:
71 if ydist < d:
72 return idx
73 idx += 1
74 return None
75
50d340f @chicagoduane Fixed transparency issues in Windows by using a GraphicsContext. Chan…
chicagoduane authored
76 def highlight(self, gc, rng, dir):
37cdd32 @chicagoduane Added 4 orders of magnitude to Z Buttons; Refactored some of XY Buttons
chicagoduane authored
77 assert(rng >= -1 and rng <= 3)
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
78 assert(dir >= -1 and dir <= 1)
79
37cdd32 @chicagoduane Added 4 orders of magnitude to Z Buttons; Refactored some of XY Buttons
chicagoduane authored
80 fudge = 11
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
81 x = 0 + fudge
7c310d7 @chicagoduane Shrunk XY and Z controls. Added Home buttons. Added enable/disable.
chicagoduane authored
82 w = 59 - fudge*2
37cdd32 @chicagoduane Added 4 orders of magnitude to Z Buttons; Refactored some of XY Buttons
chicagoduane authored
83 if rng >= 0:
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
84 k = 1 if dir > 0 else 0
85 y = ZButtons.center[1] - (dir * ZButtons.button_ydistances[rng+k])
86 h = ZButtons.button_ydistances[rng+1] - ZButtons.button_ydistances[rng]
50d340f @chicagoduane Fixed transparency issues in Windows by using a GraphicsContext. Chan…
chicagoduane authored
87 gc.DrawRoundedRectangle(x, y, w, h, 4)
88 # gc.DrawRectangle(x, y, w, h)
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
89 # self.drawPartialPie(dc, center, r1-inner_ring_radius, r2-inner_ring_radius, a1+fudge, a2-fudge)
90
91 def getRangeDir(self, pos):
92 ydelta = ZButtons.center[1] - pos[1]
93 return (self.lookupRange(abs(ydelta)), sign(ydelta))
94
7c310d7 @chicagoduane Shrunk XY and Z controls. Added Home buttons. Added enable/disable.
chicagoduane authored
95 def draw(self, dc, w, h):
96 dc.Clear()
97 gc = wx.GraphicsContext.Create(dc)
0afcc88 @kliment Integrate plating into pronterface UI
authored
98 if self.bg_bmp:
99 w, h = (self.bg_bmp.GetWidth(), self.bg_bmp.GetHeight())
100 gc.DrawBitmap(self.bg_bmp, 0, 0, w, h)
7c310d7 @chicagoduane Shrunk XY and Z controls. Added Home buttons. Added enable/disable.
chicagoduane authored
101
102 if self.enabled:
b3658bf @chicagoduane Added visual indication to highlight XY and Z increment values on mou…
chicagoduane authored
103 # Draw label overlays
104 gc.SetPen(wx.Pen(wx.Colour(255,255,255,128), 1))
105 gc.SetBrush(wx.Brush(wx.Colour(255,255,255,128+64)))
106 for idx, kpos in ZButtons.label_overlay_positions.items():
107 if kpos and idx != self.range:
108 r = kpos[2]
109 gc.DrawEllipse(ZButtons.center[0]-kpos[0]-r, ZButtons.center[1]-kpos[1]-r, r*2, r*2)
110
111 # Top 'layer' is the mouse-over highlights
7c310d7 @chicagoduane Shrunk XY and Z controls. Added Home buttons. Added enable/disable.
chicagoduane authored
112 gc.SetPen(wx.Pen(wx.Colour(100,100,100,172), 4))
113 gc.SetBrush(wx.Brush(wx.Colour(0,0,0,128)))
114 if self.range != None and self.direction != None:
115 self.highlight(gc, self.range, self.direction)
116 else:
117 gc.SetPen(wx.Pen(wx.Colour(255,255,255,0), 4))
118 gc.SetBrush(wx.Brush(wx.Colour(255,255,255,128)))
119 gc.DrawRectangle(0, 0, w, h)
120
121 ## ------ ##
122 ## Events ##
123 ## ------ ##
124
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
125 def OnMotion(self, event):
7c310d7 @chicagoduane Shrunk XY and Z controls. Added Home buttons. Added enable/disable.
chicagoduane authored
126 if not self.enabled:
127 return
128
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
129 oldr, oldd = self.range, self.direction
130
131 mpos = event.GetPosition()
132 self.range, self.direction = self.getRangeDir(mpos)
133
134 if oldr != self.range or oldd != self.direction:
135 self.update()
136
137 def OnLeftDown(self, event):
7c310d7 @chicagoduane Shrunk XY and Z controls. Added Home buttons. Added enable/disable.
chicagoduane authored
138 if not self.enabled:
139 return
140
8986a90 @chicagoduane Separate XY and Z control panels into classes.
chicagoduane authored
141 mpos = event.GetPosition()
142 r, d = self.getRangeDir(mpos)
143 if r >= 0:
144 value = math.pow(10, self.orderOfMagnitudeIdx) * math.pow(10, r - 1) * d
145 if self.moveCallback:
146 self.moveCallback(value)
147
261a09c @chicagoduane Fixed that the background was repainted as white instead of transparent
chicagoduane authored
148 def OnLeaveWindow(self, evt):
149 self.range = None
150 self.direction = None
151 self.update()
Something went wrong with that request. Please try again.