コード例 #1
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain models
    fred = Person(name='Fred', age=14)
    wilma = Person(name='Wilma', age=25)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template,
                        context={
                            'person': fred,
                            'spouse': wilma
                        })
    widget.show()

    # Start the event loop.
    #
    # Clicking on the buttons in the UI will make blocking calls to the
    # corresponding methods on the domain model. You can supply primitive as
    # well as instance objects as arguments of the method.
    app.exec_()

    # Check the final values after the UI is closed
    print(fred.name, fred.age, fred.spouse.name)
コード例 #2
0
ファイル: ex22_vuejs_demo.py プロジェクト: will133/jigna
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model

    fred = Person(name='Fred', age=42, fruits=['pear', 'apple'])

    template = VueTemplate(html_file='ex22_vuejs_demo.html')

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template,
                        context={'person': fred},
                        debug=True)
    widget.show()

    # Schedule an update to a model variable after 2.5 seconds. This update
    # will be reflected in the UI immediately.
    do_after(2500, fred.update_name, "Guido")
    do_after(2500, fred.add_fruit)
    do_after(2500, fred.add_friend)

    # Start the event loop
    app.exec_()

    # Check the values after the UI is closed
    print(fred.name, fred.age, fred.fruits, fred.friends)
コード例 #3
0
ファイル: test_html_widget.py プロジェクト: dusual/jigna
    def test_created_widget_can_access_jigna(self):
        # Create a widget
        widget = HTMLWidget(template=self.template, context={"model": self.model})

        # Check if `jigna` was loaded on the JS side
        jigna = widget.execute_js("jigna")
        self.assertIsNotNone(jigna)
コード例 #4
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    fred = Person(name='Fred')
    wilma = Person(name='Wilma')

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'person': fred})
    widget.show()

    # Schedule some operations on the domain model.
    #
    # The operation should fill in the `spouse` field of the person and this
    # should be reflected in the UI.
    do_after(2500, fred.marry, wilma)

    # Start the event loop.
    #
    # Initially, the `spouse` field of the person is empty, so the fields
    # related to the spouse should be empty in the UI.
    app.exec_()

    # Check the final values of the instance
    print(fred.name, fred.spouse.name, wilma.name)
コード例 #5
0
def main():
    # Start the Qt application
    app = QtGui.QApplication.instance() or QtGui.QApplication([])

    # Instantiate the domain model and the plot controller
    domain_model = DomainModel(scaling_factor=50)
    plot_controller = PlotController(domain_model=domain_model)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    #
    # The widget contains an embedded Chaco QWidget showing a 2D plot of
    # the domain model. Moving the slider on the UI changes the domain model
    # and hence the Chaco plot.
    widget = HTMLWidget(
        template=template,
        context={
            'domain_model': domain_model,
            'plot_controller': plot_controller
        }
    )
    widget.show()

    # Start the event loop
    app.exec_()
コード例 #6
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain models
    installer = Installer()
    pandas = Package(name='Pandas', version='1.0')

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template,
                        context={
                            'installer': installer,
                            'new_package': pandas
                        })
    widget.show()

    # Start the event loop.
    #
    # Clicking on the button in the UI will call the `install` method in a
    # thread so that the UI is still responsive while the method is executing.
    # The progress bar is also updated as the method progresses.
    app.exec_()

    # Check the final values
    print(installer.current.name, installer.current.version)
コード例 #7
0
ファイル: instance_trait.py プロジェクト: bergtholdt/jigna
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    fred = Person(name='Fred')
    wilma = Person(name='Wilma')

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'person':fred})
    widget.show()

    # Schedule some operations on the domain model.
    #
    # The operation should fill in the `spouse` field of the person and this
    # should be reflected in the UI.
    do_after(2500, fred.marry, wilma)

    # Start the event loop.
    #
    # Initially, the `spouse` field of the person is empty, so the fields
    # related to the spouse should be empty in the UI.
    app.exec_()

    # Check the final values of the instance
    print fred.name, fred.spouse.name, wilma.name
コード例 #8
0
ファイル: test_html_widget.py プロジェクト: dusual/jigna
    def test_jigna_was_initialized(self):
        # Create a widget
        widget = HTMLWidget(template=self.template, context={"model": self.model})

        # Check if `jigna` was initialised on the JS side
        client = widget.execute_js("jigna.client")
        self.assertIsNotNone(client)
