示例#1
0
 def restore_window_state(self):
     if self.gui_params.window_state:
         self.window_main.restoreState(
             QByteArray.fromHex(bytes(self.gui_params.window_state,
                                      "ascii")))
         self.window_main.restoreGeometry(
             QByteArray.fromHex(bytes(self.gui_params.geometry, "ascii")))
示例#2
0
    def changeIntensityValue(self, value):
        print("intensity value ", value)
        self.receivedData.clear()

        print("data to append : ", QByteArray.number(value, 16))

        print("QByteArray after append")
        self.receivedData.append(QByteArray.fromHex(QByteArray.number(3, 16)))
        self.receivedData.append(
            QByteArray.fromHex(QByteArray.number(value, 16)))
        print(self.receivedData)

        self.serialPort.writeData(self.receivedData)

        self.receivedData.clear()
 def __text2bytearray(self, txt, format):
     """
     Private method to convert a text to a byte array.
     
     @param txt text to be converted
     @type str
     @param format format of the text
     @type str
     @return converted text
     @rtype bytearray
     """
     assert format in self.__formatAndValidators.keys()
     
     if format == "hex":             # hex format
         ba = bytearray(QByteArray.fromHex(
             bytes(txt, encoding="ascii")))
     elif format == "dec":           # decimal format
         ba = self.__int2bytearray(int(txt, 10))
     elif format == "oct":           # octal format
         ba = self.__int2bytearray(int(txt, 8))
     elif format == "bin":           # binary format
         ba = self.__int2bytearray(int(txt, 2))
     elif format == "iso-8859-1":    # latin-1/iso-8859-1 text
         ba = bytearray(txt, encoding="iso-8859-1")
     elif format == "utf-8":         # utf-8 text
         ba = bytearray(txt, encoding="utf-8")
     
     return ba
示例#4
0
    def send_data(self, ):
        # 发送数据
        if not self._serial.isOpen():
            QMessageBox.warning(self, "警告", "串口未打开!", QMessageBox.Yes)
            return
        _text = self.plainTextEdit_send.toPlainText()
        # print(_text)
        if not _text:
            QMessageBox.warning(self, "警告", "没有发送数据!", QMessageBox.Yes)
            return
        if self.radioButton_asciisend.isChecked():
            text = QByteArray(_text.encode('utf-8'))  # 编码
            # print("发送数据", text)
            # self._serial.write(text)
        elif self.radioButton_hexsend.isChecked():
            _text = _text.strip().upper()  # 去除两边的空格,转换为大写
            if not _text:
                QMessageBox.warning(self, "警告", "发送数据错误!", QMessageBox.Yes)
                return
            # print("处理数据", _text)
            _list = _text.split()
            # print(_list)

            for i in range(len(_list)):
                if self._is_hex(_list[i]):
                    if len(_list[i]) > 2:
                        QMessageBox.warning(self, "警告", "发送数据输入格式错误!",
                                            QMessageBox.Yes)
                        return
                else:
                    QMessageBox.warning(self, "警告", "发送数据不是十六进制数据!",
                                        QMessageBox.Yes)
                    return
            _text = "".join(_list)
            # print(_text)
            text = QByteArray.fromHex(_text.encode('utf-8'))  # 编码
            # print("发送数据", text)
        _num = self._serial.write(text)
        self._num_send += _num
        self._label_num_send.setText("发送:" + str(self._num_send))
