1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2024-12-21 23:33:13 +00:00

Use Qt signals instead of calling child widgets (#2161)

This commit is contained in:
Manu 2024-12-05 13:28:16 +00:00 committed by GitHub
parent dfba373871
commit f0d0fa07fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 55 additions and 49 deletions

View file

@ -42,6 +42,7 @@ class VortaApp(QtSingleApplication):
backup_log_event = QtCore.pyqtSignal(str, dict)
backup_progress_event = QtCore.pyqtSignal(str)
check_failed_event = QtCore.pyqtSignal(dict)
profile_changed_event = QtCore.pyqtSignal()
def __init__(self, args_raw, single_app=False):
super().__init__(str(APP_ID), args_raw)

View file

@ -150,8 +150,13 @@ def __init__(self, parent=None, app=None):
self.selected_archives = None # TODO: remove unused variable
self.set_icons()
# Connect to palette change
self.app.paletteChanged.connect(lambda p: self.set_icons())
# Connect to events
self.app.paletteChanged.connect(self.set_icons)
self.app.paletteChanged.connect(self.populate_from_profile)
self.app.backup_finished_event.connect(self.populate_from_profile)
self.app.profile_changed_event.connect(self.populate_from_profile)
self.app.profile_changed_event.connect(self.toggle_compact_button_visibility)
self.app.backup_cancelled_event.connect(self.cancel_action)
def set_icons(self):
"""Used when changing between light- and dark mode"""

View file

@ -1,12 +1,13 @@
from PyQt6 import uic
from PyQt6.QtWidgets import (
QAbstractItemView,
QApplication,
QHeaderView,
QTableWidgetItem,
)
from vorta import config
from vorta.store.models import EventLogModel
from vorta.store.models import BackupProfileMixin, EventLogModel
from vorta.utils import get_asset
uifile = get_asset('UI/log_page.ui')
@ -21,11 +22,13 @@ class LogTableColumn:
ReturnCode = 4
class LogPage(LogTableBase, LogTableUI):
class LogPage(LogTableBase, LogTableUI, BackupProfileMixin):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.init_ui()
QApplication.instance().backup_finished_event.connect(self.populate_logs)
QApplication.instance().profile_changed_event.connect(self.populate_logs)
def init_ui(self):
self.logPage.setAlternatingRowColors(True)
@ -44,7 +47,13 @@ def init_ui(self):
self.populate_logs()
def populate_logs(self):
event_logs = [s for s in EventLogModel.select().order_by(EventLogModel.start_time.desc())]
profile = self.profile()
event_logs = [
s
for s in EventLogModel.select()
.where(EventLogModel.profile == profile.id)
.order_by(EventLogModel.start_time.desc())
]
sorting = self.logPage.isSortingEnabled()
self.logPage.setSortingEnabled(False)

View file

@ -184,19 +184,13 @@ def profile_selection_changed_action(self, index):
backup_profile_id = profile.data(Qt.ItemDataRole.UserRole) if profile else None
if not backup_profile_id:
return
self.current_profile = BackupProfileModel.get(id=backup_profile_id)
self.archiveTab.populate_from_profile()
self.repoTab.populate_from_profile()
self.sourceTab.populate_from_profile()
self.scheduleTab.schedulePage.populate_from_profile()
self.scheduleTab.networksPage.populate_wifi()
self.scheduleTab.networksPage.setup_connections()
self.scheduleTab.shellCommandsPage.populate_from_profile()
self.current_profile = BackupProfileModel.get(id=backup_profile_id)
SettingsModel.update({SettingsModel.str_value: self.current_profile.id}).where(
SettingsModel.key == 'previous_profile_id'
).execute()
self.archiveTab.toggle_compact_button_visibility()
self.app.profile_changed_event.emit()
def profile_clicked_action(self):
if self.miscWidget.isVisible():
@ -266,11 +260,8 @@ def profile_imported_event(profile):
self.tr('Profile import successful!'),
self.tr('Profile {} imported.').format(profile.name),
)
self.repoTab.populate_from_profile()
self.scheduleTab.logPage.populate_logs()
self.scheduleTab.networksPage.populate_wifi()
self.miscTab.populate()
self.populate_profile_selector()
self.app.profile_changed_event.emit()
filename = QFileDialog.getOpenFileName(
self,
@ -328,10 +319,6 @@ def backup_started_event(self):
self.set_log('')
def backup_finished_event(self):
self.archiveTab.populate_from_profile()
self.repoTab.init_repo_stats()
self.scheduleTab.logPage.populate_logs()
if not self.app.jobs_manager.is_worker_running() and (
self.archiveTab.remaining_refresh_archives == 0 or self.archiveTab.remaining_refresh_archives == 1
): # Either the refresh is done or this is the last archive to refresh.
@ -341,7 +328,6 @@ def backup_finished_event(self):
def backup_cancelled_event(self):
self._toggle_buttons(create_enabled=True)
self.set_log(self.tr('Task cancelled'))
self.archiveTab.cancel_action()
def closeEvent(self, event):
# Save window state in SettingsModel

View file

@ -44,8 +44,9 @@ def __init__(self, parent=None):
self.populate()
# Connect to palette change
# Connect to events
QApplication.instance().paletteChanged.connect(lambda p: self.set_icons())
QApplication.instance().profile_changed_event.connect(self.populate)
def populate(self):
"""

View file

@ -1,6 +1,6 @@
from PyQt6 import uic
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QCheckBox, QLabel, QListWidget, QListWidgetItem
from PyQt6.QtWidgets import QApplication, QCheckBox, QLabel, QListWidget, QListWidgetItem
from vorta.store.models import BackupProfileMixin, WifiSettingModel
from vorta.utils import get_asset, get_sorted_wifis
@ -18,12 +18,12 @@ def __init__(self, parent=None):
self.meteredNetworksCheckBox: QCheckBox = self.findChild(QCheckBox, 'meteredNetworksCheckBox')
self.wifiListWidget: QListWidget = self.findChild(QListWidget, 'wifiListWidget')
self.populate_wifi()
self.setup_connections()
def setup_connections(self):
# Connect signals
self.meteredNetworksCheckBox.stateChanged.connect(self.on_metered_networks_state_changed)
self.wifiListWidget.itemChanged.connect(self.save_wifi_item)
QApplication.instance().profile_changed_event.connect(self.populate_wifi)
self.populate_wifi()
def on_metered_networks_state_changed(self, state):
profile = self.profile()

View file

@ -63,12 +63,13 @@ def __init__(self, parent=None):
self.bAddSSHKey.clicked.connect(self.create_ssh_key)
self.set_icons()
# Connect to palette change
QApplication.instance().paletteChanged.connect(lambda p: self.set_icons())
self.populate_from_profile() # needs init of ssh and compression items
# Connect to events
QApplication.instance().paletteChanged.connect(lambda p: self.set_icons())
QApplication.instance().profile_changed_event.connect(self.populate_from_profile)
QApplication.instance().backup_finished_event.connect(self.init_repo_stats)
def set_icons(self):
self.bAddSSHKey.setIcon(get_colored_icon("plus"))
self.bAddRepo.setIcon(get_colored_icon("plus"))

View file

@ -64,6 +64,9 @@ def __init__(self, parent=None):
self.app.scheduler.schedule_changed.connect(lambda pid: self.draw_next_scheduled_backup())
self.populate_from_profile()
# Listen for events
self.app.profile_changed_event.connect(self.populate_from_profile)
def on_scheduler_change(self, _):
profile = self.profile()
for label, obj in self.schedulerRadioMapping.items():

View file

@ -1,5 +1,5 @@
from PyQt6 import uic
from PyQt6.QtWidgets import QLineEdit, QWidget
from PyQt6.QtWidgets import QApplication, QLineEdit, QWidget
from vorta.store.models import BackupProfileMixin
from vorta.utils import get_asset
@ -15,7 +15,17 @@ def __init__(self, parent=None):
self.postBackupCmdLineEdit: QLineEdit = self.findChild(QLineEdit, 'postBackupCmdLineEdit')
self.createCmdLineEdit: QLineEdit = self.findChild(QLineEdit, 'createCmdLineEdit')
self.populate_from_profile()
self.setup_connections()
self.preBackupCmdLineEdit.textEdited.connect(
lambda new_val, attr='pre_backup_cmd': self.save_profile_attr(attr, new_val)
)
self.postBackupCmdLineEdit.textEdited.connect(
lambda new_val, attr='post_backup_cmd': self.save_profile_attr(attr, new_val)
)
self.createCmdLineEdit.textEdited.connect(
lambda new_val, attr='create_backup_cmd': self.save_repo_attr(attr, new_val)
)
QApplication.instance().profile_changed_event.connect(self.populate_from_profile)
def populate_from_profile(self):
profile = self.profile()
@ -33,17 +43,6 @@ def populate_from_profile(self):
self.preBackupCmdLineEdit.setEnabled(False)
self.postBackupCmdLineEdit.setEnabled(False)
def setup_connections(self):
self.preBackupCmdLineEdit.textEdited.connect(
lambda new_val, attr='pre_backup_cmd': self.save_profile_attr(attr, new_val)
)
self.postBackupCmdLineEdit.textEdited.connect(
lambda new_val, attr='post_backup_cmd': self.save_profile_attr(attr, new_val)
)
self.createCmdLineEdit.textEdited.connect(
lambda new_val, attr='create_backup_cmd': self.save_repo_attr(attr, new_val)
)
def save_profile_attr(self, attr, new_value):
profile = self.profile()
setattr(profile, attr, new_value)

View file

@ -106,13 +106,14 @@ def __init__(self, parent=None):
self.bExclude.clicked.connect(self.show_exclude_dialog)
header.sortIndicatorChanged.connect(self.update_sort_order)
# Connect to palette change
QApplication.instance().paletteChanged.connect(lambda p: self.set_icons())
# Populate
self.populate_from_profile()
self.set_icons()
# Listen for events
QApplication.instance().paletteChanged.connect(lambda p: self.set_icons())
QApplication.instance().profile_changed_event.connect(self.populate_from_profile)
def set_icons(self):
"Used when changing between light- and dark mode"
self.addButton.setIcon(get_colored_icon('plus'))