当前位置: 首页>>代码示例>>Python>>正文


Python Engine.push_handlers方法代码示例

本文整理汇总了Python中engine.Engine.push_handlers方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.push_handlers方法的具体用法?Python Engine.push_handlers怎么用?Python Engine.push_handlers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在engine.Engine的用法示例。


在下文中一共展示了Engine.push_handlers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MicroWindow

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import push_handlers [as 别名]
class MicroWindow(pyglet.window.Window, LayoutWindow):
    '''
    class MicroWindow
    
    The main window for micropylis.
    Handles tool dispatching and controls program animation/simulation speed.
    Controls the updating of the rest of the program.
    Implements LayoutWindow which allows a tree of widgets to be
    sized and positioned within this window.
    '''

    def __init__(self, skipToCity=None, soundEnabled=True):

        log.info("e")

        self.register_event_type('speed_changed')

        self.DEFAULT_WIDTH = gui.config.getInt('window', 'DEFAULT_WIDTH')
        self.DEFAULT_HEIGHT = gui.config.getInt('window', 'DEFAULT_HEIGHT')
        pyglet.window.Window.__init__(self, width=self.DEFAULT_WIDTH,
                                      height=self.DEFAULT_HEIGHT,
                                      resizable=True,
                                      vsync=False)

        # load in tile specs
        tiles.readTilesSpec(gui.config.get('misc', 'TILES_SPEC_FILE'))

        self.soundPlayer = sound.SoundPlayer("res/sound/")
        self.soundPlayer.setMute(soundEnabled)
        self.soundPlayer.soundEffectVolume = gui.config.getFloat('sound', 'DEFAULT_EFFECTS_VOL')
        self.soundPlayer.musicVolume = gui.config.getFloat('sound', 'DEFAULT_MUSIC_VOL')

        self.cityView = CityView()
        self.controlView = ControlView(self, self.cityView)
        self.push_handlers(self.cityView,
                           self.controlView,
                           self.cityView.keys)
        LayoutWindow.__init__(self, HorizontalLayout([
            self.cityView,
            self.controlView],
            padding=0))

        # tool vars:
        self.dragStart = (0, 0)
        self.currentTool = None
        self.toolStroke = None
        self.lastX = 0
        self.lastY = 0
        self.drag = False

        # window stuff
        self.icon = pyglet.resource.texture(gui.config.get('window', 'ICON_FILE')).get_image_data()  # icon is set at resize
        self.set_icon(self.icon)
        self.set_location(40, 40)
        self.set_minimum_size(640, 480)
        self.set_caption(gui.config.get('window', 'CAPTION'))
        self.fpsDisplay = pyglet.clock.ClockDisplay(color=(1., 1., 1., 1))

        # setup kytten and main dialog:
        dialogs.window = self
        self.register_event_type('on_update')  # called in our update method
        self.toolDialog = dialogs.ToolDialog()
        self.push_handlers(self.toolDialog)

        for (name, font) in gui.config.items('font_files'):
            pyglet.resource.add_font(font)

        pyglet.clock.schedule_interval(self.update, 1 / 60.)
        self.speedKeyMap = {
            pyglet.window.key._1: speeds['Paused'],
            pyglet.window.key._2: speeds['Slow'],
            pyglet.window.key._3: speeds['Normal'],
            pyglet.window.key._4: speeds['Fast'],
            pyglet.window.key._5: speeds['Super Fast']}
        self.speed = None


        self.engine = None
        if skipToCity is not None:
            if skipToCity.lower() == "new":
                self.newCity(gameLevel.MIN_LEVEL)
            else:
                self.loadCity('cities/' + skipToCity)
        else:
            self.soundPlayer.playEffect("STARTUP")
            MainMenuDialog.toggle()

    def makeSoundEffect(self, soundName):
        self.soundPlayer.playEffect(soundName)

    def on_city_sound(self, soundTup):
        x = soundTup[0]
        y = soundTup[1]
        soundName = soundTup[2]
        # if car honk sound, but not on screen: return

        self.soundPlayer.playEffect(soundName)

    def cityLoaded(self):
        return False if self.engine is None else True
#.........这里部分代码省略.........
开发者ID:chrisbiggar,项目名称:micropylis,代码行数:103,代码来源:microWindow.py


注:本文中的engine.Engine.push_handlers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。