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

  1. 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 new Tkinter.Tk instance is started
  • title – the window title.
disable_key_repeat(event)[source]

Disable key repeats for all actuator control keys.

enable_key_repeat(event)[source]

Enable key repeats for all actuator control keys.

read_only(event)[source]

Emulates a read-only text widget by immediately deleting all input characters.

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.

enable_key_repeat()[source]

Enable key repeats for the control keys.

disable_key_repeat()[source]

Disable key repeats for the control keys.

print_pos()[source]

Print the current position on text widget.

print_step()[source]

Print current step size on text widget.

update_pos()[source]

Update the axis position at regular interval.

move_up(event)[source]

Returns a event binding function that moves towards the positive direction.

move_down(event)[source]

Returns a event binding function that moves towards the negative direction.

stop(event)[source]

Returns a event binding function that stops motion on the specified axis.