Example #1
0
File: runner.py Project: rwl/enaml
def main():
    import argparse
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description=__doc__,
    )
    parser.add_argument('-c', '--component', default='MainWindow',
        help="The component to view.")
    parser.add_argument('-t', '--toolkit', default='default',
        choices=['default', 'wx', 'qt', 'muntjac'],
        help='The toolkit backend to use')
    parser.add_argument('enaml_file', help='The .enaml file to show.')

    args = parser.parse_args()

    with open(args.enaml_file) as f:
        enaml_code = f.read()
    ast = parse(enaml_code)
    ns = {}

    with enaml.imports():
        EnamlCompiler.compile(ast, ns)

    with toolkits[args.toolkit]():
        if 'main' in ns:
            ns['main']()
        else:
            component = ns[args.component]
            window = component()
            window.show()
Example #2
0
    def parse_and_create(self, source, *args):
        """ Parses and compiles the source. The source should have defn 
        defined with the name 'MainView' that returns a single component. 

        Arguments
        ---------
        enaml_source : str
            The enaml source file

        *args :
            The arguments to pass to the defn.

        """
        enaml_ast = parse(source)
        enaml_module = {}
        EnamlCompiler.compile(enaml_ast, enaml_module)

        toolkit = self.toolkit

        with toolkit:
            defn = enaml_module['MainView']
            cmpnt, = defn(*args)

        self.app = toolkit.create_app()
        cmpnt.setup()
        return cmpnt
Example #3
0
def main():
    import argparse
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description=__doc__,
    )
    parser.add_argument('-c',
                        '--component',
                        default='MainWindow',
                        help="The component to view.")
    parser.add_argument('-t',
                        '--toolkit',
                        default='default',
                        choices=['default', 'wx', 'qt', 'muntjac'],
                        help='The toolkit backend to use')
    parser.add_argument('enaml_file', help='The .enaml file to show.')

    args = parser.parse_args()

    with open(args.enaml_file) as f:
        enaml_code = f.read()
    ast = parse(enaml_code)
    ns = {}

    with enaml.imports():
        EnamlCompiler.compile(ast, ns)

    with toolkits[args.toolkit]():
        if 'main' in ns:
            ns['main']()
        else:
            component = ns[args.component]
            window = component()
            window.show()
Example #4
0
    def parse_and_create(self, source, *args):
        """ Parses and compiles the source. The source should have defn 
        defined with the name 'MainView' that returns a single component. 

        Arguments
        ---------
        enaml_source : str
            The enaml source file

        *args :
            The arguments to pass to the defn.

        """
        enaml_ast = parse(source)
        enaml_module = {}
        EnamlCompiler.compile(enaml_ast, enaml_module)

        toolkit = self.toolkit

        with toolkit:
            defn = enaml_module['MainView']
            cmpnt = defn(*args)

        self.app = toolkit.create_app()
        cmpnt.setup()
        return cmpnt
Example #5
0
    def parse_and_create(self, source, **kwargs):
        """ Parses and compiles the source. The source should have a
        component defined with the name 'MainView'. 

        Arguments
        ---------
        source : str
            The enaml source file

        kwargs : dict
            The default attribute values to pass to the component.

        """
        enaml_ast = parse(source)
        enaml_module = {}
        EnamlCompiler.compile(enaml_ast, enaml_module)

        toolkit = self.toolkit

        with toolkit:
            view = enaml_module["MainView"]
            cmpnt = view(**kwargs)

        toolkit.app.initialize()
        self.app = toolkit.app.app_object()
        cmpnt.setup()
        return cmpnt
Example #6
0
def main():
    usage = 'usage: %prog [options] enaml_file'
    parser = optparse.OptionParser(usage=usage, description=__doc__)
    parser.add_option('-c', '--component', default='Main',
                      help='The component to view')
    parser.add_option('-t', '--toolkit', default='default',
                      choices=['default', 'wx', 'qt'],
                      help='The toolkit backend to use')
    
    options, args = parser.parse_args()

    if len(args) == 0:
        print 'No .enaml file specified'
        sys.exit()
    elif len(args) > 1:
        print 'Too many files specified'
        sys.exit()
    else:
        enaml_file = args[0]

    with open(enaml_file) as f:
        enaml_code = f.read()
    
    ast = parse(enaml_code, filename=enaml_file)

    ns = {}
    with enaml.imports():
        EnamlCompiler.compile(ast, ns)

    with toolkits[options.toolkit]():
        requested = options.component
        if requested in ns:
            component = ns[requested]
            window = component()
            window.show()
        elif 'main' in ns:
            ns['main']()
        else:
            msg = "Could not find component '%s'" % options.component
            print msg