Skip to content

Commit 46ae3a6

Browse files
committed
add button for removing recent lib
1 parent 06f528f commit 46ae3a6

File tree

3 files changed

+68
-24
lines changed

3 files changed

+68
-24
lines changed

tagstudio/src/core/ts_core.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
"""The core classes and methods of TagStudio."""
66

7-
import enum
87
import json
98
import os
109

@@ -19,7 +18,6 @@
1918
COLLAGE_FOLDER_NAME: str = "collages"
2019
LIBRARY_FILENAME: str = "ts_library.json"
2120

22-
2321
# TODO: Turn this whitelist into a user-configurable blacklist.
2422
IMAGE_TYPES: list[str] = [
2523
"png",

tagstudio/src/qt/ts_qt.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,11 @@ def start(self):
505505
)
506506
self.open_library(lib)
507507

508-
app.exec_()
508+
if self.args.ci:
509+
# gracefully terminate the app in CI environment
510+
self.thumb_job_queue.put((self.SIGTERM.emit, []))
511+
512+
app.exec()
509513

510514
self.shutdown()
511515

@@ -1330,6 +1334,12 @@ def filter_items(self, query=""):
13301334

13311335
# self.update_thumbs()
13321336

1337+
def remove_recent_library(self, item_key: str):
1338+
self.settings.beginGroup(SettingItems.LIBS_LIST)
1339+
self.settings.remove(item_key)
1340+
self.settings.endGroup()
1341+
self.settings.sync()
1342+
13331343
def update_libs_list(self, path: str | Path):
13341344
"""add library to list in SettingItems.LIBS_LIST"""
13351345
ITEMS_LIMIT = 5

tagstudio/src/qt/widgets/preview_panel.py

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def __init__(self, library: Library, driver: "QtDriver"):
173173
info_layout.addWidget(self.dimensions_label)
174174
info_layout.addWidget(scroll_area)
175175

176-
# keep list of rendered libraries to avoid needles re-rendering
176+
# keep list of rendered libraries to avoid needless re-rendering
177177
self.render_libs = set()
178178
self.libs_layout = QVBoxLayout()
179179
self.fill_libs_widget(self.libs_layout)
@@ -247,44 +247,80 @@ def fill_libs_widget(self, layout: QVBoxLayout):
247247
libs_sorted = sorted(lib_items.items(), key=lambda item: item[0], reverse=True)
248248

249249
self.render_libs = new_keys
250-
return self._fill_libs_widget(libs_sorted, layout)
250+
self._fill_libs_widget(libs_sorted, layout)
251251

252252
def _fill_libs_widget(
253253
self, libraries: list[tuple[str, tuple[str, str]]], layout: QVBoxLayout
254254
):
255+
def clear_layout(layout_item: QVBoxLayout):
256+
for i in reversed(range(layout_item.count())):
257+
child = layout_item.itemAt(i)
258+
if child.widget() is not None:
259+
child.widget().deleteLater()
260+
elif child.layout() is not None:
261+
clear_layout(child.layout())
262+
255263
# remove any potential previous items
256264
for idx in reversed(range(layout.count())):
257-
widget = layout.itemAt(idx).widget()
258-
layout.removeWidget(widget)
259-
# remove from GUI
260-
widget.setParent(None)
265+
row_layout = layout.itemAt(idx)
266+
clear_layout(row_layout)
261267

262268
label = QLabel("Recent Libraries")
263269
label.setAlignment(Qt.AlignCenter)
264-
layout.addWidget(label)
265270

266-
for tstamp, (full_val, cut_val) in libraries:
267-
button = QPushButton(text=cut_val)
268-
button.setObjectName(f"path{tstamp}")
271+
row_layout = QHBoxLayout()
272+
row_layout.addWidget(label)
273+
layout.addLayout(row_layout)
269274

270-
def open_library_button_clicked(path):
271-
return lambda: self.driver.open_library(path)
275+
def get_button_style(extras: list[str] | None = None):
276+
base_style = [
277+
f"background-color:{Theme.COLOR_BG.value};",
278+
"border-radius:6px;",
279+
"text-align: left;",
280+
"padding-top: 3px;",
281+
"padding-left: 6px;",
282+
"padding-bottom: 4px;",
283+
]
272284

273-
button.clicked.connect(open_library_button_clicked(full_val))
274-
button.setStyleSheet(
285+
full_style = base_style + (extras or [])
286+
287+
return (
275288
"QPushButton{"
276-
f"background-color:{Theme.COLOR_BG.value};"
277-
"border-radius:6px;"
278-
"text-align: left;"
279-
"padding-top: 3px;"
280-
"padding-left: 6px;"
281-
"padding-bottom: 4px;"
289+
f"{''.join(full_style)}"
282290
"}"
283291
f"QPushButton::hover{{background-color:{Theme.COLOR_HOVER.value};}}"
284292
f"QPushButton::pressed{{background-color:{Theme.COLOR_PRESSED.value};}}"
285293
)
294+
295+
for item_key, (full_val, cut_val) in libraries:
296+
button = QPushButton(text=cut_val)
297+
button.setObjectName(f"path{item_key}")
298+
299+
def open_library_button_clicked(path):
300+
return lambda: self.driver.open_library(path)
301+
302+
button.clicked.connect(open_library_button_clicked(full_val))
303+
button.setStyleSheet(get_button_style())
286304
button.setCursor(Qt.CursorShape.PointingHandCursor)
287-
layout.addWidget(button)
305+
306+
button_remove = QPushButton("➖")
307+
button_remove.setStyleSheet(get_button_style())
308+
button_remove.setCursor(Qt.CursorShape.PointingHandCursor)
309+
button_remove.setFixedWidth(30)
310+
311+
def remove_recent_library_clicked(key: str):
312+
return lambda: (
313+
self.driver.remove_recent_library(key),
314+
self.fill_libs_widget(self.libs_layout),
315+
)
316+
317+
button_remove.clicked.connect(remove_recent_library_clicked(item_key))
318+
319+
row_layout = QHBoxLayout()
320+
row_layout.addWidget(button)
321+
row_layout.addWidget(button_remove)
322+
323+
layout.addLayout(row_layout)
288324

289325
def resizeEvent(self, event: QResizeEvent) -> None:
290326
self.update_image_size(

0 commit comments

Comments
 (0)