EPGSearch: improvements on texts to make them better understandable
[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 from Components.config import ConfigSelection, NoSave
6
7 # GUI (Summary)
8 from Screens.Setup import SetupSummary
9 from Screens.InfoBar import InfoBar
10
11 # GUI (Components)
12 from Components.ActionMap import ActionMap
13 from Components.Sources.StaticText import StaticText
14
15 # Configuration
16 from Components.config import config, getConfigListEntry
17
18 class EPGSearchSetup(Screen, ConfigListScreen):
19         skin = """<screen name="EPGSearchSetup" position="center,120" size="820,520">
20                 <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="200,40"/>
21                 <ePixmap pixmap="skin_default/buttons/green.png" position="210,5" size="200,40"/>
22                 <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"/>
23                 <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"/>
24                 <eLabel position="10,50" size="800,1" backgroundColor="grey"/>
25                 <widget name="config" position="10,60" size="800,350" enableWrapAround="1" scrollbarMode="showOnDemand"/>
26                 <eLabel position="10,420" size="800,1" backgroundColor="grey"/>
27                 <widget source="help" render="Label" position="10,430" size="800,80" font="Regular;21" />
28                 </screen>"""
29
30         def __init__(self, session):
31                 Screen.__init__(self, session)
32
33                 # Summary
34                 self.setup_title = _("EPGSearch Setup")
35                 self.onChangedEntry = []
36
37                 #set config-values for search_scope-config
38                 self.scopeChoices = self.getScopeChoices()
39                 self.scopeChoices_default = self.getScopeChoicesDefault()
40                 self.config_search_scope = NoSave( ConfigSelection(choices=self.scopeChoices, default=self.scopeChoices_default) )
41
42                 self.list = []
43                 self.buildConfig()
44                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
45
46                 def selectionChanged():
47                         if self["config"].current:
48                                 self["config"].current[1].onDeselect(self.session)
49                         self["config"].current = self["config"].getCurrent()
50                         if self["config"].current:
51                                 self["config"].current[1].onSelect(self.session)
52                         for x in self["config"].onSelectionChanged:
53                                 x()
54                 self["config"].selectionChanged = selectionChanged
55                 self["config"].onSelectionChanged.append(self.updateHelp)
56
57                 # Initialize widgets
58                 self["key_green"] = StaticText(_("OK"))
59                 self["key_red"] = StaticText(_("Cancel"))
60                 self["help"] = StaticText()
61
62                 # Define Actions
63                 self["actions"] = ActionMap(["SetupActions"],
64                         {
65                                 "cancel": self.keyCancel,
66                                 "save": self.keySave,
67                         }
68                 )
69
70                 # Trigger change
71                 self.changed()
72
73                 self.onLayoutFinish.append(self.setCustomTitle)
74
75         def buildConfig(self):
76                 self.list.append( getConfigListEntry(_("Length of History"), config.plugins.epgsearch.history_length, _("How many entries to keep in the search history at most. 0 disables history entirely!")) )
77                 self.list.append( getConfigListEntry(_("Add search text to history when opening the plugin"), config.plugins.epgsearch.add_history_onOpen , _("Add the search text to the history when opening the plugin.")) )
78                 self.list.append( 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.")) )
79                 self.list.append( getConfigListEntry(_("Search type"), config.plugins.epgsearch.search_type, _("Select \"exact\" match to enforce \"Match title\" to match exactly, \"partial\" if you only want to search for a part of the event title or description or \"Ask user\"")) )
80                 self.list.append( getConfigListEntry(_("Search scope"), self.config_search_scope, _("Search will return only matches from services in the selected bouquet")) )
81                 if self.config_search_scope.value != "all":
82                         self.list.append( getConfigListEntry(_("show events"), config.plugins.epgsearch.show_events, _("Show 'all', 'current', 'future' or 'current & future' events. So you can filter the matches by the event time.")) )
83                 self.list.append( getConfigListEntry(_("Show Picons"), config.plugins.epgsearch.show_picon, _("Show the the picon of the channel instead of channelname. Use the picon-path from channelselection settings.")) )
84                 if not config.plugins.epgsearch.show_picon.value:
85                         self.list.append( getConfigListEntry(_("show best matching channelname in screen title"), config.plugins.epgsearch.show_sname_in_title, _("Show the best matching channelname in the screen title. So you have more space to show event name and short description.")) )
86                 self.list.append( getConfigListEntry(_("show short description"), config.plugins.epgsearch.show_shortdesc, _("Add the short description of the event to the search result")) )
87
88         def getScopeChoicesDefault(self):
89                 scopeChoices_default = "all"
90
91                 for choice in self.scopeChoices:
92                         if config.plugins.epgsearch.search_scope.value == choice[0]:
93                                 scopeChoices_default = config.plugins.epgsearch.search_scope.value
94                                 break
95
96                 return scopeChoices_default
97
98         def getScopeChoices(self):
99                 #set config-values for bouquet-config
100                 config_scope_choices = [("all",_("all services")), ("current",_("current bouquet"))]
101
102                 #get bouquetlist
103                 infoBarInstance = InfoBar.instance
104                 if infoBarInstance is not None:
105                         bouquets = infoBarInstance.servicelist.getBouquetList()
106                         for bouquet in bouquets:
107                                 config_scope_choices.append((bouquet[1].toString(),bouquet[0]))
108
109                 return config_scope_choices
110
111         def keySave(self):
112                 self.saveAll()
113                 #config.plugins.epgsearch.search_current_bouquet.value = self.config_search_current_bouquet.value
114                 config.plugins.epgsearch.search_scope.value = self.config_search_scope.value
115                 config.plugins.epgsearch.save()
116                 self.close()
117
118         def changeConfig(self):
119                 self.list = []
120                 self.buildConfig()
121                 self["config"].setList(self.list)
122
123         def changed(self):
124                 for x in self.onChangedEntry:
125                         x()
126                 current = self["config"].getCurrent()[1]
127                 if (current == config.plugins.epgsearch.show_picon) or (current == self.config_search_scope):
128                         self.changeConfig()
129                         return
130
131         def setCustomTitle(self):
132                 self.setTitle(_("EPGSearch Setup"))
133
134         def updateHelp(self):
135                 cur = self["config"].getCurrent()
136                 if cur:
137                         self["help"].text = cur[2]
138
139         def getCurrentEntry(self):
140                 return self["config"].getCurrent()[0]
141
142         def getCurrentValue(self):
143                 return str(self["config"].getCurrent()[1].getText())
144
145         def createSummary(self):
146                 return SetupSummary