Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
anim.BaseProcess Class Reference
Inheritance diagram for anim.BaseProcess:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_last_rectel_bounds
def get_last_line_points
def rgb_write
def run

Public Attributes

 types
 outfp
 images_list
 frames_total
 list_to
 list_from
 element
 frame
 symbol
 image
 gcompris_name

Detailed Description

Base class for the conversion processors.  Each concrete subclass
must provide the following methods:

initOutput()
    Initialize the output stream and any internal data structures
    that the conversion process needs.

addRecord(lname, fname, type)
    Add one record to the output stream (or the internal structures)
    where lname is the last name, fname is the first name, and type
    is either 'manager' or 'employee'.

finishOutput()
    Finish all output generation.  If all work has been on internal
    data structures, this is where they should be converted to text
    and written out.

Definition at line 2476 of file anim.py.


Constructor & Destructor Documentation

def anim.BaseProcess.__init__ (   self,
  outfp 
)
Store the input and output streams for later use.

Definition at line 2494 of file anim.py.

02494 
02495     def __init__(self, outfp):
02496         """Store the input and output streams for later use."""
02497         self.types = { 'RECT' : 'rect',
02498                        'FILL_RECT' : 'rect',
02499                        'CIRCLE' : 'ellipse',
02500                        'FILL_CIRCLE' : 'ellipse',
02501                        'TEXT' : 'text',
02502                        'IMAGE' : 'use',
02503                        'LINE' : 'line'
02504                    }
02505 
02506         global fles
02507 
02508         self.outfp = outfp
02509         self.images_list = {}
02510 
02511         self.frames_total = fles.frames_total
02512 
02513 
02514         # save the list into
02515         self.list_to = []
02516 
02517         # get the list
02518         self.list_from = []
02519 
02520         if (fles.gcomprisBoard.mode == 'draw'):
02521           # in draw we need to get the list in z order, because of svg.
02522           def get_item_at(z):
02523             for item in eval('fles.' + fles.itemlist[fles.gcomprisBoard.mode]):
02524               if item.z == z: return item
02525           for z in fles.list_z_actual:
02526             self.list_from.append(get_item_at(z))
02527 
02528           # now each item needs to get it's frames_info updated
02529           for anAnimItem in self.list_from[:]:
02530             modified = fles.get_modified_parameters(anAnimItem)
02531             if len(modified) != 0:
02532               anAnimItem.frames_info[fles.current_frame] = modified
02533         else:
02534           self.list_from = fles.animlist
02535 
02536         for item in self.list_from:
02537           frames_info_copied = {}
02538           for t, d  in item.frames_info.iteritems():
02539             frames_info_copied[t] = d.copy();
02540           Sitem = [ item.type, frames_info_copied]
02541           list_frames = Sitem[1].keys()
02542           list_frames.sort()
02543 #          if ((Sitem[0] == 'TEXT') and (Sitem[1][list_frames[0]].has_key('anchor'))):
02544 #            Sitem[1][list_frames[0]]['text-anchor']='middle'
02545 #            del Sitem[1][list_frames[0]]['anchor']
02546           self.list_to.append(Sitem)
02547 


Member Function Documentation

def anim.BaseProcess.get_last_line_points (   self,
  item,
  frame_no 
)

Definition at line 2569 of file anim.py.

02569 
02570     def get_last_line_points(self, item, frame_no):
02571         listkeys = item[1].keys()
02572         listkeys.sort()
02573 
02574         def f(x): return x < frame_no
02575 
02576         for frame in filter(f,listkeys):
02577             if  item[1][frame].has_key('points'):
02578                 points = item[1][frame]['points']
02579         return points

def anim.BaseProcess.get_last_rectel_bounds (   self,
  item,
  frame_no 
)

Definition at line 2548 of file anim.py.

02548 
02549     def get_last_rectel_bounds(self, item, frame_no):
02550         listkeys = item[1].keys()
02551         listkeys.sort()
02552 
02553 
02554         def f(x): return x < frame_no
02555 
02556         #print "rectel last", item, frame_no, filter(f,listkeys)
02557 
02558         for frame in filter(f,listkeys):
02559           if item[1][frame].has_key('x1'):
02560              x1 = item[1][frame]['x1']
02561           if item[1][frame].has_key('x2'):
02562              x2 = item[1][frame]['x2']
02563           if item[1][frame].has_key('y1'):
02564              y1 = item[1][frame]['y1']
02565           if item[1][frame].has_key('y2'):
02566              y2 = item[1][frame]['y2']
02567 
02568         return (x1,y1,x2,y2)

