Mercurial > libervia-backend
annotate frontends/wix/main_window.py @ 86:4b5f2d55b6ac
wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 11 May 2010 13:06:05 +0930 |
parents | fc7583282d40 |
children | 23caf1051099 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 wix: a SAT frontend | |
57 | 6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) |
0 | 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 | |
70 | 23 from quick_frontend.quick_chat_list import QuickChatList |
24 from quick_frontend.quick_app import QuickApp | |
25 from quick_frontend.quick_contact_management import QuickContactManagement | |
0 | 26 import wx |
72 | 27 from contact_list import ContactList |
0 | 28 from chat import Chat |
81 | 29 from card_game import CardGame |
0 | 30 from param import Param |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
31 from form import Form |
28 | 32 from gateways import GatewaysManager |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
33 from profile import Profile |
68 | 34 from profile_manager import ProfileManager |
0 | 35 import gobject |
36 import os.path | |
37 import pdb | |
38 from tools.jid import JID | |
72 | 39 from logging import debug, info, warning, error |
40 import constants | |
0 | 41 |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
42 idCONNECT,\ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
43 idDISCONNECT,\ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
44 idEXIT,\ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
45 idPARAM,\ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
46 idADD_CONTACT,\ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
47 idREMOVE_CONTACT,\ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
48 idSHOW_PROFILE,\ |
72 | 49 idJOIN_ROOM,\ |
50 idFIND_GATEWAYS = range(9) | |
0 | 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 | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
58 def createChat(self, target): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
59 return Chat(target, self.host) |
0 | 60 |
61 class MainWindow(wx.Frame, QuickApp): | |
62 """main app window""" | |
63 | |
64 def __init__(self): | |
68 | 65 wx.Frame.__init__(self,None, title="SàT Wix", size=(300,500)) |
56 | 66 self.CM = QuickContactManagement() #FIXME: not the best place |
0 | 67 |
68 | 68 #sizer |
69 self.sizer = wx.BoxSizer(wx.VERTICAL) | |
70 self.SetSizer(self.sizer) | |
71 | |
0 | 72 #Frame elements |
72 | 73 self.contactList = ContactList(self, self) |
0 | 74 self.contactList.registerActivatedCB(self.onContactActivated) |
68 | 75 self.contactList.Hide() |
76 self.sizer.Add(self.contactList, 1, flag=wx.EXPAND) | |
77 | |
0 | 78 self.chat_wins=ChatList(self) |
79 self.CreateStatusBar() | |
80 self.createMenus() | |
68 | 81 for i in range(self.menuBar.GetMenuCount()): |
82 self.menuBar.EnableTop(i, False) | |
0 | 83 |
84 #ToolBar | |
85 self.tools=self.CreateToolBar() | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
86 self.statusBox = wx.ComboBox(self.tools, -1, "Online", choices=[status[1] for status in const_STATUS], |
0 | 87 style=wx.CB_DROPDOWN | wx.CB_READONLY) |
88 self.tools.AddControl(self.statusBox) | |
89 self.tools.AddSeparator() | |
90 self.statusTxt=wx.TextCtrl(self.tools, -1, style = wx.TE_PROCESS_ENTER) | |
91 self.tools.AddControl(self.statusTxt) | |
92 self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox) | |
93 self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt) | |
94 self.tools.Disable() | |
11 | 95 |
96 #tray icon | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
97 ticon = wx.Icon(IMAGE_DIR+'/crystal/tray_icon.xpm', wx.BITMAP_TYPE_XPM) |
11 | 98 self.tray_icon = wx.TaskBarIcon() |
70 | 99 self.tray_icon.SetIcon(ticon, _("Wix jabber client")) |
11 | 100 wx.EVT_TASKBAR_LEFT_UP(self.tray_icon, self.onTrayClick) |
101 | |
0 | 102 |
103 #events | |
104 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
105 | |
106 QuickApp.__init__(self) | |
68 | 107 #self.plug_profile() #gof: |
108 | |
109 #profile panel | |
110 self.profile_pan = ProfileManager(self) | |
111 #self.profile_pan.Hide() #gof: | |
112 self.sizer.Add(self.profile_pan, 1, flag=wx.EXPAND) | |
81 | 113 |
85 | 114 #Tarot = CardGame(self) |
115 #Tarot.Show()#gof: temp for test | |
81 | 116 |
0 | 117 self.Show() |
118 | |
68 | 119 def plug_profile(self, profile_key='@DEFAULT@'): |
120 """Hide profile panel then plug profile""" | |
121 self.profile_pan.Hide() | |
122 self.contactList.Show() | |
123 self.sizer.Layout() | |
124 for i in range(self.menuBar.GetMenuCount()): | |
125 self.menuBar.EnableTop(i, True) | |
126 super(MainWindow, self).plug_profile(profile_key) | |
127 if not self.bridge.isConnected(profile_key): | |
128 self.bridge.connect(profile_key) | |
129 | |
0 | 130 def createMenus(self): |
70 | 131 info(_("Creating menus")) |
0 | 132 connectMenu = wx.Menu() |
70 | 133 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server")) |
134 connectMenu.Append(idDISCONNECT, _("&Disconnect CTRL-d"),_(" Disconnect from the server")) | |
135 connectMenu.Append(idPARAM,_("&Parameters"),_(" Configure the program")) | |
0 | 136 connectMenu.AppendSeparator() |
70 | 137 connectMenu.Append(idEXIT,_("E&xit"),_(" Terminate the program")) |
0 | 138 contactMenu = wx.Menu() |
70 | 139 contactMenu.Append(idADD_CONTACT, _("&Add contact"),_(" Add a contact to your list")) |
140 contactMenu.Append(idREMOVE_CONTACT, _("&Remove contact"),_(" Remove the selected contact from your list")) | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
141 contactMenu.AppendSeparator() |
70 | 142 contactMenu.Append(idSHOW_PROFILE, _("&Show profile"), _(" Show contact's profile")) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
143 communicationMenu = wx.Menu() |
72 | 144 communicationMenu.Append(idJOIN_ROOM, _("&Join Room"),_(" Join a Multi-User Chat room")) |
70 | 145 communicationMenu.Append(idFIND_GATEWAYS, _("&Find Gateways"),_(" Find gateways to legacy IM")) |
68 | 146 self.menuBar = wx.MenuBar() |
70 | 147 self.menuBar.Append(connectMenu,_("&General")) |
148 self.menuBar.Append(contactMenu,_("&Contacts")) | |
149 self.menuBar.Append(communicationMenu,_("&Communication")) | |
68 | 150 self.SetMenuBar(self.menuBar) |
0 | 151 |
152 #events | |
153 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest) | |
1 | 154 wx.EVT_MENU(self, idDISCONNECT, self.onDisconnectRequest) |
0 | 155 wx.EVT_MENU(self, idPARAM, self.onParam) |
156 wx.EVT_MENU(self, idEXIT, self.onExit) | |
157 wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact) | |
158 wx.EVT_MENU(self, idREMOVE_CONTACT, self.onRemoveContact) | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
159 wx.EVT_MENU(self, idSHOW_PROFILE, self.onShowProfile) |
72 | 160 wx.EVT_MENU(self, idJOIN_ROOM, self.onJoinRoom) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
161 wx.EVT_MENU(self, idFIND_GATEWAYS, self.onFindGateways) |
0 | 162 |
163 | |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
164 def newMessage(self, from_jid, msg, type, to_jid, profile): |
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
165 QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile) |
0 | 166 |
72 | 167 def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile): |
168 super(MainWindow, self).roomJoined(room_id, room_service, room_nicks, user_nick, profile) | |
169 | |
0 | 170 def showAlert(self, message): |
171 # TODO: place this in a separate class | |
172 popup=wx.PopupWindow(self) | |
173 ### following code come from wxpython demo | |
174 popup.SetBackgroundColour("CADET BLUE") | |
175 st = wx.StaticText(popup, -1, message, pos=(10,10)) | |
176 sz = st.GetBestSize() | |
177 popup.SetSize( (sz.width+20, sz.height+20) ) | |
178 x=(wx.DisplaySize()[0]-popup.GetSize()[0])/2 | |
179 popup.SetPosition((x,0)) | |
180 popup.Show() | |
181 wx.CallLater(5000,popup.Destroy) | |
182 | |
183 def showDialog(self, message, title="", type="info"): | |
184 if type == 'info': | |
185 flags = wx.OK | wx.ICON_INFORMATION | |
186 elif type == 'error': | |
187 flags = wx.OK | wx.ICON_ERROR | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
188 elif type == 'yes/no': |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
189 flags = wx.YES_NO | wx.ICON_QUESTION |
0 | 190 else: |
191 flags = wx.OK | wx.ICON_INFORMATION | |
70 | 192 error(_('unmanaged dialog type: %s'), type) |
0 | 193 dlg = wx.MessageDialog(self, message, title, flags) |
194 answer = dlg.ShowModal() | |
195 dlg.Destroy() | |
196 return True if (answer == wx.ID_YES or answer == wx.ID_OK) else False | |
197 | |
198 def setStatusOnline(self, online=True): | |
199 """enable/disable controls, must be called when local user online status change""" | |
200 if online: | |
201 self.SetStatusText(msgONLINE) | |
202 self.tools.Enable() | |
203 else: | |
204 self.SetStatusText(msgOFFLINE) | |
205 self.tools.Disable() | |
206 return | |
207 | |
208 def askConfirmation(self, type, id, data): | |
209 #TODO: refactor this in QuickApp | |
70 | 210 debug (_("Confirmation asked")) |
0 | 211 answer_data={} |
212 if type == "FILE_TRANSFERT": | |
70 | 213 debug (_("File transfert confirmation asked")) |
214 dlg = wx.MessageDialog(self, _("The contact %(jid)s wants to send you the file %(filename)s\nDo you accept ?") % {'jid':data["from"], 'filename':data["filename"]}, | |
215 _('File Request'), | |
0 | 216 wx.YES_NO | wx.ICON_QUESTION |
217 ) | |
218 answer=dlg.ShowModal() | |
219 if answer==wx.ID_YES: | |
70 | 220 filename = wx.FileSelector(_("Where do you want to save the file ?"), flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) |
0 | 221 if filename: |
222 answer_data["dest_path"] = filename | |
223 self.bridge.confirmationAnswer(id, True, answer_data) | |
70 | 224 self.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename)) |
0 | 225 else: |
226 answer = wx.ID_NO | |
227 if answer==wx.ID_NO: | |
228 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
|
229 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
230 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
|
231 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
232 elif type == "YES/NO": |
70 | 233 debug (_("Yes/No confirmation asked")) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
234 dlg = wx.MessageDialog(self, data["message"], |
70 | 235 _('Confirmation'), |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
236 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
|
237 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
238 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
|
239 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
|
240 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
|
241 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
|
242 self.bridge.confirmationAnswer(id, False, {}) |
0 | 243 |
244 dlg.Destroy() | |
245 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
246 def actionResult(self, type, id, data): |
70 | 247 debug (_("actionResult: type = [%(type)s] id = [%(id)s] data = [%(data)s]") % {'type':type, 'id':id, 'data':data}) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
248 if not id in self.current_action_ids: |
70 | 249 debug (_('unknown id, ignoring')) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
250 return |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
251 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
|
252 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
|
253 elif type == "SUCCESS": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
254 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
|
255 dlg = wx.MessageDialog(self, data["message"], |
70 | 256 _('Success'), |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
257 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
|
258 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
259 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
|
260 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
|
261 elif type == "ERROR": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
262 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
|
263 dlg = wx.MessageDialog(self, data["message"], |
70 | 264 _('Error'), |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
265 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
|
266 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
267 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
|
268 dlg.Destroy() |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
269 elif type == "FORM": |
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
270 self.current_action_ids.remove(id) |
70 | 271 debug (_("Form received")) |
272 form=Form(self, title=_('Registration'), target = data['target'], type = data['type'], xml_data = data['xml']) | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
273 elif type == "RESULT": |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
274 self.current_action_ids.remove(id) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
275 if self.current_action_ids_cb.has_key(id): |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
276 callback = self.current_action_ids_cb[id] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
277 del self.current_action_ids_cb[id] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
278 callback(data) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
279 elif type == "DICT_DICT": |
28 | 280 self.current_action_ids.remove(id) |
281 if self.current_action_ids_cb.has_key(id): | |
282 callback = self.current_action_ids_cb[id] | |
283 del self.current_action_ids_cb[id] | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
284 callback(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
|
285 else: |
70 | 286 error (_("FIXME FIXME FIXME: type [%s] not implemented") % type) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
287 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
|
288 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
289 |
0 | 290 |
291 def progressCB(self, id, title, message): | |
292 data = self.bridge.getProgress(id) | |
293 if data: | |
294 if not data['position']: | |
295 data['position'] = '0' | |
296 if not self.pbar: | |
297 #first answer, we must construct the bar | |
298 self.pbar = wx.ProgressDialog(title, message, int(data['size']), None, | |
299 wx.PD_SMOOTH | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME) | |
300 self.pbar.finish_value = int(data['size']) | |
301 | |
302 self.pbar.Update(int(data['position'])) | |
303 elif self.pbar: | |
304 self.pbar.Update(self.pbar.finish_value) | |
305 return | |
306 | |
307 wx.CallLater(10, self.progressCB, id, title, message) | |
308 | |
309 def waitProgress (self, id, title, message): | |
310 self.pbar = None | |
311 wx.CallLater(10, self.progressCB, id, title, message) | |
312 | |
313 | |
314 | |
315 ### events ### | |
316 | |
317 def onContactActivated(self, jid): | |
70 | 318 debug (_("onContactActivated: %s"), jid) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
319 if self.chat_wins[jid.short].IsShown(): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
320 self.chat_wins[jid.short].Hide() |
0 | 321 else: |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
322 self.chat_wins[jid.short].Show() |
0 | 323 |
324 def onConnectRequest(self, e): | |
68 | 325 self.bridge.connect(self.profile) |
0 | 326 |
1 | 327 def onDisconnectRequest(self, e): |
68 | 328 self.bridge.disconnect(self.profile) |
1 | 329 |
0 | 330 def __updateStatus(self): |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
331 show = filter(lambda x:x[1] == self.statusBox.GetValue(), const_STATUS)[0][0] |
0 | 332 status = self.statusTxt.GetValue() |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
333 self.bridge.setPresence(show=show, statuses={'default':status}) #FIXME: manage multilingual statuses |
0 | 334 |
335 def onStatusChange(self, e): | |
70 | 336 debug(_("Status change request")) |
0 | 337 self.__updateStatus() |
338 | |
339 def onParam(self, e): | |
70 | 340 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
|
341 param=Param(self) |
0 | 342 |
343 def onExit(self, e): | |
344 self.Close() | |
345 | |
346 def onAddContact(self, e): | |
70 | 347 debug(_("Add contact request")) |
0 | 348 dlg = wx.TextEntryDialog( |
70 | 349 self, _('Please enter new contact JID'), |
350 _('Adding a contact'), _('name@server.tld')) | |
0 | 351 |
352 if dlg.ShowModal() == wx.ID_OK: | |
353 jid=JID(dlg.GetValue()) | |
354 if jid.is_valid(): | |
355 self.bridge.addContact(jid.short) | |
356 else: | |
70 | 357 error (_("'%s' is an invalid JID !"), jid) |
0 | 358 #TODO: notice the user |
359 | |
360 dlg.Destroy() | |
361 | |
362 def onRemoveContact(self, e): | |
70 | 363 debug(_("Remove contact request")) |
0 | 364 target = self.contactList.getSelection() |
365 if not target: | |
70 | 366 dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), |
367 _('Error'), | |
0 | 368 wx.OK | wx.ICON_ERROR |
369 ) | |
370 dlg.ShowModal() | |
371 dlg.Destroy() | |
372 return | |
373 | |
70 | 374 dlg = wx.MessageDialog(self, _("Are you sure you want to delete %s from your roster list ?") % target.short, |
375 _('Contact suppression'), | |
0 | 376 wx.YES_NO | wx.ICON_QUESTION |
377 ) | |
378 | |
379 if dlg.ShowModal() == wx.ID_YES: | |
70 | 380 info(_("Unsubscribing %s presence"), target.short) |
0 | 381 self.bridge.delContact(target.short) |
382 | |
383 dlg.Destroy() | |
384 | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
385 def onShowProfile(self, e): |
70 | 386 debug(_("Show contact's profile request")) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
387 target = self.contactList.getSelection() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
388 if not target: |
70 | 389 dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), |
390 _('Error'), | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
391 wx.OK | wx.ICON_ERROR |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
392 ) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
393 dlg.ShowModal() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
394 dlg.Destroy() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
395 return |
64 | 396 id = self.bridge.getCard(target.short) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
397 self.current_action_ids.add(id) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
398 self.current_action_ids_cb[id] = self.onProfileReceived |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
399 |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
400 def onProfileReceived(self, data): |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
401 """Called when a profile is received""" |
70 | 402 debug (_('Profile received: [%s]') % data) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
403 profile=Profile(self, data) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
404 |
72 | 405 def onJoinRoom(self, e): |
406 warning('FIXME: temporary menu, must be improved') | |
80
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
407 #TODO: a proper MUC room joining dialog with nickname etc |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
408 dlg = wx.TextEntryDialog( |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
409 self, _("Please enter MUC's JID"), |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
410 _('Entering a MUC room'), _('test@conference.necton2.int')) |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
411 #_('Entering a MUC room'), _('room@muc_service.server.tld')) |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
412 if dlg.ShowModal() == wx.ID_OK: |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
413 room_jid=JID(dlg.GetValue()) |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
414 if room_jid.is_valid(): |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
415 self.bridge.joinMUC(room_jid.domain, room_jid.node, self.profiles[self.profile]['whoami'].node, self.profile) |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
416 else: |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
417 error (_("'%s' is an invalid JID !"), room_jid) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
418 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
419 def onFindGateways(self, e): |
70 | 420 debug(_("Find Gateways request")) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
421 id = self.bridge.findGateways(self.profiles[self.profile]['whoami'].domain) |
28 | 422 self.current_action_ids.add(id) |
423 self.current_action_ids_cb[id] = self.onGatewaysFound | |
424 | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
425 def onGatewaysFound(self, data): |
28 | 426 """Called when SàT has found the server gateways""" |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
427 target = data['__private__']['target'] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
428 del data['__private__'] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
429 gatewayManager = GatewaysManager(self, data, server=target) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
430 |
0 | 431 def onClose(self, e): |
70 | 432 info(_("Exiting...")) |
0 | 433 e.Skip() |
11 | 434 |
435 def onTrayClick(self, e): | |
70 | 436 debug(_("Tray Click")) |
11 | 437 if self.IsShown(): |
438 self.Hide() | |
439 else: | |
440 self.Show() | |
441 self.Raise() | |
442 e.Skip() | |
0 | 443 |