From 7cbcfe09a3253c34801575cbe526669c44f84bdf Mon Sep 17 00:00:00 2001 From: Stelios Tsampas Date: Mon, 18 Oct 2021 00:39:21 +0300 Subject: [PATCH] Enable/Disable export/import buttons based on selection Signed-off-by: Stelios Tsampas --- .../tabs/games/import_sync/egl_sync_group.py | 45 +++++++++++-------- .../stylesheets/RareStyle/stylesheet.qss | 6 +++ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/rare/components/tabs/games/import_sync/egl_sync_group.py b/rare/components/tabs/games/import_sync/egl_sync_group.py index a491e009..73aa0447 100644 --- a/rare/components/tabs/games/import_sync/egl_sync_group.py +++ b/rare/components/tabs/games/import_sync/egl_sync_group.py @@ -1,11 +1,10 @@ import os import platform from logging import getLogger -from typing import List, Tuple +from typing import List, Tuple, Iterable from PyQt5.QtCore import Qt, QThread, QFileSystemWatcher -from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QLabel, QGroupBox, \ - QCheckBox, QPushButton, QListWidgetItem, QDialog, QFileDialog +from PyQt5.QtWidgets import QGroupBox, QListWidgetItem, QFileDialog import rare.shared as shared from rare.ui.components.tabs.games.import_sync.egl_sync_group import Ui_EGLSyncGroup @@ -23,13 +22,14 @@ class EGLSyncGroup(QGroupBox, Ui_EGLSyncGroup): def __init__(self, parent=None): super(EGLSyncGroup, self).__init__(parent=parent) self.setupUi(self) + self.egl_path_info.setProperty('infoLabel', 1) self.core = shared.core - if platform.system() == "Windows": + if platform.system() == 'Windows': estimated_path = os.path.expandvars(PathSpec.egl_programdata) else: - estimated_path = str() + estimated_path = self.tr('Updating...') self.wine_resolver = WineResolver(PathSpec.egl_programdata, 'default', shared.core) self.wine_resolver.result_ready.connect(self.egl_path_info.setText) self.wine_resolver.finished.connect(self.wine_resolver.quit) @@ -72,9 +72,6 @@ class EGLSyncGroup(QGroupBox, Ui_EGLSyncGroup): self.egl_path_edit.textChanged.connect(self.egl_path_changed) self.egl_path_layout.addWidget(self.egl_path_edit) - self.egl_watcher = QFileSystemWatcher([self.egl_path_edit.text()], self) - self.egl_watcher.directoryChanged.connect(self.update_lists) - if platform.system() == "Windows": self.egl_path_label.setVisible(False) self.egl_path_edit.setVisible(False) @@ -89,6 +86,9 @@ class EGLSyncGroup(QGroupBox, Ui_EGLSyncGroup): self.export_list = EGLSyncListGroup(export=True, parent=self) self.import_export_layout.addWidget(self.export_list) + self.egl_watcher = QFileSystemWatcher([self.egl_path_edit.text()], self) + self.egl_watcher.directoryChanged.connect(self.update_lists) + self.update_lists() @staticmethod @@ -118,8 +118,6 @@ class EGLSyncGroup(QGroupBox, Ui_EGLSyncGroup): igame.egl_guid = '' shared.core.install_game(igame) else: - # NOTE: need to clear known manifests to force refresh - # shared.core.egl.manifests.clear() shared.core.egl.programdata_path = path shared.core.lgd.config.set("Legendary", "egl_programdata", path) shared.core.lgd.save_config() @@ -144,22 +142,18 @@ class EGLSyncGroup(QGroupBox, Ui_EGLSyncGroup): # self.export_list.action() self.core.lgd.save_config() - # def egl_items_changed(self, path: str): - # if path == shared.core.egl.programdata_path and self.egl_path_edit.is_valid: - # shared.core.egl.manifests.clear() - # self.import_list.populate(True) - # self.export_list.populate(True) - def update_lists(self): + self.egl_watcher.blockSignals(True) if have_path := bool(shared.core.egl.programdata_path) and self.egl_path_edit.is_valid: + # NOTE: need to clear known manifests to force refresh shared.core.egl.manifests.clear() self.egl_sync_label.setEnabled(have_path) self.egl_sync_check.setEnabled(have_path) - self.import_list.populate(have_path) self.import_list.setEnabled(have_path) self.export_list.populate(have_path) self.export_list.setEnabled(have_path) + self.egl_watcher.blockSignals(False) class EGLSyncListItem(QListWidgetItem): @@ -208,12 +202,20 @@ class EGLSyncListGroup(QGroupBox, Ui_EGLSyncListGroup): lambda item: item.setCheckState(Qt.Unchecked) if item.checkState() != Qt.Unchecked else item.setCheckState(Qt.Checked) ) + self.list.itemChanged.connect(self.has_selected) self.select_all_button.clicked.connect(lambda: self.mark(Qt.Checked)) self.select_none_button.clicked.connect(lambda: self.mark(Qt.Unchecked)) self.action_button.clicked.connect(self.action) + def has_selected(self): + for item in self.items: + if item.is_checked(): + self.action_button.setEnabled(True) + return + self.action_button.setEnabled(False) + def mark(self, state): for item in self.items: item.setCheckState(state) @@ -236,10 +238,16 @@ class EGLSyncListGroup(QGroupBox, Ui_EGLSyncListGroup): self.populate(True) @property - def items(self) -> List[EGLSyncListItem]: + def items(self) -> Iterable[EGLSyncListItem]: + # for i in range(self.list.count()): + # yield self.list.item(i) return [self.list.item(i) for i in range(self.list.count())] +''' +from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QLabel, QCheckBox, QPushButton, QDialog + + class DisableSyncDialog(QDialog): info = 1, False @@ -315,3 +323,4 @@ class EGLSyncItemWidget(QGroupBox): # FIXME: on update_egl_widget this is going to crash because # FIXME: the item is not removed from the list in the python's side self.deleteLater() +''' diff --git a/rare/resources/stylesheets/RareStyle/stylesheet.qss b/rare/resources/stylesheets/RareStyle/stylesheet.qss index 62405657..14470b56 100644 --- a/rare/resources/stylesheets/RareStyle/stylesheet.qss +++ b/rare/resources/stylesheets/RareStyle/stylesheet.qss @@ -17,6 +17,12 @@ QLabel { padding: 0px; selection-background-color: #2f4f4f; } +QLabel[infoLabel="1"] { + color: #bbbbbb; + font-style: italic; + font-weight: normal; +} + QMenu, QListView,