Commit e1bdc2e6 authored by Samuele Carcagno's avatar Samuele Carcagno
Browse files

add graphical traceback; set wavpy as default wav manager

parent 0d5fa5ce
Loading
Loading
Loading
Loading
+70 −4
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#    You should have received a copy of the GNU General Public License
#    along with emid.  If not, see <http://www.gnu.org/licenses/>.

import fnmatch, os, random, signal, time
import fnmatch, logging, os, random, signal, time, traceback
import numpy as np
import pandas as pd
from emid.pyqtver import*
@@ -32,12 +32,12 @@ from emid.dialog_edit_phones import*
if pyqtversion == 5:
    from PyQt5 import QtCore, QtGui
    from PyQt5.QtCore import Qt, QEvent, QDate, QDateTime, QTime
    from PyQt5.QtWidgets import QAction, QCheckBox, QComboBox, QDesktopWidget, QFrame, QFileDialog, QGridLayout, QHBoxLayout, QInputDialog, QLabel, QLayout, QLineEdit, QMainWindow, QMessageBox, QScrollArea, QSizePolicy, QSlider, QSpacerItem, QSplitter, QPushButton, QToolButton, QVBoxLayout, QWhatsThis, QWidget
    from PyQt5.QtWidgets import QAction, QCheckBox, QComboBox, QDesktopWidget, QDialog, QDialogButtonBox, QFrame, QFileDialog, QGridLayout, QHBoxLayout, QInputDialog, QLabel, QLayout, QLineEdit, QMainWindow, QMessageBox, QScrollArea, QSizePolicy, QSlider, QSpacerItem, QSplitter, QPushButton, QToolButton, QVBoxLayout, QWhatsThis, QWidget
    from PyQt5.QtGui import QColor, QDesktopServices, QDoubleValidator, QIcon, QPainter, QIntValidator
elif pyqtversion == 6:
    from PyQt6 import QtCore, QtGui
    from PyQt6.QtCore import Qt, QEvent, QDate, QDateTime, QTime
    from PyQt6.QtWidgets import  QCheckBox, QComboBox, QFrame, QFileDialog, QGridLayout, QHBoxLayout, QInputDialog, QLabel, QLayout, QLineEdit, QMainWindow, QMessageBox, QScrollArea, QSizePolicy, QSlider, QSpacerItem, QSplitter, QPushButton, QToolButton, QVBoxLayout, QWhatsThis, QWidget
    from PyQt6.QtWidgets import  QCheckBox, QComboBox, QDialog, QDialogButtonBox, QFrame, QFileDialog, QGridLayout, QHBoxLayout, QInputDialog, QLabel, QLayout, QLineEdit, QMainWindow, QMessageBox, QScrollArea, QSizePolicy, QSlider, QSpacerItem, QSplitter, QPushButton, QToolButton, QVBoxLayout, QWhatsThis, QWidget
    from PyQt6.QtGui import QAction, QColor, QDesktopServices, QDoubleValidator, QIcon, QPainter, QIntValidator
    
QtCore.Signal = QtCore.pyqtSignal
@@ -45,6 +45,69 @@ QtCore.Slot = QtCore.pyqtSlot

signal.signal(signal.SIGINT, signal.SIG_DFL)

local_dir = os.path.expanduser("~") +'/.local/share/data/emid/'
if os.path.exists(local_dir) == False:
    os.makedirs(local_dir)
stderrFile = os.path.expanduser("~") +'/.local/share/data/emid/emid_stderr_log.txt'

logging.basicConfig(filename=stderrFile,level=logging.DEBUG,)

# def excepthook(except_type, except_val, tbck):
#     """ Show errors in message box"""
#     # recover traceback
#     tb = traceback.format_exception(except_type, except_val, tbck)
#     ret = QMessageBox.critical(None, "Critical Error! Something went wrong, the following info may help you troubleshooting",
#                                     ''.join(tb),
#                                     QMessageBox.StandardButton.Ok)
#     timeStamp = ''+ time.strftime("%d/%m/%y %H:%M:%S", time.localtime()) + ' ' + '\n'
#     logMsg = timeStamp + ''.join(tb)
#     logging.debug(logMsg)

