From 9b215a0d3a4eab557143e784a1019449aacc65d4 Mon Sep 17 00:00:00 2001 From: elisa-k Date: Wed, 14 Oct 2020 16:26:14 +0200 Subject: [PATCH] Correct __main__.py --- __main__.py | 66 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/__main__.py b/__main__.py index 3969552..4de0d97 100644 --- a/__main__.py +++ b/__main__.py @@ -18,36 +18,64 @@ You should have received a copy of the GNU General Public License along with this program, see COPYING. If not, see . """ +import logging +import logging.handlers +import traceback import os +from io import StringIO +from typing import List from PyQt5 import QtCore, QtWidgets, QtGui from .sampleview import SampleView -from .scalebar import ScaleBar -from .ramancom.ramancontrol import defaultPath -from .ramancom.ramanSwitch import RamanSwitch -from .analysis.colorlegend import ColorLegend +from .gui.scalebar import ScaleBar +from .instrumentcom.instrumentConfig import defaultPath +from .instrumentcom.lightModeSwitch import LightModeSwitch +from .gui.colorlegend import ColorLegend +from .gepardlogging import setDefaultLoggingConfig +from .workmodes import ModeHandler +from .unittests.test_gepard import testGepard +from .helperfunctions import getAppFolder from gepard import __version__ - + + +def excepthook(excType, excValue, tracebackobj): + """ + Global function to catch unhandled exceptions. + + @param excType exception type + @param excValue exception value + @param tracebackobj traceback object + :return: + """ + tbinfofile = StringIO() + traceback.print_tb(tracebackobj, None, tbinfofile) + tbinfofile.seek(0) + tbinfo = tbinfofile.read() + logging.critical("Fatal error in program execution!") + logging.critical(tbinfo) + from .errors import showErrorMessageAsWidget + showErrorMessageAsWidget(tbinfo) + + class GEPARDMainWindow(QtWidgets.QMainWindow): - def __init__(self, logpath): + def __init__(self, logger): super(GEPARDMainWindow, self).__init__() self.setWindowTitle("GEPARD " + __version__) + self.fname: str = '' self.resize(900, 700) - - self.view = SampleView(logpath) - self.view.imparent = self - self.view.ScalingChanged.connect(self.scalingChanged) self.scalebar = ScaleBar(self) self.legend = ColorLegend(self) - self.ramanSwitch = RamanSwitch(self) + self.lightModeSwitch = LightModeSwitch(self) + self.view = SampleView(self, logger) + self.view.ScalingChanged.connect(self.scalingChanged) self.view.ScalingChanged.connect(self.scalebar.updateScale) mdiarea = QtWidgets.QMdiArea(self) mdiarea.addSubWindow(self.scalebar) mdiarea.addSubWindow(self.legend) - mdiarea.addSubWindow(self.ramanSwitch) + mdiarea.addSubWindow(self.lightModeSwitch) self.legend.hide() - self.ramanSwitch.hide() + self.lightModeSwitch.hide() subview = mdiarea.addSubWindow(self.view) subview.showMaximized() @@ -123,8 +151,16 @@ class GEPARDMainWindow(QtWidgets.QMainWindow): @QtCore.pyqtSlot() def about(self): - QtWidgets.QMessageBox.about(self, 'GEPARD', "Developed by Complex Fiber Structures GmbH " - "on behalf of Leibniz-IPF Dresden") + devbranch = None + fname = os.path.join(os.path.split(__file__)[0], + os.path.join('.git', 'HEAD')) + if os.path.exists(fname): + with open(fname, 'r') as fp: + cont = fp.read() + devbranch = cont.rsplit('/', maxsplit=1)[1] + QtWidgets.QMessageBox.about(self, 'GEPARD', + 'Gepard-Enabled PARticle Detection for Raman and FTIR microscopes. \nVersion:' + \ + __version__ + '' if devbranch is None else ('\nDevelopment branch: ' + devbranch)) def getParticleRelevantActs(self) -> List[QtWidgets.QAction]: return [self.noOverlayAct, self.selOverlayAct, self.fullOverlayAct, self.hideLabelAct, self.transpAct, self.darkenAct, self.seedAct] -- GitLab