def anim.BaseProcess.rgb_write (   self,
  rgba 
)

Definition at line 2580 of file anim.py.

02580 
02581     def rgb_write(self, rgba):
02582         red = int ( ( rgba >> 24 ) & 255 )
02583         green = int ( ( rgba >> 16 ) & 255 )
02584         blue = int ( ( rgba >> 8 ) & 255 )
02585         return 'rgb(' + str(red) +',' + str(green) + ',' + str(blue) + ')'

def anim.BaseProcess.run (   self)
Perform the complete conversion process.

This method is responsible for parsing the input and calling the
subclass-provided methods in the right order.

Definition at line 2586 of file anim.py.

02586 
02587     def run(self):
02588         """Perform the complete conversion process.
02589 
02590         This method is responsible for parsing the input and calling the
02591         subclass-provided methods in the right order.
02592         """
02593         self.initOutput()
02594 
02595         global fles
02596 
02597         for item in self.list_to:
02598           self.element = self.document.createElement(self.types[item[0]])
02599           self.svg.appendChild(self.element)
02600           listkeys = item[1].keys()
02601           listkeys.sort()
02602           for frame_no in listkeys:
02603             # if draw there is only one key.
02604             # in this case parameters are put in self.element
02605             # and not in self.frame
02606 
02607             if fles.gcomprisBoard.mode == 'draw':
02608               self.frame = self.element
02609             else:
02610              self.frame = self.document.createElement("gcompris:frame")
02611              self.frame.setAttribute('time',str(frame_no))
02612              self.element.appendChild(self.frame)
02613 
02614             for attr in item[1][frame_no].keys():
02615               if (self.types[item[0]] == 'rect'):
02616 
02617                 if (item[0] == 'RECT') and item[1][frame_no].has_key('create'):
02618                   self.frame.setAttribute('fill', 'none')
02619                 if (attr == 'x2'):
02620                   if item[1][frame_no].has_key('x1'):
02621                     self.frame.setAttribute('width', str(item[1][frame_no]['x2']-item[1][frame_no]['x1']))
02622                   else:
02623                          points = self.get_last_rectel_bounds(item, frame_no)
02624                     self.frame.setAttribute('width', str(item[1][frame_no]['x2']- points[0]))
02625                   continue
02626                 if (attr == 'y2'):
02627                   if item[1][frame_no].has_key('y1'):
02628                     self.frame.setAttribute('height', str(item[1][frame_no]['y2']-item[1][frame_no]['y1']))
02629                   else:
02630                          points = self.get_last_rectel_bounds(item, frame_no)
02631                     self.frame.setAttribute('height', str(item[1][frame_no]['y2']- points[1]))
02632                   continue
02633                 if (attr == 'x1'):
02634                   self.frame.setAttribute('x', str(item[1][frame_no]['x1']))
02635                   if not item[1][frame_no].has_key('x2'):
02636                     points = self.get_last_rectel_bounds(item, frame_no)
02637                     self.frame.setAttribute('width', str( - item[1][frame_no]['x1'] + points[2]))
02638                   continue
02639                 if (attr == 'y1'):
02640                   self.frame.setAttribute('y', str(item[1][frame_no]['y1']))
02641                   if not item[1][frame_no].has_key('y2'):
02642                     points = self.get_last_rectel_bounds(item, frame_no)
02643                     self.frame.setAttribute('width', str( - item[1][frame_no]['y1']+ points[3]))
02644                   continue
02645                 if (attr == 'fill_color_rgba'):
02646                   self.frame.setAttribute(
02647                       'fill',
02648                       self.rgb_write(item[1][frame_no]['fill_color_rgba']))
02649                   continue
02650                 if (attr == 'outline_color_rgba'):
02651                   self.frame.setAttribute(
02652                       'stroke',
02653                       self.rgb_write(item[1][frame_no]['outline_color_rgba']))
02654                   continue
02655                 if (attr == 'width-units'):
02656                   self.frame.setAttribute(
02657                       'stroke-width',
02658                       str(item[1][frame_no]['width-units']))
02659                   continue
02660 
02661               if (self.types[item[0]] == 'ellipse'):
02662                 if (attr == 'width-units'):
02663                   self.frame.setAttribute(
02664                       'stroke-width',
02665                       str(item[1][frame_no]['width-units']))
02666                   continue
02667 
02668                 if (attr == 'outline_color_rgba'):
02669                   self.frame.setAttribute(
02670                       'stroke',
02671                       self.rgb_write(item[1][frame_no]['outline_color_rgba']))
02672                   continue
02673                 if (item[0] == 'CIRCLE') and item[1][frame_no].has_key('create'):
02674                   self.frame.setAttribute('fill', 'none')
02675 
02676                 if (attr == 'fill_color_rgba'):
02677                   self.frame.setAttribute(
02678                       'fill',
02679                       self.rgb_write(item[1][frame_no]['fill_color_rgba']))
02680                   continue
02681 
02682                 if (attr == 'x2'):
02683                   if item[1][frame_no].has_key('x1'):
02684                     cx = (item[1][frame_no]['x2']+item[1][frame_no]['x1'])/2
02685                   else:
02686                          points = self.get_last_rectel_bounds(item, frame_no)
02687                     cx = (item[1][frame_no]['x2']+ points[0])/2
02688                   rx = item[1][frame_no]['x2']-cx
02689                   self.frame.setAttribute('cx',str(cx))
02690                   self.frame.setAttribute('rx',str(rx))
02691                   continue
02692                 if (attr == 'x1'):
02693                   if item[1][frame_no].has_key('x2'):
02694                     continue
02695                   else:
02696                          points = self.get_last_rectel_bounds(item, frame_no)
02697                     cx = (item[1][frame_no]['x1']+ points[2])/2
02698                     rx = cx - item[1][frame_no]['x1']
02699                     self.frame.setAttribute('cx',str(cx))
02700                     self.frame.setAttribute('rx',str(rx))
02701                   continue
02702 
02703                 if (attr == 'y2'):
02704                   if item[1][frame_no].has_key('y1'):
02705                     cy = (item[1][frame_no]['y2']+item[1][frame_no]['y1'])/2
02706                   else:
02707                          points = self.get_last_rectel_bounds(item, frame_no)
02708                     cy = (item[1][frame_no]['y2']+ points[1])/2
02709                   ry = item[1][frame_no]['y2']-cy
02710                   self.frame.setAttribute('cy',str(cy))
02711                   self.frame.setAttribute('ry',str(ry))
02712                   continue
02713                 if (attr == 'y1'):
02714                   if item[1][frame_no].has_key('y2'):
02715                     continue
02716                   else:
02717                          points = self.get_last_rectel_bounds(item, frame_no)
02718                     cy = (item[1][frame_no]['y1']+ points[3])/2
02719                     ry = cy - item[1][frame_no]['y1']
02720                     self.frame.setAttribute('cy',str(cy))
02721                     self.frame.setAttribute('ry',str(ry))
02722                   continue
02723 
02724               if (self.types[item[0]] == 'line'):
02725                 if (attr == 'fill_color_rgba'):
02726                   self.frame.setAttribute(
02727                       'stroke',
02728                       self.rgb_write(item[1][frame_no]['fill_color_rgba']))
02729                   continue
02730                 if (attr == 'width-units'):
02731                   self.frame.setAttribute(
02732                       'stroke-width',
02733                       str(item[1][frame_no]['width-units']))
02734                   continue
02735                 if (attr == 'points'):
02736                     if item[1][frame_no].has_key('create'):
02737                         self.frame.setAttribute('x1', str(item[1][frame_no]['points'][0]))
02738                         self.frame.setAttribute('y1', str(item[1][frame_no]['points'][1]))
02739                         self.frame.setAttribute('x2', str(item[1][frame_no]['points'][2]))
02740                         self.frame.setAttribute('y2', str(item[1][frame_no]['points'][3]))
02741                     else:
02742                         last_points = self.get_last_line_points(item, frame_no)
02743                         points = item[1][frame_no]['points']
02744 
02745                         if points[0] != last_points[0]:
02746                             self.frame.setAttribute('x1', str(points[0]))
02747                         if points[1] != last_points[1]:
02748                             self.frame.setAttribute('y1', str(points[1]))
02749                         if points[2] != last_points[2]:
02750                             self.frame.setAttribute('x2', str(points[2]))
02751                         if points[3] != last_points[3]:
02752                             self.frame.setAttribute('y2',str( points[3]))
02753                     continue
02754 
02755               if (self.types[item[0]] == 'text'):
02756                 if (attr == 'fill_color_rgba'):
02757                   self.frame.setAttribute(
02758                       'fill',
02759                       self.rgb_write(item[1][frame_no]['fill_color_rgba']))
02760                   continue
02761                 if (attr == 'anchor'):
02762                     self.frame.setAttribute(
02763                         'text-anchor',
02764                         'middle')
02765                     continue
02766 #                if (attr == 'text'):
02767 #                  self.frame.appendChild(self.document.createTextNode(item[1][frame_no]['text'].encode('UTF-8')))
02768 #                  continue
02769 
02770               if ( attr == 'font' ):
02771                   font = item[1][frame_no]['font']
02772                   list = font.split()
02773 
02774                   self.frame.setAttribute(
02775                       'font-size',list[-1] + 'pt')
02776                   self.frame.setAttribute(
02777                       'font-family',list[0] + ' ' + list[1])
02778 
02779 
02780               if (item[0] == 'IMAGE'):
02781                 if (attr == 'image_name'):
02782                   image_name=item[1][frame_no]['image_name']
02783                   list_image_name = image_name.split('/')
02784                   if self.images_list.has_key(image_name):
02785                     self.element.setAttribute(
02786                         'xlink:href',self.images_list[image_name])
02787                   else:
02788                     self.symbol = self.document.createElement('symbol')
02789                     self.defel.appendChild(self.symbol)
02790                     self.image = self.document.createElement('image')
02791                     self.symbol.appendChild(self.image)
02792                     self.symbol.setAttribute(
02793                         'id', 'image' + str(len(self.images_list)))
02794                     self.element.setAttribute(
02795                         'xlink:href', '#image' + str(len(self.images_list)))
02796                     self.images_list[image_name]= 'image' + str(len(self.images_list))
02797                     # Base64 included image, to get all in one file
02798                     #
02799                     # that's dirty, but i want something simple for kids
02800                     #
02801                     # anyway image can be used multiple time,
02802                     # it will be included only once
02803                     #
02804                     # Maybe put file and image in same directory ?
02805                     #
02806                     imagefile = open(gcompris.DATA_DIR + '/' + image_name)
02807                     base64string = base64.encodestring(imagefile.read())
02808                     self.image.setAttribute(
02809                         'xlink:href','data:image/png;base64,' + base64string)
02810 
02811                     # get real size of the image.
02812                     pixmap = gcompris.utils.load_pixmap(image_name)
02813                     width = pixmap.get_width()
02814                     height = pixmap.get_height()
02815 
02816                     # Pass the <symbol> with image included.
02817                     self.image.setAttribute(
02818                         'x','0')
02819                     self.image.setAttribute(
02820                         'y','0')
02821                     self.image.setAttribute(
02822                         'width', str(width))
02823                     self.image.setAttribute(
02824                         'height',str(height))
02825                     self.symbol.setAttribute(
02826                         'viewBox','0 0 '+ str(width) + ' ' + str(height))
02827                     self.symbol.setAttribute(
02828                         'preserveAspectRatio','none')
02829                     self.gcompris_name = self.document.createElement('gcompris:image_name')
02830                     # Pass the image_name info in private child
02831                     self.image.appendChild(self.gcompris_name)
02832                     self.gcompris_name.setAttribute('value',image_name)
02833                   continue
02834 
02835                 if ((attr == 'height_set') or  (attr == 'width_set')):
02836                   continue
02837 
02838               if (attr == 'matrice'):
02839                   self.frame.setAttribute(
02840                       'transform',
02841                       'matrix' + str(item[1][frame_no]['matrice']))
02842                   continue
02843 
02844               if fles.gcomprisBoard.mode == 'draw':
02845                 if (attr != 'create'):
02846                   self.frame.setAttribute(attr,str(item[1][frame_no][attr]))
02847               else:
02848                 self.frame.setAttribute(attr,str(item[1][frame_no][attr]))
02849         self.finishOutput()
02850 

Here is the call graph for this function:


Member Data Documentation

Definition at line 2597 of file anim.py.

Definition at line 2607 of file anim.py.

Definition at line 2510 of file anim.py.

Definition at line 2828 of file anim.py.

Definition at line 2789 of file anim.py.

Definition at line 2508 of file anim.py.

Definition at line 2517 of file anim.py.

Definition at line 2514 of file anim.py.

Definition at line 2507 of file anim.py.

Definition at line 2787 of file anim.py.

Definition at line 2496 of file anim.py.


The documentation for this class was generated from the following file: