Skip to content

Commit

Permalink
Merge pull request #157 from Victor-IX/toggle-library-visibility
Browse files Browse the repository at this point in the history
Toggle-library-visibility
  • Loading branch information
Victor-IX authored Nov 5, 2024
2 parents 55cbae0 + 271b221 commit 6fe52a3
Show file tree
Hide file tree
Showing 14 changed files with 408 additions and 47 deletions.
32 changes: 32 additions & 0 deletions source/modules/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,38 @@ def set_scrape_bfa_builds(b: bool):
get_settings().setValue("scrape_bfa_builds", b)


def get_show_stable_builds() -> bool:
return get_settings().value("show_stable_builds", defaultValue=True, type=bool)


def set_show_stable_builds(b: bool):
get_settings().setValue("show_stable_builds", b)


def get_show_daily_builds() -> bool:
return get_settings().value("show_daily_builds", defaultValue=True, type=bool)


def set_show_daily_builds(b: bool):
get_settings().setValue("show_daily_builds", b)


def get_show_experimental_and_patch_builds() -> bool:
return get_settings().value("show_experimental_and_patch_builds", defaultValue=True, type=bool)


def set_show_experimental_and_patch_builds(b: bool):
get_settings().setValue("show_experimental_and_patch_builds", b)


def get_show_bfa_builds() -> bool:
return get_settings().value("show_bfa_builds", defaultValue=True, type=bool)


def set_show_bfa_builds(b: bool):
get_settings().setValue("show_bfa_builds", b)


def get_show_daily_archive_builds() -> bool:
return get_settings().value("show_daily_archive_builds", defaultValue=False, type=bool)

Expand Down
1 change: 1 addition & 0 deletions source/resources/icons/download_off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions source/resources/icons/download_on.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions source/resources/icons/visibility_off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions source/resources/icons/visibility_on.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions source/resources/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<file>icons/file.svg</file>
<file>icons/expand_less.svg</file>
<file>icons/expand_more.svg</file>
<file>icons/visibility_on.svg</file>
<file>icons/visibility_off.svg</file>
<file>icons/download_on.svg</file>
<file>icons/download_off.svg</file>
<file>styles/global.qss</file>
<file>fonts/OpenSans-SemiBold.ttf</file>
</qresource>
Expand Down
18 changes: 17 additions & 1 deletion source/resources/styles/QCheckBox.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,20 @@ QCheckBox::indicator:checked {

QCheckBox::indicator:unchecked {
image: url(:resources/icons/box_unchecked.svg);
}
}

QCheckBox[Visibility=true]::indicator:checked {
image: url(:resources/icons/visibility_on.svg);
}

QCheckBox[Visibility=true]::indicator:unchecked {
image: url(:resources/icons/visibility_off.svg);
}

QCheckBox[Download=true]::indicator:checked {
image: url(:resources/icons/download_on.svg);
}

QCheckBox[Download=true]::indicator:unchecked {
image: url(:resources/icons/download_off.svg);
}
6 changes: 6 additions & 0 deletions source/resources/styles/QPushButton.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ QPushButton[CreateButton=true] {
padding: 9px;
}

QPushButton[CreateButton=true]:disabled {
background-color: rgb(133, 133, 133);
color: black;
padding: 9px;
}

QPushButton[InstalledButton=true] {
background-color: #318CE7;
border: none;
Expand Down
1 change: 0 additions & 1 deletion source/widgets/folder_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def set_folder(self, folder: Path, relative: bool | None = None):
if (self.check_perms and self.check_write_permission()) or not self.check_perms:
self.folder_changed.emit(folder)


def check_write_permission(self) -> bool:
path = Path(self.line_edit.text())
if not path.exists():
Expand Down
93 changes: 93 additions & 0 deletions source/widgets/repo_group.py
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)
125 changes: 125 additions & 0 deletions source/widgets/repo_visibility_view.py
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()
Loading

0 comments on commit 6fe52a3

Please sign in to comment.