Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
anim.Outputter Class Reference

List of all members.

Public Member Functions

def __init__
def StartElementHandler
def EndElementHandler
def CharacterDataHandler
def ProcessingInstructionHandler
def StartNamespaceDeclHandler
def EndNamespaceDeclHandler
def StartCdataSectionHandler
def EndCdataSectionHandler
def CommentHandler
def NotationDeclHandler
def UnparsedEntityDeclHandler
def NotStandaloneHandler
def ExternalEntityRefHandler
def SkippedEntityHandler
def DefaultHandler
def DefaultHandlerExpand

Public Attributes

 fixedattributs
 wait_element_list
 in_element
 svg_element
 images
 picklelist
 item_getting
 image_getting
 wait_end_of
 points
 last_points

Detailed Description

Definition at line 3016 of file anim.py.


Constructor & Destructor Documentation

def anim.Outputter.__init__ (   self)

Definition at line 3019 of file anim.py.

03019 
03020     def __init__(self):
03021        self.fixedattributs = fles.fixedattributs
03022 
03023        # used to check the element coming is the right one
03024        self.wait_element_list = ['svg']
03025 
03026        # keep where we are in the tree
03027        self.in_element = []
03028 
03029        # elements constituting the draws.
03030        self.svg_element = ['use', 'rect', 'ellipse', 'line', 'text']
03031 
03032        # dict with id : image_name pairs
03033        self.images = {}
03034 
03035        # Format of output in the gcompris anim2 pickle format,
03036        # close to the anim2 internal format
03037        self.picklelist = []
03038 
03039        # Item we are looking in. In fact we keep here the item we actually read the frames information.
03040        self.item_getting = None
03041 
03042        # id of image we are looking in
03043        self.image_getting = None
03044 
03045        # used to skip elements we are not interested in (foreignObject, script)
03046        self.wait_end_of = None
03047 


Member Function Documentation

def anim.Outputter.CharacterDataHandler (   self,
  data 
)

Definition at line 3318 of file anim.py.

03318 
03319     def CharacterDataHandler(self, data):
03320       pass

def anim.Outputter.CommentHandler (   self,
  text 
)

Definition at line 3336 of file anim.py.

03336 
03337     def CommentHandler(self, text):
03338       pass

def anim.Outputter.DefaultHandler (   self,
  userData 
)

Definition at line 3354 of file anim.py.

03354 
03355     def DefaultHandler(self, userData):
03356       pass

def anim.Outputter.DefaultHandlerExpand (   self,
  userData 
)

Definition at line 3357 of file anim.py.

03357 
03358     def DefaultHandlerExpand(self, userData):
03359       pass
03360 
03361 

Definition at line 3333 of file anim.py.

03333 
03334     def EndCdataSectionHandler(self):
03335       pass

def anim.Outputter.EndElementHandler (   self,
  name 
)

Definition at line 3273 of file anim.py.

03273 
03274     def EndElementHandler(self, name):
03275         if (self.wait_end_of != None):
03276           if (name == self.wait_end_of):
03277             self.wait_end_of = None
03278           else: return
03279 
03280         if (name != self.in_element[-1]):
03281           # Let this print it can handle error
03282           print "Error close ", name, " but ", self.in_element[-1], " waited."
03283           return
03284         self.in_element.pop()
03285 
03286         if (name == 'svg'):
03287             list_restore(self.picklelist)
03288             return
03289         if (name == 'metadata'):
03290           if (fles.gcomprisBoard.mode == 'draw'):
03291             self.wait_element_list = [ 'defs' ]
03292           else:
03293             self.wait_element_list = [ 'script' ]
03294           return
03295         if (name == 'script'):
03296             self.wait_element_list = [ 'gcompris:frames_total' ]
03297             return
03298         if (name == 'gcompris:frames_total'):
03299             self.wait_element_list = ['defs']
03300             return
03301         if (name == 'symbol'):
03302             self.wait_element_list = ['symbol']
03303             return
03304         if (name == 'defs'):
03305           if (fles.gcomprisBoard.mode == 'draw'):
03306             self.wait_element_list = self.svg_element
03307           else:
03308             self.wait_element_list = ['foreignObject']
03309             return
03310         if (name == 'foreignObject'):
03311             self.wait_element_list = self.svg_element
03312             return
03313         if (name in self.svg_element):
03314             self.wait_element_list = self.svg_element
03315             self.picklelist.append([self.item_getting[0],self.item_getting[1].copy()])
03316             self.item_getting = None
03317             return

