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

Source Code for Module fife.extensions.pychan.compat

  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 60 guimanager = fife.GUIChanManager() 61 guimanager.thisown = 0 62 63 engine.setGuiManager(guimanager) 64 65 guimanager.setDefaultFont( 66 engine.getSettings().getDefaultFontPath(), 67 engine.getSettings().getDefaultFontSize(), 68 engine.getSettings().getDefaultFontGlyphs() 69 ) 70 71 guimanager.init( 72 engine.getRenderBackend().getName(), 73 engine.getRenderBackend().getScreenWidth(), 74 engine.getRenderBackend().getScreenHeight() 75 ) 76 77 engine.getEventManager().addSdlEventListener(guimanager) 78 79 def _fife_load_image(filename): 80 img = engine.getImageManager().load(filename) 81 return guichan.GuiImage(img)
82 # use below line instead of above ones to let guichan 83 # use its image loader that supports creating/using atlases 84 # return guichan.GuiImage().load(filename) 85 86 class hook: 87 pass 88 hook = hook() 89 90 hook.add_widget = guimanager.add 91 hook.remove_widget = guimanager.remove 92 hook.default_font = guimanager.getDefaultFont() 93 hook.load_image = _fife_load_image 94 hook.translate_mouse_event = guimanager.translateMouseEvent 95 hook.translate_key_event = guimanager.translateKeyEvent 96 hook.guimanager = guimanager 97 hook.console = guimanager.getConsole() 98 hook.create_font = guimanager.createFont 99 hook.release_font = guimanager.releaseFont 100 101 hook.screen_width = engine.getRenderBackend().getScreenWidth() 102 hook.screen_height = engine.getRenderBackend().getScreenHeight() 103 104 hook.engine = engine 105 return hook 106 107
108 -class _multilistener(guichan.ActionListener,guichan.MouseListener,guichan.KeyListener):
109 - def __init__(self):
113 114
115 -class _point(object):
116 - def __init__(self,x=0,y=0):
117 self.x=0 118 self.y=0
119 120 if in_fife: 121 fife = guichan 122 guichan.ActionListener._ActionListener_init__ = lambda x : x 123 #guichan.MouseListener.__init__ = lambda x : x 124 #guichan.KeyListener.__init__ = lambda x : x 125 else: 126 guichan.Point = _point 127 guichan.ScrollArea.SHOW_AUTO = guichan.ScrollArea.ShowAuto 128 guichan.ScrollArea.SHOW_NEVER = guichan.ScrollArea.ShowNever 129 guichan.ScrollArea.SHOW_ALWAYS = guichan.ScrollArea.ShowAlways 130 131 assert isinstance(_multilistener(),guichan.ActionListener) 132 assert isinstance(_multilistener(),guichan.MouseListener) 133 assert isinstance(_multilistener(),guichan.KeyListener) 134