Merge branch 'vuplus_experimental' of code.vuplus.com:/opt/repository/dvbapp into...
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / UIPositionSetup / plugin.py
1 from Screens.Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection, ConfigInteger, ConfigSlider
4 from Components.ActionMap import ActionMap
5 from Screens.MessageBox import MessageBox
6 from Components.Sources.StaticText import StaticText
7 from Plugins.Plugin import PluginDescriptor
8 from Tools.Directories import fileExists
9 from enigma import eTimer
10 from Plugins.Plugin import PluginDescriptor
11
12 config.plugins.UIPositionSetup = ConfigSubsection()
13 config.plugins.UIPositionSetup.dst_left = ConfigInteger(default = 0)
14 config.plugins.UIPositionSetup.dst_width = ConfigInteger(default = 720)
15 config.plugins.UIPositionSetup.dst_top = ConfigInteger(default = 0)
16 config.plugins.UIPositionSetup.dst_height = ConfigInteger(default = 576)
17
18 class UIPositionSetupInit:
19         def __init__(self):
20                 self.setPosition(int(config.plugins.UIPositionSetup.dst_left.value), int(config.plugins.UIPositionSetup.dst_width.value), int(config.plugins.UIPositionSetup.dst_top.value), int(config.plugins.UIPositionSetup.dst_height.value))
21
22         def setPosition(self,dst_left, dst_width, dst_top, dst_height):
23                 if dst_left + dst_width > 720 or dst_top + dst_height > 576 :
24                         return
25                 else:
26                         print "[UIPositionSetup] write dst_left : ",dst_left
27                         print "[UIPositionSetup] write dst_width : ",dst_width
28                         print "[UIPositionSetup] write dst_top : ",dst_top
29                         print "[UIPositionSetup] write dst_height : ",dst_height
30                         try:
31                                 file = open("/proc/stb/fb/dst_left", "w")
32                                 file.write('%X' % dst_left)
33                                 file.close()
34                                 file = open("/proc/stb/fb/dst_width", "w")
35                                 file.write('%X' % dst_width)
36                                 file.close()
37                                 file = open("/proc/stb/fb/dst_top", "w")
38                                 file.write('%X' % dst_top)
39                                 file.close()
40                                 file = open("/proc/stb/fb/dst_height", "w")
41                                 file.write('%X' % dst_height)
42                                 file.close()
43                         except:
44                                 return
45
46 uipositionsetupinit = UIPositionSetupInit()
47
48 class UIPositionSetup(Screen, ConfigListScreen, UIPositionSetupInit):
49         skin =  """
50                 <screen position="0,0" size="%d,%d" title="Screen Position Setup" backgroundColor="#27d8dee2" >
51                         <ePixmap pixmap="skin_default/buttons/red.png" position="%d,%d" size="140,40" alphatest="on" />
52                         <ePixmap pixmap="skin_default/buttons/green.png" position="%d,%d" size="140,40" alphatest="on" />"
53
54                         <widget source="key_red" render="Label" position="%d,%d" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
55                         <widget source="key_green" render="Label" position="%d,%d" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
56
57                         <widget name="config" zPosition="2" position="%d,%d" size="500,200" scrollbarMode="showOnDemand" foregroundColor="#1c1c1c" transparent="1" />
58                 </screen>
59                 """
60         def __init__(self,session):
61                 w,h   = session.desktop.size().width(), session.desktop.size().height()
62                 cw,ch = w/2, h/2
63                 #                             btn_red        btn_green     lb_red         lb_green      config
64                 self.skin = self.skin % (w,h, cw-190,ch-110, cw+50,ch-110, cw-190,ch-110, cw+50,ch-110, cw-250,ch-50)
65
66                 Screen.__init__(self,session)
67                 self.session = session
68                 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
69                 {
70                         "ok": self.keyOk,
71                         "cancel": self.keyCancel,
72                         "red": self.keyCancel,
73                         "green": self.keyOk,
74                 }, -2)
75                 self.list = []
76                 ConfigListScreen.__init__(self, self.list,session = self.session)
77
78                 self["key_red"] = StaticText(_("Cancel"))
79                 self["key_green"] = StaticText(_("Save"))
80                 self["current"] = StaticText(_(" "))
81                 self.createSetup()
82
83         def createSetup(self):
84                 self.list = []
85
86                 left   = config.plugins.UIPositionSetup.dst_left.value
87                 width  = config.plugins.UIPositionSetup.dst_width.value
88                 top    = config.plugins.UIPositionSetup.dst_top.value
89                 height = config.plugins.UIPositionSetup.dst_height.value
90
91                 self.dst_left   = ConfigSlider(default = left, increment = 5, limits = (0, 720))
92                 self.dst_width  = ConfigSlider(default = width, increment = 5, limits = (0, 720))
93                 self.dst_top    = ConfigSlider(default = top, increment = 5, limits = (0, 576))
94                 self.dst_height = ConfigSlider(default = height, increment = 5, limits = (0, 576))
95
96                 self.dst_left_entry   = getConfigListEntry(_("left"), self.dst_left)
97                 self.dst_width_entry  = getConfigListEntry(_("width"), self.dst_width)
98                 self.dst_top_entry    = getConfigListEntry(_("top"), self.dst_top)
99                 self.dst_height_entry = getConfigListEntry(_("height"), self.dst_height)
100
101                 self.list.append(self.dst_left_entry)
102                 self.list.append(self.dst_width_entry)
103                 self.list.append(self.dst_top_entry)
104                 self.list.append(self.dst_height_entry)
105
106                 self["config"].list = self.list
107                 self["config"].l.setList(self.list)
108
109         def resetDisplay(self):
110                 for entry in self["config"].getList():
111                         self["config"].l.invalidateEntry(self["config"].getList().index(entry))
112
113         def adjustBorder(self):
114                 if self["config"].getCurrent() == self.dst_left_entry:
115                         if self.dst_left.value + self.dst_width.value >720:
116                                 self.dst_width.setValue(720-self.dst_left.value)
117                                 self.resetDisplay()
118                 elif self["config"].getCurrent() == self.dst_width_entry:
119                         if self.dst_left.value + self.dst_width.value >720:
120                                 self.dst_left.setValue(720-self.dst_width.value)
121                                 self.resetDisplay()
122                 elif self["config"].getCurrent() == self.dst_top_entry:
123                         if self.dst_top.value + self.dst_height.value >576:
124                                 self.dst_height.setValue(576-self.dst_top.value)
125                                 self.resetDisplay()
126                 elif self["config"].getCurrent() == self.dst_height_entry:
127                         if self.dst_top.value + self.dst_height.value >576:
128                                 self.dst_top.setValue(576-self.dst_height.value)
129                                 self.resetDisplay()
130
131         def keyLeft(self):
132                 ConfigListScreen.keyLeft(self)
133                 self.adjustBorder()
134                 self.setPosition(int(self.dst_left.value), int(self.dst_width.value), int(self.dst_top.value), int(self.dst_height.value))
135
136         def keyRight(self):
137                 ConfigListScreen.keyRight(self)
138                 self.adjustBorder()
139                 self.setPosition(int(self.dst_left.value), int(self.dst_width.value), int(self.dst_top.value), int(self.dst_height.value))
140
141         def keyOk(self):
142                 config.plugins.UIPositionSetup.dst_left.value = self.dst_left.value
143                 config.plugins.UIPositionSetup.dst_width.value = self.dst_width.value
144                 config.plugins.UIPositionSetup.dst_top.value = self.dst_top.value
145                 config.plugins.UIPositionSetup.dst_height.value = self.dst_height.value
146                 config.plugins.UIPositionSetup.save()
147                 self.close()
148
149         def keyCancel(self):
150                 if self["config"].isChanged():
151                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
152                 else:
153                         self.close()
154
155         def cancelConfirm(self,ret):
156                 if ret:
157                         self.setPosition(int(config.plugins.UIPositionSetup.dst_left.value), int(config.plugins.UIPositionSetup.dst_width.value), int(config.plugins.UIPositionSetup.dst_top.value), int(config.plugins.UIPositionSetup.dst_height.value))
158                         self.close()
159
160 def main(session, **kwargs):
161         session.open(UIPositionSetup)
162
163 def Plugins(**kwargs):
164         if fileExists("/proc/stb/fb/dst_left"):
165                 return [PluginDescriptor(name = "UI position setup", description = "Adjust screen position", where = PluginDescriptor.WHERE_PLUGINMENU, fnc = main)]
166         return []
167