- add new listbox content type for multiple strings
authorFelix Domke <tmbinc@elitedvb.net>
Mon, 25 Apr 2005 23:12:23 +0000 (23:12 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Mon, 25 Apr 2005 23:12:23 +0000 (23:12 +0000)
 - add first version of config class - a bit ugly

components.py
lib/gui/elistboxcontent.cpp
lib/gui/elistboxcontent.h
screens.py
skin.py

index af0fbffa6441814ea8891ab6689e8225bedada39..6f19a623be7cffe7fb0428cb06cba195771ff788 100644 (file)
@@ -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)
index 209b525094537fd09cec612252f20f79a591a9c7..d51729d23cbc94ee419aa5d6a035e9c918f5302e 100644 (file)
@@ -378,3 +378,54 @@ PyObject *eListboxPythonStringContent::getCurrentSelection()
 }
 
 //////////////////////////////////////
+
+void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
+{
+       ePtr<gFont> fnt = new gFont("Arial", 14);
+       ePtr<gFont> 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) : "<not-a-string>";
+               const char *string_val = (value && PyString_Check(value)) ? PyString_AsString(value) : "<not-a-string>";
+               
+               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);
+}
+
index a2e1fd3630fe87f472cd66d456ce918b282283c8..0c4cb00120b6fc6e06311accf7a6f0e1f37ee15f 100644 (file)
@@ -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
index fe8d69dbdbe73522a393aae34734dbb48ae30b5d..98cc7cbb81b8a6c7b69a0e7d6c6e1bed9c36b320 100644 (file)
@@ -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 2e913a08cdfbd4d2db95f88914dece7f7e5ada8e..1fa565f2d16a0e299a06bce78bc5862858f8b3d5 100644 (file)
--- a/skin.py
+++ b/skin.py
@@ -46,6 +46,9 @@ dom = xml.dom.minidom.parseString(
                        <widget name="title" position="10,10" size="280,20" />
                        <widget name="menu" position="10,30" size="280,140" />
                </screen>
+               <screen name="configTest" position="300,100" size="300,300" title="config menu">
+                       <widget name="config" position="10,30" size="280,140" />
+               </screen>
                <screen name="clockDisplay" position="300,100" size="300,300">
                        <widget name="okbutton" position="10,10" size="280,40" />
                        <widget name="title" position="10,120" size="280,50" />