Guest User

010-KeyboardViMode-SublimeText2.py

a guest
Dec 24th, 2012
167
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf8 -*-
  2. from GizmoDaemon import *
  3. from GizmoScriptDefault import *
  4. import subprocess
  5.  
  6. ENABLED = True
  7. VERSION_NEEDED = 3.2
  8. INTERESTED_CLASSES = [GizmoEventClass.Standard]
  9.  
  10. MOD_KEY = GizmoKey.KEY_RIGHTALT
  11. CURSOR_KEY_MAPPING = {
  12.     GizmoKey.KEY_J: GizmoKey.KEY_DOWN,
  13.     GizmoKey.KEY_K: GizmoKey.KEY_UP,
  14.     GizmoKey.KEY_L: GizmoKey.KEY_RIGHT,
  15.     GizmoKey.KEY_H: GizmoKey.KEY_LEFT,
  16.     GizmoKey.KEY_F: GizmoKey.KEY_DOWN,
  17. }
  18.  
  19. class KeyboardViModeSublimeText2Default(GizmoScriptDefault):
  20.     """
  21.    Шорткаты в Vi-стиле для Sublime Text 2
  22.    """
  23.     def onEvent(self, Event, Gizmo=None):
  24.         if not GizmoScriptDefault.checkEvent(self, Event, Gizmo):
  25.             return False
  26.  
  27.         if Gizmod.CurrentFocus.WindowClass == 'Subl' and Gizmod.CurrentFocus.WindowName.endswith(" - Sublime Text 2"):
  28.             return self.onDeviceEvent(Event, Gizmo)
  29.         else:
  30.             return False
  31.  
  32.     def onDeviceEvent(self, Event, Gizmo=None):
  33.         if Event.Code == MOD_KEY:
  34.             if Event.Value is 1:
  35.                 Gizmod.Dispatcher.IsModPressed = True
  36.             elif Event.Value is 0:
  37.                 Gizmod.Dispatcher.IsModPressed = False
  38.  
  39.             return True
  40.  
  41.         if Gizmod.Dispatcher.IsModPressed and Event.Code in CURSOR_KEY_MAPPING:
  42.             if Event.Value in [0, 1]:
  43.                 Gizmod.Keyboards[0].createEventRaw(GizmoEventType.EV_KEY, CURSOR_KEY_MAPPING[Event.Code], Event.Value)
  44.             elif Event.Value is 2:
  45.                 Gizmod.Keyboards[0].createEventPress(GizmoEventType.EV_KEY, CURSOR_KEY_MAPPING[Event.Code])
  46.  
  47.             return True
  48.  
  49.         return False
  50.  
  51. Gizmod.Dispatcher.IsModPressed = False
  52. KeyboardViModeSublimeText2Default(ENABLED, VERSION_NEEDED, INTERESTED_CLASSES)
RAW Paste Data