def get_resource_set_name(self, default=''): filename = QInputDialog.getText(self, 'Save Resource Set', 'Enter resource set name:', text=default)[0] while filename in self.remote_resources['sets']: filename = QInputDialog.getText(self, 'Save Resource Set', 'Reserved name, enter new name:', text=default)[0] if filename in self.resource_set_slugs: if QMessageBox.question( self, 'Overwrite?', 'Name in use, overwrite?') == QMessageBox.No: return return filename
def show_alternatives_dialog(self, bgg_play, data): """Show alternative games to use as the game to log a play""" alternatives_dialog = QInputDialog(self) alternatives_list = [ f'{item["nm_jogo"]} ({item["ano_publicacao"]})' for item in data ] alternatives_dialog.setComboBoxItems(alternatives_list) alternatives_dialog.setOption(QInputDialog.UseListViewForComboBoxItems) game_str = f'{bgg_play.game_name} ({bgg_play.year_published})' alternatives_dialog.setLabelText( f'Escolha uma alternativa para o jogo "{game_str}"') if alternatives_dialog.exec_(): selected_index = alternatives_list.index( alternatives_dialog.textValue()) return data[selected_index] return None
def slot_show_goto_dialog(self): (input_str, res) = QInputDialog.getText( self.dock, 'Goto', 'Enter local address to jump to') if res: # Parse as hex (TODO maybe as decimal, if no 0x and no ABCDEF) # TODO handle errors try: local_address = int(input_str, 16) except ValueError: # maybe it is a symbol? if self.symbols is not None: symbol = self.symbols.find_symbol_by_name(input_str) if symbol is not None: local_address = symbol.address else: QMessageBox.critical(self.parent(), 'Goto', f'{input_str} is not an address or symbol.') return else: QMessageBox.critical(self.parent(), 'Goto', f'{input_str} is not an address and symbols are not loaded for {self.rom_variant}.') return if local_address > ROM_OFFSET: local_address -= ROM_OFFSET # TODO error for everything that is not in [0x00000000, 0x00FFFFFF] or [0x08000000, 0x08FFFFFF] self.update_cursor(self.address_resolver.to_virtual(local_address))
def action_add_to_bookmarks_event(self): """ Adds the selected dir to the bookmark by the name the user gave it via a dialog. """ path = os.path.join(self.current_path, self.table_view.currentIndex().data()) if (os.path.isdir(path)): name, ok = QInputDialog().getText(self, 'Create new bookmark', 'Bookmark name:', text=self.table_view. currentIndex().data()) if (ok): if (name): self.bookmarks.add_bookmark(name, path) self.bookmark_view.reset() else: dialog = utility.message_dialog('Please enter name for' + ' the bookmark.', QMessageBox.Warning) dialog.exec() else: dialog = utility.message_dialog('Please select a directory, not' + ' a file, to create a bookmark.', QMessageBox.Warning) dialog.exec()
def reload_key_action(self): item = self.get_selected_item() key: Key = item.data() password = None if Key.need_password(key.path): ok_pressed = True while ok_pressed: password, ok_pressed = QInputDialog.getText( self, "需要密码", "输入密码:", QLineEdit.Password, "") if ok_pressed: illegal, msg = Key.is_password_illegal(password) if illegal: QMessageBox.information(self, '错误', msg) continue break else: return try: key.load(key.path, password) except Exception as e: QMessageBox.critical(self, '错误', '不是有效的密钥文件<br/>' + str(e)) return self.update_key_icon(item)
def slot_trigger_line_width(self): width = QInputDialog.getDouble( self, "Width selection", "Please pass decimal value from range 0.01 to 20.00 <br /> with maximally " "2 decimal places", self.graphicsView.actual_pen.width(), 0.01, 20.00, 2, Qt.WindowFlags(), 1.0) if width[1]: self.graphicsView.actual_pen.setWidthF(width[0])
def newFolder(self): (folderName, ok) = QInputDialog.getText(self, self.tr("Folder Name"), self.tr("Folder Name: ")) if ok and folderName: index = self.tree.selectionModel().currentIndex() selection = self.files.filePath(index) if QFileInfo(selection).isDir(): QDir(selection).mkdir(folderName) else: QDir(snippetPath).mkdir(folderName)
def open_registry_path(self): path, ok = QInputDialog.getText(self, "Open Registry Path", "Enter the path in the Windows registry:", QLineEdit.Normal, 'HKEY_CURRENT_USER\\') if ok and path != '': settings = QSettings(path, QSettings.NativeFormat) self.set_settings_object(settings) self.fallbacks_action.setEnabled(False)
def request_search_and_show_alternatives(self, session, bgg_play): """Request a new string to use for game search and then show results to be picked""" new_search_dialog = QInputDialog(self) game_str = f'{bgg_play.game_name} ({bgg_play.year_published})' new_search_dialog.setLabelText( f'Jogo "{game_str}" não encontrado\nBuscar por:') new_search_dialog.setInputMode(QInputDialog.TextInput) if new_search_dialog.exec_(): data = search_ludopedia_games(session, new_search_dialog.textValue()) data = self.show_alternatives_dialog(bgg_play, data) self.alternative_chosen.emit(data)
def _rename_area(self): new_name, did_confirm = QInputDialog.getText( self, "New Name", "Insert area name:", text=self.current_area.name) if not did_confirm or new_name == "" or new_name == self.current_area.name: return node_index = self.current_area.nodes.index(self.current_node) self.editor.rename_area(self.current_area, new_name) self.on_select_world() self.focus_on_area_by_name(new_name) self.focus_on_node(self.current_area.nodes[node_index])
def select_theme_action(self): path = resource_path("assets/themes") theme_files = [f for f in listdir(path) if isfile(join(path, f))] theme, ok = QInputDialog.getItem(self, "Experimental: Select Theme", "Choose theme to use from the list", theme_files, 0, False) if not ok: return with open(resource_path(f"assets/themes/{theme}"), "r") as fh: self.setStyleSheet(fh.read())
def on_addText_clicked(self): #TODO check if valid sequence if len(self.set.resources[self.active_idx].data) < 16: text = QInputDialog.getText(title='Enter Sequence As Text', label='Use ^ for on and _ for off') for character in text: if character not in ['^','_']: QMessageBox(title='Entry problem', text='Please only use ^ and _ in your entry') return self.set.resources[self.active_idx].add_data(text) self.update_resource_ui() self.unsaved_changes = True else: QMessageBox(title='Pattern full', text='Click a sequence to remove it.')
def _create_new_node(self, location: Optional[NodeLocation]): node_name, did_confirm = QInputDialog.getText(self, "New Node", "Insert node name:") if not did_confirm or node_name == "": return if self.current_area.node_with_name(node_name) is not None: if not self._warning_dialogs_disabled: QMessageBox.warning( self, "New Node", "A node named '{}' already exists.".format(node_name)) return self._do_create_node(node_name, location)
def newFileDialog(self): (snippetName, ok) = QInputDialog.getText(self, self.tr("Snippet Name"), self.tr("Snippet Name: "), flags=self.windowFlags()) if ok and snippetName: if not snippetName.endswith(".py"): snippetName += ".py" index = self.tree.selectionModel().currentIndex() selection = self.files.filePath(index) if QFileInfo(selection).isDir(): path = os.path.join(selection, snippetName) else: path = os.path.join(snippetPath, snippetName) self.readOnly(False) open(path, "w").close() self.tree.setCurrentIndex(self.files.index(path)) log_debug("Snippet %s created." % snippetName)
def SelectProgramPreset(self): if not AppGlobals.Chip().programs: return presetSelection, confirmed = QInputDialog.getItem( self, "Program Preset", "Program", [program.name for program in AppGlobals.Chip().programs], 0, False) if confirmed: selected = [ program for program in AppGlobals.Chip().programs if program.name == presetSelection ][0] newPreset = ProgramPreset(selected) AppGlobals.Chip().programPresets.append(newPreset) AppGlobals.Instance().onChipModified.emit() self.viewer.CenterItem( self.viewer.AddItem(ProgramPresetItem(newPreset)))
def action_rename_event(self): """ Prompts the user to enter a new name and changes the selected file's name. """ file_name = self.table_view.currentIndex().data() new_file_name, ok = QInputDialog().getText(self, 'Rename ' + file_name, 'New name:') if (ok): if (new_file_name): QFile().rename(os.path.join(self.current_path, file_name), os.path.join(self.current_path, new_file_name)) else: dialog = utility.message_dialog('Please enter the new name ' + 'for the file.', QMessageBox.Warning) dialog.exec()
def search(self): query_string, ok = QInputDialog.getText(self, 'Find in Trie', 'Function name') if not ok or not query_string: return self.searchResults = self.model.findItems( query_string, Qt.MatchContains | Qt.MatchRecursive, 1) if self.searchResults: self.findNextAction.setEnabled(True) self.findPrevAction.setEnabled(True) self.searchIndex = 0 self.select_next() else: self.findNextAction.setEnabled(False) self.findPrevAction.setEnabled(False) self.searchIndex = -1 QMessageBox.warning(self, 'Find in Trie', 'No results found')
def action_new_dir_event(self): """ Prompts the user for a dir name and creates one with that name in the current directory. """ dir_name, ok = QInputDialog().getText(self, 'Create new directory', 'Directory name:') if (ok): if (dir_name): if not QDir().mkpath(os.path.join(self.current_path, dir_name)): dialog = utility.message_dialog('Directory could not be' + ' created.', QMessageBox.Critical) dialog.exec() else: dialog = utility.message_dialog('Please enter a name for the ' + 'new directory.', QMessageBox.Warning) dialog.exec()
def add_key_action(self): file_name, _ = QFileDialog.getOpenFileName(self, '选择密钥文件') if len(file_name.strip()) == 0: return password = None if Key.need_password(file_name): ok_pressed = True while ok_pressed: password, ok_pressed = QInputDialog.getText( self, "需要密码", "输入密码:", QLineEdit.Password, "") if ok_pressed: illegal, msg = Key.is_password_illegal(password) if illegal: QMessageBox.information(self, '错误', msg) continue break else: return key = Key() try: key.load(file_name, password) except Exception as e: QMessageBox.critical(self, '错误', '不是有效的密钥文件<br/>' + str(e)) return row_len = self.list_model.rowCount() for i in range(0, row_len): item: QStandardItem = self.list_model.item(i, 0) k: Key = item.data() if k.id == key.id: QMessageBox.information(self, '信息', '相同的密钥已经加载') return item = self.make_item(key) self._add_key(item, key) return
def action_new_file_event(self): """ Prompts the user for a file name and creates one with that name in the current directory. """ file_name, ok = QInputDialog().getText(self, 'Create new file', 'File name:') if (ok): if (file_name): try: with open(os.path.join(self.current_path, file_name), 'a'): pass except OSError: dialog = utility.message_dialog('File cannot be created.', QMessageBox.Warning) dialog.exec() else: dialog = utility.message_dialog('Please enter a name for the' + ' new file.', QMessageBox.Warning) dialog.exec()
def save_layout(self): (layout_name, res) = QInputDialog.getText(self, 'Save Layout', 'Enter name for the layout') if res: layouts = settings.get_layouts() if layout_name in layouts: # TODO res = QMessageBox.question( self, 'Save Layout', f'Do you want to overwrite the existing layout {layout_name}?' ) print(res) if res != QMessageBox.StandardButton.Yes: return else: layout = Layout(layout_name, self.saveState(), self.saveGeometry(), self.dock_manager.save_state()) layouts.append(layout) settings.set_layouts(layouts) self.build_layouts_toolbar()
def showDialog(self): text, ok = QInputDialog.getText(self, "Input Dialog", 'Enter your name:') if ok: self.le.setText(str(text))
def getText(self, *args, **kwargs): result, okPressed = QInputDialog.getText(self, *args, **kwargs) return result, okPressed
def afterPushButtonPressed(self, button): self.after_pushButton.setEnabled(False) if os_type != OS.WINDOWS: # For Linux and Mac OSX and FreeBSD and OpenBSD # get root password passwd, ok = QInputDialog.getText(self, 'PassWord', 'Please enter root password:'******'sudo', '-S', 'echo', 'hello'], stdout=subprocess.DEVNULL, stdin=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=False) pipe.communicate(passwd.encode()) answer = pipe.wait() # Wrong password while answer != 0: passwd, ok = QInputDialog.getText( self, 'PassWord', 'Wrong Password!\nPlease try again.', QLineEdit.Password) if ok: # checking password pipe = subprocess.Popen( ['sudo', '-S', 'echo', 'hello'], stdout=subprocess.DEVNULL, stdin=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=False) pipe.communicate(passwd.encode()) answer = pipe.wait() else: ok = False break if ok != False: # if user selects shutdown option after download progress, # value of 'shutdown' will changed in temp_db for this gid # and "wait" word will be written for this value. # (see ShutDownThread and shutdown.py for more information) # shutDown method will check that value in a loop . # when "wait" changes to "shutdown" then shutdown.py script # will shut down the system. shutdown_enable = ShutDownThread(self.parent, self.gid, passwd) self.parent.threadPool.append(shutdown_enable) self.parent.threadPool[len(self.parent.threadPool) - 1].start() else: self.after_checkBox.setChecked(False) else: self.after_checkBox.setChecked(False) else: # for Windows shutdown_enable = ShutDownThread(self.parent, self.gid) self.parent.threadPool.append(shutdown_enable) self.parent.threadPool[len(self.parent.threadPool) - 1].start()
def wiiload_button(self): data = self.ui.listAppsWidget.currentItem().data(Qt.UserRole) app_name = data["internal_name"] app_display_name = data["display_name"] ip, ok = QInputDialog.getText(self, 'Send to Wii: Enter IP address', 'Enter the IP address of your Wii.\n' 'The selected app will be sent through the network to your Wii.\n\n' f'App to send: {app_display_name}\n\n' 'To find your Wii\'s IP address:\n' '1) Enter the Homebrew Channel.\n' '2) Press the home button on the Wii Remote.\n' '3) Copy the IP address written in the top left corner.\n\n' 'IP address (e.g. 192.168.1...):', QLineEdit.Normal) if not ok: return ip_match = wiiload.validate_ip_regex(ip) if ip_match is None: logging.warning('Invalid IP Address: ' + ip) QMessageBox.warning(self, 'Invalid IP Address', 'This IP address is invalid.') return self.status_message("Downloading " + app_name + " from Open Shop Channel..") self.ui.progressBar.setValue(25) # get app path_to_app = self.download_button() with open(path_to_app, 'rb') as f: content = f.read() zipped_app = io.BytesIO(content) zip_buf = io.BytesIO() # Our zip file should only contain one directory with the app data in it, # but the downloaded file contains an apps/ directory. We're removing that here. wiiload.organize_zip(zipped_app, zip_buf) # preparing prep = wiiload.prepare(zip_buf) file_size = prep[0] compressed_size = prep[1] chunks = prep[2] # connecting self.status_message('Connecting to the HBC...') self.ui.progressBar.setValue(50) try: conn = wiiload.connect(ip) except socket.error as e: logging.error('Error while connecting to the HBC. Please check the IP address and try again.') QMessageBox.warning(self, 'Connection error', 'Error while connecting to the HBC. Please check the IP address and try again.') print(f'WiiLoad: {e}') self.ui.progressBar.setValue(0) self.status_message('Error: Could not connect to the Homebrew Channel. :(') # delete application zip file os.remove(path_to_app) return wiiload.handshake(conn, compressed_size, file_size) # Sending file self.status_message('Sending app...') chunk_num = 1 for chunk in chunks: conn.send(chunk) chunk_num += 1 progress = round(chunk_num / len(chunks) * 50) + 50 self.ui.progressBar.setValue(progress) try: app.processEvents() except NameError: pass file_name = f'{app_name}.zip' conn.send(bytes(file_name, 'utf-8') + b'\x00') # delete application zip file os.remove(path_to_app) self.ui.progressBar.setValue(100) self.status_message('App transmitted!') logging.info(f"App transmitted to HBC at {ip}")
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 show_text_input(self, title: str, text: str) -> Tuple[str, bool]: return QInputDialog.getText(self.main_window, title, text)
def set_text_value(dialog: QtWidgets.QInputDialog): dialog.setTextValue("magoo") return QtWidgets.QDialog.Accepted
def set_text(self): input_d = QInputDialog(self) res_text, res_ok = input_d.getText(self, "title", "text:") if res_ok: self.text.setText(res_text)