示例#1
0
 def start_run(self):
     self.run_info = {"runcount": 0, "completed": 0}
     dates = (self.DateEdit_2.date(), self.DateEdit.date())
     select_list = []
     items_len = self.listWidget.count()
     for index in range(0, items_len):
         if self.listWidget.item(index).checkState() == Qt.CheckState(2):
             select_list.append(self.listWidget.item(index).data(1))
     self._checkByAry(select_list)
     self.run_info['runcount'] = len(select_list)
     self.browser, wait = browserInit()
     while len(select_list) > 0:
         appid = select_list.pop()
         try:
             cookies = lgm.gameWeixin_lg(self.browser, URL['login'] + appid,
                                         wait)
         except Exception:
             QtWidgets.QMessageBox.warning(self, '错误', '获取登录信息失败',
                                           QtWidgets.QMessageBox.Yes)
         myTools.logFile(json.dumps(cookies))
         gather = GatherThread(appid, cookies, dates)
         self.threadPools.append(gather)
         gather.sig.completed.connect(self._completedListener)
         gather.start()
     self.browser.quit()
示例#2
0
    def __loadSettings(self):
        settings = QSettings("Rocket Labs", "qserial-debugger")
        self.lineEditDevice.setText(str(settings.value("device",
                                                       "/dev/ttyS0")))

        self.comboBoxBaudRate.setCurrentIndex(
            int(settings.value("baudRate", 0)))
        self.comboBoxDataBits.setCurrentIndex(
            int(settings.value("dataBits", 0)))
        self.comboBoxParity.setCurrentIndex(int(settings.value("parity", 0)))
        self.comboBoxStopBits.setCurrentIndex(
            int(settings.value("stopBits", 0)))
        self.comboBoxFormat.setCurrentIndex(int(settings.value("format", 0)))

        self.checkBoxLeadingZeroes.setChecked(
            strtobool(settings.value("leadingZeroes", "False")))
        self.checkBoxTimestamp.setChecked(
            strtobool(settings.value("timestamp", "False")))

        checkBoxState = Qt.CheckState(int(settings.value("rawText", 0)))

        self.checkBoxRawText.setCheckState(
            checkBoxState
        )  # setting checkBox "checked" doesn't produce the event "stateChanged"
        self.onCheckBoxRawTextStateChanged(
            checkBoxState
        )  # so we call self.onCheckBoxRawTextStateChanged implicitly
    def unit_ui(self):

        tree_widget = QTreeWidget(self)

        # 设置列数
        tree_widget.setColumnCount(2)

        # 设置成中心控件     注意在QMainWindow才能设置,QWidget不可以。
        self.setCentralWidget(tree_widget)

        # 设置标签
        tree_widget.setHeaderLabels(['介绍', '功能'])
        tree_widget.setHeaderHidden(True)

        # 添加节点两种方式
        root1 = QTreeWidgetItem(tree_widget, ['root1'])
        root1.setIcon(0, QIcon('../images/root.png'))
        root2 = QTreeWidgetItem(tree_widget)
        root2.setText(0, 'root2')      # 指定第几列
        root2.setIcon(0, QIcon('../images/root.png'))
        # QTreeWidgetItem.Type()

        # 添加子节点
        child1 = QTreeWidgetItem(root1, ['child1', 'action'])
        # 设置子节点可选
        child1.setCheckState(0, Qt.CheckState(2))
        child2 = QTreeWidgetItem(root2, ['child2', 'action'])
        # 节点对齐缩进距离
        child2.setTextAlignment(0, 1)
        # 设置节点宽度
        tree_widget.setColumnWidth(0, 300)
        # 让节点全部展开
        tree_widget.expandAll()
