comparison frontends/src/wix/main_window.py @ 736:6246eb6d64a0

frontends: define the constants with classes and inheritance instance of using __builtin__
author souliane <souliane@mailoo.org>
date Sat, 23 Nov 2013 10:21:40 +0100
parents f7878ad3c846
children 378af36155c2
comparison
equal deleted inserted replaced
735:682933ca304c 736:6246eb6d64a0
29 from sat_frontends.wix.profile import Profile 29 from sat_frontends.wix.profile import Profile
30 from sat_frontends.wix.profile_manager import ProfileManager 30 from sat_frontends.wix.profile_manager import ProfileManager
31 import os.path 31 import os.path
32 from sat.tools.jid import JID 32 from sat.tools.jid import JID
33 from logging import debug, info, warning, error 33 from logging import debug, info, warning, error
34 import sat_frontends.wix.constants 34 from sat_frontends.wix.constants import Const
35 35
36 idCONNECT,\ 36 idCONNECT,\
37 idDISCONNECT,\ 37 idDISCONNECT,\
38 idEXIT,\ 38 idEXIT,\
39 idABOUT,\ 39 idABOUT,\
70 self.chat_wins=ChatList(self) 70 self.chat_wins=ChatList(self)
71 self.CreateStatusBar() 71 self.CreateStatusBar()
72 72
73 #ToolBar 73 #ToolBar
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_STATUS], 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)
120 connectMenu = wx.Menu() 120 connectMenu = wx.Menu()
121 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server")) 121 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server"))
122 connectMenu.Append(idDISCONNECT, _("&Disconnect CTRL-d"),_(" Disconnect from the server")) 122 connectMenu.Append(idDISCONNECT, _("&Disconnect CTRL-d"),_(" Disconnect from the server"))
123 connectMenu.Append(idPARAM,_("&Parameters"),_(" Configure the program")) 123 connectMenu.Append(idPARAM,_("&Parameters"),_(" Configure the program"))
124 connectMenu.AppendSeparator() 124 connectMenu.AppendSeparator()
125 connectMenu.Append(idABOUT,_("A&bout"),_(" About %s") % APP_NAME) 125 connectMenu.Append(idABOUT, _("A&bout"), _(" About %s") % Const.APP_NAME)
126 connectMenu.Append(idEXIT,_("E&xit"),_(" Terminate the program")) 126 connectMenu.Append(idEXIT,_("E&xit"),_(" Terminate the program"))
127 contactMenu = wx.Menu() 127 contactMenu = wx.Menu()
128 contactMenu.Append(idADD_CONTACT, _("&Add contact"),_(" Add a contact to your list")) 128 contactMenu.Append(idADD_CONTACT, _("&Add contact"),_(" Add a contact to your list"))
129 contactMenu.Append(idREMOVE_CONTACT, _("&Remove contact"),_(" Remove the selected contact from your list")) 129 contactMenu.Append(idREMOVE_CONTACT, _("&Remove contact"),_(" Remove the selected contact from your list"))
130 contactMenu.AppendSeparator() 130 contactMenu.AppendSeparator()
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):
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(msgONLINE) 215 self.SetStatusText(Const.msgONLINE)
216 self.tools.Enable() 216 self.tools.Enable()
217 else: 217 else:
218 self.SetStatusText(msgOFFLINE) 218 self.SetStatusText(Const.msgOFFLINE)
219 self.tools.Disable() 219 self.tools.Disable()
220 return 220 return
221 221
222 def askConfirmation(self, confirmation_id, confirmation_type, data, profile): 222 def askConfirmation(self, confirmation_id, confirmation_type, data, profile):
223 #TODO: refactor this in QuickApp 223 #TODO: refactor this in QuickApp
349 349
350 def onDisconnectRequest(self, e): 350 def onDisconnectRequest(self, e):
351 self.bridge.disconnect(self.profile) 351 self.bridge.disconnect(self.profile)
352 352
353 def __updateStatus(self): 353 def __updateStatus(self):
354 show = filter(lambda x:x[1] == self.statusBox.GetValue(), const_STATUS)[0][0] 354 show = filter(lambda x:x[1] == self.statusBox.GetValue(), Const.PRESENCE)[0][0]
355 status = self.statusTxt.GetValue() 355 status = self.statusTxt.GetValue()
356 self.bridge.setPresence(show=show, statuses={'default':status}, profile_key=self.profile) #FIXME: manage multilingual statuses 356 self.bridge.setPresence(show=show, statuses={'default':status}, profile_key=self.profile) #FIXME: manage multilingual statuses
357 357
358 def onStatusChange(self, e): 358 def onStatusChange(self, e):
359 debug(_("Status change request")) 359 debug(_("Status change request"))
365 #XMLUI(self, xml_data = xmlui) 365 #XMLUI(self, xml_data = xmlui)
366 param=Param(self) 366 param=Param(self)
367 367
368 def onAbout(self, e): 368 def onAbout(self, e):
369 about = wx.AboutDialogInfo() 369 about = wx.AboutDialogInfo()
370 about.SetName(APP_NAME) 370 about.SetName(Const.APP_NAME)
371 about.SetVersion (unicode(self.bridge.getVersion())) 371 about.SetVersion (unicode(self.bridge.getVersion()))
372 about.SetCopyright(u"(C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson aka Goffi") 372 about.SetCopyright(u"(C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson aka Goffi")
373 about.SetDescription( _(u"%(name)s is a SàT (Salut à Toi) frontend\n"+ 373 about.SetDescription( _(u"%(name)s is a SàT (Salut à Toi) frontend\n"+
374 u"%(name)s is based on WxPython, and is the standard graphic interface of SàT") % {'name':APP_NAME}) 374 u"%(name)s is based on WxPython, and is the standard graphic interface of SàT") % {'name': Const.APP_NAME})
375 about.SetWebSite(("http://www.goffi.org", "Goffi's non-hebdo (french)")) 375 about.SetWebSite(("http://www.goffi.org", "Goffi's non-hebdo (french)"))
376 about.SetDevelopers([ "Goffi (Jérôme Poisson)"]) 376 about.SetDevelopers([ "Goffi (Jérôme Poisson)"])
377 try: 377 try:
378 with open(LICENCE_PATH,"r") as licence: 378 with open(Const.LICENCE_PATH, "r") as licence:
379 about.SetLicence(''.join(licence.readlines())) 379 about.SetLicence(''.join(licence.readlines()))
380 except: 380 except:
381 pass 381 pass
382 382
383 wx.AboutBox(about) 383 wx.AboutBox(about)