22b4170c019adac9dd90160654142184d39616db
[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         def __init__(self,session):
50                 size_w = session.desktop.size().width()
51                 size_h = session.desktop.size().height()
52                 xpos = (size_w-500)/2
53                 ypos = (size_h-300)/2
54                 self.skin=""
55                 self.skin += "<screen position=\"0,0\" size=\"" + str(size_w) + "," + str(size_h) + "\" title=\"Screen Position Setup\" backgroundColor=\"#27d8dee2\">"
56                 self.skin += "<ePixmap pixmap=\"Vu_HD/buttons/red.png\" position=\""+str(xpos+10) + "," + str(ypos+10) + "\" size=\"25,25\" alphatest=\"on\" />"
57                 self.skin += "<ePixmap pixmap=\"Vu_HD/buttons/green.png\" position=\""+str(xpos+290) + "," + str(ypos+10) + "\" size=\"25,25\" alphatest=\"on\" />"
58                 self.skin += "<widget source=\"key_red\" render=\"Label\" position=\""+str(xpos+40) + "," + str(ypos+10) + "\" zPosition=\"1\" size=\"140,25\" font=\"Regular;20\" halign=\"center\" valign=\"center\" foregroundColor=\"#1c1c1c\" transparent=\"1\" />"
59                 self.skin += "<widget source=\"key_green\" render=\"Label\" position=\""+str(xpos+320) + "," + str(ypos+10) + "\" zPosition=\"1\" size=\"140,25\" font=\"Regular;20\" halign=\"center\" valign=\"center\" foregroundColor=\"#1c1c1c\" transparent=\"1\" />"
60                 self.skin += "<widget name=\"config\" zPosition=\"2\" position=\""+str(xpos+5) + "," + str(ypos+50) + "\" size=\"550,200\" scrollbarMode=\"showOnDemand\" foregroundColor=\"#1c1c1c\" transparent=\"1\" />"
61                 self.skin += "</screen>"
62
63                 Screen.__init__(self,session)
64                 self.session = session
65                 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
66                 {
67                         "ok": self.keyOk,
68                         "cancel": self.keyCancel,
69                         "red": self.keyCancel,
70                         "green": self.keyOk,
71                 }, -2)
72                 self.list = []
73                 ConfigListScreen.__init__(self, self.list,session = self.session)
74                 self["key_red"] = StaticText(_("Cancel"))
75                 self["key_green"] = StaticText(_("Save"))
76                 self["current"] = StaticText(_(" "))
77                 self.createSetup()
78
79         def createSetup(self):
80                 self.list = []
81
82                 left = config.plugins.UIPositionSetup.dst_left.value
83                 width = config.plugins.UIPositionSetup.dst_width.value
84                 top = config.plugins.UIPositionSetup.dst_top.value
85                 height = config.plugins.UIPositionSetup.dst_height.value
86
87                 self.dst_left = ConfigSlider(default = left, increment = 5, limits = (0, 720))
88                 self.dst_width = ConfigSlider(default = width, increment = 5, limits = (0, 720))
89                 self.dst_top = ConfigSlider(default = top, increment = 5, limits = (0, 576))
90                 self.dst_height = ConfigSlider(default = height, increment = 5, limits = (0, 576))
91
92                 self.dst_left_entry = getConfigListEntry(_("left"), self.dst_left)
93                 self.dst_width_entry = getConfigListEntry(_("width"), self.dst_width)
94                 self.dst_top_entry = getConfigListEntry(_("top"), self.dst_top)
95                 self.dst_height_entry = getConfigListEntry(_("height"), self.dst_height)
96
97                 self.list.append(self.dst_left_entry)
98                 self.list.append(self.dst_width_entry)
99                 self.list.append(self.dst_top_entry)
100                 self.list.append(self.dst_height_entry)
101
102                 self["config"].list = self.list
103                 self["config"].l.setList(self.list)
104
105         def resetDisplay(self):
106                 for entry in self["config"].getList():
107                         self["config"].l.invalidateEntry(self["config"].getList().index(entry))
108
109         def adjustBorder(self):
110                 if self["config"].getCurrent() == self.dst_left_entry:
111                         if self.dst_left.value + self.dst_width.value >720:
112                                 self.dst_width.setValue(720-self.dst_left.value)
113                                 self.resetDisplay()
114                 elif self["config"].getCurrent() == self.dst_width_entry:
115                         if self.dst_left.value + self.dst_width.value >720:
116                                 self.dst_left.setValue(720-self.dst_width.value)
117                                 self.resetDisplay()
118                 elif self["config"].getCurrent() == self.dst_top_entry:
119                         if self.dst_top.value + self.dst_height.value >576:
120                                 self.dst_height.setValue(576-self.dst_top.value)
121                                 self.resetDisplay()
122                 elif self["config"].getCurrent() == self.dst_height_entry:
123                         if self.dst_top.value + self.dst_height.value >576:
124                                 self.dst_top.setValue(576-self.dst_height.value)
125                                 self.resetDisplay()
126
127         def keyLeft(self):
128                 ConfigListScreen.keyLeft(self)
129                 self.adjustBorder()
130                 self.setPosition(int(self.dst_left.value), int(self.dst_width.value), int(self.dst_top.value), int(self.dst_height.value))
131
132         def keyRight(self):
133                 ConfigListScreen.keyRight(self)
134                 self.adjustBorder()
135                 self.setPosition(int(self.dst_left.value), int(self.dst_width.value), int(self.dst_top.value), int(self.dst_height.value))
136
137         def keyOk(self):
138                 config.plugins.UIPositionSetup.dst_left.value = self.dst_left.value
139                 config.plugins.UIPositionSetup.dst_width.value = self.dst_width.value
140                 config.plugins.UIPositionSetup.dst_top.value = self.dst_top.value
141                 config.plugins.UIPositionSetup.dst_height.value = self.dst_height.value
142                 config.plugins.UIPositionSetup.save()
143                 self.close()
144
145         def keyCancel(self):
146                 if self["config"].isChanged():
147                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
148                 else:
149                         self.close()
150
151         def cancelConfirm(self,ret):
152                 if ret:
153                         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))
154                         self.close()
155
156 def main(session, **kwargs):
157         session.open(UIPositionSetup)
158
159 def Plugins(**kwargs):
160         if fileExists("/proc/stb/fb/dst_left"):
161                 return [PluginDescriptor(name = "UI position setup", description = "Adjust screen position", where = PluginDescriptor.WHERE_PLUGINMENU, fnc = main)]
162         return []
163