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 start_gui(self, args): crypt_key = args.encryption if crypt_key is None: input_dialog = QInputDialog() input_dialog.setInputMode(QInputDialog.TextInput) input_dialog.setCancelButtonText("No Password") input_dialog.setLabelText("Please enter your Masterpassword") input_dialog.setWindowTitle("Masterpassword") input_dialog.setModal(False) while crypt_key is None: if input_dialog.exec_() == QInputDialog.Rejected: crypt_key = u"0238jh74ngz23v84m90fcqewmn4f89" else: crypt_key = input_dialog.textValue().strip() if not QtStarter.check_master_password(crypt_key): crypt_key = None input_dialog.setLabelText("Wrong Masterpassword, try again!") QtStarter.save_masterpassword_check(crypt_key) crypt = Coding(crypt_key.encode('utf-8')) self.window = ControlMainWindow(crypt) self.timer = threading.Timer(0.001, self.update_server_status, kwargs={'window': self.window}).start() self.window.show() ret = self.app.exec_() if self.timer is not None: self.timer.cancel() return ret
async def attempt_join(self): if not self.visible_sessions: return session = self.selected_session if session.has_password: dialog = QInputDialog(self) dialog.setWindowTitle("Enter password") dialog.setLabelText("This session requires a password:"******"Incorrect Password", "The password entered was incorrect.")
def annotate_state(self, id): dialog = QInputDialog() dialog.setInputMode(QInputDialog.TextInput) dialog.setLabelText("Annotation:") dialog.resize(400, 100) if dialog.exec_(): self.store_annotation(id, dialog.textValue()) self.redraw_graph()
def add_rule(self): input = QInputDialog(self.window) input.setWindowTitle("Add exclude rule") input.setLabelText("Exclude rule (eg: C:\\Users\\*\\Volumes\\*.iso)") if input.exec_(): exclude_rule = input.textValue() exclude_rule = exclude_rule.replace(os.sep, "/") self.exclude_rules.add(exclude_rule) self.reload_exclude_rules()
def on_add(self): dialog = QInputDialog(self) dialog.setLabelText("Enter appconfig.json URL") if dialog.exec_() == QInputDialog.Rejected: return app_url = dialog.textValue().strip() self.host.app_store.add_app_ui([app_url])
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 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 get_text(parent=None, title='Input Text Value', label='Value:', default_value=None): input_dialog = QInputDialog(parent) input_dialog.setInputMode(InputDialog.TextInput) input_dialog.setWindowTitle(title) input_dialog.setLabelText(label) input_dialog.setOkButtonText('确定') input_dialog.setCancelButtonText('取消') if parent: input_dialog.setFont(parent.font()) return default_value if not input_dialog.exec_( ) else input_dialog.textValue()
def get_auth_code(self, opener, request): """ :param opener: urllib.request.build_opener for sending an authcode per mail :param request: request to send using the given opener :return: the authcode """ inputDialog = QInputDialog(self) inputDialog.setInputMode(QInputDialog.TextInput) inputDialog.setCancelButtonText("Cancel") inputDialog.setLabelText("Please enter your Authcode") inputDialog.setWindowTitle("TwoFactorAuth") inputDialog.setModal(True) response = None if inputDialog.exec_() == QInputDialog.Rejected: # send mail return None, None else: return response, inputDialog.textValue().strip() inputDialog.setCancelButtonText("Cancel") if inputDialog.exec_() == QInputDialog.Rejected: return response, None return response, inputDialog.textValue().strip()
def on_mkdir(self): dialog = QInputDialog(self) dialog.setLabelText("Directory name") if dialog.exec_() == QInputDialog.Rejected: return dirname = dialog.textValue().strip() if not dirname or "/" in dirname: QMessageBox.critical(self, "Invalid input", "This directory name cannot be used") return self.host.app_store.mkdir(dirname)
def get_charname(self): """ :param mailurl: url to call for sending an authcode per mail :return: the authcode """ inputDialog = QInputDialog(self) inputDialog.setInputMode(QInputDialog.TextInput) inputDialog.setLabelText("Please enter a Charname") inputDialog.setWindowTitle("Charname Challange") inputDialog.setModal(True) if inputDialog.exec_() == QInputDialog.Rejected: return None return inputDialog.textValue().strip()
async def _host_game_session(self): if await self._game_session_active(): return if not await self._ensure_logged_in(): return dialog = QInputDialog(self) dialog.setModal(True) dialog.setWindowTitle("Enter session name") dialog.setLabelText("Select a name for the session:") if await async_dialog.execute_dialog(dialog) != dialog.Accepted: return await self.network_client.create_new_session(dialog.textValue()) self.game_session_window = await GameSessionWindow.create_and_update( self.network_client, common_qt_lib.get_game_connection(), self.preset_manager, self, self._options) if self.game_session_window is not None: self.game_session_window.show()
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 snip(bounding_box=None, file_name_pattern=DEFAULT_OUTPUT_FILE_NAME_PATTERN, override=False, show_time=1000, assign_description=0): """ Snip screen image and save it to file. :param bounding_box: [tuple] The image rectangle in screen, formatted in (left, upper, width, height). :param file_name_pattern: [string] The file name pattern (absolute path or relative path to this python script file). For example: "ScreenSnippingImages/ScreenSnippingImage_%Y-%m-%d_%H-%M-%S.png". :param override: [bool] Whether to override the output file if it exists before. :param show_time: [int] Milliseconds time to show the screen image (if 0, the image won't be shown). :param assign_description: [int] Whether to assign description to the screen image (1 for manually input, 2 for OCR, others for no description). """ logging.info("Started snipping screen.") screen_image = get_screen_image(bounding_box=bounding_box) file_name = save_image(image=screen_image, file_name_pattern=file_name_pattern, override=override) if file_name: logging.info( "Screen image has been saved in file: {}".format(file_name)) if show_time > 0: image_dialog = QDialog() image_dialog.setWindowTitle(APP_DESCRIPTION + " " + APP_VERSION) image_dialog.setWindowFlags(Qt.WindowStaysOnTopHint) image_dialog.setFixedSize(640, 360) image_dialog.setContentsMargins(0, 0, 0, 0) image_label = QLabel() image_dialog_layout = QGridLayout(image_dialog) image_dialog_layout.setContentsMargins(0, 0, 0, 0) image_dialog_layout.addWidget(image_label) image_label.setPixmap(screen_image) image_label.setScaledContents(True) QTimer().singleShot(10, image_dialog.activateWindow) QTimer().singleShot(show_time, image_dialog.close) image_dialog.exec() if assign_description == 1: description_input_dialog = QInputDialog() description_input_dialog.setWindowTitle(APP_DESCRIPTION + " " + APP_VERSION) description_input_dialog.setWindowFlags( Qt.WindowStaysOnTopHint) description_input_dialog.setFixedSize(400, 200) description_input_dialog.setInputMode( description_input_dialog.TextInput) description_input_dialog.setLabelText( "Please input description:") QTimer().singleShot(10, description_input_dialog.activateWindow) description_input_dialog.exec() description = description_input_dialog.textValue() if description: description_file_name = file_name + ".txt" with open(description_file_name, "w") as file: file.write(description) logging.info( "Assigned a description for screen image file: {}". format(file_name)) logging.debug("Description: {}".format(description)) elif assign_description == 2: import pytesseract text_from_image = pytesseract.image_to_string( Image.open(file_name)) description_file_name = file_name + "-OCR.txt" with open(description_file_name, "w") as file: file.write(text_from_image) os.startfile(description_file_name) else: pass else: logging.error("Error occurred.")
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)