annotate frontends/src/primitivus/primitivus @ 1225:82dabb442e2e

frontends (primitivus): new command :search <pattern>
author souliane <souliane@mailoo.org>
date Sat, 04 Oct 2014 10:26:10 +0200
parents 9cc858acae91
children e3a9ea76de35
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
4 # Primitivus: a SAT frontend
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 807
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
10 # (at your option) any later version.
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
15 # GNU Affero General Public License for more details.
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20
1225
82dabb442e2e frontends (primitivus): new command :search <pattern>
souliane <souliane@mailoo.org>
parents: 1186
diff changeset
21 from sat.core.i18n import _, D_
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
22 from sat_frontends.primitivus.constants import Const as C
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
23 from sat.core import log_config
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
24 log_config.satConfigure(C.LOG_BACKEND_STANDARD, C)
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
25 from sat.core import log as logging
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
26 log = logging.getLogger(__name__)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 import urwid
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
28 from urwid_satext import sat_widgets
542
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
29 from urwid_satext.files_management import FileDialog
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
30 from sat_frontends.quick_frontend.quick_app import QuickApp
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
31 from sat_frontends.quick_frontend.quick_chat_list import QuickChatList
661
d81f55a58c08 primitivus: fixed crash on private messages
Goffi <goffi@goffi.org>
parents: 641
diff changeset
32 from sat_frontends.quick_frontend.quick_utils import getNewPath, unescapePrivate
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
33 from sat_frontends.primitivus.profile_manager import ProfileManager
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
34 from sat_frontends.primitivus.contact_list import ContactList
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
35 from sat_frontends.primitivus.chat import Chat
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1103
diff changeset
36 from sat_frontends.primitivus import xmlui
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
37 from sat_frontends.primitivus.progress import Progress
475
6bb9305e0b9c frontend: Fix notify import in Primitivus.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 459
diff changeset
38 from sat_frontends.primitivus.notify import Notify
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
39 from sat_frontends.primitivus.keys import action_key_map as a_key
1159
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
40 from sat_frontends.primitivus import config
719
56aa0e98c92e frontends tools: moved src/tools/frontends to frontends/src/tools
souliane <souliane@mailoo.org>
parents: 688
diff changeset
41 from sat_frontends.tools.misc import InputHistory
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
42 from sat_frontends.constants import Const as commonConst # FIXME
1139
75025461141f move sat.tools.jid to sat_frontends.tools.jid
souliane <souliane@mailoo.org>
parents: 1125
diff changeset
43 from sat_frontends.tools.jid import JID
542
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
44 from os.path import join
1162
b32800b9793e primitivus: SIGINT is now ignored, APP_QUIT key/menu or :quit command must be used to quit Primitivus
Goffi <goffi@goffi.org>
parents: 1160
diff changeset
45 import signal
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
48 class ChatList(QuickChatList):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
49 """This class manage the list of chat windows"""
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
50
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
51 def createChat(self, target):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
52 return Chat(target, self.host)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
53
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
54
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
55 class EditBar(sat_widgets.ModalEdit):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
56 """
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
57 The modal edit bar where you would enter messages and commands.
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
58 """
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
59
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
60 def __init__(self, app):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
61 modes = {None: ('NORMAL', u''),
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
62 a_key['MODE_INSERTION']: ('INSERTION', u'> '),
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
63 a_key['MODE_COMMAND']: ('COMMAND', u':')} #XXX: captions *MUST* be unicode
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
64 super(EditBar, self).__init__(modes)
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
65 self.app = app
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
66 self.setCompletionMethod(self._text_completion)
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
67 urwid.connect_signal(self, 'click', self.onTextEntered)
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
68
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
69 def _text_completion(self, text, completion_data, mode):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
70 if mode == 'INSERTION':
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
71 return self._nick_completion(text, completion_data)
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
72 else:
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
73 return text
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
74
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
75 def _nick_completion(self, text, completion_data):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
76 """Completion method which complete pseudo in group chat
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
77 for params, see AdvancedEdit"""
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
78 contact = self.app.contact_list.getContact() ###Based on the fact that there is currently only one contact selectable at once
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
79 if contact:
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
80 chat = self.app.chat_wins[contact]
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
81 if chat.type != "group":
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
82 return text
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
83 space = text.rfind(" ")
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
84 start = text[space+1:]
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
85 nicks = list(chat.occupants)
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
86 nicks.sort()
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
87 try:
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
88 start_idx=nicks.index(completion_data['last_nick'])+1
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
89 if start_idx == len(nicks):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
90 start_idx = 0
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
91 except (KeyError,ValueError):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
92 start_idx = 0
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
93 for idx in range(start_idx,len(nicks)) + range(0,start_idx):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
94 if nicks[idx].lower().startswith(start.lower()):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
95 completion_data['last_nick'] = nicks[idx]
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
96 return text[:space+1] + nicks[idx] + (': ' if space < 0 else '')
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
97 return text
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
98
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
99 def onTextEntered(self, editBar):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
100 """Called when text is entered in the main edit bar"""
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
101 if self.mode == 'INSERTION':
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
102 contact = self.app.contact_list.getContact() ###Based on the fact that there is currently only one contact selectableat once
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
103 if contact:
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
104 chat = self.app.chat_wins[contact]
776
f89173f44850 frontends: fixed sendMessage calls, sendMessage is now async so callback and errback need to be specified + redraw in PrimivitusApp.notify
Goffi <goffi@goffi.org>
parents: 773
diff changeset
105 self.app.sendMessage(contact,
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
106 editBar.get_edit_text(),
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
107 mess_type = "groupchat" if chat.type == 'group' else "chat",
1063
6ec513ad92c2 frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents: 1060
diff changeset
108 errback=lambda failure: self.app.notify(_("Error while sending message (%s)") % failure),
776
f89173f44850 frontends: fixed sendMessage calls, sendMessage is now async so callback and errback need to be specified + redraw in PrimivitusApp.notify
Goffi <goffi@goffi.org>
parents: 773
diff changeset
109 profile_key=self.app.profile
f89173f44850 frontends: fixed sendMessage calls, sendMessage is now async so callback and errback need to be specified + redraw in PrimivitusApp.notify
Goffi <goffi@goffi.org>
parents: 773
diff changeset
110 )
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
111 editBar.set_edit_text('')
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
112 elif self.mode == 'COMMAND':
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
113 self.commandHandler()
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
114
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
115 def commandHandler(self):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
116 #TODO: separate class with auto documentation (with introspection)
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
117 # and completion method
1119
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
118 tokens = self.get_edit_text().split(' ')
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
119 command, args = tokens[0], tokens[1:]
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
120 if command == 'quit':
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
121 self.app.onExit()
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
122 raise urwid.ExitMainLoop()
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
123 elif command == 'messages':
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
124 wid = sat_widgets.GenericList(logging.memoryGet())
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
125 self.app.addWindow(wid)
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
126 elif command == 'presence':
1119
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
127 values = [value for value in commonConst.PRESENCE.keys()]
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
128 values = [value if value else 'online' for value in values] # the empty value actually means 'online'
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
129 if args and args[0] in values:
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
130 presence = '' if args[0] == 'online' else args[0]
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
131 self.app.status_bar.onChange(user_data=sat_widgets.ClickableText(commonConst.PRESENCE[presence]))
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
132 else:
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
133 self.app.status_bar.onPresenceClick()
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
134 elif command == 'status':
1119
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
135 if args:
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
136 self.app.status_bar.onChange(user_data=sat_widgets.AdvancedEdit(args[0]))
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
137 else:
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
138 self.app.status_bar.onStatusClick()
1125
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1124
diff changeset
139 elif command == 'history':
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1124
diff changeset
140 try:
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1124
diff changeset
141 limit = int(args[0])
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1124
diff changeset
142 except (IndexError, ValueError):
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1124
diff changeset
143 limit = 50
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1124
diff changeset
144 win = self.app.chat_wins[JID(self.app.contact_list.selected).bare]
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1124
diff changeset
145 win.clearHistory()
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1124
diff changeset
146 if limit > 0:
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1124
diff changeset
147 win.historyPrint(size=limit, profile=self.app.profile)
1225
82dabb442e2e frontends (primitivus): new command :search <pattern>
souliane <souliane@mailoo.org>
parents: 1186
diff changeset
148 elif command == 'search':
82dabb442e2e frontends (primitivus): new command :search <pattern>
souliane <souliane@mailoo.org>
parents: 1186
diff changeset
149 pattern = " ".join(args)
82dabb442e2e frontends (primitivus): new command :search <pattern>
souliane <souliane@mailoo.org>
parents: 1186
diff changeset
150 if not pattern:
82dabb442e2e frontends (primitivus): new command :search <pattern>
souliane <souliane@mailoo.org>
parents: 1186
diff changeset
151 self.app.notif_bar.addMessage(D_("Please specify the globbing pattern to search for"))
82dabb442e2e frontends (primitivus): new command :search <pattern>
souliane <souliane@mailoo.org>
parents: 1186
diff changeset
152 win = self.app.chat_wins[JID(self.app.contact_list.selected).bare]
82dabb442e2e frontends (primitivus): new command :search <pattern>
souliane <souliane@mailoo.org>
parents: 1186
diff changeset
153 win.clearHistory()
82dabb442e2e frontends (primitivus): new command :search <pattern>
souliane <souliane@mailoo.org>
parents: 1186
diff changeset
154 win.printInfo(D_("Results for searching the globbing pattern: %s") % pattern, timestamp=0)
82dabb442e2e frontends (primitivus): new command :search <pattern>
souliane <souliane@mailoo.org>
parents: 1186
diff changeset
155 win.historyPrint(size=C.HISTORY_LIMIT_NONE, search=pattern, profile=self.app.profile)
82dabb442e2e frontends (primitivus): new command :search <pattern>
souliane <souliane@mailoo.org>
parents: 1186
diff changeset
156 win.printInfo(D_("Type ':history <lines>' to reset the chat history"))
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
157 else:
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
158 return
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
159 self.set_edit_text('')
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
160
1160
2ff15a6c5791 primitivus: moved history method definition out of keypress
Goffi <goffi@goffi.org>
parents: 1159
diff changeset
161 def _historyCb(self, text):
2ff15a6c5791 primitivus: moved history method definition out of keypress
Goffi <goffi@goffi.org>
parents: 1159
diff changeset
162 self.set_edit_text(text)
2ff15a6c5791 primitivus: moved history method definition out of keypress
Goffi <goffi@goffi.org>
parents: 1159
diff changeset
163 self.set_edit_pos(len(text))
2ff15a6c5791 primitivus: moved history method definition out of keypress
Goffi <goffi@goffi.org>
parents: 1159
diff changeset
164
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
165 def keypress(self, size, key):
671
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
166 """Callback when a key is pressed. Send "composing" states
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
167 and move the index of the temporary history stack."""
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
168 if key == a_key['MODAL_ESCAPE']:
738
e867f146d49f primitivus: save the input history when "esc" is pressed
souliane <souliane@mailoo.org>
parents: 737
diff changeset
169 # first save the text to the current mode, then change to NORMAL
e867f146d49f primitivus: save the input history when "esc" is pressed
souliane <souliane@mailoo.org>
parents: 737
diff changeset
170 self.app._updateInputHistory(self.get_edit_text(), mode=self.mode)
671
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
171 self.app._updateInputHistory(mode='NORMAL')
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
172 if self._mode == 'NORMAL' and key in self._modes:
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
173 self.app._updateInputHistory(mode=self._modes[key][0])
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
174 if key == a_key['HISTORY_PREV']:
1163
60ebe98c9d04 primitivus: forgot to rename _historyCb method
Goffi <goffi@goffi.org>
parents: 1162
diff changeset
175 self.app._updateInputHistory(self.get_edit_text(), -1, self._historyCb, self.mode)
913
d08cbdd566e2 primitivus: EditBar doesn't propagate key pressed anymore if it manage a 'up' or 'down' event (history event)
Goffi <goffi@goffi.org>
parents: 911
diff changeset
176 return
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
177 elif key == a_key['HISTORY_NEXT']:
1163
60ebe98c9d04 primitivus: forgot to rename _historyCb method
Goffi <goffi@goffi.org>
parents: 1162
diff changeset
178 self.app._updateInputHistory(self.get_edit_text(), +1, self._historyCb, self.mode)
913
d08cbdd566e2 primitivus: EditBar doesn't propagate key pressed anymore if it manage a 'up' or 'down' event (history event)
Goffi <goffi@goffi.org>
parents: 911
diff changeset
179 return
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
180 elif key == a_key['EDIT_ENTER']:
671
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
181 self.app._updateInputHistory(self.get_edit_text(), mode=self.mode)
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
182 else:
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
183 contact = self.app.contact_list.getContact()
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
184 if contact:
661
d81f55a58c08 primitivus: fixed crash on private messages
Goffi <goffi@goffi.org>
parents: 641
diff changeset
185 self.app.bridge.chatStateComposing(unescapePrivate(contact), self.app.profile)
671
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
186 return super(EditBar, self).keypress(size, key)
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
187
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
188
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
189 class PrimitivusTopWidget(sat_widgets.FocusPile):
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
190 """Top most widget used in Primitivus"""
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
191 _focus_inversed = True
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
192 positions = ('menu', 'body', 'notif_bar', 'edit_bar')
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
193 can_hide = ('menu', 'notif_bar')
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
194
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
195 def __init__(self, body, menu, notif_bar, edit_bar):
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
196 self._body = body
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
197 self._menu = menu
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
198 self._notif_bar = notif_bar
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
199 self._edit_bar = edit_bar
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
200 self._hidden = {'notif_bar'}
1186
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
201 self._focus_extra = False
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
202 super(PrimitivusTopWidget, self).__init__([('pack', self._menu), self._body, ('pack', self._edit_bar)])
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
203 for position in self.positions:
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
204 setattr(self,
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
205 position,
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
206 property(lambda: self, self.widgetGet(position=position),
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
207 lambda pos, new_wid: self.widgetSet(new_wid, position=pos))
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
208 )
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
209 self.focus_position = len(self.contents)-1
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
210
1186
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
211 def getVisiblePositions(self, keep=None):
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
212 """Return positions that are not hidden in the right order
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
213
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
214 @param keep: if not None, this position will be keep in the right order, even if it's hidden
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
215 (can be useful to find its index)
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
216 @return (list): list of visible positions
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
217 """
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
218 return [pos for pos in self.positions if (keep and pos == keep) or pos not in self._hidden]
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
219
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
220 def keypress(self, size, key):
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
221 """Manage FOCUS keys that focus directly a main part (one of self.positions)
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
222
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
223 To avoid key conflicts, a combinaison must be made with FOCUS_EXTRA then an other key
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
224 """
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
225 if key == a_key['FOCUS_EXTRA']:
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
226 self._focus_extra = True
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
227 return
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
228 if self._focus_extra:
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
229 self._focus_extra = False
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
230 if key in ('m', '1'):
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
231 focus = 'menu'
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
232 elif key in ('b', '2'):
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
233 focus = 'body'
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
234 elif key in ('n', '3'):
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
235 focus = 'notif_bar'
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
236 elif key in ('e', '4'):
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
237 focus = 'edit_bar'
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
238 else:
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
239 return super(PrimitivusTopWidget, self).keypress(size, key)
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
240
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
241 if focus in self._hidden:
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
242 return
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
243
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
244 self.focus_position = self.getVisiblePositions().index(focus)
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
245 return
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
246
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
247 return super(PrimitivusTopWidget, self).keypress(size, key)
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
248
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
249 def widgetGet(self, position):
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
250 if not position in self.positions:
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
251 raise ValueError("Unknown position {}".format(position))
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
252 return getattr(self, "_{}".format(position))
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
253
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
254 def widgetSet(self, widget, position):
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
255 if not position in self.positions:
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
256 raise ValueError("Unknown position {}".format(position))
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
257 return setattr(self, "_{}".format(position), widget)
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
258
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
259 def hideSwitch(self, position):
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
260 if not position in self.can_hide:
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
261 raise ValueError("Can't switch position {}".format(position))
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
262 hide = not position in self._hidden
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
263 widget = self.widgetGet(position)
1186
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
264 idx = self.getVisiblePositions(position).index(position)
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
265 if hide:
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
266 del self.contents[idx]
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
267 self._hidden.add(position)
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
268 else:
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
269 self.contents.insert(idx, (widget, ('pack', None)))
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
270 self._hidden.remove(position)
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
271
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
272 def show(self, position):
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
273 if position in self._hidden:
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
274 self.hideSwitch(position)
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
275
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
276 def hide(self, position):
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
277 if not position in self._hidden:
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
278 self.hideSwitch(position)
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
279
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
280
671
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
281 class PrimitivusApp(QuickApp, InputHistory):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
282
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
283 def __init__(self):
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
284 QuickApp.__init__(self)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
285
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
286 ## main loop setup ##
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
287 self.main_widget = ProfileManager(self)
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
288 self.loop = urwid.MainLoop(self.main_widget, C.PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
289
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
290 ##misc setup##
679
59c9a7ff903d wix, misc: use picture of dimension 32x32 for tray icon + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 673
diff changeset
291 self.chat_wins = ChatList(self)
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
292 self.notif_bar = sat_widgets.NotificationBar()
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
293 urwid.connect_signal(self.notif_bar, 'change', self.onNotification)
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
294 self.progress_wid = Progress(self)
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
295 urwid.connect_signal(self.notif_bar.progress, 'click', lambda x: self.addWindow(self.progress_wid))
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
296 self.__saved_overlay = None
380
ede26abf6ca1 primitivus: freedesktop notifications (if available) when somebody is talking to us and we have not focus, or our nick is pinged and we have not focus.
Goffi <goffi@goffi.org>
parents: 276
diff changeset
297
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 503
diff changeset
298 self.x_notify = Notify()
524
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
299
1162
b32800b9793e primitivus: SIGINT is now ignored, APP_QUIT key/menu or :quit command must be used to quit Primitivus
Goffi <goffi@goffi.org>
parents: 1160
diff changeset
300 # we already manage exit with a_key['APP_QUIT'], so we don't want C-c
b32800b9793e primitivus: SIGINT is now ignored, APP_QUIT key/menu or :quit command must be used to quit Primitivus
Goffi <goffi@goffi.org>
parents: 1160
diff changeset
301 signal.signal(signal.SIGINT, signal.SIG_IGN)
b32800b9793e primitivus: SIGINT is now ignored, APP_QUIT key/menu or :quit command must be used to quit Primitivus
Goffi <goffi@goffi.org>
parents: 1160
diff changeset
302
524
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
303 @property
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
304 def mode(self):
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
305 return self.editBar.mode
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
306
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
307 @mode.setter
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
308 def mode(self, value):
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
309 self.editBar.mode = value
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
310
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
311 def modeHint(self, value):
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
312 """Change mode if make sens (i.e.: if there is nothing in the editBar)"""
524
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
313 if not self.editBar.get_edit_text():
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
314 self.mode = value
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
315
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
316 def debug(self):
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
317 """convenient method to reset screen and launch (i)p(u)db"""
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
318 log.info('Entered debug mode')
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
319 try:
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
320 import pudb
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
321 pudb.set_trace()
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
322 except ImportError:
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
323 import os
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
324 os.system('reset')
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
325 try:
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
326 import ipdb
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
327 ipdb.set_trace()
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
328 except ImportError:
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
329 import pdb
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
330 pdb.set_trace()
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
331
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
332 def redraw(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
333 """redraw the screen"""
422
5a18c5f08d9b Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents: 415
diff changeset
334 try:
5a18c5f08d9b Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents: 415
diff changeset
335 self.loop.draw_screen()
5a18c5f08d9b Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents: 415
diff changeset
336 except AttributeError:
5a18c5f08d9b Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents: 415
diff changeset
337 pass
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
338
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
339 def start(self):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
340 self.i = 0
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
341 self.loop.set_alarm_in(0,lambda a,b: self.postInit())
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
342 self.loop.run()
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
343
1159
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
344 def postInit(self):
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
345 try:
1165
ca15fb1abbc4 primitivus: added disable_mouse config option /!\ minimal Urwid version is now 1.2.0
Goffi <goffi@goffi.org>
parents: 1164
diff changeset
346 config.applyConfig(self)
1159
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
347 except Exception as e:
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
348 log.error("configuration error: {}".format(e))
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
349 popup = sat_widgets.Alert(_("Configuration Error"), _("Something went wrong while reading the configuration, please check :messages"), ok_cb=self.removePopUp)
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
350 if self.options.profile:
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
351 self._early_popup = popup
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
352 else:
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
353 self.showPopUp(popup)
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
354 super(PrimitivusApp, self).postInit()
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
355
1164
af395a6f2551 primitivus: fixed forgotten keys
Goffi <goffi@goffi.org>
parents: 1163
diff changeset
356 def inputFilter(self, input_, raw):
af395a6f2551 primitivus: fixed forgotten keys
Goffi <goffi@goffi.org>
parents: 1163
diff changeset
357 if self.__saved_overlay and input_ != a_key['OVERLAY_HIDE']:
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
358 return
1164
af395a6f2551 primitivus: fixed forgotten keys
Goffi <goffi@goffi.org>
parents: 1163
diff changeset
359 for i in input_:
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
360 if isinstance(i,tuple):
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
361 if i[0] == 'mouse press':
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
362 if i[1] == 4: #Mouse wheel up
1164
af395a6f2551 primitivus: fixed forgotten keys
Goffi <goffi@goffi.org>
parents: 1163
diff changeset
363 input_[input_.index(i)] = a_key['HISTORY_PREV']
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
364 if i[1] == 5: #Mouse wheel down
1164
af395a6f2551 primitivus: fixed forgotten keys
Goffi <goffi@goffi.org>
parents: 1163
diff changeset
365 input_[input_.index(i)] = a_key['HISTORY_NEXT']
af395a6f2551 primitivus: fixed forgotten keys
Goffi <goffi@goffi.org>
parents: 1163
diff changeset
366 return input_
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
367
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
368 def keyHandler(self, input_):
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
369 if input_ == a_key['MENU_HIDE']:
181
a566f654929e README update:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
370 """User want to (un)hide the menu roller"""
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
371 try:
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
372 self.main_widget.hideSwitch('menu')
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
373 except AttributeError:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
374 pass
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
375 elif input_ == a_key['NOTIFICATION_NEXT']:
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
376 """User wants to see next notification"""
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
377 self.notif_bar.showNext()
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
378 elif input_ == a_key['OVERLAY_HIDE']:
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
379 """User wants to (un)hide overlay window"""
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
380 if isinstance(self.loop.widget,urwid.Overlay):
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
381 self.__saved_overlay = self.loop.widget
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
382 self.loop.widget = self.main_widget
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
383 else:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
384 if self.__saved_overlay:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
385 self.loop.widget = self.__saved_overlay
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
386 self.__saved_overlay = None
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
387
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
388 elif input_ == a_key['DEBUG'] and 'D' in self.bridge.getVersion(): #Debug only for dev versions
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
389 self.debug()
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
390 elif input_ == a_key['CONTACTS_HIDE']: #user wants to (un)hide the contact_list
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
391 try:
608
ea9aa51234eb Primitivus: fixed contacts list (un)hidding
Goffi <goffi@goffi.org>
parents: 607
diff changeset
392 for wid, options in self.center_part.contents:
ea9aa51234eb Primitivus: fixed contacts list (un)hidding
Goffi <goffi@goffi.org>
parents: 607
diff changeset
393 if self.contact_list is wid:
ea9aa51234eb Primitivus: fixed contacts list (un)hidding
Goffi <goffi@goffi.org>
parents: 607
diff changeset
394 self.center_part.contents.remove((wid, options))
ea9aa51234eb Primitivus: fixed contacts list (un)hidding
Goffi <goffi@goffi.org>
parents: 607
diff changeset
395 break
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
396 else:
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 605
diff changeset
397 self.center_part.contents.insert(0, (self.contact_list, ('weight', 2, False)))
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
398 except AttributeError:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
399 #The main widget is not built (probably in Profile Manager)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
400 pass
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
401 elif input_ == 'window resize':
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
402 width,height = self.loop.screen_size
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
403 if height<=5 and width<=35:
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
404 if not 'save_main_widget' in dir(self):
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
405 self.save_main_widget = self.loop.widget
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
406 self.loop.widget = urwid.Filler(urwid.Text(_("Pleeeeasse, I can't even breathe !")))
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
407 else:
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
408 if 'save_main_widget' in dir(self):
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
409 self.loop.widget = self.save_main_widget
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
410 del self.save_main_widget
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
411 try:
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
412 return self.menu_roller.checkShortcuts(input_)
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
413 except AttributeError:
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
414 return input_
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
415
1093
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
416 def addMenus(self, menu, type_, menu_data=None):
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
417 """Add cached menus to instance
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
418 @param menu: sat_widgets.Menu instance
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
419 @param type_: menu type like is sat.core.sat_main.importMenu
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
420 @param menu_data: data to send with these menus
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
421
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
422 """
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
423 menus = self.profiles[self.profile]['menus'].get(type_,[])
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
424 def add_menu_cb(callback_id):
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
425 self.launchAction(callback_id, menu_data, profile_key = self.profile)
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
426 for id_, path, path_i18n in menus:
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
427 if len(path) != 2:
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
428 raise NotImplementedError("Menu with a path != 2 are not implemented yet")
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
429 menu.addMenu(path_i18n[0], path_i18n[1], lambda dummy,id_=id_: add_menu_cb(id_))
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
430
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
431
755
e3ad48a2aab2 core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents: 752
diff changeset
432 def _buildMenuRoller(self):
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
433 menu = sat_widgets.Menu(self.loop)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
434 general = _("General")
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
435 menu.addMenu(general, _("Connect"), self.onConnectRequest)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
436 menu.addMenu(general, _("Disconnect"), self.onDisconnectRequest)
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
437 menu.addMenu(general, _("Parameters"), self.onParam)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
438 menu.addMenu(general, _("About"), self.onAboutRequest)
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
439 menu.addMenu(general, _("Exit"), self.onExitRequest, a_key['APP_QUIT'])
987
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 917
diff changeset
440 contact = _("Contacts")
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 917
diff changeset
441 menu.addMenu(contact)
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
442 communication = _("Communication")
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
443 menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, a_key['ROOM_JOIN'])
145
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
444 #additionals menus
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
445 #FIXME: do this in a more generic way (in quickapp)
1093
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
446 self.addMenus(menu, C.MENU_GLOBAL)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
447
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
448 menu_roller = sat_widgets.MenuRoller([(_('Main menu'),menu)])
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
449 return menu_roller
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
450
755
e3ad48a2aab2 core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents: 752
diff changeset
451 def _buildMainWidget(self):
679
59c9a7ff903d wix, misc: use picture of dimension 32x32 for tray icon + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 673
diff changeset
452 self.contact_list = ContactList(self, on_click=self.contactSelected, on_change=lambda w: self.redraw())
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 495
diff changeset
453 #self.center_part = urwid.Columns([('weight',2,self.contact_list),('weight',8,Chat('',self))])
679
59c9a7ff903d wix, misc: use picture of dimension 32x32 for tray icon + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 673
diff changeset
454 self.center_part = urwid.Columns([('weight', 2, self.contact_list), ('weight', 8, urwid.Filler(urwid.Text('')))])
524
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
455
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
456 self.editBar = EditBar(self)
755
e3ad48a2aab2 core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents: 752
diff changeset
457 self.menu_roller = self._buildMenuRoller()
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
458 self.main_widget = PrimitivusTopWidget(self.center_part, self.menu_roller, self.notif_bar, self.editBar)
118
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
459 return self.main_widget
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
460
1034
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1021
diff changeset
461 def plug_profile_1(self, profile_key='@DEFAULT@'):
755
e3ad48a2aab2 core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents: 752
diff changeset
462 self.loop.widget = self._buildMainWidget()
415
3348331e0f09 primitivus: fixed screen redraw after plugin profile
Goffi <goffi@goffi.org>
parents: 411
diff changeset
463 self.redraw()
1034
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1021
diff changeset
464 QuickApp.plug_profile_1(self, profile_key)
1159
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
465 try:
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
466 # if a popup arrived before main widget is build, we need to show it now
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
467 self.showPopUp(self._early_popup)
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
468 except AttributeError:
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
469 pass
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
470 else:
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
471 del self._early_popup
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
472
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
473 def removePopUp(self, widget=None):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
474 "Remove current pop-up, and if there is other in queue, show it"
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
475 self.loop.widget = self.main_widget
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
476 next_popup = self.notif_bar.getNextPopup()
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
477 if next_popup:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
478 #we still have popup to show, we display it
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
479 self.showPopUp(next_popup)
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
480
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
481 def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40, align='center', valign='middle'):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
482 "Show a pop-up window if possible, else put it in queue"
687
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 679
diff changeset
483 if not isinstance(self.loop.widget, urwid.Overlay):
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
484 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, align, ('relative', perc_width), valign, ('relative', perc_height))
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
485 self.loop.widget = display_widget
219
782319a64ac6 primitivus, wix: added forgotten profile
Goffi <goffi@goffi.org>
parents: 216
diff changeset
486 self.redraw()
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
487 else:
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
488 self.notif_bar.addPopUp(pop_up_widget)
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
489
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
490 def notify(self, message):
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
491 """"Notify message to user via notification bar"""
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
492 self.notif_bar.addMessage(message)
776
f89173f44850 frontends: fixed sendMessage calls, sendMessage is now async so callback and errback need to be specified + redraw in PrimivitusApp.notify
Goffi <goffi@goffi.org>
parents: 773
diff changeset
493 self.redraw()
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
494
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
495 def addWindow(self, widget):
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
496 """Display a window if possible,
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
497 else add it in the notification bar queue
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
498 @param widget: BoxWidget"""
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
499 assert(len(self.center_part.widget_list)<=2)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
500 wid_idx = len(self.center_part.widget_list)-1
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
501 self.center_part.widget_list[wid_idx] = widget
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
502 self.menu_roller.removeMenu(_('Chat menu'))
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 495
diff changeset
503 self.contact_list.unselectAll()
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
504 self.redraw()
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
505
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
506 def removeWindow(self):
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
507 """Remove window showed on the right column"""
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
508 #TODO: to a better Window management than this crappy hack
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
509 assert(len(self.center_part.widget_list)<=2)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
510 wid_idx = len(self.center_part.widget_list)-1
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
511 self.center_part.widget_list[wid_idx] = urwid.Filler(urwid.Text(''))
911
b12706d164d7 primitivus: removed deprecated use of set_focus
Goffi <goffi@goffi.org>
parents: 907
diff changeset
512 self.center_part.focus_position = 0
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
513 self.redraw()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
514
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
515 def addProgress (self, id, message):
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
516 """Follow a SàT progress bar
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
517 @param id: SàT id of the progression
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
518 @param message: message to show to identify the progression"""
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
519 self.progress_wid.addProgress(id, message)
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
520
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
521 def setProgress(self, percentage):
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
522 """Set the progression shown in notification bar"""
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
523 self.notif_bar.setProgress(percentage)
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
524
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
525 def contactSelected(self, contact_list):
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 495
diff changeset
526 contact = contact_list.getContact()
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
527 if contact:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
528 assert(len(self.center_part.widget_list)==2)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
529 self.center_part.widget_list[1] = self.chat_wins[contact]
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
530 self.menu_roller.addMenu(_('Chat menu'), self.chat_wins[contact].getMenu())
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
531
1103
a096b8579a3c frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents: 1093
diff changeset
532 def newMessageHandler(self, from_jid, to_jid, msg, _type, extra, profile):
a096b8579a3c frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents: 1093
diff changeset
533 QuickApp.newMessageHandler(self, from_jid, to_jid, msg, _type, extra, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
534
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 687
diff changeset
535 if not from_jid in self.contact_list and from_jid.bare != self.profiles[profile]['whoami'].bare:
503
10119c2a9d33 Primitivus: new entities are added to contact list if they send messages + QuickFrontend: names fixes
Goffi <goffi@goffi.org>
parents: 501
diff changeset
536 #XXX: needed to show entities which haven't sent any
10119c2a9d33 Primitivus: new entities are added to contact list if they send messages + QuickFrontend: names fixes
Goffi <goffi@goffi.org>
parents: 501
diff changeset
537 # presence information and which are not in roster
1058
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1034
diff changeset
538 self.contact_list.replace(from_jid, [C.GROUP_NOT_IN_ROSTER])
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
539
1124
7ee18dbfb661 primitivus: improve the check to alert for new message
souliane <souliane@mailoo.org>
parents: 1119
diff changeset
540 if self.contact_list.selected is None or JID(self.contact_list.selected).bare != from_jid.bare:
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
541 self.contact_list.putAlert(from_jid)
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
542
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
543 def _dialogOkCb(self, widget, data):
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
544 self.removePopUp()
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
545 answer_cb = data[0]
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
546 answer_data = [data[1]] if data[1] else []
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
547 answer_cb(True, *answer_data)
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
548
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
549 def _dialogCancelCb(self, widget, data):
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
550 self.removePopUp()
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
551 answer_cb = data[0]
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
552 answer_data = [data[1]] if data[1] else []
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
553 answer_cb(False, *answer_data)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
554
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
555
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
556 def showDialog(self, message, title="", type_="info", answer_cb = None, answer_data = None):
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
557 if type_ == 'info':
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
558 popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
559 elif type_ == 'error':
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
560 popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
561 elif type_ == 'yes/no':
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
562 popup = sat_widgets.ConfirmDialog(unicode(message),
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
563 yes_cb=self._dialogOkCb, yes_value = (answer_cb, answer_data),
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
564 no_cb=self._dialogCancelCb, no_value = (answer_cb, answer_data))
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
565 else:
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
566 popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
567 log.error(_('unmanaged dialog type: %s'), type_)
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
568 self.showPopUp(popup)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
569
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
570 def onNotification(self, notif_bar):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
571 """Called when a new notification has been received"""
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
572 if not isinstance(self.main_widget, PrimitivusTopWidget):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
573 #if we are not in the main configuration, we ignore the notifications bar
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
574 return
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
575 if self.notif_bar.canHide():
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
576 #No notification left, we can hide the bar
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
577 self.main_widget.hide('notif_bar')
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
578 else:
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
579 self.main_widget.show('notif_bar')
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
580
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
581 def launchAction(self, callback_id, data=None, profile_key="@NONE@"):
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
582 """ Launch a dynamic action
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
583 @param callback_id: id of the action to launch
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
584 @param data: data needed only for certain actions
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
585 @param profile_key: %(doc_profile_key)s
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
586
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
587 """
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
588 if data is None:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
589 data = dict()
1019
6a16ec17a458 better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1010
diff changeset
590
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
591 def action_cb(data):
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
592 if not data:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
593 # action was a one shot, nothing to do
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
594 pass
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
595 elif "xmlui" in data:
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1103
diff changeset
596 ui = xmlui.create(self, xml_data=data['xmlui'])
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 799
diff changeset
597 ui.show()
1034
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1021
diff changeset
598 elif "authenticated_profile" in data:
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1021
diff changeset
599 assert("caller" in data)
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1021
diff changeset
600 if data["caller"] == "profile_manager":
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1021
diff changeset
601 assert(isinstance(self.main_widget, ProfileManager))
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1021
diff changeset
602 self.main_widget.getXMPPParams(data['authenticated_profile'])
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1021
diff changeset
603 elif data["caller"] == "plug_profile":
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1021
diff changeset
604 self.plug_profile_1(data['authenticated_profile'])
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1021
diff changeset
605 else:
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1021
diff changeset
606 raise NotImplementedError
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
607 else:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
608 self.showPopUp(sat_widgets.Alert(_("Error"), _(u"Unmanaged action result"), ok_cb=self.removePopUp))
1019
6a16ec17a458 better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1010
diff changeset
609
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
610 def action_eb(failure):
1063
6ec513ad92c2 frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents: 1060
diff changeset
611 self.showPopUp(sat_widgets.Alert(failure.fullname, failure.message, ok_cb=self.removePopUp))
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
612
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
613 self.bridge.launchAction(callback_id, data, profile_key, callback=action_cb, errback=action_eb)
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
614
1103
a096b8579a3c frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents: 1093
diff changeset
615 def askConfirmationHandler(self, confirmation_id, confirmation_type, data, profile):
542
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
616 answer_data={}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
617
542
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
618 def dir_selected_cb(path):
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
619 dest_path = join(path, data['filename'])
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
620 answer_data["dest_path"] = getNewPath(dest_path)
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
621 self.addProgress(confirmation_id, dest_path)
542
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
622 accept_cb(None)
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
623
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
624 def accept_file_transfer_cb(widget):
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
625 self.removePopUp()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
626 pop_up_widget = FileDialog(dir_selected_cb, refuse_cb, title=_(u"Where do you want to save the file ?"), style=['dir'])
542
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
627 self.showPopUp(pop_up_widget)
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
628
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
629 def accept_cb(widget):
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
630 self.removePopUp()
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
631 self.bridge.confirmationAnswer(confirmation_id, True, answer_data, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
632
542
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
633 def refuse_cb(widget):
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
634 self.removePopUp()
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
635 self.bridge.confirmationAnswer(confirmation_id, False, answer_data, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
636
542
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
637 if confirmation_type == "FILE_TRANSFER":
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
638 pop_up_widget = sat_widgets.ConfirmDialog(_("The contact %(jid)s wants to send you the file %(filename)s\nDo you accept ?") % {'jid':data["from"], 'filename':data["filename"]}, no_cb=refuse_cb, yes_cb=accept_file_transfer_cb)
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
639 self.showPopUp(pop_up_widget)
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
640
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
641 elif confirmation_type == "YES/NO":
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
642 pop_up_widget = sat_widgets.ConfirmDialog(data["message"], no_cb=refuse_cb, yes_cb=accept_cb)
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
643 self.showPopUp(pop_up_widget)
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 530
diff changeset
644
1103
a096b8579a3c frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents: 1093
diff changeset
645 def actionResultHandler(self, type_, id, data, profile):
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 804
diff changeset
646 # FIXME: to be removed
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
647
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
648 if not id in self.current_action_ids:
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
649 log.debug (_('unknown id, ignoring'))
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
650 return
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
651 if type_ == "SUPPRESS":
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
652 self.current_action_ids.remove(id)
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
653 elif type_ == "XMLUI":
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
654 self.current_action_ids.remove(id)
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
655 log.debug (_("XML user interface received"))
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
656 misc = {}
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
657 #FIXME FIXME FIXME: must clean all this crap !
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
658 title = _('Form')
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
659 if data['type'] == 'registration':
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
660 title = _('Registration')
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
661 misc['target'] = data['target']
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
662 misc['action_back'] = self.bridge.gatewayRegister
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1103
diff changeset
663 ui = xmlui.create(self, title=title, xml_data = data['xml'], misc = misc)
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
664 if data['type'] == 'registration':
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
665 ui.show('popup')
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
666 else:
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
667 ui.show('window')
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
668 elif type_ == "ERROR":
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
669 self.current_action_ids.remove(id)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
670 self.showPopUp(sat_widgets.Alert(_("Error"), unicode(data["message"]), ok_cb=self.removePopUp)) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
671 elif type_ == "RESULT":
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
672 self.current_action_ids.remove(id)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
673 if self.current_action_ids_cb.has_key(id):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
674 callback = self.current_action_ids_cb[id]
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
675 del self.current_action_ids_cb[id]
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
676 callback(data)
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
677 elif type_ == "DICT_DICT":
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
678 self.current_action_ids.remove(id)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
679 if self.current_action_ids_cb.has_key(id):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
680 callback = self.current_action_ids_cb[id]
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
681 del self.current_action_ids_cb[id]
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
682 callback(data)
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
683 else:
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
684 log.error (_("FIXME FIXME FIXME: type [%s] not implemented") % type_)
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
685 raise NotImplementedError
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
686
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
687 ##DIALOGS CALLBACKS##
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
688 def onJoinRoom(self, button, edit):
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
689 self.removePopUp()
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
690 room_jid = JID(edit.get_edit_text())
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
691 if room_jid.is_valid():
405
10b4f577d0c0 MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents: 382
diff changeset
692 self.bridge.joinMUC(room_jid, self.profiles[self.profile]['whoami'].node, {}, self.profile)
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
693 else:
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
694 message = _("'%s' is an invalid JID !") % room_jid
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
695 log.error (message)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
696 self.showPopUp(sat_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
697
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
698 #MENU EVENTS#
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
699 def onConnectRequest(self, menu):
1060
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1059
diff changeset
700 QuickApp.asyncConnect(self, self.profile)
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
701
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
702 def onDisconnectRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
703 self.bridge.disconnect(self.profile)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
704
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
705 def onParam(self, menu):
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
706 def success(params):
1185
6184779544c7 Primitivus (xmlui): fixed window closing on save params + removed now unused onConfigureRoom in Chat
Goffi <goffi@goffi.org>
parents: 1181
diff changeset
707 ui = xmlui.create(self, xml_data=params)
6184779544c7 Primitivus (xmlui): fixed window closing on save params + removed now unused onConfigureRoom in Chat
Goffi <goffi@goffi.org>
parents: 1181
diff changeset
708 ui.show()
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 776
diff changeset
709
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
710 def failure(error):
1063
6ec513ad92c2 frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents: 1060
diff changeset
711 self.showPopUp(sat_widgets.Alert(_("Error"), _("Can't get parameters (%s)") % error, ok_cb=self.removePopUp))
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
712 self.bridge.getParamsUI(app=C.APP_NAME, profile_key=self.profile, callback=success, errback=failure)
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
713
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
714 def onExitRequest(self, menu):
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
715 QuickApp.onExit(self)
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
716 raise urwid.ExitMainLoop()
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
717
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
718 def onJoinRoomRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
719 """User wants to join a MUC room"""
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
720 pop_up_widget = sat_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt = 'room@muc_service.server.tld', cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom)
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
721 self.showPopUp(pop_up_widget)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
722
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
723 def onAboutRequest(self, menu):
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
724 self.showPopUp(sat_widgets.Alert(_("About"), C.APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
725
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
726 #MISC CALLBACKS#
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
727
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
728 def setStatusOnline(self, online=True, show="", statuses={}):
850
30fd34309949 primitivus: displayed presence/status was not updated when the presence is "Online".
souliane <souliane@mailoo.org>
parents: 812
diff changeset
729 if not online or not statuses:
917
a9401694d2dc bridge, frontends: display presence with the highest priority + reset your own presence when you (dis)connect
souliane <souliane@mailoo.org>
parents: 913
diff changeset
730 self.status_bar.setPresenceStatus(show if online else 'unavailable', '')
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
731 return
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
732 try:
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
733 self.status_bar.setPresenceStatus(show, statuses['default'])
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
734 except (KeyError, TypeError):
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
735 pass
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
736
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
737 sat = PrimitivusApp()
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
738 sat.start()