Source code for imagect.core.mainwin
import imagect.api.mainwin
from imagect.api.mainwin import IMainWin
import imagect.api.actmgr
import imagect.core.actmgr
from imagect.api.actmgr import addAct, addActFun, addActWdg, renameAct
import imagect.api.app as app
from zope import interface
from PyQt5.QtWidgets import QMainWindow, QAction, QToolBar, QLabel, QSpinBox
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
#qtconsole
from qtconsole.rich_jupyter_widget import RichJupyterWidget
from qtconsole.inprocess import QtInProcessKernelManager
[docs]@interface.implementer(IMainWin)
class MainWin(QMainWindow) :
"""
implements IMainWin
"""
def __init__(self, parent=None, flags=Qt.WindowFlags()):
super().__init__(parent=parent, flags=flags)
self._jupyter_widget = make_jupyter_widget_with_kernel()
self.setCentralWidget(self._jupyter_widget)
app.get().aboutToQuit.connect(self.shutdown_kernel)
self.statusBar()
self.toolBarFile = QToolBar(self)
self.addToolBar(self.toolBarFile)
[docs] def window(self):
return self
[docs] def menuBar(self):
return super().menuBar()
[docs] def console(self) :
return self._jupyter_widget
[docs] def showMessage(self, msg) :
self.statusBar().showMessage(msg)
[docs] def shutdown_kernel(self):
self._jupyter_widget.kernel_client.stop_channels()
self._jupyter_widget.kernel_manager.shutdown_kernel()
from zope.component import getUtility
[docs]def get() :
return getUtility(IMainWin)
@addActFun("file.exit", text="&Exit", index=10)
def appexit():
app.get().exit()
@addActFun("file.exampe.msg", text="&Message", index=1)
def apptest():
win = get()
win.showMessage("Test Message")
@addActWdg("file.exampe.wdg", text="Show Widget", index = 3)
class ActWdg(QSpinBox) :
def __init__(self, parent):
super().__init__(parent)
@addActFun("file.exampe.print", text="Print Actions", index = 4)
def appPrint():
mngr = imagect.api.actmgr.get()
acts = mngr.queryAll()
for a in acts:
print("id={}, title={}".format(a.id, a.title))
renameAct("file.exampe", "Examples", index =12)