示例#4
0
    def loadSettingInformation(self):
        self.lstOrder = []
        trialDuration = self.XML_settingTrial.getValue(['TrialSettings','GeneralSettings','sbTrialDuration'])
        self.stimulusDuration = self.XML_settingTrial.getValue(['TrialSettings','GeneralSettings','sbStimulusDuration'])
        self.pauseDuration = self.XML_settingTrial.getValue(['TrialSettings','GeneralSettings','sbPause'])
        self.randomizeStimuli = self.XML_settingTrial.getValue(['TrialSettings','GeneralSettings','cbRandomizeStimuli'])
        self.amountOfTrials = int(self.XML_artifactOrder.getValue(['AmountOfTrials']))
        self.pauseBetweenTrials = 60*int(self.XML_artifactOrder.getValue(['PauseInBetweenTrials','Minute']))+int(self.XML_artifactOrder.getValue(['PauseInBetweenTrials','Second']))
        self.amount_of_stimuli = ceil(int(trialDuration)*60/(float(self.stimulusDuration)+float(self.pauseDuration)))
        self.artifacts = list(list(zip(*self.XML_artifactOrder.getChildren(['Order'])))[0])
        
        amount_of_stimuli_per_artifact = ceil(self.amount_of_stimuli/len(self.artifacts))
        all_stimuli_list = self.artifacts*amount_of_stimuli_per_artifact
        
        if int(self.randomizeStimuli) == Qt.CheckState(Qt.Checked):
            random.shuffle(all_stimuli_list)
        self.all_stimuli_list = all_stimuli_list

        self.ERP = self.XML_settingTrial.getAttrib(['TrialSettings','ERP'],'Checked')
        
        filename,filetype = QFileDialog.getSaveFileName(None,"Stimulus file", os.path.join(QtCore.QDir.currentPath(),self.XML_Read.getValue(['Paths','StimulusFilesDefault'])),
                                                        "CSV Files (*.csv)")

        if  self.ERP == 'True':
            stimuliList = self.generateERPStimuliSequence()
            self.writeToCSVFile(filename,stimuliList,'ERP')
            return 'ERP',stimuliList, self.artifacts
        else:
            stimuliList = self.generateArtifactStimuliSequence()
            self.writeToCSVFile(filename,stimuliList,'Artifact')
            return 'Artifact',stimuliList, self.artifacts
示例#5
0
    def data(self, index: QModelIndex, role: int) -> typing.Any:
        if not index.isValid():
            return QVariant()

        if index.column() == 1 and role == Qt.CheckStateRole and isinstance(
                index.internalPointer(), PartitionItem):
            if index.internalPointer().enabled:
                return Qt.CheckState(Qt.Checked)
            else:
                return Qt.CheckState(Qt.Unchecked)

        if role != Qt.DisplayRole or index.column() == 1:
            return QVariant()
        item = index.internalPointer()

        return item.data(index.column())
    def unit_ui(self):

        # 先设置一个垂直布局    注意QMainWindow有自己的布局所以如果用QMainWindow直接addLayout即可
        v_layout = QVBoxLayout()
        self.setLayout(v_layout)

        # 设置一个水平布局放三个按钮
        h_layout = QHBoxLayout()
        # 水平布局放入整体的处置布局
        v_layout.addLayout(h_layout)

        # 水平布局放三个按钮
        add_button = QPushButton('添加节点')
        update_button = QPushButton('更新节点')
        delete_button = QPushButton('删除节点')

        h_layout.addWidget(add_button)
        h_layout.addWidget(update_button)
        h_layout.addWidget(delete_button)

        # 创建树控件
        v_layout.addWidget(self.tree_widget)

        # 设置列数
        self.tree_widget.setColumnCount(2)

        # 设置成中心控件     注意在QMainWindow才能设置,QWidget不可以。
        # self.setCentralWidget(self.tree_widget)

        # 设置标签
        self.tree_widget.setHeaderLabels(['介绍', '功能'])
        self.tree_widget.setHeaderHidden(True)

        # 添加节点两种方式
        self.root1.setIcon(0, QIcon('../images/root.png'))
        root2 = QTreeWidgetItem(self.tree_widget)
        root2.setText(0, 'root2')  # 指定第几列
        root2.setIcon(0, QIcon('../images/root.png'))
        # QTreeWidgetItem.Type()

        # 添加子节点
        child1 = QTreeWidgetItem(self.root1, ['child1', 'action'])
        # 设置子节点可选
        child1.setCheckState(0, Qt.CheckState(2))
        child2 = QTreeWidgetItem(root2, ['child2', 'action'])
        # 节点对齐缩进距离
        child2.setTextAlignment(0, 1)
        # 设置节点宽度
        self.tree_widget.setColumnWidth(0, 300)
        # 让节点全部展开
        self.tree_widget.expandAll()

        # 绑定事件
        add_button.clicked.connect(self.add_node)
        update_button.clicked.connect(self.update_node)
        delete_button.clicked.connect(self.delete_node)
示例#7
0
 def _initdata(self):
     data = self.db.listApps()
     self.listWidget.clear()
     # self.listWidget.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
     for idx, acc in enumerate(data):
         _id, appid, app_name, check = acc
         item = QtWidgets.QListWidgetItem()
         item.setText(str(idx + 1) + "    " + app_name + "    " + appid)
         if int(check) == 1:
             item.setCheckState(Qt.CheckState(2))
         else:
             item.setCheckState(Qt.CheckState(0))
         item.setData(1, appid)
         self.listWidget.addItem(item)
     today = QDate.currentDate()
     self.DateEdit.setDate(today)
     self.DateEdit.setCalendarPopup(True)
     self.DateEdit_2.setDate(today.addDays(-5))
     self.DateEdit_2.setEnabled(False)
