- load palette from png
authorFelix Domke <tmbinc@elitedvb.net>
Sun, 17 Apr 2005 20:01:28 +0000 (20:01 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Sun, 17 Apr 2005 20:01:28 +0000 (20:01 +0000)
 - named color support

components.py
lib/gdi/gpixmap.cpp
lib/gdi/grc.cpp
lib/gdi/grc.h
lib/gui/ewidgetdesktop.cpp
lib/gui/ewidgetdesktop.h
lib/gui/ewindowstyleskinned.cpp
lib/gui/ewindowstyleskinned.h
screens.py
skin.py

index abf25f208988a2f24d067bdc53112152c705d5ff..deb3760cccef06db3ffd3b0ae8294b910ca092d4 100644 (file)
@@ -348,7 +348,8 @@ class ServiceScan:
                        print "*** warning *** scan was not finished!"
 
        def isDone(self):
                        print "*** warning *** scan was not finished!"
 
        def isDone(self):
-               return self.state == self.Done
+               print "state is %d " % (self.state)
+               return self.state == self.Done or self.state == self.Error
        
 class ActionMap:
        def __init__(self, contexts = [ ], actions = { }, prio=0):
        
 class ActionMap:
        def __init__(self, contexts = [ ], actions = { }, prio=0):
@@ -406,12 +407,12 @@ class EventInfo(PerServiceDisplay):
        def __init__(self, navcore, now_or_next):
                # listen to evUpdatedEventInfo and evStopService
                # note that evStopService will be called once to establish a known state
        def __init__(self, navcore, now_or_next):
                # listen to evUpdatedEventInfo and evStopService
                # note that evStopService will be called once to establish a known state
+               self.now_or_next = now_or_next
                PerServiceDisplay.__init__(self, navcore, 
                        { 
                                pNavigation.evUpdatedEventInfo: self.ourEvent, 
                                pNavigation.evStopService: self.stopEvent 
                        })
                PerServiceDisplay.__init__(self, navcore, 
                        { 
                                pNavigation.evUpdatedEventInfo: self.ourEvent, 
                                pNavigation.evStopService: self.stopEvent 
                        })
-               self.now_or_next = now_or_next
 
        def ourEvent(self):
                info = iServiceInformationPtr()
 
        def ourEvent(self):
                info = iServiceInformationPtr()
@@ -428,7 +429,8 @@ class EventInfo(PerServiceDisplay):
                print "new event info in EventInfo! yeah!"
 
        def stopEvent(self):
                print "new event info in EventInfo! yeah!"
 
        def stopEvent(self):
-                       self.setText("waiting for event data...");
+               self.setText(
+                       ("waiting for event data...", "", "--:--",  "--:--")[self.now_or_next]);
 
 class ServiceName(PerServiceDisplay):
        def __init__(self, navcore):
 
 class ServiceName(PerServiceDisplay):
        def __init__(self, navcore):
index e9c469c425714241441a5ad7717b3754e4887ce6..9e8219a5e588caeae6e11b6938722a9c38895ca1 100644 (file)
@@ -388,6 +388,8 @@ gColor gPalette::findColor(const gRGB &rgb) const
                ttd+=td;
                if (ttd>=difference)
                        continue;
                ttd+=td;
                if (ttd>=difference)
                        continue;
+               if (!ttd)
+                       return t;
                difference=ttd;
                best_choice=t;
        }
                difference=ttd;
                best_choice=t;
        }
index 9cb1a0720f9f8044fd40e77d7a9ba3ae7663a892..756ed9b7e724e1a3e2eb50d1905dc0f539f28673 100644 (file)
@@ -240,6 +240,12 @@ void gPainter::setPalette(gRGB *colors, int start, int len)
        m_rc->submit(o);
 }
 
        m_rc->submit(o);
 }
 
+void gPainter::setPalette(gPixmap *source)
+{
+       ASSERT(source);
+       setPalette(source->surface->clut.data, source->surface->clut.start, source->surface->clut.colors);
+}
+
 void gPainter::mergePalette(gPixmap *target)
 {
        gOpcode o;
 void gPainter::mergePalette(gPixmap *target)
 {
        gOpcode o;
index 574391789c70d39ebf3bcefc9a8e998c8e157275..53bf7f09c11fbb4737efbc6f15e70f748cb76943 100644 (file)
@@ -215,6 +215,7 @@ public:
        void blit(gPixmap *pixmap, ePoint pos, const eRect &what=eRect(), int flags=0);
 
        void setPalette(gRGB *colors, int start=0, int len=256);
        void blit(gPixmap *pixmap, ePoint pos, const eRect &what=eRect(), int flags=0);
 
        void setPalette(gRGB *colors, int start=0, int len=256);
+       void setPalette(gPixmap *source);
        void mergePalette(gPixmap *target);
        
        void line(ePoint start, ePoint end);
        void mergePalette(gPixmap *target);
        
        void line(ePoint start, ePoint end);
index 8c489eb3afccc890cd8561c8cc454dcd8d4a74ab..24fb334b5ec88ed9dd6fdf23b064620181697fc7 100644 (file)
@@ -55,7 +55,7 @@ void eWidgetDesktop::invalidate(const gRegion &region)
        m_dirty_region |= region;
 }
 
        m_dirty_region |= region;
 }
 
