Fixed very useful TestPlugin-plugin (callback wasn't called correctly)
[enigma2.git] / lib / python / Plugins / DemoPlugins / TestPlugin / plugin.py
1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Components.ActionMap import NumberActionMap
4 from Components.Input import Input
5 from Components.Pixmap import Pixmap
6 from Components.FileList import FileList
7 from Screens.ChoiceBox import ChoiceBox
8 from Plugins.Plugin import PluginDescriptor
9
10 class Test(Screen):
11         skin = """
12                 <screen position="100,100" size="550,400" title="Test" >
13                         <!--widget name="text" position="0,0" size="550,25" font="Regular;20" /-->
14                         <widget name="list" position="10,0" size="190,250" scrollbarMode="showOnDemand" />
15                         <widget name="pixmap" position="200,0" size="190,250" />
16                 </screen>"""
17         def __init__(self, session, args = None):
18                 self.skin = Test.skin
19                 Screen.__init__(self, session)
20
21                 self["list"] = FileList("/", matchingPattern = "^.*\.(png|avi|mp3|mpeg|ts)")
22                 self["pixmap"] = Pixmap()
23                 
24                 #self["text"] = Input("1234", maxSize=True, type=Input.NUMBER)
25                                 
26                 self["actions"] = NumberActionMap(["WizardActions", "InputActions"],
27                 {
28                         "ok": self.openTest,
29                         "back": self.close,
30 #                       "left": self.keyLeft,
31 #                       "right": self.keyRight,
32                         "1": self.keyNumberGlobal,
33                         "2": self.keyNumberGlobal,
34                         "3": self.keyNumberGlobal,
35                         "4": self.keyNumberGlobal,
36                         "5": self.keyNumberGlobal,
37                         "6": self.keyNumberGlobal,
38                         "7": self.keyNumberGlobal,
39                         "8": self.keyNumberGlobal,
40                         "9": self.keyNumberGlobal,
41                         "0": self.keyNumberGlobal
42                 }, -1)
43                 
44                 #self.onShown.append(self.openTest)
45
46         def openTest(self):
47                 self.session.openWithCallback(self.mycallback, MessageBox, _("Test-Messagebox?"))
48
49 #               self.session.open(InputBox)
50         
51         def mycallback(self, answer):
52                 print "answer:", answer
53                 self.close()
54         
55         def keyLeft(self):
56                 self["text"].left()
57         
58         def keyRight(self):
59                 self["text"].right()
60         
61         def ok(self):
62                 selection = self["list"].getSelection()
63                 if selection[1] == True: # isDir
64                         self["list"].changeDir(selection[0])
65                 else:
66                         self["pixmap"].instance.setPixmapFromFile(selection[0])
67         
68         def keyNumberGlobal(self, number):
69                 print "pressed", number
70                 self["text"].number(number)
71
72 def main(session, **kwargs):
73         session.open(Test)
74         #session.openWithCallback(test, MessageBox, _("Test-Messagebox?"), timeout = 10)
75         #session.openWithCallback(test, ChoiceBox, title="Delete everything on this Dreambox?", list=[(_("yes"), "yes"), (_("no"), "no"), (_("perhaps"), "perhaps"), (_("ask me tomorrow"), "ask me tomorrow"), (_("leave me alone with this!"), "yes")])
76         
77 def test(returnValue):
78         print "You entered", returnValue
79
80 def Plugins(**kwargs):
81         return PluginDescriptor(name="Test", description="plugin to test some capabilities", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)