Esempio n. 1
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
Esempio n. 2
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")
Esempio n. 3
0
body_html = """
    <div>
        <img ng-src='{{person.name}}.png' /><br/>
        <div id="caption" class='red'>
            {{person.name}} - {{person.age}} years old
        </div>
    </div>

    <script type='text/javascript' src='color_change.js'></script>
    <link rel='stylesheet' href='colors.css' />
"""

# The base_url field specifies where to look when trying to get external
# resources(defaults to an empty string, i.e. the current directory)
template = Template(body_html=body_html,
                    base_url='user_resources_data/',
                    recommended_size=(600, 600))

#### Entry point ####


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})
Esempio n. 4
0
class TestJignaWebSync(TestJignaQt):
    @classmethod
    def setUpClass(cls, async=False):
        ioloop = IOLoop.instance()
        fred = Person(name='Fred', age=42)
        template = Template(body_html=body_html, async=async)
Esempio n. 5
0
        stream.seek(0)
        self.plot = stream.buf.encode('base64')


#### UI layer ####

body_html = """
   <div>
        Scaling factor: <input type="range" ng-model="domain_model.scaling_factor"
                        min=0 max=30><br>
        Plot:<br>
        <img ng-src="data:image/png;base64,{{plot_controller.plot}}">
    </div>
"""

template = Template(body_html=body_html)

#### Entry point ####


def main():
    # Start the tornado ioloop application
    ioloop = IOLoop.instance()

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

    # Create a WebApp to render the HTML template with the given context.
    #
    # The web app shows a matplotlib plot in a browser by displaying the png
Esempio n. 6
0
    def setUp(self):
        self.model = MyModel(attr1="Attr1", attr2=2)
        self.template = Template(body_html="")

        self.app = QtWidgets.QApplication.instance() or QtWidgets.QApplication(
            [])
Esempio n. 7
0
                self.plot.contour.number_of_contours = value
                self._update_mesh_data()

    plot = Instance(PipelineBase)

    mesh_data = Instance(MeshData, ())

    def _update_mesh_data(self):
        self.mesh_data.copy_traits(
            MeshData.from_dataset(dataset=self.plot.contour.outputs[0],
                                  module_manager=self.plot.module_manager))


#### UI layer ####

template = Template(html_file='mayavi_webgl_demo.html')

#### Entry point ####


def main():
    # Start the tornado ioloop application
    ioloop = IOLoop.instance()

    # Instantiate the domain model
    plotter = Plotter3D(expression="x*x*0.5 + y*y + z*z*2.0", n_contour=4)

    # Create a web app serving the view with the domain model added to its
    # context.
    app = WebApp(template=template, context={'plotter': plotter})
    app.listen(8000)
Esempio n. 8
0
body_html = """
    <div>
        <img ng-src='{{person.name}}.png' /><br/>
        <div id="caption" class='red'>
            {{person.name}} - {{person.age}} years old
        </div>
    </div>

    <script type='text/javascript' src='color_change.js'></script>
    <link rel='stylesheet' href='colors.css' />
"""

# The base_url field specifies where to look when trying to get external
# resources(defaults to an empty string, i.e. the current directory)
template = Template(body_html=body_html,
                    base_url='ex5_data/',
                    recommended_size=(600, 600))

#### Entry point ####


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})
Esempio n. 9
0
from jigna.qt import QtGui

#### Domain model ####


class Person(HasTraits):
    name = Str
    age = Int

    def update_name(self, name):
        self.name = name


#### UI layer ####

template = Template(html_file='simple_view_full.html')

#### Entry point ####


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.
    widget = HTMLWidget(template=template, context={'person': fred})
    widget.show()
    def start(self):
        self.state = 'running'
        while self.state == 'running':
            time.sleep(1)
            self.time += 1

    def stop(self):
        self.state = 'stopped'

    def reset(self):
        self.time = 0


#### UI layer ####

template = Template(html_file='ex17_custom_angular_application.html')

#### Entry point ####


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
Esempio n. 11
0
html = """
  <html ng-app='templating'>
    <head>
      <script type='text/javascript' src='/jigna/jigna.js'></script>
      <script type='text/javascript' src='ex16_templating.js'></script>
    </head>
    <body>
      <person-view person="fred"></person-view>
      <person-view person="wilma"></person-view>
    </body>
  </html>
"""

# The base_url field specifies where to look when trying to get external
# resources(defaults to an empty string, i.e. the current directory)
template = Template(html=html)

#### Entry point ####


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(
Esempio n. 12
0

class Worker(HasTraits):
    def do_work(self):
        """ Simulate doing some work by sleeping a bit :) """
        time.sleep(1)

    def do_illegal_work(self):
        """ Simulate doing an illegal work that will raise an error """
        time.sleep(1)
        raise Exception("Illegal operation")


#### UI layer ####

template = Template(html_file='success_error_callbacks.html')

#### Entry point ####


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()
Esempio n. 13
0
                       min=0 max=100><br>
      Plot:<br>

      <!-- Specify type='application/x-qwidget' to embed a QWidget in the jigna
      view. Note that 'widget-factory' here refers to the factory method in
      Python which will generate that QWidget. -->
      <div>
        <object type="application/x-qwidget"
                widget-factory="plot_controller.create_plot_widget"
                width="500" height="400">
        </object>
      </div>
    </div>
"""

template = Template(body_html=body_html, recommended_size=(600, 600))

#### Entry point ####


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.
    #