Exemple #1
0
	def __init__(self, application, testmanager):
		"""
		Initializes all listeners and registers itself with the eventmanager.
		"""
		self._application = application
			
		self._engine = self._application.engine
		self._eventmanager = self._engine.getEventManager()
		
		self._testmanager = testmanager

		fife.IKeyListener.__init__(self)
		self._eventmanager.addKeyListener(self)

		fife.ICommandListener.__init__(self)
		self._eventmanager.addCommandListener(self)

		self._console = get_manager().getConsole()
		
		fife.ConsoleExecuter.__init__(self)
		self._console.setConsoleExecuter(self)

		keyfilter = KeyFilter([fife.Key.ESCAPE, fife.Key.F10, fife.Key.PRINT_SCREEN])
		keyfilter.__disown__()		

		self._eventmanager.setKeyFilter(keyfilter)

		self.quit = False
		
		# Init Pychan
		pychan.loadFonts("data/fonts/freefont.fontdef")
		pychan.loadFonts("data/fonts/samanata.fontdef")
		pychan.manager.setDefaultFont("FreeSans")
		pychan.setupModalExecution(self._application.mainLoop, self._application.breakFromMainLoop)
Exemple #2
0
def standalone_error_popup(headline, msg):
	"""Display an error via gui.
	Use only for errors that make 'import horizons.main' fail."""
	from fife.extensions import pychan
	from fife import fife

	e = fife.Engine()
	e.getSettings().setDefaultFontPath("content/fonts/LinLibertine.ttf")
	e.init()

	pychan.init(e)
	pychan.loadFonts("content/fonts/libertine.fontdef")

	# hack for accessing this in do_quit (global does't work as the variables here are local)
	class Quit(object):
		do = False

	def do_quit():
		Quit.do=True

	dlg = pychan.loadXML("content/gui/xml/startup_error_popup.xml")
	# can't translate as translations are only set up later
	dlg.findChild(name="headline").text = headline
	dlg.findChild(name="msg").text = msg
	dlg.mapEvents({'quit_button': do_quit})
	dlg.show()


	e.initializePumping()
	while not Quit.do:
		e.pump()
	e.finalizePumping()
Exemple #3
0
 def __init__(self, settings_file='settings-dist.xml'):
     setting = Setting(settings_file=settings_file)
     super(GuichanDesignerApplication, self).__init__(setting=setting)
     # PyChanDesigner fonts
     pychan.loadFonts('fonts/freefont.fontdef')
     pychan.setupModalExecution(self.mainLoop, self.breakFromMainLoop)
     # pychan default settings need an overwrite, because we don't like some aspects (like opaque widgets)
     screen_width, screen_height = \
         [int(dimension) for dimension in
          setting.get('FIFE', 'ScreenResolution').split('x')]
     self.xml_script_path = ''
     self.active_widget = None
     self.selected_widget = None
     self.widget_stack = []
     self.logger = logging.getLogger('PychanDesignerApplication')
     self.xml_editor = pychan.loadXML('gui/xml_editor.xml')
     self.console = pychan.loadXML('gui/console.xml')
     with file('gui/pychan_designer.xml') as xml_file:
         self.gui = pychan.loadXML(xml_file)
     self.gui.min_size = (screen_width, screen_height)
     self.gui.max_size = (screen_width, screen_height)
     editor = self.gui.findChild(name='editor')
     editor.content = self.xml_editor
     self.gui.mapEvents(
         {
             'exitButton': self.quit,
             'reloadButton': self.reloadXml,
             'applyButton': self.applyXml,
             'saveButton': self.saveXml,
             'xmlEditorTab': self.showXmlEditor,
             'consoleTab': self.showConsole,
         }
     )
     self.gui.adaptLayout()
     self.gui.show()
	def __init__(self):
		# Let the ApplicationBase initialise FIFE
		super(DemoApplication,self).__init__()

		# Init Pychan
		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")


		# import example modules
		from dynamic import DynamicExample
		from styling import StylingExample
		from sliders import SliderExample
		from colortester import ColorExample
		from poc_gui_animation import PocAnimations

		# Our list of examples
		# We keep a dictionary of these and fill
		# the ListBox on the left with its names.
		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'),
			'Colortester': ColorExample(),
			'GuiAnimations' : PocAnimations(),
		}
		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(StylingExample,self).__init__('gui/styling.xml')

		self.styles = ['default'] + STYLES.keys()
		for name,style in STYLES.items():
			pychan.manager.addStyle(name,style)

		pychan.loadFonts("fonts/samanata.fontdef")
    def __init__(self):
        super(StylingExample, self).__init__('gui/styling.xml')

        self.styles = ['default'] + STYLES.keys()
        for name, style in STYLES.items():
            pychan.manager.addStyle(name, style)

        pychan.loadFonts("fonts/samanata.fontdef")
