Пример #1
0
def main(argv):
    """A simple example of using the workbench."""

    # Create the GUI.
    gui = GUI()

    # Create the workbench.
    #
    # fixme: I wouldn't really want to specify the state location here.
    # Ideally this would be part of the GUI's as DOMs idea, and the state
    # location would be an attribute picked up from the DOM hierarchy. This
    # would also be the mechanism for doing 'confirm' etc... Let the request
    # bubble up the DOM until somebody handles it.
    workbench = ExampleWorkbench(state_location=gui.state_location)

    # Create the workbench window.
    window = workbench.create_window(position=(300, 300), size=(800, 600))
    window.open()

    # This will cause a TraitsUI editor to be created.
    window.edit(Person(name='fred', age=42, salary=50000))

    # This will cause a toolkit specific editor to be created.
    window.edit("This text is implemented by a toolkit specific widget.")

    # Start the GUI event loop.
    gui.start_event_loop()
Пример #2
0
    def wrapper(*args, **kw):
        """Wrapper function to run given function inside the GUI event
        loop.
        """
        global _gui, _stop_show
        tk = ETSConfig.toolkit

        if is_ui_running():
            # In this case we should not pop up the UI since we likely
            # don't want to stop the mainloop.
            return func(*args, **kw)
        else:
            g = GUI()
            if tk == 'wx':
                # Create a dummy app so invoke later works on wx.
                a = ApplicationWindow(size=(1, 1))
                GUI.invoke_later(lambda: a.close())
                a.open()

            GUI.invoke_later(func, *args, **kw)
            _gui = g
            if stop:
                # Pop up the UI to stop the mainloop.
                _stop_show = StopShow()
            g.start_event_loop()
Пример #3
0
def viewer(browser=True, instantiate_gui=False):
    """Creates an IVTK instance, opens the window and returns the
    embedded scene inside it.  This is useful from an IPython/vanilla
    Python shell.  It returns the viewer window instance.

    Parameters
    ----------

    - browser : `bool` (default, True)
    
      If True, creates an IVTK scene with an embedded PipelineBrowser.
      If False, does not create it.

    - instantiate_gui : `bool` (default: False)

      If True, create an instance of GUI().  This is useful when this
      function is invoked from within an IPython shell.  OTOH, if this
      is called from within a wxPython app (or with ipython -wthread)
      you don't want to start another GUI instance.
    """
    if instantiate_gui:
        gui = GUI()
    if browser:
        v = IVTKWithBrowser(size=(600, 600))
    else:
        v = IVTK(size=(600, 600))
    v.open()
    return v
Пример #4
0
def main():
    import optparse
    parser = optparse.OptionParser(usage="""\
%prog [options] [trace.txt|trace.txt.gz|trace.txt.lzma|trace.dat]

pytimechart - Fast graphical exploration and visualisation for linux kernel traces."""
                                   )
    parser.add_option("-p",
                      "--prof",
                      dest="prof",
                      action="store_true",
                      help="activate profiling",
                      default=False)
    (options, args) = parser.parse_args()

    # Create the GUI (this does NOT start the GUI event loop).
    gui = GUI()
    if len(args) == 0:
        args.append("dummy")
    for fn in args:
        if not open_file(fn):
            sys.exit(0)
    if options.prof:
        import cProfile
        dict = {"gui": gui}
        cProfile.runctx('gui.start_event_loop()', dict, dict, 'timechart.prof')
    else:
        gui.start_event_loop()
Пример #5
0
def main(argv):
    """ A simple example of using the the application scripting framework in a
    workbench.
    """

    # Create the GUI.
    gui = GUI()

    # Create the workbench.
    workbench = ExampleScript(state_location=gui.state_location)

    window = workbench.create_window(position=(300, 300), size=(400, 300))
    window.open()

    # Create some objects to edit.
    # FIXME v3: The need to explicitly set the style to its default value is
    # due to a bug in the implementation of Scriptable.
    label = Label(text="Label", style='normal')
    label2 = Label(text="Label2", style='normal')

    # Edit the objects.
    window.edit(label)
    window.edit(label2)

    # Start the GUI event loop.
    gui.start_event_loop()

    return
Пример #6
0
def main():
    # Create the GUI.
    gui = GUI()
    # Create and open an application window.
    window = IVTKWithCrustAndBrowser(size=(800, 600))
    window.open()
    # Start the GUI event loop!
    gui.start_event_loop()
