diff 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
line wrap: on
line diff
--- a/frontends/src/wix/main_window.py	Sat Nov 23 10:21:40 2013 +0100
+++ b/frontends/src/wix/main_window.py	Mon Nov 25 01:56:07 2013 +0100
@@ -76,7 +76,7 @@
                                       style=wx.CB_DROPDOWN | wx.CB_READONLY)
         self.tools.AddControl(self.statusBox)
         self.tools.AddSeparator()
-        self.statusTxt=wx.TextCtrl(self.tools, -1, style = wx.TE_PROCESS_ENTER)
+        self.statusTxt = wx.TextCtrl(self.tools, -1, style=wx.TE_PROCESS_ENTER)
         self.tools.AddControl(self.statusTxt)
         self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox)
         self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt)
@@ -209,11 +209,20 @@
             data = [answer_data] if answer_data else []
             answer_cb(True if (answer == wx.ID_YES or answer == wx.ID_OK) else False, *data)
 
-    def setStatusOnline(self, online=True):
+    def setStatusOnline(self, online=True, show="", statuses={}):
         """enable/disable controls, must be called when local user online status change"""
         if online:
             self.SetStatusText(Const.msgONLINE)
             self.tools.Enable()
+            try:
+                presence = [x for x in Const.PRESENCE if x[0] == show][0][1]
+                self.statusBox.SetValue(presence)
+            except (TypeError, IndexError):
+                pass
+            try:
+                self.statusTxt.SetValue(statuses['default'])
+            except (TypeError, KeyError):
+                pass
         else:
             self.SetStatusText(Const.msgOFFLINE)
             self.tools.Disable()
@@ -351,9 +360,9 @@
         self.bridge.disconnect(self.profile)
 
     def __updateStatus(self):
-        show = filter(lambda x:x[1] == self.statusBox.GetValue(), Const.PRESENCE)[0][0]
-        status =  self.statusTxt.GetValue()
-        self.bridge.setPresence(show=show, statuses={'default':status}, profile_key=self.profile)  #FIXME: manage multilingual statuses
+        show = [x for x in Const.PRESENCE if x[1] == self.statusBox.GetValue()][0][0]
+        status = self.statusTxt.GetValue()
+        self.bridge.setPresence(show=show, statuses={'default': status}, profile_key=self.profile)  #FIXME: manage multilingual statuses
 
     def onStatusChange(self, e):
         debug(_("Status change request"))