#the except hook allows to see most startup errors in a window
#rather than the console
def excepthook(except_type, except_val, tbck):
    """ Show errors in message box"""
    # recover traceback
    tb = traceback.format_exception(except_type, except_val, tbck)
    def onClickSaveTbButton():
        ftow = QFileDialog.getSaveFileName(None, 'Choose where to save the traceback', "traceback.txt", 'All Files (*)')[0]
        if len(ftow) > 0:
            if fnmatch.fnmatch(ftow, '*.txt') == False:
                ftow = ftow + '.txt'
            fName = open(ftow, 'w')
            fName.write("".join(tb))
            fName.close()
    
    diag = QDialog(None, Qt.WindowType.CustomizeWindowHint | Qt.WindowType.WindowCloseButtonHint)
    diag.window().setWindowTitle("Critical Error!")
    siz = QVBoxLayout()
    lay = QVBoxLayout()
    saveTbButton = QPushButton("Save Traceback", diag)
    saveTbButton.clicked.connect(onClickSaveTbButton)
    lab = QLabel("Sorry, something went wrong. The attached traceback can help you troubleshoot the problem: \n\n" + "".join(tb))
    lab.setMargin(10)
    lab.setWordWrap(True)
    lab.setTextInteractionFlags(Qt.TextInteractionFlag.TextSelectableByMouse)
    lab.setStyleSheet("QLabel { background-color: white }");
    lay.addWidget(lab)

    sc = QScrollArea()
    sc.setWidget(lab)
    siz.addWidget(sc) #SCROLLAREA IS A WIDGET SO IT NEEDS TO BE ADDED TO A LAYOUT

    buttonBox = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok|QDialogButtonBox.StandardButton.Cancel)

    buttonBox.accepted.connect(diag.accept)
    buttonBox.rejected.connect(diag.reject)
    siz.addWidget(saveTbButton)
    siz.addWidget(buttonBox)
    diag.setLayout(siz)
    diag.exec()

    timeStamp = ''+ time.strftime("%d/%m/%y %H:%M:%S", time.localtime()) + ' ' + '\n'
    logMsg = timeStamp + ''.join(tb)
    logging.debug(logMsg)

class mainWin(QMainWindow):
    def __init__(self, prm=None):
        QMainWindow.__init__(self)
@@ -545,12 +608,15 @@ class responseLight(QWidget):
            painter.drawText(r, Qt.AlignmentFlag.AlignCenter, self.feedbackText)



    
def main():
    prm = {}
    prm['appData'] = {}
    prm = get_prefs(prm)
    prm = set_global_parameters(prm)
    qApp = QApplication(sys.argv)
    sys.excepthook = excepthook
    #qApp.setWindowIcon(QtGui.QIcon(":/app_icon"))
 

+2 −2
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-

emid_version = "0.0.6"
emid_builddate = "09-Jun-2023 00:03"
emid_version = "0.0.7"
emid_builddate = "09-Jun-2023 11:44"
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
project = 'emid'
copyright = '2022-2023, Samuele Carcagno'
author = 'Samuele Carcagno'
release = "0.0.6"
release = "0.0.7"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
+1 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ def def_pref(prm):
    # prm["pref"]["sound"]["writewav"] = True
    # ##prm["pref"]["sound"]["writeSndSeqSegments"] = False
    # prm["pref"]["sound"]["writeParticipantWAVs"] = False
    prm["pref"]["sound"]["wavmanager"] = "soundfile"
    prm["pref"]["sound"]["wavmanager"] = "wavpy"
    prm["pref"]["sound"]["bufferSize"] = 1024
    prm["pref"]["sound"]["appendSilence"] = 0
    prm["pref"]["sound"]["phones"] = "Phones 1"
+1 −1
Original line number Diff line number Diff line
6
 No newline at end of file
7
 No newline at end of file
Loading