Back to index

gcompris  8.2.2
Classes | Functions | Variables
anim Namespace Reference

Classes

class  Gcompris_anim
class  BaseProcess
class  DOMProcess
class  Outputter

Functions

def general_save
def general_restore
def anim2_to_file
def file_to_anim2
def list_restore
def restore_item
def anim2_to_svg
 SVG anim 2 export.
def svg_to_anim2
def image_selected

Variables

 python_xml = False
 fles = None

Function Documentation

def anim.anim2_to_file (   filename)

Definition at line 2217 of file anim.py.

02217 
02218 def anim2_to_file(filename):
02219   global fles
02220 
02221   file =   open(filename, 'wb')
02222 
02223   # Save the descriptif frame:
02224   pickle.dump(fles.format_string['gcompris'],file,True)
02225 
02226   # save the total of frames
02227   pickle.dump(fles.frames_total, file, True)
02228 
02229   # save the list into
02230   list_to = []
02231 
02232   # get the list
02233   list_from = []
02234 
02235   if (fles.gcomprisBoard.mode == 'draw'):
02236     # in draw we need to get the list in z order, because of svg.
02237     def get_item_at(z):
02238       for item in eval('fles.' + fles.itemlist[fles.gcomprisBoard.mode]):
02239         if item.z == z: return item
02240     for z in fles.list_z_actual:
02241       list_from.append(get_item_at(z))
02242 
02243     # now each item needs to get it's frames_info updated
02244     for anAnimItem in list_from[:]:
02245       modified = fles.get_modified_parameters(anAnimItem)
02246       if len(modified) != 0:
02247         anAnimItem.frames_info[fles.current_frame] = modified
02248 
02249   else:
02250     list_from = fles.animlist
02251 
02252   for item in list_from:
02253     frames_info_copied = {}
02254     for t, d  in item.frames_info.iteritems():
02255       frames_info_copied[t] = d.copy();
02256     Sitem = [ item.type, frames_info_copied]
02257     list_frames = Sitem[1].keys()
02258     list_frames.sort()
02259     if ((Sitem[0] == 'TEXT') and (Sitem[1][list_frames[0]].has_key('anchor'))):
02260         Sitem[1][list_frames[0]]['text-anchor']='middle'
02261         del Sitem[1][list_frames[0]]['anchor']
02262     list_to.append(Sitem)
02263 
02264   pickle.dump(list_to, file, True)
02265   file.close()

Here is the call graph for this function:

Here is the caller graph for this function:

def anim.anim2_to_svg (   filename)

SVG anim 2 export.

Definition at line 2464 of file anim.py.

02464 
02465 def anim2_to_svg(filename):
02466 
02467     processor_class = DOMProcess
02468 
02469     outfp = open(filename,'w')
02470 
02471     processor = processor_class(outfp)
02472     processor.run()
02473 
02474     outfp.close()
02475 

Here is the caller graph for this function:

def anim.file_to_anim2 (   filename)

Definition at line 2266 of file anim.py.

02266 
02267 def file_to_anim2(filename):
02268   global fles
02269 
02270   file =   open(filename, 'rb')
02271   try:
02272     desc = pickle.load(file)
02273   except:
02274     file.close()
02275     print 'Cannot load ', filename , " as a GCompris animation"
02276     return
02277 
02278   if type(desc) == type('str'):
02279     # string
02280     if 'desc' != fles.format_string['gcompris']:
02281       if (desc == 'GCompris draw 2 cPikle file'
02282           or desc == 'GCompris anim 2 cPikle file'):
02283         fles.frames_total = pickle.load(file)
02284       else:
02285         print "ERROR: Unrecognized file format, file", filename, ' has description : ', desc
02286         file.close()
02287         return
02288     else:
02289       print "ERROR: Unrecognized file format (desc), file", filename, ' has description : ', desc
02290       file.close()
02291       return
02292 
02293   elif type(desc) == type(1):
02294     print filename, 'has no description. Are you sure it\'s', fles.format_string['gcompris'],'?'
02295     # int
02296     fles.frames_total = desc
02297 
02298   picklelist = pickle.load(file)
02299   file.close()
02300   list_restore(picklelist)

Here is the call graph for this function:

Here is the caller graph for this function:

def anim.general_restore (   filename,
  filetype 
)

