From e66dffeef0bfa468d48ffeded1496b7ca06b2ed2 Mon Sep 17 00:00:00 2001 From: Boris Yumankulov Date: Wed, 11 Mar 2026 17:42:20 +0500 Subject: [PATCH] feat: added create pfx Signed-off-by: Boris Yumankulov --- portprotonqt/dialogs/settings_dialog.py | 46 ++++++-- portprotonqt/input_manager.py | 143 ++++++++++++++++++++++-- portprotonqt/main_window.py | 68 +++++++++-- 3 files changed, 228 insertions(+), 29 deletions(-) diff --git a/portprotonqt/dialogs/settings_dialog.py b/portprotonqt/dialogs/settings_dialog.py index df3df4d1d..5a7bbf65c 100644 --- a/portprotonqt/dialogs/settings_dialog.py +++ b/portprotonqt/dialogs/settings_dialog.py @@ -425,14 +425,24 @@ class ExeSettingsDialog(QDialog, MangoHudSettingsMixin): current_val = self.current_settings.get(toggle, '0') is_blocked = toggle in self.blocked_keys - checkbox = QTableWidgetItem() - check_state = Qt.CheckState.Checked if current_val == '1' and not is_blocked else Qt.CheckState.Unchecked - checkbox.setCheckState(check_state) + checkbox_widget = QCheckBox() + checkbox_widget.setStyleSheet(self.theme.SETTINGS_CHECKBOX_STYLE) + checkbox_widget.setChecked(current_val == '1' and not is_blocked) + checkbox_widget.setEnabled(not is_blocked) + checkbox_widget.setFocusPolicy(Qt.FocusPolicy.StrongFocus) + checkbox_container = QWidget() + checkbox_layout = QHBoxLayout(checkbox_container) + checkbox_layout.setContentsMargins(0, 0, 0, 0) + checkbox_layout.setAlignment(Qt.AlignmentFlag.AlignCenter) + checkbox_layout.addWidget(checkbox_widget) + checkbox_container.setFocusPolicy(Qt.FocusPolicy.NoFocus) + checkbox_item = QTableWidgetItem() + checkbox_item.setFlags(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled) if is_blocked: - checkbox.setFlags(checkbox.flags() & ~Qt.ItemFlag.ItemIsUserCheckable) - checkbox.setBackground(QColor(self.theme.color_disabled_bg)) name_item.setForeground(QColor(self.theme.color_disabled_text)) - self.settings_table.setItem(row, 1, checkbox) + checkbox_container.setStyleSheet(f"background-color: {self.theme.color_disabled_bg};") + self.settings_table.setItem(row, 1, checkbox_item) + self.settings_table.setCellWidget(row, 1, checkbox_container) desc_item = QTableWidgetItem(description) desc_item.setFlags(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled) @@ -442,12 +452,16 @@ class ExeSettingsDialog(QDialog, MangoHudSettingsMixin): self.settings_table.setItem(row, 2, desc_item) self.settings_table.setItem(row, 0, name_item) - self.value_widgets[(row, 1)] = checkbox + self.value_widgets[(row, 1)] = checkbox_widget self.settings_table.resizeRowsToContents() if self.settings_table.rowCount() > 0: - self.settings_table.setCurrentCell(0, 0) - self.settings_table.setFocus(Qt.FocusReason.OtherFocusReason) + self.settings_table.setCurrentCell(0, 1) + first_widget = self.value_widgets.get((0, 1)) + if isinstance(first_widget, QCheckBox): + first_widget.setFocus(Qt.FocusReason.OtherFocusReason) + else: + self.settings_table.setFocus(Qt.FocusReason.OtherFocusReason) self.on_table_selection_changed() @@ -483,6 +497,12 @@ class ExeSettingsDialog(QDialog, MangoHudSettingsMixin): if setting['type'] == 'combo': combo = QComboBox() combo.addItems(setting['options']) + if setting['key'] == 'PW_PREFIX_NAME': + combo.setEditable(True) + combo.setInsertPolicy(QComboBox.InsertPolicy.NoInsert) + prefix_line_edit = combo.lineEdit() + if prefix_line_edit is not None: + prefix_line_edit.setPlaceholderText(_("Enter prefix name")) current_raw = current.get(setting['key'], setting['default']) if setting['key'] == 'PW_WINE_CPU_TOPOLOGY': @@ -616,11 +636,11 @@ class ExeSettingsDialog(QDialog, MangoHudSettingsMixin): if row == -1: continue - item = self.settings_table.item(row, 1) - if not item: + widget = self.value_widgets.get((row, 1)) + if not isinstance(widget, QCheckBox): continue - new_val = '1' if item.checkState() == Qt.CheckState.Checked else '0' + new_val = '1' if widget.isChecked() else '0' if new_val != orig_val: changes.append(f"{key}={new_val}") # Track if PW_MANGOHUD is being enabled @@ -631,6 +651,8 @@ class ExeSettingsDialog(QDialog, MangoHudSettingsMixin): orig_val = self.original_display_values.get(key, '') if isinstance(widget, QComboBox): new_val = widget.currentText() + if key == 'PW_PREFIX_NAME': + new_val = new_val.strip() if key in self.value_mapping and 'forward' in self.value_mapping[key]: value_map = self.value_mapping[key]['forward'] diff --git a/portprotonqt/input_manager.py b/portprotonqt/input_manager.py index 5b50ef4b2..a8d167fb3 100644 --- a/portprotonqt/input_manager.py +++ b/portprotonqt/input_manager.py @@ -801,6 +801,16 @@ class InputManager(QObject): current_row = table.currentRow() current_col = table.currentColumn() if current_row >= 0 and current_col >= 0: + cell_widget = table.cellWidget(current_row, current_col) + if isinstance(cell_widget, QCheckBox) and cell_widget.isEnabled(): + cell_widget.setChecked(not cell_widget.isChecked()) + return True + if cell_widget is not None: + checkbox = cell_widget.findChild(QCheckBox) + if checkbox and checkbox.isEnabled(): + checkbox.setChecked(not checkbox.isChecked()) + return True + # Check if the cell contains a checkbox item = table.item(current_row, current_col) if item and (item.flags() & Qt.ItemFlag.ItemIsUserCheckable): @@ -1176,8 +1186,10 @@ class InputManager(QObject): if button_code in BUTTONS['back']: if open_combo: open_combo.hidePopup() - if table: - table.setFocus() + if open_combo.isEditable() and open_combo.lineEdit() is not None: + open_combo.lineEdit().setFocus() + else: + open_combo.setFocus() else: self.settings_dialog.reject() return @@ -1189,12 +1201,28 @@ class InputManager(QObject): if view.currentIndex().isValid(): open_combo.setCurrentIndex(view.currentIndex().row()) open_combo.hidePopup() - if table: - table.setFocus() + if open_combo.isEditable() and open_combo.lineEdit() is not None: + open_combo.lineEdit().setFocus() + else: + open_combo.setFocus() return # Standard interaction focused = QApplication.focusWidget() + if isinstance(focused, QCheckBox) and focused.isEnabled(): + focused.setChecked(not focused.isChecked()) + return + combo_from_focus = None + if isinstance(focused, QComboBox): + combo_from_focus = focused + else: + parent = focused.parentWidget() if focused else None + if isinstance(parent, QComboBox): + combo_from_focus = parent + if combo_from_focus and combo_from_focus.isEnabled(): + combo_from_focus.showPopup() + combo_from_focus.setFocus() + return if isinstance(focused, QTableWidget) and table and focused.currentRow() >= 0: # Main settings (checkboxes) if self.settings_dialog and table == self.settings_dialog.settings_table: @@ -1233,6 +1261,29 @@ class InputManager(QObject): self.settings_dialog.apply_changes() elif button_code in BUTTONS['prev_dir']: # Y: Search + Keyboard + focused = QApplication.focusWidget() + focused_combo = None + if isinstance(focused, QTableWidget) and self.settings_dialog: + table = self._get_current_settings_table() + if table is not None and table == self.settings_dialog.advanced_table: + row = focused.currentRow() + if row >= 0: + cell_widget = focused.cellWidget(row, 1) + if isinstance(cell_widget, QComboBox): + focused_combo = cell_widget + if focused_combo is None: + if isinstance(focused, QComboBox): + focused_combo = focused + else: + parent = focused.parentWidget() if focused else None + if isinstance(parent, QComboBox): + focused_combo = parent + if focused_combo and focused_combo.isEditable() and focused_combo.isEnabled(): + line_edit = focused_combo.lineEdit() + if line_edit is not None: + line_edit.setFocus() + self.settings_dialog.show_virtual_keyboard(line_edit) + return self.settings_dialog.search_edit.setFocus() self.settings_dialog.show_virtual_keyboard(self.settings_dialog.search_edit) @@ -1383,18 +1434,28 @@ class InputManager(QObject): new_row += step if 0 <= new_row < table.rowCount(): - focus_column = 1 if (self.settings_dialog and table == self.settings_dialog.advanced_table) else 0 + focus_column = 1 table.setCurrentCell(new_row, focus_column) - table.setFocus(Qt.FocusReason.OtherFocusReason) + self._focus_settings_advanced_value_widget(table, new_row) elif code == ecodes.ABS_HAT0X: # Left/Right current_col = table.currentColumn() if value < 0: # Left if current_col > 0: - table.setCurrentCell(current_row, max(0, current_col - 1)) + new_col = max(0, current_col - 1) + table.setCurrentCell(current_row, new_col) + if new_col == 1: + self._focus_settings_advanced_value_widget(table, current_row) + else: + table.setFocus(Qt.FocusReason.OtherFocusReason) else: # Right if current_col < table.columnCount() - 1: - table.setCurrentCell(current_row, min(table.columnCount() - 1, current_col + 1)) + new_col = min(table.columnCount() - 1, current_col + 1) + table.setCurrentCell(current_row, new_col) + if new_col == 1: + self._focus_settings_advanced_value_widget(table, current_row) + else: + table.setFocus(Qt.FocusReason.OtherFocusReason) except Exception as e: logger.error(f"Error in handle_settings_dpad: {e}") @@ -1419,12 +1480,44 @@ class InputManager(QObject): return combo return None + def _focus_settings_advanced_value_widget(self, table, row): + """Focus value widget in settings row when available.""" + if not self.settings_dialog: + table.setFocus(Qt.FocusReason.OtherFocusReason) + return + + if table == self.settings_dialog.settings_table: + cell_widget = table.cellWidget(row, 1) + if cell_widget is not None: + checkbox = cell_widget.findChild(QCheckBox) + if checkbox and checkbox.isEnabled(): + checkbox.setFocus(Qt.FocusReason.OtherFocusReason) + return + table.setFocus(Qt.FocusReason.OtherFocusReason) + return + + if table != self.settings_dialog.advanced_table: + table.setFocus(Qt.FocusReason.OtherFocusReason) + return + cell_widget = table.cellWidget(row, 1) + if isinstance(cell_widget, QComboBox): + line_edit = cell_widget.lineEdit() + if cell_widget.isEditable() and line_edit is not None: + line_edit.setFocus(Qt.FocusReason.OtherFocusReason) + else: + cell_widget.setFocus(Qt.FocusReason.OtherFocusReason) + return + if isinstance(cell_widget, QLineEdit): + cell_widget.setFocus(Qt.FocusReason.OtherFocusReason) + return + table.setFocus(Qt.FocusReason.OtherFocusReason) + def _focus_first_row_in_current_settings_table(self): table = self._get_current_settings_table() if table and table.rowCount() > 0: - col = 1 if (self.settings_dialog and table == self.settings_dialog.advanced_table) else 0 + col = 1 table.setCurrentCell(0, col) - table.setFocus(Qt.FocusReason.OtherFocusReason) + self._focus_settings_advanced_value_widget(table, 0) return if self.settings_dialog and self.settings_dialog.tab_widget.currentIndex() == 2: @@ -2088,6 +2181,23 @@ class InputManager(QObject): keyboard.show_for_widget(focused) return + # Y on editable combo opens keyboard for combo input + if button_code in BUTTONS['prev_dir']: + focused_combo = None + if isinstance(focused, QComboBox): + focused_combo = focused + else: + parent = focused.parentWidget() if focused else None + if isinstance(parent, QComboBox): + focused_combo = parent + if focused_combo and focused_combo.isEditable(): + line_edit = focused_combo.lineEdit() + keyboard = getattr(self._parent, 'keyboard', None) + if line_edit and keyboard: + line_edit.setFocus() + keyboard.show_for_widget(line_edit) + return + # Handle Y button to focus search if button_code in BUTTONS['prev_dir']: # Y button search_edit = None @@ -2707,6 +2817,14 @@ class InputManager(QObject): focused.cursorForward(False, 1) # Move cursor right by one character return True # Consume the event to prevent further processing + # Allow text editing in editable combo boxes + if key == Qt.Key.Key_Backspace: + if isinstance(focused, QComboBox) and focused.isEditable(): + return False + parent = focused.parentWidget() if focused else None + if isinstance(parent, QComboBox) and parent.isEditable(): + return False + # Open system overlay with Insert if key == Qt.Key.Key_Insert: if not popup and not isinstance(active_win, QDialog): @@ -2838,6 +2956,11 @@ class InputManager(QObject): elif key in (Qt.Key.Key_Escape, Qt.Key.Key_Backspace): if isinstance(focused, QLineEdit): return False + if isinstance(focused, QComboBox) and focused.isEditable(): + return False + parent = focused.parentWidget() if focused else None + if isinstance(parent, QComboBox) and parent.isEditable(): + return False self._parent.goBackDetailPage(self._parent.currentDetailPage) return True elif key == Qt.Key.Key_E: diff --git a/portprotonqt/main_window.py b/portprotonqt/main_window.py index 0d9275389..e46e15947 100644 --- a/portprotonqt/main_window.py +++ b/portprotonqt/main_window.py @@ -12,7 +12,7 @@ from portprotonqt.animations import DetailPageAnimations from portprotonqt.custom_widgets import ClickableLabel, AutoSizeButton, NavLabel, FlowLayout from portprotonqt.detail_pages import DetailPageManager from portprotonqt.portproton_api import PortProtonAPI, get_user_conf_setting, set_user_conf_setting -from portprotonqt.debug_utils import get_gpu_list +from portprotonqt.debug_utils import get_gpu_list, get_prefix_name from portprotonqt.input_manager import InputManager, MainWindowProtocol from portprotonqt.context_menu_manager import ContextMenuManager, CustomLineEdit from portprotonqt.system_overlay import SystemOverlay @@ -45,7 +45,7 @@ from portprotonqt.config_utils import find_game_by_exe, create_desktop_file from PySide6.QtWidgets import (QLineEdit, QMainWindow, QStatusBar, QWidget, QVBoxLayout, QLabel, QHBoxLayout, QStackedWidget, QComboBox, QDialog, QFormLayout, QMessageBox, QApplication, QPushButton, QProgressBar, QCheckBox, QSizePolicy, QGridLayout, QScrollArea, QScroller, QSlider, QFrame) -from PySide6.QtCore import Qt, QAbstractAnimation, QUrl, Signal, QTimer, Slot, QProcess, QFileSystemWatcher +from PySide6.QtCore import Qt, QAbstractAnimation, QUrl, Signal, QTimer, Slot, QProcess, QProcessEnvironment, QFileSystemWatcher from PySide6.QtGui import QIcon, QPixmap, QColor, QDesktopServices from typing import cast from collections.abc import Callable @@ -1810,6 +1810,11 @@ class MainWindow(QMainWindow): self.prefixCombo = QComboBox() self.prefixCombo.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed) self.prefixCombo.addItems(self.prefixes) + self.prefixCombo.setEditable(True) + self.prefixCombo.setInsertPolicy(QComboBox.InsertPolicy.NoInsert) + prefix_line_edit = self.prefixCombo.lineEdit() + if prefix_line_edit is not None: + prefix_line_edit.setPlaceholderText(_("Enter prefix name")) self.prefixCombo.setStyleSheet(self.theme.SETTINGS_COMBO_STYLE) self.prefixCombo.setFocusPolicy(Qt.FocusPolicy.StrongFocus) self.prefixTitleLabel = QLabel(_("Prefix:")) @@ -1894,11 +1899,13 @@ class MainWindow(QMainWindow): def launch_generic_tool(self, cli_arg): wine = self.wineCombo.currentText() - prefix = self.prefixCombo.currentText() + prefix = self.prefixCombo.currentText().strip() if not wine or not prefix: return if not self.portproton_location or not self.start_sh: return + env_vars = os.environ.copy() + self._check_missing_prefix_by_name_before_launch(prefix, env_vars) start_sh = self.start_sh cmd = start_sh + ["cli", cli_arg, wine, prefix] @@ -1907,6 +1914,12 @@ class MainWindow(QMainWindow): self.update_status_message.emit(_("Launching tool..."), 0) proc = QProcess(self) + process_env = QProcessEnvironment.systemEnvironment() + if env_vars.get("DISABLE_CP_DEFPFX") == "1": + process_env.insert("DISABLE_CP_DEFPFX", "1") + else: + process_env.remove("DISABLE_CP_DEFPFX") + proc.setProcessEnvironment(process_env) proc.finished.connect(lambda exitCode: self._on_wine_tool_finished(exitCode, cli_arg)) proc.errorOccurred.connect(lambda error: self._on_wine_tool_error(error, cli_arg)) proc.start(cmd[0], cmd[1:]) @@ -1984,7 +1997,7 @@ class MainWindow(QMainWindow): def clear_prefix(self): """Clear prefix""" - selected_prefix = self.prefixCombo.currentText() + selected_prefix = self.prefixCombo.currentText().strip() selected_wine = self.wineCombo.currentText() if not selected_prefix or not selected_wine: @@ -2035,7 +2048,7 @@ class MainWindow(QMainWindow): QMessageBox.warning(self, _("Error"), _("Failed to run clear prefix command: {}").format(error)) def create_prefix_backup(self): - selected_prefix = self.prefixCombo.currentText() + selected_prefix = self.prefixCombo.currentText().strip() if not selected_prefix: return file_explorer = FileExplorer(self, directory_only=True) @@ -2085,7 +2098,7 @@ class MainWindow(QMainWindow): QMessageBox.warning(self, _("Error"), _("Prefix restore failed.")) def delete_prefix(self): - selected_prefix = self.prefixCombo.currentText() + selected_prefix = self.prefixCombo.currentText().strip() if not self.portproton_location: return @@ -2132,6 +2145,7 @@ class MainWindow(QMainWindow): if not self.portproton_location: return + current_prefix = self.prefixCombo.currentText().strip() prefixes_path = os.path.join(self.portproton_location, "data", "prefixes") if not os.path.exists(prefixes_path): return @@ -2140,10 +2154,12 @@ class MainWindow(QMainWindow): self.prefixes = sorted([d for d in os.listdir(prefixes_path) if os.path.isdir(os.path.join(prefixes_path, d))], key=version_sort_key) self.prefixCombo.clear() self.prefixCombo.addItems(self.prefixes) + if current_prefix: + self.prefixCombo.setCurrentText(current_prefix) def open_winetricks(self): """Open the Winetricks dialog for the selected prefix and wine.""" - selected_prefix = self.prefixCombo.currentText() + selected_prefix = self.prefixCombo.currentText().strip() if not selected_prefix: return @@ -3181,6 +3197,35 @@ class MainWindow(QMainWindow): self.wine_download_seen = False self.wine_download_percent = 0.0 + def _check_missing_prefix_by_name_before_launch(self, prefix_name: str, env_vars: dict[str, str]) -> None: + """Check prefix presence and optionally disable default recommended libs.""" + if not prefix_name or not self.portproton_location: + return + + prefix_path = os.path.join(self.portproton_location, "data", "prefixes", prefix_name) + if os.path.isdir(prefix_path): + return + + msg_box = QMessageBox(self) + msg_box.setIcon(QMessageBox.Icon.Question) + msg_box.setWindowTitle(_("Prefix not found")) + msg_box.setText(_("Prefix '{0}' was not found. Install recommended libraries?").format(prefix_name)) + msg_box.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) + msg_box.setDefaultButton(QMessageBox.StandardButton.Yes) + msg_box.setButtonText(QMessageBox.StandardButton.Yes, _("Yes")) + msg_box.setButtonText(QMessageBox.StandardButton.No, _("No")) + reply = msg_box.exec() + if reply == QMessageBox.StandardButton.No: + env_vars["DISABLE_CP_DEFPFX"] = "1" + + def _check_missing_prefix_before_launch(self, game_exe_path: str, env_vars: dict[str, str]) -> None: + """Check game prefix and optionally disable default recommended libs.""" + if not game_exe_path: + return + + prefix_name = get_prefix_name(game_exe_path) + self._check_missing_prefix_by_name_before_launch(prefix_name, env_vars) + def toggleGame(self, exec_line, button=None): # Handle Steam games if exec_line.startswith("steam://"): @@ -3250,6 +3295,7 @@ class MainWindow(QMainWindow): # Launch game via PortProton env_vars = os.environ.copy() env_vars['LEGENDARY_CONFIG_PATH'] = self.legendary_config_path + self._check_missing_prefix_before_launch(game_exe, env_vars) wrapper = self.start_sh or "" @@ -3356,6 +3402,14 @@ class MainWindow(QMainWindow): self.target_exe = current_exe exe_name = os.path.splitext(current_exe)[0] env_vars = os.environ.copy() + game_exe_for_prefix = "" + for part in reversed(entry_exec_split): + if part.lower().endswith(".exe"): + game_exe_for_prefix = os.path.expanduser(part) + break + if not game_exe_for_prefix and file_to_check.lower().endswith(".exe"): + game_exe_for_prefix = os.path.expanduser(file_to_check) + self._check_missing_prefix_before_launch(game_exe_for_prefix, env_vars) # Launch game try: