示例#1
0
 def __init__(self):
     super().__init__()
     if os.path.exists("gui/window.ui"):
         self.ui = uic.loadUi("gui/window.ui", self)
     else:
         from gui.window import Ui_MainWindow
         self.ui = Ui_MainWindow()
         self.ui.setupUi(self)
     self.comm = None
     self.comm_thread_running = False
     self.comm_thread = None
     self.preset = {}
     self.has_log = 0
     self.on_btn_reload_clicked()
示例#2
0
class App(QMainWindow):
    def __init__(self):
        super().__init__()
        if os.path.exists("gui/window.ui"):
            self.ui = uic.loadUi("gui/window.ui", self)
        else:
            from gui.window import Ui_MainWindow
            self.ui = Ui_MainWindow()
            self.ui.setupUi(self)
        self.comm = None
        self.comm_thread_running = False
        self.comm_thread = None
        self.preset = {}
        self.has_log = 0
        self.on_btn_reload_clicked()

    def init_port(self):
        items = Comm.scan_ports()

        item = self.ui.cb_port.currentText()
        if len(item) == 0 and len(items) > 0:
            item = items[0]

        self.ui.cb_port.clear()
        self.ui.cb_port.addItems(items)
        self.ui.cb_port.setCurrentText(item)

    def init_speed(self):
        items = ["9600", "19200", "38400", "57600", "115200"]

        item = self.ui.cb_speed.currentText()
        if item not in items:
            item = "38400"

        self.ui.cb_speed.clear()
        self.ui.cb_speed.addItems(items)
        self.ui.cb_speed.setCurrentText(item)

    def init_preset(self):
        self.preset = {}
        try:
            filename = os.path.splitext(sys.argv[0])[0] + '.csv'
            with open(filename, 'r', encoding=_ENCODING) as f:
                reader = csv.reader(f, skipinitialspace=True)
                for key, *val in reader:
                    self.preset[key] = val
        except Exception as ex:
            print(f"init_preset: {ex}")

        self.ui.lst_preset.clear()
        self.ui.lst_preset.addItems(list(self.preset.keys()))

    @pyqtSlot()
    def on_btn_reload_clicked(self):
        if self.comm:
            self.on_btn_open_clicked()

        self.init_port()
        self.init_speed()
        self.init_preset()

    @pyqtSlot()
    def on_btn_clear_clicked(self):
        self.ui.lst_log.clear()
        self.ui.edt_log.clear()
        self.ui.txt_log.clear()

    @pyqtSlot()
    def on_lst_preset_itemSelectionChanged(self):
        key = self.ui.lst_preset.currentItem().text()
        self.ui.edt_caption.setText(key)
        self.ui.edt_dat.clear()
        for val in self.preset[key]:
            self.ui.edt_dat.append(val)

    @pyqtSlot()
    def on_btn_send_clicked(self):
        try:
            if self.comm:
                dat = self.ui.edt_dat.toPlainText().replace('\n', '').encode(_ENCODING)
                if len(dat) > 0:
                    dat = PacketBuilder().decode(dat).build()
                    dat = self.comm.build(dat)

                    self.append_log(dat, ">>")
                    self.scroll_log()

                    self.comm.write(dat)
        except Exception as ex:
            QMessageBox.warning(self, "SEND", str(ex))

    def append_log(self, dat, sender):
        ts = datetime.datetime.now().strftime("%H:%M:%S.%f")[:-3]
        dump = binascii.hexlify(dat).decode().upper()
        self.ui.lst_log.addItem(f"[{ts}] {sender} {dump}")
        self.has_log = 1

    def scroll_log(self):
        if self.has_log:
            self.ui.lst_log.scrollToBottom()
            self.has_log = 0

    @pyqtSlot()
    def on_lst_log_itemSelectionChanged(self):
        log = self.ui.lst_log.currentItem().text()
        ts, sender, dump = log.split()
        dat = binascii.unhexlify(dump)
        hd = hexdump.hexdump(dat)
        sd = hexdump.strdump(dat, encoding=_ENCODING)
        self.ui.edt_log.setPlainText(f"{ts} {sender} {len(dat)} bytes\n{hd}")
        self.ui.txt_log.setText(sd)

    @pyqtSlot()
    def on_btn_open_clicked(self):
        if self.comm:
            self.comm_thread_running = False
            self.comm_thread.join()
            self.comm_thread = None

            self.comm.close()
            self.comm = None

            self.ui.btn_open.setText("&OPEN")
        else:
            try:
                if _POS_UPLOAD:
                    self.comm = CommPosUpload(self.ui.cb_port.currentText(), int(self.ui.cb_speed.currentText()))
                else:
                    self.comm = Comm(self.ui.cb_port.currentText(), int(self.ui.cb_speed.currentText()))
                self.comm.open()

                self.comm_thread_running = True
                self.comm_thread = threading.Thread(target=self.run_comm_thread, daemon=True)
                self.comm_thread.start()

                self.ui.btn_open.setText("CL&OSE")
            except Exception as ex:
                self.comm = None
                QMessageBox.warning(self, "OPEN", str(ex))

    def run_comm_thread(self):
        print("run_comm_thread: start")

        while self.comm_thread_running:
            try:
                dat = self.comm.read(1, True)
                self.append_log(dat, "<<")
            except CommTimeoutError as ex:
                self.scroll_log()
            except CommError as ex:
                self.append_log(ex.raw, "<" + str(ex)[0])
            except Exception as ex:
                print(f"run_comm_thread: {ex}")
                break

        print("run_comm_thread: stop")
