Mercurial > fife-parpg
comparison engine/python/fife/extensions/pychan/compat.py @ 378:64738befdf3b
bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 11 Jan 2010 23:34:52 +0000 |
parents | |
children | ecaa4d98f05f |
comparison
equal
deleted
inserted
replaced
377:fe6fb0e0ed23 | 378:64738befdf3b |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 # #################################################################### | |
4 # Copyright (C) 2005-2009 by the FIFE team | |
5 # http://www.fifengine.de | |
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 in_fife = None | |
25 guichan = None | |
26 | |
27 def _import_guichan(): | |
28 global in_fife | |
29 | |
30 err_fife = "" | |
31 try: | |
32 from fife import fife | |
33 in_fife = True | |
34 return fife | |
35 except ImportError, e: | |
36 err_fife = str(e) | |
37 | |
38 try: | |
39 import guichan | |
40 in_fife = False | |
41 return guichan | |
42 except ImportError, e: | |
43 import traceback | |
44 traceback.print_exc() | |
45 raise ImportError("Couldn't import neither fife nor guichan: fife:'%s' guichan:'%s'" % (err_fife,str(e))) | |
46 guichan = _import_guichan() | |
47 | |
48 | |
49 | |
50 def _munge_engine_hook(engine): | |
51 engine.translate_mouse_event = getattr(engine,'translate_mouse_event',lambda x : x ) | |
52 engine.translate_key_event = getattr(engine,'translate_key_event',lambda x : x ) | |
53 | |
54 if not in_fife: | |
55 return engine | |
56 if not isinstance(engine,fife.Engine): | |
57 return engine | |
58 | |
59 guimanager = engine.getGuiManager() | |
60 | |
61 def _fife_load_image(filename): | |
62 index = engine.getImagePool().addResourceFromFile(filename) | |
63 return guichan.GuiImage(index,engine.getImagePool()) | |
64 | |
65 class hook: | |
66 pass | |
67 hook = hook() | |
68 | |
69 hook.add_widget = guimanager.add | |
70 hook.remove_widget = guimanager.remove | |
71 hook.default_font = engine.getDefaultFont() | |
72 hook.load_image = _fife_load_image | |
73 hook.translate_mouse_event = guimanager.translateMouseEvent | |
74 hook.translate_key_event = guimanager.translateKeyEvent | |
75 | |
76 hook.screen_width = engine.getRenderBackend().getScreenWidth() | |
77 hook.screen_height = engine.getRenderBackend().getScreenHeight() | |
78 | |
79 hook.engine = engine | |
80 return hook | |
81 | |
82 | |
83 class _multilistener(guichan.ActionListener,guichan.MouseListener,guichan.KeyListener): | |
84 def __init__(self): | |
85 guichan.ActionListener.__init__(self) | |
86 guichan.MouseListener.__init__(self) | |
87 guichan.KeyListener.__init__(self) | |
88 | |
89 | |
90 class _point(object): | |
91 def __init__(self,x=0,y=0): | |
92 self.x=0 | |
93 self.y=0 | |
94 | |
95 if in_fife: | |
96 fife = guichan | |
97 guichan.ActionListener._ActionListener_init__ = lambda x : x | |
98 #guichan.MouseListener.__init__ = lambda x : x | |
99 #guichan.KeyListener.__init__ = lambda x : x | |
100 else: | |
101 guichan.Point = _point | |
102 guichan.ScrollArea.SHOW_AUTO = guichan.ScrollArea.ShowAuto | |
103 guichan.ScrollArea.SHOW_NEVER = guichan.ScrollArea.ShowNever | |
104 guichan.ScrollArea.SHOW_ALWAYS = guichan.ScrollArea.ShowAlways | |
105 | |
106 assert isinstance(_multilistener(),guichan.ActionListener) | |
107 assert isinstance(_multilistener(),guichan.MouseListener) | |
108 assert isinstance(_multilistener(),guichan.KeyListener) |