#/*##########################################################################
# Copyright (C) 2004-2014 V.A. Sole, European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software group.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#############################################################################*/
__author__ = "V.A. Sole - ESRF Data Analysis"
__contact__ = "sole@esrf.fr"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
import sys, getopt, string
from PyMca5.PyMcaGui import PyMcaQt as qt
if hasattr(qt, "QString"):
QString = qt.QString
else:
QString = str
QTVERSION = qt.qVersion()
from PyMca5.PyMcaGui import PyMca_Icons
IconDict = PyMca_Icons.IconDict
from .PyMca_help import HelpDict
DEBUG = 0
__version__ = "1.5"
[docs]class PyMcaMdi(qt.QMainWindow):
def __init__(self, parent=None, name="PyMca Mdi", fl=None, options={}):
qt.QMainWindow.__init__(self, parent)
self.setWindowTitle(name)
if fl is None:
fl = qt.Qt.WA_DeleteOnClose
self.options= {}
self.options["FileToolBar"]= options.get("FileToolBar", 1)
self.options["WinToolBar"] = options.get("WinToolBar", 1)
self.options["MenuFile"] = options.get("MenuFile", 1)
self.options["MenuTools"] = options.get("MenuTools", 1)
self.options["MenuWindow"] = options.get("MenuWindow", 1)
self.options["MenuHelp"] = options.get("MenuHelp", 1)
self.splitter = qt.QSplitter(self)
self.splitter.setOrientation(qt.Qt.Horizontal)
#self.splitterLayout = qt.QVBoxLayout(self.splitter)
#self.splitterLayout.setContentsMargins(0, 0, 0, 0)
#self.splitterLayout.setSpacing(0)
self.printer= qt.QPrinter()
if QTVERSION > '5.0.0':
self.mdi = qt.QMdiArea(self.splitter)
else:
self.mdi = qt.QWorkspace(self.splitter)
self.mdi.setScrollBarsEnabled(1)
#if QTVERSION > '4.0.0':self.mdi.setBackground(qt.QBrush(qt.QColor(238,234,238)))
#self.setCentralWidget(self.mdi)
#self.splitterLayout.addWidget(self.mdi)
self.setCentralWidget(self.splitter)
self.splitter.insertWidget(1, self.mdi)
self.windowMapper = qt.QSignalMapper(self)
if QTVERSION > '5.0.0':
self.windowMapper.mapped[qt.QWidget].connect(self.mdi.setActiveSubWindow)
else:
self.windowMapper.mapped[qt.QWidget].connect(self.mdi.setActiveWindow)
#self.setDockEnabled(qt.Qt.DockTop, 0)
self.initIcons()
if QTVERSION > '4.0.0':
self.createActions()
self.initMenuBar()
self.initToolBar()
self.followActiveWindow= 0
self.mdi.show()
#self.resize(600,400)
[docs] def createActions(self):
#fileopen
self.actionOpen = qt.QAction(self)
self.actionOpen.setText(QString("&Open"))
self.actionOpen.setIcon(self.Icons["fileopen"])
self.actionOpen.setShortcut(qt.Qt.CTRL+qt.Qt.Key_O)
self.actionOpen.triggered[bool].connect(self.onOpen)
#filesaveas
self.actionSaveAs = qt.QAction(self)
self.actionSaveAs.setText(QString("&Save"))
self.actionSaveAs.setIcon(self.Icons["filesave"])
self.actionSaveAs.setShortcut(qt.Qt.CTRL+qt.Qt.Key_S)
self.actionSaveAs.triggered[bool].connect(self.onSaveAs)
#filesave
self.actionSave = qt.QAction(self)
self.actionSave.setText(QString("Save &Defaults"))
#self.actionSave.setIcon(self.Icons["filesave"])
#self.actionSave.setShortcut(qt.Qt.CTRL+qt.Qt.Key_S)
self.actionSave.triggered[bool].connect(self.onSave)
#fileprint
self.actionPrint = qt.QAction(self)
self.actionPrint.setText(QString("&Print"))
self.actionPrint.setIcon(self.Icons["fileprint"])
self.actionPrint.setShortcut(qt.Qt.CTRL+qt.Qt.Key_P)
self.actionPrint.triggered[bool].connect(self.onPrint)
#filequit
self.actionQuit = qt.QAction(self)
self.actionQuit.setText(QString("&Quit"))
#self.actionQuit.setIcon(self.Icons["fileprint"])
self.actionQuit.setShortcut(qt.Qt.CTRL+qt.Qt.Key_Q)
qApp = qt.QApplication.instance()
self.actionQuit.triggered[bool].connect(qApp.closeAllWindows)
[docs] def initIcons(self):
self.Icons= {}
for (name, icon) in IconDict.items():
pixmap= qt.QPixmap(icon)
self.Icons[name]= qt.QIcon(pixmap)
#
# Mdi windows geometry
#
[docs] def windowCascade(self):
if self.followActiveWindow: self.__disconnectFollow()
self.mdi.cascade()
for window in self.mdi.windowList():
window.resize(0.7*self.mdi.width(),0.7*self.mdi.height())
if self.followActiveWindow: self.__connectFollow()
[docs] def windowTile(self):
if self.followActiveWindow: self.__disconnectFollow()
self.mdi.tile()
if self.followActiveWindow: self.__connectFollow()
[docs] def windowHorizontal(self):
#if self.followActiveWindow: self.__disconnectFollow()
if not len(self.mdi.windowList()): return
windowheight=float(self.mdi.height())/len(self.mdi.windowList())
i=0
for window in self.mdi.windowList():
window.parentWidget().showNormal()
window.parentWidget().setGeometry(0, int(windowheight*i),
self.mdi.width(),int(windowheight))
if QTVERSION < '4.0.0':
window.parentWidget().raiseW()
else:
window.parentWidget().raise_()
i+=1
self.mdi.update()
self.update()
#if self.followActiveWindow: self.__connectFollow()
[docs] def windowVertical(self):
#if self.followActiveWindow: self.__disconnectFollow()
if not len(self.mdi.windowList()): return
windowwidth=float(self.mdi.width())/len(self.mdi.windowList())
i=0
for window in self.mdi.windowList():
window.parentWidget().showNormal()
window.parentWidget().setGeometry(int(windowwidth*i),0,
int(windowwidth),self.mdi.height())
if QTVERSION < '4.0.0':
window.parentWidget().raiseW()
else:
window.parentWidget().raise_()
i+=1
self.mdi.update()
self.update()
#if self.followActiveWindow: self.__connectFollow()
[docs] def windowFullScreen(self):
if len(self.mdi.windowList()):
self.mdi.activeWindow().showMaximized()
def __connectFollow(self):
self.mdi.windowActivated.connect(self.onWindowActivated)
def __disconnectFollow(self):
self.mdi.windowActivated.disconnect(self.onWindowActivated)
[docs] def setFollowActiveWindow(self, follow):
if follow != self.followActiveWindow:
if not follow:
self.__disconnectFollow()
else:
self.__connectFollow()
self.followActiveWindow= follow
[docs] def onWindowActivated(self, win):
print("Window activated")
pass
#
# Dock windows
#
[docs] def isCustomizable(self):
nb= 0
for win in self.dockWindows():
nb += isinstance(win, DockWindow)
return (nb>0)
[docs] def customize(self, *args):
dg= DockPlaceDialog(self, window=self, title="Tool Places")
dg.exec_loop()
#
# Menus customization
#
def onInitMenuBar(self, menubar):
pass
def onInitFileToolBar(self, toolbar):
pass
def onInitToolBar(self):
pass
def onInitWinToolBar(self, toolbar):
pass
#
# Menus customization
#
#
# Menus callback
#
[docs] def onAboutQt(self):
qt.QMessageBox.aboutQt(self, "About Qt")
[docs] def onAbout(self):
qt.QMessageBox.about(self, "MDI",
"MDI Application Framework\nVersion: "+__version__)
[docs] def onOpen(self):
qt.QMessageBox.about(self, "Open", "Not implemented")
[docs] def onSave(self):
qt.QMessageBox.about(self, "Save", "Not implemented")
[docs] def onSaveAs(self):
qt.QMessageBox.about(self, "SaveAs", "Not implemented")
[docs] def onPrint(self):
qt.QMessageBox.about(self, "Print", "Not implemented")
[docs]def main(args):
app = qt.QApplication(args)
#if sys.platform == 'win32':
if 1:
winpalette = qt.QPalette(qt.QColor(230,240,249),qt.QColor(238,234,238))
app.setPalette(winpalette)
options = ''
longoptions = ['spec=','shm=']
try:
opts, args = getopt.getopt(
sys.argv[1:],
options,
longoptions)
except getopt.error:
print(sys.exc_info()[1])
sys.exit(1)
# --- waiting widget
kw={}
for opt, arg in opts:
if opt in ('--spec'):
kw['spec'] = arg
elif opt in ('--shm'):
kw['shm'] = arg
#demo = McaWindow.McaWidget(**kw)
demo = PyMca()
app.lastWindowClosed.connect(app.quit())
demo.show()
app.exec_()
if __name__ == '__main__':
main(sys.argv)