Author: duncan
Date: Thu Jun 14 20:44:15 2007
New Revision: 9697

Added:
   branches/rel-1/freevo/src/skins/main/scrollabletext_area.py   (contents, 
props changed)
Modified:
   branches/rel-1/freevo/share/skins/main/basic.fxd
   branches/rel-1/freevo/src/skin.py

Log:
[ 1737454 ] Add scrollable text area to buttonbars program info
Part of this patch from Adam Charrett applied


Modified: branches/rel-1/freevo/share/skins/main/basic.fxd
==============================================================================
--- branches/rel-1/freevo/share/skins/main/basic.fxd    (original)
+++ branches/rel-1/freevo/share/skins/main/basic.fxd    Thu Jun 14 20:44:15 2007
@@ -823,13 +823,28 @@
 
        <tvguideinfo>
            <screen layout="screen" x="0" y="0" width="800" height="600"/>
-           <title layout="tvguideinfo title" x="10" y="70" width="780" 
height="80"/>
-           <info layout="info" x="10" y="130" width="780" height="460"/>
+           <info layout="tvguideinfo program details" x="10" y="70" 
width="780" height="80"/>
+        <scrollabletext layout="info" x="10" y="160" width="740" height="420 - 
buttonbar_height">
+            <image x="758" y="160" width="32" height="32" label="uparrow" 
filename="up.png"/>
+            <image x="758" y="max-32" width="32" height="32" label="downarrow" 
filename="down.png"/>
+        </scrollabletext>
        </tvguideinfo>
     
-    <layout label="tvguideinfo title">
-           <content x="0" y="0" type="menu" font="title area" align="left" 
valign="center"/>
-       </layout>
+    <layout label="tvguideinfo program details">
+        <content x="0" y="0" type="text" spacing="20" font="default">
+            <item type="default">
+                <if expression="time">
+                    <text font="info font" align="right" width="max" 
expression="time"/>
+                    <newline/>
+                </if>
+                <if expression="title">
+                    <text font="tv title"  align="left"  expression="title"/>
+                    <newline/>
+                </if>                
+            </item>
+        </content>
+    </layout>
+
     </skin>
 </freevo>
 <!-- Keep this comment at the end of the file

Modified: branches/rel-1/freevo/src/skin.py
==============================================================================
--- branches/rel-1/freevo/src/skin.py   (original)
+++ branches/rel-1/freevo/src/skin.py   Thu Jun 14 20:44:15 2007
@@ -58,6 +58,134 @@
             'prepare', 'draw' )
 
 
