mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-02-01 15:49:09 +00:00
Open/Close all buttons
This commit is contained in:
@@ -77,73 +77,7 @@ def reverse_tag(library:Library,tag:Tag,list:list[Tag]) -> list[Tag]:
|
||||
|
||||
#=========== UI ===========
|
||||
|
||||
|
||||
class FoldersToTagsModal(QWidget):
|
||||
# done = Signal(int)
|
||||
def __init__(self, library:'Library', driver:'QtDriver'):
|
||||
super().__init__()
|
||||
self.library = library
|
||||
self.driver = driver
|
||||
self.count = -1
|
||||
self.filename = ''
|
||||
|
||||
self.setWindowTitle(f'Folders To Tags')
|
||||
self.setWindowModality(Qt.WindowModality.ApplicationModal)
|
||||
self.setMinimumSize(500, 800)
|
||||
self.root_layout = QVBoxLayout(self)
|
||||
self.root_layout.setContentsMargins(6,6,6,6)
|
||||
|
||||
self.desc_widget = QLabel()
|
||||
self.desc_widget.setObjectName('descriptionLabel')
|
||||
self.desc_widget.setWordWrap(True)
|
||||
self.desc_widget.setStyleSheet(
|
||||
# 'background:blue;'
|
||||
'text-align:left;'
|
||||
# 'font-weight:bold;'
|
||||
'font-size:18px;'
|
||||
# 'padding-top: 6px'
|
||||
'')
|
||||
self.desc_widget.setText('''Creates tags based on the folder structure and applies them to entries.\n The Structure below shows all the tags that would be added and to which files they would be added. It being empty means that there are no Tag to be created or assigned''')
|
||||
self.desc_widget.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
self.scroll_contents = QWidget()
|
||||
self.scroll_layout = QVBoxLayout(self.scroll_contents)
|
||||
self.scroll_layout.setContentsMargins(6,0,6,0)
|
||||
self.scroll_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
||||
|
||||
self.scroll_area = QScrollArea()
|
||||
self.scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
|
||||
self.scroll_area.setWidgetResizable(True)
|
||||
self.scroll_area.setFrameShadow(QFrame.Shadow.Plain)
|
||||
self.scroll_area.setFrameShape(QFrame.Shape.NoFrame)
|
||||
self.scroll_area.setWidget(self.scroll_contents)
|
||||
|
||||
self.apply_button = QPushButton()
|
||||
self.apply_button.setText('&Apply')
|
||||
self.apply_button.mouseReleaseEvent = self.on_apply
|
||||
|
||||
self.showEvent = self.on_open
|
||||
|
||||
self.root_layout.addWidget(self.desc_widget)
|
||||
self.root_layout.addWidget(self.scroll_area)
|
||||
self.root_layout.addWidget(self.apply_button)
|
||||
|
||||
def on_apply(self,event):
|
||||
folders_to_tags(self.library)
|
||||
self.close()
|
||||
self.driver.preview_panel.update_widgets()
|
||||
|
||||
def on_open(self,event):
|
||||
for i in reversed(range(self.scroll_layout.count())):
|
||||
self.scroll_layout.itemAt(i).widget().setParent(None)
|
||||
|
||||
data = self.generate_preview_data(self.library)
|
||||
|
||||
for folder in data["dirs"].values():
|
||||
test = TreeItem(folder,None)
|
||||
self.scroll_layout.addWidget(test)
|
||||
|
||||
def generate_preview_data(self,library:Library):
|
||||
def generate_preview_data(library:Library):
|
||||
tree = dict(dirs={},files=[])
|
||||
|
||||
def add_tag_to_tree(list:list[Tag]):
|
||||
@@ -200,6 +134,146 @@ class FoldersToTagsModal(QWidget):
|
||||
|
||||
return tree
|
||||
|
||||
|
||||
class FoldersToTagsModal(QWidget):
|
||||
# done = Signal(int)
|
||||
def __init__(self, library:'Library', driver:'QtDriver'):
|
||||
super().__init__()
|
||||
self.library = library
|
||||
self.driver = driver
|
||||
self.count = -1
|
||||
self.filename = ''
|
||||
|
||||
self.setWindowTitle(f'Folders To Tags')
|
||||
self.setWindowModality(Qt.WindowModality.ApplicationModal)
|
||||
self.setMinimumSize(500, 800)
|
||||
self.root_layout = QVBoxLayout(self)
|
||||
self.root_layout.setContentsMargins(6,6,6,6)
|
||||
|
||||
self.desc_widget = QLabel()
|
||||
self.desc_widget.setObjectName('descriptionLabel')
|
||||
self.desc_widget.setWordWrap(True)
|
||||
self.desc_widget.setStyleSheet(
|
||||
# 'background:blue;'
|
||||
'text-align:left;'
|
||||
# 'font-weight:bold;'
|
||||
'font-size:18px;'
|
||||
# 'padding-top: 6px'
|
||||
'')
|
||||
self.desc_widget.setText('''Creates tags based on the folder structure and applies them to entries.\n The Structure below shows all the tags that would be added and to which files they would be added. It being empty means that there are no Tag to be created or assigned''')
|
||||
self.desc_widget.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
self.open_close_button_w = QWidget()
|
||||
self.open_close_button_layout = QHBoxLayout(self.open_close_button_w)
|
||||
|
||||
self.open_all_button = QPushButton()
|
||||
self.open_all_button.setText("Open All")
|
||||
self.open_all_button.clicked.connect(lambda:self.set_all_branches(False))
|
||||
self.close_all_button = QPushButton()
|
||||
self.close_all_button.setText("Close All")
|
||||
self.close_all_button.clicked.connect(lambda:self.set_all_branches(True))
|
||||
|
||||
self.open_close_button_layout.addWidget(self.open_all_button)
|
||||
self.open_close_button_layout.addWidget(self.close_all_button)
|
||||
|
||||
self.scroll_contents = QWidget()
|
||||
self.scroll_layout = QVBoxLayout(self.scroll_contents)
|
||||
self.scroll_layout.setContentsMargins(6,0,6,0)
|
||||
self.scroll_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
||||
|
||||
self.scroll_area = QScrollArea()
|
||||
self.scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
|
||||
self.scroll_area.setWidgetResizable(True)
|
||||
self.scroll_area.setFrameShadow(QFrame.Shadow.Plain)
|
||||
self.scroll_area.setFrameShape(QFrame.Shape.NoFrame)
|
||||
self.scroll_area.setWidget(self.scroll_contents)
|
||||
|
||||
self.apply_button = QPushButton()
|
||||
self.apply_button.setText('&Apply')
|
||||
self.apply_button.clicked.connect(self.on_apply)
|
||||
|
||||
self.showEvent = self.on_open
|
||||
|
||||
self.root_layout.addWidget(self.desc_widget)
|
||||
self.root_layout.addWidget(self.open_close_button_w)
|
||||
self.root_layout.addWidget(self.scroll_area)
|
||||
self.root_layout.addWidget(self.apply_button)
|
||||
|
||||
def on_apply(self,event):
|
||||
folders_to_tags(self.library)
|
||||
self.close()
|
||||
self.driver.preview_panel.update_widgets()
|
||||
|
||||
def on_open(self,event):
|
||||
for i in reversed(range(self.scroll_layout.count())):
|
||||
self.scroll_layout.itemAt(i).widget().setParent(None)
|
||||
|
||||
data = generate_preview_data(self.library)
|
||||
|
||||
for folder in data["dirs"].values():
|
||||
test = TreeItem(folder,None)
|
||||
self.scroll_layout.addWidget(test)
|
||||
|
||||
def set_all_branches(self,hidden:bool):
|
||||
for i in reversed(range(self.scroll_layout.count())):
|
||||
child = self.scroll_layout.itemAt(i).widget()
|
||||
if type(child) == TreeItem:
|
||||
child.set_all_branches(hidden)
|
||||
|
||||
class TreeItem(QWidget):
|
||||
def __init__(self,data:dict,parentTag:Tag):
|
||||
super().__init__()
|
||||
|
||||
self.setStyleSheet("QLabel{font-size: 13px}")
|
||||
|
||||
self.root_layout = QVBoxLayout(self)
|
||||
self.root_layout.setContentsMargins(20,0,0,0)
|
||||
self.root_layout.setSpacing(1)
|
||||
|
||||
self.test = QWidget()
|
||||
self.root_layout.addWidget(self.test)
|
||||
|
||||
self.tag_layout = FlowLayout(self.test)
|
||||
|
||||
self.label = QLabel()
|
||||
self.tag_layout.addWidget(self.label)
|
||||
self.tag_widget = ModifiedTagWidget(data["tag"],parentTag)
|
||||
self.tag_widget.bg_button.clicked.connect(lambda:self.hide_show())
|
||||
self.tag_layout.addWidget(self.tag_widget)
|
||||
|
||||
self.children_widget = QWidget()
|
||||
self.children_layout = QVBoxLayout(self.children_widget)
|
||||
self.root_layout.addWidget(self.children_widget)
|
||||
|
||||
self.populate(data)
|
||||
|
||||
def hide_show(self):
|
||||
self.children_widget.setHidden(not self.children_widget.isHidden())
|
||||
self.label.setText(">" if self.children_widget.isHidden() else "v")
|
||||
|
||||
def populate(self,data:dict):
|
||||
for folder in data["dirs"].values():
|
||||
item = TreeItem(folder,data["tag"])
|
||||
self.children_layout.addWidget(item)
|
||||
for file in data["files"]:
|
||||
label = QLabel()
|
||||
label.setText(" -> "+file)
|
||||
self.children_layout.addWidget(label)
|
||||
|
||||
if len(data["files"]) == 0 and len(data["dirs"].values()) == 0:
|
||||
self.hide_show()
|
||||
else:
|
||||
self.label.setText("v")
|
||||
|
||||
def set_all_branches(self,hidden:bool):
|
||||
for i in reversed(range(self.children_layout.count())):
|
||||
child = self.children_layout.itemAt(i).widget()
|
||||
if type(child) == TreeItem:
|
||||
child.set_all_branches(hidden)
|
||||
|
||||
self.children_widget.setHidden(hidden)
|
||||
self.label.setText(">" if self.children_widget.isHidden() else "v")
|
||||
|
||||
class ModifiedTagWidget(QWidget): # Needed to be modified because the original searched the display name in the library where it wasn't added yet
|
||||
def __init__(self, tag:Tag,parentTag:Tag) -> None:
|
||||
super().__init__()
|
||||
@@ -244,41 +318,4 @@ class ModifiedTagWidget(QWidget): # Needed to be modified because the original s
|
||||
f'}}')
|
||||
|
||||
self.base_layout.addWidget(self.bg_button)
|
||||
self.setMinimumSize(50,20)
|
||||
class TreeItem(QWidget):
|
||||
def __init__(self,data:dict,parentTag:Tag):
|
||||
super().__init__()
|
||||
|
||||
self.root_layout = QVBoxLayout(self)
|
||||
self.root_layout.setContentsMargins(20,0,0,0)
|
||||
self.root_layout.setSpacing(1)
|
||||
|
||||
self.test = QWidget()
|
||||
self.root_layout.addWidget(self.test)
|
||||
|
||||
self.tag_layout = FlowLayout(self.test)
|
||||
|
||||
self.tag_widget = ModifiedTagWidget(data["tag"],parentTag)
|
||||
self.tag_widget.bg_button.clicked.connect(lambda:self.hide_show())
|
||||
self.tag_layout.addWidget(self.tag_widget)
|
||||
|
||||
self.children_widget = QWidget()
|
||||
self.children_layout = QVBoxLayout(self.children_widget)
|
||||
self.root_layout.addWidget(self.children_widget)
|
||||
|
||||
self.populate(data)
|
||||
|
||||
def hide_show(self):
|
||||
self.children_widget.setHidden(not self.children_widget.isHidden())
|
||||
|
||||
def populate(self,data:dict):
|
||||
for folder in data["dirs"].values():
|
||||
item = TreeItem(folder,data["tag"])
|
||||
self.children_layout.addWidget(item)
|
||||
for file in data["files"]:
|
||||
label = QLabel()
|
||||
label.setText(file)
|
||||
self.children_layout.addWidget(label)
|
||||
|
||||
if len(data["files"]) == 0 and len(data["dirs"].values()) == 0:
|
||||
self.hide_show()
|
||||
self.setMinimumSize(50,20)
|
||||
Reference in New Issue
Block a user