Exemple #7
0
	def create(self, engine, application):
		self._application = application
		self._engine = engine
		self._running = False
		
		# Init Pychan
		pychan.loadFonts("data/fonts/freefont.fontdef")
		pychan.loadFonts("data/fonts/samanata.fontdef")
		pychan.manager.setDefaultFont("FreeSans")
		pychan.setupModalExecution(self._application.mainLoop, self._application.breakFromMainLoop)

		# Build the main GUI
		self.gui = pychan.loadXML('data/gui/demoapp.xml')
		self.gui.min_size = self._engine.getRenderBackend().getScreenWidth(),self._engine.getRenderBackend().getScreenHeight()

		eventMap = {
			'creditsLink'  : self.showCredits,
			'closeButton'  : self._application.testmanager.stopTest,
			'demoList'     : self.selectExample,
		}
		self.gui.mapEvents(eventMap)
		
		# A simple hover-effect for the credits label
		credits = self.gui.findChild(name="creditsLink")
		# Note that we can't simply write:
		# credits.capture(credits._setText(u"CREDITS"), event_name="mouseEntered")
		# 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="mouseEntered")
		# 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")
		
		self._examples = {
			'Absolute Positioning' : PyChanExample('data/gui/absolute.xml'),
			'All Widgets' : PyChanExample('data/gui/all_widgets.xml'),
			'Basic Styling' : StylingExample(),
			'Dynamic Widgets' : DynamicExample(),
			'Sliders' : SliderExample(),
			'ScrollArea' : PyChanExample('data/gui/scrollarea.xml'),
			'Colortester': ColorExample(),
			'GuiAnimations' : PocAnimations(),
			'Show Hide Test' : ShowHideTest(),
		}
		self.demoList = self.gui.findChild(name='demoList')
		self.demoList.items = sorted(self._examples.keys())
		
		self.currentExample = None
Exemple #8
0
def main(argv=sys.argv):
    option_parser = OptionParser(
        usage=USAGE_MESSAGE,
        args=argv[1:]
    )
    logging_level = logging.WARNING
    for option in option_parser:
        if option == '-h' or option =='--help':
            print(option_parser.usage)
            sys.exit(0)
        elif option == '-v':
            logging_level -= 10
        elif option == '-q':
            logging_level += 10
        else:
            print('Error: unknown option {0!r}\n'.format(option),
                  file=sys.stderr)
            print(option_parser.usage, file=sys.stderr)
            sys.exit(1)
    try:
        xml_script_path = os.path.abspath(option_parser.get_next_prog_arg())
    except OptionError as exception:
        print('Error: {0}\n'.format(exception), file=sys.stderr)
        print(option_parser.usage, file=sys.stderr)
        sys.exit(1)
    application = GuichanDesignerApplication()
    application.setupLogging(logging_level)
    parpg_root = os.path.abspath(os.path.join('..', '..', 'game'))
    os.chdir(parpg_root)
    # Load PARPG fonts
    fonts_directory = os.path.abspath('fonts')
    file_names = os.listdir(fonts_directory)
    for file_name in file_names:
        base_name, extension = os.path.splitext(file_name)
        if extension == '.fontdef':
            file_path = os.path.join(fonts_directory, file_name)
            pychan.loadFonts(file_path)
    application.xml_script_path = xml_script_path
    with file(xml_script_path) as xml_file:
        application.loadXml(xml_file)
    application.run()
