2 from enigma import eEPGCache, eServiceReference
4 from Screens.EpgSelection import EPGSelection
5 from Screens.InputBox import InputBox
6 from Screens.ChoiceBox import ChoiceBox
8 from Components.config import config
10 class EPGSearch(EPGSelection):
11 def __init__(self, session):
12 EPGSelection.__init__(self, session, '') # Empty string serviceref so we get EPG_TYPE_SINGLE
13 self.skinName = "EPGSelection"
15 # XXX: we lose sort begin/end here
16 self["key_yellow"].setText(_("New Search"))
17 self["key_blue"].setText(_("History"))
25 def closeScreen(self):
27 config.plugins.epgsearch.save()
28 EPGSelection.closeScreen(self)
30 def yellowButtonPressed(self):
31 self.session.openWithCallback(
34 title = _("Enter text to search for")
37 def blueButtonPressed(self):
38 self.session.openWithCallback(
39 self.searchEPGWrapper,
41 title = _("Select text to search for"),
42 list = [(x, x) for x in config.plugins.epgsearch.history.value]
45 def searchEPGWrapper(self, ret):
47 self.searchEPG(ret[1])
49 # Yeah, the encoding stuff is still pretty bad :-)
50 def searchEPG(self, searchString):
53 history = config.plugins.epgsearch.history.value
54 if searchString not in history:
55 history.insert(0, searchString)
59 history.remove(searchString)
60 history.insert(0, searchString)
62 # Workaround to allow search for umlauts if we know the encoding
63 encoding = config.plugins.epgsearch.encoding.value
64 if encoding != 'UTF-8':
66 searchString = searchString.decode('UTF-8', 'replace').encode(encoding)
67 except UnicodeDecodeError:
70 # Search EPG, default to empty list
71 epgcache = eEPGCache.getInstance() # XXX: the EPGList also keeps an instance of the cache but we better make sure that we get what we want :-)
72 ret = epgcache.search(('RIBDT', 200, eEPGCache.PARTIAL_TITLE_SEARCH, searchString, eEPGCache.NO_CASE_CHECK)) or []