From 8130bae4c00a698aecd07504f8b133199ae99427 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Mon, 13 Jul 2015 16:54:40 +0200 Subject: [PATCH 1/4] Add a crash handler to catch uncaught exceptions This should catch any uncaught exceptions and avoid the Py2Exe message about Cura.log Fixes #133 --- cura/CrashHandler.py | 41 +++++++++++++++++++++++++++++++++++++++++ cura_app.py | 11 ++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 cura/CrashHandler.py diff --git a/cura/CrashHandler.py b/cura/CrashHandler.py new file mode 100644 index 0000000000..1df1ab773e --- /dev/null +++ b/cura/CrashHandler.py @@ -0,0 +1,41 @@ +import sys +import platform +import traceback +import webbrowser + +from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR +from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QTextEdit + +def show(): + dialog = QDialog() + dialog.setWindowTitle("Oops!") + + layout = QVBoxLayout(dialog) + + label = QLabel(dialog) + layout.addWidget(label) + label.setText("

An uncaught exception has occurred!

Please use the information below to post a bug report at http://github.com/Ultimaker/Cura/issues

") + + textarea = QTextEdit(dialog) + layout.addWidget(textarea) + + try: + from UM.Application import Application + version = Application.getInstance().getVersion() + except: + version = "Unknown" + + trace = "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])) + + crash_info = "Version: {0}\nPlatform: {1}\nQt: {2}\nPyQt: {3}\n\nException:\n{4}" + crash_info = crash_info.format(version, platform.platform(), QT_VERSION_STR, PYQT_VERSION_STR, trace) + + textarea.setText(crash_info) + + buttons = QDialogButtonBox(QDialogButtonBox.Close, dialog) + layout.addWidget(buttons) + buttons.addButton("Open Web Page", QDialogButtonBox.HelpRole) + buttons.rejected.connect(lambda: dialog.close()) + buttons.helpRequested.connect(lambda: webbrowser.open("http://github.com/Ultimaker/Cura/issues")) + + dialog.exec_() diff --git a/cura_app.py b/cura_app.py index cfe99284b3..35ea0375b6 100755 --- a/cura_app.py +++ b/cura_app.py @@ -3,7 +3,12 @@ # Copyright (c) 2015 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. -import cura.CuraApplication +try: + import cura.CuraApplication + + app = cura.CuraApplication.CuraApplication.getInstance() + app.run() +except Exception as e: + import cura.CrashHandler + cura.CrashHandler.show() -app = cura.CuraApplication.CuraApplication.getInstance() -app.run() From 0bcd5d875df0cb1adff6a8fb0bc31ce745477699 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Tue, 14 Jul 2015 11:16:10 +0200 Subject: [PATCH 2/4] Display the actual application version in the about dialog This helps people reporting issues since they can report the proper application version --- resources/qml/AboutDialog.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/qml/AboutDialog.qml b/resources/qml/AboutDialog.qml index 369a2cfbfc..a736a7fbda 100644 --- a/resources/qml/AboutDialog.qml +++ b/resources/qml/AboutDialog.qml @@ -31,7 +31,7 @@ UM.Dialog { Label { id: version - text: "Cura 15.06" + text: "Cura %1".arg(UM.Application.version) font: UM.Theme.fonts.large anchors.horizontalCenter : logo.horizontalCenter anchors.horizontalCenterOffset : (logo.width * 0.25) From a3cc4b98b89aa807b87d4c6ac4e42068acf607b2 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Tue, 14 Jul 2015 16:02:03 +0200 Subject: [PATCH 3/4] Bump application version --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index e0de1b9f34..3c63d07b4f 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -53,7 +53,7 @@ class CuraApplication(QtApplication): if not hasattr(sys, "frozen"): Resources.addResourcePath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..")) - super().__init__(name = "cura", version = "15.06.01") + super().__init__(name = "cura", version = "15.06.02") self.setWindowIcon(QIcon(Resources.getPath(Resources.ImagesLocation, "cura-icon.png"))) From c1d8e204b7051561e610bc4d1ad6a6a9391519c4 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Wed, 15 Jul 2015 00:19:35 +0200 Subject: [PATCH 4/4] Increase baud rate detection timeout and do not send \n between M105 Improves printer detection rate on MacOSX Contributes to #82 --- plugins/USBPrinting/PrinterConnection.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/USBPrinting/PrinterConnection.py b/plugins/USBPrinting/PrinterConnection.py index 9d3c3334ef..cf020c4f49 100644 --- a/plugins/USBPrinting/PrinterConnection.py +++ b/plugins/USBPrinting/PrinterConnection.py @@ -201,18 +201,18 @@ class PrinterConnection(SignalEmitter): continue # Could not set the baud rate, go to the next time.sleep(1.5) # Ensure that we are not talking to the bootloader. 1.5 sec seems to be the magic number sucesfull_responses = 0 - timeout_time = time.time() + 5 + timeout_time = time.time() + 15 self._serial.write(b"\n") self._sendCommand("M105") # Request temperature, as this should (if baudrate is correct) result in a command with "T:" in it + while timeout_time > time.time(): - line = self._readline() + line = self._readline() if line is None: self.setIsConnected(False) # Something went wrong with reading, could be that close was called. return if b"T:" in line: self._serial.timeout = 0.5 - self._serial.write(b"\n") self._sendCommand("M105") sucesfull_responses += 1 if sucesfull_responses >= self._required_responses_auto_baud: @@ -220,6 +220,8 @@ class PrinterConnection(SignalEmitter): self.setIsConnected(True) Logger.log("i", "Established printer connection on port %s" % self._serial_port) return + + Logger.log("e", "Baud rate detection for %s failed", self._serial_port) self.close() # Unable to connect, wrap up. self.setIsConnected(False)