示例#5
0
    def initUI(self):
        main_layout = QVBoxLayout(self)

        self.setWindowTitle('DOCXImport')
        self.upd_layout = QVBoxLayout()
        self.update_label = QLabel()
        self.update_label.setAlignment(Qt.AlignCenter)
        self.upd_layout.addWidget(self.update_label)
        self.get_update_button = QPushButton()
        self.get_update_button.clicked.connect(self.get_update)
        self.upd_layout.addWidget(self.get_update_button)
        main_layout.addLayout(self.upd_layout)
        if not self.update:
            self.update_label.hide()
            self.get_update_button.hide()

        self.details_grid = QGridLayout()
        self.epub2_select = QRadioButton()
        self.epub2_select.setText('EPUB2')
        self.epubType = QButtonGroup()
        self.epubType.addButton(self.epub2_select)
        self.details_grid.addWidget(self.epub2_select, 0, 0, 1, 1)
        self.checkbox_get_updates = QCheckBox()
        self.details_grid.addWidget(self.checkbox_get_updates, 0, 1, 1, 1)
        self.epub3_select = QRadioButton()
        self.epub3_select.setText('EPUB3')
        self.epubType.addButton(self.epub3_select)
        self.details_grid.addWidget(self.epub3_select, 1, 0, 1, 1)
        main_layout.addLayout(self.details_grid)
        self.checkbox_get_updates.setChecked(self.prefs['check_for_updates'])
        if self.prefs['epub_version'] == '2.0':
            self.epub2_select.setChecked(True)
        elif self.prefs['epub_version'] == '3.0':
            self.epub3_select.setChecked(True)
        else:
            self.epub2_select.setChecked(True)

        self.groupBox = QGroupBox()
        self.groupBox.setTitle('')
        self.verticalLayout_2 = QVBoxLayout(self.groupBox)
        self.docx_grid = QGridLayout()
        self.docx_label = QLabel()
        self.docx_grid.addWidget(self.docx_label, 0, 0, 1, 1)
        self.docx_path = QLineEdit()
        self.docx_grid.addWidget(self.docx_path, 1, 0, 1, 1)
        self.choose_docx_button = QPushButton()
        self.choose_docx_button.setText('...')
        self.docx_grid.addWidget(self.choose_docx_button, 1, 1, 1, 1)
        self.verticalLayout_2.addLayout(self.docx_grid)
        self.choose_docx_button.clicked.connect(
            lambda: self.fileChooser('docx', self.docx_path))
        if len(self.prefs['lastDocxPath']):
            self.docx_path.setText(self.prefs['lastDocxPath'])
        self.docx_path.setEnabled(False)

        self.smap_grid = QGridLayout()
        self.checkbox_smap = QCheckBox(self.groupBox)
        self.smap_grid.addWidget(self.checkbox_smap, 0, 0, 1, 1)
        self.cust_smap_path = QLineEdit(self.groupBox)
        self.smap_grid.addWidget(self.cust_smap_path, 1, 0, 1, 1)
        self.choose_smap_button = QPushButton(self.groupBox)
        self.choose_smap_button.setText('...')
        self.smap_grid.addWidget(self.choose_smap_button, 1, 1, 1, 1)
        self.verticalLayout_2.addLayout(self.smap_grid)
        self.checkbox_smap.setChecked(self.prefs['useSmap'])
        self.checkbox_smap.stateChanged.connect(lambda: self.chkBoxActions(
            self.checkbox_smap, self.choose_smap_button))
        self.choose_smap_button.clicked.connect(
            lambda: self.fileChooser('smap', self.cust_smap_path, self.
                                     checkbox_smap, self.choose_smap_button))
        if len(self.prefs['useSmapPath']):
            self.cust_smap_path.setText(self.prefs['useSmapPath'])
        self.cust_smap_path.setEnabled(False)
        self.chkBoxActions(self.checkbox_smap, self.choose_smap_button)

        self.css_grid = QGridLayout()
        self.checkbox_css = QCheckBox(self.groupBox)
        self.css_grid.addWidget(self.checkbox_css, 0, 0, 1, 1)
        self.cust_css_path = QLineEdit(self.groupBox)
        self.css_grid.addWidget(self.cust_css_path, 1, 0, 1, 1)
        self.choose_css_button = QPushButton(self.groupBox)
        self.choose_css_button.setText('...')
        self.css_grid.addWidget(self.choose_css_button, 1, 1, 1, 1)
        self.verticalLayout_2.addLayout(self.css_grid)
        self.checkbox_css.setChecked(self.prefs['useCss'])
        self.checkbox_css.stateChanged.connect(lambda: self.chkBoxActions(
            self.checkbox_css, self.choose_css_button))
        self.choose_css_button.clicked.connect(
            lambda: self.fileChooser('css', self.cust_css_path, self.
                                     checkbox_css, self.choose_css_button))
        if len(self.prefs['useCssPath']):
            self.cust_css_path.setText(self.prefs['useCssPath'])
        self.cust_css_path.setEnabled(False)
        self.chkBoxActions(self.checkbox_css, self.choose_css_button)

        main_layout.addWidget(self.groupBox)
        self.checkbox_debug = QCheckBox()
        main_layout.addWidget(self.checkbox_debug)
        self.checkbox_debug.setChecked(self.prefs['debug'])

        spacerItem = QSpacerItem(20, 15, QSizePolicy.Minimum,
                                 QSizePolicy.Expanding)
        main_layout.addItem(spacerItem)

        button_box = QDialogButtonBox(QDialogButtonBox.Ok
                                      | QDialogButtonBox.Cancel)
        button_box.accepted.connect(self._ok_clicked)
        button_box.rejected.connect(self._cancel_clicked)
        main_layout.addWidget(button_box)
        self.retranslateUi(self)
        if self.prefs['qt_geometry'] is not None:
            try:
                self.restoreGeometry(
                    QByteArray.fromHex(
                        self.prefs['qt_geometry'].encode('ascii')))
            except:
                pass
        self.show()