Пример #7
0
def show_actors(actors, shell=False):
    gui = GUI()
    if shell:
        window = ivtk.IVTKWithCrustAndBrowser(size=(800, 600))
    else:
        window = ivtk.IVTKWithBrowser(size=(600, 400))
    window.open()
    for a in actors:
        window.scene.add_actor(a)
    window.scene.background = (1, 1, 1)
    return window, gui
Пример #8
0
    def _create_ivtk_window(self, size=(800, 800)):
        from enthought.tvtk.tools import ivtk
        from enthought.pyface.api import GUI

        # Create a GUI instance.
        self.gui = GUI()
        window = ivtk.IVTKWithCrustAndBrowser(size=size)  # Size is optional.
        # Open the window.
        window.open()
        self.renderer = window.scene
        self.render_window = window
Пример #9
0
def _test():
    import doctest, numpy
    from enthought.pyface.api import GUI, ApplicationWindow, ImageResource, SplashScreen
    #splash_screen = SplashScreen(image=ImageResource('splash'))
    splash_screen = SplashScreen()
    gui = GUI(splash_screen=splash_screen)
    #doctest.testmod()
    x = numpy.linspace(0, 100)
    y = numpy.linspace(0, 100) + numpy.random.randn(50)
    t = FitFunction(name='general.linear')
    data = FitData(x=x, y=y)
    #t = DataFitterPanel(data = data, category = 'general', function_name = 'linear')
    t = DataFitter(data=data, function=t)
    #t.fit()
    #t.plotter.savefig('test.png')
    gui.start_event_loop()
    t.configure_traits()
Пример #10
0
def main():
    gui = GUI()
    # Create and open an application window.
    window = ivtk.IVTKWithCrustAndBrowser(size=(800, 600))
    window.open()
    f = Figure(window.scene)

    # Create an outline.
    o = Outline()
    f.add(o)

    # Create some pretty pictures.
    #test_lines(f)
    test_surf(f)

    window.scene.reset_zoom()

    # Start the GUI event loop!
    gui.start_event_loop()
Пример #11
0
def visual_test(jpos, jfreedom, loads, elements, E, r, p, max_stress=3e+8):
    displacements, strains, stresses, mass, status, times = analyse_truss(jpos, jfreedom, loads, elements, E, r, p)
    jpos_d = jpos + displacements*100
    print status
    print times
    print 'displacements: ', displacements
    print 'strains: ', strains
    print 'stresses: ', stresses
    #strains_abs = N.abs(strains)

    from enthought.tvtk.api import tvtk
    from enthought.tvtk.tools import ivtk
    from enthought.pyface.api import GUI
    v = ivtk.viewer(False, False)
    v.scene.z_plus_view()

    pd = tvtk.PolyData()
    pts = jpos[elements].reshape((-1,2))
    pd.points = N.column_stack((pts[:,0], pts[:,1], N.zeros(len(pts))))
    pd.lines = N.r_[:len(elements)*2].reshape((-1,2))
    pd.cell_data.scalars = -strains
    pd.point_data.scalars = N.column_stack((r, r)).ravel()
    #tubes = tvtk.TubeFilter(input=pd, radius=N.sqrt(element_A.max() / N.pi), number_of_sides=16)
    tubes = tvtk.TubeFilter(input=pd, number_of_sides=16, vary_radius='vary_radius_by_absolute_scalar', capping=True)
    #tubes = tvtk.RibbonFilter(input=pd, use_default_normal=True, vary_width=True)
    b = tvtk.Actor(mapper=tvtk.PolyDataMapper(input=tubes.output, scalar_range=(-N.abs(strains).max(), N.abs(strains).max()), scalar_mode='use_cell_data'))
    b.mapper.lookup_table.hue_range = (0, 0.66)
    v.scene.add_actor(b)

    pd1 = tvtk.PolyData()
    pd1.points = N.column_stack((jpos_d[:,0], jpos_d[:,1], N.zeros(len(jpos))))
    pd1.lines = elements
    tubes1 = tvtk.TubeFilter(input=pd1, radius=0.01, number_of_sides=16)
    a = tvtk.Actor(mapper=tvtk.PolyDataMapper(input=tubes1.output))
    a.property.opacity = 0.3
    v.scene.add_actor(a)

    print "strain: ", strains.min(), strains.max()

    v.scene.reset_zoom()
    GUI().start_event_loop()
