def __init__(self, parse_args=True): super().__init__() if system.darwin: Application._osx_init() self.app = QtWidgets.QApplication(sys.argv) self._reported_tracebacks = [] qcrash.get_system_information = system.get_system_infos qcrash.get_application_log = logger.get_application_log qcrash.install_backend( qcrash.backends.GithubBackend(QCRASH_GH_OWNER, QCRASH_GH_REPO), qcrash.backends.EmailBackend(QCRASH_EMAIL, 'OpenCobolIDE')) qcrash.set_qsettings(Settings()._settings) qcrash.install_except_hook(except_hook=self._report_exception) # if hasattr(sys, 'frozen') and sys.platform == 'win32': # sys.stdout = open(os.path.join(system.get_cache_directory(), # 'ocide_stdout.log'), 'w') # sys.stderr = open(os.path.join(system.get_cache_directory(), # 'ocide_stderr.log'), 'w') if parse_args and not system.darwin: files = self.handle_command_line_args() else: files = [] _logger().info('files to open: %r' % files) self.name = 'OpenCobolIDE' self.version = __version__ self.title = '%s %s' % (self.name, self.version) self.apply_mimetypes_preferences() self.win = MainWindow() self.win.setWindowTitle(self.title) self.file = FileController(self) self.view = ViewController(self) self.home = HomeController(self) self.edit = EditController(self) self.cobol = CobolController(self) self.help = HelpController(self) self.win.app = self self.view.show_perspective(Settings().perspective) self.update_app_style() try: check_compiler() except CompilerNotFound: msg = 'Failed to find a working GnuCOBOL compiler!\n' \ "The IDE will continue to work but you won't be able to " \ 'compile...' if system.windows: msg += '\n\nTip: Ensure that there is no additional ' \ 'installation of MinGW in %s:\MinGW' % sys.executable[0] QtWidgets.QMessageBox.warning( self.win, 'COBOL compiler not found or not working', msg) else: _logger().info('GnuCOBOL version: %s', GnuCobolCompiler.get_version(include_all=False)) self._files = files
def _setup_except_hook(self): qcrash.get_system_information = versions.get_system_infos qcrash.get_application_log = logger.get_application_log qcrash.install_backend( qcrash.backends.GithubBackend(QCRASH_GH_OWNER, QCRASH_GH_REPO), qcrash.backends.EmailBackend(QCRASH_EMAIL, 'HackEdit')) qcrash.set_qsettings(QtCore.QSettings()) qcrash.install_except_hook(except_hook=self._report_exception)
def setup_qcrash(): github = qcrash.backends.GithubBackend("tmontes", "qtcrashme") qcrash.install_backend(github) email = qcrash.backends.EmailBackend("*****@*****.**", "qtcrashme") qcrash.install_backend(email) qcrash.get_application_log = lambda: "line1\nline2\n" qcrash.get_system_information = lambda: "system information here" qcrash.install_except_hook()
def test_install_except_hook(): api.install_except_hook() assert isinstance(api._except_hook, QtExceptHook) assert sys.excepthook == api._except_hook._except_hook
def test_value_errors(): api._backends[:] = [] with pytest.raises(ValueError): api.install_except_hook() with pytest.raises(ValueError): api.show_report_dialog()
# create a window win = QtWidgets.QMainWindow() label = QtWidgets.QLabel() label.setText('Wait a few seconds for an unhandled exception to occur...') label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) win.setCentralWidget(label) win.showMaximized() # install our own except hook. def except_hook(exc, tb): res = QtWidgets.QMessageBox.question( win, "Unhandled exception", "An unhandled exception has occured. Do " "you want to report") if res == QtWidgets.QMessageBox.Yes: qcrash.show_report_dialog( window_title='Report unhandled exception', issue_title=str(exc), traceback=tb) qcrash.install_except_hook(except_hook=except_hook) # raise an unhandled exception in a few seconds def raise_unhandled_exception(): raise Exception('this is an unhandled exception') QtCore.QTimer.singleShot(2000, raise_unhandled_exception) # run qt app app.exec_()
label = QtGui.QLabel() label.setText('Wait a few seconds for an unhandled exception to occur...') label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) win.setCentralWidget(label) win.showMaximized() # install our own except hook. def except_hook(exc, tb): res = QtGui.QMessageBox.question( win, "Unhandled exception", "An unhandled exception has occured. Do " "you want to report") if res == QtGui.QMessageBox.Ok: qcrash.show_report_dialog(window_title='Report unhandled exception', issue_title=str(exc), traceback=tb) qcrash.install_except_hook(except_hook=except_hook) # raise an unhandled exception in a few seconds def raise_unhandled_exception(): raise Exception('this is an unhandled exception') QtCore.QTimer.singleShot(2000, raise_unhandled_exception) # run qt app app.exec_()
import Flux.ucd from Flux.project import FluxProject from Flux.editor import FluxEditor from PyQt5.QtWidgets import QApplication import qcrash.api as qcrash app = QApplication(sys.argv) app.setApplicationName("Flux") app.setOrganizationDomain("corvelsoftware.co.uk") # app.setOrganizationName("Corvel Software") email = qcrash.backends.EmailBackend('*****@*****.**', 'flux') github = qcrash.backends.GithubBackend('simoncozens', 'flux') qcrash.install_backend(github) qcrash.install_backend(email) qcrash.install_except_hook() proj = None if len(sys.argv) > 1: if sys.argv[1].endswith(".fluxml"): proj = FluxProject(sys.argv[1]) else: proj = FluxProject.new(sys.argv[1]) f = FluxEditor(proj) f.show() sys.exit(app.exec_())