summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2018-08-26 14:32:34 -0400
committerLex Neva <github.com@lexneva.name>2018-08-26 14:32:34 -0400
commit8351cf21a09168ae1faa3be916b1b418d3d388e8 (patch)
treeed712d23100b437681f575d839f23d9538338a42
parent0bc2992686339fcdd8b71018f43fecb3c9111349 (diff)
add keyboard shortcut support
-rw-r--r--lib/simulator.py107
-rw-r--r--messages.po40
2 files changed, 97 insertions, 50 deletions
diff --git a/lib/simulator.py b/lib/simulator.py
index 070213c5..b9e8692b 100644
--- a/lib/simulator.py
+++ b/lib/simulator.py
@@ -21,17 +21,17 @@ class ControlPanel(wx.Panel):
# Widgets
self.btnMinus = wx.Button(self, -1, label='-')
- self.btnMinus.Bind(wx.EVT_BUTTON, self.OnSpeedMinus)
+ self.btnMinus.Bind(wx.EVT_BUTTON, self.animation_slow_down)
self.btnPlus = wx.Button(self, -1, label='+')
- self.btnPlus.Bind(wx.EVT_BUTTON, self.OnSpeedPlus)
+ self.btnPlus.Bind(wx.EVT_BUTTON, self.animation_speed_up)
self.direction = wx.Button(self, -1, label='>>')
- self.direction.Bind(wx.EVT_BUTTON, self.OnDirection)
+ self.direction.Bind(wx.EVT_BUTTON, self.on_direction_button)
self.pauseBtn = wx.Button(self, -1, label='Pause')
- self.pauseBtn.Bind(wx.EVT_BUTTON, self.OnPauseStart)
+ self.pauseBtn.Bind(wx.EVT_BUTTON, self.on_pause_start_button)
self.restartBtn = wx.Button(self, -1, label='Restart')
- self.restartBtn.Bind(wx.EVT_BUTTON, self.on_restart)
+ self.restartBtn.Bind(wx.EVT_BUTTON, self.animation_restart)
self.quitBtn = wx.Button(self, -1, label='Quit')
- self.quitBtn.Bind(wx.EVT_BUTTON, self.on_quit)
+ self.quitBtn.Bind(wx.EVT_BUTTON, self.animation_quit)
self.slider = wx.Slider(self, -1, value=1, minValue=1, maxValue=self.num_stitches,
style=wx.SL_HORIZONTAL | wx.SL_LABELS)
self.slider.Bind(wx.EVT_SLIDER, self.on_slider)
@@ -57,23 +57,60 @@ class ControlPanel(wx.Panel):
vbSizer.Add(hbSizer2, 0, wx.EXPAND | wx.ALL, 3)
self.SetSizer(vbSizer)
+ # Keyboard Shortcuts
+ shortcut_keys = [
+ (wx.ACCEL_NORMAL, wx.WXK_RIGHT, self.animation_forward),
+ (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_RIGHT, self.animation_forward),
+ (wx.ACCEL_NORMAL, wx.WXK_LEFT, self.animation_reverse),
+ (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_LEFT, self.animation_reverse),
+ (wx.ACCEL_NORMAL, wx.WXK_UP, self.animation_speed_up),
+ (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_UP, self.animation_speed_up),
+ (wx.ACCEL_NORMAL, wx.WXK_DOWN, self.animation_slow_down),
+ (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_DOWN, self.animation_slow_down),
+ (wx.ACCEL_NORMAL, ord('+'), self.animation_one_frame_forward),
+ (wx.ACCEL_NORMAL, ord('='), self.animation_one_frame_forward),
+ (wx.ACCEL_SHIFT, ord('='), self.animation_one_frame_forward),
+ (wx.ACCEL_NORMAL, wx.WXK_ADD, self.animation_one_frame_forward),
+ (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_ADD, self.animation_one_frame_forward),
+ (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_UP, self.animation_one_frame_forward),
+ (wx.ACCEL_NORMAL, ord('-'), self.animation_one_frame_backward),
+ (wx.ACCEL_NORMAL, ord('_'), self.animation_one_frame_backward),
+ (wx.ACCEL_NORMAL, wx.WXK_SUBTRACT, self.animation_one_frame_backward),
+ (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_SUBTRACT, self.animation_one_frame_backward),
+ (wx.ACCEL_NORMAL, ord('r'), self.animation_restart),
+ (wx.ACCEL_NORMAL, ord('p'), self.on_pause_start_button),
+ (wx.ACCEL_NORMAL, wx.WXK_SPACE, self.on_pause_start_button),
+ (wx.ACCEL_NORMAL, ord('q'), self.animation_quit)]
+
+ accel_entries = []
+
+ for shortcut_key in shortcut_keys:
+ eventId = wx.NewId()
+ accel_entries.append((shortcut_key[0], shortcut_key[1], eventId))
+ self.Bind(wx.EVT_MENU, shortcut_key[2], id=eventId)
+
+ accel_table = wx.AcceleratorTable(accel_entries)
+ self.SetAcceleratorTable(accel_table)
+
self.set_speed(16)
- def OnDirection(self, event):
- """
- Handles the ``wx.EVT_BUTTON`` event.
+ self.SetFocus()
- :param `event`: A `wx.CommandEvent` to be processed.
- :type `event`: `wx.CommandEvent`
- """
+ def animation_forward(self, event=None):
+ self.direction.SetLabel(">>")
+ self.drawing_panel.forward()
+
+ def animation_reverse(self, event=None):
+ self.direction.SetLabel("<<")
+ self.drawing_panel.reverse()
+
+ def on_direction_button(self, event):
evtObj = event.GetEventObject()
lbl = evtObj.GetLabel()
if lbl == '>>':
- evtObj.SetLabel('<<')
- self.drawing_panel.reverse()
+ self.animation_reverse()
else:
- evtObj.SetLabel('>>')
- self.drawing_panel.forward()
+ self.animation_forward()
def set_speed(self, speed):
self.speed = int(max(speed, 1))
@@ -86,7 +123,7 @@ class ControlPanel(wx.Panel):
self.stitchBox.SetValue(stitch)
self.drawing_panel.set_current_stitch(stitch)
- def set_current_stitch(self, stitch):
+ def on_current_stitch(self, stitch):
self.slider.SetValue(stitch)
self.stitchBox.SetValue(stitch)
@@ -98,29 +135,39 @@ class ControlPanel(wx.Panel):
self.slider.SetValue(stitch)
self.drawing_panel.set_current_stitch(stitch)
- def OnSpeedMinus(self, event):
+ def animation_slow_down(self, event):
""""""
self.set_speed(self.speed / 2.0)
- def OnSpeedPlus(self, event):
+ def animation_speed_up(self, event):
""""""
self.set_speed(self.speed * 2.0)
- def OnPauseStart(self, event):
+ def animation_pause(self, event=None):
+ self.drawing_panel.stop()
+ self.pauseBtn.SetLabel('Start')
+
+ def animation_start(self, event=None):
+ self.drawing_panel.go()
+ self.pauseBtn.SetLabel('Pause')
+
+ def on_pause_start_button(self, event):
""""""
- evtObj = event.GetEventObject()
- lbl = evtObj.GetLabel()
- if lbl == 'Pause':
- self.drawing_panel.stop()
- evtObj.SetLabel('Start')
+ if self.pauseBtn.GetLabel() == 'Pause':
+ self.animation_pause()
else:
- self.drawing_panel.go()
- evtObj.SetLabel('Pause')
+ self.animation_start()
- def on_quit(self, event):
+ def animation_one_frame_forward(self, event):
+ pass
+
+ def animation_one_frame_backward(self, event):
+ pass
+
+ def animation_quit(self, event):
self.parent.quit()
- def on_restart(self, event):
+ def animation_restart(self, event):
self.drawing_panel.restart()
class DrawingPanel(wx.Panel):
@@ -204,7 +251,7 @@ class DrawingPanel(wx.Panel):
self.stop_if_at_end()
if self.control_panel:
- self.control_panel.set_current_stitch(self.current_stitch)
+ self.control_panel.on_current_stitch(self.current_stitch)
self.Refresh()
diff --git a/messages.po b/messages.po
index 1c5be39a..0a431bd1 100644
--- a/messages.po
+++ b/messages.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
-"POT-Creation-Date: 2018-08-25 22:48-0400\n"
+"POT-Creation-Date: 2018-08-26 14:32-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -674,79 +674,79 @@ msgstr ""
msgid "Generate INX files"
msgstr ""
-#: lib/simulator.py:413
+#: lib/simulator.py:460
msgid "<<"
msgstr ""
-#: lib/simulator.py:413
+#: lib/simulator.py:460
msgid "Play reverse (arrow left)"
msgstr ""
-#: lib/simulator.py:414
+#: lib/simulator.py:461
msgid "-"
msgstr ""
-#: lib/simulator.py:414
+#: lib/simulator.py:461
msgid "Play one frame backward (+)"
msgstr ""
-#: lib/simulator.py:415
+#: lib/simulator.py:462
msgid "+"
msgstr ""
-#: lib/simulator.py:415
+#: lib/simulator.py:462
msgid "Play one frame forward (+)"
msgstr ""
-#: lib/simulator.py:416
+#: lib/simulator.py:463
msgid ">>"
msgstr ""
-#: lib/simulator.py:416
+#: lib/simulator.py:463
msgid "Play forward (arrow right)"
msgstr ""
-#: lib/simulator.py:417
+#: lib/simulator.py:464
msgid "^"
msgstr ""
-#: lib/simulator.py:417
+#: lib/simulator.py:464
msgid "Speed up (arrow up)"
msgstr ""
-#: lib/simulator.py:418
+#: lib/simulator.py:465
msgid "v"
msgstr ""
-#: lib/simulator.py:418
+#: lib/simulator.py:465
msgid "Slow down (arrow down)"
msgstr ""
-#: lib/simulator.py:419
+#: lib/simulator.py:466
msgid "Pause"
msgstr ""
-#: lib/simulator.py:419
+#: lib/simulator.py:466
msgid "Pause (P)"
msgstr ""
-#: lib/simulator.py:420
+#: lib/simulator.py:467
msgid "Restart"
msgstr ""
-#: lib/simulator.py:420
+#: lib/simulator.py:467
msgid "Restart (R)"
msgstr ""
-#: lib/simulator.py:421
+#: lib/simulator.py:468
msgid "Quit"
msgstr ""
-#: lib/simulator.py:421
+#: lib/simulator.py:468
msgid "Close (Q)"
msgstr ""
-#: lib/simulator.py:599
+#: lib/simulator.py:646
msgid "Stitch # "
msgstr ""