示例#8
0
    def eventFilter(self, obj, event):
        """Reimplemented."""
        if self.__popupIsShown and \
                event.type() == QEvent.MouseMove and \
                self.view().isVisible() and self.__initialMousePos is not None:
            diff = obj.mapToGlobal(event.pos()) - self.__initialMousePos
            if diff.manhattanLength() > 9 and \
                    self.__blockMouseReleaseTimer.isActive():
                self.__blockMouseReleaseTimer.stop()
            # pass through

        if self.__popupIsShown and \
                event.type() == QEvent.MouseButtonRelease and \
                self.view().isVisible() and \
                self.view().rect().contains(event.pos()) and \
                self.view().currentIndex().isValid() and \
                self.view().currentIndex().flags() & Qt.ItemIsSelectable and \
                self.view().currentIndex().flags() & Qt.ItemIsEnabled and \
                self.view().currentIndex().flags() & Qt.ItemIsUserCheckable and \
                self.view().visualRect(self.view().currentIndex()).contains(event.pos()) and \
                not self.__blockMouseReleaseTimer.isActive():
            model = self.model()
            index = self.view().currentIndex()
            state = model.data(index, Qt.CheckStateRole)
            model.setData(index,
                          Qt.Checked if state == Qt.Unchecked else Qt.Unchecked,
                          Qt.CheckStateRole)
            self.view().update(index)
            self.update()
            self.flagChanged.emit(index.row(),state == Qt.Unchecked)
            return True

        if self.__popupIsShown and event.type() == QEvent.KeyPress:
            if event.key() == Qt.Key_Space:
                # toogle the current items check state
                model = self.model()
                index = self.view().currentIndex()
                flags = model.flags(index)
                state = model.data(index, Qt.CheckStateRole)
                if flags & Qt.ItemIsUserCheckable and \
                        flags & Qt.ItemIsTristate:
                    state = Qt.CheckState((int(state) + 1) % 3)
                elif flags & Qt.ItemIsUserCheckable:
                    state = Qt.Checked if state != Qt.Checked else Qt.Unchecked
                model.setData(index, state, Qt.CheckStateRole)
                self.view().update(index)
                self.update()
                self.flagChanged.emit(index.row(),state != Qt.Unchecked)
                return True
            # TODO: handle Qt.Key_Enter, Key_Return?

        return super(CheckComboBox, self).eventFilter(obj, event)
示例#9
0
 def itemCheckState(self, index):
     """
     Return the check state for item at `index`
     Parameters
     ----------
     index : int
     Returns
     -------
     state : Qt.CheckState
     """
     state = self.itemData(index, role=Qt.CheckStateRole)
     if isinstance(state, int):
         return Qt.CheckState(state)
     else:
         return Qt.Unchecked
示例#10
0
 def generateArtifactStimuliSequence(self):
     
     lstOrder = []
     time = 0
     
     
     for i in range(self.amountOfTrials):
         if int(self.randomizeStimuli) == Qt.CheckState(Qt.Checked):
             random.shuffle(self.all_stimuli_list)
         all_stimuli_list = iter(self.all_stimuli_list)
         if (time != 0):
             lstOrder.append({'start_time':str(time),'end_time':str(time+self.pauseBetweenTrials),'type':PAUSEBETWEENTRIALSTEXT})
             time+=self.pauseBetweenTrials
             
         for num in range(self.amount_of_stimuli):
             lstOrder.append({'start_time':str(time),'end_time':str(time+float(self.pauseDuration)),'type':PAUSETEXT})
             time+=float(self.pauseDuration)
             
             artifact_name = all_stimuli_list.__next__()
             lstOrder.append({'start_time':str(time),'end_time':str(time+float(self.stimulusDuration)),
                                           'type':artifact_name})
             time+=float(self.stimulusDuration)
     
     return lstOrder
示例#11
0
 def _clearCheck(self):
     items_len = self.listWidget.count()
     for index in range(0, items_len):
         self.listWidget.item(index).setCheckState(Qt.CheckState(0))
示例#12
0
 def _onoffCheck(self, click_item: QtWidgets.QListWidgetItem):
     state = 2 if int(click_item.checkState()) == 0 else 0
     click_item.setCheckState(Qt.CheckState(state))
     return True
