From ee0903f520403c5e03caef287f813e7b062d05ab Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Sat, 17 Jun 2006 16:48:40 +0000 Subject: [PATCH] add some new (currently unused) source/renderer based elements --- lib/python/Components/Converter/Converter.py | 20 +---- lib/python/Components/Converter/Makefile.am | 3 +- lib/python/Components/Converter/StringList.py | 40 ++++++++++ lib/python/Components/Element.py | 30 +++++++ lib/python/Components/Makefile.am | 4 +- lib/python/Components/Renderer/Label.py | 9 +-- lib/python/Components/Renderer/Listbox.py | 79 +++++++++++++++++++ lib/python/Components/Renderer/Makefile.am | 4 +- lib/python/Components/Renderer/Progress.py | 11 +-- lib/python/Components/Renderer/Renderer.py | 7 ++ lib/python/Components/Sources/Clock.py | 7 +- lib/python/Components/Sources/EventInfo.py | 2 +- lib/python/Components/Sources/Makefile.am | 3 +- lib/python/Components/Sources/MenuList.py | 40 ++++++++++ lib/python/Components/Sources/Source.py | 3 +- lib/python/Tools/CList.py | 7 ++ lib/python/Tools/Makefile.am | 3 +- 17 files changed, 229 insertions(+), 43 deletions(-) create mode 100644 lib/python/Components/Converter/StringList.py create mode 100644 lib/python/Components/Element.py create mode 100644 lib/python/Components/Renderer/Listbox.py create mode 100644 lib/python/Components/Renderer/Renderer.py create mode 100644 lib/python/Components/Sources/MenuList.py create mode 100644 lib/python/Tools/CList.py diff --git a/lib/python/Components/Converter/Converter.py b/lib/python/Components/Converter/Converter.py index b75d253f..3f054c12 100644 --- a/lib/python/Components/Converter/Converter.py +++ b/lib/python/Components/Converter/Converter.py @@ -1,18 +1,4 @@ -from Tools.Event import Event +from Components.Element import Element -class Converter: - def __init__(self): - self.changed = Event(start = self.start, stop = self.stop) - - def connect(self, source): - source.changed.listen(self.changed) - self.source = source - - def disconnect(self): - self.source.changed.unlisten(self.changed) - - def start(self): - pass - - def stop(self): - pass +class Converter(Element): + pass diff --git a/lib/python/Components/Converter/Makefile.am b/lib/python/Components/Converter/Makefile.am index c2e55eef..5b55ac42 100644 --- a/lib/python/Components/Converter/Makefile.am +++ b/lib/python/Components/Converter/Makefile.am @@ -2,4 +2,5 @@ installdir = $(LIBDIR)/enigma2/python/Components/Converter install_PYTHON = \ __init__.py ClockToText.py Converter.py EventName.py StaticText.py EventTime.py \ - Poll.py RemainingToText.py + Poll.py RemainingToText.py StringList.py + diff --git a/lib/python/Components/Converter/StringList.py b/lib/python/Components/Converter/StringList.py new file mode 100644 index 00000000..31dbcd3c --- /dev/null +++ b/lib/python/Components/Converter/StringList.py @@ -0,0 +1,40 @@ +from Converter import Converter +from enigma import eListboxPythonStringContent + + +class StringList(Converter): + """Turns a simple python list into a list which can be used in a listbox.""" + def __init__(self, *args, **kwargs): + Converter.__init__(self) + + def changed(self): + self.content = eListboxPythonStringContent() + if self.source: + self.content.setList(self.source.list) + self.downstream_elements.changed() + + def selectionChanged(self, index): + self.upstream_elements.selectionChanged(index) + # update all non-master targets + for x in self.downstream_elements: + if x is not self.master: + x.index = index + + def getCurrent(self): + if self.source is None: + return None + return self.source.list[self.index] + + current = property(getCurrent) + + # pass through: getIndex / setIndex to master + def getIndex(self): + if self.master is None: + return None + return self.master.index + + def setIndex(self, index): + if self.master is not None: + self.master.index = index + + index = property(getIndex, setIndex) diff --git a/lib/python/Components/Element.py b/lib/python/Components/Element.py new file mode 100644 index 00000000..6f812b20 --- /dev/null +++ b/lib/python/Components/Element.py @@ -0,0 +1,30 @@ +from Tools.CList import CList + +# down up +# Render Converter Converter Source + +# a bidirectional connection +class Element: + def __init__(self): + self.downstream_elements = CList() + self.upstream_elements = CList() + self.master = None + self.source = None + + def connectDownstream(self, downstream): + self.downstream_elements.append(downstream) + if self.master is None: + self.master = downstream + + def connectUpstream(self, upstream): + self.upstream_elements.append(upstream) + self.source = upstream # for single-source elements (i.e., most of them.) + self.changed() + + def connect(self, upstream): + self.connectUpstream(upstream) + upstream.connectDownstream(self) + + # default action: push downstream + def changed(self): + self.downstream_elements.changed() diff --git a/lib/python/Components/Makefile.am b/lib/python/Components/Makefile.am index ab334cd6..af8d1b9c 100644 --- a/lib/python/Components/Makefile.am +++ b/lib/python/Components/Makefile.am @@ -15,4 +15,6 @@ install_PYTHON = \ BlinkingPixmap.py Pixmap.py ConditionalWidget.py Slider.py LanguageList.py \ PluginList.py PluginComponent.py RecordingConfig.py About.py UsageConfig.py \ FIFOList.py ServiceEventTracker.py Input.py TimerSanityCheck.py FileList.py \ - MultiContent.py MediaPlayer.py TunerInfo.py VideoWindow.py ChoiceList.py + MultiContent.py MediaPlayer.py TunerInfo.py VideoWindow.py ChoiceList.py \ + Element.py + diff --git a/lib/python/Components/Renderer/Label.py b/lib/python/Components/Renderer/Label.py index 02acb938..1d06a214 100644 --- a/lib/python/Components/Renderer/Label.py +++ b/lib/python/Components/Renderer/Label.py @@ -1,18 +1,17 @@ from Components.VariableText import VariableText -from Components.GUIComponent import GUIComponent +from Renderer import Renderer from enigma import eLabel -class Label(VariableText, GUIComponent): +class Label(VariableText, Renderer): def __init__(self): - GUIComponent.__init__(self) + Renderer.__init__(self) VariableText.__init__(self) GUI_WIDGET = eLabel def connect(self, source): - source.changed.listen(self.changed) - self.source = source + Renderer.connect(self, source) self.changed() def changed(self): diff --git a/lib/python/Components/Renderer/Listbox.py b/lib/python/Components/Renderer/Listbox.py new file mode 100644 index 00000000..fb787bfa --- /dev/null +++ b/lib/python/Components/Renderer/Listbox.py @@ -0,0 +1,79 @@ +from Components.VariableText import VariableText +from Renderer import Renderer +from Tools.Event import Event + +from enigma import eListbox + +# the listbox renderer is the listbox, but no listbox content +# the content will be provided by the source (or converter). + +# the source should emit the 'changed' signal whenever +# it has a new listbox content. + +# the source needs to have the 'content' property for the +# used listbox content + +# it should expose exactly the non-content related functions +# of the eListbox class. more or less. + +class Listbox(Renderer, object): + def __init__(self): + Renderer.__init__(self) + self.__content = None + self.__wrap_around = False + self.__selection_enabled = True + + GUI_WIDGET = eListbox + + def contentChanged(self): + self.content = self.source.content + + def setContent(self, content): + self.__content = content + if self.instance is not None: + self.instance.setContent(self.__content) + + content = property(lambda self: self.__content, setContent) + + def postWidgetCreate(self, instance): + if self.__content is not None: + instance.setContent(self.__content) + instance.selectionChanged.get().append(self.selectionChanged) + self.wrap_around = self.wrap_around # trigger + self.selection_enabled = self.selection_enabled # trigger + + def setWrapAround(self, wrap_around): + self.__wrap_around = wrap_around + if self.instance is not None: + self.instance.setWrapAround(self.__wrap_around) + + wrap_around = property(lambda self: self.__wrap_around, setWrapAround) + + def selectionChanged(self): + self.upstream_elements.selectionChanged(self.index) + + def getIndex(self): + if self.instance is None: + return None + return self.instance.getCurrentIndex() + + def moveToIndex(self, index): + if self.instance is None: + return + self.instance.moveSelectionTo(index) + + index = property(getIndex, moveToIndex) + + def move(self, direction): + if self.instance is not None: + self.instance.moveSelection(direction) + + def setSelectionEnabled(self, enabled): + self.__selection_enabled = enabled + if self.instance is not None: + self.instance.setSelectionEnable(enabled) + + selection_enabled = property(lambda self: self.__selection_enabled, setSelectionEnabled) + + def changed(self): + self.content = self.source.content diff --git a/lib/python/Components/Renderer/Makefile.am b/lib/python/Components/Renderer/Makefile.am index 3040d72f..a8ca2939 100644 --- a/lib/python/Components/Renderer/Makefile.am +++ b/lib/python/Components/Renderer/Makefile.am @@ -1,4 +1,6 @@ installdir = $(LIBDIR)/enigma2/python/Components/Renderer install_PYTHON = \ - __init__.py Label.py Progress.py + __init__.py Label.py Progress.py Listbox.py Renderer.py + + diff --git a/lib/python/Components/Renderer/Progress.py b/lib/python/Components/Renderer/Progress.py index b8534287..9caea5e5 100644 --- a/lib/python/Components/Renderer/Progress.py +++ b/lib/python/Components/Renderer/Progress.py @@ -1,22 +1,17 @@ from Components.VariableValue import VariableValue -from Components.GUIComponent import GUIComponent +from Renderer import Renderer from enigma import eSlider -class Progress(VariableValue, GUIComponent): +class Progress(VariableValue, Renderer): def __init__(self): - GUIComponent.__init__(self) + Renderer.__init__(self) VariableValue.__init__(self) self.__start = 0 self.__end = 100 GUI_WIDGET = eSlider - def connect(self, source): - source.changed.listen(self.changed) - self.source = source - self.changed() - def changed(self): range = self.source.range or 100 value = self.source.value diff --git a/lib/python/Components/Renderer/Renderer.py b/lib/python/Components/Renderer/Renderer.py new file mode 100644 index 00000000..373aa02c --- /dev/null +++ b/lib/python/Components/Renderer/Renderer.py @@ -0,0 +1,7 @@ +from Components.GUIComponent import GUIComponent +from Components.Element import Element + +class Renderer(GUIComponent, Element): + def __init__(self): + Element.__init__(self) + GUIComponent.__init__(self) diff --git a/lib/python/Components/Sources/Clock.py b/lib/python/Components/Sources/Clock.py index f840ea24..608a7190 100644 --- a/lib/python/Components/Sources/Clock.py +++ b/lib/python/Components/Sources/Clock.py @@ -6,16 +6,11 @@ from Source import Source class Clock(Source): def __init__(self): - self.changed = Event(start=self.start, stop=self.stop) + Source.__init__(self) self.clock_timer = eTimer() self.clock_timer.timeout.get().append(self.changed) - - def start(self): self.clock_timer.start(1000) - def stop(self): - self.clock_timer.stop() - def getClock(self): return time.time() diff --git a/lib/python/Components/Sources/EventInfo.py b/lib/python/Components/Sources/EventInfo.py index 724d9c1f..fc420d83 100644 --- a/lib/python/Components/Sources/EventInfo.py +++ b/lib/python/Components/Sources/EventInfo.py @@ -8,7 +8,7 @@ class EventInfo(PerServiceBase, Source): NEXT = 1 def __init__(self, navcore, now_or_next): - self.changed = Event() + Source.__init__(self) PerServiceBase.__init__(self, navcore, { iPlayableService.evUpdatedEventInfo: self.ourEvent, diff --git a/lib/python/Components/Sources/Makefile.am b/lib/python/Components/Sources/Makefile.am index 3bf75d17..9e151123 100644 --- a/lib/python/Components/Sources/Makefile.am +++ b/lib/python/Components/Sources/Makefile.am @@ -1,4 +1,5 @@ installdir = $(LIBDIR)/enigma2/python/Components/Sources install_PYTHON = \ - __init__.py Clock.py EventInfo.py Source.py + __init__.py Clock.py EventInfo.py Source.py MenuList.py + diff --git a/lib/python/Components/Sources/MenuList.py b/lib/python/Components/Sources/MenuList.py new file mode 100644 index 00000000..98764418 --- /dev/null +++ b/lib/python/Components/Sources/MenuList.py @@ -0,0 +1,40 @@ +from Source import Source +from Tools.Event import Event + +class MenuList(Source, object): + def __init__(self, list = [ ], enableWrapAround = False): + Source.__init__(self) + self.__list = list + self.onSelectionChanged = [ ] + + def setList(self, list): + self.__list = list + self.changed() + + list = property(lambda self: self.__list, setList) + + def entry_changed(self, index): + self.downstream_elements.entry_changed(self, index) + + def selectionChanged(self, index): + for x in self.onSelectionChanged: + x() + + def getCurrent(self): + return self.master and self.master.current + + current = property(getCurrent) + + def setIndex(self, index): + if self.master is not None: + self.master = index + + def getIndex(self, index): + if self.master is not None: + return self.master.index + else: + return -1 + + setCurrentIndex = setIndex + + index = property(getIndex, setIndex) diff --git a/lib/python/Components/Sources/Source.py b/lib/python/Components/Sources/Source.py index 77fcb55f..49bbdbcf 100644 --- a/lib/python/Components/Sources/Source.py +++ b/lib/python/Components/Sources/Source.py @@ -1,5 +1,6 @@ -class Source(object): +from Components.Element import Element +class Source(Element): def execBegin(self): pass diff --git a/lib/python/Tools/CList.py b/lib/python/Tools/CList.py new file mode 100644 index 00000000..d820175c --- /dev/null +++ b/lib/python/Tools/CList.py @@ -0,0 +1,7 @@ +class CList(list): + def __getattr__(self, attr): + return CList([getattr(a, attr) for a in self]) + + def __call__(self, *args, **kwargs): + for x in self: + x(*args, **kwargs) diff --git a/lib/python/Tools/Makefile.am b/lib/python/Tools/Makefile.am index 2521cd97..4828e1fb 100644 --- a/lib/python/Tools/Makefile.am +++ b/lib/python/Tools/Makefile.am @@ -3,4 +3,5 @@ installdir = $(LIBDIR)/enigma2/python/Tools install_DATA = \ FuzzyDate.py XMLTools.py Directories.py NumericalTextInput.py \ KeyBindings.py BoundFunction.py ISO639.py Notifications.py __init__.py \ - RedirectOutput.py DreamboxHardware.py Import.py Event.py + RedirectOutput.py DreamboxHardware.py Import.py Event.py CList.py + -- 2.30.2