예제 #1
0
def show_simple_view(view, toolkit='qt', description=''):
    """ Display a simple view to the screen in the local process.

    Parameters
    ----------
    view : Object
        The top level Object to use as the view.

    toolkit : string, optional
        The toolkit backend to use to display the view. Currently
        supported values are 'qt' and 'wx'. The default is 'qt'.
        Note that not all functionality is available on Wx.

    description : string, optional
        An optional description to give to the session.

    """
    f = lambda: view
    if toolkit == 'qt':
        from enaml.qt.qt_application import QtApplication
        app = QtApplication([simple_session('main', description, f)])
    elif toolkit == 'wx':
        from enaml.wx.wx_application import WxApplication
        app = WxApplication([simple_session('main', description, f)])
    else:
        raise ValueError('Unknown toolkit `%s`' % toolkit)
    app.start_session('main')
    app.start()
    return app
예제 #2
0
def main():
    import enaml
    from enaml.stdlib.sessions import simple_session
    from enaml.qt.qt_application import QtApplication
    with enaml.imports():
        from analyzarr.ui.main_view import Main
    from controllers.HighSeasAdventure import HighSeasAdventure
    
    controller = HighSeasAdventure()
    # For enaml 0.7
    #qtapp = QtApplication()
    #view=Main("Ahoy!")
    
    # for enaml 0.6
    qtapp = QtApplication([])
    main_ui = simple_session('main', 'The main UI window', Main, controller=controller)
    qtapp.add_factories([main_ui])
    qtapp.start_session('main')
    # version agnostic
    qtapp.start()
예제 #3
0
def main():
    import enaml
    from enaml.stdlib.sessions import simple_session
    from enaml.qt.qt_application import QtApplication
    with enaml.imports():
        from analyzarr.ui.main_view import Main
    from controllers.HighSeasAdventure import HighSeasAdventure

    controller = HighSeasAdventure()
    # For enaml 0.7
    #qtapp = QtApplication()
    #view=Main("Ahoy!")

    # for enaml 0.6
    qtapp = QtApplication([])
    main_ui = simple_session('main',
                             'The main UI window',
                             Main,
                             controller=controller)
    qtapp.add_factories([main_ui])
    qtapp.start_session('main')
    # version agnostic
    qtapp.start()
예제 #4
0
파일: images.py 프로젝트: 5n1p/enaml
        if p is not None:
            with open(p, 'rb') as f:
                data = f.read()
            image = Image(data=data)
        else:
            image = None
        callback(image)


class ImageSession(Session):
    """ A simple session object for the image example.

    """
    def on_open(self):
        """ Setup the windows and resources for the session.

        """
        self.resource_manager.image_providers['myimages'] = MyImageProvider()
        with enaml.imports():
            from images_view import ImagesView
        images = sorted(PATHS.keys())
        self.windows.append(ImagesView(images=images))


if __name__ == '__main__':
    from enaml.qt.qt_application import QtApplication
    app = QtApplication([ImageSession.factory('main')])
    app.start_session('main')
    app.start()

예제 #5
0
        p = PATHS.get(path.lstrip('/'))
        if p is not None:
            with open(p, 'rb') as f:
                data = f.read()
            image = Image(data=data)
        else:
            image = None
        callback(image)


class ImageSession(Session):
    """ A simple session object for the image example.

    """
    def on_open(self):
        """ Setup the windows and resources for the session.

        """
        self.resource_manager.image_providers['myimages'] = MyImageProvider()
        with enaml.imports():
            from images_view import ImagesView
        images = sorted(PATHS.keys())
        self.windows.append(ImagesView(images=images))


if __name__ == '__main__':
    from enaml.qt.qt_application import QtApplication
    app = QtApplication([ImageSession.factory('main')])
    app.start_session('main')
    app.start()
예제 #6
0
파일: person.py 프로젝트: 5n1p/enaml
    debug = Bool(False)

    @on_trait_change('age')
    def debug_print(self):
        """ Prints out a debug message whenever the person's age changes.

        """
        if self.debug:
            templ = "{first} {last} is {age} years old."
            s = templ.format(
                first=self.first_name, last=self.last_name, age=self.age,
            )
            print s


if __name__ == '__main__':
    with enaml.imports():
        from person_view import PersonView

    john = Person(first_name='John', last_name='Doe', age=42)
    john.debug = True

    session = simple_session(
        'john', 'A view of the Person john', PersonView, person=john
    )

    app = QtApplication([session])
    app.start_session('john')
    app.start()

예제 #7
0
    @on_trait_change('age')
    def debug_print(self):
        """ Prints out a debug message whenever the person's age changes.

        """
        if self.debug:
            templ = "{first} {last} is {age} years old."
            s = templ.format(
                first=self.first_name,
                last=self.last_name,
                age=self.age,
            )
            print s


