From a1a9522c1bf4d5e785dd92bc9321420d4c8a90f2 Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Thu, 1 Mar 2007 17:38:13 +0000 Subject: [PATCH] add support for non-wrapping labels, add debug assert for incomplete skins --- lib/gui/elabel.cpp | 16 ++++++++++++++-- lib/gui/elabel.h | 2 ++ skin.py | 16 +++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/gui/elabel.cpp b/lib/gui/elabel.cpp index f64adb2d..6e53c851 100644 --- a/lib/gui/elabel.cpp +++ b/lib/gui/elabel.cpp @@ -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 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(); diff --git a/lib/gui/elabel.h b/lib/gui/elabel.h index 84b2c5e4..84995ecc 100644 --- a/lib/gui/elabel.h +++ b/lib/gui/elabel.h @@ -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 b2daa7fc..21839435 100644 --- 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": -- 2.30.2