コード例 #9
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain models
    installer = Installer()
    pandas = Package(name='Pandas', version='1.0')

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(
        template=template,
        context={'installer': installer, 'new_package': pandas}
    )
    widget.show()

    # Start the event loop.
    #
    # Clicking on the button in the UI will call the `install` method in a
    # thread so that the UI is still responsive while the method is executing.
    # The progress bar is also updated as the method progresses.
    app.exec_()

    # Check the final values
    print(installer.current.name, installer.current.version)
コード例 #10
0
ファイル: ex22_vuejs_demo.py プロジェクト: enthought/jigna
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model

    fred = Person(name='Fred', age=42, fruits=['pear', 'apple'])

    template = VueTemplate(html_file='ex22_vuejs_demo.html')

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'person': fred}, debug=True)
    widget.show()

    # Schedule an update to a model variable after 2.5 seconds. This update
    # will be reflected in the UI immediately.
    do_after(2500, fred.update_name, "Guido")
    do_after(2500, fred.add_fruit)
    do_after(2500, fred.add_friend)

    # Start the event loop
    app.exec_()

    # Check the values after the UI is closed
    print(fred.name, fred.age, fred.fruits, fred.friends)
コード例 #11
0
    def test_created_widget_can_access_jigna(self):
        # Create a widget
        widget = HTMLWidget(template=self.template,
                            context={'model': self.model})

        # Check if `jigna` was loaded on the JS side
        jigna = widget.execute_js("jigna")
        self.assertIsNotNone(jigna)
コード例 #12
0
    def test_jigna_was_initialized(self):
        # Create a widget
        widget = HTMLWidget(template=self.template,
                            context={'model': self.model})

        # Check if `jigna` was initialised on the JS side
        client = widget.execute_js("jigna.client")
        self.assertIsNotNone(client)
コード例 #13
0
ファイル: test_jigna_qt.py プロジェクト: dusual/jigna
 def setUpClass(cls):
     qapp = QtGui.QApplication.instance() or QtGui.QApplication([])
     template = Template(body_html=body_html)
     fred = Person(name='Fred', age=42)
     widget = HTMLWidget(template=template, context={'model':fred})
     widget.show()
     gui.process_events()
     cls.widget = widget
     cls.fred = fred
コード例 #14
0
 def setUpClass(cls):
     qapp = QtGui.QApplication.instance() or QtGui.QApplication([])
     template = Template(body_html=body_html)
     fred = Person(name='Fred', age=42)
     widget = HTMLWidget(template=template, context={'model': fred})
     widget.show()
     gui.process_events()
     cls.widget = widget
     cls.fred = fred
コード例 #15
0
ファイル: test_html_widget.py プロジェクト: dusual/jigna
    def test_jigna_was_initialized_with_python_models(self):
        # Create a widget
        widget = HTMLWidget(template=self.template, context={"model": self.model})

        # Check if `jigna` was initialised with the correct python models
        # (check by making sure that primitive variables are the same)
        attr1 = widget.execute_js("jigna.models.model.attr1")
        attr2 = widget.execute_js("jigna.models.model.attr2")
        self.assertEqual(attr1, self.model.attr1)
        self.assertEqual(attr2, self.model.attr2)
コード例 #16
0
ファイル: test_html_widget.py プロジェクト: dusual/jigna
    def test_two_widgets_are_created(self):
        widget1 = HTMLWidget(template=self.template, context={"model": self.model})

        widget2 = HTMLWidget(template=self.template, context={"model": self.model})

        # Check if `jigna` was initialised with the correct python models
        # (check by making sure that primitive variables are the same)
        attr1 = widget1.execute_js("jigna.models.model.attr1")
        attr2 = widget2.execute_js("jigna.models.model.attr2")
        self.assertEqual(attr1, self.model.attr1)
        self.assertEqual(attr2, self.model.attr2)
コード例 #17
0
    def test_jigna_was_initialized_with_python_models(self):
        # Create a widget
        widget = HTMLWidget(template=self.template,
                            context={'model': self.model})

        # Check if `jigna` was initialised with the correct python models
        # (check by making sure that primitive variables are the same)
        attr1 = widget.execute_js("jigna.models.model.attr1")
        attr2 = widget.execute_js("jigna.models.model.attr2")
        self.assertEqual(attr1, self.model.attr1)
        self.assertEqual(attr2, self.model.attr2)