Пример #12
0
def main(argv):
    """ A simple example of using the workbench. """

    # Create the GUI (this does NOT start the GUI event loop).
    gui = GUI()

    # Create some objects to edit.
    fred = Person(name='fred', age=42)
    wilma = Person(name='wilma', age=35)

    # Create the workbench.
    #
    # fixme: I wouldn't really want to specify the state location here.
    # Ideally this would be part of the GUI's as DOMs idea, and the state
    # location would be an attribute picked up from the DOM hierarchy. This
    # would also be the mechanism for doing 'confirm' etc... Let the request
    # bubble up the DOM until somebody handles it.
    workbench = ExampleWorkbench(state_location=gui.state_location)

    # Create some workbench windows.
    x = 300
    y = 300
    for i in range(2):
        window = workbench.create_window(position=(x, y), size=(800, 600))
        window.open()

        # Edit the objects if they weren't restored from a previous session.
        if window.get_editor_by_id('fred') is None:
            window.edit(fred)

        if window.get_editor_by_id('wilma') is None:
            window.edit(wilma)

        # Cascade the windows.
        x += 100
        y += 100

    # Start the GUI event loop.
    gui.start_event_loop()

    return
Пример #13
0
def main(argv):
    """ A simple example of using the the undo framework in a workbench. """

    # Create the GUI.
    gui = GUI()

    # Create the workbench.
    workbench = ExampleUndo(state_location=gui.state_location)

    window = workbench.create_window(position=(300, 300), size=(400, 300))
    window.open()

    # Create some objects to edit.
    label = Label(text="Label")
    label2 = Label(text="Label2")

    # Edit the objects.
    window.edit(label)
    window.edit(label2)

    # Start the GUI event loop.
    gui.start_event_loop()

    return
Пример #14
0
from enthought.traits import *
from enthought.pyface.api import GUI
from enthought.traits.api import HasTraits, Int, Button
from enthought.traits.ui.api import View, Item, ButtonEditor


class Counter(HasTraits):
    value = Int()
    add_one = Button()

    def _add_one_fired(self):
        self.value += 1

    view = View('value', Item('add_one', show_label=False))


Counter().edit_traits()
GUI().start_event_loop()
#Counter().configure_traits()
Пример #15
0
        python_shell.bind('window', self)
        python_shell.bind('actions', self._actions)

        return python_shell.control

    #### Trait event handlers #################################################

    def _on_selection_changed(self, selection):
        """ Called when the selection in the tree is changed. """

        if len(selection) > 0:
            self._table_viewer.input = selection[0]

        return


# Application entry point.
if __name__ == '__main__':
    # Create the GUI and put up a splash screen (this does NOT start the GUI
    # event loop).
    gui = GUI(splash_screen=SplashScreen())

    # Create and open the main window.
    window = MainWindow()
    window.open()

    # Start the GUI event loop.
    gui.start_event_loop()

##### EOF #####################################################################
Пример #16
0
            self.my_timer = Timer(500, self._timer_task)
        else:
            self.my_timer.Start()

    def _stop_timer(self):
        """Called when the user selecte "Stop Timer" from the menu."""

        if self.my_timer is not None:
            self.my_timer.Stop()

    def _timer_task(self):
        """The method run periodically by the timer."""

        self.counter += 1
        print "counter = %d" % self.counter


if __name__ == "__main__":

    gui = GUI(splash_screen=splash_screen)

    # Create and open the main window.
    window = MainWindow()

    # Simulate a busy window initialization.
    time.sleep(5)
    window.open()

    # Start the GUI event loop!
    gui.start_event_loop()
Пример #17
0
    # notifies others that the engine is ready.
    e.start()

    # Do this if you need to see the MayaVi tree view UI.
    ev = EngineView(engine=e)
    ui = ev.edit_traits()

    # Create a new scene.
    scene = e.new_scene()
    # Now create a new scene just for kicks.
    scene1 = e.new_scene()

    # Now setup a normal MayaVi pipeline.
    src = VTKXMLFileReader()
    src.initialize(join(get_data_dir(abspath(__file__)), 'fire_ug.vtu'))
    e.add_source(src)
    e.add_module(Outline())
    e.add_module(ScalarCutPlane())
    e.add_module(Streamline())
    return e, ui


if __name__ == '__main__':
    # When main returns the ui to go out of scope and be gc'd causing the view
    # to disappear with qt4.
    e, ui = main()
    # Create a GUI instance and start the event loop.  We do this here so that
    # main can be run from IPython -wthread if needed.
    gui = GUI()
    gui.start_event_loop()