示例#3
0
文件: main.py 项目: gipdiaz/fti_final
 def __init__(self):
     "" ""
     QtGui.QMainWindow.__init__(self)
     self.ui=Ui_MainWindow()
     self.ui.setupUi(self)
     self.ui.transcisionesWidget
示例#4
0
文件: main.py 项目: gipdiaz/fti_final
class MainWindow(QtGui.QMainWindow):
    
    #----------------------------------------------------#
    
    def __init__(self):
        "" ""
        QtGui.QMainWindow.__init__(self)
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.transcisionesWidget
    
    #----------------------------------------------------#
    
    def nueva(self):
        self.ui.transcisionesWidget.setColumnCount(5)
        self.ui.transcisionesWidget.setAlternatingRowColors(True)
        self.ui.transcisionesWidget.setContentsMargins(1, 1, 1, 1)
        self.ui.transcisionesWidget.setAllColumnsShowFocus(True)
        self.ui.transcisionesWidget.setColumnWidth(0,55)
        self.ui.transcisionesWidget.setColumnWidth(1,55)
        self.ui.transcisionesWidget.setColumnWidth(2,55)
        self.ui.transcisionesWidget.setColumnWidth(3,55)
        self.ui.transcisionesWidget.setColumnWidth(4,55)
    
        # set objetos "enable"
        self.ui.EstadosText.setEnabled(True)
        self.ui.EstadosText.setToolTip("'a,b,c' sino 'a b c'")
        self.ui.EstadosText.clear()
        self.ui.AlfabetoText.setEnabled(True)
        self.ui.AlfabetoText.setToolTip("'1,2,3' sino '1 2 3'")
        self.ui.AlfabetoText.clear()
        self.ui.EstadosAcepText.setEnabled(True)
        self.ui.EstadosAcepText.setToolTip("'a,b,c' sino 'a b c'")
        self.ui.EstadosAcepText.clear()
        self.ui.SimbBlancoText.setEnabled(True)
        self.ui.SimbBlancoText.setToolTip("'@' sino '#' sino '&' sino 'Cualquier caracter'")
        self.ui.SimbBlancoText.clear()
        self.ui.EstadoIniText.setEnabled(True)
        self.ui.EstadoIniText.setToolTip("'a' sino 'b' sino 'c'")
        self.ui.EstadoIniText.clear()
        self.ui.aceptarTuringBoton.setEnabled(True)
                
        # set objetos "disable"
        self.ui.comboBox.setEnabled(False)
        self.ui.comboBox_2.setEnabled(False)
        self.ui.comboBox_3.setEnabled(False)
        self.ui.comboBox_4.setEnabled(False)
        self.ui.comboBox_5.setEnabled(False)
        self.ui.transcisionesWidget.setEnabled(False)
        self.ui.transcisionesWidget.clear()
        self.ui.CintatextBrowser.setEnabled(False)
        self.ui.CintatextBrowser.clear()
        self.ui.AgregarTransicionBoton.setEnabled(False)
        self.ui.BorrarTransicionBoton.setEnabled(False)
        
        # set el estado de los botones de la interfaz
        self.ui.actionNueva.setDisabled(False)
        self.ui.actionAbrir.setDisabled(False)
        self.ui.actionCerrar.setDisabled(True)
        self.ui.actionGuardar.setDisabled(True)
        self.ui.actionEjecutar.setDisabled(True)
        self.ui.actionPaso.setDisabled(True)
        self.ui.actionDetener.setDisabled(True)
        self.ui.actionCargar.setDisabled(True)
        
    #----------------------------------------------------#
    
    def mostrar(self,msj):
        self.ui.CintatextBrowser.setText(msj)
    
    #----------------------------------------------------#
    
    def imprimir(self,msj):
        self.ui.CintatextBrowser.append(msj)
        self.ui.CintatextBrowser.show()
     
    #----------------------------------------------------#
        
    def activarTransicion(self,datos):
        self.ui.comboBox.setEnabled(True)
        self.ui.comboBox_2.setEnabled(True)
        self.ui.comboBox_3.setEnabled(True)
        self.ui.comboBox_4.setEnabled(True)
        self.ui.comboBox_5.setEnabled(True)
        self.ui.transcisionesWidget.setEnabled(True)
        self.ui.CintatextBrowser.setEnabled(True)
        self.ui.AgregarTransicionBoton.setEnabled(True)
        self.ui.BorrarTransicionBoton.setEnabled(True)
        
        self.ui.comboBox.addItems(datos.conj_estados)
        self.ui.comboBox_2.addItems(datos.alfabeto_entrada + [datos.char_blanco])
        self.ui.comboBox_3.addItems(datos.conj_estados)
        self.ui.comboBox_4.addItems(datos.alfabeto_entrada + [datos.char_blanco])
        self.ui.comboBox_5.addItems(['D','I', '-'])
    
    #----------------------------------------------------#
        
    def desactivarCargaDatos(self):
        self.ui.EstadosText.setEnabled(False)
        self.ui.AlfabetoText.setEnabled(False)
        self.ui.EstadosAcepText.setEnabled(False)
        self.ui.SimbBlancoText.setEnabled(False)
        self.ui.EstadoIniText.setEnabled(False)
