Mercurial > libervia-backend
annotate frontends/wix/main_window.py @ 28:c2b131e4e262
wix: new gateways manager
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 06 Dec 2009 13:27:54 +0100 |
parents | 53e921c8a357 |
children | b9bb5d8e0cc7 |
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() |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
330 elif type == "DICT_DICT": |
28 | 331 self.current_action_ids.remove(id) |
332 if self.current_action_ids_cb.has_key(id): | |
333 callback = self.current_action_ids_cb[id] | |
334 del self.current_action_ids_cb[id] | |
335 callback(id,data) | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
336 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
|
337 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
338 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
|
339 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
|
340 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
341 |
0 | 342 |
343 def progressCB(self, id, title, message): | |
344 data = self.bridge.getProgress(id) | |
345 if data: | |
346 if not data['position']: | |
347 data['position'] = '0' | |
348 if not self.pbar: | |
349 #first answer, we must construct the bar | |
350 self.pbar = wx.ProgressDialog(title, message, int(data['size']), None, | |
351 wx.PD_SMOOTH | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME) | |
352 self.pbar.finish_value = int(data['size']) | |
353 | |
354 self.pbar.Update(int(data['position'])) | |
355 elif self.pbar: | |
356 self.pbar.Update(self.pbar.finish_value) | |
357 return | |
358 | |
359 wx.CallLater(10, self.progressCB, id, title, message) | |
360 | |
361 def waitProgress (self, id, title, message): | |
362 self.pbar = None | |
363 wx.CallLater(10, self.progressCB, id, title, message) | |
364 | |
365 | |
366 | |
367 ### events ### | |
368 | |
369 def onContactActivated(self, jid): | |
370 debug ("onContactActivated: %s", jid) | |
371 if self.chat_wins[jid].IsShown(): | |
372 self.chat_wins[jid].Hide() | |
373 else: | |
374 self.chat_wins[jid].Show() | |
375 | |
376 def onConnectRequest(self, e): | |
377 self.bridge.connect() | |
378 | |
1 | 379 def onDisconnectRequest(self, e): |
380 self.bridge.disconnect() | |
381 | |
0 | 382 def __updateStatus(self): |
383 show = const_STATUS[self.statusBox.GetValue()] | |
384 status = self.statusTxt.GetValue() | |
385 self.bridge.setPresence(show=show, status=status) | |
386 | |
387 def onStatusChange(self, e): | |
388 debug("Status change request") | |
389 self.__updateStatus() | |
390 | |
391 def onParam(self, e): | |
392 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
|
393 param=Param(self) |
0 | 394 |
395 def onExit(self, e): | |
396 self.Close() | |
397 | |
398 def onAddContact(self, e): | |
399 debug("Add contact request") | |
400 dlg = wx.TextEntryDialog( | |
401 self, 'Please enter new contact JID', | |
402 'Adding a contact', 'name@server.ext') | |
403 | |
404 if dlg.ShowModal() == wx.ID_OK: | |
405 jid=JID(dlg.GetValue()) | |
406 if jid.is_valid(): | |
407 self.bridge.addContact(jid.short) | |
408 else: | |
409 error ("'%s' is an invalid JID !", jid) | |
410 #TODO: notice the user | |
411 | |
412 dlg.Destroy() | |
413 | |
414 def onRemoveContact(self, e): | |
415 debug("Remove contact request") | |
416 target = self.contactList.getSelection() | |
417 if not target: | |
418 dlg = wx.MessageDialog(self, "You haven't selected any contact !", | |
419 'Error', | |
420 wx.OK | wx.ICON_ERROR | |
421 ) | |
422 dlg.ShowModal() | |
423 dlg.Destroy() | |
424 return | |
425 | |
426 dlg = wx.MessageDialog(self, "Are you sure you want to delete %s from your roster list ?" % target.short, | |
427 'Contact suppression', | |
428 wx.YES_NO | wx.ICON_QUESTION | |
429 ) | |
430 | |
431 if dlg.ShowModal() == wx.ID_YES: | |
432 info("Unsubsribing %s presence", target.short) | |
433 self.bridge.delContact(target.short) | |
434 | |
435 dlg.Destroy() | |
436 | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
437 def onFindGateways(self, e): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
438 debug("Find Gateways request") |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
439 id = self.bridge.findGateways(self.whoami.domain) |
28 | 440 self.current_action_ids.add(id) |
441 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
|
442 print "Find Gateways id=", id |
28 | 443 |
444 def onGatewaysFound(self, id, data): | |
445 """Called when SàT has found the server gateways""" | |
446 gatewayManager = GatewaysManager(self, data) | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
447 |
0 | 448 def onClose(self, e): |
449 info("Exiting...") | |
450 e.Skip() | |
11 | 451 |
452 def onTrayClick(self, e): | |
453 debug("Tray Click") | |
454 if self.IsShown(): | |
455 self.Hide() | |
456 else: | |
457 self.Show() | |
458 self.Raise() | |
459 e.Skip() | |
0 | 460 |