Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CID: Remove prints, some small cleanup+type hints #433

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions pupgui2/pupgui2customiddialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,26 @@ def setup_ui(self):
self.ui.txtInstallDirectory.textChanged.connect(lambda text: self.ui.btnSave.setEnabled(self.is_valid_custom_install_path(text)))

def btn_save_clicked(self):
install_dir = os.path.expanduser(self.ui.txtInstallDirectory.text().strip())
install_dir: str = os.path.expanduser(self.ui.txtInstallDirectory.text().strip())
if not install_dir.endswith(os.sep):
install_dir += '/'
launcher = get_dict_key_from_value(self.install_locations_dict, self.ui.comboLauncher.currentText()) or ''

if self.is_valid_custom_install_path(install_dir):
config_custom_install_location(install_dir, launcher)
print(f'New Custom Install Directory set to: {install_dir}')

self.custom_id_set.emit(install_dir)
self.ui.close()

def btn_default_clicked(self):
self.ui.txtInstallDirectory.setText('')
config_custom_install_location(remove=True)
print(f'Removed custom install directory')

self.custom_id_set.emit('')

def txt_id_browse_action_triggered(self):
# Open dialog at entered path if it exists, and fall back to HOME_DIR
txt_install_dir = os.path.expanduser(self.ui.txtInstallDirectory.text())
txt_install_dir: str = os.path.expanduser(self.ui.txtInstallDirectory.text())
initial_dir = txt_install_dir if self.is_valid_custom_install_path(txt_install_dir) else HOME_DIR

dialog = QFileDialog(self.ui, directory=initial_dir)
Expand All @@ -92,10 +90,11 @@ def txt_id_browse_action_triggered(self):
dialog.open()

def set_selected_launcher(self, ctool_name: str):
if ctool_name:
index = get_combobox_index_by_value(self.ui.comboLauncher, ctool_name)
if index >= 0:
self.ui.comboLauncher.setCurrentIndex(index)
if not ctool_name:
return

if (index := get_combobox_index_by_value(self.ui.comboLauncher, ctool_name)) >= 0:
self.ui.comboLauncher.setCurrentIndex(index)

def is_valid_custom_install_path(self, path: str) -> bool:
expand_path = os.path.expanduser(path)
Expand Down
14 changes: 8 additions & 6 deletions pupgui2/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import PySide6
from PySide6.QtCore import QCoreApplication
from PySide6.QtWidgets import QApplication, QStyleFactory, QMessageBox, QCheckBox
from PySide6.QtWidgets import QApplication, QComboBox, QStyleFactory, QMessageBox, QCheckBox

from pupgui2.constants import POSSIBLE_INSTALL_LOCATIONS, CONFIG_FILE, PALETTE_DARK, TEMP_DIR, IS_FLATPAK
from pupgui2.constants import AWACY_GAME_LIST_URL, LOCAL_AWACY_GAME_LIST
Expand Down Expand Up @@ -698,18 +698,20 @@ def get_dict_key_from_value(d, searchval):
return None


def get_combobox_index_by_value(combobox, value: str) -> int:
def get_combobox_index_by_value(combobox: QComboBox, value: str) -> int:
"""
Get the index in a combobox where a text value is located.
Returns an integer >= 0 if found, otherwise -1.

Return Type: int
"""

if value:
for i in range(combobox.count()):
if value == combobox.itemText(i):
return i
if not value:
return -1

for i in range(combobox.count()):
if value == combobox.itemText(i):
return i

return -1

Expand Down