add support for non-wrapping labels, add debug assert for incomplete skins
authorFelix Domke <tmbinc@elitedvb.net>
Thu, 1 Mar 2007 17:38:13 +0000 (17:38 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Thu, 1 Mar 2007 17:38:13 +0000 (17:38 +0000)
lib/gui/elabel.cpp
lib/gui/elabel.h
skin.py

index f64adb2d79a7b74a6a912abe3ed30cad860870f1..6e53c851ba6434fbb136fec3828aac00183bf9f5 100644 (file)
@@ -15,6 +15,8 @@ eLabel::eLabel(eWidget *parent, int markedPos): eWidget(parent)
        
        m_have_foreground_color = 0;
        m_have_shadow_color = 0;
+       
+       m_nowrap = 0;
 }
 
 int eLabel::event(int event, void *data, void *data2)
@@ -89,7 +91,8 @@ int eLabel::event(int event, void *data, void *data2)
                        else if (m_halign == alignBlock)
                                flags |= gPainter::RT_HALIGN_BLOCK;
                        
-                       flags |= gPainter::RT_WRAP;
+                       if (!m_nowrap)
+                               flags |= gPainter::RT_WRAP;
                        
                                /* if we don't have shadow, m_shadow_offset will be 0,0 */
                        painter.renderText(eRect(-m_shadow_offset.x(), -m_shadow_offset.y(), size().width(), size().height()), m_text, flags);
@@ -180,6 +183,15 @@ void eLabel::setShadowOffset(const ePoint &offset)
        m_shadow_offset = offset;
 }
 
+void eLabel::setNoWrap(int nowrap)
+{
+       if (m_nowrap != nowrap)
+       {
+               m_nowrap = nowrap;
+               invalidate();
+       }
+}
+
 void eLabel::clearForegroundColor()
 {
        if (m_have_foreground_color)
@@ -194,7 +206,7 @@ eSize eLabel::calculateSize()
        ePtr<eTextPara> p = new eTextPara(eRect(0, 0, size().width(), size().height()));
        
        p->setFont(m_font);
-       p->renderString(m_text.empty()?0:m_text.c_str(), RS_WRAP);
+       p->renderString(m_text.empty()?0:m_text.c_str(), m_nowrap ? 0 : RS_WRAP);
        
        eRect bbox = p->getBoundBox();
        return bbox.size();
index 84b2c5e4ba23977d797059ad28b24dc07cb37898..84995eccd056c8e2b5995a27bc661f35efa28d1c 100644 (file)
@@ -28,6 +28,7 @@ public:
        void setForegroundColor(const gRGB &col);
        void setShadowColor(const gRGB &col);
        void setShadowOffset(const ePoint &offset);
+       void setNoWrap(int nowrap);
        void clearForegroundColor();
        
        eSize calculateSize();
@@ -41,6 +42,7 @@ private:
        int m_have_foreground_color, m_have_shadow_color;
        gRGB m_foreground_color, m_shadow_color;
        ePoint m_shadow_offset;
+       int m_nowrap;
        
        enum eLabelEvent
        {
diff --git a/skin.py b/skin.py
index b2daa7fcd0f2bb15d1b023f41e13cd94b81eb671..21839435ab844007b95e7dd074ca1dfeedbceedc 100644 (file)
--- a/skin.py
+++ b/skin.py
@@ -10,6 +10,7 @@ from Components.Element import Element
 from Components.Converter.Converter import Converter
 from Tools.Directories import resolveFilename, SCOPE_SKIN, SCOPE_SKIN_IMAGE, SCOPE_FONTS
 from Tools.Import import my_import
+
 from Tools.XMLTools import elementsWithTag, mergeText
 
 colorNames = dict()
@@ -192,6 +193,8 @@ def applySingleAttribute(guiObject, desktop, attrib, value):
                        guiObject.setPointer({"pointer": 0, "seek_pointer": 1}[attrib], ptr.__deref__(), pos)
                elif attrib == 'shadowOffset':
                        guiObject.setShadowOffset(parsePosition(value))
+               elif attrib == 'noWrap':
+                       guiObject.setNoWrap(1)
                else:
                        raise "unsupported attribute " + attrib + "=" + value
        except int:
@@ -281,6 +284,7 @@ def lookupScreen(name):
        return None, None
 
 def readSkin(screen, skin, name, desktop):
+       
        myscreen, path = lookupScreen(name)
        
        # otherwise try embedded skin
@@ -301,6 +305,8 @@ def readSkin(screen, skin, name, desktop):
        screen.additionalWidgets = [ ]
        screen.renderer = [ ]
        
+       visited_components = set()
+       
        # now walk all widgets
        for widget in elementsWithTag(myscreen.childNodes, "widget"):
                # ok, we either have 1:1-mapped widgets ('old style'), or 1:n-mapped 
@@ -309,11 +315,14 @@ def readSkin(screen, skin, name, desktop):
                wname = widget.getAttribute('name')
                wsource = widget.getAttribute('source')
                
+
                if wname is None and wsource is None:
                        print "widget has no name and no source!"
                        continue
                
                if wname:
+                       visited_components.add(wname)
+
                        # get corresponding 'gui' object
                        try:
                                attributes = screen[wname].skinAttributes = [ ]
@@ -321,7 +330,7 @@ def readSkin(screen, skin, name, desktop):
                                raise SkinError("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
 
 #                      assert screen[wname] is not Source
-               
+
                        # and collect attributes for this
                        collectAttributes(attributes, widget, skin_path_prefix, ignore=['name'])
                elif wsource:
@@ -366,6 +375,11 @@ def readSkin(screen, skin, name, desktop):
                        
                        screen.renderer.append(renderer)
 
+       from Components.GUIComponent import GUIComponent
+       nonvisited_components = [x for x in set(screen.keys()) - visited_components if isinstance(x, GUIComponent)]
+       
+       assert not nonvisited_components, "the following components in %s don't have a skin entry: %s" % (name, ', '.join(nonvisited_components))
+
        # now walk additional objects
        for widget in elementsWithTag(myscreen.childNodes, lambda x: x != "widget"):
                if widget.tagName == "applet":