annotate engine/extensions/fife_compat.py @ 357:2cdce58c1109

Fixes the scroll areas in the pychan demo. fixes[t:363]
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 25 Sep 2009 19:48:07 +0000
parents dfd48d49c044
children
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 # -*- coding: utf-8 -*-
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
2
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 # 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
5 # http://www.fifengine.de
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
6 # 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
7 #
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
8 # 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
9 # 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
10 # 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
11 # 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
12 #
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
13 # 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
14 # 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
15 # 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
16 # 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
17 #
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
18 # 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
19 # 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
20 # Free Software Foundation, Inc.,
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
21 # 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
22 # ####################################################################
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23
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 FIFE Backwards Combatibility Layer
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 ==================================
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 This module can be imported if you want to
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 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
30
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 2008.1
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 ------
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 - 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
35 - Pool.getIndex is just an alias for Pool.addResourceFromFile.
157
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
36 - EventManager.setNonConsumableKeys is superseeded by EventManager.setKeyFilter
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37
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 import fife
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
42 # Utility functions
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
43
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
44 def deprecated(revision,message):
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
45 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
46 print " - ",message
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
47
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
48 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
49 if message is None:
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
50 message = repr(func) + " is deprecated."
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
51 def wrapped_func(*args,**kwargs):
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
52 deprecated(revision,message)
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
53 return func(*args,**kwargs)
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
54 return wrapped_func
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
55
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 # 2008.1 compatibility functions
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 def decorate_addFrame(f):
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
59
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 def addFrame(self,image_ptr, delay):
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
61 if not isinstance(image_ptr,fife.ResourcePtr):
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
62 image_ptr = fife.ResourcePtr(image_ptr)
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
63 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
64 return f(self,image_ptr,delay)
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65 return addFrame
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
67 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
68 fife.Pool.getIndex = this_is_deprecated(
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
69 fife.Pool.addResourceFromFile,
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
70 revision = 2617,
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
71 message = "Use addResourceFromFile instead of getIndex"
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
72 )
157
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
73
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
74 def _compat_NonConsumableKeys():
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
75 class CompatKeyFilter(fife.IKeyFilter):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
76 def __init__(self, keys):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
77 fife.IKeyFilter.__init__(self)
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
78 self.keys = keys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
79
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
80 def isFiltered(self, event):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
81 return event.getKey().getValue() in self.keys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
82
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
83 def _setNonConsumableKeys(self,keys):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
84 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
85 "You probably don't need it anyway")
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
86 self.compat_keyfilter = CompatKeyFilter(keys)
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
87 self.compat_keyfilter.__disown__()
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
88 self.setKeyFilter(self.compat_keyfilter)
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
89
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
90 def _getNonConsumableKeys(self,keys):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
91 deprecated(2636, "Write an IKeyFilter instead of using EventManager.getNonConsumableKeys.")
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
92 return self.compat_keyfilter.keys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
93
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
94 fife.EventManager.setNonConsumableKeys = _setNonConsumableKeys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
95 fife.EventManager.getNonConsumableKeys = _getNonConsumableKeys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
96
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
97 _compat_NonConsumableKeys()