def __init__(self, params, *args, **kwargs): Editor.editor = self self._filemanager = None self._open_files = [] self._params = params self._eventlistener = None self._pluginmanager = None self._inited = False self._mapview = None self._mapviewlist = [] self._mapgroup = None self._mapbar = None self._maparea = None self._mapeditor = None self._file_menu = None self._edit_menu = None self._view_menu = None self._tools_menu = None self._help_menu = None self._settings = None self._help_dialog = None ApplicationBase.__init__(self, *args, **kwargs) MainWindow.__init__(self, *args, **kwargs) pychan.init(self.engine, debug=False)
def __init__(self, engine, object_title, desc): """ Initialize the popup @type engine: fife.Engine @param engine: an instance of the fife engine @type object_title: string @param object_title: The title for the window, probably should just be the name of the object @type desc: string @param desc: The description of the object @return: None """ self.engine = engine pychan.init(self.engine, debug=True) self.examine_window = pychan.widgets.\ Window(title=unicode(object_title), position_technique="center:center", min_size=(175,175)) self.scroll = pychan.widgets.ScrollArea(name='scroll', size=(150,150)) self.description = pychan.widgets.Label(name='descText', text=unicode(desc), wrap_text=True) self.description.max_width = 170 self.scroll.addChild(self.description) self.examine_window.addChild(self.scroll) self.close_button = pychan.widgets.Button(name='closeButton', text=unicode('Close')) self.examine_window.addChild(self.close_button) self.examine_window.mapEvents({'closeButton':self.examine_window.hide})
def __init__(self, xmlfiles): self.engine = micron.Micron() self.engine.init(640, 640, 0) self.gui = guichan.Gui() self.gui.setGraphics(self.engine.getGraphics()) self.gui.setInput(self.engine.getInput()) self.font = micron.TTFont("content/fonts/vera.ttf", 12) guichan.Widget.setGlobalFont(self.font) self.top = guichan.Container() self.gui.setTop(self.top) self.top.setSize(640, 640) pychan.init(self.create_hook(), debug=True) for xmlfile in xmlfiles: self.widget = pychan.loadXML(xmlfile) self.widget.mapEvents({ 'okButton/mouseEntered': pychan.tools.attrSetCallback(base_color=(255, 0, 0)), 'okButton/mouseExited': pychan.tools.attrSetCallback(base_color=(255, 0, 255)), 'okButton': self.quit }) self.widget.show()
def __init__(self, engine, inventory, callbacks): """Initialise the instance. @type engine: fife.Engine @param engine: An instance of the fife engine @type inventory: Inventory @param inventory: An inventory object to be displayed and manipulated @type callbacks: dict @param callbacks: a dict of callbacks refreshReadyImages: Function that will make the ready slots on the HUD reflect those within the inventory toggleInventoryButton: Function that will toggle the state of the inventory button @return: None""" pychan.init(engine, debug = True) self.engine = engine self.readyCallback = callbacks['refreshReadyImages'] self.toggleInventoryButtonCallback = callbacks['toggleInventoryButton'] self.original_cursor_id = self.engine.getCursor().getId() self.inventory = pychan.loadXML("gui/inventory.xml") self.inventory_shown = False events_to_map = {} self.inventory_storage = inventory # Buttons of inventory arranged by slots self.slot_buttons = {'head': ('Head',), 'chest': ('Body',), 'left_arm': ('LeftHand',), 'right_arm': ('RightHand',), 'hips' : ('Belt',), 'left_leg': ('LeftFoot',), 'right_leg': ('RightFoot',), 'left_hand': ('LeftHeld',), 'right_hand': ('RightHeld',), 'backpack': ('A1', 'A2', 'A3', 'A4', 'A5', 'B1', 'B2', 'B3', 'B4', 'B5', 'C1', 'C2', 'C3', 'C4', 'C5', 'D1', 'D2', 'D3', 'D4', 'D5'), 'ready': ('Ready1', 'Ready2', 'Ready3', 'Ready4') } # the images that should be used for the buttons when they are "empty" self.slot_empty_images = {'head':'gui/inv_images/inv_head.png', 'chest':'gui/inv_images/inv_torso.png', 'left_arm':'gui/inv_images/inv_lhand.png', 'right_arm':'gui/inv_images/inv_rhand.png', 'hips':'gui/inv_images/inv_belt.png', 'left_leg':'gui/inv_images/inv_lfoot.png', 'right_leg':'gui/inv_images/inv_rfoot.png', 'left_hand':'gui/inv_images/inv_litem.png', 'right_hand':'gui/inv_images/inv_ritem.png', 'backpack':'gui/inv_images/inv_backpack.png', 'ready':'gui/inv_images/inv_belt_pouches.png', } self.updateInventoryButtons() for slot in self.slot_buttons: for index, button in enumerate(self.slot_buttons[slot]): events_to_map[button] = cbwa(self.dragDrop, button) events_to_map['close_button'] = self.closeInventoryAndToggle self.inventory.mapEvents(events_to_map)
def __init__(self, xmlfiles): self.engine = micron.Micron() self.engine.init(640, 640, 0) self.gui = guichan.Gui() self.gui.setGraphics(self.engine.getGraphics()) self.gui.setInput(self.engine.getInput()) self.font = micron.TTFont("content/fonts/vera.ttf", 12) guichan.Widget.setGlobalFont(self.font) self.top = guichan.Container() self.gui.setTop(self.top) self.top.setSize(640, 640) pychan.init(self.create_hook(), debug=True) for xmlfile in xmlfiles: self.widget = pychan.loadXML(xmlfile) self.widget.mapEvents( { "okButton/mouseEntered": pychan.tools.attrSetCallback(base_color=(255, 0, 0)), "okButton/mouseExited": pychan.tools.attrSetCallback(base_color=(255, 0, 255)), "okButton": self.quit, } ) self.widget.show()
def __init__(self): """Initialise the instance. @return: None""" super(PARPG,self).__init__() self.world = world.World(self.engine) self.model = engine.Engine(self.world) self.world.data = self.model self.listener = ApplicationListener(self.engine,self.world,self.model) self.world.quitFunction = self.listener.quitGame self.model.loadMap("main-map", str(TDS.readSetting("MapFile"))) pychan.init(self.engine, debug = True)
def __init__(self): # Let the ApplicationBase initialise FIFE super(DemoApplication,self).__init__() # Init Pychan pychan.init(self.engine,debug=False) pychan.loadFonts("fonts/freefont.fontdef") pychan.manager.setDefaultFont("FreeSans") pychan.setupModalExecution(self.mainLoop,self.breakFromMainLoop) # Build the main GUI self.gui = pychan.loadXML('gui/demoapp.xml') self.gui.min_size = self.engine.getRenderBackend().getScreenWidth(),self.engine.getRenderBackend().getScreenHeight() eventMap = { 'creditsLink' : self.showCredits, 'closeButton' : self.quit, 'demoList' : self.selectExample, } self.gui.mapEvents(eventMap) # A simple hover-effect for the credits label credits = self.gui.findChild(name="creditsLink") # setEnterCallback is deprecated - we use it here to test it. credits.setEnterCallback(TextSetter(u"CREDITS")) # Note that we can't simply write: # credits.capture(credits._setText(u"Credits"), event_name="mouseExited") # that's because that would call credits._setText _NOW_ and we want to call # it later. credits.capture(lambda : credits._setText(u"Credits"), event_name="mouseExited") # Our list of examples # We keep a dictionary of these and fill # the ListBox on the left with its names. from dynamic import DynamicExample from styling import StylingExample from sliders import SliderExample self.examples = { 'Absolute Positioning' : PyChanExample('gui/absolute.xml'), 'All Widgets' : PyChanExample('gui/all_widgets.xml'), 'Basic Styling' : StylingExample(), 'Dynamic Widgets' : DynamicExample(), 'Sliders' : SliderExample(), 'ScrollArea' : PyChanExample('gui/scrollarea.xml'), } self.demoList = self.gui.findChild(name='demoList') self.demoList.items = sorted(self.examples.keys()) # Finally show the main GUI self.gui.show() self.currentExample = None self.creditsWidget = None
def __init__(self): super(IslandDemo,self).__init__() pychan.init(self.engine, debug=TDS.readSetting("PychanDebug", type='bool')) self.world = world.World(self.engine) self.listener = ApplicationListener(self.engine, self.world) self.world.load(str(TDS.readSetting("MapFile"))) self.soundmanager = self.engine.getSoundManager() self.soundmanager.init() if int(TDS.readSetting("PlaySounds")): # play track as background music emitter = self.soundmanager.createEmitter() id = self.engine.getSoundClipPool().addResourceFromFile('music/rio_de_hola.ogg') emitter.setSoundClip(id) emitter.setLooping(True) emitter.play()
def __init__(self, engine, settings, inv_model, callbacks): """Initialise the instance. @type engine: fife.Engine @param engine: An instance of the fife engine @type settings: settings.Setting @param settings: The settings data @type inv_model: dict @type callbacks: dict @param callbacks: a dict of callbacks saveGame: called when the user clicks on Save loadGame: called when the user clicks on Load quitGame: called when the user clicks on Quit @return: None""" pychan.init(engine, debug = True) # TODO: perhaps this should not be hard-coded here self.hud = pychan.loadXML("gui/hud.xml") self.engine = engine self.settings = settings inv_callbacks = { 'refreshReadyImages': self.refreshReadyImages, 'toggleInventoryButton': self.toggleInventoryButton, } self.inventory = inventory.Inventory(self.engine, \ inv_model, inv_callbacks) self.refreshReadyImages() self.save_game_callback = callbacks['saveGame'] self.load_game_callback = callbacks['loadGame'] self.quit_callback = callbacks['quitGame'] self.box_container = None self.examine_box = None self.actions_box = self.hud.findChild(name="actionsBox") self.actions_text = [] self.menu_displayed = False self.initializeHud() self.initializeMainMenu() self.initializeContextMenu() self.initializeOptionsMenu() self.initializeHelpMenu() self.initializeEvents() self.initializeQuitDialog()
def __init__(self, engine, world, settings): """Initialise the instance. @type engine: fife.Engine @param engine: An instance of the fife engine @type settings: settings.Setting @param settings: The settings data @return: None""" pychan.init(engine, debug = True) # TODO: perhaps this should not be hard-coded here self.hud = pychan.loadXML("gui/hud.xml") self.engine = engine self.settings = settings self.world = weakref.proxy(world) self.actionsBox = self.hud.findChild(name="actionsBox") self.actionsText = [] self.menu_displayed = False self.initializeHud() self.initializeMainMenu() self.initializeContextMenu() self.initializeOptionsMenu() self.initializeHelpMenu() self.initializeEvents()
def __init__(self, engine, title, container): """ A class to create a window showing the contents of a container. @type engine: fife.Engine @param engine: an instance of the fife engine @type title: string @param title: The title of the window @type data: list or string @param data: A list of 9 items to use for the slots 1 - 9 OR one item to be used for all the slots @return: None """ self.engine = engine pychan.init(self.engine, debug=True) self.container_gui = pychan.loadXML("gui/container_base.xml") self.container_gui.findChild(name="topWindow").title = title data_drag.dragging = False self.original_cursor_id = self.engine.getCursor().getId() self.container = container self.resetMouseCursor()
def __init__(self, engine, items, readyCallback, toggleInventoryButtonCallback): """Initialise the instance. @type engine: fife.Engine @param engine: An instance of the fife engine @type items: dict @param items: A dictionary for every slot that goes '{slot:item, slot:item}' if a slot is not included in the dict, it is assumed to be empty @type readyCallback: function @param readyCallback: The function that will make the ready slots on the HUD reflect those within the inventory @type toggleInventoryButtonCallback: function @param toggleInventoryButtonCallback: Function that will toggle the state of the inventory button @return: None""" pychan.init(engine, debug = True) self.engine = engine self.readyCallback = readyCallback self.toggleInventoryButtonCallback = toggleInventoryButtonCallback self.original_cursor_id = self.engine.getCursor().getId() # TODO: remove hard-coded string? self.inventory = pychan.loadXML("gui/inventory.xml") self.inventoryShown = False self.events_to_map = {} # the images that should be used for the buttons when they are "empty" self.empty_images = {'A1':'gui/inv_images/inv_backpack.png', 'A2':'gui/inv_images/inv_backpack.png', 'A3':'gui/inv_images/inv_backpack.png', 'A4':'gui/inv_images/inv_backpack.png', 'A5':'gui/inv_images/inv_backpack.png', 'B1':'gui/inv_images/inv_backpack.png', 'B2':'gui/inv_images/inv_backpack.png', 'B3':'gui/inv_images/inv_backpack.png', 'B4':'gui/inv_images/inv_backpack.png', 'B5':'gui/inv_images/inv_backpack.png', 'C1':'gui/inv_images/inv_backpack.png', 'C2':'gui/inv_images/inv_backpack.png', 'C3':'gui/inv_images/inv_backpack.png', 'C4':'gui/inv_images/inv_backpack.png', 'C5':'gui/inv_images/inv_backpack.png', 'D1':'gui/inv_images/inv_backpack.png', 'D2':'gui/inv_images/inv_backpack.png', 'D3':'gui/inv_images/inv_backpack.png', 'D4':'gui/inv_images/inv_backpack.png', 'D5':'gui/inv_images/inv_backpack.png', 'Head':'gui/inv_images/inv_head.png', 'LeftHeld':'gui/inv_images/inv_litem.png', 'RightHeld':'gui/inv_images/inv_ritem.png', 'LeftHand':'gui/inv_images/inv_lhand.png', 'RightHand':'gui/inv_images/inv_rhand.png', 'Body':'gui/inv_images/inv_torso.png', 'Belt':'gui/inv_images/inv_belt.png', 'Ready1':'gui/inv_images/inv_belt_pouches.png', 'Ready2':'gui/inv_images/inv_belt_pouches.png', 'Ready3':'gui/inv_images/inv_belt_pouches.png', 'Ready4':'gui/inv_images/inv_belt_pouches.png', 'LeftFoot':'gui/inv_images/inv_lfoot.png', 'RightFoot':'gui/inv_images/inv_rfoot.png'} # every button on the inventory and its category self.buttons = {'A1':'main_inv', 'A2':'main_inv', 'A3':'main_inv', 'A4':'main_inv', 'A5':'main_inv', 'B1':'main_inv', 'B2':'main_inv', 'B3':'main_inv', 'B4':'main_inv', 'B5':'main_inv', 'C1':'main_inv', 'C2':'main_inv', 'C3':'main_inv', 'C4':'main_inv', 'C5':'main_inv', 'D1':'main_inv', 'D2':'main_inv', 'D3':'main_inv', 'D4':'main_inv', 'D5':'main_inv', 'LeftFoot':'foot', 'RightFoot':'foot', 'LeftHand':'hand', 'RightHand':'hand', 'Head':'head', 'Ready1':'ready', 'Ready2':'ready', 'Ready3':'ready', 'Ready4':'ready', 'Belt':'belt', 'LeftHeld':'held', 'RightHeld':'held', 'Body':'body'} # all possible categories self.locations = ['ready', 'head', 'foot', 'hand', 'belt', 'held', 'body'] for key in items: widget = self.inventory.findChild(name=key) item = items[key] image = item_image_dict[item] widget.item = item widget.up_image = image widget.down_image = image widget.hover_image = image for button in self.buttons: # make every button's callback be self.dragDrop self.events_to_map[button] = cbwa(self.dragDrop, button) ch = self.inventory.findChild(name = button) # make every slot's item be none if it has not already been set if button not in items: ch.item = "" self.events_to_map['close_button'] = self.closeInventoryAndToggle self.inventory.mapEvents(self.events_to_map) self.resetMouseCursor()
def __init__(self,xmlfile): super(TestXMLApplication,self).__init__() pychan.init(self.engine,debug=True) self.start()
def __init__(self, engine, title, data): """ A class to create a window showing the contents of a container. @type engine: fife.Engine @param engine: an instance of the fife engine @type title: string @param title: The title of the window @type data: list or string @param data: A list of 9 items to use for the slots 1 - 9 OR one item to be used for all the slots @return: None """ self.engine = engine pychan.init(self.engine, debug=True) self.container_gui = pychan.loadXML("gui/container_base.xml") self.container_gui.findChild(name="topWindow").title = title data_drag.dragging = False self.original_cursor_id = self.engine.getCursor().getId() # Prepare slots 1 through 9 dataIsList = False emptyImage = "gui/inv_images/inv_backpack.png" slotCount = 9 self.empty_images = dict() # Did this step because I'm unsure which is more costly , to check the # type of object or the value of boolean object. Change as you see fit. if type(data) == list: dataIsList = True for counter in range(1, slotCount): slotName = "Slot%i" % counter selectedData = None if dataIsList: selectedData = data[counter-1] else: selectedData = data self.setContainerImage(slotName, item_image_dict[selectedData]) self.container_gui.findChild(name=slotName).item = selectedData self.empty_images[slotName] = emptyImage self.events_to_map = {} self.buttons = {} for key in self.empty_images: self.buttons[key] = "main_inv" for button in self.buttons: # make every button's callback be self.dragDrop self.events_to_map[button] = cbwa(self.dragDrop, button) self.locations = ["main_inv"] self.container_gui.mapEvents(self.events_to_map) self.resetMouseCursor()