Mercurial > libervia-backend
changeset 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 | c4b62e6b7377 |
children | 85fd02356dba |
files | frontends/src/primitivus/card_game.py frontends/src/primitivus/chat.py frontends/src/primitivus/contact_list.py frontends/src/primitivus/keys.py frontends/src/primitivus/primitivus |
diffstat | 5 files changed, 93 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/card_game.py Wed Sep 03 20:54:14 2014 +0200 +++ b/frontends/src/primitivus/card_game.py Thu Sep 04 19:05:57 2014 +0200 @@ -23,6 +23,7 @@ from sat_frontends.tools.games import TarotCard from sat_frontends.quick_frontend.quick_card_game import QuickCardGame from sat_frontends.primitivus import xmlui +from sat_frontends.primitivus.keys import action_key_map as a_key class CardDisplayer(urwid.Text): @@ -38,7 +39,7 @@ return True def keypress(self, size, key): - if key == ' ': + if key == a_key['CARD_SELECT']: self.select(not self.__selected) self._emit('click') return key @@ -95,7 +96,7 @@ return self.columns.keypress(size, key) else: #No card displayed, we still have to manage the clicks - if key == ' ': + if key == a_key['CARD_SELECT']: self._emit('click', None) return key
--- a/frontends/src/primitivus/chat.py Wed Sep 03 20:54:14 2014 +0200 +++ b/frontends/src/primitivus/chat.py Thu Sep 04 19:05:57 2014 +0200 @@ -26,6 +26,7 @@ from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate from sat_frontends.primitivus import xmlui from sat_frontends.primitivus.constants import Const as C +from sat_frontends.primitivus.keys import action_key_map as a_key import time from sat_frontends.tools.jid import JID @@ -95,26 +96,26 @@ self.subject = None def keypress(self, size, key): - if key == "meta p": #user wants to (un)hide the presents panel + if key == a_key['OCCUPANTS_HIDE']: #user wants to (un)hide the presents panel if self.type == 'group': widgets = [widget for (widget, options) in self.chat_colums.contents] if self.present_panel in widgets: self.__removePresentPanel() else: self.__appendPresentPanel() - elif key == "meta t": #user wants to (un)hide timestamp + elif key == a_key['TIMESTAMP_HIDE']: #user wants to (un)hide timestamp self.show_timestamp = not self.show_timestamp for wid in self.content: wid._invalidate() - elif key == "meta n": #user wants to (not) use short nick + elif key == a_key['SHORT_NICKNAME']: #user wants to (not) use short nick self.show_short_nick = not self.show_short_nick for wid in self.content: wid._invalidate() - elif key == "meta l": #user wants to (un)hide widget decoration + elif key == a_key['DECORATION_HIDE']: #user wants to (un)hide widget decoration show = not isinstance(self._w, sat_widgets.LabelLine) self.showDecoration(show) self._invalidate() - elif key == "meta s": #user wants to (un)hide group's subject or change its apperance + elif key == a_key['SUBJECT_SWITCH']: #user wants to (un)hide group's subject or change its apperance if self.subject: self.show_title = (self.show_title + 1) % 3 if self.show_title == 0:
--- a/frontends/src/primitivus/contact_list.py Wed Sep 03 20:54:14 2014 +0200 +++ b/frontends/src/primitivus/contact_list.py Thu Sep 04 19:05:57 2014 +0200 @@ -21,10 +21,12 @@ import urwid from urwid_satext import sat_widgets from sat_frontends.quick_frontend.quick_contact_list import QuickContactList -from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate +from sat_frontends.quick_frontend.quick_utils import unescapePrivate from sat_frontends.tools.jid import JID from sat_frontends.primitivus.status import StatusBar from sat_frontends.primitivus.constants import Const +from sat_frontends.primitivus.keys import action_key_map as a_key + class ContactList(urwid.WidgetWrap, QuickContactList): signals = ['click','change'] @@ -63,10 +65,10 @@ self.update() def keypress(self, size, key): - if key == "meta s": #user wants to (un)hide contacts' statuses + if key == a_key['STATUS_HIDE']: #user wants to (un)hide contacts' statuses self.show_status = not self.show_status self.update() - elif key == "meta d": #user wants to (un)hide disconnected contacts + elif key == a_key['DISCONNECTED_HIDE']: #user wants to (un)hide disconnected contacts self.show_disconnected = not self.show_disconnected self.update() return super(ContactList, self).keypress(size, key)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frontends/src/primitivus/keys.py Thu Sep 04 19:05:57 2014 +0200 @@ -0,0 +1,61 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Primitivus: a SAT frontend +# Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +"""This file manage the action <=> key map""" + +from urwid_satext.keys import action_key_map + + +action_key_map.update( + { + # Edit bar + ("edit", "MODE_INSERTION"): "i", + ("edit", "MODE_COMMAND"): ":", + ("edit", "HISTORY_PREV"): "up", + ("edit", "HISTORY_NEXT"): "down", + + # global + ("global", "MENU_HIDE"): 'meta m', + ("global", "NOTIFICATION_NEXT"): 'ctrl n', + ("global", "OVERLAY_HIDE"): 'ctrl s', + ("global", "DEBUG"): 'ctrl d', + ("global", "CONTACTS_HIDE"): 'f2', + + # global menu + ("menu_global", "APP_QUIT"): 'ctrl x', + ("menu_global", "ROOM_JOIN"): 'meta j', + + # contact list + ("contact_list", "STATUS_HIDE"): "meta s", + ("contact_list", "DISCONNECTED_HIDE"): "meta d", + + # chat panel + ("chat_panel", "OCCUPANTS_HIDE"): "meta p", + ("chat_panel", "TIMESTAMP_HIDE"): "meta t", + ("chat_panel", "SHORT_NICKNAME"): "meta n", + ("chat_panel", "DECORATION_HIDE"): "meta l", + ("chat_panel", "SUBJECT_SWITCH"): "meta s", + + #card game + ("card_game", "CARD_SELECT"): ' ', + }) + + +action_key_map.set_close_namespaces(tuple(), ('global', 'focus', 'menu_global')) +action_key_map.check_namespaces()
--- 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)