示例#6
0
    def displayImageList(self):

        # Table Source model
        self.mainW.imageSourceModel = QtSql.QSqlTableModel()
        self.mainW.imageSourceModel.setTable("images")
        self.mainW.imageSourceModel.setSort(3, QtCore.Qt.DescendingOrder)

        self.mainW.imageSourceModel.select()
        while self.mainW.imageSourceModel.canFetchMore():
            self.mainW.imageSourceModel.fetchMore()

        # Proxy model used for filtering and sorting.
        self.mainW.imageListModel.setDynamicSortFilter(True)
        self.mainW.imageListModel.setSourceModel(self.mainW.imageSourceModel)

        for i, label in enumerate(self.app.filterDictToList("description")):
            self.mainW.imageListModel.setHeaderData(i, QtCore.Qt.Horizontal,
                                                    label)

        # restore the header state only if it is allowed
        if self.app.settings.value("readStateOnStart") == "True":
            try:
                rs = QByteArray.fromHex(
                    bytes(self.app.settings.value("imageListState"), 'ascii'))
                self.mainW.ui.tableViewImages.horizontalHeader().restoreState(
                    rs)
            except Exception as e:
                self.logger.error(f"Could not restore table header state {e}")
        else:
            self.app.settings.setValue("readStateOnStart", "True")

        self.mainW.ui.tableViewImages.setWordWrap(False)
        #self.mainW.ui.tableViewImages.verticalHeader().hide()
        self.mainW.ui.tableViewImages.setSortingEnabled(True)
        self.mainW.ui.tableViewImages.setAlternatingRowColors(True)
        self.mainW.ui.tableViewImages.setModel(self.mainW.imageListModel)
        self.mainW.ui.tableViewImages.setTextElideMode(QtCore.Qt.ElideLeft)
        self.mainW.ui.tableViewImages.setEditTriggers(
            QtGui.QAbstractItemView.NoEditTriggers)

        fd = FileDelegate(self.mainW.ui.tableViewImages)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(1, fd)

        framed = FrameDelegate(self.mainW.ui.tableViewImages)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(4, framed)

        filterd = FilterDelegate(self.mainW.ui.tableViewImages)
        filterd.getFilters(self.app.confFilters)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(5, filterd)
        dd = DateDelegate(self.mainW.ui.tableViewImages)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(16, dd)
        rd = RoundDelegate(self.mainW.ui.tableViewImages)
        rd.getPrecision(self.app.config["precision"])
        # Site Long and Site Lat have dms representation
        latd = LatDelegate(self.mainW.ui.tableViewImages)
        longd = LongDelegate(self.mainW.ui.tableViewImages)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(10, latd)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(11, longd)

        # RA has hms representation
        rad = HmsDelegate(self.mainW.ui.tableViewImages)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(12, rad)
        # DEC, ALT, AZ  have dms reprentation
        dad = DmsDelegate(self.mainW.ui.tableViewImages)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(13, dad)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(14, dad)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(15, dad)

        self.mainW.ui.tableViewImages.setItemDelegateForColumn(25, rd)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(26, rd)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(27, rd)
        self.mainW.ui.tableViewImages.setItemDelegateForColumn(28, rd)

        hideColList = self.app.filterDictToList("hide", "hide")
        for col, val in enumerate(hideColList):
            if val > 0:
                self.mainW.ui.tableViewImages.hideColumn(col)