Mercurial > libervia-backend
annotate frontends/wix/main_window.py @ 33:b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 08 Dec 2009 09:54:44 +0100 |
parents | c2b131e4e262 |
children | c45deebb40a5 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 wix: a SAT frontend | |
6 Copyright (C) 2009 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 import wx | |
24 from chat import Chat | |
25 from param import Param | |
28 | 26 from gateways import GatewaysManager |
0 | 27 import gobject |
28 import os.path | |
29 import pdb | |
30 from tools.jid import JID | |
31 from logging import debug, info, error | |
32 from quick_frontend.quick_chat_list import QuickChatList | |
33 from quick_frontend.quick_contact_list import QuickContactList | |
34 from quick_frontend.quick_app import QuickApp | |
35 | |
36 | |
37 msgOFFLINE = "offline" | |
38 msgONLINE = "online" | |
39 idCONNECT = 1 | |
1 | 40 idDISCONNECT = 2 |
41 idEXIT = 3 | |
42 idPARAM = 4 | |
43 idADD_CONTACT = 5 | |
44 idREMOVE_CONTACT = 6 | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
45 idFIND_GATEWAYS = 7 |
0 | 46 const_DEFAULT_GROUP = "Unclassed" |
47 const_STATUS = {"Online":"", | |
48 "Want to discuss":"chat", | |
49 "AFK":"away", | |
50 "Do Not Disturb":"dnd", | |
51 "Away":"xa"} | |
52 | |
53 class ChatList(QuickChatList): | |
54 """This class manage the list of chat windows""" | |
55 | |
56 def __init__(self, host): | |
57 QuickChatList.__init__(self, host) | |
58 | |
59 def createChat(self, name): | |
60 return Chat(name, self.host) | |
61 | |
62 | |
63 | |
64 class ContactList(wx.TreeCtrl, QuickContactList): | |
65 """Customized control to manage contacts.""" | |
66 | |
67 def __init__(self, parent): | |
68 wx.TreeCtrl.__init__(self, parent, style = wx.TR_HIDE_ROOT | wx.TR_HAS_BUTTONS) | |
69 QuickContactList.__init__(self) | |
70 self.jid_ids={} | |
71 self.groups={} | |
72 self.root=self.AddRoot("") | |
73 self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.onActivated, self) | |
74 | |
75 #icons | |
76 isz = (16,16) | |
77 il = wx.ImageList(isz[0], isz[1]) | |
78 self.icon_online = il.Add(wx.ArtProvider_GetBitmap(wx.ART_TICK_MARK, wx.ART_OTHER, isz)) | |
79 self.icon_unavailable = il.Add(wx.ArtProvider_GetBitmap(wx.ART_CROSS_MARK, wx.ART_OTHER, isz)) | |
80 self.AssignImageList(il) | |
81 | |
82 self.__addNode(const_DEFAULT_GROUP) | |
83 | |
84 def __addNode(self, label): | |
85 """Add an item container""" | |
86 ret=self.AppendItem(self.root, label) | |
87 self.SetPyData(ret, "[node]") | |
88 self.SetItemBold(ret) | |
89 self.groups[label]=ret | |
90 | |
91 def replace(self, jid, name="", show="", status="", group=""): | |
92 debug("status = %s show = %s",status, show) | |
93 if not self.jid_ids.has_key(jid): | |
94 self.add(jid, name, show, status, group) | |
95 else: | |
96 debug ("updating %s",jid) | |
97 self.__presentItem(jid, name, show, status, group) | |
98 | |
99 def __presentItem(self, jid, name, show, status, group): | |
100 """Make a nice presentation of the contact in the list.""" | |
101 id=self.jid_ids[jid] | |
102 label= "%s [%s] \n %s" % ((name or jid), (show or "online"), status) | |
103 self.SetItemText(id, label) | |
104 | |
105 # icon | |
106 if not show or show=="chat": | |
107 self.SetItemImage(id, self.icon_online) | |
108 else: | |
109 self.SetItemImage(id, self.icon_unavailable) | |
110 | |
111 #colour | |
112 if not show: | |
113 self.SetItemTextColour(id, wx.BLACK) | |
114 elif show=="chat": | |
115 self.SetItemTextColour(id, wx.GREEN) | |
116 elif show=="away": | |
117 self.SetItemTextColour(id, wx.BLUE) | |
118 else: | |
119 self.SetItemTextColour(id, wx.RED) | |
120 | |
121 def add(self, jid, name="", show="", status="", group=""): | |
122 """add a contact to the list""" | |
123 debug ("adding %s",jid) | |
124 dest_group=group or const_DEFAULT_GROUP | |
125 if not self.groups.has_key(dest_group): | |
126 self.__addNode(dest_group) | |
127 self.jid_ids[jid]=self.AppendItem(self.groups[dest_group], "") | |
128 self.__presentItem(jid, name, show, status, group) | |
129 self.SetPyData(self.jid_ids[jid], "[contact]"+jid) | |
130 self.EnsureVisible(self.jid_ids[jid]) | |
131 self.Refresh() #FIXME: Best way ? | |
132 | |
133 def remove(self, jid): | |
134 """remove a contact from the list""" | |
135 debug ("removing %s",jid) | |
136 self.Delete(self.jid_ids[jid]) | |
137 del self.jid_ids[jid] | |
138 self.Refresh() #FIXME: Best way ? | |
139 | |
140 def onActivated(self, event): | |
141 """Called when a contact is clicked or activated with keyboard.""" | |
142 if self.GetPyData(event.GetItem()).startswith("[contact]"): | |
143 self.onActivatedCB(self.GetPyData(event.GetItem())[9:]) | |
144 else: | |
145 event.Skip() | |
146 | |
147 def getSelection(self): | |
148 """Return the selected contact, or an empty string if there is not""" | |
149 data = self.GetPyData(self.GetSelection()) | |
150 if not data or not data.startswith("[contact]"): | |
151 return "" | |
152 return JID(data[9:]) | |
153 | |
154 def registerActivatedCB(self, cb): | |
155 """Register a callback with manage contact activation.""" | |
156 self.onActivatedCB=cb | |
157 | |
158 class MainWindow(wx.Frame, QuickApp): | |
159 """main app window""" | |
160 | |
161 def __init__(self): | |
162 wx.Frame.__init__(self,None, title="SAT Wix", size=(400,200)) | |
163 | |
164 | |
165 #Frame elements | |
166 self.contactList = ContactList(self) | |
167 self.contactList.registerActivatedCB(self.onContactActivated) | |
168 self.chat_wins=ChatList(self) | |
169 self.CreateStatusBar() | |
170 self.SetStatusText(msgOFFLINE) | |
171 self.createMenus() | |
172 | |
173 #ToolBar | |
174 self.tools=self.CreateToolBar() | |
175 self.statusBox = wx.ComboBox(self.tools, -1, "Online", choices=const_STATUS.keys(), | |
176 style=wx.CB_DROPDOWN | wx.CB_READONLY) | |
177 self.tools.AddControl(self.statusBox) | |
178 self.tools.AddSeparator() | |
179 self.statusTxt=wx.TextCtrl(self.tools, -1, style = wx.TE_PROCESS_ENTER) | |
180 self.tools.AddControl(self.statusTxt) | |
181 self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox) | |
182 self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt) | |
183 self.tools.Disable() | |
11 | 184 |
185 #tray icon | |
186 ticon = wx.Icon("images/tray_icon.xpm", wx.BITMAP_TYPE_XPM) | |
187 self.tray_icon = wx.TaskBarIcon() | |
188 self.tray_icon.SetIcon(ticon, "Wix jabber client") | |
189 wx.EVT_TASKBAR_LEFT_UP(self.tray_icon, self.onTrayClick) | |
190 | |
0 | 191 |
192 #events | |
193 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
194 | |
195 QuickApp.__init__(self) | |
196 | |
197 self.Show() | |
198 | |
199 def createMenus(self): | |
200 info("Creating menus") | |
201 connectMenu = wx.Menu() | |
202 connectMenu.Append(idCONNECT, "&Connect CTRL-c"," Connect to the server") | |
1 | 203 connectMenu.Append(idDISCONNECT, "&Disconnect CTRL-d"," Disconnect from the server") |
0 | 204 connectMenu.Append(idPARAM,"&Parameters"," Configure the program") |
205 connectMenu.AppendSeparator() | |
206 connectMenu.Append(idEXIT,"E&xit"," Terminate the program") | |
207 contactMenu = wx.Menu() | |
208 contactMenu.Append(idADD_CONTACT, "&Add contact"," Add a contact to your list") | |
209 contactMenu.Append(idREMOVE_CONTACT, "&Remove contact"," Remove the selected contact from your list") | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
210 communicationMenu = wx.Menu() |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
211 communicationMenu.Append(idFIND_GATEWAYS, "&Find Gateways"," Find gateways to legacy IM") |
0 | 212 menuBar = wx.MenuBar() |
213 menuBar.Append(connectMenu,"&General") | |
214 menuBar.Append(contactMenu,"&Contacts") | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
215 menuBar.Append(communicationMenu,"&Communication") |
0 | 216 self.SetMenuBar(menuBar) |
217 | |
218 #events | |
219 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest) | |
1 | 220 wx.EVT_MENU(self, idDISCONNECT, self.onDisconnectRequest) |
0 | 221 wx.EVT_MENU(self, idPARAM, self.onParam) |
222 wx.EVT_MENU(self, idEXIT, self.onExit) | |
223 wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact) | |
224 wx.EVT_MENU(self, idREMOVE_CONTACT, self.onRemoveContact) | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
225 wx.EVT_MENU(self, idFIND_GATEWAYS, self.onFindGateways) |
0 | 226 |
227 | |
228 def newMessage(self, from_jid, msg, type, to_jid): | |
229 QuickApp.newMessage(self, from_jid, msg, type, to_jid) | |
230 | |
231 def showAlert(self, message): | |
232 # TODO: place this in a separate class | |
233 popup=wx.PopupWindow(self) | |
234 ### following code come from wxpython demo | |
235 popup.SetBackgroundColour("CADET BLUE") | |
236 st = wx.StaticText(popup, -1, message, pos=(10,10)) | |
237 sz = st.GetBestSize() | |
238 popup.SetSize( (sz.width+20, sz.height+20) ) | |
239 x=(wx.DisplaySize()[0]-popup.GetSize()[0])/2 | |
240 popup.SetPosition((x,0)) | |
241 popup.Show() | |
242 wx.CallLater(5000,popup.Destroy) | |
243 | |
244 def showDialog(self, message, title="", type="info"): | |
245 if type == 'info': | |
246 flags = wx.OK | wx.ICON_INFORMATION | |
247 elif type == 'error': | |
248 flags = wx.OK | wx.ICON_ERROR | |
249 elif type == 'question': | |
250 flags = wx.OK | wx.ICON_QUESTION | |
251 else: | |
252 flags = wx.OK | wx.ICON_INFORMATION | |
253 dlg = wx.MessageDialog(self, message, title, flags) | |
254 answer = dlg.ShowModal() | |
255 dlg.Destroy() | |
256 return True if (answer == wx.ID_YES or answer == wx.ID_OK) else False | |
257 | |
258 def setStatusOnline(self, online=True): | |
259 """enable/disable controls, must be called when local user online status change""" | |
260 if online: | |
261 self.SetStatusText(msgONLINE) | |
262 self.tools.Enable() | |
263 else: | |
264 self.SetStatusText(msgOFFLINE) | |
265 self.tools.Disable() | |
266 return | |
267 | |
268 | |
269 def presenceUpdate(self, jabber_id, type, show, status, priority): | |
270 QuickApp.presenceUpdate(self, jabber_id, type, show, status, priority) | |
271 | |
272 def askConfirmation(self, type, id, data): | |
273 #TODO: refactor this in QuickApp | |
274 debug ("Confirmation asked") | |
275 answer_data={} | |
276 if type == "FILE_TRANSFERT": | |
277 debug ("File transfert confirmation asked") | |
278 dlg = wx.MessageDialog(self, "The contact %s wants to send you the file %s\nDo you accept ?" % (data["from"], data["filename"]), | |
279 'File Request', | |
280 wx.YES_NO | wx.ICON_QUESTION | |
281 ) | |
282 answer=dlg.ShowModal() | |
283 if answer==wx.ID_YES: | |
284 filename = wx.FileSelector("Where do you want to save the file ?", flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) | |
285 if filename: | |
286 answer_data["dest_path"] = filename | |
287 self.bridge.confirmationAnswer(id, True, answer_data) | |
288 self.waitProgress(id, "File Transfer", "Copying %s" % os.path.basename(filename)) | |
289 else: | |
290 answer = wx.ID_NO | |
291 if answer==wx.ID_NO: | |
292 self.bridge.confirmationAnswer(id, False, answer_data) | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
293 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
294 dlg.Destroy() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
295 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
296 elif type == "YES/NO": |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
297 debug ("Yes/No confirmation asked") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
298 dlg = wx.MessageDialog(self, data["message"], |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
299 'Confirmation', |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
300 wx.YES_NO | wx.ICON_QUESTION |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
301 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
302 answer=dlg.ShowModal() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
303 if answer==wx.ID_YES: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
304 self.bridge.confirmationAnswer(id, True, {}) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
305 if answer==wx.ID_NO: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
306 self.bridge.confirmationAnswer(id, False, {}) |
0 | 307 |
308 dlg.Destroy() | |
309 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
310 def actionResult(self, type, id, data): |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
311 debug ("actionResult: type = [%s] id = [%s] data = [%s]" % (type, id, data)) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
312 if type == "SUPPRESS": |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
313 self.current_action_ids.remove(id) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
314 elif type == "SUCCESS": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
315 self.current_action_ids.remove(id) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
316 dlg = wx.MessageDialog(self, data["message"], |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
317 'Success', |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
318 wx.OK | wx.ICON_INFORMATION |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
319 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
320 dlg.ShowModal() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
321 dlg.Destroy() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
322 elif type == "ERROR": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
323 self.current_action_ids.remove(id) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
324 dlg = wx.MessageDialog(self, data["message"], |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
325 'Error', |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
326 wx.OK | wx.ICON_ERROR |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
327 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
328 dlg.ShowModal() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
329 dlg.Destroy() |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
330 elif type == "FORM": |
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
331 self.current_action_ids.remove(id) |
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
332 info ("Form received !") |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
333 elif type == "DICT_DICT": |
28 | 334 self.current_action_ids.remove(id) |
335 if self.current_action_ids_cb.has_key(id): | |
336 callback = self.current_action_ids_cb[id] | |
337 del self.current_action_ids_cb[id] | |
338 callback(id,data) | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
339 print ("Dict of dict found as result") |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
340 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
341 error ("FIXME FIXME FIXME: type [%s] not implemented" % type) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
342 raise NotImplementedError |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
343 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
344 |
0 | 345 |
346 def progressCB(self, id, title, message): | |
347 data = self.bridge.getProgress(id) | |
348 if data: | |
349 if not data['position']: | |
350 data['position'] = '0' | |
351 if not self.pbar: | |
352 #first answer, we must construct the bar | |
353 self.pbar = wx.ProgressDialog(title, message, int(data['size']), None, | |
354 wx.PD_SMOOTH | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME) | |
355 self.pbar.finish_value = int(data['size']) | |
356 | |
357 self.pbar.Update(int(data['position'])) | |
358 elif self.pbar: | |
359 self.pbar.Update(self.pbar.finish_value) | |
360 return | |
361 | |
362 wx.CallLater(10, self.progressCB, id, title, message) | |
363 | |
364 def waitProgress (self, id, title, message): | |
365 self.pbar = None | |
366 wx.CallLater(10, self.progressCB, id, title, message) | |
367 | |
368 | |
369 | |
370 ### events ### | |
371 | |
372 def onContactActivated(self, jid): | |
373 debug ("onContactActivated: %s", jid) | |
374 if self.chat_wins[jid].IsShown(): | |
375 self.chat_wins[jid].Hide() | |
376 else: | |
377 self.chat_wins[jid].Show() | |
378 | |
379 def onConnectRequest(self, e): | |
380 self.bridge.connect() | |
381 | |
1 | 382 def onDisconnectRequest(self, e): |
383 self.bridge.disconnect() | |
384 | |
0 | 385 def __updateStatus(self): |
386 show = const_STATUS[self.statusBox.GetValue()] | |
387 status = self.statusTxt.GetValue() | |
388 self.bridge.setPresence(show=show, status=status) | |
389 | |
390 def onStatusChange(self, e): | |
391 debug("Status change request") | |
392 self.__updateStatus() | |
393 | |
394 def onParam(self, e): | |
395 debug("Param request") | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
396 param=Param(self) |
0 | 397 |
398 def onExit(self, e): | |
399 self.Close() | |
400 | |
401 def onAddContact(self, e): | |
402 debug("Add contact request") | |
403 dlg = wx.TextEntryDialog( | |
404 self, 'Please enter new contact JID', | |
405 'Adding a contact', 'name@server.ext') | |
406 | |
407 if dlg.ShowModal() == wx.ID_OK: | |
408 jid=JID(dlg.GetValue()) | |
409 if jid.is_valid(): | |
410 self.bridge.addContact(jid.short) | |
411 else: | |
412 error ("'%s' is an invalid JID !", jid) | |
413 #TODO: notice the user | |
414 | |
415 dlg.Destroy() | |
416 | |
417 def onRemoveContact(self, e): | |
418 debug("Remove contact request") | |
419 target = self.contactList.getSelection() | |
420 if not target: | |
421 dlg = wx.MessageDialog(self, "You haven't selected any contact !", | |
422 'Error', | |
423 wx.OK | wx.ICON_ERROR | |
424 ) | |
425 dlg.ShowModal() | |
426 dlg.Destroy() | |
427 return | |
428 | |
429 dlg = wx.MessageDialog(self, "Are you sure you want to delete %s from your roster list ?" % target.short, | |
430 'Contact suppression', | |
431 wx.YES_NO | wx.ICON_QUESTION | |
432 ) | |
433 | |
434 if dlg.ShowModal() == wx.ID_YES: | |
435 info("Unsubsribing %s presence", target.short) | |
436 self.bridge.delContact(target.short) | |
437 | |
438 dlg.Destroy() | |
439 | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
440 def onFindGateways(self, e): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
441 debug("Find Gateways request") |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
442 id = self.bridge.findGateways(self.whoami.domain) |
28 | 443 self.current_action_ids.add(id) |
444 self.current_action_ids_cb[id] = self.onGatewaysFound | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
445 print "Find Gateways id=", id |
28 | 446 |
447 def onGatewaysFound(self, id, data): | |
448 """Called when SàT has found the server gateways""" | |
449 gatewayManager = GatewaysManager(self, data) | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
450 |
0 | 451 def onClose(self, e): |
452 info("Exiting...") | |
453 e.Skip() | |
11 | 454 |
455 def onTrayClick(self, e): | |
456 debug("Tray Click") | |
457 if self.IsShown(): | |
458 self.Hide() | |
459 else: | |
460 self.Show() | |
461 self.Raise() | |
462 e.Skip() | |
0 | 463 |