Changeset 52:50bbffd99071 in xplra for src/client/python


Ignore:
Timestamp:
02/16/13 13:44:12 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Implemented the Python client for hotkey support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/client/python/xplra.py

    r40 r52  
    3434COMMAND_SHOW_MESSAGE = 0x41
    3535
     36COMMAND_REGISTER_HOTKEYS = 0x51
     37
     38COMMAND_QUERY_HOTKEYS = 0x52
     39
     40COMMAND_UNREGISTER_HOTKEYS = 0x53
     41
    3642TYPE_INT = 0x01
    3743
     
    6571
    6672RESULT_OTHER_ERROR = 0xff
     73
     74HOTKEY_MODIFIER_SHIFT = 0x0100
     75
     76HOTKEY_MODIFIER_CONTROL = 0x0200
    6777
    6878#-------------------------------------------------------------------------------
     
    239249        self._writeString(message)
    240250        self._writeFloat(duration)
     251        self._flush()
     252        self._checkResult()
     253
     254    def registerHotkeys(self, hotkeyCodes):
     255        """Register the given hotkey codes for watching."""
     256        self._writeU8(COMMAND_REGISTER_HOTKEYS)
     257        self._writeU32(len(hotkeyCodes))
     258        for hotkeyCode in hotkeyCodes:
     259            self._writeU16(hotkeyCode)
     260        self._flush()
     261        self._checkResult()
     262
     263    def queryHotkeys(self):
     264        """Query the state of the hotkeys registered previously"""
     265        self._writeU8(COMMAND_QUERY_HOTKEYS)
     266        self._flush()
     267        self._checkResult()
     268
     269        length = self._readU32()
     270        states = []
     271        for i in range(0, length):
     272            states.append(self._readU8())
     273
     274        return states
     275
     276    def unregisterHotkeys(self):
     277        """Unregister the previously registered hotkeys."""
     278        self._writeU8(COMMAND_UNREGISTER_HOTKEYS)
    241279        self._flush()
    242280        self._checkResult()
     
    334372        """Write the given value as an unsigned, 8-bit value."""
    335373        self._stream.write(struct.pack("B", x))
     374
     375    def _writeU16(self, x):
     376        """Write the given value as an unsigned, 16-bit value."""
     377        self._stream.write(struct.pack("H", x))
    336378
    337379    def _writeS32(self, x):
Note: See TracChangeset for help on using the changeset viewer.