frontends: define the constants with classes and inheritance instance of using __builtin__

This commit is contained in:
souliane 2013-11-23 10:21:40 +01:00
commit f5dd3f2265
3 changed files with 169 additions and 95 deletions

View file

@ -1,17 +1,44 @@
import sys,os.path
import __builtin__
import sat_frontends.wix
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Primitivus: a SAT frontend
# Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import os.path
import gettext
import sat_frontends.wix
from sat_frontends.quick_frontend import constants
_ = gettext.gettext
wix_root = os.path.dirname(sat_frontends.wix.__file__)
__builtin__.__dict__['APP_NAME'] = "Wix"
__builtin__.__dict__['LICENCE_PATH'] = os.path.join(wix_root,"COPYING")
__builtin__.__dict__['msgOFFLINE'] = _("offline")
__builtin__.__dict__['msgONLINE'] = _("online")
__builtin__.__dict__['const_DEFAULT_GROUP'] = "Unclassed"
__builtin__.__dict__['const_STATUS'] = [("", _("Online"), None),
("chat", _("Free for chat"), "green"),
("away", _("AFK"), "brown"),
("dnd", _("DND"), "red"),
("xa", _("Away"), "red")]
class Const(constants.Const):
APP_NAME = "Wix"
LICENCE_PATH = os.path.join(wix_root, "COPYING")
msgOFFLINE = _("offline")
msgONLINE = _("online")
DEFAULT_GROUP = "Unclassed"
PRESENCE = [("", _("Online"), None),
("chat", _("Free for chat"), "green"),
("away", _("AFK"), "brown"),
("dnd", _("DND"), "red"),
("xa", _("Away"), "red")
]

View file

@ -19,6 +19,7 @@
import wx
from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
from sat_frontends.wix.constants import Const
from logging import debug, info, error
from cgi import escape
from sat.tools.jid import JID
@ -113,7 +114,7 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
_show = self.getCache(jid,'show')
if _show == None or _show == 'unavailable':
return None
show = filter(lambda x : x[0] == _show, const_STATUS)[0]
show = filter(lambda x : x[0] == _show, Const.PRESENCE)[0]
#show[0]==shortcut
#show[1]==human readable

View file

@ -31,7 +31,7 @@ from sat_frontends.wix.profile_manager import ProfileManager
import os.path
from sat.tools.jid import JID
from logging import debug, info, warning, error
import sat_frontends.wix.constants
from sat_frontends.wix.constants import Const
idCONNECT,\
idDISCONNECT,\
@ -72,7 +72,7 @@ class MainWindow(wx.Frame, QuickApp):
#ToolBar
self.tools=self.CreateToolBar()
self.statusBox = wx.ComboBox(self.tools, -1, "Online", choices=[status[1] for status in const_STATUS],
self.statusBox = wx.ComboBox(self.tools, -1, "Online", choices=[status[1] for status in Const.PRESENCE],
style=wx.CB_DROPDOWN | wx.CB_READONLY)
self.tools.AddControl(self.statusBox)
self.tools.AddSeparator()
@ -122,7 +122,7 @@ class MainWindow(wx.Frame, QuickApp):
connectMenu.Append(idDISCONNECT, _("&Disconnect CTRL-d"),_(" Disconnect from the server"))
connectMenu.Append(idPARAM,_("&Parameters"),_(" Configure the program"))
connectMenu.AppendSeparator()
connectMenu.Append(idABOUT,_("A&bout"),_(" About %s") % APP_NAME)
connectMenu.Append(idABOUT, _("A&bout"), _(" About %s") % Const.APP_NAME)
connectMenu.Append(idEXIT,_("E&xit"),_(" Terminate the program"))
contactMenu = wx.Menu()
contactMenu.Append(idADD_CONTACT, _("&Add contact"),_(" Add a contact to your list"))
@ -212,10 +212,10 @@ class MainWindow(wx.Frame, QuickApp):
def setStatusOnline(self, online=True):
"""enable/disable controls, must be called when local user online status change"""
if online:
self.SetStatusText(msgONLINE)
self.SetStatusText(Const.msgONLINE)
self.tools.Enable()
else:
self.SetStatusText(msgOFFLINE)
self.SetStatusText(Const.msgOFFLINE)
self.tools.Disable()
return
@ -351,7 +351,7 @@ class MainWindow(wx.Frame, QuickApp):
self.bridge.disconnect(self.profile)
def __updateStatus(self):
show = filter(lambda x:x[1] == self.statusBox.GetValue(), const_STATUS)[0][0]
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
@ -367,15 +367,15 @@ class MainWindow(wx.Frame, QuickApp):
def onAbout(self, e):
about = wx.AboutDialogInfo()
about.SetName(APP_NAME)
about.SetName(Const.APP_NAME)
about.SetVersion (unicode(self.bridge.getVersion()))
about.SetCopyright(u"(C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson aka Goffi")
about.SetDescription( _(u"%(name)s is a SàT (Salut à Toi) frontend\n"+
u"%(name)s is based on WxPython, and is the standard graphic interface of SàT") % {'name':APP_NAME})
u"%(name)s is based on WxPython, and is the standard graphic interface of SàT") % {'name': Const.APP_NAME})
about.SetWebSite(("http://www.goffi.org", "Goffi's non-hebdo (french)"))
about.SetDevelopers([ "Goffi (Jérôme Poisson)"])
try:
with open(LICENCE_PATH,"r") as licence:
with open(Const.LICENCE_PATH, "r") as licence:
about.SetLicence(''.join(licence.readlines()))
except:
pass