Definition at line 2186 of file anim.py.

02186 
02187 def general_restore(filename, filetype):
02188   #print "general_restore : ", filename, " type ",filetype
02189   if filetype == None:
02190     filetype = filename.split('.')[-1]
02191 
02192   # Determine the file format by reading the first line
02193   file = open(filename, 'r')
02194   line = file.read(24)
02195   file.close();
02196   filetype = ""
02197   if(line == "UGCompris draw 2 cPikle"
02198      or line == "UGCompris anim 2 cPikle"):
02199     filetype = 'image/gcompris+anim'
02200   elif(line == "<?xml version='1.0' enco"):
02201     filetype = 'image/svg+xml'
02202 
02203   #   print " Detected type ",filetype
02204 
02205   if (filetype in ['image/svg+xml+javascript','image/svg+xml']):
02206     global python_xml
02207     if python_xml:
02208       svg_to_anim2(filename)
02209     else:
02210       gcompris.utils.dialog(_('SVG is disabled. Install python xml module to enable it'),None)
02211     return
02212   if (filetype in ['image/gcompris+anim','image/gcompris+draw']):
02213     file_to_anim2(filename)
02214     return
02215   print "Error File selector return unknown filetype :",filetype, "!!!"
02216 

Here is the call graph for this function:

def anim.general_save (   filename,
  filetype 
)

Definition at line 2170 of file anim.py.

02170 
02171 def general_save(filename, filetype):
02172   global fles
02173 
02174   fles.z_reinit()
02175 
02176   #print "general_save : ", filename, " type ",filetype
02177   if filetype == None:
02178     filetype = filename.split('.')[-1]
02179   if (filetype in ['image/svg+xml+javascript','image/svg+xml']):
02180     anim2_to_svg(filename)
02181     return
02182   if (filetype in ['image/gcompris+anim','image/gcompris+draw']):
02183     anim2_to_file(filename)
02184     return
02185   print "Error File selector return unknown filetype :",'|' + filetype + '|', "!!!"

Here is the call graph for this function:

def anim.image_selected (   image)

Definition at line 3362 of file anim.py.

03362 
03363 def image_selected(image):
03364   #fles is used because self is not passed through callback
03365   global fles
03366 
03367   pixmap = gcompris.utils.load_pixmap(image)
03368 
03369   fles.newitem = None
03370   fles.newitemgroup = fles.root_anim.add(
03371     gnomecanvas.CanvasGroup,
03372     x=0.0,
03373     y=0.0
03374     )
03375 
03376   x= fles.pos_x
03377   y= fles.pos_y
03378   width  = pixmap.get_width()
03379   height = pixmap.get_height()
03380 
03381   fles.newitem = fles.newitemgroup.add(
03382     gnomecanvas.CanvasPixbuf,
03383     pixbuf = pixmap,
03384     x=x,
03385     y=y,
03386     width=width,
03387     height=height,
03388     width_set = True,
03389     height_set = True
03390     )
03391 
03392   # Tell svg_save the filename
03393   # Write "filename=image" in the property of newitem
03394   # Can't do it here because in C python string are unreadable
03395   # gcompris.utils.canvas_set_property(fles.newitem, "filename", image)
03396 
03397   anAnimItem = fles.AnimItem()
03398   anAnimItem.z = fles.new_z()
03399   anAnimItem.canvas_item = fles.newitem
03400   anAnimItem.canvas_item.set_data("AnimItem", anAnimItem)
03401   anAnimItem.type = 'IMAGE'
03402   anAnimItem.image_name = image
03403   fles.framelist.append(anAnimItem)
03404   fles.list_z_actual.append(anAnimItem.z)
03405 
03406   fles.anchorize(fles.newitemgroup)
03407   fles.object_set_size_and_pos(fles.newitemgroup, x, y, x+width, y+height)
03408   fles.select_item(fles.newitemgroup)
03409 
03410   fles.newitem = None
03411   fles.newitemgroup = None
03412 
def anim.list_restore (   picklelist)

Definition at line 2301 of file anim.py.

