Ejemplo n.º 1
0
def start_qt_event_loop(qApp):
    """ Starts the eventloop if it's not yet running.

        If the IPython event loop is active (and set to Qt) this function does nothing. The IPython 
        event loop will process Qt events as well so the user can continue to use the command 
        prompt together with the ObjectBrower. Unfortunately this behaviour is broken again in
        IPython 5, so there we fall back on the non-interactive event loop.
    """
    if in_ipython():
        from IPython import version_info
        logger.debug("IPython detected. Version info: {}".format(version_info))
        if version_info[0] < 4:
            logger.debug("Event loop integration not supported for IPython < 4")
        elif version_info[0] == 5 and version_info[1] <= 1:
            # The is_event_loop_running_qt4 function is broken in IPython 5.0 and 5.1.
            # https://github.com/ipython/ipython/issues/9974
            logger.debug("Event loop integration does not work in IPython 5.0 and 5.1")
        else:
            try:
                from IPython.lib.guisupport import is_event_loop_running_qt4, start_event_loop_qt4
                if is_event_loop_running_qt4(qApp):
                    logger.info("IPython event loop already running. GUI integration possible.")
                else:
                    # No gui integration
                    logger.info("Starting (non-interactive) IPython event loop")
                    start_event_loop_qt4(qApp) # exit code always 0
                return
            except Exception as ex:
                logger.warning("Unable to start IPython Qt event loop: {}".format(ex))
                logger.warning("Falling back on non-interactive event loop: {}".format(ex))

    logger.info("Starting (non-interactive) event loop")
    return qApp.exec_()
Ejemplo n.º 2
0
def show(model):
    """Take an instance of tardis model and display it.

    If IPython functions were successfully imported then QApplication instance 
    is created using get_app_qt4. This will only create the app instance if 
    it doesn't already exists. Otherwise it is explicitly started. 

    Then the mainwindow is created, the model is attached to it and its 
    show method is called.

    Finally the eventloop is started using IPython functions (which start them
    consistently) if they were imported. Otherwise it is started explicitly. 

    """
    if importFailed:
        app = QtGui.QApplication([])
    else:
        app = get_app_qt4()

    tablemodel = SimpleTableModel
    win = Tardis(tablemodel)
    win.show_model(model)

    if importFailed:
        app.exec_()
    else:
        start_event_loop_qt4(app)

        #If the IPython console is being used, this will evaluate to true.
        #In that case the window created will be garbage collected unless a
        #reference to it is maintained after this function exits. So the win is
        #returned.
        if is_event_loop_running_qt4(app):
            return win
Ejemplo n.º 3
0
def show(model):
    """Take an instance of tardis model and display it.

    If IPython functions were successfully imported then QApplication instance 
    is created using get_app_qt4. This will only create the app instance if 
    it doesn't already exists. Otherwise it is explicitly started. 

    Then the mainwindow is created, the model is attached to it and its 
    show method is called.

    Finally the eventloop is started using IPython functions (which start them
    consistently) if they were imported. Otherwise it is started explicitly. 

    """
    if importFailed:
        app = QtGui.QApplication([])
    else:
        app = get_app_qt4()

    tablemodel = SimpleTableModel
    win = Tardis(tablemodel)
    win.show_model(model)

    if importFailed:
        app.exec_()
    else:
        start_event_loop_qt4(app)

        #If the IPython console is being used, this will evaluate to true.
        #In that case the window created will be garbage collected unless a 
        #reference to it is maintained after this function exits. So the win is
        #returned.
        if is_event_loop_running_qt4(app):
            return win
Ejemplo n.º 4
0
def start_event_loop():
    from IPython.lib.guisupport import start_event_loop_qt4, is_event_loop_running_qt4
    from pyface.qt import QtCore
    if not is_event_loop_running_qt4():
        print('qt4 event loop not running')
        print(
            'starting event loop via IPython.lib.guisupport.start_event_loop_qt4'
        )
        start_event_loop_qt4(QtCore.QCoreApplication.instance())
    else:
        print('running qt4 event loop detected')
Ejemplo n.º 5
0
def create (data=[], args=[], log=None):
    '''
    Starts a viewer instance.
    '''
    app = gui.get_app_qt4 (args)
    main_win = ViewerWindow()
    plot (data, win=main_win)
    main_win.show()
        
    if not gui.is_event_loop_running_qt4():
        app.exec_()
        
    return main_win
