Exemple #1
0
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)
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_()
Exemple #3
0
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)
Exemple #4
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)
Exemple #5
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)
Exemple #6
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
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)
Exemple #8
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)
Exemple #9
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
 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
Exemple #11
0
 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
Exemple #12
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
Exemple #13
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
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_()
Exemple #15
0
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_()
 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
Exemple #17
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_()
Exemple #18
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_()
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_()
Exemple #20
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_()
Exemple #21
0
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_()
Exemple #22
0
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_()
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_()
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
Exemple #25
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_()
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
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")
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")
Exemple #29
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_()
Exemple #30
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])
Exemple #31
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)
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)
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)