02301 
02302 def list_restore(picklelist):
02303   global fles
02304 
02305   def update_anchors(item):
02306     global fles
02307 
02308     data_list = { 'LINE' : ['parent', 'points'],
02309                   'IMAGE' : ['parent', 'x', 'y', 'width', 'height'],
02310                   'TEXT' : ['parent', 'x', 'y'],
02311                   'RECT': ['parent', 'x1', 'y1', 'x2', 'y2'],
02312                   'FILL_RECT': ['parent', 'x1', 'y1', 'x2', 'y2'],
02313                   'CIRCLE': ['parent', 'x1', 'y1', 'x2', 'y2'],
02314                   'FILL_CIRCLE': ['parent', 'x1', 'y1', 'x2', 'y2']
02315       }
02316 
02317     data = {}
02318     for prop in data_list[item.type]:
02319       data[prop]=item.canvas_item.get_property(prop)
02320 
02321     if item.type == 'LINE':
02322       param = data['parent'], data['points'][0], data['points'][1], data['points'][2], data['points'][3],
02323     elif item.type == 'TEXT':
02324       bounds = item.canvas_item.get_bounds()
02325       param = data['parent'], bounds[0],bounds[1],bounds[2],bounds[3]
02326     elif item.type == 'IMAGE':
02327       param = data['parent'], data['x'], data['y'], data['x']+data['width'], data['y']+data['height']
02328     else:
02329       param = data['parent'], data['x1'], data['y1'], data['x2'], data['y2']
02330 
02331 
02332     fles.object_set_size_and_pos(*param)
02333 
02334   # Historic strate
02335   #fles.current_image = 0
02336 
02337   fles.selected = None
02338 
02339   for item in fles.framelist:
02340     try:
02341       # can have been destroyed before by a delete action. No matter
02342       item.canvas_item.get_property("parent").destroy()
02343     except:
02344       pass
02345 
02346   fles.framelist = []
02347   fles.animlist=[]
02348 
02349   for Sitem in picklelist:
02350     AItem = fles.AnimItem()
02351     AItem.type = Sitem[0]
02352     AItem.frames_info = Sitem[1]
02353     fles.animlist.append(AItem)
02354 
02355   missing_images = []
02356   for fles.current_frame in range(fles.frames_total+1):
02357     for item in fles.animlist[:]:
02358       if fles.gcomprisBoard.mode == 'draw':
02359         item.z = fles.animlist.index(item)
02360       restore_item( item, fles.current_frame, missing_images)
02361 
02362   if missing_images:
02363     list_images = ''
02364     for im in missing_images:
02365       list_images = list_images + im + '\n'
02366       gcompris.utils.dialog(_('Warning: the following images cannot be accessed on your system.\n') +
02367                             list_images +
02368                             _('The corresponding items have been skipped.'),
02369                             None)
02370   fles.list_z_last_shot= []
02371   for item in fles.framelist:
02372     fles.list_z_last_shot.append(item.z)
02373     update_anchors(item)
02374   fles.list_z_last_shot.sort()
02375   fles.list_z_actual = fles.list_z_last_shot[:]
02376   fles.z_reinit()
02377   fles.current_frame = fles.frames_total
02378 
02379   fles.root_anim.show()
02380 
02381   # now each item needs to get it's frames_info cleared
02382   if fles.gcomprisBoard.mode != 'draw':
02383     fles.item_frame_counter.set(text=fles.current_frame + 1)
02384   else:
02385     for anAnimItem in fles.animlist[:]:
02386       anAnimItem.frames_info = {}

Here is the call graph for this function:

Here is the caller graph for this function:

def anim.restore_item (   item,
  frame,
  missing 
)

Definition at line 2387 of file anim.py.

