The keypad
module: a virtual keypad for controlling actuators¶
Tkinter
virtual keypad for motion devices.
This is part of the microscopy
package.
The devices must conform to the interface defined in hal.Actuator
.
Example: |
---|
To create a keypad for three axes X, Y and Z, controlled by PageUp/PageDown, Up/Down and Left/Right respectively:
>>> kp = keypad.Keypad(((z, ('Prior', 'Next')),
(x, ('Up', 'Down')),
(y, ('Left', 'Right'))),
title='XYZ')
Pressing a key will make the device move until the key is released. Pressing Shift+key at the same time will make an incremental step. Pressing Ctlr+key will increase or decrese the step size. Arbitrary numbers of axes are supported.
Warning
Key repeat for the control keys will be disabled while the widget has focus.
This requires that the module variable X_KEY_CODES
knows the correspondance
between Tkinter key names and the X server keycodes (see Tip below).
Tip
- http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/key-names.html for the Tkinter key names.
- http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/event-handlers.html for the how to handle key modifiers (shift, control etc.).
- Use the
xev
utility to figure out the X server key codes.
- Guillaume Lepert, November 2015
-
microscopy.keypad.
X_KEY_CODES
= {'Down': 116, 'Prior': 112, 'KP_2': 88, 'Right': 114, 'KP_4': 83, 'KP_6': 85, 'KP_8': 80, 'Next': 117, 'Up': 111, 'Left': 113}¶ X server key codes for enabling/disabling key repeats (as returned by xev)
-
microscopy.keypad.
KEY_MODS
= {'Control': 4, 'Alt_L': 8, 'Num_Lock': 16, 'Mouse_2': 512, 'Mouse_3': 1024, 'Shift': 1, 'Mouse_1': 256, 'Alt_R': 128, 'Caps_Lock': 2}¶ Tkinter key modifier masks (see http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/event-handlers.html)
-
class
microscopy.keypad.
Keypad
(axes, master=None, title='')[source]¶ Tkinter virtual keypad for motion devices.
Parameters: - axes – list of
hal.Actuator
objects. - master – a Tkinter object.
The keypad will be created as a
Tkinter.Toplevel
object. If no master is provided, a newTkinter.Tk
instance is started - title – the window title.
- axes – list of
-
class
microscopy.keypad.
KeypadAxis
(axis, keys, widget, line, tab=10, dir=1)[source]¶ Represent individual actuators within a
Keypad
instance.Parameters: - axis (
hal.Actuator
) – - keys – the two controlling keys (see http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/key-names.html for info about Tkinter key identifiers)
- widget – Tkinter widget where the axis should be attached.
(normally
Keypad.text
) - line (int) – in the text widget, number of the line where the axis position should be printed.
- tab (int) – number of characters reserved for printing the axis name
- dir (float) – The requested motion will be multiplied by this number. Most useful to swap the direction of motion if the actuator is set up in such a way that it goes up when it is expected to go down.
-
update_rate
= None¶ Position update rate, in seconds.
- axis (