def AddBookFromURL(self): # Create Resized Input Dialog dlg = QInputDialog() dlg.setInputMode(QInputDialog.TextInput) dlg.setLabelText('Enter URL:') dlg.setTextValue('https://www.readlightnovel.org/only-i-level-up') dlg.setWindowTitle('Add Novel') dlg.resize(500, 100) # If Cancelled if dlg.exec_() == 0: return # Get URL url = dlg.textValue() # Check URL if self.settings['MainURL'] not in url: print('{0} not in {1}'.format(self.settings['MainURL'], url)) return # Dump Info try: info = Utils.dumpInfo(url, self.settings) except AttributeError: print('Incorrect URL') return # Dump Cover Utils.dumpCover(info, self.settings) self.UpdateList()
def edit_watcher(self): index = self.watcherlist.currentRow() addr = self.workspace.cartprograph.watchers[index][0] dialog = QInputDialog() dialog.setInputMode(QInputDialog.TextInput) dialog.setLabelText("Edit watcher @ " + hex(addr) + ":") dialog.setTextValue(", ".join( self.workspace.cartprograph.watchers[index][1])) dialog.resize(500, 100) if dialog.exec_(): self.workspace.cartprograph.watchers[index][ 1] = self._process_registers(dialog.textValue()) self.update_watcherlist()
def connectStream(self): dlg = QInputDialog(self) dlg.setInputMode(QInputDialog.TextInput) dlg.setLabelText("URL:") dlg.setTextEchoMode(QLineEdit.Normal) dlg.setTextValue(self.current_stream) dlg.resize(400, 100) dlg.exec() if dlg.result() and validators.url( dlg.textValue()) and dlg.textValue() != self.current_stream: self.current_stream = dlg.textValue() self.player.setMedia(QUrl(self.current_stream)) elif dlg.result() and not validators.url(dlg.textValue()): msg_box = QMessageBox() msg_box.setText("Error URL. Please try again") msg_box.setWindowTitle("Error URL") msg_box.exec() self.connectStream()
def askGenericText(message, title, parent=None, previous=""): """Uses `QInputDialog` to ask a text answer for a given question. Parameters: message: the question to be displayed title: the window title parent (optional, default None): the parent of the window Output: return a tuple containing the text as first element and True/False (depending if the user selected "Ok" or "Cancel") as the second element """ dialog = QInputDialog(parent) dialog.setInputMode(QInputDialog.TextInput) dialog.setWindowTitle(title) dialog.setLabelText(message) dialog.setTextValue(previous) out = dialog.exec_() return dialog.textValue(), out
def _renameItem(self): item = self._list.currentItem() input_dialog = QInputDialog(self.parentWidget(), Qt.WindowSystemMenuHint | Qt.WindowTitleHint | Qt.WindowCloseButtonHint) font = input_dialog.font() font.setPixelSize(16) input_dialog.setFont(font) input_dialog.setMinimumWidth(300) input_dialog.setInputMode(QInputDialog.TextInput) input_dialog.setWindowTitle("Renommer l'analyse") input_dialog.setLabelText("Nouveau nom pour '%s' :" % item.data(Qt.UserRole + 1)) input_dialog.setTextValue(item.data(Qt.UserRole + 1)) input_dialog.setOkButtonText("OK") input_dialog.setCancelButtonText("Annuler") if not input_dialog.exec_(): return new_name = input_dialog.textValue() if self._analysis is None: return if new_name == self._analysis.parameters().name(): return regexp = QRegExp("^[a-zA-Z0-9_-#éèêëàîï ]{5,30}$") if not regexp.exactMatch(new_name): QMessageBox.warning(self, "Nouveau nom invalide", "Caractères autorisés : alphanumérique, espace, #, - et _ avec une longueur maximale de 30 caractères") return self._analysis.parameters().setName(new_name) HistoryManager.renameAnalysis(item.data(Qt.UserRole), self._analysis) current_row = self._list.currentRow() self.reset(self._analysis) self._list.setCurrentRow(current_row) self.currentAnalysisChanged.emit(self._analysis)
def set_text_value(dialog: QtWidgets.QInputDialog): dialog.setTextValue("magoo") return QtWidgets.QDialog.Accepted
def GenerateBook(self): wdgList = self.ui.wdgList # Get Selected List selected = [ item.text().split(' | ') for item in wdgList.selectedItems() ] if len(selected) <= 0: return # Dump not downloaded chapters notDumped = [x for x in selected if x[1][-1] != ']'] # Download chapters if not self.downloadChapters(notDumped): self.UpdateList() # If canceled stop epub generation return self.UpdateList() # Update selected list selected = [[x[0][1:], x[1][:-1]] for x in selected if x[1][-1] == ']'] selected += notDumped # Get dicts from Info dictionary chapters = [ chp for chp in self.info['chapters'] for volume, name in selected if name == chp['name'] and volume == chp['volume'] ] # Generate Title for book volume = chapters[0]['volume'] for chapter in chapters: if chapter['volume'] != volume or 'chapters' in volume.lower(): volume = 'Chapters:' title = self.info['title'] + ' ' + volume try: # If chapters are not from the same volume if volume == 'Chapters:': numbers = [ int( float(''.join(s for s in name if s.isdigit() or s == '.' or s == '-'))) for name in selected ] numbers = list(set(numbers)) # Generate ranges for number list ranges = Utils.ranges(numbers) for r in ranges: if r[0] == r[1]: title += ' {0},'.format(r[0]) else: title += ' {0} - {1},'.format(r[0], r[1]) if title[-1] == ',': title = title[:-1] except ValueError: pass # Show Title Input Dialog dlg = QInputDialog() dlg.setInputMode(QInputDialog.TextInput) dlg.setLabelText('Enter Title:') dlg.setWindowTitle('Select Book Title') dlg.setTextValue(title) dlg.resize(500, 100) # If Cancelled if dlg.exec_() == 0: return # Get URL title = dlg.textValue() # Show File Dialog ans = QFileDialog.getSaveFileName(caption='Save ePUB', filter='ePUB (*.epub)', dir=title + '.epub') filename = ans[0] # Add file format if not present if filename[-5:] != '.epub': filename += '.epub' # Generate ePUB file Utils.generateEPUB(filename, title, self.info, chapters, self.settings)