replaced deprecated ConfigEnableDisable by ConfigOnOff
[enigma2-plugins.git] / emailclient / src / __init__.py
1 '''
2 Common functions for EmailClient
3 '''
4 from Tools.Directories import resolveFilename, SCOPE_LANGUAGE, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
5 from Components.Language import language
6 from Components.config import config
7 import os, gettext, time
8
9 lang = language.getLanguage()
10 os.environ["LANGUAGE"] = lang[:2]
11 gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE))
12 gettext.textdomain("enigma2")
13 gettext.bindtextdomain("EmailClient", "%s%s" % (resolveFilename(SCOPE_PLUGINS), "Extensions/EmailClient/locale/"))
14
15 def _(txt):
16         # pylint: disable-msg=C0103
17         t = gettext.dgettext("EmailClient", txt)
18         if t == txt:
19                 t = gettext.gettext(txt)
20         return t
21
22 def initLog():
23         try:
24                 os.remove("/tmp/EmailClient.log")
25         except OSError:
26                 pass
27
28 def debug(message):
29         if config.plugins.emailimap.debug.value:
30                 try:
31                         deb = open("/tmp/EmailClient.log", "aw")
32                         deb.write(time.ctime() + ': ' + message + "\n")
33                         deb.close()
34                 except Exception, e:
35                         debug("%s (retried debug: %s)" %(repr(message), str(e)))
36
37 from enigma import getDesktop
38 DESKTOP_WIDTH = getDesktop(0).size().width()
39 DESKTOP_HEIGHT = getDesktop(0).size().height()
40 def scaleH(y2, y1):
41         if y2 == -1:
42                 y2 = y1*1280/720
43         elif y1 == -1:
44                 y1 = y2*720/1280
45         return scale(y2, y1, 1280, 720, DESKTOP_WIDTH)
46 def scaleV(y2, y1):
47         if y2 == -1:
48                 y2 = y1*720/576
49         elif y1 == -1:
50                 y1 = y2*576/720
51         return scale(y2, y1, 720, 576, DESKTOP_HEIGHT)
52 def scale(y2, y1, x2, x1, x):
53         return (y2 - y1) * (x - x1) / (x2 - x1) + y1