示例#5
0
 def __init__(self):
     "" ""
     QtGui.QMainWindow.__init__(self)
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.ui.transcisionesWidget
示例#6
0
class MainWindow(QtGui.QMainWindow):

    #----------------------------------------------------#

    def __init__(self):
        "" ""
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.transcisionesWidget

    #----------------------------------------------------#

    def nueva(self):
        self.ui.transcisionesWidget.setColumnCount(5)
        self.ui.transcisionesWidget.setAlternatingRowColors(True)
        self.ui.transcisionesWidget.setContentsMargins(1, 1, 1, 1)
        self.ui.transcisionesWidget.setAllColumnsShowFocus(True)
        self.ui.transcisionesWidget.setColumnWidth(0, 55)
        self.ui.transcisionesWidget.setColumnWidth(1, 55)
        self.ui.transcisionesWidget.setColumnWidth(2, 55)
        self.ui.transcisionesWidget.setColumnWidth(3, 55)
        self.ui.transcisionesWidget.setColumnWidth(4, 55)

        # set objetos "enable"
        self.ui.EstadosText.setEnabled(True)
        self.ui.EstadosText.setToolTip("'a,b,c' sino 'a b c'")
        self.ui.EstadosText.clear()
        self.ui.AlfabetoText.setEnabled(True)
        self.ui.AlfabetoText.setToolTip("'1,2,3' sino '1 2 3'")
        self.ui.AlfabetoText.clear()
        self.ui.EstadosAcepText.setEnabled(True)
        self.ui.EstadosAcepText.setToolTip("'a,b,c' sino 'a b c'")
        self.ui.EstadosAcepText.clear()
        self.ui.SimbBlancoText.setEnabled(True)
        self.ui.SimbBlancoText.setToolTip(
            "'@' sino '#' sino '&' sino 'Cualquier caracter'")
        self.ui.SimbBlancoText.clear()
        self.ui.EstadoIniText.setEnabled(True)
        self.ui.EstadoIniText.setToolTip("'a' sino 'b' sino 'c'")
        self.ui.EstadoIniText.clear()
        self.ui.aceptarTuringBoton.setEnabled(True)

        # set objetos "disable"
        self.ui.comboBox.setEnabled(False)
        self.ui.comboBox_2.setEnabled(False)
        self.ui.comboBox_3.setEnabled(False)
        self.ui.comboBox_4.setEnabled(False)
        self.ui.comboBox_5.setEnabled(False)
        self.ui.transcisionesWidget.setEnabled(False)
        self.ui.transcisionesWidget.clear()
        self.ui.CintatextBrowser.setEnabled(False)
        self.ui.CintatextBrowser.clear()
        self.ui.AgregarTransicionBoton.setEnabled(False)
        self.ui.BorrarTransicionBoton.setEnabled(False)

        # set el estado de los botones de la interfaz
        self.ui.actionNueva.setDisabled(False)
        self.ui.actionAbrir.setDisabled(False)
        self.ui.actionCerrar.setDisabled(True)
        self.ui.actionGuardar.setDisabled(True)
        self.ui.actionEjecutar.setDisabled(True)
        self.ui.actionPaso.setDisabled(True)
        self.ui.actionDetener.setDisabled(True)
        self.ui.actionCargar.setDisabled(True)

    #----------------------------------------------------#

    def mostrar(self, msj):
        self.ui.CintatextBrowser.setText(msj)

    #----------------------------------------------------#

    def imprimir(self, msj):
        self.ui.CintatextBrowser.append(msj)
        self.ui.CintatextBrowser.show()

    #----------------------------------------------------#

    def activarTransicion(self, datos):
        self.ui.comboBox.setEnabled(True)
        self.ui.comboBox_2.setEnabled(True)
        self.ui.comboBox_3.setEnabled(True)
        self.ui.comboBox_4.setEnabled(True)
        self.ui.comboBox_5.setEnabled(True)
        self.ui.transcisionesWidget.setEnabled(True)
        self.ui.CintatextBrowser.setEnabled(True)
        self.ui.AgregarTransicionBoton.setEnabled(True)
        self.ui.BorrarTransicionBoton.setEnabled(True)

        self.ui.comboBox.addItems(datos.conj_estados)
        self.ui.comboBox_2.addItems(datos.alfabeto_entrada +
                                    [datos.char_blanco])
        self.ui.comboBox_3.addItems(datos.conj_estados)
        self.ui.comboBox_4.addItems(datos.alfabeto_entrada +
                                    [datos.char_blanco])
        self.ui.comboBox_5.addItems(['D', 'I', '-'])

    #----------------------------------------------------#

    def desactivarCargaDatos(self):
        self.ui.EstadosText.setEnabled(False)
        self.ui.AlfabetoText.setEnabled(False)
        self.ui.EstadosAcepText.setEnabled(False)
        self.ui.SimbBlancoText.setEnabled(False)
        self.ui.EstadoIniText.setEnabled(False)