コード例 #18
0
ファイル: test_jigna_vue_qt.py プロジェクト: bergtholdt/jigna
 def setUpClass(cls):
     from jigna.api import HTMLWidget, VueTemplate
     from jigna.utils import gui
     from jigna.qt import QtGui
     qapp = QtGui.QApplication.instance() or QtGui.QApplication([])
     template = VueTemplate(body_html=body_vue_html)
     fred = Person(name='Fred', age=42)
     widget = HTMLWidget(template=template, context={'model':fred})
     widget.show()
     gui.process_events()
     cls.widget = widget
     cls.fred = fred
コード例 #19
0
ファイル: test_html_widget.py プロジェクト: bergtholdt/jigna
    def test_events_are_not_sent_after_widget_is_closed(self):
        # Given
        template = Template(body_html="Attr1: {{model.attr1}}")
        widget = HTMLWidget(template=template, context={'model': self.model})

        # When
        self.model.attr1 = "one"
        widget.close()
        self.model.attr1 = "two"

        # Then
        #
        # After the widget is closed, we should not fire any further object
        # changed events.
        self.assertEqual(widget.execute_js("jigna.models.model.attr1"), "one")
コード例 #20
0
    def test_events_are_not_sent_after_widget_is_closed(self):
        # Given
        template = Template(body_html="Attr1: {{model.attr1}}")
        widget = HTMLWidget(template=template, context={'model': self.model})

        # When
        self.model.attr1 = "one"
        widget.close()
        self.model.attr1 = "two"

        # Then
        #
        # After the widget is closed, we should not fire any further object
        # changed events.
        self.assertEqual(widget.execute_js("jigna.models.model.attr1"), "one")
コード例 #21
0
def main():
    # Start a QtGui application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    fred = Person(name='Fred', age=42)

    # Create a jigna based HTML widget to render the HTML template with the
    # given context.
    widget = HTMLWidget(template=template, context={'person': fred})
    widget.show()

    # Start the event loop
    app.exec_()

    # Check the values after the UI is closed
    print fred.name, fred.age
コード例 #22
0
ファイル: simple_view.py プロジェクト: bergtholdt/jigna
def main():
    # Start a QtGui application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    fred = Person(name='Fred', age=42)

    # Create a jigna based HTML widget to render the HTML template with the
    # given context.
    widget = HTMLWidget(template=template, context={'person': fred})
    widget.show()

    # Start the event loop
    app.exec_()

    # Check the values after the UI is closed
    print fred.name, fred.age
コード例 #23
0
 def setUpClass(cls):
     from jigna.api import HTMLWidget, VueTemplate
     from jigna.utils import gui
     from jigna.qt import QtWidgets
     qapp = QtWidgets.QApplication.instance() or QtWidgets.QApplication([])
     template = VueTemplate(body_html=body_vue_html)
     fred = Person(name='Fred', age=42)
     addressbook = AddressBook()
     widget = HTMLWidget(template=template,
                         context={
                             'model': fred,
                             'addressbook': addressbook
                         })
     widget.show()
     gui.process_events()
     cls.widget = widget
     cls.fred = fred
     cls.addressbook = addressbook
コード例 #24
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain models
    worker = Worker()

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'worker': worker})
    widget.show()

    # Start the event loop.
    #
    # The view related code is such that clicking on the buttons in the UI will
    # call methods on the domain model and do something when the method call
    # succeeded or failed.
    app.exec_()
コード例 #25
0
ファイル: ex5_user_resources.py プロジェクト: enthought/jigna
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    lena = Person(name='Lena', age=28)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'person':lena})
    widget.show()

    # Start the event loop.
    #
    # You should see that user resources like CSS, images and custom JS are
    # pulled in properly from the `user_resources_data` directory and displayed
    # in the view.
    app.exec_()
コード例 #26
0
    def test_widget_is_created(self):
        # Create a widget
        widget = HTMLWidget(template=self.template,
                            context={'model': self.model})

        # Check if a qwebview widget was created
        self.assertIsNotNone(widget)
        self.assertIsInstance(widget, QtWidgets.QWidget)
        self.assertIsInstance(widget.webview, QtWebKitWidgets.QWebView)
コード例 #27
0
ファイル: templating.py プロジェクト: dusual/jigna
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    fred = Person(name="Fred", age=28)
    wilma = Person(name="Wilma", age=25)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={"fred": fred, "wilma": wilma})
    widget.show()

    # Start the event loop.
    #
    # You should see that the person-view component's template is rendered with
    # the correct domain models.
    app.exec_()
