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