if __name__ == '__main__':
    with enaml.imports():
        from person_view import PersonView

    john = Person(first_name='John', last_name='Doe', age=42)
    john.debug = True

    session = simple_session('john',
                             'A view of the Person john',
                             PersonView,
                             person=john)

    app = QtApplication([session])
    app.start_session('john')
    app.start()
예제 #8
0
#------------------------------------------------------------------------------
#  Copyright (c) 2011, Enthought, Inc.
#  All rights reserved.
#------------------------------------------------------------------------------
import enaml
from enaml.stdlib.sessions import simple_session


if __name__ == '__main__':
    with enaml.imports():
        from hello_world_view import Main

    sess_one = simple_session('hello-world', 'A hello world example', Main)
    sess_two = simple_session(
        'hello-world-python', 'A customized hello world example',
        Main, message="Hello, world, from Python!"
    )

    from enaml.qt.qt_application import QtApplication
    app = QtApplication([sess_one, sess_two])
    app.start_session('hello-world')
    app.start_session('hello-world-python')
    app.start()
예제 #9
0
파일: icons.py 프로젝트: vahndi/enaml
                    data = f.read()
                image = Image(data=data)
                icon_img = IconImage(image=image)
                icon = Icon(images=[icon_img])
            else:
                icon = None
        callback(icon)


class IconSession(Session):
    """ A simple session object for the icon example.

    """

    def on_open(self):
        """ Setup the windows and resources for the session.

        """
        self.resource_manager.icon_providers["myicons"] = MyIconProvider()
        with enaml.imports():
            from icons_view import IconsView
        self.windows.append(IconsView())


if __name__ == "__main__":
    from enaml.qt.qt_application import QtApplication

    app = QtApplication([IconSession.factory("main")])
    app.start_session("main")
    app.start()
예제 #10
0
    def age_at_date(self, date):
        """Return age rounded to the nearest 1/2 year.
        """
        age = int((date - self.DOB).days / 365.25 * 2) / 2.
        return age

    def _get_age(self):
        time_since_birth = date.today() - self.DOB
        return int(time_since_birth.days / 365.25 * 2.) / 2.

if __name__ == '__main__':
    import enaml
    from enaml.stdlib.sessions import show_simple_view, simple_session
    from enaml.qt.qt_application import QtApplication

    eld = Person(first_name="Eliza", last_name="Diller", DOB=date(2003,6,9))
    print "{} {} is {} years old.".format(eld.first_name, eld.last_name, eld.age)
    with enaml.imports():
        from bod_person_view import PersonView
    eld_view = PersonView(person=eld)
    session = simple_session(
        eld.first_name,
        'A view of the Person {} {}'.format(eld.first_name, eld.last_name),
        PersonView, person=eld
        )

    app = QtApplication([session])
    app.start_session(eld.first_name)
    app.start()
#    show_simple_view(eld_view)
예제 #11
0
#------------------------------------------------------------------------------
#  Copyright (c) 2011, Enthought, Inc.
#  All rights reserved.
#------------------------------------------------------------------------------
import enaml
from enaml.stdlib.sessions import simple_session

if __name__ == '__main__':
    with enaml.imports():
        from hello_world_view import Main

    sess_one = simple_session('hello-world', 'A hello world example', Main)
    sess_two = simple_session('hello-world-python',
                              'A customized hello world example',
                              Main,
                              message="Hello, world, from Python!")

    from enaml.qt.qt_application import QtApplication
    app = QtApplication([sess_one, sess_two])
    app.start_session('hello-world')
    app.start_session('hello-world-python')
    app.start()
예제 #12
0
        """
        age = int((date - self.DOB).days / 365.25 * 2) / 2.
        return age

    def _get_age(self):
        time_since_birth = date.today() - self.DOB
        return int(time_since_birth.days / 365.25 * 2.) / 2.


if __name__ == '__main__':
    import enaml
    from enaml.stdlib.sessions import show_simple_view, simple_session
    from enaml.qt.qt_application import QtApplication

    eld = Person(first_name="Eliza", last_name="Diller", DOB=date(2003, 6, 9))
    print "{} {} is {} years old.".format(eld.first_name, eld.last_name,
                                          eld.age)
    with enaml.imports():
        from bod_person_view import PersonView
    eld_view = PersonView(person=eld)
    session = simple_session(eld.first_name,
                             'A view of the Person {} {}'.format(
                                 eld.first_name, eld.last_name),
                             PersonView,
                             person=eld)

    app = QtApplication([session])
    app.start_session(eld.first_name)
    app.start()
#    show_simple_view(eld_view)
예제 #13
0
import enaml
from enaml.qt.qt_application import QtApplication
from enaml.stdlib.sessions import SimpleSession
from necofs_model import OceanModel

if __name__ == '__main__':
    model = OceanModel()

    with enaml.imports():
        from ocean_view import Main

    app = QtApplication(
        [SimpleSession.factory('default', 'Ocean Model',
                           lambda: Main(model=model))])
    app.start_session('default')
    app.start()
    app.destroy()