コード例 #28
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain models
    worker = Worker()

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'worker': worker})
    widget.show()

    # Start the event loop.
    #
    # The view related code is such that clicking on the buttons in the UI will
    # call methods on the domain model and do something when the method call
    # succeeded or failed.
    app.exec_()
コード例 #29
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    lena = Person(name='Lena', age=28)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'person': lena})
    widget.show()

    # Start the event loop.
    #
    # You should see that user resources like CSS, images and custom JS are
    # pulled in properly from the `user_resources_data` directory and displayed
    # in the view.
    app.exec_()
コード例 #30
0
ファイル: ex6_model_updates.py プロジェクト: will133/jigna
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    motd = MOTD(message="Explicit is better than implicit.")

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'motd':motd})
    widget.show()

    # Schedule an update to a model variable after 2.5 seconds. This update
    # will be reflected in the UI immediately.
    do_after(2500, motd.update_message, "Flat is better than nested.")

    # Start the event loop
    app.exec_()
コード例 #31
0
ファイル: ex14_event_trait.py プロジェクト: will133/jigna
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    file_urls = ['images/lena.png', 'videos/big-buck-bunny.mp4']
    downloader = Downloader(file_urls=file_urls)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'downloader': downloader})
    widget.show()

    # Start the event loop.
    #
    # Clicking on the button in the UI will call the `download_files` method in
    # a thread. After each file is "downloaded", a Javascript alert should come
    # up. This is in response to a Python event on each file download.
    app.exec_()
コード例 #32
0
    def test_created_widget_loads_html(self):
        # Create a widget
        widget = HTMLWidget(template=self.template,
                            context={'model': self.model})

        # Check if the widget has html loaded in it
        webview = widget.webview
        frame = webview.page().mainFrame()
        self.assertIsInstance(frame.toHtml(), basestring)
        self.assertGreater(len(frame.toHtml()), 0)
コード例 #33
0
ファイル: ex14_event_trait.py プロジェクト: bergtholdt/jigna
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    file_urls = ['images/lena.png', 'videos/big-buck-bunny.mp4']
    downloader = Downloader(file_urls=file_urls)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'downloader':downloader})
    widget.show()

    # Start the event loop.
    #
    # Clicking on the button in the UI will call the `download_files` method in
    # a thread. After each file is "downloaded", a Javascript alert should come
    # up. This is in response to a Python event on each file download.
    app.exec_()
コード例 #34
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    fred = Person(name='Fred', age=28)
    wilma = Person(name='Wilma', age=25)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(
        template=template, context={'fred': fred, 'wilma': wilma}
    )
    widget.show()

    # Start the event loop.
    #
    # You should see that the person-view component's template is rendered with
    # the correct domain models.
    app.exec_()
コード例 #35
0
def create_jigna_widget():
    """ Create a jigna based HTML widget. This widget is embedded in a QtGui
    application.

    """
    # Instantiate the domain model
    tom = Employee(name='Tom', salary=2000)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    return HTMLWidget(template=template, context={'employee': tom})
コード例 #36
0
def main():
    # Start the Qt application
    app = QtGui.QApplication.instance() or QtGui.QApplication([])

    # Instantiate the domain model
    scene_controller = SceneController()

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    #
    # The view contains an embedded Mayavi QWidget showing a visualization of
    # the domain model. Moving the sliders on the UI changes the domain model and
    # hence the Mayavi visualization.
    widget = HTMLWidget(
        template=template, context={'scene_controller': scene_controller}
    )
    widget.show()

    # Start the event loop
    app.exec_()
コード例 #37
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    fred = Person(name='Fred', age=42)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    #
    # This will behave as a static page since we don't have the traits
    # machinery here to reflect model updates in the view.
    widget = HTMLWidget(template=template, context={'person': fred})
    widget.show()

    # Start the event loop
    app.exec_()

    # Check the values after the UI is closed
    print fred.name, fred.age
コード例 #38
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    fred = Person(name='Fred', age=42)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    #
    # This will behave as a static page since we don't have the traits
    # machinery here to reflect model updates in the view.
    widget = HTMLWidget(template=template, context={'person': fred})
    widget.show()

    # Start the event loop
    app.exec_()

    # Check the values after the UI is closed
    print fred.name, fred.age