def test_delete_add_stations(downloader_bot, mocker):
    wxdata_downloader, qtbot = downloader_bot
    station_table = wxdata_downloader.station_table

    dirname = os.path.join(os.getcwd(), "@ new-prô'jèt!")
    fname = os.path.join(dirname, "weather_station_list.lst")

    # Load a station list from file.
    original_list = wxdata_downloader.load_stationList(fname)

    # Try to delete stations when no station are selected.
    wxdata_downloader.btn_delSta_isClicked()

    # Select stations MONT ST HILAIRE, MONTREAL/ST-HUBERT A, and ROUGEMONT
    # in the list and delete them.
    expected_results = [[
        "L'ACADIE", "10843", "1994", "2018", "QC", "702LED4", '45.29',
        '-73.35', '43.8'
    ],
                        [
                            "STE MADELEINE", "5501", "1979", "2016", "QC",
                            "7027517", '45.62', '-73.13', '30.0'
                        ],
                        [
                            "SABREVOIS", "5444", "1975", "2018", "QC",
                            "7026734", '45.22', '-73.2', '38.1'
                        ],
                        [
                            "MARIEVILLE", "5406", "1960", "2018", "QC",
                            "7024627", '45.4', '-73.13', '38.0'
                        ],
                        [
                            "LAPRAIRIE", "5389", "1963", "2018", "QC",
                            "7024100", '45.38', '-73.43', '30.0'
                        ],
                        [
                            "IBERVILLE", "5376", "1963", "2016", "QC",
                            "7023270", '45.33', '-73.25', '30.5'
                        ],
                        [
                            "FARNHAM", "5358", "1917", "2018", "QC", "7022320",
                            '45.3', '-72.9', '68.0'
                        ]]

    for row in [2, 4, 5]:
        item = station_table.cellWidget(row, 0).layout().itemAtPosition(1, 1)
        widget = item.widget()
        qtbot.mouseClick(widget, Qt.LeftButton)
    wxdata_downloader.btn_delSta_isClicked()
    assert expected_results == station_table.get_stationlist()

    # Save station list.
    fname = os.path.join(dirname, "cleaned_station_list.lst")
    mocker.patch.object(QFileDialog,
                        'getSaveFileName',
                        return_value=(fname, "*.lst"))
    wxdata_downloader.btn_saveAs_staList_isClicked()
    wxdata_downloader.btn_save_staList_isClicked()

    # Add back the stations that were deleted.
    expected_results = [[
        "L'ACADIE", "10843", "1994", "2018", "QC", "702LED4", '45.29',
        '-73.35', '43.8'
    ],
                        [
                            "STE MADELEINE", "5501", "1979", "2016", "QC",
                            "7027517", '45.62', '-73.13', '30.0'
                        ],
                        [
                            "SABREVOIS", "5444", "1975", "2018", "QC",
                            "7026734", '45.22', '-73.2', '38.1'
                        ],
                        [
                            "MARIEVILLE", "5406", "1960", "2018", "QC",
                            "7024627", '45.4', '-73.13', '38.0'
                        ],
                        [
                            "LAPRAIRIE", "5389", "1963", "2018", "QC",
                            "7024100", '45.38', '-73.43', '30.0'
                        ],
                        [
                            "IBERVILLE", "5376", "1963", "2016", "QC",
                            "7023270", '45.33', '-73.25', '30.5'
                        ],
                        [
                            "FARNHAM", "5358", "1917", "2018", "QC", "7022320",
                            '45.3', '-72.9', '68.0'
                        ],
                        [
                            "MONTREAL/ST-HUBERT A", "5490", "1928", "2015",
                            "QC", "7027320", '45.52', '-73.42', '27.4'
                        ],
                        [
                            "ROUGEMONT", "5442", "1956", "1985", "QC",
                            "7026700", '45.43', '-73.1', '39.9'
                        ],
                        [
                            "MONT ST HILAIRE", "5423", "1960", "1969", "QC",
                            "7025330", '45.55', '-73.08', '173.7'
                        ]]

    wxdata_downloader.add_stations2list(original_list)
    assert expected_results == station_table.get_stationlist()

    # Clear completely the station list.
    station_table.chkbox_header.setCheckState(Qt.CheckState(True))
    assert len(station_table.get_checked_rows()) == len(expected_results)

    wxdata_downloader.btn_delSta_isClicked()
    assert [] == station_table.get_stationlist()

    # Add back the stations that were deleted.
    wxdata_downloader.add_stations2list(original_list)
    assert original_list == station_table.get_stationlist()