annotate engine/extensions/fife_compat.py @ 331:48c99636453e

Added Licence header to all pypthon modules in extension/ Commit 3k, Yay :-)
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 24 Aug 2009 12:01:34 +0000
parents bb9902910067
children dfd48d49c044
rev   line source
331
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
1 #!/usr/bin/env python
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
2 # -*- coding: utf-8 -*-
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
3
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
4 # ####################################################################
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
5 # Copyright (C) 2005-2009 by the FIFE team
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
6 # http://www.fifengine.de
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
7 # This file is part of FIFE.
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
8 #
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
9 # FIFE is free software; you can redistribute it and/or
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
10 # modify it under the terms of the GNU Lesser General Public
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
11 # License as published by the Free Software Foundation; either
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
12 # version 2.1 of the License, or (at your option) any later version.
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
13 #
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
14 # This library is distributed in the hope that it will be useful,
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
17 # Lesser General Public License for more details.
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
18 #
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
19 # You should have received a copy of the GNU Lesser General Public
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
20 # License along with this library; if not, write to the
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
21 # Free Software Foundation, Inc.,
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
23 # ####################################################################
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 """
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 FIFE Backwards Combatibility Layer
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 ==================================
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 This module can be imported if you want to
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 run code that wasn't adapted to API changes in FIFE.
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 2008.1
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 ------
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 - Animation.addFrame now expects a fife.ResourcePtr instead of an fife.Image
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
36 - Pool.getIndex is just an alias for Pool.addResourceFromFile.
157
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
37 - EventManager.setNonConsumableKeys is superseeded by EventManager.setKeyFilter
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 """
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 import fife
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
43 # Utility functions
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
44
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
45 def deprecated(revision,message):
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
46 print "fife_compat: Deprecation warning - See revision %d " % revision
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
47 print " - ",message
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
48
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
49 def this_is_deprecated(func,revision=0,message=None):
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
50 if message is None:
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
51 message = repr(func) + " is deprecated."
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
52 def wrapped_func(*args,**kwargs):
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
53 deprecated(revision,message)
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
54 return func(*args,**kwargs)
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
55 return wrapped_func
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
56
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 # 2008.1 compatibility functions
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 def decorate_addFrame(f):
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
60
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 def addFrame(self,image_ptr, delay):
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
62 if not isinstance(image_ptr,fife.ResourcePtr):
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
63 image_ptr = fife.ResourcePtr(image_ptr)
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
64 deprecated(2616,"Animation.addFrame doesn't accept Image* anymore ")
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
65 return f(self,image_ptr,delay)
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66 return addFrame
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
68 fife.Animation.addFrame = decorate_addFrame(fife.Animation.addFrame)
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
69 fife.Pool.getIndex = this_is_deprecated(
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
70 fife.Pool.addResourceFromFile,
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
71 revision = 2617,
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
72 message = "Use addResourceFromFile instead of getIndex"
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
73 )
157
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
74
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
75 def _compat_NonConsumableKeys():
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
76 class CompatKeyFilter(fife.IKeyFilter):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
77 def __init__(self, keys):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
78 fife.IKeyFilter.__init__(self)
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
79 self.keys = keys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
80
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
81 def isFiltered(self, event):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
82 return event.getKey().getValue() in self.keys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
83
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
84 def _setNonConsumableKeys(self,keys):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
85 deprecated(2636, "Write an IKeyFilter instead of using EventManager.setNonConsumableKeys.\n" +
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
86 "You probably don't need it anyway")
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
87 self.compat_keyfilter = CompatKeyFilter(keys)
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
88 self.compat_keyfilter.__disown__()
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
89 self.setKeyFilter(self.compat_keyfilter)
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
90
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
91 def _getNonConsumableKeys(self,keys):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
92 deprecated(2636, "Write an IKeyFilter instead of using EventManager.getNonConsumableKeys.")
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
93 return self.compat_keyfilter.keys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
94
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
95 fife.EventManager.setNonConsumableKeys = _setNonConsumableKeys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
96 fife.EventManager.getNonConsumableKeys = _getNonConsumableKeys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
97
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
98 _compat_NonConsumableKeys()