コード例 #39
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    stop_watch = StopWatch()

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    #
    # The operations on the stop watch can be controlled from the UI. The view
    # related logic is such that it always displays the integer time of the
    # domain model in a proper hh:mm:ss format.
    widget = HTMLWidget(template=template, context={'stop_watch': stop_watch})
    widget.show()

    # Start the event loop
    app.exec_()

    # Check the values after the UI is closed
    print(stop_watch.time, "seconds")
コード例 #40
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    stop_watch = StopWatch()

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    #
    # The operations on the stop watch can be controlled from the UI. The view
    # related logic is such that it always displays the integer time of the
    # domain model in a proper hh:mm:ss format.
    widget = HTMLWidget(template=template, context={'stop_watch': stop_watch})
    widget.show()

    # Start the event loop
    app.exec_()

    # Check the values after the UI is closed
    print(stop_watch.time, "seconds")
コード例 #41
0
ファイル: ex18_embedding_chaco.py プロジェクト: will133/jigna
def main():
    # Start the Qt application
    app = QtGui.QApplication.instance() or QtGui.QApplication([])

    # Instantiate the domain model and the plot controller
    domain_model = DomainModel(scaling_factor=50)
    plot_controller = PlotController(domain_model=domain_model)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    #
    # The widget contains an embedded Chaco QWidget showing a 2D plot of
    # the domain model. Moving the slider on the UI changes the domain model
    # and hence the Chaco plot.
    widget = HTMLWidget(template=template,
                        context={
                            'domain_model': domain_model,
                            'plot_controller': plot_controller
                        })
    widget.show()

    # Start the event loop
    app.exec_()
コード例 #42
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    fred = Person(name='Fred', friends=[Person(name='Dino')])

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'person':fred})
    widget.show()

    # Schedule some operations on the list.
    #
    # We're trying to append and insert instances in the list in the future.
    # This should be reflected in the UI.
    do_after(2500, fred.friends.append, Person(name='Wilma'))
    do_after(5000, fred.friends.insert, 0, Person(name='Barney'))

    # Start the event loop
    app.exec_()

    # Check the final values of the list attribute
    print([friend.name for friend in fred.friends])
コード例 #43
0
ファイル: ex11_method_call.py プロジェクト: enthought/jigna
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain models
    fred = Person(name='Fred', age=14)
    wilma = Person(name='Wilma', age=25)

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(
        template=template, context={'person': fred, 'spouse': wilma}
    )
    widget.show()

    # Start the event loop.
    #
    # Clicking on the buttons in the UI will make blocking calls to the
    # corresponding methods on the domain model. You can supply primitive as
    # well as instance objects as arguments of the method.
    app.exec_()

    # Check the final values after the UI is closed
    print(fred.name, fred.age, fred.spouse.name)
コード例 #44
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    basket = Basket(fruits=['peach', 'pear'])

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'basket': basket})
    widget.show()

    # Schedule some operations on the list.
    #
    # We're trying to append and insert primitives to the list in the future.
    # This should be reflected in the UI.
    do_after(2500, basket.fruits.append, 'mango')
    do_after(5000, basket.fruits.insert, 0, 'banana')

    # Start the event loop
    app.exec_()

    # Check the final values of the list attribute
    print(basket.fruits)
コード例 #45
0
def main():
    # Start the Qt application
    app = QtGui.QApplication([])

    # Instantiate the domain model
    basket = Basket(fruits=['peach', 'pear'])

    # Create the jigna based HTML widget which renders the given HTML template
    # with the given context.
    widget = HTMLWidget(template=template, context={'basket':basket})
    widget.show()

    # Schedule some operations on the list.
    #
    # We're trying to append and insert primitives to the list in the future.
    # This should be reflected in the UI.
    do_after(2500, basket.fruits.append, 'mango')
    do_after(5000, basket.fruits.insert, 0, 'banana')

    # Start the event loop
    app.exec_()

    # Check the final values of the list attribute
    print(basket.fruits)
コード例 #46
0
    def test_two_widgets_are_created(self):
        widget1 = HTMLWidget(template=self.template,
                             context={'model': self.model})

        widget2 = HTMLWidget(template=self.template,
                             context={'model': self.model})

        # Check if `jigna` was initialised with the correct python models
        # (check by making sure that primitive variables are the same)
        attr1 = widget1.execute_js("jigna.models.model.attr1")
        attr2 = widget2.execute_js("jigna.models.model.attr2")
        self.assertEqual(attr1, self.model.attr1)
        self.assertEqual(attr2, self.model.attr2)