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