Skip to content

Commit

Permalink
Merge pull request #23 from kusti8/dev
Browse files Browse the repository at this point in the history
Add excepthook
  • Loading branch information
Gustav Hansen authored Oct 21, 2017
2 parents d97c701 + 5212b7c commit f367bea
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
36 changes: 35 additions & 1 deletion hue_plus/hue_ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3
VERSION="1.4.2"
VERSION="1.4.3"
import sys
import io
import traceback
from time import sleep
import os
import types
Expand Down Expand Up @@ -55,6 +57,7 @@ def main():
# sys.exit("You need to have root privileges to run this script.\nPlease try again, this time using 'sudo'.")
#if not is_admin():
# runAsAdmin()
sys.excepthook = excepthook
app = QApplication(sys.argv)
form = MainWindow()
form.show()
Expand Down Expand Up @@ -735,5 +738,36 @@ def animatedApply(self):
self.animatedThread = multiprocessing.Process(target=hue.animated, args=(self.portTxt.text(), self.getChannel(), self.animatedColors, self.animatedSpeed.value()))
self.animatedThread.start()


def excepthook(excType, excValue, tracebackobj):
"""Rewritten "excepthook" function, to display a message box with details about the exception.
@param excType exception type
@param excValue exception value
@param tracebackobj traceback object
"""
separator = '-' * 40
notice = "An unhandled exception has occurred\n"

tbinfofile = io.StringIO()
traceback.print_tb(tracebackobj, None, tbinfofile)
tbinfofile.seek(0)
tbinfo = tbinfofile.read()
errmsg = '%s: \n%s' % (str(excType), str(excValue))
sections = [separator, errmsg, separator, tbinfo]
msg = '\n'.join(sections)

# Create a QMessagebox
error_box = QMessageBox()

error_box.setText(str(notice)+str(msg))
error_box.setWindowTitle("Hue-plus - unhandled exception")
error_box.setIcon(QMessageBox.Critical)
error_box.setStandardButtons(QMessageBox.Ok)
error_box.setTextInteractionFlags(Qt.TextSelectableByMouse)

# Show the window
error_box.exec_()
sys.exit(1)

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion installer.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Application]
name=hue_plus
version=1.4.2
version=1.4.3
publisher=Gustav Hansen
# How to launch the app - this calls the 'main' function from the 'myapp' package:
entry_point=hue_plus.hue_ui:main
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os

setup(name='hue_plus',
version='1.4.2',
version='1.4.3',
description='A utility to control the NZXT Hue+ in Linux',
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.2
1.4.3

0 comments on commit f367bea

Please sign in to comment.