use Components.Input in seek window
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Thu, 19 Jan 2006 03:59:43 +0000 (03:59 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Thu, 19 Jan 2006 03:59:43 +0000 (03:59 +0000)
data/keymap.xml
lib/gui/elabel.cpp
lib/python/Components/Input.py
lib/python/Plugins/test/plugin.py
lib/python/Screens/MinuteInput.py

index 2034aa1..fea9cf7 100644 (file)
                <key id="KEY_OK" mapto="ok" flags="m" />
                <key id="KEY_EXIT" mapto="back" flags="m" />
        </map>
                <key id="KEY_OK" mapto="ok" flags="m" />
                <key id="KEY_EXIT" mapto="back" flags="m" />
        </map>
+
+       <map context="MinuteInputActions">
+               <key id="KEY_UP" mapto="up" flags="mr" />
+               <key id="KEY_DOWN" mapto="down" flags="mr" />
+               <key id="KEY_OK" mapto="ok" flags="m" />
+               <key id="KEY_EXIT" mapto="cancel" flags="m" />
+       </map>
        
        <map context="InfobarMenuActions">
                <key id="KEY_MENU" mapto="mainMenu" flags="mr" />
        
        <map context="InfobarMenuActions">
                <key id="KEY_MENU" mapto="mainMenu" flags="mr" />
                <key id="KEY_0" mapto="0" flags="m" />
        </map>
        
                <key id="KEY_0" mapto="0" flags="m" />
        </map>
        
+
+       
        <map context="TextEntryActions">
                <key id="KEY_MUTE" mapto="delete" flags="mr" />
        </map>  
        <map context="TextEntryActions">
                <key id="KEY_MUTE" mapto="delete" flags="mr" />
        </map>  
index 970669c..3cec3a1 100644 (file)
@@ -37,13 +37,18 @@ int eLabel::event(int event, void *data, void *data2)
                        para->setFont(m_font);
                        para->renderString(m_text, 0);
                        para->realign(eTextPara::dirLeft);
                        para->setFont(m_font);
                        para->renderString(m_text, 0);
                        para->realign(eTextPara::dirLeft);
+                       int glyphs = para->size();
 
 
-                       para->setGlyphFlag(m_pos, GS_INVERT);
-                       eRect bbox;
-                       bbox = para->getGlyphBBox(m_pos);
-                       printf("BBOX: %d %d %d %d\n", bbox.left(), 0, bbox.width(), size().height());
-                       bbox = eRect(bbox.left(), 0, bbox.width(), size().height());
-                       painter.fill(bbox);
+                       if ((m_pos < 0) || (m_pos >= glyphs))
+                               eWarning("glyph index %d in eLabel out of bounds!");
+                       else
+                       {
+                               para->setGlyphFlag(m_pos, GS_INVERT);
+                               eRect bbox;
+                               bbox = para->getGlyphBBox(m_pos);
+                               bbox = eRect(bbox.left(), 0, bbox.width(), size().height());
+                               painter.fill(bbox);
+                       }
 
                        painter.renderPara(para, ePoint(0, 0));
                        return 0;
 
                        painter.renderPara(para, ePoint(0, 0));
                        return 0;
index 7ffc5c7..a0252e4 100644 (file)
@@ -7,19 +7,30 @@ from enigma import eLabel
 from Tools.NumericalTextInput import NumericalTextInput
 
 class Input(HTMLComponent, GUIComponent, VariableText):
 from Tools.NumericalTextInput import NumericalTextInput
 
 class Input(HTMLComponent, GUIComponent, VariableText):
-       def __init__(self, text=""):
+       TEXT = 0
+       PIN = 1
+       NUMBER = 2      
+       
+       def __init__(self, text="", maxSize = False, type = TEXT):
                GUIComponent.__init__(self)
                VariableText.__init__(self)
                self.numericalTextInput = NumericalTextInput(self.right)
                GUIComponent.__init__(self)
                VariableText.__init__(self)
                self.numericalTextInput = NumericalTextInput(self.right)
+               self.type = type
+               self.maxSize = maxSize
                self.currPos = 0
                self.text = text
                self.update()
 
        def update(self):
                self.setMarkedPos(self.currPos)
                self.currPos = 0
                self.text = text
                self.update()
 
        def update(self):
                self.setMarkedPos(self.currPos)
-               self.setText(self.text)
+               text = self.text
+               if self.type == self.PIN:
+                       text = "*" * len(self.text)
+               self.setText(text)
                #self.setText(self.text[0:self.currPos] + "_" + self.text[self.currPos] + "_" + self.text[self.currPos + 1:])
 
                #self.setText(self.text[0:self.currPos] + "_" + self.text[self.currPos] + "_" + self.text[self.currPos + 1:])
 
+       def getText(self):
+               return self.text
        
        def createWidget(self, parent):
                return eLabel(parent, self.currPos)
        
        def createWidget(self, parent):
                return eLabel(parent, self.currPos)
@@ -31,15 +42,41 @@ class Input(HTMLComponent, GUIComponent, VariableText):
        def right(self):
                self.currPos += 1
                if self.currPos == len(self.text):
        def right(self):
                self.currPos += 1
                if self.currPos == len(self.text):
-                       self.text = self.text + " "
+                       if self.maxSize:
+                               self.currPos -= 1
+                       else:
+                               self.text = self.text + " "
+                       
                self.update()
                
        def left(self):
                self.currPos -= 1
                self.update()
                
                self.update()
                
        def left(self):
                self.currPos -= 1
                self.update()
                
+       def up(self):
+               if self.text[self.currPos] == "9":
+                       newNumber = "0"
+               else:
+                       newNumber = str(int(self.text[self.currPos]) + 1)
+               self.text = self.text[0:self.currPos] + newNumber + self.text[self.currPos + 1:]
+               self.update()
+               
+       def down(self):
+               if self.text[self.currPos] == "0":
+                       newNumber = "9"
+               else:
+                       newNumber = str(int(self.text[self.currPos]) - 1)
+               self.text = self.text[0:self.currPos] + newNumber + self.text[self.currPos + 1:]
+               self.update()
+               
        def number(self, number):
        def number(self, number):
-               self.text = self.text[0:self.currPos] + self.numericalTextInput.getKey(number) + self.text[self.currPos + 1:]
+               if self.type == self.TEXT:
+                       newChar = self.numericalTextInput.getKey(number)
+               elif self.type == self.PIN or self.type == self.NUMBER:
+                       newChar = str(number)
+               self.text = self.text[0:self.currPos] + newChar + self.text[self.currPos + 1:]
+               if self.type == self.PIN or self.type == self.NUMBER:
+                       self.right()
                self.update()
 
        def show(self):
                self.update()
 
        def show(self):
index d85a80c..90c45e6 100644 (file)
@@ -18,7 +18,7 @@ class Test(Screen):
                self.skin = Test.skin
                Screen.__init__(self, session)
 
                self.skin = Test.skin
                Screen.__init__(self, session)
 
-               self["text"] = Input("Please press OK!")
+               self["text"] = Input("1234", maxSize=True, type=Input.NUMBER)
                                
                self["actions"] = NumberActionMap(["WizardActions", "InputActions"], 
                {
                                
                self["actions"] = NumberActionMap(["WizardActions", "InputActions"], 
                {
index 68909b6..d804570 100644 (file)
@@ -4,16 +4,16 @@ from Components.Label import Label
 from Components.Button import Button
 from Components.Pixmap import Pixmap
 from Components.MenuList import MenuList
 from Components.Button import Button
 from Components.Pixmap import Pixmap
 from Components.MenuList import MenuList
+from Components.Input import Input
 from enigma import eSize, ePoint
 
 class MinuteInput(Screen):
                def __init__(self, session, basemins = 5):
                        Screen.__init__(self, session)
                                                
 from enigma import eSize, ePoint
 
 class MinuteInput(Screen):
                def __init__(self, session, basemins = 5):
                        Screen.__init__(self, session)
                                                
-                       self["minutes"] = Label()
-                       self.updateValue(basemins)
+                       self["minutes"] = Input(str(basemins), type=Input.NUMBER)
                        
                        
-                       self["actions"] = NumberActionMap([ "NumberZapActions", "MinuteInputActions" ],
+                       self["actions"] = NumberActionMap([ "InputActions" , "MinuteInputActions" ],
                        {
                                "1": self.keyNumberGlobal,
                                "2": self.keyNumberGlobal,
                        {
                                "1": self.keyNumberGlobal,
                                "2": self.keyNumberGlobal,
@@ -25,29 +25,32 @@ class MinuteInput(Screen):
                                "8": self.keyNumberGlobal,
                                "9": self.keyNumberGlobal,
                                "0": self.keyNumberGlobal,
                                "8": self.keyNumberGlobal,
                                "9": self.keyNumberGlobal,
                                "0": self.keyNumberGlobal,
+                               "left": self.left,
+                               "right": self.right,
                                "up": self.up,
                                "down": self.down,
                                "ok": self.ok,
                                "cancel": self.cancel
                        })
                        
                                "up": self.up,
                                "down": self.down,
                                "ok": self.ok,
                                "cancel": self.cancel
                        })
                        
-               def updateValue(self, minutes):
-                       self.minutes = minutes
-                       self["minutes"].setText(str(self.minutes) + _(" mins"))
-                       
                def keyNumberGlobal(self, number):
                def keyNumberGlobal(self, number):
-                       #self.updateValue(self.minutes * 10 + number)
+                       self["minutes"].number(number)
                        pass
                        
                        pass
                        
+               def left(self):
+                       self["minutes"].left()
+                       
+               def right(self):
+                       self["minutes"].right()
+                       
                def up(self):
                def up(self):
-                       self.updateValue(self.minutes + 1)
+                       self["minutes"].up()
                
                def down(self):
                
                def down(self):
-                       if self.minutes > 0:
-                               self.updateValue(self.minutes - 1)
+                       self["minutes"].down()
                                
                def ok(self):
                                
                def ok(self):
-                       self.close(self.minutes)
+                       self.close(int(self["minutes"].getText()))
                        
                def cancel(self):
                        self.close(0)
\ No newline at end of file
                        
                def cancel(self):
                        self.close(0)
\ No newline at end of file