Пример #18
0
def main():
    try:
        from enthought.etsconfig.api import ETSConfig
        from enthought.pyface.api import GUI
    except:
        print >> sys.stderr, "did you install python-chaco?"
        print >> sys.stderr, "maybe you did install chaco>=4, then you will need to install the package etsproxy"
        print >> sys.stderr, "sudo easy_install etsproxy"
        raise

    # select the toolkit we want to use
    # WX is more stable for now
    #ETSConfig.toolkit = 'qt4'
    ETSConfig.toolkit = 'wx'

    # workaround bad bg color in ubuntu, with Ambiance theme
    # wxgtk (or traitsGUI, I dont know) looks like using the menu's bgcolor
    # for all custom widgets bg colors. :-(

    if ETSConfig.toolkit == 'wx':
        import wx, os
        if "gtk2" in wx.PlatformInfo:
            from gtk import rc_parse, MenuBar
            m = MenuBar()
            if m.rc_get_style(
            ).bg[0].red_float < 0.5:  # only customize dark bg
                rc_parse(
                    os.path.join(os.path.dirname(__file__), "images/gtkrc"))
            m.destroy()

    # workaround bug in kiva's font manager that fails to find a correct default font on linux
    if os.name == "posix":
        import warnings

        def devnull(*args):
            pass

        warnings.showwarning = devnull
        from enthought.kiva.fonttools.font_manager import fontManager, FontProperties
        try:
            font = FontProperties()
            font.set_name("DejaVu Sans")
            fontManager.defaultFont = fontManager.findfont(font)
            fontManager.warnings = None
        except:  # this code will throw exception on ETS4, which has actually fixed fontmanager
            pass

    from window import open_file

    import optparse
    parser = optparse.OptionParser(usage="""\
%prog [options] [trace.txt|trace.txt.gz|trace.txt.lzma|trace.dat]

pytimechart - Fast graphical exploration and visualisation for linux kernel traces."""
                                   )
    parser.add_option("-p",
                      "--prof",
                      dest="prof",
                      action="store_true",
                      help="activate profiling",
                      default=False)
    (options, args) = parser.parse_args()

    # Create the GUI (this does NOT start the GUI event loop).
    gui = GUI()
    if len(args) == 0:
        args.append("dummy")
    for fn in args:
        if not open_file(fn):
            sys.exit(0)
    if options.prof:
        import cProfile
        dict = {"gui": gui}
        cProfile.runctx('gui.start_event_loop()', dict, dict, 'timechart.prof')
    else:
        gui.start_event_loop()
Пример #19
0
def show(func=None, stop=False):
    """ Start interacting with the figure.
    
    By default, this function simply creates a GUI and starts its
    event loop if needed.
    
    If it is used as a decorator, then it may be used to decorate a
    function which requires a UI.   If the GUI event loop is already
    running it simply runs the function.  If not the event loop is
    started and function is run in the toolkit's event loop.  The choice
    of UI is via `ETSConfig.toolkit`.  

    If the argument stop is set to True then it pops up a UI where the
    user can stop the event loop.  Subsequent calls to `show` will
    restart the event loop.

    **Parameters**

      :stop:  A boolean which specifies if a UI dialog is displayed which
              allows the event loop to be stopped.

    **Examples**

    Here is a simple example demonstrating the use of show::

      >>> from enthought.mayavi import mlab
      >>> mlab.test_contour3d()
      >>> mlab.show()

    You can stop interaction via a simple pop up UI like so::

      >>> mlab.test_contour3d()
      >>> mlab.show(stop=True)

    The decorator can be used like so::

      >>> @mlab.show
      ... def do():
      ...    mlab.test_contour3d()
      ...
      >>> do()
    
    The decorator can also be passed the stop argument::

      >>> @mlab.show(stop=True)
      ... def do():
      ...    mlab.test_contour3d()
      ...
      >>> do()

    """
    global _gui, _stop_show
    if func is None:
        if not is_ui_running():
            g = GUI()
            _gui = g
            if stop:
                _stop_show = StopShow()
            g.start_event_loop()
        return

    def wrapper(*args, **kw):
        """Wrapper function to run given function inside the GUI event
        loop.
        """
        global _gui, _stop_show
        tk = ETSConfig.toolkit

        if is_ui_running():
            # In this case we should not pop up the UI since we likely
            # don't want to stop the mainloop.
            return func(*args, **kw)
        else:
            g = GUI()
            if tk == 'wx':
                # Create a dummy app so invoke later works on wx.
                a = ApplicationWindow(size=(1, 1))
                GUI.invoke_later(lambda: a.close())
                a.open()

            GUI.invoke_later(func, *args, **kw)
            _gui = g
            if stop:
                # Pop up the UI to stop the mainloop.
                _stop_show = StopShow()
            g.start_event_loop()

    return wrapper