EPGSearch: allow preconfiguring sources to be searched, improve setup skin
[enigma2-plugins.git] / epgsearch / src / EPGSearchSetup.py
1 # for localized messages         
2 # GUI (Screens)
3 from Screens.Screen import Screen
4 from Components.ConfigList import ConfigListScreen
5
6 # GUI (Summary)
7 from Screens.Setup import SetupSummary
8
9 # GUI (Components)
10 from Components.ActionMap import ActionMap
11 from Components.Sources.StaticText import StaticText
12
13 # Configuration
14 from Components.config import config, getConfigListEntry
15
16 class EPGSearchSetup(Screen, ConfigListScreen):
17         skin = """<screen name="EPGSearchSetup" position="center,120" size="820,520">
18                 <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="200,40"/>
19                 <ePixmap pixmap="skin_default/buttons/green.png" position="210,5" size="200,40"/>
20                 <widget source="key_red" render="Label" position="10,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2"/>
21                 <widget source="key_green" render="Label" position="210,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2"/>
22                 <eLabel position="10,50" size="800,1" backgroundColor="grey"/>
23                 <widget name="config" position="10,60" size="800,350" enableWrapAround="1" scrollbarMode="showOnDemand"/>
24                 <eLabel position="10,420" size="800,1" backgroundColor="grey"/>
25                 <widget source="help" render="Label" position="10,430" size="800,80" font="Regular;21" />
26         </screen>"""
27
28         def __init__(self, session):
29                 Screen.__init__(self, session)
30
31                 # Summary
32                 self.setup_title = _("EPGSearch Setup")
33                 self.onChangedEntry = []
34
35                 ConfigListScreen.__init__(
36                         self,
37                         [
38                                 getConfigListEntry(_("Length of History"), config.plugins.epgsearch.history_length, _("How many entries to keep in the search history at most. 0 disables history entirely!")),
39                                 getConfigListEntry(_("Add \"Search\" Button to EPG"), config.plugins.epgsearch.add_search_to_epg , _("If this setting is enabled, the plugin adds a \"Search\" Button to the regular EPG.")),
40                                 getConfigListEntry(_("Sources used for searching"), config.plugins.epgsearch.search_type, _("Sources to search for the given text"))
41                         ],
42                         session = session,
43                         on_change = self.changed
44                 )
45                 def selectionChanged():
46                         if self["config"].current:
47                                 self["config"].current[1].onDeselect(self.session)
48                         self["config"].current = self["config"].getCurrent()
49                         if self["config"].current:
50                                 self["config"].current[1].onSelect(self.session)
51                         for x in self["config"].onSelectionChanged:
52                                 x()
53                 self["config"].selectionChanged = selectionChanged
54                 self["config"].onSelectionChanged.append(self.updateHelp)
55
56                 # Initialize widgets
57                 self["key_green"] = StaticText(_("OK"))
58                 self["key_red"] = StaticText(_("Cancel"))
59                 self["help"] = StaticText()
60
61                 # Define Actions
62                 self["actions"] = ActionMap(["SetupActions"],
63                         {
64                                 "cancel": self.keyCancel,
65                                 "save": self.keySave,
66                         }
67                 )
68
69                 # Trigger change
70                 self.changed()
71
72                 self.onLayoutFinish.append(self.setCustomTitle)
73
74         def setCustomTitle(self):
75                 self.setTitle(_("EPGSearch Setup"))
76
77         def updateHelp(self):
78                 cur = self["config"].getCurrent()
79                 if cur:
80                         self["help"].text = cur[2]
81
82         def changed(self):
83                 for x in self.onChangedEntry:
84                         x()
85
86         def getCurrentEntry(self):
87                 return self["config"].getCurrent()[0]
88
89         def getCurrentValue(self):
90                 return str(self["config"].getCurrent()[1].getText())
91
92         def createSummary(self):
93                 return SetupSummary
94