comparison frontends/src/wix/main_window.py @ 587:952322b1d490

Remove trailing whitespaces.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:34 +0100
parents ca13633d3b6b
children 84a6e83157c2
comparison
equal deleted inserted replaced
586:6a718ede8be1 587:952322b1d490
46 idJOIN_ROOM,\ 46 idJOIN_ROOM,\
47 idFIND_GATEWAYS = range(10) 47 idFIND_GATEWAYS = range(10)
48 48
49 class ChatList(QuickChatList): 49 class ChatList(QuickChatList):
50 """This class manage the list of chat windows""" 50 """This class manage the list of chat windows"""
51 51
52 def createChat(self, target): 52 def createChat(self, target):
53 return Chat(target, self.host) 53 return Chat(target, self.host)
54 54
55 class MainWindow(wx.Frame, QuickApp): 55 class MainWindow(wx.Frame, QuickApp):
56 """main app window""" 56 """main app window"""
57 57
58 def __init__(self): 58 def __init__(self):
59 QuickApp.__init__(self) 59 QuickApp.__init__(self)
60 wx.Frame.__init__(self,None, title="SàT Wix", size=(300,500)) 60 wx.Frame.__init__(self,None, title="SàT Wix", size=(300,500))
61 61
62 #sizer 62 #sizer
63 self.sizer = wx.BoxSizer(wx.VERTICAL) 63 self.sizer = wx.BoxSizer(wx.VERTICAL)
64 self.SetSizer(self.sizer) 64 self.SetSizer(self.sizer)
65 65
66 #Frame elements 66 #Frame elements
67 self.contact_list = ContactList(self, self) 67 self.contact_list = ContactList(self, self)
68 self.contact_list.registerActivatedCB(self.onContactActivated) 68 self.contact_list.registerActivatedCB(self.onContactActivated)
69 self.contact_list.Hide() 69 self.contact_list.Hide()
70 self.sizer.Add(self.contact_list, 1, flag=wx.EXPAND) 70 self.sizer.Add(self.contact_list, 1, flag=wx.EXPAND)
71 71
72 self.chat_wins=ChatList(self) 72 self.chat_wins=ChatList(self)
73 self.CreateStatusBar() 73 self.CreateStatusBar()
74 74
75 #ToolBar 75 #ToolBar
76 self.tools=self.CreateToolBar() 76 self.tools=self.CreateToolBar()
78 style=wx.CB_DROPDOWN | wx.CB_READONLY) 78 style=wx.CB_DROPDOWN | wx.CB_READONLY)
79 self.tools.AddControl(self.statusBox) 79 self.tools.AddControl(self.statusBox)
80 self.tools.AddSeparator() 80 self.tools.AddSeparator()
81 self.statusTxt=wx.TextCtrl(self.tools, -1, style = wx.TE_PROCESS_ENTER) 81 self.statusTxt=wx.TextCtrl(self.tools, -1, style = wx.TE_PROCESS_ENTER)
82 self.tools.AddControl(self.statusTxt) 82 self.tools.AddControl(self.statusTxt)
83 self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox) 83 self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox)
84 self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt) 84 self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt)
85 self.tools.Disable() 85 self.tools.Disable()
86 86
87 87
88 88
89 #tray icon 89 #tray icon
90 ticon = wx.Icon(os.path.join(self.media_dir, 'icons/crystal/tray_icon.xpm'), wx.BITMAP_TYPE_XPM) 90 ticon = wx.Icon(os.path.join(self.media_dir, 'icons/crystal/tray_icon.xpm'), wx.BITMAP_TYPE_XPM)
91 self.tray_icon = wx.TaskBarIcon() 91 self.tray_icon = wx.TaskBarIcon()
92 self.tray_icon.SetIcon(ticon, _("Wix jabber client")) 92 self.tray_icon.SetIcon(ticon, _("Wix jabber client"))
93 wx.EVT_TASKBAR_LEFT_UP(self.tray_icon, self.onTrayClick) 93 wx.EVT_TASKBAR_LEFT_UP(self.tray_icon, self.onTrayClick)
94 94
95 95
96 #events 96 #events
97 self.Bind(wx.EVT_CLOSE, self.onClose, self) 97 self.Bind(wx.EVT_CLOSE, self.onClose, self)
98 98
99 #menus 99 #menus
100 self.createMenus() 100 self.createMenus()
101 for i in range(self.menuBar.GetMenuCount()): 101 for i in range(self.menuBar.GetMenuCount()):
102 self.menuBar.EnableTop(i, False) 102 self.menuBar.EnableTop(i, False)
103 103
104 #profile panel 104 #profile panel
105 self.profile_pan = ProfileManager(self) 105 self.profile_pan = ProfileManager(self)
106 self.sizer.Add(self.profile_pan, 1, flag=wx.EXPAND) 106 self.sizer.Add(self.profile_pan, 1, flag=wx.EXPAND)
107 107
108 self.postInit() 108 self.postInit()
109 109
110 self.Show() 110 self.Show()
111 111
112 def plug_profile(self, profile_key='@DEFAULT@'): 112 def plug_profile(self, profile_key='@DEFAULT@'):
193 popup.SetSize( (sz.width+20, sz.height+20) ) 193 popup.SetSize( (sz.width+20, sz.height+20) )
194 x=(wx.DisplaySize()[0]-popup.GetSize()[0])/2 194 x=(wx.DisplaySize()[0]-popup.GetSize()[0])/2
195 popup.SetPosition((x,0)) 195 popup.SetPosition((x,0))
196 popup.Show() 196 popup.Show()
197 wx.CallLater(5000,popup.Destroy) 197 wx.CallLater(5000,popup.Destroy)
198 198
199 def showDialog(self, message, title="", type="info", answer_cb = None, answer_data = None): 199 def showDialog(self, message, title="", type="info", answer_cb = None, answer_data = None):
200 if type == 'info': 200 if type == 'info':
201 flags = wx.OK | wx.ICON_INFORMATION 201 flags = wx.OK | wx.ICON_INFORMATION
202 elif type == 'error': 202 elif type == 'error':
203 flags = wx.OK | wx.ICON_ERROR 203 flags = wx.OK | wx.ICON_ERROR
210 answer = dlg.ShowModal() 210 answer = dlg.ShowModal()
211 dlg.Destroy() 211 dlg.Destroy()
212 if answer_cb: 212 if answer_cb:
213 data = [answer_data] if answer_data else [] 213 data = [answer_data] if answer_data else []
214 answer_cb(True if (answer == wx.ID_YES or answer == wx.ID_OK) else False, *data) 214 answer_cb(True if (answer == wx.ID_YES or answer == wx.ID_OK) else False, *data)
215 215
216 def setStatusOnline(self, online=True): 216 def setStatusOnline(self, online=True):
217 """enable/disable controls, must be called when local user online status change""" 217 """enable/disable controls, must be called when local user online status change"""
218 if online: 218 if online:
219 self.SetStatusText(msgONLINE) 219 self.SetStatusText(msgONLINE)
220 self.tools.Enable() 220 self.tools.Enable()
239 if answer==wx.ID_YES: 239 if answer==wx.ID_YES:
240 filename = wx.FileSelector(_("Where do you want to save the file ?"), flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) 240 filename = wx.FileSelector(_("Where do you want to save the file ?"), flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
241 if filename: 241 if filename:
242 answer_data["dest_path"] = filename 242 answer_data["dest_path"] = filename
243 self.bridge.confirmationAnswer(confirmation_id, True, answer_data, profile) 243 self.bridge.confirmationAnswer(confirmation_id, True, answer_data, profile)
244 self.waitProgress(confirmation_id, _("File Transfer"), _("Copying %s") % os.path.basename(filename), profile) 244 self.waitProgress(confirmation_id, _("File Transfer"), _("Copying %s") % os.path.basename(filename), profile)
245 else: 245 else:
246 answer = wx.ID_NO 246 answer = wx.ID_NO
247 if answer==wx.ID_NO: 247 if answer==wx.ID_NO:
248 self.bridge.confirmationAnswer(confirmation_id, False, answer_data, profile) 248 self.bridge.confirmationAnswer(confirmation_id, False, answer_data, profile)
249 249
250 dlg.Destroy() 250 dlg.Destroy()
251 251
252 elif confirmation_type == "YES/NO": 252 elif confirmation_type == "YES/NO":
253 debug (_("Yes/No confirmation asked")) 253 debug (_("Yes/No confirmation asked"))
254 dlg = wx.MessageDialog(self, data["message"], 254 dlg = wx.MessageDialog(self, data["message"],
321 data = self.bridge.getProgress(progress_id, profile) 321 data = self.bridge.getProgress(progress_id, profile)
322 if data: 322 if data:
323 if not self.pbar: 323 if not self.pbar:
324 #first answer, we must construct the bar 324 #first answer, we must construct the bar
325 self.pbar = wx.ProgressDialog(title, message, float(data['size']), None, 325 self.pbar = wx.ProgressDialog(title, message, float(data['size']), None,
326 wx.PD_SMOOTH | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME) 326 wx.PD_SMOOTH | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME)
327 self.pbar.finish_value = float(data['size']) 327 self.pbar.finish_value = float(data['size'])
328 328
329 self.pbar.Update(int(data['position'])) 329 self.pbar.Update(int(data['position']))
330 elif self.pbar: 330 elif self.pbar:
331 self.pbar.Update(self.pbar.finish_value) 331 self.pbar.Update(self.pbar.finish_value)
332 return 332 return
333 333
334 wx.CallLater(10, self.progressCB, progress_id, title, message, profile) 334 wx.CallLater(10, self.progressCB, progress_id, title, message, profile)
335 335
336 def waitProgress (self, progress_id, title, message, profile): 336 def waitProgress (self, progress_id, title, message, profile):
337 self.pbar = None 337 self.pbar = None
338 wx.CallLater(10, self.progressCB, progress_id, title, message, profile) 338 wx.CallLater(10, self.progressCB, progress_id, title, message, profile)
339 339
340 340
341 341
342 ### events ### 342 ### events ###
343 343
344 def onContactActivated(self, jid): 344 def onContactActivated(self, jid):
345 debug (_("onContactActivated: %s"), jid) 345 debug (_("onContactActivated: %s"), jid)
386 386
387 wx.AboutBox(about) 387 wx.AboutBox(about)
388 388
389 def onExit(self, e): 389 def onExit(self, e):
390 self.Close() 390 self.Close()
391 391
392 def onAddContact(self, e): 392 def onAddContact(self, e):
393 debug(_("Add contact request")) 393 debug(_("Add contact request"))
394 dlg = wx.TextEntryDialog( 394 dlg = wx.TextEntryDialog(
395 self, _('Please enter new contact JID'), 395 self, _('Please enter new contact JID'),
396 _('Adding a contact'), _('name@server.tld')) 396 _('Adding a contact'), _('name@server.tld'))
437 wx.OK | wx.ICON_ERROR 437 wx.OK | wx.ICON_ERROR
438 ) 438 )
439 dlg.ShowModal() 439 dlg.ShowModal()
440 dlg.Destroy() 440 dlg.Destroy()
441 return 441 return
442 _id = self.bridge.getCard(target.short, profile_key=self.profile) 442 _id = self.bridge.getCard(target.short, profile_key=self.profile)
443 self.current_action_ids.add(_id) 443 self.current_action_ids.add(_id)
444 self.current_action_ids_cb[_id] = self.onProfileReceived 444 self.current_action_ids_cb[_id] = self.onProfileReceived
445 445
446 def onProfileReceived(self, data): 446 def onProfileReceived(self, data):
447 """Called when a profile is received""" 447 """Called when a profile is received"""
448 debug (_('Profile received: [%s]') % data) 448 debug (_('Profile received: [%s]') % data)
449 profile=Profile(self, data) 449 profile=Profile(self, data)
450 450
451 def onJoinRoom(self, e): 451 def onJoinRoom(self, e):
452 warning('FIXME: temporary menu, must be improved') 452 warning('FIXME: temporary menu, must be improved')
453 #TODO: a proper MUC room joining dialog with nickname etc 453 #TODO: a proper MUC room joining dialog with nickname etc
454 dlg = wx.TextEntryDialog( 454 dlg = wx.TextEntryDialog(
455 self, _("Please enter MUC's JID"), 455 self, _("Please enter MUC's JID"),
471 def onGatewaysFound(self, data): 471 def onGatewaysFound(self, data):
472 """Called when SàT has found the server gateways""" 472 """Called when SàT has found the server gateways"""
473 target = data['__private__']['target'] 473 target = data['__private__']['target']
474 del data['__private__'] 474 del data['__private__']
475 gatewayManager = GatewaysManager(self, data, server=target) 475 gatewayManager = GatewaysManager(self, data, server=target)
476 476
477 def onClose(self, e): 477 def onClose(self, e):
478 QuickApp.onExit(self) 478 QuickApp.onExit(self)
479 info(_("Exiting...")) 479 info(_("Exiting..."))
480 for win in self.chat_wins: 480 for win in self.chat_wins:
481 self.chat_wins[win].Destroy() 481 self.chat_wins[win].Destroy()
487 self.Hide() 487 self.Hide()
488 else: 488 else:
489 self.Show() 489 self.Show()
490 self.Raise() 490 self.Raise()
491 e.Skip() 491 e.Skip()
492 492