Update of /cvsroot/freevo/freevo/src/gui/areas
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25255
Modified Files:
area.py
Log Message:
Major cleanup:
o merge self.content, self.settings and self.area_values into self.settings
o move init into draw
o make some functions and variables private
o move rectangle calculation to theme
Index: area.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/gui/areas/area.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** area.py 20 Nov 2004 18:23:01 -0000 1.20
--- area.py 30 Dec 2004 11:26:59 -0000 1.21
***************
*** 77,88 ****
"""
self.area_name = name
- self.area_values = None
- self.layout = None
- self.name = name
self.screen = None
self.imagelib = None
self.__background = []
!
def set_screen(self, screen, bg_layer, content_layer):
"""
--- 77,88 ----
"""
self.area_name = name
self.screen = None
self.imagelib = None
+ self.__area = None
+ self.__layout = None
self.__background = []
+ self.settings = None
!
def set_screen(self, screen, bg_layer, content_layer):
"""
***************
*** 116,120 ****
"""
if not self.screen:
! log.info('ERROR in area %s: no screen defined' % self.name)
return
--- 116,120 ----
"""
if not self.screen:
! log.info('ERROR in area %s: no screen defined' % self.area_name)
return
***************
*** 138,262 ****
self.infoitem = infoitem
! if not self.__init_vars(settings, area_definitions):
! return
! if not self.area_values.visible or not self.layout:
self.clear_all()
return
self.layer = self.bg_layer
self.__draw_background()
self.layer = self.content_layer
self.update()
! def calc_geometry(self, obj, copy_object=0):
"""
Calculate the real values of the obj (e.g. content) based
on the geometry of the area.
"""
! if copy_object:
! obj = copy.copy(obj)
!
font_h=0
if isinstance(obj.width, str):
! obj.width = int(eval(obj.width, {'MAX': self.area_values.width}))
if isinstance(obj.height, str):
! obj.height = int(eval(obj.height,{'MAX':
self.area_values.height}))
if isinstance(obj.x, str):
! obj.x = int(eval(obj.x, {'MAX':self.area_values.height}))
if isinstance(obj.y, str):
! obj.y = int(eval(obj.y, {'MAX':self.area_values.height}))
! obj.x += self.area_values.x
! obj.y += self.area_values.y
if not obj.width:
! obj.width = self.area_values.width
if not obj.height:
! obj.height = self.area_values.height
! if obj.width + obj.x > self.area_values.width + \
! self.area_values.x:
! obj.width = self.area_values.width - obj.x
! if obj.height + obj.y > self.area_values.height + \
! self.area_values.y:
! obj.height = self.area_values.height + self.area_values.y - \
! obj.y
return obj
- def calc_rectangle(self, rectangle, width, height):
- """
- Calculates the values for a rectangle to fit width and height
- inside it.
- """
- r = copy.copy(rectangle)
-
- # 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 __init_vars(self, settings, area):
- """
- Check which layout is used and set variables for the object
- """
- self.settings = settings
-
- try:
- area = getattr(area, self.area_name)
- except AttributeError:
- try:
- area = area.areas[self.area_name]
- except (KeyError, AttributeError):
- log.warning('no skin information for %s' % self.area_name)
- return False
-
- if (not self.area_values) or area != self.area_values:
- area.r = (area.x, area.y, area.width, area.height)
- self.area_values = area
-
- self.layout = area.layout
- return True
-
-
def __draw_background(self):
"""
--- 138,236 ----
self.infoitem = infoitem
! try:
! # get the area based on the area name
! area = getattr(area_definitions, self.area_name)
! except AttributeError:
! try:
! # maybe areas is a special attribute
! area = area_definitions.areas[self.area_name]
! except (KeyError, AttributeError):
! # area defintions not found
! log.warning('no skin information for %s' % self.area_name)
! return
! if self.settings:
! self.settings.changed = False
!
! # check if the area definitions changed
! if (not self.__area) or area != self.__area:
! area.r = (area.x, area.y, area.width, area.height)
! self.__area = area
! # set layout
! self.__layout = area.layout
! if area.layout:
! # recalculate self.settings
! self.settings = self.__calc_geometry(area.layout.content)
! self.settings.images = area.images
! self.settings.changed = True
! self.settings.box_under_icon = settings.box_under_icon
! self.settings.icon_dir = settings.icon_dir
!
! elif area and self.__layout != area.layout:
! # set layout
! self.__layout = area.layout
! # recalculate self.settings
! self.settings = self.__calc_geometry(area.layout.content)
! self.settings.images = area.images
! self.settings.changed = True
! self.settings.box_under_icon = settings.box_under_icon
! self.settings.icon_dir = settings.icon_dir
!
! if not area.visible or not self.__layout:
! # not visible
self.clear_all()
return
+ # set layer to background
self.layer = self.bg_layer
+ # draw background
self.__draw_background()
+ # set layer to content
self.layer = self.content_layer
+ # draw content
self.update()
! def __calc_geometry(self, obj):
"""
Calculate the real values of the obj (e.g. content) based
on the geometry of the area.
"""
! obj = copy.copy(obj)
font_h=0
if isinstance(obj.width, str):
! obj.width = int(eval(obj.width, {'MAX': self.__area.width}))
if isinstance(obj.height, str):
! obj.height = int(eval(obj.height,{'MAX': self.__area.height}))
if isinstance(obj.x, str):
! obj.x = int(eval(obj.x, {'MAX':self.__area.height}))
if isinstance(obj.y, str):
! obj.y = int(eval(obj.y, {'MAX':self.__area.height}))
! obj.x += self.__area.x
! obj.y += self.__area.y
if not obj.width:
! obj.width = self.__area.width
if not obj.height:
! obj.height = self.__area.height
! if obj.width + obj.x > self.__area.width + \
! self.__area.x:
! obj.width = self.__area.width - obj.x
! if obj.height + obj.y > self.__area.height + \
! self.__area.y:
! obj.height = self.__area.height + self.__area.y - obj.y
return obj
def __draw_background(self):
"""
***************
*** 266,271 ****
background_rect = []
! for bg in self.layout.background:
! bg = self.calc_geometry(bg, copy_object=True)
if bg.type == 'image' and bg.visible:
# if this is the real background image, ignore the
--- 240,245 ----
background_rect = []
! for bg in self.__layout.background:
! bg = self.__calc_geometry(bg)
if bg.type == 'image' and bg.visible:
# if this is the real background image, ignore the
***************
*** 296,317 ****
for b in copy.copy(self.__background):
try:
background_rect.remove(b.info)
except ValueError:
try:
background_image.remove(b.info)
except ValueError:
self.__background.remove(b)
b.unparent()
- for rec in background_rect:
- x, y, width, height, bgcolor, size, color, radius = rec
- box = self.drawbox(x, y, width, height, (bgcolor, size, color,
- radius))
- self.__background.append(box)
- box.info = rec
- box.set_zindex(-1)
-
for image in background_image:
imagefile, x, y, width, height = image
i = self.drawimage(imagefile, (x, y, width, height),
--- 270,288 ----
for b in copy.copy(self.__background):
+ # remove the background objects already on the screen
try:
+ # maybe it's a rectangle
background_rect.remove(b.info)
except ValueError:
try:
+ # maybe it's an image
background_image.remove(b.info)
except ValueError:
+ # not found, remove this old object
self.__background.remove(b)
b.unparent()
for image in background_image:
+ # add the new images to the screen
imagefile, x, y, width, height = image
i = self.drawimage(imagefile, (x, y, width, height),
***************
*** 322,325 ****
--- 293,305 ----
i.set_zindex(-1)
+ for rec in background_rect:
+ # add the new rectangles to the screen
+ x, y, width, height, bgcolor, size, color, radius = rec
+ box = self.drawbox(x, y, width, height, (bgcolor, size, color,
+ radius))
+ self.__background.append(box)
+ box.info = rec
+ box.set_zindex(-1)
+
***************
*** 339,343 ****
! def drawstring(self, text, font, content, x=-1, y=-1, width=None,
height=None, align_h = None, align_v = None, mode='hard',
ellipses='...', dim=True):
--- 319,323 ----
! def drawstring(self, text, font, settings, x=-1, y=-1, width=None,
height=None, align_h = None, align_v = None, mode='hard',
ellipses='...', dim=True):
***************
*** 349,370 ****
return None
! # set default values from 'content'
if x == -1:
! x = content.x
if y == -1:
! y = content.y
if width == None:
! width = content.width
if height == None:
! height = content.height
! if not align_h and content:
! align_h = content.align
if not align_h:
align_h = 'left'
! if not align_v and content:
! align_v = content.valign
if not align_v:
align_v = 'top'
--- 329,350 ----
return None
! # set default values from 'settings'
if x == -1:
! x = settings.x
if y == -1:
! y = settings.y
if width == None:
! width = settings.width
if height == None:
! height = settings.height
! if not align_h and settings:
! align_h = settings.align
if not align_h:
align_h = 'left'
! if not align_v and settings:
! align_v = settings.valign
if not align_v:
align_v = 'top'
***************
*** 399,405 ****
if not (x == 0 and y == 0 and w == self.screen.width and \
h == self.screen.height) and \
! self.area_values.x == x and self.area_values.y == y and \
! self.area_values.width == w and \
! self.area_values.height == h:
i = Image(image, (0, 0), (self.screen.width,
self.screen.height))
--- 379,385 ----
if not (x == 0 and y == 0 and w == self.screen.width and \
h == self.screen.height) and \
! self.__area.x == x and self.__area.y == y and \
! self.__area.width == w and \
! self.__area.height == h:
i = Image(image, (0, 0), (self.screen.width,
self.screen.height))
***************
*** 418,420 ****
delete function of memory debugging
"""
! _mem_debug_('Area', self.name)
--- 398,400 ----
delete function of memory debugging
"""
! _mem_debug_('Area', self.area_name)
-------------------------------------------------------
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