Here is the call graph for this function:

def anim.Outputter.EndNamespaceDeclHandler (   self,
  prefix 
)

Definition at line 3327 of file anim.py.

03327 
03328     def EndNamespaceDeclHandler(self, prefix):
03329       pass

def anim.Outputter.ExternalEntityRefHandler (   self,
  args 
)

Definition at line 3348 of file anim.py.

03348 
03349     def ExternalEntityRefHandler(self, *args):
03350       return 1

def anim.Outputter.NotationDeclHandler (   self,
  args 
)

Definition at line 3339 of file anim.py.

03339 
03340     def NotationDeclHandler(self, *args):
03341       pass

def anim.Outputter.NotStandaloneHandler (   self,
  userData 
)

Definition at line 3345 of file anim.py.

03345 
03346     def NotStandaloneHandler(self, userData):
03347       return 1

def anim.Outputter.ProcessingInstructionHandler (   self,
  target,
  data 
)

Definition at line 3321 of file anim.py.

03321 
03322     def ProcessingInstructionHandler(self, target, data):
03323       pass

def anim.Outputter.SkippedEntityHandler (   self,
  args 
)

Definition at line 3351 of file anim.py.

03351 
03352     def SkippedEntityHandler(self, *args):
03353       pass

Definition at line 3330 of file anim.py.

03330 
03331     def StartCdataSectionHandler(self):
03332       pass

def anim.Outputter.StartElementHandler (   self,
  name,
  attrs 
)

Definition at line 3048 of file anim.py.

