Let ChoiceBox font and calculated size be set from the aliasses.
authorMike Looijmans <milo-software@users.sourceforge.net>
Sun, 27 Nov 2011 13:19:03 +0000 (14:19 +0100)
committerMike Looijmans <milo-software@users.sourceforge.net>
Tue, 29 Nov 2011 08:39:11 +0000 (09:39 +0100)
data/skin_default.xml
lib/python/Components/ChoiceList.py
lib/python/Screens/ChoiceBox.py
skin.py

index 6edc021..c0fca2f 100755 (executable)
                <font filename="tuxtxt.ttf" name="Console" scale="100" />
                <!-- Arabic and Thai char set replacement -->
                <font filename="ae_AlMateen.ttf" name="Replacement" scale="100" replacement="1" />
+               <!-- Aliases that should be present -->
+               <alias name="Body" font="Regular" size="20" height="25" />
+               <alias name="ChoiceList" font="Regular" size="20" height="25" />
+               <alias name="TextNormal" font="Regular" size="20" height="24" />
        </fonts>
        <colors>
                <color name="white" value="#ffffff" />
        </screen>
        <!-- Choice box -->
        <screen name="ChoiceBox" position="center,center" size="550,400" title="Input">
-               <widget name="text" position="10,10" size="550,25" font="Regular;20" />
-               <widget name="list" position="0,30" size="550,335" scrollbarMode="showOnDemand" />
+               <widget name="text" position="top" size="*,48h" font="TextNormal" />
+               <widget name="list" position="fill" scrollbarMode="showOnDemand" />
                <applet type="onLayoutFinish">
-# this should be factored out into some helper code, but currently demonstrates applets.
-from enigma import eSize, ePoint
-
-orgwidth = self.instance.size().width()
-orgpos = self.instance.position()
-textsize = self[&quot;text&quot;].getSize()
-
-# y size still must be fixed in font stuff...
-textsize = (textsize[0] + 50, textsize[1] + 50)
-count = len(self.list)
-if count &gt; 10:
-       count = 10
-offset = 25 * count
-wsizex = textsize[0] + 60
-wsizey = textsize[1] + offset
-
-if (520 &gt; wsizex):
-       wsizex = 520
-wsize = (wsizex, wsizey)
-
-# resize
-self.instance.resize(eSize(*wsize))
-
-# resize label
-self[&quot;text&quot;].instance.resize(eSize(*textsize))
-
-# move list
-listsize = (wsizex, 25 * count)
-self[&quot;list&quot;].instance.move(ePoint(0, textsize[1]))
-self[&quot;list&quot;].instance.resize(eSize(*listsize))
-
-# center window
-newwidth = wsize[0]
-self.instance.move(ePoint((720-wsizex)/2, (576-wsizey)/(count &gt; 7 and 2 or 3)))
-
+self.autoResize()
                </applet>
        </screen>
 
index 33868d6..dcc3df3 100755 (executable)
@@ -2,6 +2,7 @@ from MenuList import MenuList
 from Tools.Directories import SCOPE_CURRENT_SKIN, resolveFilename
 from enigma import RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont
 from Tools.LoadPixmap import LoadPixmap
+import skin
 
 def ChoiceEntryComponent(key = "", text = ["--"]):
        res = [ text ]
@@ -19,8 +20,9 @@ def ChoiceEntryComponent(key = "", text = ["--"]):
 class ChoiceList(MenuList):
        def __init__(self, list, selection = 0, enableWrapAround=False):
                MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
-               self.l.setFont(0, gFont("Regular", 20))
-               self.l.setItemHeight(25)
+               font = skin.fonts["ChoiceList"]
+               self.l.setFont(0, gFont(font[0], font[1]))
+               self.l.setItemHeight(font[2])
                self.selection = selection
 
        def postWidgetCreate(self, instance):
index f8123e5..7392d1a 100644 (file)
@@ -3,6 +3,7 @@ from Components.ActionMap import NumberActionMap
 from Components.Label import Label
 from Components.ChoiceList import ChoiceEntryComponent, ChoiceList
 from Components.Sources.StaticText import StaticText
+import enigma
 
 class ChoiceBox(Screen):
        def __init__(self, session, title = "", list = [], keys = None, selection = 0, skin_name = []):
@@ -55,7 +56,32 @@ class ChoiceBox(Screen):
                        "up": self.up,
                        "down": self.down
                }, -1)
-               
+
+       def autoResize(self):
+               orgwidth = self.instance.size().width()
+               orgpos = self.instance.position()
+               textsize = self["text"].getSize()
+               count = len(self.list)
+               if count > 10:
+                       count = 10
+               offset = 25 * count
+               wsizex = textsize[0] + 60
+               wsizey = textsize[1] + offset
+               if (520 > wsizex):
+                       wsizex = 520
+               wsize = (wsizex, wsizey)
+               # resize
+               self.instance.resize(enigma.eSize(*wsize))
+               # resize label
+               self["text"].instance.resize(enigma.eSize(*textsize))
+               # move list
+               listsize = (wsizex, 25 * count)
+               self["list"].instance.move(enigma.ePoint(0, textsize[1]))
+               self["list"].instance.resize(enigma.eSize(*listsize))
+               # center window
+               newwidth = wsize[0]
+               self.instance.move(enigma.ePoint((720-wsizex)/2, (576-wsizey)/(count > 7 and 2 or 3)))
+
        def keyLeft(self):
                pass
        
diff --git a/skin.py b/skin.py
index f013faa..3aa40a8 100755 (executable)
--- a/skin.py
+++ b/skin.py
@@ -14,7 +14,12 @@ from Tools.Import import my_import
 from Tools.LoadPixmap import LoadPixmap
 
 colorNames = {}
-fonts = {}
+# Predefined fonts, typically used in built-in screens and for components like
+# the movie list and so.
+fonts = {
+       "Body": ("Regular", 18, 22, 16),
+       "ChoiceList": ("Regular", 20, 24, 18),
+}
 
 def dump(x, i=0):
        print " " * i + str(x)