Package fife :: Package extensions :: Module fife_compat
[hide private]
[frames] | no frames]

Source Code for Module fife.extensions.fife_compat

 1  # -*- coding: utf-8 -*- 
 2   
 3  # #################################################################### 
 4  #  Copyright (C) 2005-2019 by the FIFE team 
 5  #  http://www.fifengine.net 
 6  #  This file is part of FIFE. 
 7  # 
 8  #  FIFE is free software; you can redistribute it and/or 
 9  #  modify it under the terms of the GNU Lesser General Public 
10  #  License as published by the Free Software Foundation; either 
11  #  version 2.1 of the License, or (at your option) any later version. 
12  # 
13  #  This library is distributed in the hope that it will be useful, 
14  #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
16  #  Lesser General Public License for more details. 
17  # 
18  #  You should have received a copy of the GNU Lesser General Public 
19  #  License along with this library; if not, write to the 
20  #  Free Software Foundation, Inc., 
21  #  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
22  # #################################################################### 
23   
24  """ 
25  FIFE Backwards Combatibility Layer 
26  ================================== 
27   
28  This module can be imported if you want to 
29  run code that wasn't adapted to API changes in FIFE. 
30   
31  2008.1 
32  ------ 
33   
34   - Animation.addFrame now expects a fife.ResourcePtr instead of an fife.Image 
35   - Pool.getIndex is just an alias for Pool.addResourceFromFile. 
36   - EventManager.setNonConsumableKeys is superseeded by EventManager.setKeyFilter 
37   
38  """ 
39  from __future__ import print_function 
40   
41  from fife import fife 
42   
43  # Utility functions 
44   
45 -def deprecated(revision,message):
46 print("fife_compat: Deprecation warning - See revision %d " % revision) 47 print(" - ",message)
48
49 -def this_is_deprecated(func,revision=0,message=None):
50 if message is None: 51 message = repr(func) + " is deprecated." 52 def wrapped_func(*args,**kwargs): 53 deprecated(revision,message) 54 return func(*args,**kwargs)
55 return wrapped_func 56
57 -def _compat_NonConsumableKeys():
58 class CompatKeyFilter(fife.IKeyFilter): 59 def __init__(self, keys): 60 fife.IKeyFilter.__init__(self) 61 self.keys = keys
62 63 def isFiltered(self, event): 64 return event.getKey().getValue() in self.keys 65 66 def _setNonConsumableKeys(self,keys): 67 deprecated(2636, "Write an IKeyFilter instead of using EventManager.setNonConsumableKeys.\n" + 68 "You probably don't need it anyway") 69 self.compat_keyfilter = CompatKeyFilter(keys) 70 self.compat_keyfilter.__disown__() 71 self.setKeyFilter(self.compat_keyfilter) 72 73 def _getNonConsumableKeys(self,keys): 74 deprecated(2636, "Write an IKeyFilter instead of using EventManager.getNonConsumableKeys.") 75 return self.compat_keyfilter.keys 76 77 fife.EventManager.setNonConsumableKeys = _setNonConsumableKeys 78 fife.EventManager.getNonConsumableKeys = _getNonConsumableKeys 79 80 _compat_NonConsumableKeys() 81