03048 
03049     def StartElementHandler(self, name, attrs):
03050         global fles
03051         def get_attrs(attrs):
03052           global fles
03053 
03054           def rgb(r,g,b):
03055              return (r<<24L) + (g<<16) + (b<<8) + 255
03056 
03057           def matrix(a, b, c, d, e, f):
03058             return (a , b, c, d, e, f)
03059 
03060           frame_info = {}
03061 
03062           keys = attrs.keys()
03063           for k in keys:
03064              if (k == 'create'):
03065                if (self.item_getting[0] == 'IMAGE'):
03066                  frame_info['image_name'] = self.image_getting
03067                if ('fill' in keys):
03068                  if (attrs['fill']=='none'):
03069                    if (self.item_getting[0] == 'FILL_RECT'):
03070                      self.item_getting[0] = 'RECT'
03071                    if (self.item_getting[0] == 'FILL_CIRCLE'):
03072                      self.item_getting[0] = 'CIRCLE'
03073                frame_info.update(self.fixedattributs[self.item_getting[0]])
03074              if (k == 'transform'):
03075                  frame_info['matrice'] =  eval(attrs[k])
03076                  continue
03077              if (k == 'stroke'):
03078                # used in CIRCLE LINE and RECT
03079                if (self.item_getting[0] in ['CIRCLE','RECT','LINE','FILL_RECT','FILL_CIRCLE']):
03080                  # CIRCLE RECT -> outline_color_rgba
03081                  # LINE -> fill_color_rgba
03082                  if (self.item_getting[0] == 'LINE'):
03083                    frame_info['fill_color_rgba'] = eval(attrs[k])
03084                  else:
03085                    frame_info['outline_color_rgba'] = eval(attrs[k])
03086                  continue
03087              if (k == 'fill'):
03088                #used in FILL_CIRCLE and FILL_RECT
03089                if (self.item_getting[0] in ['FILL_CIRCLE','FILL_RECT','TEXT']):
03090                  frame_info['fill_color_rgba'] = eval(attrs[k])
03091                continue
03092              if (k in ['stroke-width', 'font-size', 'font-family', 'font', 'text-anchor']):
03093                continue
03094              if (k in ['x1', 'y1', 'x2', 'y2','x','y','width','height', 'cx', 'cy', 'rx', 'ry']):
03095                self.points[k] =  eval(attrs[k])
03096                continue
03097 
03098              if (k == 'text'):
03099                 frame_info['text']=attrs[k]
03100                 continue
03101              if (k == 'xlink:href'):
03102                # in draw, this is in attrs becaus the frame is directly in element.
03103                frame_info['image_name'] = self.image_getting
03104                continue
03105 
03106              if (not (k in ['x1', 'y1', 'x2', 'y2','x','y','width','height', 'cx', 'cy', 'rx', 'ry'])):
03107                #print u'Attribut non trait\xe9 :', self.item_getting[0], " ", k, "=", attrs[k]
03108                frame_info[k] = eval(attrs[k])
03109 
03110           if (self.points != {}):
03111             if (self.item_getting[0] == 'LINE'):
03112               for coord in ['x1', 'y1', 'x2', 'y2']:
03113                 if (not self.points.has_key(coord)):
03114                   self.points[coord] = self.last_points[coord]
03115               frame_info['points'] = ( self.points['x1'],
03116                                          self.points['y1'],
03117                                          self.points['x2'],
03118                                          self.points['y2'])
03119               self.last_points.update(self.points)
03120               self.points = {}
03121 
03122             if (self.item_getting[0] == 'IMAGE'):
03123               for j in self.points.keys():
03124                   frame_info[j] = self.points[j]
03125               self.points = {}
03126 
03127             if (self.item_getting[0] in ['RECT', 'FILL_RECT']):
03128               dist = { 'x' : 'width', 'y': 'height'}
03129               for c in ['x', 'y']:
03130                 if (self.points.has_key(c)):
03131                   b1 = self.points[c]
03132                   if (self.points.has_key(dist[c])):
03133                     # x and w changed
03134                     b2 = b1 + self.points[dist[c]]
03135                   else:
03136                     # x changed but not w
03137                     b2 = b1 + self.last_points[c + '2'] - self.last_points[c + 1]
03138                 else:
03139                   b1 = self.last_points[c + '1']
03140 
03141                   if (self.points.has_key(dist[c])):
03142                     # x not changed but w
03143                     b2 = b1 + self.points[dist[c]]
03144                   else:
03145                     # x and w not changed. normally never here
03146                     b2 = self.last_points[c + '2']
03147 
03148                 if (b1 != self.last_points[c+'1']):
03149                   frame_info[c+'1'] = b1
03150                   self.last_points[c+'1'] = b1
03151                 if (b2 != self.last_points[c+'2']):
03152                   frame_info[c+'2'] = b2
03153                   self.last_points[c+'2'] = b2
03154 
03155             if (self.item_getting[0] in ['CIRCLE', 'FILL_CIRCLE']):
03156               dist = { 'x' : 'rx', 'y': 'ry'}
03157               for c in ['x', 'y']:
03158                 if (self.points.has_key('c' + c)):
03159                   if (self.points.has_key(dist[c])):
03160                     # c and r change
03161                     b1 = self.points['c' + c] - self.points[dist[c]]
03162                     b2 = self.points['c' + c] + self.points[dist[c]]
03163                   else:
03164                     # c changed but not r
03165                     b1 = self.points['c' + c] - (self.last_points[c +'2'] - self.last_points[c +'1'])/2
03166                     b2 = self.points['c' + c] + (self.last_points[c +'2'] - self.last_points[c +'1'])/2
03167                 else:
03168                   if (self.points.has_key(dist[c])):
03169                     # c not changed , r changed
03170                     b1 = (self.last_points[c + '1'] + self.last_points[c + '2'])/2 - self.points[dist[c]]
03171                     b2 = b1 + 2 * self.points[dist[c]]
03172                   else:
03173                     # c and r not changed
03174                     b1 = self.last_points[c + '1']
03175                     b2 = self.last_points[c + '2']
03176 
03177                 if (b1 != self.last_points[c+'1']):
03178                   frame_info[c+'1'] = b1
03179                   self.last_points[c+'1'] = b1
03180                 if (b2 != self.last_points[c+'2']):
03181                   frame_info[c+'2'] = b2
03182                   self.last_points[c+'2'] = b2
03183 
03184             if (self.item_getting[0] in ['TEXT']):
03185               for c in ['x', 'y']:
03186                 if (self.points[c] != self.last_points[c+'1']):
03187                   frame_info[c] = self.points[c]
03188                   self.last_points[c+'1'] = self.points[c]
03189 
03190           return frame_info
03191 
03192         if self.wait_end_of != None:
03193            # ignore all childs of that element .
03194            return
03195 
03196         if not (name in self.wait_element_list):
03197            #print "Error : wait ", self.wait_element_list, " get ", name
03198            return
03199         self.in_element.append(name)
03200         if (name == 'svg'):
03201           if (fles.gcomprisBoard.mode == 'draw'):
03202             self.wait_element_list = [ 'defs', 'metadata' ]
03203           else:
03204             self.wait_element_list = [ 'script', 'metadata' ]
03205           return
03206         if (name == 'metadata'):
03207            self.wait_element_list = ['gcompris:description']
03208            return
03209         if (name == 'gcompris:description'):
03210            desc = attrs['value']
03211            return
03212         if (name == 'script'):
03213            self.wait_end_of = name
03214            return
03215         if (name == 'foreignObject'):
03216            self.wait_end_of = name
03217            return
03218         if (name == 'gcompris:frames_total'):
03219            fles.frames_total = eval(attrs['value'])
03220            return
03221         if (name == 'defs'):
03222            self.wait_element_list = ['symbol']
03223            return
03224         if (name == 'symbol'):
03225            # just get the id.
03226            self.wait_element_list = ['image']
03227            self.image_getting = attrs['id']
03228         if (name == 'image'):
03229            #the only interresting thing is the name in gcompris tree of this image. This the child element <gcompris:image_name /> value attribut.
03230            self.wait_element_list = ['gcompris:image_name']
03231            return
03232         if (name == 'gcompris:image_name'):
03233            #the only interresting thing is the name in gcompris tree of this image. This the child element <gcompris:image_name /> value attribut.
03234            image_id = attrs['value']
03235            self.images['#' + self.image_getting] =  image_id
03236            return
03237         if (name in self.svg_element):
03238            self.wait_element_list = ['gcompris:frame']
03239            # used to check modification in x, y, w, h positions
03240            self.points = {}
03241            self.last_points = { 'x1' : None,
03242                                 'y1' : None,
03243                                 'x2' : None,
03244                                 'y2' : None
03245                                 }
03246 
03247            if (name == 'use'):
03248              self.item_getting = ['IMAGE',{}]
03249              # We will put image_name when we meet 'create' attr, in frame_info spec. For that we need to keep the name of that image.
03250              self.image_getting = self.images[attrs['xlink:href']]
03251            if (name == 'text'):
03252              self.item_getting = ['TEXT',{}]
03253            if (name == 'line'):
03254              self.item_getting = ['LINE',{}]
03255            if (name == 'rect'):
03256              # Warning ! Will be changed in RECT
03257              # if fill='none' found with create attr.
03258              self.item_getting = ['FILL_RECT',{}]
03259            if (name == 'ellipse'):
03260              # Warning ! Will be changed in CIRCLE
03261              # if fill='none'  found with create attr.
03262              self.item_getting = ['FILL_CIRCLE',{}]
03263 
03264            if (fles.gcomprisBoard.mode == 'draw'):
03265              self.item_getting[1][0] = get_attrs(attrs)
03266 
03267         if (name == 'gcompris:frame'):
03268           self.item_getting[1][eval(attrs['time'])] = {}
03269           frame_info = self.item_getting[1][eval(attrs['time'])]
03270           del attrs['time']
03271 
03272           frame_info.update(get_attrs(attrs))

Here is the call graph for this function:

def anim.Outputter.StartNamespaceDeclHandler (   self,
  prefix,
  uri 
)

Definition at line 3324 of file anim.py.

03324 
03325     def StartNamespaceDeclHandler(self, prefix, uri):
03326       pass

def anim.Outputter.UnparsedEntityDeclHandler (   self,
  args 
)

Definition at line 3342 of file anim.py.

03342 
03343     def UnparsedEntityDeclHandler(self, *args):
03344       pass


Member Data Documentation

Definition at line 3020 of file anim.py.

Definition at line 3042 of file anim.py.

Definition at line 3032 of file anim.py.

Definition at line 3026 of file anim.py.

Definition at line 3039 of file anim.py.

Definition at line 3240 of file anim.py.

Definition at line 3036 of file anim.py.

Definition at line 3119 of file anim.py.

Definition at line 3029 of file anim.py.

Definition at line 3023 of file anim.py.

Definition at line 3045 of file anim.py.


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