+class ScrollableText:
+    """
+    Container for scrolling text using the skin area "scrollabletext"
+    """
+    def __init__(self, text):
+        """
+        Initialise the scrollable text area with the text to scroll.
+        """
+        self.text = text
+        self.page = []
+        self.lines = []
+        self.max_lines = 1
+
+    def get_page(self):
+        """
+        Returns the page of text to display.
+        """
+        return self.page
+
+    def __get_line__(self, string, max_width, font, word_splitter, hard):
+        """
+        calculate _one_ line. Returns a list:
+        string to draw, rest that didn't fit and True if this
+        function stopped because of a \n.
+        """
+        c = 0                           # num of chars fitting
+        width = 0                       # width needed
+        ls = len(string)
+        space = 0                       # position of last space
+        last_char_size = 0              # width of the last char
+        last_word_size = 0              # width of the last word
+
+        data = None
+        while(True):
+            if width > (max_width - 1):
+                # ok, that's it. We don't have any space left
+                break
+            if ls == c:
+                # everything fits
+                return (string, '', False)
+            if string[c] == '\n':
+                # linebreak, we have to stop
+                return (string[:c], string[c+1:], True)
+            if string[c] in word_splitter:
+                # rememeber the last space for mode == 'soft' (not hard)
+                space = c
+                last_word_size = 0
+
+            # add a char
+            last_char_size = font.charsize(string[c])
+            width += last_char_size
+            last_word_size += last_char_size
+            c += 1
+
+        rest_start = c
+
+        if not hard:
+            # go one word back, than it fits
+            c = space
+            if string[c] == ' ':
+                rest_start = c + 1
+
+        # calc the matching and rest string and return all this
+        return (string[:c], string[rest_start:], False)
+
+    def layout(self, width, height, font):
+        """
+        Layout the text into lines/pages based on the width,height and font
+        supplied.
+        """
+        self.first_line_index = 0
+        self.max_lines = height / font.height
+        self.lines = []
+        rest = self.text
+        while rest:
+            line, rest, nl = self.__get_line__(rest, width, font, ' ', False)
+            if not line and rest and not nl:
+                line, rest, nl = self.__get_line__(rest, width, font, ' -_', 
False)
+                if not line and rest and not nl:
+                    line, rest, nl = self.__get_line__(rest, width, font, ' 
-_', True)
+
+            self.lines.append(line)
+
+        self.build_page()
+
+
+    def build_page(self):
+        """
+        Create the page based on the first_line_index.
+        """
+        self.page = []
+        if self.first_line_index + self.max_lines >= len(self.lines):
+            self.page = self.lines[self.first_line_index:]
+        else:
+            end_line_index = self.first_line_index + self.max_lines
+            self.page = self.lines[self.first_line_index:end_line_index]
+
+    def more_lines_up(self):
+        """
+        Returns true if the first line of the page is not the top of text, 
false
+        if we are at the top.
+        """
+        return self.first_line_index != 0
+
+    def more_lines_down(self):
+        """
+        Returns true if there are more lines below the bottom line of the
+        current page.
+        """
+        return self.first_line_index + self.max_lines < len(self.lines)
+
+    def scroll(self, up):
+        """
+        Scrolls the current page, up if 'up' is true or down if it is false, by
+        one line.
+        """
+        # The text is not larger than the area so no need to scroll.
+        if len(self.lines) <= self.max_lines:
+            return
+
+        if up:
+            self.first_line_index = max(0, self.first_line_index - 1)
+        else:
+            self.first_line_index = min(self.first_line_index + 1,
+                min(len(self.lines) - 1, len(self.lines) - self.max_lines))
+        self.build_page()
+
+
 def get_singleton():
     """
     Returns an initialized skin object, containing the users preferred

Added: branches/rel-1/freevo/src/skins/main/scrollabletext_area.py
==============================================================================
--- (empty file)
+++ branches/rel-1/freevo/src/skins/main/scrollabletext_area.py Thu Jun 14 
20:44:15 2007
@@ -0,0 +1,102 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------
+# scrollabletext_area.py - A scrollable text area for the Freevo skin
+# -----------------------------------------------------------------------
+# $Id$
+#
+# Notes:
+# Todo:
+#
+# -----------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002 Krister Lagerstrom, et al.
+# Please see the file freevo/Docs/CREDITS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------
+
+
+import copy
+import types
+from area import Skin_Area
+from skin_utils import *
+from skin import eval_attr
+import config
+
+class Scrollabletext_Area(Skin_Area):
+    """
+    this call defines the listing area
+    """
+
+    def __init__(self):
+        Skin_Area.__init__(self, 'scrollabletext')
+        self.last_first_line = -1
+        self.scrollable_text = None
+
+
+    def update_content_needed(self):
+        """
+        check if the content needs an update
+        """
+        return True
+
+
+    def update_content(self):
+        """
+        update the listing area
+        """
+
+        menuw     = self.menuw
+        settings  = self.settings
+        layout    = self.layout
+        area      = self.area_val
+        content   = self.calc_geometry(layout.content, copy_object=True)
+
+        if not hasattr(menuw, "scrollable_text"):
+            return
+
+        scrollable_text = menuw.scrollable_text
+
+        if self.scrollable_text != scrollable_text:
+
+            scrollable_text.layout(content.width, content.height, 
content.font.font)
+            self.scrollable_text = scrollable_text
+
+        page = scrollable_text.get_page()
+
+        if not len(page):
+            return
+
+        y = 0
+        for line in page:
+            self.drawstring(line, content.font, content, content.x, content.y 
+ y, mode='hard')
+            y += content.font.height
+
+        # print arrow:
+        try:
+            if scrollable_text.more_lines_up() and area.images['uparrow']:
+                self.drawimage(area.images['uparrow'].filename, 
area.images['uparrow'])
+
+            if scrollable_text.more_lines_down() and area.images['downarrow']:
+                if isinstance(area.images['downarrow'].y, types.TupleType):
+                    v = copy.copy(area.images['downarrow'])
+                    v.y = eval_attr(v.y, content.y + content.height)
+                else:
+                    v = area.images['downarrow']
+                self.drawimage(area.images['downarrow'].filename, v)
+        except:
+            # empty menu / missing images
+            pass

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to