1 from enigma import eEPGCache, eServiceReference
3 from Screens.ChannelSelection import SimpleChannelSelection
4 from Screens.ChoiceBox import ChoiceBox
5 from Screens.EpgSelection import EPGSelection
6 from Screens.InputBox import InputBox
7 from Screens.Screen import Screen
9 from Components.ActionMap import ActionMap
10 from Components.Button import Button
11 from Components.config import config
12 from Components.TimerList import TimerList
14 class EPGSearch(EPGSelection):
15 def __init__(self, session):
16 EPGSelection.__init__(self, session, '') # Empty string serviceref so we get EPG_TYPE_SINGLE
17 self.skinName = "EPGSelection"
19 # XXX: we lose sort begin/end here
20 self["key_yellow"].setText(_("New Search"))
21 self["key_blue"].setText(_("History"))
29 def closeScreen(self):
31 config.plugins.epgsearch.save()
32 EPGSelection.closeScreen(self)
34 def yellowButtonPressed(self):
35 self.session.openWithCallback(
38 title = _("Enter text to search for")
41 def blueButtonPressed(self):
43 (_("From Timer"), "xxImportFromTimer"),
44 (_("From EPG"), "xxImportFromEPG")
46 options.extend([(x, x) for x in config.plugins.epgsearch.history.value])
48 self.session.openWithCallback(
49 self.searchEPGWrapper,
51 title = _("Select text to search for"),
55 def searchEPGWrapper(self, ret):
58 if ret is "xxImportFromTimer":
59 self.session.openWithCallback(
63 elif ret is "xxImportFromEPG":
64 self.session.openWithCallback(
66 EPGSearchChannelSelection
71 def searchEPG(self, searchString):
74 history = config.plugins.epgsearch.history.value
75 if searchString not in history:
76 history.insert(0, searchString)
80 history.remove(searchString)
81 history.insert(0, searchString)
83 # Workaround to allow search for umlauts if we know the encoding (pretty bad, I know...)
84 encoding = config.plugins.epgsearch.encoding.value
85 if encoding != 'UTF-8':
87 searchString = searchString.decode('UTF-8', 'replace').encode(encoding)
88 except UnicodeDecodeError:
91 # Search EPG, default to empty list
92 epgcache = eEPGCache.getInstance() # XXX: the EPGList also keeps an instance of the cache but we better make sure that we get what we want :-)
93 ret = epgcache.search(('RIBDT', 200, eEPGCache.PARTIAL_TITLE_SEARCH, searchString, eEPGCache.NO_CASE_CHECK)) or []
94 ret.sort(key = lambda x: x[2]) # sort by time
102 class EPGSearchTimerImport(Screen):
103 def __init__(self, session):
104 Screen.__init__(self, session)
105 self.skinName = "TimerEditList"
110 self["timerlist"] = TimerList(self.list)
112 self["key_red"] = Button(_("Cancel"))
113 self["key_green"] = Button(_("OK"))
114 self["key_yellow"] = Button("")
115 self["key_blue"] = Button("")
117 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
120 "cancel": self.cancel,
121 "green": self.search,
124 self.onLayoutFinish.append(self.setCustomTitle)
126 def setCustomTitle(self):
127 self.setTitle(_("Select a timer to search"))
129 def fillTimerList(self):
133 for timer in self.session.nav.RecordTimer.timer_list:
134 l.append((timer, False))
136 for timer in self.session.nav.RecordTimer.processed_timers:
137 l.append((timer, True))
138 l.sort(key = lambda x: x[0].begin)
141 cur = self["timerlist"].getCurrent()
148 class EPGSearchChannelSelection(SimpleChannelSelection):
149 def __init__(self, session):
150 SimpleChannelSelection.__init__(self, session, _("Channel Selection"))
151 self.skinName = "SimpleChannelSelection"
153 self["ChannelSelectEPGActions"] = ActionMap(["ChannelSelectEPGActions"],
155 "showEPGList": self.channelSelected
159 def channelSelected(self):
160 ref = self.getCurrentSelection()
161 if (ref.flags & 7) == 7:
163 elif not (ref.flags & eServiceReference.isMarker):
164 self.session.openWithCallback(
166 EPGSearchEPGSelection,
170 def epgClosed(self, ret = None):
174 class EPGSearchEPGSelection(EPGSelection):
175 def __init__(self, session, ref):
176 EPGSelection.__init__(self, session, ref)
177 self.skinName = "EPGSelection"
178 self["key_green"].setText(_("Search"))
180 def infoKeyPressed(self):
184 cur = self["list"].getCurrent()
190 self.close(evt.getEventName())