Ejemplo n.º 6
0
def start_qt_event_loop(qApp):
    """ Starts the eventloop if it's not yet running.

        If the IPython event loop is active (and set to Qt) this function does nothing. The IPython 
        event loop will process Qt events as well so the user can continue to use the command 
        prompt together with the ObjectBrower. Unfortunately this behaviour is broken again in
        IPython 5, so there we fall back on the non-interactive event loop.
    """
    if in_ipython():
        from IPython import version_info
        logger.debug("IPython detected. Version info: {}".format(version_info))
        if version_info[0] < 4:
            logger.debug(
                "Event loop integration not supported for IPython < 4")
        elif version_info[0] == 5 and version_info[1] <= 1:
            # The is_event_loop_running_qt4 function is broken in IPython 5.0 and 5.1.
            # https://github.com/ipython/ipython/issues/9974
            logger.debug(
                "Event loop integration does not work in IPython 5.0 and 5.1")
        else:
            try:
                from IPython.lib.guisupport import is_event_loop_running_qt4, start_event_loop_qt4
                if is_event_loop_running_qt4(qApp):
                    logger.info(
                        "IPython event loop already running. GUI integration possible."
                    )
                else:
                    # No gui integration
                    logger.info(
                        "Starting (non-interactive) IPython event loop")
                    start_event_loop_qt4(qApp)  # exit code always 0
                return
            except Exception as ex:
                logger.warning(
                    "Unable to start IPython Qt event loop: {}".format(ex))
                logger.warning(
                    "Falling back on non-interactive event loop: {}".format(
                        ex))

    logger.info("Starting (non-interactive) event loop")
    return qApp.exec_()
Ejemplo n.º 7
0
try:
    from IPython.lib import guisupport as gui
    from IPython.lib.inputhook import InputHookManager

    # create class managing hook for event loop in ipython
    hook = InputHookManager()

    # get the QApplication, creating one if not existing
    app = gui.get_app_qt4()

    # add the application to the hook
    hook.enable_qt4(app)

    # if event loop not running, run it for ipython
    if not gui.is_event_loop_running_qt4(app):
        gui.start_event_loop_qt4(app)

except:
    pass


class Figure(QGraphicsView):

    def __init__(self, *args, **kwargs):

        super(Figure, self).__init__(*args, **kwargs)

        # Creation of the Plotting class:
        # Then we add it as background of the View:
        self._context = QGLWidget(QGLFormat(QGL.NoAccumBuffer))
Ejemplo n.º 8
0
def create(path="~", args=[], log=None, shell=False):
    """
    Creates a paul-browser instance, returns the main window object.
    A "paul-browser" is a GUI window featuring a tree-view and a
    paul viewer window. Clicking on an item in the tree view will
    display it in the viewer window.
    Parameters:
      *path*: Starting point of the tree view, if specified
      *args*: Arguments to pass to the paul-browser. You can
              pass qt command line arguments, or a single
              file name, which, if it is an IBW, will be loaded
              and displayed.
      *shell*: If 'True', the paul-browser will feature an interactive
               IPython shell in the main terminal, which can be used
               for introspection and for control of main features
               of the paul-browser. Enjoy! ;-)
               Default is 'False', but the parameter will be set 
               explicitly 'True' when the browser is called as a
               stand-alone application.
    """
    app = gui.get_app_qt4(args)

    # find the first non-option argument
    if len(args) > 1:
        for a in args[1:]:
            if a[0] != "-":
                path = a
                break

    if log is not None:
        log.debug("Start path is '%s'" % path)

    main_win = BrowserWindow(path)
    main_win.show()

    if shell:
        # Start an interactive shell, this will be the name space
        # of the shell. Basically, everything needs to be accessed
        # through main_win (aliased 'P' in the shell :-) )

        import numpy as np
        import scipy as sp
        import matplotlib as mpl
        import paul.loader.igor as igor
        import paul.loader.elmitec as elmitec
        import paul.base.wave as wave
        import paul.base.wave as wave
        import paul.toolbox.arpes as arpes
        import paul.toolbox.arplot as arplot
        import paul.toolbox.atrix as atrix
        import paul.toolbox as tools
        import paul.shell as psh

        P = main_win
        ipshell = InteractiveShellEmbed.instance()
        IPython.lib.inputhook.enable_gui(gui="qt")
        ipshell()

    if not gui.is_event_loop_running_qt4():
        if log is not None:
            log.debug("Starting main event loop")
        app.exec_()
    else:
        if log is not None:
            log.debug("Event loop is already running")
    return main_win