printrun-src/printrun/gui/zbuttons.py

changeset 46
cce0af6351f0
parent 15
0bbb006204fc
equal deleted inserted replaced
45:c82943fb205f 46:cce0af6351f0
12 # 12 #
13 # You should have received a copy of the GNU General Public License 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/>. 14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
15 15
16 import wx 16 import wx
17 from .bufferedcanvas import BufferedCanvas 17 from printrun.gui.xybuttons import FocusCanvas
18 from printrun.utils import imagefile 18 from printrun.utils import imagefile
19 19
20 def sign(n): 20 def sign(n):
21 if n < 0: return -1 21 if n < 0: return -1
22 elif n > 0: return 1 22 elif n > 0: return 1
23 else: return 0 23 else: return 0
24 24
25 class ZButtons(BufferedCanvas): 25 class ZButtons(FocusCanvas):
26 button_ydistances = [7, 30, 55, 83] # ,112 26 button_ydistances = [7, 30, 55, 83] # ,112
27 move_values = [0.1, 1, 10] 27 move_values = [0.1, 1, 10]
28 center = (30, 118) 28 center = (30, 118)
29 label_overlay_positions = { 29 label_overlay_positions = {
30 0: (1.1, 18, 9), 30 0: (1.1, 18, 9),
42 self.enabled = False 42 self.enabled = False
43 # Remember the last clicked value, so we can repeat when spacebar pressed 43 # Remember the last clicked value, so we can repeat when spacebar pressed
44 self.lastValue = None 44 self.lastValue = None
45 45
46 self.bgcolor = wx.Colour() 46 self.bgcolor = wx.Colour()
47 self.bgcolor.SetFromName(bgcolor) 47 self.bgcolor.Set(bgcolor)
48 self.bgcolormask = wx.Colour(self.bgcolor.Red(), self.bgcolor.Green(), self.bgcolor.Blue(), 128) 48 self.bgcolormask = wx.Colour(self.bgcolor.Red(), self.bgcolor.Green(), self.bgcolor.Blue(), 128)
49 49
50 BufferedCanvas.__init__(self, parent, ID, size=self.bg_bmp.GetSize()) 50 # On MS Windows super(style=WANTS_CHARS) prevents tab cycling
51 # pass empty style explicitly
52 super().__init__(parent, ID, size=self.bg_bmp.GetSize(), style=0)
51 53
52 # Set up mouse and keyboard event capture 54 # Set up mouse and keyboard event capture
53 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) 55 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
54 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDown) 56 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDown)
55 self.Bind(wx.EVT_MOTION, self.OnMotion) 57 self.Bind(wx.EVT_MOTION, self.OnMotion)
56 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow) 58 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
59 self.Bind(wx.EVT_SET_FOCUS, self.RefreshFocus)
60 self.Bind(wx.EVT_KILL_FOCUS, self.RefreshFocus)
61
62 def RefreshFocus(self, evt):
63 self.Refresh()
64 evt.Skip()
57 65
58 def disable(self): 66 def disable(self):
67 self.Enabled = False # prevents focus
59 self.enabled = False 68 self.enabled = False
60 self.update() 69 self.update()
61 70
62 def enable(self): 71 def enable(self):
72 self.Enabled = True
63 self.enabled = True 73 self.enabled = True
64 self.update() 74 self.update()
65 75
66 def repeatLast(self): 76 def repeatLast(self):
67 if self.lastValue: 77 if self.lastValue:
121 self.highlight(gc, self.range, self.direction) 131 self.highlight(gc, self.range, self.direction)
122 else: 132 else:
123 gc.SetPen(wx.Pen(self.bgcolor, 0)) 133 gc.SetPen(wx.Pen(self.bgcolor, 0))
124 gc.SetBrush(wx.Brush(self.bgcolormask)) 134 gc.SetBrush(wx.Brush(self.bgcolormask))
125 gc.DrawRectangle(0, 0, w, h) 135 gc.DrawRectangle(0, 0, w, h)
136 self.drawFocusRect(dc)
126 137
127 # ------ # 138 # ------ #
128 # Events # 139 # Events #
129 # ------ # 140 # ------ #
130 141
144 if not self.enabled: 155 if not self.enabled:
145 return 156 return
146 157
147 mpos = event.GetPosition() 158 mpos = event.GetPosition()
148 r, d = self.getRangeDir(mpos) 159 r, d = self.getRangeDir(mpos)
149 if r >= 0: 160 if r is not None and r >= 0:
150 value = d * self.move_values[r] 161 value = d * self.move_values[r]
151 if self.moveCallback: 162 if self.moveCallback:
152 self.lastValue = value 163 self.lastValue = value
153 self.moveCallback(value) 164 self.moveCallback(value)
154 165

mercurial