Update of /cvsroot/freevo/freevo/src/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26013

Modified Files:
        theme_engine.py 
Log Message:
o move rectangle calculation from area to Rectangle class
o add ContentItem and make sure all attributes have defaults


Index: theme_engine.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/gui/theme_engine.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** theme_engine.py     28 Dec 2004 19:51:25 -0000      1.11
--- theme_engine.py     30 Dec 2004 11:30:48 -0000      1.12
***************
*** 547,550 ****
--- 547,551 ----
          self.y = -1
          self.visible = False
+         self.images = {}
  
      def parse(self, node, scale, current_dir):
***************
*** 640,643 ****
--- 641,656 ----
  
  
+ class ContentItem(XML_data):
+     """
+     class for <item> inside content
+     """
+     def __init__(self):
+         XML_data.__init__(self, ('font', 'align', 'valign', 'height',
+                                  'width', 'icon'))
+         self.rectangle = None
+         self.shadow    = None
+         self.cdata     = ''
+         self.fcontent  = []
+         
  
  class Content(XML_data):
***************
*** 660,668 ****
                  type = attr_str(subnode, "type", '')
                  if type and not self.types.has_key(type):
!                     self.types[type] = XML_data(('font', 'align', 'valign',
!                                                  'height', 'width', 'icon' ))
!                     self.types[type].rectangle = None
!                     self.types[type].shadow    = None
!                     self.types[type].cdata     = ''
                  if type:
                      self.types[type].parse(subnode, scale, current_dir)
--- 673,677 ----
                  type = attr_str(subnode, "type", '')
                  if type and not self.types.has_key(type):
!                     self.types[type] = ContentItem()
                  if type:
                      self.types[type].parse(subnode, scale, current_dir)
***************
*** 683,688 ****
                          elif rnode.name in ( u'if', u'text', u'newline',
                                               u'goto_pos', u'img' ):
!                             if (not hasattr(self.types[type], 'fcontent')) or 
\
!                                    delete_fcontent:
                                  self.types[ type ].fcontent = [ ]
                              delete_fcontent = False
--- 692,696 ----
                          elif rnode.name in ( u'if', u'text', u'newline',
                                               u'goto_pos', u'img' ):
!                             if delete_fcontent:
                                  self.types[ type ].fcontent = [ ]
                              delete_fcontent = False
***************
*** 704,711 ****
  
          if not self.types.has_key('default'):
!             self.types['default'] = XML_data(('font',))
!             self.types['default'].rectangle = None
!             self.types['default'].shadow    = None
!             self.types['default'].cdata     = ''
  
  
--- 712,716 ----
  
          if not self.types.has_key('default'):
!             self.types['default'] = ContentItem()
  
  
***************
*** 721,727 ****
              if self.types[type].shadow:
                  self.types[type].shadow.prepare(None, color)
!             if hasattr( self.types[type], 'fcontent' ):
!                 for i in self.types[type].fcontent:
!                     i.prepare( font, color, search_dirs )
  
  
--- 726,731 ----
              if self.types[type].shadow:
                  self.types[type].shadow.prepare(None, color)
!             for i in self.types[type].fcontent:
!                 i.prepare( font, color, search_dirs )
  
  
***************
*** 910,920 ****
--- 914,968 ----
              self.radius = radius
  
+ 
      def prepare(self, color, search_dirs=None, image_names=None):
          XML_data.prepare(self, None, color)
  
+ 
+     def calculate(self, width, height):
+         """
+         Calculates the values for the rectangle to fit width and height
+         inside it.
+         """
+         r = copy.copy(self)
+ 
+         # get the x and y value, based on MAX
+         if isinstance(r.x, str):
+             r.x = int(eval(r.x, {'MAX':width}))
+         if isinstance(r.y, str):
+             r.y = int(eval(r.y, {'MAX':height}))
+ 
+         # set rect width and height to something
+         if not r.width:
+             r.width = width
+ 
+         if not r.height:
+             r.height = height
+ 
+         # calc width and height based on MAX settings
+         if isinstance(r.width, str):
+             r.width = int(eval(r.width, {'MAX':width}))
+ 
+         if isinstance(r.height, str):
+             r.height = int(eval(r.height, {'MAX':height}))
+ 
+         # correct width and height to fit the rect
+         width = max(width, r.width)
+         height = max(height, r.height)
+         if r.x < 0:
+             width -= r.x
+         if r.y < 0:
+             height -= r.y
+ 
+         # return needed width and height to fit original width and height
+         # and the rectangle attributes
+         return max(width, r.width), max(height, r.height), r
+ 
+ 
      def __str__(self):
          return 'theme.Rectangle at %s,%s %sx%s' % \
                 (self.x, self.y, self.width, self.height)
  
+ 
+ 
  class Font(XML_data):
      """



-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to