plugin api change: Plugins() and main functions must receive (and possibly ignore...
[enigma2.git] / lib / python / Plugins / SystemPlugins / PositionerSetup / plugin.py
1 from enigma import eTimer, eDVBSatelliteEquipmentControl
2 from Screens.Screen import Screen
3 from Plugins.Plugin import PluginDescriptor
4
5 from Components.Label import Label
6 from Components.ConfigList import ConfigList
7 from Components.ActionMap import ActionMap
8 from Components.config import config, ConfigSubsection, configElement_nonSave, configNothing, getConfigListEntry, configSelection
9
10 class PositionerSetup(Screen):
11         skin = """
12                 <screen position="100,100" size="560,400" title="Positioner setup..." >
13                         <widget name="red" position="0,100" size="140,80" backgroundColor="red" halign="center" valign="center" font="Regular;21" />
14                         <widget name="green" position="140,100" size="140,80" backgroundColor="green" halign="center" valign="center" font="Regular;21" />
15                         <widget name="yellow" position="280,100" size="140,80" backgroundColor="yellow" halign="center" valign="center" font="Regular;21" />
16                         <widget name="blue" position="420,100" size="140,80" backgroundColor="blue" halign="center" valign="center" font="Regular;21" />
17                         <widget name="status" position="0,200" size="550,40" font="Regular;15" />
18                         <widget name="list" position="100,0" size="350,100" />
19                 </screen>"""
20         def __init__(self, session):
21                 self.skin = PositionerSetup.skin
22                 Screen.__init__(self, session)
23                 
24                 self.createConfig()
25                 
26                 self.status = Label("")
27                 self["status"] = self.status
28                 
29                 self.red = Label("")
30                 self["red"] = self.red
31                 self.green = Label("")
32                 self["green"] = self.green
33                 self.yellow = Label("")
34                 self["yellow"] = self.yellow
35                 self.blue = Label("")
36                 self["blue"] = self.blue
37
38                 self.list = []
39                 self["list"] = ConfigList(self.list)
40                 self.createSetup()
41
42                 self["actions"] = ActionMap(["DirectionActions", "OkCancelActions", "ColorActions"],
43                 {
44                         "ok": self.go,
45                         "cancel": self.close,
46                         "up": self.up,
47                         "down": self.down,
48                         "left": self.left,
49                         "right": self.right,
50                         "red": self.redKey,
51                         "green": self.greenKey,
52                         "yellow": self.yellowKey,
53                         "blue": self.blueKey,
54                 }, -1)
55                 
56                 self.updateColors("move")
57                 
58                 self.statusTimer = eTimer()
59                 self.statusTimer.timeout.get().append(self.updateStatus)
60                 self.statusTimer.start(500, False)
61                 
62         def createConfig(self):
63                 config.positioner = ConfigSubsection()
64                 config.positioner.move = configElement_nonSave("move", configNothing, 0, None)
65                 config.positioner.limits = configElement_nonSave("limits", configNothing, 0, None)
66                 config.positioner.storage = configElement_nonSave("storage", configSelection, 0, ("1", "2", "3"))
67         
68         def createSetup(self):
69                 self.list.append(getConfigListEntry(_("Positioner movement"), config.positioner.move))
70                 self.list.append(getConfigListEntry(_("Set limits"), config.positioner.limits))
71                 self.list.append(getConfigListEntry(_("Positioner storage"), config.positioner.storage))
72                 
73                 self["list"].l.setList(self.list)
74                 
75         def go(self):
76                 pass
77         
78         def up(self):
79                 self["list"].instance.moveSelection(self["list"].instance.moveUp)
80                 self.updateColors(self["list"].getCurrent()[1].parent.configPath)
81         
82         def down(self):
83                 self["list"].instance.moveSelection(self["list"].instance.moveDown)
84                 self.updateColors(self["list"].getCurrent()[1].parent.configPath)
85         
86         def left(self):
87                 self["list"].handleKey(config.key["prevElement"])
88         
89         def right(self):
90                 self["list"].handleKey(config.key["nextElement"])
91         
92         def updateColors(self, entry):
93                 if entry == "move":
94                         self.red.setText(_("Move east"))
95                         self.green.setText(_("Step east"))
96                         self.yellow.setText(_("Step west"))
97                         self.blue.setText(_("Move west"))
98                 elif entry == "limits":
99                         self.red.setText(_("Limits off"))
100                         self.green.setText(_("Limit east"))
101                         self.yellow.setText(_("Limit west"))
102                         self.blue.setText("")
103                 elif entry == "storage":
104                         self.red.setText(_("Apply satellite"))
105                         self.green.setText(_("Store position"))
106                         self.yellow.setText(_("Goto position"))
107                         self.blue.setText("")
108                 else:
109                         self.red.setText("")
110                         self.green.setText("")
111                         self.yellow.setText("")
112                         self.blue.setText("")
113         
114         def redKey(self):
115                 print "red"
116         
117         def greenKey(self):
118                 pass
119         
120         def yellowKey(self):
121                 pass
122         
123         def blueKey(self):
124                 pass
125
126         def updateStatus(self):
127                 if eDVBSatelliteEquipmentControl.getInstance().isRotorMoving():
128                         self.status.setText("moving...")
129                 else:
130                         self.status.setText("not moving")
131                 
132 def PositionerMain(session, **kwargs):
133         session.open(PositionerSetup)
134
135 def Plugins(**kwargs):
136         return PluginDescriptor(name="Positioner setup", description="Setup your positioner", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=PositionerMain)