Exemple #9
0
    def __init__(self, application, testmanager):
        """
		Initializes all listeners and registers itself with the eventmanager.
		"""
        self._application = application

        self._engine = self._application.engine
        self._eventmanager = self._engine.getEventManager()

        self._testmanager = testmanager

        fife.IKeyListener.__init__(self)
        self._eventmanager.addKeyListener(self)

        fife.ICommandListener.__init__(self)
        self._eventmanager.addCommandListener(self)

        self._console = get_manager().getConsole()

        fife.ConsoleExecuter.__init__(self)
        self._console.setConsoleExecuter(self)

        keyfilter = KeyFilter(
            [fife.Key.ESCAPE, fife.Key.F10, fife.Key.PRINT_SCREEN])
        keyfilter.__disown__()

        self._eventmanager.setKeyFilter(keyfilter)

        self.quit = False

        # Init Pychan
        pychan.loadFonts("data/fonts/freefont.xml")
        pychan.loadFonts("data/fonts/samanata.xml")
        pychan.manager.setDefaultFont("FreeSans")
        pychan.setupModalExecution(self._application.mainLoop,
                                   self._application.breakFromMainLoop)
	def __init__(self):
		# Let the ApplicationBase initialise FIFE
		super(DemoApplication,self).__init__()

		# Init Pychan
		pychan.loadFonts("fonts/freefont.xml")
		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,
			'xmlButton' : self.loadRuntimeXML,
		}
		self.gui.mapEvents(eventMap)

		# A simple hover-effect for the credits label
		credits = self.gui.findChild(name="creditsLink")
		# 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="mouseEntered")
		credits.capture(lambda : credits._setText(u"Credits"), event_name="mouseExited")

		# import example modules
		from dynamic import DynamicExample
		from styling import StylingExample
		from sliders import SliderExample
		from colortester import ColorExample
		from poc_gui_animation import PocAnimations
		from stretching import StretchingExample
		from tabbedarea import TabbedAreaExample
		from dynamicgraph import DynamicGraphExample
		from iconprogressbar import IconProgressBarExample
		from imageprogressbar import ImageProgressBarExample
		from modalfocus import ModalFocusExample
		from showhide import ShowHideExample

		# Our list of examples
		# We keep a dictionary of these and fill
		# the ListBox on the left with its names.
		self.examples = {
			'Absolute Positioning' : PyChanExample('gui/absolute.xml', self),
			'Adjusting Container' : PyChanExample('gui/adjustingcontainer.xml'),
			'All Widgets' : PyChanExample('gui/all_widgets.xml'),
			'Basic Styling' : StylingExample(),
			'Circular Box' : PyChanExample('gui/circularcontainer.xml'),
			'Dynamic Widgets' : DynamicExample(),
			'Sliders' : SliderExample(),
			'ScrollArea' : PyChanExample('gui/scrollarea.xml'),
			'Colortester': ColorExample(),
			'GuiAnimations' : PocAnimations(),
			'Tabbed Area' : TabbedAreaExample(),
			'Image Stretching' : StretchingExample(),
			'Resizable Window' : PyChanExample('gui/resizable.xml'),
			'Dock Area' : PyChanExample('gui/dockarea.xml'),
			'Graph Widgets' : PyChanExample('gui/graphwidgets.xml'),
			'Dynamic Graph' : DynamicGraphExample(),
			'Icon Progress Bar' : IconProgressBarExample(),
			'Image Progress Bar' : ImageProgressBarExample(),
			'Flow Container' : PyChanExample('gui/flowcontainer.xml'),
			'Animation Icon' : PyChanExample('gui/animationicon.xml'),
			'Modal Focus' : ModalFocusExample(),
			'Show and Hide' : ShowHideExample(),
		}
		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
Exemple #11
0
    def __init__(self):
        # Let the ApplicationBase initialise FIFE
        super(DemoApplication, self).__init__()

        # Init Pychan
        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")
        # 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: TextSetter(u"CREDITS"),
                        event_name="mouseEntered")
        credits.capture(lambda: credits._setText(u"Credits"),
                        event_name="mouseExited")

        # import example modules
        from dynamic import DynamicExample
        from styling import StylingExample
        from sliders import SliderExample
        from colortester import ColorExample
        from poc_gui_animation import PocAnimations
        from stretching import StretchingExample

        # Our list of examples
        # We keep a dictionary of these and fill
        # the ListBox on the left with its names.
        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'),
            'Colortester': ColorExample(),
            'GuiAnimations': PocAnimations(),
            'Image Stretching': StretchingExample(),
        }
        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