diff frontends/src/primitivus/primitivus @ 1158:c0f15e52695a

primitivus: use of new keys modules from Urwid SàText
author Goffi <goffi@goffi.org>
date Thu, 04 Sep 2014 19:05:57 +0200
parents 75025461141f
children 85fd02356dba
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus	Wed Sep 03 20:54:14 2014 +0200
+++ b/frontends/src/primitivus/primitivus	Thu Sep 04 19:05:57 2014 +0200
@@ -36,6 +36,7 @@
 from sat_frontends.primitivus import xmlui
 from sat_frontends.primitivus.progress import Progress
 from sat_frontends.primitivus.notify import Notify
+from sat_frontends.primitivus.keys import action_key_map as a_key
 from sat_frontends.tools.misc import InputHistory
 from sat_frontends.constants import Const as commonConst # FIXME
 from sat_frontends.tools.jid import JID
@@ -56,8 +57,8 @@
 
     def __init__(self, app):
         modes = {None: ('NORMAL', u''),
-                 'i': ('INSERTION', u'> '),
-                 ':': ('COMMAND', u':')} #XXX: captions *MUST* be unicode
+                 a_key['MODE_INSERTION']: ('INSERTION', u'> '),
+                 a_key['MODE_COMMAND']: ('COMMAND', u':')} #XXX: captions *MUST* be unicode
         super(EditBar, self).__init__(modes)
         self.app = app
         self.setCompletionMethod(self._text_completion)
@@ -153,19 +154,19 @@
             self.set_edit_text(text)
             self.set_edit_pos(len(text))
 
-        if key == "esc":
+        if key == a_key['MODAL_ESCAPE']:
             # first save the text to the current mode, then change to NORMAL
             self.app._updateInputHistory(self.get_edit_text(), mode=self.mode)
             self.app._updateInputHistory(mode='NORMAL')
         if self._mode == 'NORMAL' and key in self._modes:
             self.app._updateInputHistory(mode=self._modes[key][0])
-        if key == "up":
+        if key == a_key['HISTORY_PREV']:
             self.app._updateInputHistory(self.get_edit_text(), -1, history_cb, self.mode)
             return
-        elif key == "down":
+        elif key == a_key['HISTORY_NEXT']:
             self.app._updateInputHistory(self.get_edit_text(), +1, history_cb, self.mode)
             return
-        elif key == "enter":
+        elif key == a_key['EDIT_ENTER']:
             self.app._updateInputHistory(self.get_edit_text(), mode=self.mode)
         else:
             contact = self.app.contact_list.getContact()
@@ -246,8 +247,8 @@
                         input[input.index(i)] = 'down'
         return input
 
-    def keyHandler(self, input):
-        if input == 'meta m':
+    def keyHandler(self, input_):
+        if input_ == a_key['MENU_HIDE']:
             """User want to (un)hide the menu roller"""
             try:
                 if self.main_widget.header == None:
@@ -256,10 +257,10 @@
                     self.main_widget.header = None
             except AttributeError:
                 pass
-        elif input == 'ctrl n':
+        elif input_ == a_key['NOTIFICATION_NEXT']:
             """User wants to see next notification"""
             self.notBar.showNext()
-        elif input == 'ctrl s':
+        elif input_ == a_key['OVERLAY_HIDE']:
             """User wants to (un)hide overlay window"""
             if isinstance(self.loop.widget,urwid.Overlay):
                 self.__saved_overlay = self.loop.widget
@@ -269,9 +270,9 @@
                     self.loop.widget = self.__saved_overlay
                     self.__saved_overlay = None
 
-        elif input == 'ctrl d' and 'D' in self.bridge.getVersion(): #Debug only for dev versions
+        elif input_ == a_key['DEBUG'] and 'D' in self.bridge.getVersion(): #Debug only for dev versions
             self.debug()
-        elif input == 'f2': #user wants to (un)hide the contact_list
+        elif input_ == a_key['CONTACTS_HIDE']: #user wants to (un)hide the contact_list
             try:
                 for wid, options in self.center_part.contents:
                     if self.contact_list is wid:
@@ -282,7 +283,7 @@
             except AttributeError:
                 #The main widget is not built (probably in Profile Manager)
                 pass
-        elif input == 'window resize':
+        elif input_ == 'window resize':
             width,height = self.loop.screen_size
             if height<=5 and width<=35:
                 if not 'save_main_widget' in dir(self):
@@ -293,9 +294,9 @@
                     self.loop.widget = self.save_main_widget
                     del self.save_main_widget
         try:
-            return self.menu_roller.checkShortcuts(input)
+            return self.menu_roller.checkShortcuts(input_)
         except AttributeError:
-            return input
+            return input_
 
     def addMenus(self, menu, type_, menu_data=None):
         """Add cached menus to instance
@@ -320,11 +321,11 @@
         menu.addMenu(general, _("Disconnect"), self.onDisconnectRequest)
         menu.addMenu(general, _("Parameters"), self.onParam)
         menu.addMenu(general, _("About"), self.onAboutRequest)
-        menu.addMenu(general, _("Exit"), self.onExitRequest, 'ctrl x')
+        menu.addMenu(general, _("Exit"), self.onExitRequest, a_key['APP_QUIT'])
         contact = _("Contacts")
         menu.addMenu(contact)
         communication = _("Communication")
-        menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j')
+        menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, a_key['ROOM_JOIN'])
         #additionals menus
         #FIXME: do this in a more generic way (in quickapp)
         self.addMenus(menu, C.MENU_GLOBAL)