comparison frontends/src/wix/main_window.py @ 737:378af36155c2

frontends: set and retrieve your own presence and status
author souliane <souliane@mailoo.org>
date Mon, 25 Nov 2013 01:56:07 +0100
parents 6246eb6d64a0
children e3ad48a2aab2
comparison
equal deleted inserted replaced
736:6246eb6d64a0 737:378af36155c2
74 self.tools=self.CreateToolBar() 74 self.tools=self.CreateToolBar()
75 self.statusBox = wx.ComboBox(self.tools, -1, "Online", choices=[status[1] for status in Const.PRESENCE], 75 self.statusBox = wx.ComboBox(self.tools, -1, "Online", choices=[status[1] for status in Const.PRESENCE],
76 style=wx.CB_DROPDOWN | wx.CB_READONLY) 76 style=wx.CB_DROPDOWN | wx.CB_READONLY)
77 self.tools.AddControl(self.statusBox) 77 self.tools.AddControl(self.statusBox)
78 self.tools.AddSeparator() 78 self.tools.AddSeparator()
79 self.statusTxt=wx.TextCtrl(self.tools, -1, style = wx.TE_PROCESS_ENTER) 79 self.statusTxt = wx.TextCtrl(self.tools, -1, style=wx.TE_PROCESS_ENTER)
80 self.tools.AddControl(self.statusTxt) 80 self.tools.AddControl(self.statusTxt)
81 self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox) 81 self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox)
82 self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt) 82 self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt)
83 self.tools.Disable() 83 self.tools.Disable()
84 84
207 dlg.Destroy() 207 dlg.Destroy()
208 if answer_cb: 208 if answer_cb:
209 data = [answer_data] if answer_data else [] 209 data = [answer_data] if answer_data else []
210 answer_cb(True if (answer == wx.ID_YES or answer == wx.ID_OK) else False, *data) 210 answer_cb(True if (answer == wx.ID_YES or answer == wx.ID_OK) else False, *data)
211 211
212 def setStatusOnline(self, online=True): 212 def setStatusOnline(self, online=True, show="", statuses={}):
213 """enable/disable controls, must be called when local user online status change""" 213 """enable/disable controls, must be called when local user online status change"""
214 if online: 214 if online:
215 self.SetStatusText(Const.msgONLINE) 215 self.SetStatusText(Const.msgONLINE)
216 self.tools.Enable() 216 self.tools.Enable()
217 try:
218 presence = [x for x in Const.PRESENCE if x[0] == show][0][1]
219 self.statusBox.SetValue(presence)
220 except (TypeError, IndexError):
221 pass
222 try:
223 self.statusTxt.SetValue(statuses['default'])
224 except (TypeError, KeyError):
225 pass
217 else: 226 else:
218 self.SetStatusText(Const.msgOFFLINE) 227 self.SetStatusText(Const.msgOFFLINE)
219 self.tools.Disable() 228 self.tools.Disable()
220 return 229 return
221 230
349 358
350 def onDisconnectRequest(self, e): 359 def onDisconnectRequest(self, e):
351 self.bridge.disconnect(self.profile) 360 self.bridge.disconnect(self.profile)
352 361
353 def __updateStatus(self): 362 def __updateStatus(self):
354 show = filter(lambda x:x[1] == self.statusBox.GetValue(), Const.PRESENCE)[0][0] 363 show = [x for x in Const.PRESENCE if x[1] == self.statusBox.GetValue()][0][0]
355 status = self.statusTxt.GetValue() 364 status = self.statusTxt.GetValue()
356 self.bridge.setPresence(show=show, statuses={'default':status}, profile_key=self.profile) #FIXME: manage multilingual statuses 365 self.bridge.setPresence(show=show, statuses={'default': status}, profile_key=self.profile) #FIXME: manage multilingual statuses
357 366
358 def onStatusChange(self, e): 367 def onStatusChange(self, e):
359 debug(_("Status change request")) 368 debug(_("Status change request"))
360 self.__updateStatus() 369 self.__updateStatus()
361 370