コード例 #1
0
def main():
    """ Create and show a QMainWindow which embeds the given widget on a button
    click.

    """
    app = QtGui.QApplication([])

    # Define a new QMainWindow
    window = QtGui.QMainWindow()
    window.setMinimumSize(600, 400)

    # Set up the QLayout
    layout = QtGui.QVBoxLayout()
    window.setCentralWidget(QtGui.QWidget())
    window.centralWidget().setLayout(layout)

    # Add a button to the layout which embeds the supplied widget on click.
    button = QtGui.QPushButton("I'm a QPushButton. Press me to embed a widget")
    button.clicked.connect(lambda: layout.addWidget(create_jigna_widget()))
    layout.addWidget(button)

    # Show the window
    window.show()

    app.exec_()
コード例 #2
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)
コード例 #3
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)
コード例 #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)
コード例 #5
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)
コード例 #6
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
コード例 #7
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
コード例 #8
0
ファイル: test_jigna_vue_qt.py プロジェクト: will133/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)
     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
コード例 #9
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_()
コード例 #10
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_()
コード例 #11
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_()
コード例 #12
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_()
コード例 #13
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
コード例 #14
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_()
コード例 #15
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_()
コード例 #16
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")
コード例 #17
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_()
コード例 #18
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])
コード例 #19
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)
コード例 #20
0
    def setUp(self):
        self.model = MyModel(attr1="Attr1", attr2=2)
        self.template = Template(body_html="")

        self.app = QtGui.QApplication.instance() or QtGui.QApplication([])
コード例 #21
0
class ProxyQWebPage(QtWebKit.QWebPage):
    """ Overridden to open external links in a web browser.

    Source: http://www.expobrain.net/2012/03/01/open-urls-in-external-browser-by-javascript-in-webkit/
    """

    def acceptNavigationRequest(self, frame, request, type):
        # Checking this is same as checking if the client side <a> tag making
        # the HTTP request had target="_blank" as an attribute.
        if frame is None:
            import webbrowser
            webbrowser.open_new(request.url().toString())

            return False

        else:
            return super(ProxyQWebPage, self).acceptNavigationRequest(
                frame, request, type
            )

    def createWindow(self, *args, **kwargs):
        return ProxyQWebPage()

if __name__ == '__main__':
    app = QtGui.QApplication([])
    w = ProxyQWebView()
    w.show()
    w.raise_()
    w.load(QtCore.QUrl('http://www.google.com/'))
    app.exec_()