beautify messagebox
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Fri, 23 Dec 2005 05:19:57 +0000 (05:19 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Fri, 23 Dec 2005 05:19:57 +0000 (05:19 +0000)
add functionality to the messagebox

data/keymap.xml
data/skin.xml
lib/python/Plugins/Makefile.am
lib/python/Plugins/example.py
lib/python/Screens/HarddiskSetup.py
lib/python/Screens/InfoBarGenerics.py
lib/python/Screens/MessageBox.py
lib/python/Screens/MovieSelection.py

index a60935f..2462ef6 100644 (file)
        </map>
 
        <map context="MsgBoxActions">
        </map>
 
        <map context="MsgBoxActions">
-               <key id="KEY_GREEN" mapto="ok" flags="m" />
+               <key id="KEY_GREEN" mapto="alwaysOK" flags="m" />
                <key id="KEY_OK" mapto="ok" flags="m" />                
                <key id="KEY_RED" mapto="cancel" flags="m" />
                <key id="KEY_EXIT" mapto="cancel" flags="m" />
                <key id="KEY_OK" mapto="ok" flags="m" />                
                <key id="KEY_RED" mapto="cancel" flags="m" />
                <key id="KEY_EXIT" mapto="cancel" flags="m" />
index 4c1a25c..e8e8a9e 100644 (file)
                        <eLabel position="500,40" size="220,60" text="help..." font="Regular;50" />
                </screen>
                <screen name="MessageBox" position="0,300" size="720,10" title="Message">
                        <eLabel position="500,40" size="220,60" text="help..." font="Regular;50" />
                </screen>
                <screen name="MessageBox" position="0,300" size="720,10" title="Message">
-                       <widget name="text" position="0,35" size="650,0" font="Regular;22" />
-                       <widget name="key_red" position="0,0" size="140,30" backgroundColor="red" font="Regular;21" />
-                       <widget name="key_green" position="140,0" size="140,30" backgroundColor="green" font="Regular;21" />
+                       <widget name="text" position="60,10" size="650,0" font="Regular;22" />
+                       <widget name="ErrorPixmap" pixmap="/usr/share/enigma2/error.png" position="0,0" zPosition="3" size="53,53" alphatest="on" transparent="1" />
+                       <widget name="QuestionPixmap" pixmap="/usr/share/enigma2/question.png" position="0,0" zPosition="3" size="53,53" alphatest="on" transparent="1" />
+                       <widget name="list" position="100,100" size="550,375" />
                        <applet type="onLayoutFinish">
 # this should be factored out into some helper code, but currently demonstrates applets.
 from enigma import eSize, ePoint
                        <applet type="onLayoutFinish">
 # this should be factored out into some helper code, but currently demonstrates applets.
 from enigma import eSize, ePoint
@@ -283,8 +284,11 @@ textsize = self["text"].getSize()
 
 # y size still must be fixed in font stuff...
 textsize = (textsize[0] + 50, textsize[1] + 50)
 
 # y size still must be fixed in font stuff...
 textsize = (textsize[0] + 50, textsize[1] + 50)
-wsizex = textsize[0] + 50
-wsizey = textsize[1] + 50
+offset = 0
+if self.type == self.TYPE_YESNO:
+       offset = 60
+wsizex = textsize[0] + offset
+wsizey = textsize[1] + offset
 if (280 > wsizex):
        wsizex = 280
 wsize = (wsizex, wsizey)
 if (280 > wsizex):
        wsizex = 280
 wsize = (wsizex, wsizey)
@@ -296,6 +300,11 @@ self.instance.resize(eSize(*wsize))
 # resize label
 self["text"].instance.resize(eSize(*textsize))
 
 # resize label
 self["text"].instance.resize(eSize(*textsize))
 
+# move list
+listsize = (wsizex, 50)
+self["list"].instance.move(ePoint(0, textsize[1]))
+self["list"].instance.resize(eSize(*listsize))
+
 # center window
 newwidth = wsize[0]
 self.instance.move(ePoint(orgpos.x() + (orgwidth - newwidth)/2, orgpos.y()))
 # center window
 newwidth = wsize[0]
 self.instance.move(ePoint(orgpos.x() + (orgwidth - newwidth)/2, orgpos.y()))
index 6cf5ffa..610314d 100644 (file)
@@ -2,5 +2,5 @@ installdir = $(LIBDIR)/enigma2/python/Plugins
 
 install_PYTHON =       \
        __init__.py \
 
 install_PYTHON =       \
        __init__.py \
-       update.py 
+       update.py
 #      example.py 
 #      example.py 
index 5b96ee3..f201191 100644 (file)
@@ -1,5 +1,7 @@
 from enigma import *
 from Screens.Screen import Screen
 from enigma import *
 from Screens.Screen import Screen
+from Screens.MessageBox import MessageBox
+
 from Components.ActionMap import ActionMap
 from Components.Label import Label
 
 from Components.ActionMap import ActionMap
 from Components.Label import Label
 
@@ -13,16 +15,17 @@ class Example(Screen):
                self.skin = Example.skin
                Screen.__init__(self, session)
 
                self.skin = Example.skin
                Screen.__init__(self, session)
 
-               self["text"] = Label("Small test")
+               self["text"] = Label("Big test")
 
                self["actions"] = ActionMap(["WizardActions"], 
                {
 
                self["actions"] = ActionMap(["WizardActions"], 
                {
-                       "ok": self.ok
+                       "ok": self.ok,
+                       "back": self.close
                }, -1)
                
        def ok(self):
                }, -1)
                
        def ok(self):
-               self.close()
-               
+               self.session.open(MessageBox, "Bla bla bla bla bla bla bla bla\n bla bla bla bla bla bla\n bla bla bla bla bla bla\n bla bla bla bla bla", MessageBox.TYPE_YESNO)
+                               
 def main(session):
        session.open(Example)
        
 def main(session):
        session.open(Example)
        
index 72480ce..290d0ba 100644 (file)
@@ -44,7 +44,7 @@ class HarddiskSetup(Screen):
        def hddReady(self, result):
                print "Result: " + str(result)
                if (result != 0):
        def hddReady(self, result):
                print "Result: " + str(result)
                if (result != 0):
-                       self.session.open(MessageBox, _("Unable to initialize harddisk.\nPlease refer to the user manual.\nError: ") + str(self.hdd.errorList[0 - result]))
+                       self.session.open(MessageBox, _("Unable to initialize harddisk.\nPlease refer to the user manual.\nError: ") + str(self.hdd.errorList[0 - result]), MessageBox.TYPE_ERROR)
                else:
                        self.close()
                        
                else:
                        self.close()
                        
index 0fcb6ba..96d8587 100644 (file)
@@ -668,7 +668,7 @@ class InfoBarInstantRecord:
                try:
                        stat = os.stat("/hdd/movies")
                except:
                try:
                        stat = os.stat("/hdd/movies")
                except:
-                       self.session.open(MessageBox, "No HDD found!")
+                       self.session.open(MessageBox, "No HDD found!", MessageBox.TYPE_ERROR)
                        return
        
                if self.isInstantRecordRunning():
                        return
        
                if self.isInstantRecordRunning():
index 87da7f9..632c9bc 100644 (file)
@@ -2,21 +2,42 @@ from Screen import Screen
 from Components.ActionMap import ActionMap
 from Components.Label import Label
 from Components.Button import Button
 from Components.ActionMap import ActionMap
 from Components.Label import Label
 from Components.Button import Button
+from Components.Pixmap import Pixmap
+from Components.MenuList import MenuList
 from enigma import eSize, ePoint
 
 class MessageBox(Screen):
 from enigma import eSize, ePoint
 
 class MessageBox(Screen):
-       def __init__(self, session, text):
+       TYPE_YESNO = 0
+       TYPE_INFO = 1
+       TYPE_WARNING = 2
+       TYPE_ERROR = 3
+       
+       def __init__(self, session, text, type = TYPE_YESNO):
+               self.type = type
                Screen.__init__(self, session)
                
                self["text"] = Label(text)
                
                Screen.__init__(self, session)
                
                self["text"] = Label(text)
                
-               self["key_green"] = Button("OK")
-               self["key_red"] = Button("Exit")
+               self["ErrorPixmap"] = Pixmap()
+               self["QuestionPixmap"] = Pixmap()
+               
+               self.list = []
+               if type != self.TYPE_ERROR:
+                       self.onShown.append(self["ErrorPixmap"].hideWidget)
+               elif type != self.TYPE_YESNO:
+                       self.onShown.append(self["QuestionPixmap"].hideWidget)
+
+               if type == self.TYPE_YESNO:
+                       self.list = [ (_("yes"), 0), (_("no"), 1) ]
 
 
+
+               self["list"] = MenuList(self.list)
+               
                self["actions"] = ActionMap(["MsgBoxActions"], 
                        {
                                "cancel": self.cancel,
                self["actions"] = ActionMap(["MsgBoxActions"], 
                        {
                                "cancel": self.cancel,
-                               "ok": self.ok
+                               "ok": self.ok,
+                               "alwaysOK": self.alwaysOK
                        })
                        
        
                        })
                        
        
@@ -24,4 +45,10 @@ class MessageBox(Screen):
                self.close(False)
        
        def ok(self):
                self.close(False)
        
        def ok(self):
-               self.close(True)
+               if self.type == self.TYPE_YESNO:
+                       self.close(self["list"].getCurrent()[1] == 0)
+               else:
+                       self.close(True)
+
+       def alwaysOK(self):
+               self.close(True)
\ No newline at end of file
index ffa73c1..2ba2d05 100644 (file)
@@ -32,7 +32,7 @@ class ChannelContextMenu(FixedMenu):
                if result == True:
                        self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete this recording?"))
                else:
                if result == True:
                        self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete this recording?"))
                else:
-                       self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"))
+                       self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
 
        def deleteConfirmed(self, confirmed):
                if not confirmed:
 
        def deleteConfirmed(self, confirmed):
                if not confirmed:
@@ -47,7 +47,7 @@ class ChannelContextMenu(FixedMenu):
                                result = True
                
                if result == False:
                                result = True
                
                if result == False:
-                       self.session.openWithCallback(self.close, MessageBox, _("Delete failed!"))
+                       self.session.openWithCallback(self.close, MessageBox, _("Delete failed!"), MessageBox.TYPE_ERROR)
                else:
                        list = self.csel["list"]
                        currentIndex = list.getCurrentIndex()
                else:
                        list = self.csel["list"]
                        currentIndex = list.getCurrentIndex()