def start_RepTate(argv): """ Main RepTate application. :param list argv: Command line parameters passed to Reptate """ GUI = True parser = argparse.ArgumentParser( description= "RepTate: Rheology of Entangled Polymers: Toolkit for the Analysis of Theory and Experiment.", epilog= "(c) Jorge Ramirez ([email protected], UPM), Victor Boudara (U. Leeds) (2017-2020)", ) parser.add_argument("-d", "--dpi", help="High DPI support on Windows", action="store_true") parser.add_argument("-l", "--tool", help="Open the tool L (if available)", default="", metavar="L") parser.add_argument( "-s", "--single", help="Run Reptate as a single thread application", action="store_true", ) parser.add_argument( "-t", "--theory", help="Open the theory T (if available)", default="", metavar="T", ) parser.add_argument("-v", "--verbose", help="Write debug information to stdout", action="store_true") parser.add_argument("-V", "--version", help="Print RepTate version and exit", action="store_true") parser.add_argument("finlist", nargs="*") args = parser.parse_args(args=argv) # Get files from command line dictfiles = get_argument_files(args.finlist) if args.version: print(QApplicationManager.intro) sys.exit() if args.verbose: loglevel = logging.DEBUG else: loglevel = logging.INFO QApplication.setStyle("Fusion") # comment that line for a native look # for a list of available styles: "from PyQt5.QtWidgets import QStyleFactory; print(QStyleFactory.keys())" if args.dpi or sys.platform == "darwin": os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1" QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) app = QApplication(sys.argv) app.setApplicationName("RepTate") if args.dpi and sys.platform == "win32": #os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1" import matplotlib #matplotlib.pyplot.matplotlib.rcParams['figure.dpi'] = int (np.round(app.desktop().physicalDpiX()/10)) matplotlib.pyplot.matplotlib.rcParams['figure.dpi'] = 34 #matplotlib.pyplot.matplotlib.rcParams['figure.dpi'] = app.desktop().physicalDpiX()/4 splash = SplashScreen() splash.show() ex = QApplicationManager(loglevel=loglevel) ex.setStyleSheet("QTabBar::tab { color:black; height: 22px; }") # splash.showMessage("Loading RepTate...") splash.finish(ex) # Handle files & open apps accordingly CmdBase.calcmode = ( CalcMode.singlethread ) # avoid troubles when loading multiple apps/files/theories d = { ex.extension: ex.appname for ex in list(ex.available_applications.values()) } toolopen = False for k in dictfiles.keys(): if k == "rept": ex.open_project(dictfiles[k][0]) elif np.any([k == key for key in d.keys()]): # exact match ex.handle_new_app(d[k]) appname = "%s%d" % (d[k], ex.application_counter) ex.applications[appname].new_tables_from_files(dictfiles[k]) if args.theory in list(ex.applications[appname].theories.keys()): ex.applications[appname].datasets["Set1"].new_theory( args.theory) if args.tool in ( list(ex.applications[appname].availabletools.keys()) + list(ex.applications[appname].extratools.keys())): ex.applications[appname].new_tool(args.tool) ex.applications[appname].update_all_ds_plots() ex.applications[appname].showDataInspector(True) toolopen = True elif np.any([k in key for key in d.keys()]): # works with spaces in extensions for key in d.keys(): if k in key: ex.handle_new_app(d[key]) appname = "%s%d" % (d[key], ex.application_counter) ex.applications[appname].new_tables_from_files( dictfiles[k]) if args.theory in list( ex.applications[appname].theories.keys()): ex.applications[appname].datasets["Set1"].new_theory( args.theory) if args.tool in ( list( ex.applications[appname].availabletools.keys()) + list(ex.applications[appname].extratools.keys())): ex.applications[appname].new_tool(args.tool) ex.applications[appname].update_all_ds_plots() ex.applications[appname].showDataInspector(True) toolopen = True break else: print("File type %s cannot be opened" % k) # set the calmode back if args.single: CmdBase.calcmode = CalcMode.singlethread else: CmdBase.calcmode = CalcMode.multithread ex.showMaximized() sys.exit(app.exec_())
def start_RepTate(argv): """ Main RepTate application. :param list argv: Command line parameters passed to Reptate """ GUI = True parser = argparse.ArgumentParser( description= 'RepTate: Rheologhy of Entangled Polymers: Toolkit for the Analysis of Theory and Experiment.', epilog= '(c) Jorge Ramirez - [email protected] - UPM , Victor Boudara - U. Leeds (2018)' ) parser.add_argument('-d', '--dpi', help='High DPI support on Windows', action='store_true') parser.add_argument('-s', '--single', help='Run Reptate as a single thread application', action='store_true') parser.add_argument('-t', '--theory', help='Open the given theory (if available)', default='') parser.add_argument('-v', '--verbose', help='Write debug information to stdout', action='store_true') parser.add_argument('-V', '--version', help='Print RepTate version and exit', action='store_true') parser.add_argument('finlist', nargs='*') args = parser.parse_args(args=argv) # Get files from command line dictfiles = get_argument_files(args.finlist) if args.version: print(QApplicationManager.intro) sys.exit() if args.verbose: loglevel = logging.DEBUG else: loglevel = logging.INFO QApplication.setStyle("Fusion") #comment that line for a native look #for a list of available styles: "from PyQt5.QtWidgets import QStyleFactory; print(QStyleFactory.keys())" if args.dpi: os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1" QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) app = QApplication(sys.argv) #if args.dpi: # app.setAttribute(Qt.AA_EnableHighDpiScaling) splash = SplashScreen() # splash.showMessage("Loading RepTate...\n") splash.show() ex = QApplicationManager(loglevel=loglevel) ex.setStyleSheet("QTabBar::tab { color:black; height: 22px; }") # splash.showMessage("Loading RepTate...") splash.finish(ex) # Handle files & open apps accordingly CmdBase.calcmode = CalcMode.singlethread # avoid troubles when loading multiple apps/files/theories d = { ex.extension: ex.appname for ex in list(ex.available_applications.values()) } for k in dictfiles.keys(): if k == 'rept': ex.open_project(dictfiles[k][0]) elif np.any([k == key for key in d.keys()]): # exact match ex.handle_new_app(d[k]) appname = "%s%d" % (d[k], ex.application_counter) ex.applications[appname].new_tables_from_files(dictfiles[k]) if args.theory in list(ex.applications[appname].theories.keys()): ex.applications[appname].datasets['Set1'].new_theory( args.theory) elif np.any([k in key for key in d.keys()]): # works with spaces in extensions for key in d.keys(): if k in key: ex.handle_new_app(d[key]) appname = "%s%d" % (d[key], ex.application_counter) ex.applications[appname].new_tables_from_files( dictfiles[k]) if args.theory in list( ex.applications[appname].theories.keys()): ex.applications[appname].datasets['Set1'].new_theory( args.theory) break else: print("File type %s cannot be opened" % k) # set the calmode back if args.single: CmdBase.calcmode = CalcMode.singlethread else: CmdBase.calcmode = CalcMode.multithread def my_excepthook(type, value, tb): """Catch exceptions and print error message. Open email client to report bug to devlopers""" tb_msg = '' for e in traceback.format_tb(tb): tb_msg += str(e) tb_msg += "%s: %s\n" % (type.__name__, str(value)) #print(tb_msg) # JR: Not needed anymore l = logging.getLogger('RepTate') if CmdBase.mode == CmdMode.GUI: l.error(tb_msg.replace('\n', '<br>')) else: l.error(tb_msg) msg = 'Sorry, something went wrong:\n \"%s: %s\".\nTry to save your work and quit RepTate.\nDo you want to help RepTate developers by reporting this bug?' % ( type.__name__, str(value)) ans = QMessageBox.critical(ex, 'Critical Error', msg, QMessageBox.Yes | QMessageBox.No) if ans == QMessageBox.Yes: address = "*****@*****.**" subject = "Something went wrong" body = "%s\nIf you can, please describe below what you were doing with RepTate when the error happened (apps and theories or tools open if any) and send the message\nPlease, do NOT include confidential information\n%s\nError Traceback:\n %s" % ( "-" * 60, "-" * 60 + "\n" * 10 + "-" * 60, tb_msg) QDesktopServices.openUrl( QUrl( "mailto:?to=%s&subject=%s&body=%s" % (address, subject, body), QUrl.TolerantMode)) sys.excepthook = my_excepthook ex.showMaximized() sys.exit(app.exec_())