Author: duncan
Date: Tue Jun 12 15:46:35 2007
New Revision: 9681

Modified:
   branches/rel-1/freevo/src/gui/Window.py
   branches/rel-1/freevo/src/skin.py
   branches/rel-1/freevo/src/skins/main/area.py
   branches/rel-1/freevo/src/skins/main/listing_area.py
   branches/rel-1/freevo/src/skins/main/tvlisting_area.py
   branches/rel-1/freevo/src/skins/main/xml_skin.py

Log:
[ 1733061 ] Improved int attribute handling in xml skins
Third patch from Adam Charrett applied


Modified: branches/rel-1/freevo/src/gui/Window.py
==============================================================================
--- branches/rel-1/freevo/src/gui/Window.py     (original)
+++ branches/rel-1/freevo/src/gui/Window.py     Tue Jun 12 15:46:35 2007
@@ -81,8 +81,8 @@
     def __init__content__(self):
         x, y, width, height = self.content_layout.x, self.content_layout.y, \
                               self.content_layout.width, 
self.content_layout.height
-        width  = eval_attr(str(width), self.width) or self.width
-        height = eval_attr(str(height), self.height) or self.height
+        width  = eval_attr(width, self.width) or self.width
+        height = eval_attr(height, self.height) or self.height
 
         self.content = Container('frame', x, y, width, height, 
vertical_expansion=1)
         GUIObject.add_child(self, self.content)
@@ -102,8 +102,8 @@
         self.height += height
 
         width, height = self.content_layout.width, self.content_layout.height
-        self.content.width  = eval_attr(str(width),  self.width ) or self.width
-        self.content.height = eval_attr(str(height), self.height) or 
self.height
+        self.content.width  = eval_attr(width,  self.width ) or self.width
+        self.content.height = eval_attr(height, self.height) or self.height
 
         self.left = self.osd.width/2 - self.width/2
         self.top  = self.osd.height/2 - self.height/2
@@ -136,8 +136,8 @@
         for o in self.background_layout:
             if o[0] == 'rectangle':
                 r = copy.deepcopy(o[1])
-                r.width  = eval_attr(str(r.width),  self.get_size()[0])
-                r.height = eval_attr(str(r.height), self.get_size()[1])
+                r.width  = eval_attr(r.width,  self.get_size()[0])
+                r.height = eval_attr(r.height, self.get_size()[1])
                 if not r.width:
                     r.width  = self.get_size()[0]
                 if not r.height:

Modified: branches/rel-1/freevo/src/skin.py
==============================================================================
--- branches/rel-1/freevo/src/skin.py   (original)
+++ branches/rel-1/freevo/src/skin.py   Tue Jun 12 15:46:35 2007
@@ -45,6 +45,7 @@
 import plugin
 import config
 import sys
+import types
 import os.path
 
 _singleton = None
