Exemple #1
0
async def test_examples(native_app, path):
    example = path[:-6].replace("/", ".")  # Remove example/ and .enaml

    if "thermostat" in example:
        return pytest.skip("thermostat example needs updated")

    app = AndroidApplication(debug=True)
    with enaml.imports():
        try:
            ContentView = locate(f"{example}.ContentView")
        except ErrorDuringImport as e:
            msg = f"{e}"
            if iconify is None and "iconify" in msg:
                return pytest.skip("enaml-native-icons is not installed")
            if googlemaps is None and "googlemaps" in msg:
                return pytest.skip("enaml-native-maps is not installed")
            if charts is None and "charts" in msg:
                return pytest.skip("enaml-native-charts is not installed")
            raise

    app.activity = ExampleActivity(example=ContentView())
    f = nativehooks.shown = app.create_future()

    def on_error(event):
        f.set_exception(event["value"])

    app.observe("error_occurred", on_error)

    # f.add_done_callback(lambda f: app.stop())
    # Add fail timeout
    app.timed_call(5 * 1000, lambda: f.set_result(False))
    app.deferred_call(app.activity.start)
    assert await f
Exemple #2
0
def test_playground_app(enamlnative_app):
    app = AndroidApplication(debug=True)

    with open("examples/playground/view.enaml") as f:
        ContentView = load(f.read())

    app.activity = ExampleActivity(example=ContentView())
    app.run()
Exemple #3
0
    def _observe_bible(self, change):
        if self.bible is None:
            if 'bible' in self.state:
                del self.state['bible']
        else:
            self.state['bible'] = self.bible.version.key

        #: When a bible is set, force an update
        AndroidApplication.instance().force_update()
Exemple #4
0
def main():
    """ Called by PyBridge.start()
    """

    #: If we don't our code goes away
    os.environ['TMP'] = os.path.join(sys.path[0], '../tmp')

    from enamlnative.android.app import AndroidApplication
    app = AndroidApplication(
        debug=True,
        dev='remote',  # "10.0.2.2" # or 'server'
        load_view=load_view)
    app.start()
Exemple #5
0
def main():
    """ Called by PyBridge.start()
    """
    print(sys.path)
    import enamlnative
    with enamlnative.imports():
        from enamlnative.android.app import AndroidApplication
        app = AndroidApplication('com.codelv.enamlnative.EnamlActivity')
    #app.debug = True #: Makes a lot of lag!
    app.dev = '192.168.34.103'
    app.reload_view = reload_view
    app.deferred_call(load_view, app)
    app.deferred_call(dump_stats)
    app.start()
Exemple #6
0
def main():
    """ Called by PyBridge.start()
    """
    #init_logging()
    #: If we don't our code goes away
    #os.environ['TMP'] = os.path.join(sys.path[0], '../tmp')
    #from charts.android.factories import install
    #install()

    from enamlnative.android.app import AndroidApplication
    app = AndroidApplication(
        #dev='remote',
        load_view=load_view
    )
    app.start()
Exemple #7
0
def main():
    """ Called by PyBridge.start()
    """
    #: If we don't our code goes away
    os.environ['TMP'] = os.path.join(sys.path[0], '../tmp')

    import enamlnative
    from enamlnative.android.app import AndroidApplication
    app = AndroidApplication()
    #app.debug = True #: Makes a lot of lag!
    app.dev = 'server' # "10.0.2.2" # or 'server'
    app.reload_view = reload_view
    app.deferred_call(load_view, app)
    app.deferred_call(dump_stats)
    app.start()
Exemple #8
0
    def reset(self, platform, eventloop='builtin'):
        if eventloop == 'builtin':
            from enamlnative.core.loop import BuiltinEventLoop
            self.loop = BuiltinEventLoop()
        elif eventloop == 'twisted':
            from enamlnative.core.loop import TwistedEventLoop
            self.loop = TwistedEventLoop()
        elif eventloop == 'tornado':
            from enamlnative.core.loop import TornadoEventLoop
            self.loop = TornadoEventLoop()

        #: Clear it again
        from enaml.application import Application
        Application._instance = None

        #: Update resolver
        if platform == 'ios':
            from enamlnative.ios.app import IPhoneApplication

            app = IPhoneApplication()
            from enamlnative.ios.factories import IOS_FACTORIES
            self.resolver.factories = IOS_FACTORIES
        else:
            from enamlnative.android.app import AndroidApplication
            app = AndroidApplication()
            from enamlnative.android.factories import ANDROID_FACTORIES
            self.resolver.factories = ANDROID_FACTORIES

        #: Clear state
        self.error = None
        self.done = self._default_done()
        self.bridge.reset(platform)
        return app
Exemple #9
0
def main():
    #: TODO: Plugins should support this...
    from zxing.android.factories import install
    install()

    #: Called to start your app
    from enamlnative.android.app import AndroidApplication
    app = AndroidApplication()
    app.debug = True  #: Makes a lot of lag!
    app.dev = 'server'  # "10.0.2.2" # or 'server'
    app.reload_view = reload_view
    app.deferred_call(load_view, app)
    app.start()
Exemple #10
0
def main():
    """ Called by PyBridge.start()
    """

    #: If we set the TMP env variable the dev reloader will save file
    #: and load changes in this directory instead of overwriting the
    #: ones installed with the app.
    os.environ['TMP'] = os.path.join(sys.path[0], '../tmp')

    from enamlnative.android.app import AndroidApplication

    app = AndroidApplication(
        debug=True,  #: Makes a lot of lag!
        dev='server',
        load_view=load_view,
    )
    app.start()
Exemple #11
0
def main():
    from charts.android.factories import install
    install()
    #: Called to start your app
    from enamlnative.android.app import AndroidApplication
    app = AndroidApplication()
    #app.debug = True #: Uncomment to debug the bridge
    app.dev = '192.168.41.139'  #: Uncomment to enable reloading
    app.reload_view = reload_view
    app.deferred_call(load_view, app)
    app.start()
Exemple #12
0
    def _handle_response(self, response):
        self.status = u"Converting..."
        AndroidApplication.instance().force_update()
        try:
            #: Load buffer into json
            self._buffer.seek(3)  # First 3 bytes are crap
            data = json.load(self._buffer)

            #: Create downloads folder
            downloads = os.path.dirname(self.path)
            if not os.path.exists(downloads):
                os.makedirs(downloads)

            #: Save in msgpack format
            with open(self.path, 'wb') as f:
                msgpack.dump(data, f)

            self.downloaded = True
            self.status = u"Done!"
        except Exception as e:
            self.status = u"{}".format(e)
        finally:
            self.downloading = False
def main():
    # Make sure instance is cleared
    from enaml.application import Application
    Application._instance = None

    from enamlnative.android.app import AndroidApplication
    app = AndroidApplication(
        debug=True,
        dev='remote',  # "10.0.2.2" # or 'server'
        load_view=load_view)
    app.timed_call(5000, run_gestures, app)
    app.start()
Exemple #14
0
 def _queue_save(self, change):
     """ Schedule a save """
     self._pending_saves += 1
     AndroidApplication.instance().timed_call(self._save_delay,
                                              self._dequeue_save)
Exemple #15
0
 def _observe_wake_lock(self, change):
     AndroidApplication.instance().keep_screen_on = self.wake_lock
     self.state['wake_lock'] = self.wake_lock