def stop(self): """Taken from ipython/examples/Embedding/inprocess_qtconsole.py. Ensure that both the kernel process and the main Python app that launched it are killed.""" # greatly slows down shutdown, doesn't seem necessary: #self.ipw.kernel_client.stop_channels() self.ipw.kernel_manager.shutdown_kernel(now=True) # now=True shuts down faster guisupport.get_app_qt4().exit()
def stop(self): """Taken from ipython/examples/Embedding/inprocess_qtconsole.py. Ensure that both the kernel process and the main Python app that launched it are killed.""" # greatly slows down shutdown, doesn't seem necessary: #self.ipw.kernel_client.stop_channels() self.ipw.kernel_manager.shutdown_kernel( now=True) # now=True shuts down faster guisupport.get_app_qt4().exit()
def closeEvent(self, event): """ Handle the close event by asking for confirmation """ result = QMessageBox.question(self, "Exit?", "Are you sure you want to exit ?", QMessageBox.Yes | QMessageBox.No) if result == QMessageBox.Yes: if self._main: self._qtconsole.kernel_client.stop_channels() self._qtconsole.kernel_manager.shutdown_kernel() guisupport.get_app_qt4().exit() event.accept() else: event.ignore()
def main(): """Start kernel manager and client, create window, run app event loop""" app = guisupport.get_app_qt4() if INPROCESS: from qtconsole.inprocess import QtInProcessKernelManager km = QtInProcessKernelManager() else: from qtconsole.manager import QtKernelManager km = QtKernelManager() km.start_kernel() km.kernel.gui = 'qt4' kc = km.client() kc.start_channels() widget = RichJupyterWidget() widget.kernel_manager = km widget.kernel_client = kc if CLEANSHUTDOWN: # slow exit on CTRL+D def stop(): kc.stop_channels() km.shutdown_kernel() app.exit() widget.exit_requested.connect(stop) else: # fast exit on CTRL+D widget.exit_requested.connect(app.quit) widget.show() guisupport.start_event_loop_qt4(app)
def main(): """Start kernel manager and client, create window, run app event loop, auto execute some code in user namespace. A minimalist example is shown in qt_ip_test.py. NOTE: Make sure that the Qt v2 API is being used by IPython by running `export QT_API=pyqt` at the command line before running neuropy, or by adding it to `.bashrc`""" app = guisupport.get_app_qt4() if INPROCESS: from qtconsole.inprocess import QtInProcessKernelManager km = QtInProcessKernelManager() else: from qtconsole.manager import QtKernelManager km = QtKernelManager() km.start_kernel() km.kernel.gui = 'qt4' kc = km.client() kc.start_channels() nw = NeuropyWindow() ipw = nw.ipw config_ipw(ipw) ipw.kernel_manager = km ipw.kernel_client = kc ipw.exit_requested.connect(nw.stop) nw.show() # execute some code through the frontend (once the event loop is running). # The output appears in the IPythonWidget (ipw). do_later(ipw.execute, 'run -i %s' % 'startup.py', hidden=True) do_later(ipw.execute, 'run -i %s' % 'globals.py', hidden=True) #guisupport.start_event_loop_qt4(app) # doesn't seem to work in IPy 5.3.0 app.exec_()
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
def main(): # Print the ID of the main process print_process_id() init_asyncio_patch() app = guisupport.get_app_qt4() # Create an in-process kernel # >>> print_process_id() # will print the same process ID as the main process kernel_manager = QtInProcessKernelManager() kernel_manager.start_kernel() kernel = kernel_manager.kernel kernel.gui = 'qt4' kernel.shell.push({'foo': 43, 'print_process_id': print_process_id}) kernel_client = kernel_manager.client() kernel_client.start_channels() def stop(): kernel_client.stop_channels() kernel_manager.shutdown_kernel() app.exit() control = RichIPythonWidget() control.kernel_manager = kernel_manager control.kernel_client = kernel_client control.exit_requested.connect(stop) control.show() guisupport.start_event_loop_qt4(app)
def main(): #LETS ALSO DO SOME IPYTHOPN PARRALLEL STUFF global splicer app = guisupport.get_app_qt4() from LZM100 import splicer # Create an in-process kernel # >>> print_process_id() # will print the same process ID as the main process kernel_manager = QtInProcessKernelManager() kernel_manager.start_kernel() kernel = kernel_manager.kernel kernel.gui = 'qt4' kernel.shell.push({'splicer': splicer}) kernel_client = kernel_manager.client() kernel_client.start_channels() def stop(): kernel_client.stop_channels() kernel_manager.shutdown_kernel() app.exit() control = RichIPythonWidget() control.kernel_manager = kernel_manager control.kernel_client = kernel_client control.exit_requested.connect(stop) control.show() #app = QtGui.QApplication(sys.argv) #ex = Example() b = TaperDesign(Taper()) sys.exit(app.exec_())
def main(): """Start kernel manager and client, create window, run app event loop""" app = guisupport.get_app_qt4() if INPROCESS: from IPython.qt.inprocess import QtInProcessKernelManager km = QtInProcessKernelManager() else: from IPython.qt.manager import QtKernelManager km = QtKernelManager() km.start_kernel() km.kernel.gui = 'qt4' kc = km.client() kc.start_channels() widget = RichIPythonWidget() widget.kernel_manager = km widget.kernel_client = kc if CLEANSHUTDOWN: # slow exit on CTRL+D def stop(): kc.stop_channels() km.shutdown_kernel() app.exit() widget.exit_requested.connect(stop) else: # fast exit on CTRL+D widget.exit_requested.connect(app.quit) widget.show() guisupport.start_event_loop_qt4(app)
def show_ipython_console(): # from https://github.com/ipython/ipython/blob/1.x/examples/inprocess/embedded_qtconsole.py # this might be able to be a dockable panel at some point in the future. # it should also only allow one window open at a time - I think it steals stdout at start # and opening a new window stops output working on the old one! app = guisupport.get_app_qt4() # Create an in-process kernel # >>> print_process_id() # will print the same process ID as the main process kernel_manager = QtInProcessKernelManager() kernel_manager.start_kernel() kernel = kernel_manager.kernel kernel.gui = 'qt4' kernel_client = kernel_manager.client() kernel_client.start_channels() def stop(): kernel_client.stop_channels() kernel_manager.shutdown_kernel() app.exit() control = RichIPythonWidget() control.kernel_manager = kernel_manager control.kernel_client = kernel_client control.exit_requested.connect(stop) control.show() guisupport.start_event_loop_qt4(app)
def main(): """Start kernel manager, create window, run app event loop, auto execute some code in user namespace. Adapted from IPython example in: docs/examples/frontend/inprocess_qtconsole.py""" app = guisupport.get_app_qt4() if INPROCESS: from IPython.kernel.inprocess.ipkernel import InProcessKernel from IPython.frontend.qt.inprocess_kernelmanager import QtInProcessKernelManager kernel = InProcessKernel(gui='qt4') km = QtInProcessKernelManager(kernel=kernel) kernel.frontends.append(km) else: from IPython.frontend.qt.kernelmanager import QtKernelManager km = QtKernelManager() km.start_kernel() km.start_channels() neuropywindow = NeuropyWindow() ipw = neuropywindow.ipw config_ipw(ipw) ipw.exit_requested.connect(app.quit) ipw.kernel_manager = km neuropywindow.show() # execute some code directly, note the output appears at the system command line: #kernel.shell.run_cell('print "x=%r, y=%r, z=%r" % (x,y,z)') # execute some code through the frontend (once the event loop is # running). The output appears in the ipw: do_later(ipw.execute_file, 'startup.py', hidden=True) # import division in startup.py doesn't seem to work, execute directly: do_later(ipw.execute, "from __future__ import division", hidden=True) do_later(ipw.execute_file, 'globals.py', hidden=True) guisupport.start_event_loop_qt4(app)
def main(): # Print the ID of the main process print_process_id() app = guisupport.get_app_qt4() # Create an in-process kernel # >>> print_process_id() # will print the same process ID as the main process kernel_manager = QtAsyncInProcessKernelManager() kernel_manager.start_kernel() kernel = kernel_manager.kernel kernel.gui = 'qt4' kernel.shell.push({'foo': 43, 'print_process_id': print_process_id}) kernel_client = kernel_manager.client() kernel_client.start_channels() def stop(): kernel_client.stop_channels() kernel_manager.shutdown_kernel() app.exit() control = RichIPythonWidget() control.kernel_manager = kernel_manager control.kernel_client = kernel_client control.exit_requested.connect(stop) control.show() guisupport.start_event_loop_qt4(app)
def create_window(window_class, **kwargs): """Create a QT window in Python, or interactively in IPython with QT GUI event loop integration. """ global app app = get_app_qt4(sys.argv) app.references = set() net = None fname = None if len(sys.argv) > 1: fname = sys.argv[1] if os.path.exists(fname): net = read_pickle(fname) else: QMessageBox.critical( None, "Error opening file %s", fname, QMessageBox.Ok, QMessageBox.NoButton) window = window_class(net, fname) app.references.add(window) window.show() start_event_loop_qt4(app) return window
def create_window(window_class, **kwargs): """Create a QT window in Python, or interactively in IPython with QT GUI event loop integration. """ global app app = get_app_qt4(sys.argv) app.references = set() net = None fname = None if len(sys.argv) > 1: fname = sys.argv[1] if os.path.exists(fname): net = read_pickle(fname) else: QMessageBox.critical(None, "Error opening file %s", fname, QMessageBox.Ok, QMessageBox.NoButton) window = window_class(net, fname) app.references.add(window) window.show() start_event_loop_qt4(app) return window
def run(): # app = QtGui.QApplication.instance() # checks if QApplication already exists # if not app: # create QApplication if it doesnt exist # app = QtGui.QApplication(sys.argv) app = guisupport.get_app_qt4() global browser # otherwise window appears and immediately disappears browser = PlotBrowser() browser.show() guisupport.start_event_loop_qt4(app)
def init_gui(self): """Initialize the GUI.""" self.app = guisupport.get_app_qt4() self.window = MainWindow(self.app, self.tree, confirm_exit=self.confirm_exit, config=self.config) self.window.log = self.log global _mainwindow _mainwindow = self.window
def __init__(self, parent=None, **kwargs): super(self.__class__, self).__init__(parent) self.app = app = guisupport.get_app_qt4() self.kernel_manager = kernel_manager = QtInProcessKernelManager() kernel_manager.start_kernel() self.kernel = kernel = kernel_manager.kernel kernel.gui = 'qt4' self.kernel_client = kernel_client = kernel_manager.client() kernel_client.start_channels()
def __init__(self, parent=None, **kwargs): super(self.__class__, self).__init__(parent) self.app = app = guisupport.get_app_qt4() self.kernel_manager = QtKernelManager() self.kernel_manager.start_kernel() self.kernel_manager.kernel.gui = 'qt4' self.kernel_client=self.kernel_manager.client() self.kernel_client.start_channels() self.confirm_restart=False
def __init__(self, parent=None, **kwargs): super(self.__class__, self).__init__(parent) self.app = app = guisupport.get_app_qt4() self.kernel_manager = QtKernelManager() self.kernel_manager.start_kernel() self.kernel_manager.kernel.gui = 'qt4' self.kernel_client = self.kernel_manager.client() self.kernel_client.start_channels() self.confirm_restart = False
def __init__(self, **kwarg): super(RichIPythonWidget, self).__init__() self.app = app = guisupport.get_app_qt4() self.kernel_manager = QtInProcessKernelManager() self.kernel_manager.start_kernel() self.kernel = self.kernel_manager.kernel self.kernel.gui = 'qt4' self.kernel.shell.push(kwarg) self.kernel_client = self.kernel_manager.client() self.kernel_client.start_channels()
def loop_qt4(kernel): """Start a kernel with PyQt4 event loop integration.""" from IPython.lib.guisupport import get_app_qt4 kernel.app = get_app_qt4([" "]) kernel.app.setQuitOnLastWindowClosed(False) _notify_stream_qt(kernel, kernel.shell_stream) _loop_qt(kernel.app)
def init_gui(self): """Initialize the GUI.""" self.app = guisupport.get_app_qt4() self.window = MainWindow(self.app, self.tree, config=self.config) self.window.log = self.log global _mainwindow _mainwindow = self.window self.app.icon = QtGui.QIcon( pkg_resources.resource_filename('nexpy.gui', 'resources/icon/NeXpy.svg')) QtGui.QApplication.setWindowIcon(self.app.icon)
def loop_qt4(kernel): """Start a kernel with PyQt4 event loop integration.""" from IPython.lib.guisupport import get_app_qt4 from IPython.external.qt_for_kernel import QtGui kernel.app = get_app_qt4([" "]) if isinstance(kernel.app, QtGui.QApplication): kernel.app.setQuitOnLastWindowClosed(False) _notify_stream_qt(kernel, kernel.shell_stream) _loop_qt(kernel.app)
def loop_qt4(kernel): """Start a kernel with PyQt4 event loop integration.""" from IPython.lib.guisupport import get_app_qt4, start_event_loop_qt4 kernel.app = get_app_qt4([" "]) kernel.app.setQuitOnLastWindowClosed(False) for s in kernel.shell_streams: _notify_stream_qt(kernel, s) start_event_loop_qt4(kernel.app)
def loop_qt4(kernel): """Start a kernel with PyQt4 event loop integration.""" from IPython.external.qt_for_kernel import QtCore from IPython.lib.guisupport import get_app_qt4, start_event_loop_qt4 kernel.app = get_app_qt4([" "]) kernel.app.setQuitOnLastWindowClosed(False) kernel.timer = QtCore.QTimer() kernel.timer.timeout.connect(kernel.do_one_iteration) # Units for the timer are in milliseconds kernel.timer.start(1000*kernel._poll_interval) start_event_loop_qt4(kernel.app)
def start(self): """Start a kernel with QtPy4 event loop integration.""" from PyQt4 import QtCore from IPython.lib.guisupport import get_app_qt4, start_event_loop_qt4 self.app = get_app_qt4([" "]) self.app.setQuitOnLastWindowClosed(False) self.timer = QtCore.QTimer() self.timer.timeout.connect(self.do_one_iteration) # Units for the timer are in milliseconds self.timer.start(1000*self._poll_interval) start_event_loop_qt4(self.app)
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
def loop_qt4(kernel): """Start a kernel with PyQt4 event loop integration.""" from IPython.external.qt_for_kernel import QtCore from IPython.lib.guisupport import get_app_qt4, start_event_loop_qt4 kernel.app = get_app_qt4([" "]) kernel.app.setQuitOnLastWindowClosed(False) kernel.timer = QtCore.QTimer() kernel.timer.timeout.connect(kernel.do_one_iteration) # Units for the timer are in milliseconds kernel.timer.start(1000 * kernel._poll_interval) start_event_loop_qt4(kernel.app)
def start(self): """Start a kernel with QtPy4 event loop integration.""" from PyQt4 import QtCore from IPython.lib.guisupport import get_app_qt4, start_event_loop_qt4 self.app = get_app_qt4([" "]) self.app.setQuitOnLastWindowClosed(False) self.timer = QtCore.QTimer() self.timer.timeout.connect(self.do_one_iteration) # Units for the timer are in milliseconds self.timer.start(1000 * self._poll_interval) start_event_loop_qt4(self.app)
def loop_qt4(kernel): """Start a kernel with PyQt4 event loop integration.""" from IPython.lib.guisupport import get_app_qt4 kernel.app = get_app_qt4([" "]) kernel.app.setQuitOnLastWindowClosed(False) # Only register the eventloop for the shell stream because doing # it for the control stream is generating a bunch of unnecessary # warnings on Windows. _notify_stream_qt(kernel, kernel.shell_streams[0]) _loop_qt(kernel.app)
def execute(args): app = guisupport.get_app_qt4(sys.argv) app.setApplicationName('HEXRD') # configure logging if args.debug: log_level = logging.DEBUG add_handler(log_level) else: log_level = logging.CRITICAL if args.quiet else logging.INFO ctlr = MainController(log_level, args.config) guisupport.start_event_loop_qt4(app)
def main(): """Create a QT window in Python, or interactively in IPython with QT GUI event loop integration. """ print_process_id() app = guisupport.get_app_qt4() app.references = set() window = GUI() app.references.add(window) window.show() guisupport.start_event_loop_qt4(app)
def init_gui(self): """Initialize the GUI.""" self.app = guisupport.get_app_qt4() self.window = MainWindow(self.app, self.tree, config=self.config) self.window.log = self.log global _mainwindow _mainwindow = self.window if 'svg' in QtGui.QImageReader.supportedImageFormats(): self.app.icon = QtGui.QIcon( pkg_resources.resource_filename('nexpy.gui', 'resources/icon/NeXpy.svg')) else: self.app.icon = QtGui.QIcon( pkg_resources.resource_filename('nexpy.gui', 'resources/icon/NeXpy.png')) QtGui.QApplication.setWindowIcon(self.app.icon)
def main(): # Print the ID of the main process print_process_id() app = guisupport.get_app_qt4() control = terminal_widget(testing=123) def stop(): control.kernel_client.stop_channels() control.kernel_manager.shutdown_kernel() app.exit() control.exit_requested.connect(stop) control.show() guisupport.start_event_loop_qt4(app)
def initialize(self): kernel_manager = QtInProcessKernelManager() kernel_manager.start_kernel() kernel = kernel_manager.kernel kernel.gui = 'qt4' kernel_client = kernel_manager.client() kernel_client.start_channels() app = guisupport.get_app_qt4() def stop(): kernel_client.stop_channels() kernel_manager.shutdown_kernel() app.exit() self.kernel = kernel self.kernel_manager = kernel_manager self.kernel_client = kernel_client self.exit_requested.connect(stop)
def initialize(self): kernel_manager = QtInProcessKernelManager() kernel_manager.start_kernel() kernel = kernel_manager.kernel kernel.gui = "qt4" kernel_client = kernel_manager.client() kernel_client.start_channels() app = guisupport.get_app_qt4() def stop(): kernel_client.stop_channels() kernel_manager.shutdown_kernel() app.exit() self.kernel = kernel self.kernel_manager = kernel_manager self.kernel_client = kernel_client self.exit_requested.connect(stop)
def __init__(self, parent=None, run='', **kwargs): super(self.__class__, self).__init__() self.app = app = guisupport.get_app_qt4() self.kernel_manager = kernel_manager = QtInProcessKernelManager() try: kernel_manager.start_kernel() except: return self.kernel_manager.kernel._abort_queues = self._abort_queues #"monkey patch" self.kernel = kernel = kernel_manager.kernel kernel.gui = 'qt' kernel.shell.push(kwargs) self.kernel_client = kernel_client = kernel_manager.client() kernel_client.start_channels() def stop(): self.hide() return kernel.shell.run_cell(run) self.exit_requested.connect(stop)
def __init__(self, parent=None, run='', **kwargs): super(self.__class__, self).__init__() self.app = app = guisupport.get_app_qt4() self.kernel_manager = kernel_manager = QtInProcessKernelManager() try: kernel_manager.start_kernel() except: return self.kernel = kernel = kernel_manager.kernel kernel.gui = 'qt4' kernel.shell.push(kwargs) self.kernel_client = kernel_client = kernel_manager.client() kernel_client.start_channels() def stop(): self.hide() return kernel.shell.run_cell(run) self.exit_requested.connect(stop)
def __init__(self, *args, **kwargs): super(ConsoleWidget, self).__init__(*args, **kwargs) # Create an in-process kernel app = guisupport.get_app_qt4() kernel_manager = QtInProcessKernelManager() kernel_manager.start_kernel() # Set the kernel data self.kernel = kernel_manager.kernel self.kernel.gui = 'qt4' kernel_client = kernel_manager.client() kernel_client.start_channels() def stop(): kernel_client.stop_channels() kernel_manager.shutdown_kernel() app.exit() self.kernel_manager = kernel_manager self.kernel_client = kernel_client self.exit_requested.connect(stop)
def __init__(self, *args, **kwargs): super(ConsoleWidget, self).__init__(*args, **kwargs) # Create an in-process kernel app = guisupport.get_app_qt4() kernel_manager = QtInProcessKernelManager() kernel_manager.start_kernel() # Set the kernel data self.kernel = kernel_manager.kernel self.kernel.gui = 'qt' kernel_client = kernel_manager.client() kernel_client.start_channels() def stop(): kernel_client.stop_channels() kernel_manager.shutdown_kernel() app.exit() self.kernel_manager = kernel_manager self.kernel_client = kernel_client self.exit_requested.connect(stop)
def main(): """Start kernel manager and client, create window, run app event loop, auto execute some code in user namespace. A minimalist example is shown in qt_ip_test.py. This is gleaned from ipython.examples.inprocess.embedded_qtconsole and ipython.IPython.qt.console.qtconsoleapp.new_frontend_master()""" app = guisupport.get_app_qt4() if INPROCESS: from IPython.qt.inprocess import QtInProcessKernelManager km = QtInProcessKernelManager() else: from IPython.qt.manager import QtKernelManager km = QtKernelManager() km.start_kernel() km.kernel.gui = 'qt4' kc = km.client() kc.start_channels() neuropywindow = NeuropyWindow() ipw = neuropywindow.ipw config_ipw(ipw) ipw.exit_requested.connect(app.quit) ipw.kernel_manager = km ipw.kernel_client = kc neuropywindow.show() # execute some code directly, note the output appears at the system command line: #kernel.shell.run_cell('print "x=%r, y=%r, z=%r" % (x,y,z)') # execute some code through the frontend (once the event loop is running). # The output appears in the ipw. __future__ import in startup.py doesn't seem to work, # execute directly: do_later(ipw.execute, "from __future__ import division", hidden=True) do_later(ipw.execute, "from __future__ import print_function", hidden=True) do_later(ipw.execute_file, 'startup.py', hidden=True) do_later(ipw.execute_file, 'globals.py', hidden=True) guisupport.start_event_loop_qt4(app)
def main(): app = guisupport.get_app_qt4() # Create a kernel. # # Setting the GUI is not necessary for the normal operation of the kernel, # but it is used for IPython GUI's integration, particularly in pylab. By # default, the inline backend is used, which is safe under all toolkits. # # WARNING: Under no circumstances should another GUI toolkit, like wx, be # used when running a Qt application. This will lead to unexpected behavior, # including segfaults. kernel = InProcessKernel(gui='qt4') # Populate the kernel's namespace. kernel.shell.push({'x': 0, 'y': 1, 'z': 2}) # Create a kernel manager for the frontend and register it with the kernel. km = QtInProcessKernelManager(kernel=kernel) km.start_channels() kernel.frontends.append(km) # Create the Qt console frontend. control = RichIPythonWidget() control.exit_requested.connect(app.quit) control.kernel_manager = km control.show() # Execute some code directly. Note where the output appears. kernel.shell.run_cell('print "x=%r, y=%r, z=%r" % (x,y,z)') # Execute some code through the frontend (once the event loop is # running). Again, note where the output appears. do_later(control.execute, '%who') guisupport.start_event_loop_qt4(app)
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
def stop(): """Stop the kernel.""" self.kernel_client.stop_channels() self.kernel_manager.shutdown_kernel() guisupport.get_app_qt4().exit()
from amoco.ui.render import Formats,conf from amoco.logger import Log logger = Log(__name__) logger.debug("loading module") #from . import rc_icons try: # integrate Qt mainloop into IPython console: # (the name qt4 here is a relic of the API but what happens # really is not restricted to Qt4...) from IPython.lib.guisupport import get_app_qt4, start_event_loop_qt4 app = get_app_qt4() start_event_loop_qt4(app) except ImportError: app = QApplication.instance() or QApplication([]) app.setApplicationName("amoco-qt") # set default styleSheet: current_path = path.abspath(path.dirname(__file__)) filename = path.join(current_path, 'style.qss') filename = conf.UI.qstylesheet or filename if filename.startswith(":"): if filename[1:]=="qdarkstyle": try: import qdarkstyle app.setStyleSheet(qdarkstyle.load_stylesheet(qt_api='pyside2')) except:
'y': { 'z': 3, 'y': 9 } } # nested items my_namespace.c = { 'y': EmptyClass(), 5: 'q', (4, 5): 't' } # different keys for dict my_namespace.c['y'].z = [1, 2, 3] my_namespace.c['y'].y = 4 my_namespace.c['y'].x = my_namespace.c # circular reference my_namespace.d = np.matrix(b'[11,12,13;14,15,16;17,18,19]') my_namespace.e = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) my_namespace.s = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e']) my_namespace.df = pd.DataFrame({ 'one': my_namespace.s, 'two': my_namespace.s }) my_namespace.n = 8 my_namespace.o = bytearray(b'hello') app = guisupport.get_app_qt4() # app = QtGui.QApplication(sys.argv) form = ObjectExplorer() form.show() guisupport.start_event_loop_qt4( app) # doesn't block terminal when run in ipython # app.exec_()
def console(client, args): local = { 'client': client, 'auth': client.auth, 'reset': client.reset, 'config': client.config, 'execute': client.execute, } if args['scriptName']: ############################################################# # EXECUTE FILE # ############################################################# sys.argv = [] sys.argv.append(args['scriptName']) sys.argv.extend(args['scriptArgs']) try: f = open(sys.argv[0]) source_code = f.read() f.close() except IOError as e: raise pyAMI.exception.Error(e) compiled_code = compile(source_code, sys.argv[0], 'exec') safe_exec(compiled_code, globals(), local) ############################################################# else: ############################################################# # RUN CONSOLE # ############################################################# sys.argv = [sys.argv[0]] ############################################################# banner = pyAMI.config.banner if args['nosplash'] == False else '' ############################################################# if args['gIPython']: ##################################################### # IPYTHON GRAPHICAL MODE # ##################################################### try: from IPython.qt.console.rich_ipython_widget import RichIPythonWidget from IPython.qt.inprocess import QtInProcessKernelManager from IPython.lib import guisupport except ImportError as e: raise pyAMI.exception.Error('module `IPython` not properly installed: %s' % e) ################################ # HACK IPYTHON BANNER # ################################ RichIPythonWidget._banner_default = lambda self: banner ################################ # KERNEL_MANAGER # ################################ kernel_manager = QtInProcessKernelManager() kernel_manager.start_kernel() ################################ # KERNEL_CLIENT # ################################ kernel_client = kernel_manager.client() kernel_client.start_channels() ################################ # PYAMI # ################################ kernel_manager.kernel.shell.push(local) ################################ # APPLICATION # ################################ a = guisupport.get_app_qt4() def stop(): kernel_client.stop_channels() kernel_manager.shutdown_kernel() a.exit() control = RichIPythonWidget() control.kernel_manager = kernel_manager control.kernel_client = kernel_client control.exit_requested.connect(stop) control.show() guisupport.start_event_loop_qt4(a) ##################################################### elif args['cIPython']: ##################################################### # IPYTHON CONSOLE MODE # ##################################################### try: from IPython.terminal.embed import InteractiveShellEmbed except ImportError as e: raise pyAMI.exception.Error('module `IPython` not properly installed: %s' % e) ################################ # SHELL # ################################ shell = InteractiveShellEmbed(banner1 = banner, banner2 = None) shell(local_ns = local) ##################################################### else: ##################################################### # DEFAULT MODE # ##################################################### code.interact(banner = banner, local = local) ##################################################### return 0
def stop(): kernel_client.stop_channels() kernel_manager.shutdown_kernel() guisupport.get_app_qt4().exit()
from PyQt4.QtGui import QGraphicsItem from OpenGL.arrays import numpymodule from .OGLWidget import OGLWidget numpymodule.NumpyHandler.ERROR_ON_COPY = True 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):