Support turbo2.
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / UIPositionSetup / plugin.py
index 0ad18d0..25c7f92 100755 (executable)
@@ -20,46 +20,48 @@ class UIPositionSetupInit:
                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))
 
        def setPosition(self,dst_left, dst_width, dst_top, dst_height):
-               if dst_left + dst_width > 720:
-                       dst_width = 720 - dst_left
-               if dst_top + dst_height > 576:
-                       dst_height = 576 - dst_top
-               print "[UIPositionSetup] write dst_left : ",dst_left
-               print "[UIPositionSetup] write dst_width : ",dst_width
-               print "[UIPositionSetup] write dst_top : ",dst_top
-               print "[UIPositionSetup] write dst_height : ",dst_height
-               try:
-                       file = open("/proc/stb/fb/dst_left", "w")
-                       file.write('%X' % dst_left)
-                       file.close()
-                       file = open("/proc/stb/fb/dst_width", "w")
-                       file.write('%X' % dst_width)
-                       file.close()
-                       file = open("/proc/stb/fb/dst_top", "w")
-                       file.write('%X' % dst_top)
-                       file.close()
-                       file = open("/proc/stb/fb/dst_height", "w")
-                       file.write('%X' % dst_height)
-                       file.close()
-               except:
+               if dst_left + dst_width > 720 or dst_top + dst_height > 576 :
                        return
+               else:
+                       print "[UIPositionSetup] write dst_left : ",dst_left
+                       print "[UIPositionSetup] write dst_width : ",dst_width
+                       print "[UIPositionSetup] write dst_top : ",dst_top
+                       print "[UIPositionSetup] write dst_height : ",dst_height
+                       try:
+                               file = open("/proc/stb/fb/dst_left", "w")
+                               file.write('%X' % dst_left)
+                               file.close()
+                               file = open("/proc/stb/fb/dst_width", "w")
+                               file.write('%X' % dst_width)
+                               file.close()
+                               file = open("/proc/stb/fb/dst_top", "w")
+                               file.write('%X' % dst_top)
+                               file.close()
+                               file = open("/proc/stb/fb/dst_height", "w")
+                               file.write('%X' % dst_height)
+                               file.close()
+                       except:
+                               return
 
 uipositionsetupinit = UIPositionSetupInit()
 
 class UIPositionSetup(Screen, ConfigListScreen, UIPositionSetupInit):
+       skin =  """
+               <screen position="0,0" size="%d,%d" title="Screen Position Setup" backgroundColor="#27d8dee2" >
+                       <ePixmap pixmap="skin_default/buttons/red.png" position="%d,%d" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/green.png" position="%d,%d" size="140,40" alphatest="on" />"
+
+                       <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" />
+                       <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" />
+
+                       <widget name="config" zPosition="2" position="%d,%d" size="500,200" scrollbarMode="showOnDemand" foregroundColor="#1c1c1c" transparent="1" />
+               </screen>
+               """
        def __init__(self,session):
-               size_w = session.desktop.size().width()
-               size_h = session.desktop.size().height()
-               xpos = (size_w-500)/2
-               ypos = (size_h-300)/2
-               self.skin=""
-               self.skin += "<screen position=\"0,0\" size=\"" + str(size_w) + "," + str(size_h) + "\" title=\"Screen Position Setup\" backgroundColor=\"#27d8dee2\">"
-               self.skin += "<ePixmap pixmap=\"Vu_HD/buttons/red.png\" position=\""+str(xpos+10) + "," + str(ypos+10) + "\" size=\"25,25\" alphatest=\"on\" />"
-               self.skin += "<ePixmap pixmap=\"Vu_HD/buttons/green.png\" position=\""+str(xpos+290) + "," + str(ypos+10) + "\" size=\"25,25\" alphatest=\"on\" />"
-               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\" />"
-               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\" />"
-               self.skin += "<widget name=\"config\" zPosition=\"2\" position=\""+str(xpos+5) + "," + str(ypos+50) + "\" size=\"550,200\" scrollbarMode=\"showOnDemand\" foregroundColor=\"#1c1c1c\" transparent=\"1\" />"
-               self.skin += "</screen>"
+               w,h   = session.desktop.size().width(), session.desktop.size().height()
+               cw,ch = w/2, h/2
+               #                             btn_red        btn_green     lb_red         lb_green      config
+               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)
 
                Screen.__init__(self,session)
                self.session = session
