From 9a1eb9bbf5d26648c761459ec7019f9c6eae24d7 Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Mon, 25 Apr 2005 23:12:23 +0000 Subject: [PATCH] - add new listbox content type for multiple strings - add first version of config class - a bit ugly --- components.py | 58 +++++++++++++++++++++++++++++++++++++ lib/gui/elistboxcontent.cpp | 51 ++++++++++++++++++++++++++++++++ lib/gui/elistboxcontent.h | 15 ++++++++-- screens.py | 25 ++++++++++++++-- skin.py | 3 ++ 5 files changed, 147 insertions(+), 5 deletions(-) diff --git a/components.py b/components.py index af0fbffa..6f19a623 100644 --- a/components.py +++ b/components.py @@ -38,6 +38,8 @@ class GUISkin: except: pass + # DIESER KOMMENTAR IST NUTZLOS UND MITTLERWEILE VERALTET! (glaub ich) + # BITTE NICHT LESEN! # note: you'll probably run into this assert. if this happens, don't panic! # yes, it's evil. I told you that programming in python is just fun, and # suddently, you have to care about things you don't even know. @@ -273,6 +275,62 @@ class MenuList(HTMLComponent, GUIComponent): self.instance.setContent(None) del self.instance + +# temp stuff :) +class configBoolean: + def __init__(self, reg): + self.reg = reg + self.val = 0 + + def toggle(self): + self.val += 1 + self.val %= 3 + + def __str__(self): + return ("NO", "YES", "MAYBE")[self.val] + +class configValue: + def __init__(self, obj): + self.obj = obj + + def __str__(self): + return self.obj + +def configEntry(obj): + # das hier ist ein zugriff auf die registry... + if obj == "HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/SDTV/FLASHES/GREEN": + return ("SDTV green flashes", configBoolean(obj)) + elif obj == "HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/HDTV/FLASHES/GREEN": + return ("HDTV reen flashes", configBoolean(obj)) + else: + return ("invalid", "") + +class ConfigList(HTMLComponent, GUIComponent): + def __init__(self, list): + GUIComponent.__init__(self) + self.l = eListboxPythonConfigContent() + self.l.setList(list) + self.l.setSeperation(100) + + def toggle(self): + selection = self.getCurrent() + selection[1].toggle() + self.invalidateCurrent() + + def getCurrent(self): + return self.l.getCurrentSelection() + + def invalidateCurrent(self): + self.l.invalidateEntry(self.l.getCurrentSelectionIndex()) + + def GUIcreate(self, parent, skindata): + self.instance = eListbox(parent) + self.instance.setContent(self.l) + + def GUIdelete(self): + self.instance.setContent(None) + del self.instance + class ServiceList(HTMLComponent, GUIComponent): def __init__(self): GUIComponent.__init__(self) diff --git a/lib/gui/elistboxcontent.cpp b/lib/gui/elistboxcontent.cpp index 209b5250..d51729d2 100644 --- a/lib/gui/elistboxcontent.cpp +++ b/lib/gui/elistboxcontent.cpp @@ -378,3 +378,54 @@ PyObject *eListboxPythonStringContent::getCurrentSelection() } ////////////////////////////////////// + +void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected) +{ + ePtr fnt = new gFont("Arial", 14); + ePtr fnt2 = new gFont("Arial", 16); + painter.clip(eRect(offset, m_itemsize)); + style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal); + painter.clear(); + + if (m_list && cursorValid()) + { + PyObject *item = PyList_GetItem(m_list, m_cursor); // borrowed reference! + PyObject *text = 0, *value = 0; + painter.setFont(fnt); + + /* the user can supply tuples, in this case the first one will be displayed. */ + if (PyTuple_Check(item)) + { + text = PyTuple_GetItem(item, 0); + value = PyTuple_GetItem(item, 1); + } + + text = PyObject_Str(text); + value = PyObject_Str(value); + + const char *string = (text && PyString_Check(text)) ? PyString_AsString(text) : ""; + const char *string_val = (value && PyString_Check(value)) ? PyString_AsString(value) : ""; + + eSize item_left = eSize(m_seperation, m_itemsize.height()); + eSize item_right = eSize(m_itemsize.width() - m_seperation, m_itemsize.height()); + + painter.renderText(eRect(offset, item_left), string, gPainter::RT_HALIGN_LEFT); + + painter.setFont(fnt2); + painter.renderText(eRect(offset + eSize(m_seperation, 0), item_right), string_val, gPainter::RT_HALIGN_RIGHT); + + Py_XDECREF(text); + Py_XDECREF(value); + + if (selected) + style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry); + } + + painter.clippop(); +} + +void eListboxPythonConfigContent::invalidateEntry(int index) +{ + m_listbox->entryChanged(index); +} + diff --git a/lib/gui/elistboxcontent.h b/lib/gui/elistboxcontent.h index a2e1fd36..0c4cb001 100644 --- a/lib/gui/elistboxcontent.h +++ b/lib/gui/elistboxcontent.h @@ -82,6 +82,7 @@ public: void setList(PyObject *list); PyObject *getCurrentSelection(); + int getCurrentSelectionIndex() { return m_cursor; } #ifndef SWIG protected: void cursorHome(); @@ -101,13 +102,23 @@ protected: void setSize(const eSize &size); /* the following functions always refer to the selected item */ - void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected); + virtual void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected); -private: +protected: PyObject *m_list; int m_cursor, m_saved_cursor; eSize m_itemsize; #endif }; +class eListboxPythonConfigContent: public eListboxPythonStringContent +{ +public: + void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected); + void invalidateEntry(int index); + void setSeperation(int sep) { m_seperation = sep; } +private: + int m_seperation; +}; + #endif diff --git a/screens.py b/screens.py index fe8d69db..98cc7cbb 100644 --- a/screens.py +++ b/screens.py @@ -38,10 +38,29 @@ class Screen(dict, HTMLSkin, GUISkin): def close(self, retval=None): self.session.close() +class configTest(Screen): + + def __init__(self, session): + Screen.__init__(self, session) + + + self["config"] = ConfigList( + [ + configEntry("HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/SDTV/FLASHES/GREEN"), + configEntry("HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/HDTV/FLASHES/GREEN"), + ]) + + self["actions"] = ActionMap(["OkCancelActions"], + { + "ok": self["config"].toggle, + "cancel": self.close + }) + + class mainMenu(Screen): - def goEmu(self): - self["title"].setText("EMUs ARE ILLEGAL AND NOT SUPPORTED!") + def goSetup(self): + self.session.open(configTest) def goTimeshift(self): self["title"].setText("JUST PRESS THE YELLOW BUTTON!") @@ -77,7 +96,7 @@ class mainMenu(Screen): ("Close Main Menu", self.close), ("Service Scan", self.goScan), ("Quit", quitMainloop), - ("EMU SETUP", self.goEmu), + ("setup", self.goSetup), ("TIMESHIFT SETUP", self.goTimeshift), ("HDTV PIP CONFIG", self.goHDTV), ("wie spaet ists?!", self.goClock) diff --git a/skin.py b/skin.py index 2e913a08..1fa565f2 100644 --- a/skin.py +++ b/skin.py @@ -46,6 +46,9 @@ dom = xml.dom.minidom.parseString( + + + -- 2.30.2