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 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 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 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 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 _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 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 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 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 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 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)
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 getText(self, *args, **kwargs): result, okPressed = QInputDialog.getText(self, *args, **kwargs) return result, okPressed
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}")
def show_text_input(self, title: str, text: str) -> Tuple[str, bool]: return QInputDialog.getText(self.main_window, title, text)
def showDialog(self): text, ok = QInputDialog.getText(self, "Input Dialog", 'Enter your name:') if ok: self.le.setText(str(text))