Enable/Disable export/import buttons based on selection
Signed-off-by: Stelios Tsampas <loathingkernel@gmail.com>
This commit is contained in:
parent
f2401af6de
commit
7cbcfe09a3
|
@ -1,11 +1,10 @@
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple, Iterable
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt, QThread, QFileSystemWatcher
|
from PyQt5.QtCore import Qt, QThread, QFileSystemWatcher
|
||||||
from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QLabel, QGroupBox, \
|
from PyQt5.QtWidgets import QGroupBox, QListWidgetItem, QFileDialog
|
||||||
QCheckBox, QPushButton, QListWidgetItem, QDialog, QFileDialog
|
|
||||||
|
|
||||||
import rare.shared as shared
|
import rare.shared as shared
|
||||||
from rare.ui.components.tabs.games.import_sync.egl_sync_group import Ui_EGLSyncGroup
|
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):
|
def __init__(self, parent=None):
|
||||||
super(EGLSyncGroup, self).__init__(parent=parent)
|
super(EGLSyncGroup, self).__init__(parent=parent)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
self.egl_path_info.setProperty('infoLabel', 1)
|
||||||
|
|
||||||
self.core = shared.core
|
self.core = shared.core
|
||||||
|
|
||||||
if platform.system() == "Windows":
|
if platform.system() == 'Windows':
|
||||||
estimated_path = os.path.expandvars(PathSpec.egl_programdata)
|
estimated_path = os.path.expandvars(PathSpec.egl_programdata)
|
||||||
else:
|
else:
|
||||||
estimated_path = str()
|
estimated_path = self.tr('Updating...')
|
||||||
self.wine_resolver = WineResolver(PathSpec.egl_programdata, 'default', shared.core)
|
self.wine_resolver = WineResolver(PathSpec.egl_programdata, 'default', shared.core)
|
||||||
self.wine_resolver.result_ready.connect(self.egl_path_info.setText)
|
self.wine_resolver.result_ready.connect(self.egl_path_info.setText)
|
||||||
self.wine_resolver.finished.connect(self.wine_resolver.quit)
|
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_edit.textChanged.connect(self.egl_path_changed)
|
||||||
self.egl_path_layout.addWidget(self.egl_path_edit)
|
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":
|
if platform.system() == "Windows":
|
||||||
self.egl_path_label.setVisible(False)
|
self.egl_path_label.setVisible(False)
|
||||||
self.egl_path_edit.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.export_list = EGLSyncListGroup(export=True, parent=self)
|
||||||
self.import_export_layout.addWidget(self.export_list)
|
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()
|
self.update_lists()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -118,8 +118,6 @@ class EGLSyncGroup(QGroupBox, Ui_EGLSyncGroup):
|
||||||
igame.egl_guid = ''
|
igame.egl_guid = ''
|
||||||
shared.core.install_game(igame)
|
shared.core.install_game(igame)
|
||||||
else:
|
else:
|
||||||
# NOTE: need to clear known manifests to force refresh
|
|
||||||
# shared.core.egl.manifests.clear()
|
|
||||||
shared.core.egl.programdata_path = path
|
shared.core.egl.programdata_path = path
|
||||||
shared.core.lgd.config.set("Legendary", "egl_programdata", path)
|
shared.core.lgd.config.set("Legendary", "egl_programdata", path)
|
||||||
shared.core.lgd.save_config()
|
shared.core.lgd.save_config()
|
||||||
|
@ -144,22 +142,18 @@ class EGLSyncGroup(QGroupBox, Ui_EGLSyncGroup):
|
||||||
# self.export_list.action()
|
# self.export_list.action()
|
||||||
self.core.lgd.save_config()
|
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):
|
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:
|
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()
|
shared.core.egl.manifests.clear()
|
||||||
self.egl_sync_label.setEnabled(have_path)
|
self.egl_sync_label.setEnabled(have_path)
|
||||||
self.egl_sync_check.setEnabled(have_path)
|
self.egl_sync_check.setEnabled(have_path)
|
||||||
|
|
||||||
self.import_list.populate(have_path)
|
self.import_list.populate(have_path)
|
||||||
self.import_list.setEnabled(have_path)
|
self.import_list.setEnabled(have_path)
|
||||||
self.export_list.populate(have_path)
|
self.export_list.populate(have_path)
|
||||||
self.export_list.setEnabled(have_path)
|
self.export_list.setEnabled(have_path)
|
||||||
|
self.egl_watcher.blockSignals(False)
|
||||||
|
|
||||||
|
|
||||||
class EGLSyncListItem(QListWidgetItem):
|
class EGLSyncListItem(QListWidgetItem):
|
||||||
|
@ -208,12 +202,20 @@ class EGLSyncListGroup(QGroupBox, Ui_EGLSyncListGroup):
|
||||||
lambda item:
|
lambda item:
|
||||||
item.setCheckState(Qt.Unchecked) if item.checkState() != Qt.Unchecked else item.setCheckState(Qt.Checked)
|
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_all_button.clicked.connect(lambda: self.mark(Qt.Checked))
|
||||||
self.select_none_button.clicked.connect(lambda: self.mark(Qt.Unchecked))
|
self.select_none_button.clicked.connect(lambda: self.mark(Qt.Unchecked))
|
||||||
|
|
||||||
self.action_button.clicked.connect(self.action)
|
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):
|
def mark(self, state):
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
item.setCheckState(state)
|
item.setCheckState(state)
|
||||||
|
@ -236,10 +238,16 @@ class EGLSyncListGroup(QGroupBox, Ui_EGLSyncListGroup):
|
||||||
self.populate(True)
|
self.populate(True)
|
||||||
|
|
||||||
@property
|
@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())]
|
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):
|
class DisableSyncDialog(QDialog):
|
||||||
info = 1, False
|
info = 1, False
|
||||||
|
|
||||||
|
@ -315,3 +323,4 @@ class EGLSyncItemWidget(QGroupBox):
|
||||||
# FIXME: on update_egl_widget this is going to crash because
|
# 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
|
# FIXME: the item is not removed from the list in the python's side
|
||||||
self.deleteLater()
|
self.deleteLater()
|
||||||
|
'''
|
||||||
|
|
|
@ -17,6 +17,12 @@ QLabel {
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
selection-background-color: #2f4f4f;
|
selection-background-color: #2f4f4f;
|
||||||
}
|
}
|
||||||
|
QLabel[infoLabel="1"] {
|
||||||
|
color: #bbbbbb;
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QMenu,
|
QMenu,
|
||||||
QListView,
|
QListView,
|
||||||
|
|
Loading…
Reference in a new issue