@@ -72,6 +74,7 @@ class UIPositionSetup(Screen, ConfigListScreen, UIPositionSetupInit):
                }, -2)
                self.list = []
                ConfigListScreen.__init__(self, self.list,session = self.session)
+
                self["key_red"] = StaticText(_("Cancel"))
                self["key_green"] = StaticText(_("Save"))
                self["current"] = StaticText(_(" "))
@@ -80,30 +83,59 @@ class UIPositionSetup(Screen, ConfigListScreen, UIPositionSetupInit):
        def createSetup(self):
                self.list = []
 
-               left = config.plugins.UIPositionSetup.dst_left.value
-               width = config.plugins.UIPositionSetup.dst_width.value
-               top = config.plugins.UIPositionSetup.dst_top.value
+               left   = config.plugins.UIPositionSetup.dst_left.value
+               width  = config.plugins.UIPositionSetup.dst_width.value
+               top    = config.plugins.UIPositionSetup.dst_top.value
                height = config.plugins.UIPositionSetup.dst_height.value
 
-               self.dst_left = ConfigSlider(default = left, increment = 5, limits = (0, 720))
-               self.dst_width = ConfigSlider(default = width, increment = 5, limits = (0, 720))
-               self.dst_top = ConfigSlider(default = top, increment = 5, limits = (0, 576))
+               self.dst_left   = ConfigSlider(default = left, increment = 5, limits = (0, 720))
+               self.dst_width  = ConfigSlider(default = width, increment = 5, limits = (0, 720))
+               self.dst_top    = ConfigSlider(default = top, increment = 5, limits = (0, 576))
                self.dst_height = ConfigSlider(default = height, increment = 5, limits = (0, 576))
 
-               self.list.append(getConfigListEntry(_("left"), self.dst_left))
-               self.list.append(getConfigListEntry(_("width"), self.dst_width))
-               self.list.append(getConfigListEntry(_("top"), self.dst_top))
-               self.list.append(getConfigListEntry(_("height"), self.dst_height))
+               self.dst_left_entry   = getConfigListEntry(_("left"), self.dst_left)
+               self.dst_width_entry  = getConfigListEntry(_("width"), self.dst_width)
+               self.dst_top_entry    = getConfigListEntry(_("top"), self.dst_top)
+               self.dst_height_entry = getConfigListEntry(_("height"), self.dst_height)
+
+               self.list.append(self.dst_left_entry)
+               self.list.append(self.dst_width_entry)
+               self.list.append(self.dst_top_entry)
+               self.list.append(self.dst_height_entry)
 
                self["config"].list = self.list
                self["config"].l.setList(self.list)
 
+       def resetDisplay(self):
+               for entry in self["config"].getList():
+                       self["config"].l.invalidateEntry(self["config"].getList().index(entry))
+
+       def adjustBorder(self):
+               if self["config"].getCurrent() == self.dst_left_entry:
+                       if self.dst_left.value + self.dst_width.value >720:
+                               self.dst_width.setValue(720-self.dst_left.value)
+                               self.resetDisplay()
+               elif self["config"].getCurrent() == self.dst_width_entry:
+                       if self.dst_left.value + self.dst_width.value >720:
+                               self.dst_left.setValue(720-self.dst_width.value)
+                               self.resetDisplay()
+               elif self["config"].getCurrent() == self.dst_top_entry:
+                       if self.dst_top.value + self.dst_height.value >576:
+                               self.dst_height.setValue(576-self.dst_top.value)
+                               self.resetDisplay()
+               elif self["config"].getCurrent() == self.dst_height_entry:
+                       if self.dst_top.value + self.dst_height.value >576:
+                               self.dst_top.setValue(576-self.dst_height.value)
+                               self.resetDisplay()
+
        def keyLeft(self):
                ConfigListScreen.keyLeft(self)
+               self.adjustBorder()
                self.setPosition(int(self.dst_left.value), int(self.dst_width.value), int(self.dst_top.value), int(self.dst_height.value))
 
        def keyRight(self):
                ConfigListScreen.keyRight(self)
+               self.adjustBorder()
                self.setPosition(int(self.dst_left.value), int(self.dst_width.value), int(self.dst_top.value), int(self.dst_height.value))
 
        def keyOk(self):