-void eWidgetDesktop::setBackgroundColor(gColor col)
+void eWidgetDesktop::setBackgroundColor(gRGB col)
 {
        m_background_color = col;
        
 {
        m_background_color = col;
        
@@ -70,6 +70,13 @@ void eWidgetDesktop::setBackgroundColor(gColor col)
        }
 }
 
        }
 }
 
+void eWidgetDesktop::setPalette(gPixmap &pm)
+{
+       ASSERT(m_dc);
+       gPainter painter(m_dc);
+       painter.setPalette(&pm);
+}
+
 void eWidgetDesktop::paint()
 {
        gPainter painter(m_dc);
 void eWidgetDesktop::paint()
 {
        gPainter painter(m_dc);
index 22914ec5cd7d1b32b24d2ec41f1eebeb8d11b1de..c917e36a6f55cf294fad7598e257d64d55c775e8 100644 (file)
@@ -15,7 +15,7 @@ public: // weil debug
        gRegion m_dirty_region;
        gRegion m_background_region;
        ePtr<gDC> m_dc;
        gRegion m_dirty_region;
        gRegion m_background_region;
        ePtr<gDC> m_dc;
-       gColor m_background_color;
+       gRGB m_background_color;
 public:
        eWidgetDesktop(eSize screen);
        ~eWidgetDesktop();
 public:
        eWidgetDesktop(eSize screen);
        ~eWidgetDesktop();
@@ -27,7 +27,9 @@ public:
        void paint();
        void setDC(gDC *dc);
        
        void paint();
        void setDC(gDC *dc);
        
-       void setBackgroundColor(gColor col);
+       void setBackgroundColor(gRGB col);
+       
+       void setPalette(gPixmap &pm);
        
        void setRedrawTask(eMainloop &ml);
        
        
        void setRedrawTask(eMainloop &ml);
        
index a3152e5f5f466ba6375213e81eb9980e343d01e1..55092e1daf5b413eee97cd8ce0af60feb928c884 100644 (file)
@@ -8,7 +8,9 @@ DEFINE_REF(eWindowStyleSkinned);
 
 eWindowStyleSkinned::eWindowStyleSkinned()
 {
 
 eWindowStyleSkinned::eWindowStyleSkinned()
 {
-       m_background_color = gRGB(0x808080);
+       // m_background_color = gRGB(0x808080);
+       
+       // TODO: initialize colors!!
 }
 
 void eWindowStyleSkinned::handleNewSize(eWindow *wnd, eSize &size, eSize &offset)
 }
 
 void eWindowStyleSkinned::handleNewSize(eWindow *wnd, eSize &size, eSize &offset)
@@ -37,7 +39,7 @@ void eWindowStyleSkinned::paintWindowDecoration(eWindow *wnd, gPainter &painter,
 
 void eWindowStyleSkinned::paintBackground(gPainter &painter, const ePoint &offset, const eSize &size)
 {
 
 void eWindowStyleSkinned::paintBackground(gPainter &painter, const ePoint &offset, const eSize &size)
 {
-       painter.setBackgroundColor(m_background_color);
+       painter.setBackgroundColor(m_color[colBackground]);
        painter.clear();
 }
 
        painter.clear();
 }
 
@@ -46,19 +48,19 @@ void eWindowStyleSkinned::setStyle(gPainter &painter, int what)
        switch (what)
        {
        case styleLabel:
        switch (what)
        {
        case styleLabel:
-               painter.setForegroundColor(gColor(0x1F));
+               painter.setForegroundColor(m_color[colLabelForeground]);
                break;
        case styleListboxSelected:
                break;
        case styleListboxSelected:
-               painter.setForegroundColor(gColor(0x1F));
-               painter.setBackgroundColor(gColor(0x1A));
+               painter.setForegroundColor(m_color[colListboxSelectedForeground]);
+               painter.setBackgroundColor(m_color[colListboxSelectedBackground]);
                break;
        case styleListboxNormal:
                break;
        case styleListboxNormal:
-               painter.setForegroundColor(gColor(0x1C));
-               painter.setBackgroundColor(m_background_color);
+               painter.setForegroundColor(m_color[colListboxForeground]);
+               painter.setBackgroundColor(m_color[colListboxBackground]);
                break;
        case styleListboxMarked:
                break;
        case styleListboxMarked:
-               painter.setForegroundColor(gColor(0x2F));
-               painter.setBackgroundColor(gColor(0x2A));
+               painter.setForegroundColor(m_color[colListboxMarkedForeground]);
+               painter.setBackgroundColor(m_color[colListboxMarkedBackground]);
                break;
        }
 }
                break;
        }
 }
@@ -240,9 +242,9 @@ void eWindowStyleSkinned::setPixmap(int bs, int bp, gPixmap &pixmap)
                m_border[bs].m_border_right, m_border[bs].m_border_bottom); 
 }
 
                m_border[bs].m_border_right, m_border[bs].m_border_bottom); 
 }
 
