Back to index

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

List of all members.

Public Member Functions

def initOutput
def finishOutput
def get_last_rectel_bounds
def get_last_line_points
def rgb_write
def run

Public Attributes

 document
 svg
 metadata
 gc_desc
 script
 gcompris_frames_total
 defel
 foreign
 button1
 button1text
 button2
 button2text
 speedtext
 ratetext
 button3
 button3text
 button4
 button4text
 types
 outfp
 images_list
 frames_total
 list_to
 list_from
 element
 frame
 symbol
 image
 gcompris_name

Detailed Description

Concrete conversion process which uses a DOM structure as an
internal data structure.

Content is added to the DOM tree for each input record, and the
entire tree is serialized and written to the output stream in the
finishOutput() method.

Definition at line 2851 of file anim.py.


Member Function Documentation

Definition at line 2945 of file anim.py.

02945 
02946     def finishOutput(self):
02947 #        t = self.document.createTextNode("\n")
02948 #        self.svg.appendChild(t)
02949         # XXX toxml not supported by 4DOM
02950         # self.outfp.write(self.document.toxml())
02951         xml.dom.ext.PrettyPrint(self.document, self.outfp)
02952         self.outfp.write("\n")
02953 
02954         # now each item needs to get it's frames_info cleared
02955         global fles
02956         if fles.gcomprisBoard.mode == 'draw':
02957           for anAnimItem in self.list_from[:]:
02958             del anAnimItem.frames_info[fles.current_frame]
02959 
02960 
02961 
02962 
02963 

def anim.BaseProcess.get_last_line_points (   self,
  item,
  frame_no 
) [inherited]

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 
) [inherited]

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)

Definition at line 2859 of file anim.py.

02859 
02860     def initOutput(self):
02861         global fles
02862         # Create a new document with no namespace uri, qualified name,
02863         # or document type
02864         self.document = implementation.createDocument(None,None,None)
02865         self.svg = self.document.createElement("svg")
02866         self.svg.setAttribute("id","svgroot")
02867         self.svg.setAttribute("width","800")
02868         self.svg.setAttribute("height","550")
02869         self.svg.setAttribute("version","1.1")
02870         self.svg.setAttribute("xmlns","http://www.w3.org/2000/svg")
02871         self.svg.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink")
02872         self.svg.setAttribute("xmlns:html","http://www.w3.org/1999/xhtml")
02873         self.svg.setAttribute("xmlns:gcompris","http://www.ofset.org/gcompris")
02874         self.svg.setAttribute("onload","init();")
02875         self.document.appendChild(self.svg)
02876 
02877         self.metadata = self.document.createElement("metadata")
02878         self.svg.appendChild(self.metadata)
02879         self.gc_desc = self.document.createElement("gcompris:description")
02880         self.metadata.appendChild(self.gc_desc)
02881         self.gc_desc.setAttribute('value',fles.format_string['svg'])
02882 
02883         if fles.gcomprisBoard.mode != 'draw':
02884           self.script = self.document.createElement("script")
02885           self.svg.appendChild(self.script)
02886           self.gcompris_frames_total = self.document.createElement("gcompris:frames_total")
02887           self.svg.appendChild(self.gcompris_frames_total)
02888           self.gcompris_frames_total.setAttribute("value",str(self.frames_total))
02889           scriptfile = open(gcompris.DATA_DIR + "/anim/animation.js")
02890           t = self.document.createCDATASection(scriptfile.read())
02891           self.script.appendChild(t)
02892 
02893         self.defel = self.document.createElement("defs")
02894         self.svg.appendChild(self.defel)
02895 
02896         if fles.gcomprisBoard.mode != 'draw':
02897           # html buttons included
02898           self.foreign = self.document.createElement("foreignObject")
02899           self.svg.appendChild(self.foreign)
02900           self.foreign.setAttribute("x","300")
02901           self.foreign.setAttribute("y","520")
02902           self.foreign.setAttribute("width","800")
02903           self.foreign.setAttribute("height","30")
02904           self.foreign.setAttribute("requiredExtensions","http://www.mozilla.org/SVGExtensions/EmbeddedXHTML")
02905           self.button1 = self.document.createElement("html:button")
02906           self.foreign.appendChild(self.button1)
02907           self.button1.setAttribute("onclick", "start_animation();")
02908           self.button1text = self.document.createTextNode(u'>'.encode('UTF-8'))
02909           self.button1.appendChild(self.button1text)
02910 
02911           self.button2 = self.document.createElement("html:button")
02912           self.foreign.appendChild(self.button2)
02913           self.button2.setAttribute("onclick", "speed_down();")
02914           self.button2text = self.document.createTextNode(u'<<'.encode('UTF-8'))
02915           self.button2.appendChild(self.button2text)
02916 
02917           self.speedtext = self.document.createElement("html:input")
02918           self.foreign.appendChild(self.speedtext)
02919           self.speedtext.setAttribute("id","speed_text")
02920           self.speedtext.setAttribute("type","TEXT")
02921           self.speedtext.setAttribute("size","6")
02922           self.speedtext.setAttribute("maxlength","6")
02923           self.speedtext.setAttribute("value","4 fps")
02924 
02925           self.ratetext = self.document.createElement("html:input")
02926           self.foreign.appendChild(self.ratetext)
02927           self.ratetext.setAttribute("id","rate_text")
02928           self.ratetext.setAttribute("type","TEXT")
02929           self.ratetext.setAttribute("size","6")
02930           self.ratetext.setAttribute("maxlength","6")
02931           self.ratetext.setAttribute("value","")
02932 
02933           self.button3 = self.document.createElement("html:button")
02934           self.foreign.appendChild(self.button3)
02935           self.button3.setAttribute("onclick", "speed_up();")
02936           self.button3text = self.document.createTextNode(u'>>'.encode('UTF-8'))
02937           self.button3.appendChild(self.button3text)
02938 
02939           self.button4 = self.document.createElement("html:button")
02940           self.foreign.appendChild(self.button4)
02941           self.button4.setAttribute("onclick", "stop_animation();")
02942           self.button4text = self.document.createTextNode(u'||'.encode('UTF-8'))
02943           self.button4.appendChild(self.button4text)
02944 

Here is the caller graph for this function:

def anim.BaseProcess.rgb_write (   self,
  rgba 
) [inherited]

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) [inherited]
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 2904 of file anim.py.

Definition at line 2907 of file anim.py.

Definition at line 2910 of file anim.py.

Definition at line 2913 of file anim.py.

Definition at line 2932 of file anim.py.

Definition at line 2935 of file anim.py.

Definition at line 2938 of file anim.py.

Definition at line 2941 of file anim.py.

Definition at line 2892 of file anim.py.

Definition at line 2863 of file anim.py.

Definition at line 2597 of file anim.py.

Definition at line 2897 of file anim.py.

Definition at line 2607 of file anim.py.

Definition at line 2510 of file anim.py.

Definition at line 2878 of file anim.py.

Definition at line 2885 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 2876 of file anim.py.

Definition at line 2507 of file anim.py.

Definition at line 2924 of file anim.py.

Definition at line 2883 of file anim.py.

Definition at line 2916 of file anim.py.

Definition at line 2864 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: