Skip to content

Commit

Permalink
MS Windows Fix: toolbar shortcuts, blank jog, jog tab-out
Browse files Browse the repository at this point in the history
Connect, Print, Pause shortcuts worked only when toolbar is focused
'P' shortcut is specially coded to invoke either Print or Pause even
when Pause is labeled Resume.
Fix blank Jog control when focused
Fix: TAB cycles inside Jog without exit to next control
  • Loading branch information
volconst committed Aug 27, 2020
1 parent 00a932e commit 1f0290b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
3 changes: 2 additions & 1 deletion printrun/gui/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def MainToolbar(root, parentpanel = None, use_wrapsizer = False):
self.Add(root.baud)

if not hasattr(root, "connectbtn"):
root.connectbtn = make_autosize_button(parentpanel, _("Connect"), root.connect, _("Connect to the printer"))
root.connectbtn_cb_var = root.connect
root.connectbtn = make_autosize_button(parentpanel, _("&Connect"), root.connectbtn_cb, _("Connect to the printer"))
root.statefulControls.append(root.connectbtn)
else:
root.connectbtn.Reparent(parentpanel)
Expand Down
10 changes: 7 additions & 3 deletions printrun/gui/xybuttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def drawFocusRect(self, dc):
pen = wx.Pen(wx.BLACK, 1, wx.PENSTYLE_USER_DASH)
pen.SetDashes(DASHES)
dc.Pen = pen
dc.Brush = wx.NullBrush
dc.Brush = wx.Brush(wx.TRANSPARENT_BRUSH)
dc.DrawRectangle(self.ClientRect)

class XYButtons(FocusCanvas):
Expand Down Expand Up @@ -333,8 +333,12 @@ def OnKey(self, evt):
keypad = self.cycleKeypadIndex(not evt.ShiftDown())
self.setKeypadIndex(keypad)
if keypad == -1:
# exit widget after largest step
evt.Skip()
# exit widget after largest step
# evt.Skip()
# On MS Windows if tab event is delivered,
# it is not handled
self.Navigate(not evt.ShiftDown())
return
elif key == wx.WXK_ESCAPE:
self.setKeypadIndex(-1)
elif key == wx.WXK_UP:
Expand Down
4 changes: 3 additions & 1 deletion printrun/gui/zbuttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def __init__(self, parent, moveCallback = None, bgcolor = "#FFFFFF", ID=-1):
self.bgcolor.Set(bgcolor)
self.bgcolormask = wx.Colour(self.bgcolor.Red(), self.bgcolor.Green(), self.bgcolor.Blue(), 128)

super().__init__(parent, ID, size=self.bg_bmp.GetSize())
# On MS Windows super(style=WANTS_CHARS) prevents tab cycling
# pass empty style explicitly
super().__init__(parent, ID, size=self.bg_bmp.GetSize(), style=0)

# Set up mouse and keyboard event capture
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
Expand Down
42 changes: 35 additions & 7 deletions printrun/pronterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,27 @@ def on_key(self, event):
#ignore Alt+(S, H), so it can open Settings, Help menu
if widget and (ch not in 'SH' or not event.AltDown()):
widget.SetFocus()
return
# On MSWindows button mnemonics are processed only if the
# focus is in the parent panel
if event.AltDown() and ch < 'Z':
in_toolbar = self.toolbarsizer.GetItem(event.EventObject)
candidates = (self.connectbtn, self.connectbtn_cb_var), \
(self.pausebtn, self.pause), \
(self.printbtn, self.printfile)
for ctl, cb in candidates:
match = ('&' + ch) in ctl.Label.upper()
handled = in_toolbar and match
if handled:
break
# react to 'P' even for 'Restrart', 'Resume'
# print('match', match, 'handled', handled, ctl.Label, ctl.Enabled)
if (match or ch == 'P' and ctl != self.connectbtn) and ctl.Enabled:
# print('call', ch, cb)
cb()
# react to only 1 of 'P' buttons, prefer Resume
return

event.Skip()

def closewin(self, e):
Expand Down Expand Up @@ -1142,6 +1163,12 @@ def lock(self, event = None, force = None):
# Printer connection handling
# --------------------------------------------------------------

def connectbtn_cb(self, event):
# Implement toggle behavior with a single Bind
# and switched variable, so we have reference to
# the actual callback to use in on_key
self.connectbtn_cb_var()

def connect(self, event = None):
self.log(_("Connecting..."))
port = None
Expand Down Expand Up @@ -1190,11 +1217,12 @@ def disconnect(self, event = None):
self.status_thread.join()
self.status_thread = None

wx.CallAfter(self.connectbtn.SetLabel, _("&Connect"))
wx.CallAfter(self.connectbtn.SetToolTip, wx.ToolTip(_("Connect to the printer")))
wx.CallAfter(self.connectbtn.Bind, wx.EVT_BUTTON, self.connect)

wx.CallAfter(self.gui_set_disconnected)
def toggle():
self.connectbtn.SetLabel(_("&Connect"))
self.connectbtn.SetToolTip(wx.ToolTip(_("Connect to the printer")))
self.connectbtn_cb_var = self.connect
self.gui_set_disconnected()
wx.CallAfter(toggle)

if self.paused:
self.p.paused = 0
Expand Down Expand Up @@ -1234,7 +1262,7 @@ def on_startprint(self):
wx.CallAfter(self.printbtn.SetLabel, _("Restart"))
wx.CallAfter(self.toolbarsizer.Layout)

def printfile(self, event):
def printfile(self, event=None):
self.extra_print_time = 0
if self.paused:
self.p.paused = 0
Expand Down Expand Up @@ -1700,7 +1728,7 @@ def online_gui(self):
"""Callback when printer goes online (graphical bits)"""
self.connectbtn.SetLabel(_("Dis&connect"))
self.connectbtn.SetToolTip(wx.ToolTip("Disconnect from the printer"))
self.connectbtn.Bind(wx.EVT_BUTTON, self.disconnect)
self.connectbtn_cb_var = self.disconnect

if hasattr(self, "extrudersel"):
self.do_tool(self.extrudersel.GetValue())
Expand Down

0 comments on commit 1f0290b

Please sign in to comment.