Mercurial > libervia-backend
annotate frontends/primitivus/primitivus @ 204:b2e1a13ed596
misc minors fixed before release
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 20 Aug 2010 01:15:58 +0800 |
parents | 879beacb8e16 |
children | 783d6a61e0bd |
rev | line source |
---|---|
112 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Primitivus: a SAT frontend | |
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 | |
23 from quick_frontend.quick_app import QuickApp | |
24 from quick_frontend.quick_chat_list import QuickChatList | |
25 from quick_frontend.quick_contact_list import QuickContactList | |
26 from quick_frontend.quick_contact_management import QuickContactManagement | |
27 import urwid | |
28 from profile_manager import ProfileManager | |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
29 from contact_list import ContactList |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
30 from chat import Chat |
173 | 31 from gateways import GatewaysManager |
128
2240f34f6452
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
127
diff
changeset
|
32 import custom_widgets |
112 | 33 import logging |
34 from logging import debug, info, error | |
35 import sys, os | |
120 | 36 from tools.jid import JID |
153
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
37 from xmlui import XMLUI |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
38 from progress import Progress |
112 | 39 |
40 | |
41 ### logging configuration FIXME: put this elsewhere ### | |
42 logging.basicConfig(level=logging.CRITICAL, #TODO: configure it to put messages in a log file | |
43 format='%(message)s') | |
44 ### | |
45 | |
46 const_APP_NAME = "Primitivus" | |
113 | 47 const_PALETTE = [('title', 'black', 'light gray', 'standout,underline'), |
192
879beacb8e16
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
48 ('title_focus', 'white,bold', 'light gray', 'standout,underline'), |
113 | 49 ('selected', 'default', 'dark red'), |
50 ('selected_focus', 'default,bold', 'dark red'), | |
51 ('default', 'default', 'default'), | |
52 ('default_focus', 'default,bold', 'default'), | |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
53 ('alert', 'default,underline', 'default'), |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
54 ('alert_focus', 'default,bold,underline', 'default'), |
124 | 55 ('date', 'light gray', 'default'), |
56 ('my_nick', 'dark red,bold', 'default'), | |
57 ('other_nick', 'dark cyan,bold', 'default'), | |
128
2240f34f6452
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
127
diff
changeset
|
58 ('menubar', 'light gray,bold', 'dark red'), |
192
879beacb8e16
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
59 ('menubar_focus', 'light gray,bold', 'dark green'), |
131 | 60 ('selected_menu', 'light gray,bold', 'dark green'), |
61 ('menuitem', 'light gray,bold', 'dark red'), | |
62 ('menuitem_focus', 'light gray,bold', 'dark green'), | |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
63 ('notifs', 'black,bold', 'yellow'), |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
64 ('notifs_focus', 'dark red', 'yellow'), |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
65 ('card_neutral', 'dark gray', 'white', 'standout,underline'), |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
66 ('card_neutral_selected', 'dark gray', 'dark green', 'standout,underline'), |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
67 ('card_special', 'brown', 'white', 'standout,underline'), |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
68 ('card_special_selected', 'brown', 'dark green', 'standout,underline'), |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
69 ('card_red', 'dark red', 'white', 'standout,underline'), |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
70 ('card_red_selected', 'dark red', 'dark green', 'standout,underline'), |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
71 ('card_black', 'black', 'white', 'standout,underline'), |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
72 ('card_black_selected', 'black', 'dark green', 'standout,underline'), |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
73 ('directory', 'dark cyan, bold', 'default'), |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
74 ('directory_focus', 'dark cyan, bold', 'dark green'), |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
75 ('separator', 'brown', 'default'), |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
76 ('warning', 'light red', 'default'), |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
77 ('progress_normal', 'default', 'black'), |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
78 ('progress_complete', 'default', 'light red'), |
113 | 79 ] |
112 | 80 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
81 class ChatList(QuickChatList): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
82 """This class manage the list of chat windows""" |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
83 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
84 def __init__(self, host): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
85 QuickChatList.__init__(self, host) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
86 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
87 def createChat(self, target): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
88 return Chat(target, self.host) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
89 |
112 | 90 class PrimitivusApp(QuickApp): |
91 | |
92 def __init__(self): | |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
93 self.CM = QuickContactManagement() #FIXME: not the best place |
166
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
94 QuickApp.__init__(self) |
112 | 95 |
96 ## main loop setup ## | |
117 | 97 self.main_widget = ProfileManager(self) |
127
55d3ef84f01f
Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
98 self.loop = urwid.MainLoop(self.main_widget, const_PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler) |
112 | 99 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
100 ##misc setup## |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
101 self.chat_wins=ChatList(self) |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
102 self.notBar = custom_widgets.NotificationBar() |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
103 urwid.connect_signal(self.notBar,'change',self.onNotification) |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
104 self.progress_wid = Progress(self) |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
105 urwid.connect_signal(self.notBar.progress,'click',lambda x:self.addWindow(self.progress_wid)) |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
106 self.__saved_overlay = None |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
107 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
108 def debug(self): |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
109 """convenient method to reset screen and launch p(u)db""" |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
110 try: |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
111 import pudb |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
112 pudb.set_trace() |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
113 except: |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
114 import os,pdb |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
115 os.system('reset') |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
116 print 'Entered debug mode' |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
117 pdb.set_trace() |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
118 |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
119 def writeLog(self, log, file_name='/tmp/primitivus_log'): |
131 | 120 """method to write log in a temporary file, useful for debugging""" |
157
13888bdb72b6
primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
121 with open(file_name, 'a') as f: |
13888bdb72b6
primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
122 f.write(log+"\n") |
129
542682d67282
sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
123 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
124 def redraw(self): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
125 """redraw the screen""" |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
126 self.loop.draw_screen() |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
127 |
112 | 128 def start(self): |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
129 self.i = 0 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
130 self.loop.set_alarm_in(0,lambda a,b: self.postInit()) |
112 | 131 self.loop.run() |
132 | |
127
55d3ef84f01f
Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
133 def inputFilter(self, input, raw): |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
134 if self.__saved_overlay and input != ['ctrl s']: |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
135 return |
127
55d3ef84f01f
Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
136 for i in input: |
153
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
137 if isinstance(i,tuple): |
127
55d3ef84f01f
Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
138 if i[0] == 'mouse press': |
55d3ef84f01f
Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
139 if i[1] == 4: #Mouse wheel up |
55d3ef84f01f
Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
140 input[input.index(i)] = 'up' |
55d3ef84f01f
Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
141 if i[1] == 5: #Mouse wheel down |
55d3ef84f01f
Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
142 input[input.index(i)] = 'down' |
55d3ef84f01f
Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
143 return input |
55d3ef84f01f
Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
144 |
55d3ef84f01f
Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
145 def keyHandler(self, input): |
131 | 146 if input == 'meta m': |
181 | 147 """User want to (un)hide the menu roller""" |
128
2240f34f6452
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
127
diff
changeset
|
148 try: |
2240f34f6452
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
127
diff
changeset
|
149 if self.main_widget.header == None: |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
150 self.main_widget.header = self.menu_roller |
128
2240f34f6452
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
127
diff
changeset
|
151 else: |
2240f34f6452
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
127
diff
changeset
|
152 self.main_widget.header = None |
2240f34f6452
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
127
diff
changeset
|
153 except AttributeError: |
2240f34f6452
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
127
diff
changeset
|
154 pass |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
155 elif input == 'ctrl n': |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
156 """User wants to see next notification""" |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
157 self.notBar.showNext() |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
158 elif input == 'ctrl s': |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
159 """User wants to (un)hide overlay window""" |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
160 if isinstance(self.loop.widget,urwid.Overlay): |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
161 self.__saved_overlay = self.loop.widget |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
162 self.loop.widget = self.main_widget |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
163 else: |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
164 if self.__saved_overlay: |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
165 self.loop.widget = self.__saved_overlay |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
166 self.__saved_overlay = None |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
167 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
168 elif input == 'ctrl d' and 'D' in self.bridge.getVersion(): #Debug only for dev versions |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
169 self.debug() |
124 | 170 elif input == 'f2': #user wants to (un)hide the contact_list |
171 try: | |
172 center_widgets = self.center_part.widget_list | |
173 if self.contactList in center_widgets: | |
174 self.center_part.set_focus(0) #necessary as the focus change to the next object, we can go out of range if we are on the last object of self.center_part | |
175 center_widgets.remove(self.contactList) | |
176 del self.center_part.column_types[0] | |
177 else: | |
178 center_widgets.insert(0, self.contactList) | |
179 self.center_part.column_types.insert(0, ('weight', 2)) | |
180 except AttributeError: | |
181 #The main widget is not built (probably in Profile Manager) | |
182 pass | |
129
542682d67282
sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
183 elif input == 'window resize': |
542682d67282
sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
184 width,height = self.loop.screen_size |
542682d67282
sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
185 if height<=5 and width<=35: |
542682d67282
sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
186 if not 'save_main_widget' in dir(self): |
542682d67282
sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
187 self.save_main_widget = self.loop.widget |
542682d67282
sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
188 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
|
189 else: |
542682d67282
sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
190 if 'save_main_widget' in dir(self): |
542682d67282
sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
191 self.loop.widget = self.save_main_widget |
542682d67282
sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
192 del self.save_main_widget |
128
2240f34f6452
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
127
diff
changeset
|
193 try: |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
194 return self.menu_roller.checkShortcuts(input) |
128
2240f34f6452
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
127
diff
changeset
|
195 except AttributeError: |
2240f34f6452
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
127
diff
changeset
|
196 return input |
124 | 197 |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
198 def __buildMenuRoller(self): |
131 | 199 menu = custom_widgets.Menu(self.loop) |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
200 general = _("General") |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
201 menu.addMenu(general, _("Connect"), self.onConnectRequest) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
202 menu.addMenu(general, _("Disconnect"), self.onDisconnectRequest) |
166
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
203 menu.addMenu(general, _("Parameters"), self.onParam) |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
204 menu.addMenu(general, _("About"), self.onAboutRequest) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
205 menu.addMenu(general, _("Exit"), self.onExitRequest, 'ctrl x') |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
206 contact = _("Contact") |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
207 menu.addMenu(contact, _("Add contact"), self.onAddContactRequest) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
208 menu.addMenu(contact, _("Remove contact"), self.onRemoveContactRequest) |
131 | 209 communication = _("Communication") |
210 menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j') | |
173 | 211 menu.addMenu(communication, _("Find Gateways"), self.onFindGatewaysRequest, 'meta g') |
145
c8b231abfe96
Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
212 #additionals menus |
c8b231abfe96
Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
213 #FIXME: do this in a more generic way (in quickapp) |
c8b231abfe96
Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
214 add_menus = self.bridge.getMenus() |
c8b231abfe96
Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
215 def add_menu_cb(menu): |
c8b231abfe96
Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
216 category, item = menu |
c8b231abfe96
Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
217 id = self.bridge.callMenu(category, item, "NORMAL") |
c8b231abfe96
Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
218 self.current_action_ids.add(id) |
c8b231abfe96
Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
219 for new_menu in add_menus: |
c8b231abfe96
Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
220 category,item,type = new_menu |
c8b231abfe96
Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
221 assert(type=="NORMAL") #TODO: manage other types |
c8b231abfe96
Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
222 menu.addMenu(category, item, add_menu_cb) |
c8b231abfe96
Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
223 |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
224 menu_roller = custom_widgets.MenuRoller([(_('Main menu'),menu)]) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
225 return menu_roller |
131 | 226 |
112 | 227 def __buildMainWidget(self): |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
228 self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw()) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
229 #self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))]) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
230 self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))]) |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
231 self.editBar = custom_widgets.AdvancedEdit('> ') |
189 | 232 self.editBar.setCompletionMethod(self._nick_completion) |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
233 urwid.connect_signal(self.editBar,'click',self.onTextEntered) |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
234 self.menu_roller = self.__buildMenuRoller() |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
235 self.main_widget = custom_widgets.FocusFrame(self.center_part, header=self.menu_roller, footer=self.editBar, focus_part='footer') |
118
76055a209ed9
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
236 return self.main_widget |
112 | 237 |
189 | 238 def _nick_completion(self, text, completion_data): |
239 """Completion method which complete pseudo in group chat | |
240 for params, see AdvancedEdit""" | |
241 contact = self.contactList.get_contact() ###Based on the fact that there is currently only one contact selectableat once | |
242 if contact: | |
243 chat = self.chat_wins[contact] | |
244 if chat.type != "group": | |
245 return text | |
246 space = text.rfind(" ") | |
247 start = text[space+1:] | |
248 nicks = list(chat.occupants) | |
249 nicks.sort() | |
250 try: | |
251 start_idx=nicks.index(completion_data['last_nick'])+1 | |
252 if start_idx == len(nicks): | |
253 start_idx = 0 | |
254 except (KeyError,ValueError): | |
255 start_idx = 0 | |
256 for idx in range(start_idx,len(nicks)) + range(0,start_idx): | |
257 if nicks[idx].lower().startswith(start.lower()): | |
258 completion_data['last_nick'] = nicks[idx] | |
259 return text[:space+1] + nicks[idx] + (': ' if space < 0 else '') | |
260 return text | |
261 | |
262 | |
263 | |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
264 def plug_profile(self, profile_key='@DEFAULT@'): |
118
76055a209ed9
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
265 self.loop.widget = self.__buildMainWidget() |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
266 QuickApp.plug_profile(self, profile_key) |
117 | 267 |
120 | 268 def removePopUp(self, widget=None): |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
269 "Remove current pop-up, and if there is other in queue, show it" |
117 | 270 self.loop.widget = self.main_widget |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
271 next_popup = self.notBar.getNextPopup() |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
272 if next_popup: |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
273 #we still have popup to show, we display it |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
274 self.showPopUp(next_popup) |
117 | 275 |
176 | 276 def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40): |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
277 "Show a pop-up window if possible, else put it in queue" |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
278 if not isinstance(self.loop.widget,urwid.Overlay): |
176 | 279 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', perc_width), 'middle', ('relative', perc_height)) |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
280 self.loop.widget = display_widget |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
281 else: |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
282 self.notBar.addPopUp(pop_up_widget) |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
283 |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
284 def notify(self, message): |
166
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
285 """"Notify message to user via notification bar""" |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
286 self.notBar.addMessage(message) |
112 | 287 |
166
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
288 def addWindow(self, widget): |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
289 """Display a window if possible, |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
290 else add it in the notification bar queue |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
291 @param widget: BoxWidget""" |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
292 assert(len(self.center_part.widget_list)<=2) |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
293 wid_idx = len(self.center_part.widget_list)-1 |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
294 self.center_part.widget_list[wid_idx] = widget |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
295 self.menu_roller.removeMenu(_('Chat menu')) |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
296 self.contactList.unselectAll() |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
297 self.redraw() |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
298 |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
299 def removeWindow(self): |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
300 """Remove window showed on the right column""" |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
301 #TODO: to a better Window management than this crappy hack |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
302 assert(len(self.center_part.widget_list)<=2) |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
303 wid_idx = len(self.center_part.widget_list)-1 |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
304 self.center_part.widget_list[wid_idx] = urwid.Filler(urwid.Text('')) |
168 | 305 self.center_part.set_focus(0) |
166
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
306 self.redraw() |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
307 |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
308 def addProgress (self, id, message): |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
309 """Follow a SàT progress bar |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
310 @param id: SàT id of the progression |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
311 @param message: message to show to identify the progression""" |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
312 self.progress_wid.addProgress(id, message) |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
313 |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
314 def setProgress(self, percentage): |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
315 """Set the progression shown in notification bar""" |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
316 self.notBar.setProgress(percentage) |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
317 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
318 def contactSelected(self, contact_list): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
319 contact = contact_list.get_contact() |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
320 if contact: |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
321 assert(len(self.center_part.widget_list)==2) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
322 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
|
323 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
|
324 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
325 def onTextEntered(self, editBar): |
120 | 326 """Called when text is entered in the main edit bar""" |
327 contact = self.contactList.get_contact() ###Based on the fact that there is currently only one contact selectableat once | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
328 if contact: |
120 | 329 chat = self.chat_wins[contact] |
330 self.bridge.sendMessage(contact, | |
331 editBar.get_edit_text(), | |
332 type = "groupchat" if chat.type == 'group' else "chat", | |
333 profile_key=self.profile) | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
334 editBar.set_edit_text('') |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
335 |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
336 def newMessage(self, from_jid, msg, type, to_jid, profile): |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
337 if not self.check_profile(profile): |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
338 return |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
339 QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile) |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
340 sender = JID(from_jid) |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
341 if JID(self.contactList.selected).short != sender.short: |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
342 self.contactList.putAlert(sender) |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
343 |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 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
|
354 answer_cb(False, *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
|
355 |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
356 |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
357 def showDialog(self, message, title="", type="info", answer_cb = None, answer_data = None): |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
358 if type == 'info': |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
359 popup = custom_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 |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
360 flags = wx.OK | wx.ICON_INFORMATION |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
361 elif type == 'error': |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
362 popup = custom_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 |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
363 elif type == 'yes/no': |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
364 popup = custom_widgets.ConfirmDialog(unicode(message), |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
365 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
|
366 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
|
367 else: |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
368 popup = custom_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 |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
369 error(_('unmanaged dialog type: %s'), type) |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
370 self.showPopUp(popup) |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
371 |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
372 def onNotification(self, notBar): |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
373 """Called when a new notification has been received""" |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
374 if not isinstance(self.main_widget, custom_widgets.FocusFrame): |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
375 #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
|
376 return |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
377 if isinstance(self.main_widget.footer,custom_widgets.AdvancedEdit): |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
378 if not self.notBar.canHide(): |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
379 #the notification bar is not visible and has usefull informations, we show it |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
380 pile = urwid.Pile([self.notBar, self.editBar]) |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
381 self.main_widget.footer = pile |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
382 else: |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
383 if not isinstance(self.main_widget.footer, urwid.Pile): |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
384 error(_("INTERNAL ERROR: Unexpected class for main widget's footer")) |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
385 assert(False) |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
386 if self.notBar.canHide(): |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
387 #No notification left, we can hide the bar |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
388 self.main_widget.footer = self.editBar |
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
389 |
153
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
390 def actionResult(self, type, id, data): |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
391 if not id in self.current_action_ids: |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
392 debug (_('unknown id, ignoring')) |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
393 return |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
394 if type == "SUPPRESS": |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
395 self.current_action_ids.remove(id) |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
396 elif type == "XMLUI": |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
397 self.current_action_ids.remove(id) |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
398 debug (_("XML user interface received")) |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
399 misc = {} |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
400 #FIXME FIXME FIXME: must clean all this crap ! |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
401 title = _('Form') |
173 | 402 if data['type'] == 'registration': |
153
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
403 title = _('Registration') |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
404 misc['target'] = data['target'] |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
405 misc['action_back'] = self.bridge.gatewayRegister |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
406 ui = XMLUI(self, title=title, xml_data = data['xml'], misc = misc) |
173 | 407 if data['type'] == 'registration': |
408 ui.show('popup') | |
409 else: | |
410 ui.show('window') | |
411 elif type == "ERROR": | |
412 self.current_action_ids.remove(id) | |
413 self.showPopUp(custom_widgets.Alert(_("Error"), unicode(data["message"]), ok_cb=self.removePopUp)) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore | |
414 elif type == "RESULT": | |
415 self.current_action_ids.remove(id) | |
416 if self.current_action_ids_cb.has_key(id): | |
417 callback = self.current_action_ids_cb[id] | |
418 del self.current_action_ids_cb[id] | |
419 callback(data) | |
420 elif type == "DICT_DICT": | |
421 self.current_action_ids.remove(id) | |
422 if self.current_action_ids_cb.has_key(id): | |
423 callback = self.current_action_ids_cb[id] | |
424 del self.current_action_ids_cb[id] | |
425 callback(data) | |
153
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
426 else: |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
427 error (_("FIXME FIXME FIXME: type [%s] not implemented") % type) |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
428 raise NotImplementedError |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
429 |
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
430 ##DIALOGS CALLBACKS## |
120 | 431 def onJoinRoom(self, button, edit): |
432 self.removePopUp() | |
433 room_jid = JID(edit.get_edit_text()) | |
434 if room_jid.is_valid(): | |
435 self.bridge.joinMUC(room_jid.domain, room_jid.node, self.profiles[self.profile]['whoami'].node, self.profile) | |
436 else: | |
437 message = _("'%s' is an invalid JID !") % room_jid | |
438 error (message) | |
173 | 439 self.showPopUp(custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp)) |
120 | 440 |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
441 def onAddContact(self, button, edit): |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
442 self.removePopUp() |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
443 jid=JID(edit.get_edit_text()) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
444 if jid.is_valid(): |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
445 self.bridge.addContact(jid.short, profile_key=self.profile) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
446 else: |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
447 message = _("'%s' is an invalid JID !") % jid |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
448 error (message) |
173 | 449 self.showPopUp(custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp)) |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
450 |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
451 def onRemoveContact(self, button): |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
452 self.removePopUp() |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
453 info(_("Unsubscribing %s presence"),self.contactList.get_contact()) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
454 self.bridge.delContact(self.contactList.get_contact(), profile_key=self.profile) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
455 |
173 | 456 #MENU EVENTS# |
131 | 457 def onConnectRequest(self, menu): |
458 self.bridge.connect(self.profile) | |
459 | |
460 def onDisconnectRequest(self, menu): | |
461 self.bridge.disconnect(self.profile) | |
462 | |
166
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
463 def onParam(self, menu): |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
464 params = XMLUI(self,xml_data=self.bridge.getParamsUI(self.profile)) |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
465 self.addWindow(params) |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
466 |
131 | 467 def onExitRequest(self, menu): |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
468 QuickApp.onExit(self) |
131 | 469 raise urwid.ExitMainLoop() |
470 | |
471 def onJoinRoomRequest(self, menu): | |
472 """User wants to join a MUC room""" | |
204 | 473 pop_up_widget = custom_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 | 474 self.showPopUp(pop_up_widget) |
475 | |
173 | 476 def onFindGatewaysRequest(self, e): |
477 debug(_("Find Gateways request")) | |
478 id = self.bridge.findGateways(self.profiles[self.profile]['whoami'].domain, self.profile) | |
479 self.current_action_ids.add(id) | |
480 self.current_action_ids_cb[id] = self.onGatewaysFound | |
481 | |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
482 def onAddContactRequest(self, menu): |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
483 pop_up_widget = custom_widgets.InputDialog(_("Adding a contact"), _("Please enter new contact JID"), default_txt = 'name@server.tld', cancel_cb=self.removePopUp, ok_cb=self.onAddContact) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
484 self.showPopUp(pop_up_widget) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
485 |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
486 def onRemoveContactRequest(self, menu): |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
487 contact = self.contactList.get_contact() |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
488 if not contact: |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
489 self.showPopUp(custom_widgets.Alert(_("Error"), _("You have not selected any contact to delete !"), ok_cb=self.removePopUp)) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
490 else: |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
491 pop_up_widget = custom_widgets.ConfirmDialog(_("Are you sure you want to delete the contact [%s] ?" % contact), yes_cb=self.onRemoveContact, no_cb=self.removePopUp) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
492 self.showPopUp(pop_up_widget) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
493 |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
494 def onAboutRequest(self, menu): |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
495 self.showPopUp(custom_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp)) |
173 | 496 |
497 #MISC CALLBACKS# | |
498 | |
499 def onGatewaysFound(self, data): | |
500 """Called when SàT has found the server gateways""" | |
501 target = data['__private__']['target'] | |
502 del data['__private__'] | |
503 gatewayManager = GatewaysManager(self, data, server=target) | |
504 self.addWindow(gatewayManager) | |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
505 |
112 | 506 sat = PrimitivusApp() |
507 sat.start() | |
117 | 508 |