def remove_templates(self, event):
print_and_log(['Deleting templates: %s' %str(sorted(self.inspect_templates))], 'default', logger)
self.app.setOverrideCursor(QCursor(Qt.WaitCursor))
if len(self.inspect_templates) > 0:
self.to_delete = numpy.concatenate((self.to_delete, self.to_consider[self.inspect_templates]))
self.generate_data()
self.collections = None
self.selected_points = set()
self.selected_templates = set()
self.inspect_points = set()
self.inspect_templates = set()
self.score_ax1.clear()
self.score_ax2.clear()
self.score_ax3.clear()
self.update_lag(self.use_lag)
self.update_data_sort_order()
self.update_detail_plot()
self.update_waveforms()
self.plot_scores()
# do lengthy process
self.app.restoreOverrideCursor()
python类WaitCursor()的实例源码
def makeLSA(self):
self.calculator.setConfiguration(self.configurations)
self.calculator.lsa_components_count = self.lsa_components_count.value()
self.buttonMakeLSA.setEnabled(False)
self.button2DView.setEnabled(False)
self.buttonRelationTable.setEnabled(False)
QApplication.setOverrideCursor(Qt.WaitCursor)
self.textEdit.setText("")
self.configurations['need_full_preprocessing'] = self.radio_preprocessing_full.isChecked()
self.configurations["minimal_word_size"] = self.spinBoxMinimalWordsLen.value()
self.configurations["cut_ADJ"] = self.checkBoxPrilag.isChecked()
self.configurations["need_apriori"] = self.checkBoxNeedApriori.isChecked()
self.radio_preprocessing_full.setEnabled(False)
self.radio_preprocessing_stopwords.setEnabled(False)
self.groupBoxFullPreprocessingPanel.setEnabled(False)
self.profiler.start()
self.calculator.start()
def makeClassification(self):
QApplication.setOverrideCursor(Qt.WaitCursor)
self.textEdit.setText("")
self.checkBoxNeedPreprocessing.setEnabled(False)
need_preprocessing = self.checkBoxNeedPreprocessing.isChecked()
self.configurations['classification_knn_k'] = self.spinBox_KNN_K.value()
if self.radioButtonNaiveBayes.isChecked():
self.calculator.setMethod(ClassificationCalculator.METHOD_NAIVE_BAYES, need_preprocessing)
if self.radioButtonRocchio.isChecked():
self.calculator.setMethod(ClassificationCalculator.METHOD_ROCCHIO, need_preprocessing)
if self.radioButtonKNN.isChecked():
self.calculator.setMethod(ClassificationCalculator.METHOD_KNN, need_preprocessing)
if self.radioButtonLLSF.isChecked():
self.calculator.setMethod(ClassificationCalculator.METHOD_LLSF, need_preprocessing)
if self.radioButtonID3.isChecked():
self.calculator.setMethod(ClassificationCalculator.METHOD_ID3, need_preprocessing)
self.profiler.start()
self.calculator.start()
def start(self):
self.startButton.setEnabled(False)
QApplication.setOverrideCursor(Qt.WaitCursor)
self.bytesWritten = 0
self.bytesReceived = 0
while not self.tcpServer.isListening() and not self.tcpServer.listen():
ret = QMessageBox.critical(self, "Loopback",
"Unable to start the test: %s." % self.tcpServer.errorString(),
QMessageBox.Retry | QMessageBox.Cancel)
if ret == QMessageBox.Cancel:
return
self.serverStatusLabel.setText("Listening")
self.clientStatusLabel.setText("Connecting")
self.tcpClient.connectToHost(QHostAddress(QHostAddress.LocalHost), self.tcpServer.serverPort())
def modelFromFile(self, fileName):
f = QFile(fileName)
if not f.open(QFile.ReadOnly):
return QStringListModel(self.completer)
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
words = []
while not f.atEnd():
line = f.readLine().trimmed()
if line.length() != 0:
try:
line = str(line, encoding='ascii')
except TypeError:
line = str(line)
words.append(line)
QApplication.restoreOverrideCursor()
return QStringListModel(words, self.completer)
def save(self):
filename, _ = QFileDialog.getSaveFileName(self,
"Choose a file name", '.', "HTML (*.html *.htm)")
if not filename:
return
file = QFile(filename)
if not file.open(QFile.WriteOnly | QFile.Text):
QMessageBox.warning(self, "Dock Widgets",
"Cannot write file %s:\n%s." % (filename, file.errorString()))
return
out = QTextStream(file)
QApplication.setOverrideCursor(Qt.WaitCursor)
out << self.textEdit.toHtml()
QApplication.restoreOverrideCursor()
self.statusBar().showMessage("Saved '%s'" % filename, 2000)
def start(self):
self.startButton.setEnabled(False)
QApplication.setOverrideCursor(Qt.WaitCursor)
self.bytesWritten = 0
self.bytesReceived = 0
while not self.tcpServer.isListening() and not self.tcpServer.listen():
ret = QMessageBox.critical(self, "Loopback",
"Unable to start the test: %s." % self.tcpServer.errorString(),
QMessageBox.Retry | QMessageBox.Cancel)
if ret == QMessageBox.Cancel:
return
self.serverStatusLabel.setText("Listening")
self.clientStatusLabel.setText("Connecting")
self.tcpClient.connectToHost(QHostAddress(QHostAddress.LocalHost), self.tcpServer.serverPort())
def modelFromFile(self, fileName):
f = QFile(fileName)
if not f.open(QFile.ReadOnly):
return QStringListModel(self.completer)
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
words = []
while not f.atEnd():
line = f.readLine().trimmed()
if line.length() != 0:
try:
line = str(line, encoding='ascii')
except TypeError:
line = str(line)
words.append(line)
QApplication.restoreOverrideCursor()
return QStringListModel(words, self.completer)
def save(self):
filename, _ = QFileDialog.getSaveFileName(self,
"Choose a file name", '.', "HTML (*.html *.htm)")
if not filename:
return
file = QFile(filename)
if not file.open(QFile.WriteOnly | QFile.Text):
QMessageBox.warning(self, "Dock Widgets",
"Cannot write file %s:\n%s." % (filename, file.errorString()))
return
out = QTextStream(file)
QApplication.setOverrideCursor(Qt.WaitCursor)
out << self.textEdit.toHtml()
QApplication.restoreOverrideCursor()
self.statusBar().showMessage("Saved '%s'" % filename, 2000)
def exec_process(self):
if os.path.exists(self.dirname):
try:
QApplication.setOverrideCursor(Qt.WaitCursor)
self.fileList.setup(self.dirname, '.py')
maxCnt = self.fileList.length
self.pbar.setValue(0)
self.pbar.setMinimum(0)
self.pbar.setMaximum(maxCnt)
self.fileList.start()
except Exception as e:
self.print_log(str(e))
finally:
QApplication.restoreOverrideCursor()
else:
self.print_log('{0} is not exists'.format(self.dirname))
def read_opened_filenames(self):
if self.project_file is not None:
tree = ET.parse(self.project_file)
root = tree.getroot()
file_names = []
for file_tag in root.findall("open_file"):
pos = int(file_tag.attrib["position"])
filename = os.path.normpath(os.path.join(self.project_path, file_tag.attrib["name"]))
file_names.insert(pos, filename)
QApplication.setOverrideCursor(Qt.WaitCursor)
file_names = FileOperator.uncompress_archives(file_names, QDir.tempPath())
QApplication.restoreOverrideCursor()
return file_names
return []
def draw_spectrogram(self, show_full_scene=False, force_redraw=False):
self.setCursor(Qt.WaitCursor)
window_size = 2 ** self.ui.sliderFFTWindowSize.value()
data_min, data_max = self.ui.sliderSpectrogramMin.value(), self.ui.sliderSpectrogramMax.value()
redraw_needed = self.ui.gvSpectrogram.scene_manager.set_parameters(self.signal.data, window_size=window_size,
data_min=data_min, data_max=data_max)
self.ui.gvSpectrogram.scene_manager.update_scene_rect()
if show_full_scene:
self.ui.gvSpectrogram.show_full_scene()
if redraw_needed or force_redraw:
self.ui.gvSpectrogram.scene_manager.show_full_scene()
self.ui.gvSpectrogram.show_full_scene()
self.on_slider_y_scale_value_changed()
self.__set_samples_in_view()
self.unsetCursor()
def contextMenuEvent(self, event: QContextMenuEvent):
if self.signal is None:
return
menu = QMenu()
apply_to_all_action = menu.addAction(self.tr("Apply values (BitLen, 0/1-Threshold, Tolerance) to all signals"))
menu.addSeparator()
auto_detect_action = menu.addAction(self.tr("Auto-Detect signal parameters"))
action = menu.exec_(self.mapToGlobal(event.pos()))
if action == apply_to_all_action:
self.setCursor(Qt.WaitCursor)
self.apply_to_all_clicked.emit(self.signal)
self.unsetCursor()
elif action == auto_detect_action:
self.setCursor(Qt.WaitCursor)
self.signal.auto_detect()
self.unsetCursor()
def handle_signal_loaded(self, protocol):
self.setCursor(Qt.WaitCursor)
self.ui.cbShowDataBitsOnly.setEnabled(True)
self.ui.chkBoxLockSIV.setEnabled(True)
self.ui.btnAutoDetect.setEnabled(True)
self.protocol = protocol
# Apply bit length of original signal to current modulator
self.ui.spinBoxBitLength.setValue(self.ui.gVOriginalSignal.signal.bit_len)
# https://github.com/jopohl/urh/issues/130
self.ui.gVModulated.show_full_scene(reinitialize=True)
self.ui.gVCarrier.show_full_scene(reinitialize=True)
self.ui.gVData.show_full_scene(reinitialize=True)
self.unsetCursor()
def draw_sine_wave(self):
if self.dialog_ui.graphicsViewSineWave.scene_manager:
self.dialog_ui.graphicsViewSineWave.scene_manager.clear_path()
QApplication.instance().setOverrideCursor(Qt.WaitCursor)
self.__set_status_of_editable_elements(enabled=False)
t = np.arange(0, self.num_samples) / self.sample_rate
arg = ((2 * np.pi * self.frequency * t + self.phase) * 1j).astype(np.complex64)
self.complex_wave = self.amplitude * np.exp(arg) # type: np.ndarray
self.draw_data = np.insert(self.original_data, self.position, self.complex_wave).imag.astype(np.float32)
y, h = self.dialog_ui.graphicsViewSineWave.view_rect().y(), self.dialog_ui.graphicsViewSineWave.view_rect().height()
self.insert_indicator.setRect(self.position, y - h, self.num_samples, 2 * h + abs(y))
self.__set_status_of_editable_elements(enabled=True)
QApplication.instance().restoreOverrideCursor()
self.dialog_ui.graphicsViewSineWave.plot_data(self.draw_data)
self.dialog_ui.graphicsViewSineWave.show_full_scene()
def start(self):
self.startButton.setEnabled(False)
QApplication.setOverrideCursor(Qt.WaitCursor)
self.bytesWritten = 0
self.bytesReceived = 0
while not self.tcpServer.isListening() and not self.tcpServer.listen():
ret = QMessageBox.critical(self, "Loopback",
"Unable to start the test: %s." % self.tcpServer.errorString(),
QMessageBox.Retry | QMessageBox.Cancel)
if ret == QMessageBox.Cancel:
return
self.serverStatusLabel.setText("Listening")
self.clientStatusLabel.setText("Connecting")
self.tcpClient.connectToHost(QHostAddress(QHostAddress.LocalHost), self.tcpServer.serverPort())
def modelFromFile(self, fileName):
f = QFile(fileName)
if not f.open(QFile.ReadOnly):
return QStringListModel(self.completer)
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
words = []
while not f.atEnd():
line = f.readLine().trimmed()
if line.length() != 0:
try:
line = str(line, encoding='ascii')
except TypeError:
line = str(line)
words.append(line)
QApplication.restoreOverrideCursor()
return QStringListModel(words, self.completer)
def save(self):
filename, _ = QFileDialog.getSaveFileName(self,
"Choose a file name", '.', "HTML (*.html *.htm)")
if not filename:
return
file = QFile(filename)
if not file.open(QFile.WriteOnly | QFile.Text):
QMessageBox.warning(self, "Dock Widgets",
"Cannot write file %s:\n%s." % (filename, file.errorString()))
return
out = QTextStream(file)
QApplication.setOverrideCursor(Qt.WaitCursor)
out << self.textEdit.toHtml()
QApplication.restoreOverrideCursor()
self.statusBar().showMessage("Saved '%s'" % filename, 2000)
def process_started(self):
# Disable everything except for the stop button and the output area
all_children = [obj for obj in self.ui.findChildren(QWidget)
if isinstance(obj, (QCheckBox, QPushButton, QLineEdit))]
self._previous_state = [(obj, obj.isEnabled()) for obj in all_children]
for obj in all_children:
obj.setEnabled(False)
self.ui.btn_stop.setEnabled(True)
# If we let the user interact, this messes with the cursor we use to
# support the progress bar display
self.ui.edit_stdout.setTextInteractionFlags(Qt.NoTextInteraction)
self.app.setOverrideCursor(Qt.WaitCursor)
def suggest_pairs(self, event):
self.inspect_points = set()
indices = numpy.where(self.score_y > numpy.maximum(0, self.score_z-self.suggest_value))[0]
self.app.setOverrideCursor(QCursor(Qt.WaitCursor))
self.update_inspect(indices, add_or_remove='add')
self.app.restoreOverrideCursor()
def lockGUI(self, locked: bool) -> None:
if locked:
qApp.setOverrideCursor(Qt.WaitCursor)
self.parent.cliplist.setEnabled(False)
self.parent.parent.setEnabled(False)
self.blockSignals(True)
else:
self.blockSignals(False)
self.parent.parent.setEnabled(True)
self.parent.cliplist.setEnabled(True)
qApp.restoreOverrideCursor()
def showKeyframes(self):
qApp.setOverrideCursor(Qt.WaitCursor)
keyframes = self.parent.videoService.getKeyframes(self.media, formatted_time=True)
kframes = KeyframesDialog(keyframes, self)
kframes.show()
def makeClassification(self):
QApplication.setOverrideCursor(Qt.WaitCursor)
self.textEdit.setText("")
self.checkBoxNeedPreprocessing.setEnabled(False)
self.calculator.knn_n_neighbors = self.knn_n_neighbors.value()
self.calculator.linear_svm_c = self.linear_svm_c.value()
self.calculator.rbf_svm_c = self.rbf_svm_c.value()
self.calculator.need_preprocessing = self.checkBoxNeedPreprocessing.isChecked()
self.calculator.method_index = self.tabWidget.currentIndex()
self.profiler.start()
self.calculator.start()
def processIt(self):
self.buttonProcess.setEnabled(False)
QApplication.setOverrideCursor(Qt.WaitCursor)
self.textEdit.setText("")
self.calculator.need_preprocessing = self.checkBoxEnablePreprocessing.isChecked()
self.calculator.need_apriori = self.checkBoxNeedApriori.isChecked()
self.calculator.min_support = self.spinBoxMinSupport.value()
self.calculator.min_conf = self.spinBoxMinConf.value()
self.profiler.start()
self.calculator.start()
def process_it(self):
self.buttonProcess.setEnabled(False)
QApplication.setOverrideCursor(Qt.WaitCursor)
self.progressBar.setValue(0)
self.textEdit.setText("")
self.calculator.result_sentence_count = self.spinBoxOutputSentenceCount.value()
if(self.radioButtonMethodWordsSum.isChecked()):
self.calculator.setCalculationMethod(AnnotationMakerCalculator.METHOD_BY_WORDS_SUM)
if (self.radioButtonMethodSentenceValue.isChecked()):
self.calculator.setCalculationMethod(AnnotationMakerCalculator.METHOD_BY_SENTENCE_VALUE )
self.profiler.start()
self.calculator.start()
def loadFile(self, fileName):
file = QFile(fileName)
if not file.open( QFile.ReadOnly | QFile.Text):
QMessageBox.warning(self, "Recent Files",
"Cannot read file %s:\n%s." % (fileName, file.errorString()))
return
instr = QTextStream(file)
QApplication.setOverrideCursor(Qt.WaitCursor)
self.textEdit.setPlainText(instr.readAll())
QApplication.restoreOverrideCursor()
self.setCurrentFile(fileName)
self.statusBar().showMessage("File loaded", 2000)
def saveFile(self, fileName):
file = QFile(fileName)
if not file.open( QFile.WriteOnly | QFile.Text):
QMessageBox.warning(self, "Recent Files",
"Cannot write file %s:\n%s." % (fileName, file.errorString()))
return
outstr = QTextStream(file)
QApplication.setOverrideCursor(Qt.WaitCursor)
outstr << self.textEdit.toPlainText()
QApplication.restoreOverrideCursor()
self.setCurrentFile(fileName)
self.statusBar().showMessage("File saved", 2000)
def loadFile(self, fileName):
file = QFile(fileName)
if not file.open( QFile.ReadOnly | QFile.Text):
QMessageBox.warning(self, "Recent Files",
"Cannot read file %s:\n%s." % (fileName, file.errorString()))
return
instr = QTextStream(file)
QApplication.setOverrideCursor(Qt.WaitCursor)
self.textEdit.setPlainText(instr.readAll())
QApplication.restoreOverrideCursor()
self.setCurrentFile(fileName)
self.statusBar().showMessage("File loaded", 2000)
def saveFile(self, fileName):
file = QFile(fileName)
if not file.open( QFile.WriteOnly | QFile.Text):
QMessageBox.warning(self, "Recent Files",
"Cannot write file %s:\n%s." % (fileName, file.errorString()))
return
outstr = QTextStream(file)
QApplication.setOverrideCursor(Qt.WaitCursor)
outstr << self.textEdit.toPlainText()
QApplication.restoreOverrideCursor()
self.setCurrentFile(fileName)
self.statusBar().showMessage("File saved", 2000)
def resize_me(self):
QApplication.instance().setOverrideCursor(Qt.WaitCursor)
w = self.font().pointSize() + 2
for i in range(10):
self.setColumnWidth(i, 2 * w)
for i in range(10, self.model().col_count):
self.setColumnWidth(i, w * len(str(i + 1)))
QApplication.instance().restoreOverrideCursor()