-void eWindowStyleSkinned::setDefaultBackgroundColor(const gRGB &back)
+void eWindowStyleSkinned::setColor(int what, const gRGB &col)
 {
 {
-       m_background_color = back;
-       eDebug("set default background color!");
+       if ((what < colMax) && (what >= 0))
+               m_color[what] = col;
 }
 
 }
 
index 79557386ee2e1f5839bfb11b7bbb4a7e44acf731..bc9c0549619d33d6737c8867f009feaf95d5cc9d 100644 (file)
@@ -52,7 +52,19 @@ public:
        
        void setPixmap(int bs, int bp, gPixmap &pixmap);
        
        
        void setPixmap(int bs, int bp, gPixmap &pixmap);
        
-       void setDefaultBackgroundColor(const gRGB &back);
+       enum {
+               colBackground,
+               colLabelForeground,
+               colListboxBackground,
+               colListboxForeground,
+               colListboxSelectedBackground,
+               colListboxSelectedForeground,
+               colListboxMarkedBackground,
+               colListboxMarkedForeground,
+               colMax
+       };
+       
+       void setColor(int what, const gRGB &back);
        
 private:
        struct borderSet
        
 private:
        struct borderSet
@@ -63,7 +75,7 @@ private:
        
        borderSet m_border[bsMax];
        
        
        borderSet m_border[bsMax];
        
-       gRGB m_background_color;
+       gRGB m_color[colMax];
        
        void drawBorder(gPainter &painter, const eRect &size, struct borderSet &border, int where);
 };
        
        void drawBorder(gPainter &painter, const eRect &size, struct borderSet &border, int where);
 };
index 77d064f586b48292d76bb71275c5f77bdfef63c5..999ad4bff9104cf65a2e4b0cae82eb6b80e04a3b 100644 (file)
@@ -162,6 +162,7 @@ class clockDisplay(Screen):
 
 class serviceScan(Screen):
        def ok(self):
 
 class serviceScan(Screen):
        def ok(self):
+               print "ok"
                if self["scan"].isDone():
                        self.close()
        
                if self["scan"].isDone():
                        self.close()
        
diff --git a/skin.py b/skin.py
index 73d4b02de0a5e0251cdadab59ef4110601d5d06c..2986a4476f17223bdf7e24a7b336d2bc8ec5aaab 100644 (file)
--- a/skin.py
+++ b/skin.py
@@ -2,6 +2,9 @@ from enigma import *
 import xml.dom.minidom
 from xml.dom import EMPTY_NAMESPACE
 
 import xml.dom.minidom
 from xml.dom import EMPTY_NAMESPACE
 
+
+colorNames = dict()
+
 def dump(x, i=0):
        print " " * i + str(x)
        try:
 def dump(x, i=0):
        print " " * i + str(x)
        try:
@@ -12,8 +15,21 @@ def dump(x, i=0):
 
 dom = xml.dom.minidom.parseString(
        """<skin>
 
 dom = xml.dom.minidom.parseString(
        """<skin>
+       
+               <colors>
+                       <color name="white" value="#ffffff" />
+                       <color name="black" value="#000000" />
+                       <color name="dark"  value="#294a6b" />
+               </colors>
                <windowstyle type="skinned">
                <windowstyle type="skinned">
-                       <color name="defaultBackground" color="#4075a7" />
+                       <color name="Background" color="#4075a7" />
+                       <color name="LabelForeground" color="#ffffff" />
+                       <color name="ListboxBackground" color="#4075a7" />
+                       <color name="ListboxForeground" color="#ffffff" />
+                       <color name="ListboxSelectedBackground" color="#80ff80" />
+                       <color name="ListboxSelectedForeground" color="#ffffff" />
+                       <color name="ListboxMarkedBackground" color="#ff0000" />
+                       <color name="ListboxMarkedForeground" color="#ffffff" />
                        <borderset name="bsWindow">
                                <pixmap pos="bpTopLeft"     filename="data/b_w_tl.png" />
                                <pixmap pos="bpTop"         filename="data/b_w_t.png"  />
                        <borderset name="bsWindow">
                                <pixmap pos="bpTopLeft"     filename="data/b_w_tl.png" />
                                <pixmap pos="bpTop"         filename="data/b_w_t.png"  />
@@ -36,14 +52,14 @@ dom = xml.dom.minidom.parseString(
                        <widget name="theClock" position="10,60" size="280,50" />
                </screen>
                <screen name="infoBar" position="0,380" size="720,151" title="InfoBar" flags="wfNoBorder">
                        <widget name="theClock" position="10,60" size="280,50" />
                </screen>
                <screen name="infoBar" position="0,380" size="720,151" title="InfoBar" flags="wfNoBorder">
-                       <ePixmap position="0,0" size="720,151" pixmap="info-bg.png" />
+                       <ePixmap position="0,0" size="720,151" pixmap="data/info-bg.png" />
                        
                        
-                       <widget name="ServiceName" position="69,30" size="427,26" valign="center" font="Arial;32" />
-                       <widget name="CurrentTime" position="575,10" size="66,30" />
-                       <widget name="Event_Now" position="273,68" size="282,30" font="Arial;29" backgroundColor="#586D88" />
-                       <widget name="Event_Next" position="273,98" size="282,30" font="Arial;29" />
-                       <widget name="Event_Now_Duration" position="555,68" size="70,26" font="Arial;26" />
-                       <widget name="Event_Next_Duration" position="555,98" size="70,26" font="Arial;26" />
+                       <widget name="ServiceName" position="69,30" size="427,26" valign="center" font="Arial;32" backgroundColor="#101258" />
+                       <widget name="CurrentTime" position="575,10" size="66,30" backgroundColor="dark" font="Arial;16" />
+                       <widget name="Event_Now" position="273,68" size="282,30" font="Arial;29" backgroundColor="dark" />
+                       <widget name="Event_Next" position="273,98" size="282,30" font="Arial;29" backgroundColor="dark" />
+                       <widget name="Event_Now_Duration" position="555,68" size="70,26" font="Arial;26" backgroundColor="dark" />
+                       <widget name="Event_Next_Duration" position="555,98" size="70,26" font="Arial;26" backgroundColor="dark" />
 <!--                   <eLabel position="70,0" size="300,30" text=".oO skin Oo." font="Arial;20" /> -->
                </screen>
                <screen name="channelSelection" position="100,80" size="500,240" title="Channel Selection">
 <!--                   <eLabel position="70,0" size="300,30" text=".oO skin Oo." font="Arial;20" /> -->
                </screen>
                <screen name="channelSelection" position="100,80" size="500,240" title="Channel Selection">
@@ -86,7 +102,10 @@ def parseFont(str):
 
 def parseColor(str):
        if str[0] != '#':
 
 def parseColor(str):
        if str[0] != '#':
-               raise "color must be #aarrggbb"
+               try:
+                       return colorNames[str]
+               except:
+                       raise ("color '%s' must be #aarrggbb or valid named color" % (str))
        return gRGB(int(str[1:], 0x10))
 
 def applyAttributes(guiObject, node, desktop):
        return gRGB(int(str[1:], 0x10))
 
 def applyAttributes(guiObject, node, desktop):
@@ -168,6 +187,16 @@ def loadSkin():
        skin = dom.childNodes[0]
        assert skin.tagName == "skin", "root element in skin must be 'skin'!"
        
        skin = dom.childNodes[0]
        assert skin.tagName == "skin", "root element in skin must be 'skin'!"
        
+       for c in elementsWithTag(skin.childNodes, "colors"):
+               for color in elementsWithTag(c.childNodes, "color"):
+                       name = str(color.getAttribute("name"))
+                       color = str(color.getAttribute("value"))
+                       
+                       if not len(color):
+                               raise ("need color and name, got %s %s" % (name, color))
+                               
+                       colorNames[name] = parseColor(color)
+       
        for windowstyle in elementsWithTag(skin.childNodes, "windowstyle"):
                style = eWindowStyleSkinned()
                
        for windowstyle in elementsWithTag(skin.childNodes, "windowstyle"):
                style = eWindowStyleSkinned()
                
@@ -183,10 +212,10 @@ def loadSkin():
                        type = str(color.getAttribute("name"))
                        color = parseColor(color.getAttribute("color"))
                        
                        type = str(color.getAttribute("name"))
                        color = parseColor(color.getAttribute("color"))
                        
-                       if type == "defaultBackground":
-                               style.setDefaultBackgroundColor(color)
-                       else:
-                               raise "unknown color %s" % (type)
+                       try:
+                               style.setColor(eWindowStyleSkinned.__dict__["col" + type], color)
+                       except:
+                               raise ("Unknown color %s" % (type))
                        
                x = eWindowStyleManagerPtr()
                eWindowStyleManager.getInstance(x)
                        
                x = eWindowStyleManagerPtr()
                eWindowStyleManager.getInstance(x)