02387 
02388 def restore_item(item, frame, missing):
02389   global fles
02390   if not item.frames_info.has_key(frame):
02391     return
02392   modif = item.frames_info[frame].copy()
02393   if modif.has_key('delete'):
02394     item.canvas_item.get_property("parent").destroy()
02395     fles.framelist.remove(item)
02396     return False
02397   if (modif.has_key('create') or (fles.gcomprisBoard.mode == 'draw')):
02398 
02399     if modif.has_key('create'):
02400       del modif['create']
02401     if modif.has_key('z'):
02402       item.z = modif['z']
02403       del modif['z']
02404     if fles.gcomprisBoard.mode == 'draw':
02405       modif.update(fles.fixedattributs[item.type])
02406     matrice = modif['matrice']
02407     del modif['matrice']
02408     if ((item.type == 'TEXT') and (modif.has_key('text-anchor'))):
02409       del modif['text-anchor']
02410       del item.frames_info[frame]['text-anchor']
02411       item.frames_info[frame]['anchor']= gtk.ANCHOR_CENTER
02412       modif['anchor']= gtk.ANCHOR_CENTER
02413     if item.type == 'IMAGE':
02414       item.image_name =  modif['image_name']
02415 
02416       if (not os.access(gcompris.DATA_DIR + '/' + item.image_name, os.R_OK)
02417           and not os.access(item.image_name, os.R_OK)):
02418         missing.append(item.image_name)
02419         fles.animlist.remove(item)
02420         return False
02421       del modif['image_name']
02422       pixmap = gcompris.utils.load_pixmap(item.image_name)
02423       modif['pixbuf']= pixmap
02424     newitemgroup = fles.root_anim.add(
02425         gnomecanvas.CanvasGroup,
02426         x=0.0,
02427         y=0.0
02428         )
02429     item.canvas_item = newitemgroup.add(fles.types[item.type], **modif)
02430     item.canvas_item.set_data("AnimItem", item)
02431     fles.anchorize(newitemgroup)
02432     delta = len(fles.root_anim.item_list) - item.z -1
02433     if delta != 0:
02434       newitemgroup.lower(delta)
02435     newitemgroup.affine_absolute(matrice)
02436     fles.framelist.append(item)
02437     return True
02438   else:
02439     if modif.has_key('z'):
02440       item.z = modif['z']
02441       del modif['z']
02442       index = fles.root_anim.item_list.index(item.canvas_item.get_property("parent"))
02443       if index > item.z:
02444         item.canvas_item.get_property("parent").lower(index - item.z)
02445       else:
02446         item.canvas_item.get_property("parent").raise_(item.z - index)
02447     if  modif.has_key('matrice'):
02448       matrice = modif['matrice']
02449       del modif['matrice']
02450       item.canvas_item.get_property("parent").affine_absolute(matrice)
02451     if len(modif) != 0:
02452       # Bourrin: je supprime les ancres et je les remets apres les modifs
02453       # Pas envie de me faire ch*** a retraiter les resize et les move
02454       #item.canvas_item.get_property("parent").item_list[1].destroy()
02455       item.canvas_item.set(**modif)
02456       #fles.anchorize(item.canvas_item.get_property("parent"))
02457     return True

Here is the caller graph for this function:

def anim.svg_to_anim2 (   filename)
Process command line parameters and run the conversion.

Definition at line 2978 of file anim.py.

02978 
02979 def svg_to_anim2(filename):
02980     """Process command line parameters and run the conversion."""
02981 
02982     infp = open(filename)
02983     global fles
02984 
02985     fles.filename = filename
02986     out = Outputter()
02987     parser = expat.ParserCreate()
02988 
02989     HANDLER_NAMES = [
02990         'StartElementHandler', 'EndElementHandler',
02991         'CharacterDataHandler', 'ProcessingInstructionHandler',
02992         'UnparsedEntityDeclHandler', 'NotationDeclHandler',
02993         'StartNamespaceDeclHandler', 'EndNamespaceDeclHandler',
02994         'CommentHandler', 'StartCdataSectionHandler',
02995         'EndCdataSectionHandler',
02996         'DefaultHandler', 'DefaultHandlerExpand',
02997         #'NotStandaloneHandler',
02998         'ExternalEntityRefHandler', 'SkippedEntityHandler',
02999         ]
03000     parser.returns_unicode = 1
03001 
03002     for name in HANDLER_NAMES:
03003         setattr(parser, name, getattr(out, name))
03004 
03005     try:
03006         parser.ParseFile(infp)
03007     except expat.error:
03008         print '** Error', parser.ErrorCode, expat.ErrorString(parser.ErrorCode)
03009         print '** Line', parser.ErrorLineNumber
03010         print '** Column', parser.ErrorColumnNumber
03011         print '** Byte', parser.ErrorByteIndex
03012 
03013 
03014     infp.close()
03015     return

Here is the caller graph for this function:


Variable Documentation

anim.fles = None

Definition at line 62 of file anim.py.

anim.python_xml = False

Definition at line 51 of file anim.py.