-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from Victor-IX/toggle-library-visibility
Toggle-library-visibility
- Loading branch information
Showing
14 changed files
with
408 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from modules.settings import ( | ||
get_scrape_automated_builds, | ||
get_scrape_bfa_builds, | ||
get_scrape_stable_builds, | ||
get_show_bfa_builds, | ||
get_show_daily_builds, | ||
get_show_experimental_and_patch_builds, | ||
get_show_stable_builds, | ||
) | ||
from PyQt5.QtCore import pyqtSlot | ||
from PyQt5.QtWidgets import ( | ||
QButtonGroup, | ||
QFrame, | ||
QSizePolicy, | ||
QVBoxLayout, | ||
) | ||
from widgets.repo_visibility_view import RepoUserView | ||
|
||
|
||
class RepoGroup(QFrame): | ||
def __init__(self, parent=None): | ||
super().__init__(parent) | ||
self.setProperty("SettingsGroup", True) | ||
self.setContentsMargins(0, 0, 0, 0) | ||
self.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Maximum) | ||
|
||
self.stable_repo = RepoUserView( | ||
"Stable", | ||
"Production-ready builds.", | ||
library=get_show_stable_builds(), | ||
download=get_scrape_stable_builds(), | ||
parent=self, | ||
) | ||
self.daily_repo = RepoUserView( | ||
"Daily", | ||
"Builds created every day. They have the latest features and bug fixes, but they can be unstable.", | ||
library=get_show_daily_builds(), | ||
download=get_scrape_automated_builds(), | ||
bind_download_to_library=False, | ||
parent=self, | ||
) | ||
self.experimental_repo = RepoUserView( | ||
"Experimental and Patch", | ||
"These have new features that may end up in official Blender releases. They can be unstable.", | ||
library=get_show_experimental_and_patch_builds(), | ||
download=get_scrape_automated_builds(), | ||
bind_download_to_library=False, | ||
parent=self, | ||
) | ||
self.bforartists_repo = RepoUserView( | ||
"Bforartists", | ||
"A popular fork of Blender with the goal of improving the UI.", | ||
library=get_show_bfa_builds(), | ||
download=get_scrape_bfa_builds(), | ||
parent=self, | ||
) | ||
|
||
self.daily_repo.library_changed.connect(self.check_if_both_automated_are_disabled) | ||
self.experimental_repo.library_changed.connect(self.check_if_both_automated_are_disabled) | ||
|
||
self.automated_groups = QButtonGroup() | ||
self.automated_groups.setExclusive(False) | ||
self.daily_repo.add_downloads_to_group(self.automated_groups) | ||
self.experimental_repo.add_downloads_to_group(self.automated_groups) | ||
|
||
self.check_if_both_automated_are_disabled() | ||
|
||
self.repos = [ | ||
self.stable_repo, | ||
self.daily_repo, | ||
self.experimental_repo, | ||
self.bforartists_repo, | ||
] | ||
|
||
self.layout_ = QVBoxLayout(self) | ||
self.layout_.setContentsMargins(0, 0, 0, 5) | ||
|
||
for widget in self.repos: | ||
self.layout_.addWidget(widget) | ||
|
||
@pyqtSlot() | ||
def check_if_both_automated_are_disabled(self): | ||
if (not self.daily_repo.library) and (not self.experimental_repo.library): | ||
self.daily_repo.download = False # Will also set experimental_repo | ||
self.daily_repo.download_enable_button.setEnabled(False) | ||
self.experimental_repo.download_enable_button.setEnabled(False) | ||
return | ||
if (self.daily_repo.library or self.experimental_repo.library) and not self.daily_repo.download: | ||
self.daily_repo.download_enable_button.setEnabled(True) | ||
self.experimental_repo.download_enable_button.setEnabled(True) | ||
|
||
def total_height(self): | ||
return sum(r.height() for r in self.repos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
from __future__ import annotations | ||
|
||
from PyQt5.QtCore import Qt, pyqtSignal | ||
from PyQt5.QtGui import QFont | ||
from PyQt5.QtWidgets import ( | ||
QButtonGroup, | ||
QCheckBox, | ||
QGridLayout, | ||
QLabel, | ||
QSizePolicy, | ||
QVBoxLayout, | ||
QWidget, | ||
) | ||
|
||
|
||
class RepoUserView(QWidget): | ||
library_changed = pyqtSignal(bool) | ||
download_changed = pyqtSignal(bool) | ||
|
||
def __init__( | ||
self, | ||
name: str, | ||
description: str = "", | ||
library: bool | None = True, # bool if used, None if disabled | ||
download: bool | None = True, # bool if used, None if disabled | ||
bind_download_to_library: bool = True, | ||
parent=None, | ||
): | ||
super().__init__(parent) | ||
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum) | ||
self.name = name | ||
|
||
self.title_label = QLabel(name, self) | ||
self.title_label.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) | ||
font = QFont(self.title_label.font()) | ||
font.setPointSize(11) | ||
self.title_label.setFont(font) | ||
if description: | ||
self.title_label.setToolTip(description) | ||
|
||
self.library_enable_button = QCheckBox(self) | ||
self.library_enable_button.setProperty("Visibility", True) | ||
self.library_enable_button.setChecked(library or False) | ||
self.library_enable_button.setToolTip( | ||
"Make this repository visible / hidden in the launcher view.<br>\ | ||
If disabled, then it will automatically disable fetching,<br>\ | ||
unless another repository shares the fetching behavior." | ||
) | ||
self.library_enable_button.toggled.connect(self.__library_button_toggled) | ||
|
||
if library is None: | ||
self.library_enable_button.setEnabled(False) | ||
|
||
self.download_enable_button = QCheckBox(self) | ||
self.download_enable_button.setProperty("Download", True) | ||
self.download_enable_button.setChecked(download or False) | ||
self.download_enable_button.setToolTip( | ||
'Enable / Disable fetching this repository.<br>\ | ||
If you force-check by holding SHIFT while pressing the "Check" button,<br>\ | ||
Then all visible categories will download regardless of fetching settings.' | ||
) | ||
self.download_enable_button.toggled.connect(self.__download_button_toggled) | ||
self.previous_download = download or False | ||
|
||
if download is None: | ||
self.download_enable_button.setEnabled(False) | ||
|
||
self.bind_download_to_library = bind_download_to_library | ||
|
||
self.layout_ = QGridLayout(self) | ||
self.layout_.setContentsMargins(5, 5, 0, 5) | ||
self.layout_.setSpacing(5) | ||
self.layout_.setSizeConstraint(QVBoxLayout.SizeConstraint.SetMinimumSize) | ||
self.layout_.setAlignment(Qt.AlignmentFlag.AlignVCenter) | ||
|
||
self.layout_.addWidget(self.title_label, 0, 0, 1, 1) | ||
self.layout_.addWidget(self.library_enable_button, 0, 1, 1, 1) | ||
self.layout_.addWidget(self.download_enable_button, 0, 2, 1, 1) | ||
|
||
def add_library_to_group(self, grp: QButtonGroup): | ||
grp.addButton(self.library_enable_button) | ||
grp.buttonToggled.connect(self.__library_toggled) | ||
|
||
def add_downloads_to_group(self, grp: QButtonGroup): | ||
grp.addButton(self.download_enable_button) | ||
grp.buttonToggled.connect(self.__download_toggled) | ||
|
||
def __library_button_toggled(self, checked: bool): | ||
self.title_label.setEnabled(checked) | ||
if self.bind_download_to_library: | ||
self.__library_bound_toggle(checked) | ||
self.library_changed.emit(checked) | ||
|
||
def __download_button_toggled(self, checked: bool): | ||
if not self.library_enable_button.isChecked() and checked: | ||
self.library_enable_button.setChecked(True) | ||
self.download_enable_button.setChecked(checked) | ||
self.download_changed.emit(checked) | ||
|
||
def __library_bound_toggle(self, b: bool): | ||
if not b: | ||
self.previous_download = self.download_enable_button.isChecked() | ||
self.download_enable_button.setChecked(False) | ||
else: | ||
self.download_enable_button.setChecked(self.previous_download) | ||
|
||
def __library_toggled(self, btn: QCheckBox, checked: bool): | ||
if btn is not self and checked != self.library_enable_button.isChecked(): | ||
self.library_enable_button.setChecked(checked) | ||
|
||
def __download_toggled(self, btn: QCheckBox, checked: bool): | ||
if btn is not self and checked != self.download_enable_button.isChecked(): | ||
self.download_enable_button.setChecked(checked) | ||
|
||
@property | ||
def download(self): | ||
return self.download_enable_button.isChecked() | ||
|
||
@download.setter | ||
def download(self, v: bool): | ||
self.download_enable_button.setChecked(v) | ||
|
||
@property | ||
def library(self): | ||
return self.library_enable_button.isChecked() |
Oops, something went wrong.