@@ -90,7 +91,7 @@
     Returns attr_value if it is not a string or evaluates it substituting max
     for 'MAX' or 'max' in the attr_value string.
     """
-    if isinstance(attr_value,str):
+    if isinstance(attr_value,types.TupleType):
         global attr_global_dict
         if attr_global_dict is None:
             attr_global_dict = {}
@@ -112,13 +113,15 @@
             else:
                 attr_global_dict['buttonbar'] = 0
                 attr_global_dict['buttonbar_height'] = 0
+        attr_str,scale = attr_value
         # Set max values
         if max is not None:
-            attr_global_dict['MAX'] = max
-            attr_global_dict['max'] = max
-
-        return eval(attr_value, attr_global_dict)
-
+            scaled_max = int(round(float(max) / scale))
+            attr_global_dict['MAX'] = scaled_max
+            attr_global_dict['max'] = scaled_max
+        
+        return int(round(scale * eval(attr_str, attr_global_dict)))
+    
     return attr_value
 
 attr_global_dict = None

Modified: branches/rel-1/freevo/src/skins/main/area.py
==============================================================================
--- branches/rel-1/freevo/src/skins/main/area.py        (original)
+++ branches/rel-1/freevo/src/skins/main/area.py        Tue Jun 12 15:46:35 2007
@@ -51,6 +51,7 @@
 import os
 import pygame
 import stat
+import types
 
 import osd
 import config
@@ -366,10 +367,10 @@
 
         font_h=0
 
-        if isinstance(object.width, str):
+        if isinstance(object.width, types.TupleType):
             object.width = int(eval_attr(object.width, self.area_val.width))
 
-        if isinstance(object.height, str):
+        if isinstance(object.height, types.TupleType):
             object.height = int(eval_attr(object.height, self.area_val.height))
 
         object.x += self.area_val.x
@@ -398,9 +399,9 @@
         r = copy.copy(rectangle)
 
         # get the x and y value, based on MAX
-        if isinstance(r.x, str):
+        if isinstance(r.x, types.TupleType):
             r.x = int(eval_attr(r.x, item_w))
-        if isinstance(r.y, str):
+        if isinstance(r.y, types.TupleType):
             r.y = int(eval_attr(r.y, item_h))
 
         # set rect width and height to something
@@ -411,10 +412,10 @@
             r.height = item_h
 
         # calc width and height based on MAX settings
-        if isinstance(r.width, str):
+        if isinstance(r.width, types.TupleType):
             r.width = int(eval_attr(r.width, item_w))
 
-        if isinstance(r.height, str):
+        if isinstance(r.height, types.TupleType):
             r.height = int(eval_attr(r.height, item_h))
 
         # correct item_w and item_h to fit the rect

Modified: branches/rel-1/freevo/src/skins/main/listing_area.py
==============================================================================
--- branches/rel-1/freevo/src/skins/main/listing_area.py        (original)
+++ branches/rel-1/freevo/src/skins/main/listing_area.py        Tue Jun 12 
15:46:35 2007
@@ -30,6 +30,7 @@
 
 
 import copy
+import types
 
 from area import Skin_Area
 from skin_utils import *
@@ -467,7 +468,7 @@
             if menuw.menu_items[0] != menu.choices[0] and 
area.images['uparrow']:
                 self.drawimage(area.images['uparrow'].filename, 
area.images['uparrow'])
             if menuw.menu_items[-1] != menu.choices[-1] and 
area.images['downarrow']:
-                if isinstance(area.images['downarrow'].y, str):
+                if isinstance(area.images['downarrow'].y, types.TupleType):
                     v = copy.copy(area.images['downarrow'])
                     v.y = eval_attr(v.y, (item_y0-vskip))
                 else:

Modified: branches/rel-1/freevo/src/skins/main/tvlisting_area.py
==============================================================================
--- branches/rel-1/freevo/src/skins/main/tvlisting_area.py      (original)
+++ branches/rel-1/freevo/src/skins/main/tvlisting_area.py      Tue Jun 12 
15:46:35 2007
@@ -30,7 +30,7 @@
 
 
 import copy
-
+import types
 import time
 import config
 import math
@@ -387,7 +387,7 @@
         if menuw.display_up_arrow and area.images['uparrow']:
             self.drawimage(area.images['uparrow'].filename, 
area.images['uparrow'])
         if menuw.display_down_arrow and area.images['downarrow']:
-            if isinstance(area.images['downarrow'].y, str):
+            if isinstance(area.images['downarrow'].y, types.TupleType):
                 v = copy.copy(area.images['downarrow'])
                 v.y = eval_attr(v.y, y0)
             else:

Modified: branches/rel-1/freevo/src/skins/main/xml_skin.py
==============================================================================
--- branches/rel-1/freevo/src/skins/main/xml_skin.py    (original)
+++ branches/rel-1/freevo/src/skins/main/xml_skin.py    Tue Jun 12 15:46:35 2007
@@ -32,6 +32,7 @@
 # some python stuff
 import os
 import copy
+import types
 import re
 import traceback
 import config
@@ -99,7 +100,7 @@
                 value = eval(val)
                 return int(round(scale * value))
             except:
-                return 'int(%s)' % (str(val))
+                return ('int(%s)' % str(val), scale)
 
     except ValueError:
         pass
@@ -297,6 +298,8 @@
         create all object variables for this type
         """
         self.content = content
+        self.ints_to_prepare = []
+
         for c in content:
             if XML_types[c][0] in ('str', 'file', 'font'):
                 setattr(self, c, '')
@@ -320,10 +323,12 @@
                 if XML_types[c][1] == 3: this_scale = min(scale[0], scale[1])
 
                 if this_scale:
-                    e = 'attr_int(node, "%s", self.%s, %s)' % (c, c, 
this_scale)
+                    value = eval('attr_int(node, "%s", self.%s, %s)' % (c, c, 
this_scale))
+                    if isinstance(value, types.TupleType):
+                        self.ints_to_prepare.append(c)
                 else:
-                    e = 'attr_%s(node, "%s", self.%s)' % (XML_types[c][0], c, 
c)
-                setattr(self, c, eval(e))
+                    value = eval('attr_%s(node, "%s", self.%s)' % 
(XML_types[c][0], c, c))
+                setattr(self, c, value)
 
 
     def prepare(self):
@@ -331,13 +336,13 @@
         basic prepare function
         """
         try:
-            for c in self.content:
-                if XML_types[c][0] == 'int' and isinstance(getattr(self,c), 
str):
-                    try:
-                        result = eval_attr(getattr(self, c))
-                        setattr(self, c, result)
-                    except:
-                        pass
+            for c in self.ints_to_prepare:
+                try:
+                    value,scale = getattr(self, c)
+                    result = int(round(scale * eval_attr(value) ))
+                    setattr(self, c,  result)
+                except:
+                    pass
 
             if self.visible not in ('', 'yes'):
                 if len(self.visible) > 4 and self.visible[:4] == 'not ':

-------------------------------------------------------------------------
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