Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More ways to open files #455

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
21 changes: 21 additions & 0 deletions tagstudio/src/qt/ts_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,27 @@ def start(self) -> None:
add_new_files_action.setStatusTip("Ctrl+R")
# file_menu.addAction(refresh_lib_action)
file_menu.addAction(add_new_files_action)

open_selected_action = QAction("Open selected files", self)
open_selected_action.triggered.connect(
lambda: (
(
[self.item_thumbs[selection].opener.open_file() for selection in self.selected]
if QApplication.focusWidget() == self.main_window.scrollArea
else None
),
logger.info("Opening files", count=len(self.selected)),
)
)
shortcut = QtCore.QKeyCombination(
QtCore.Qt.KeyboardModifier(QtCore.Qt.KeyboardModifier.ControlModifier),
QtCore.Qt.Key.Key_Down,
)
if sys.platform == "win32":
shortcut = Qt.Key.Key_Return

open_selected_action.setShortcut(shortcut)
file_menu.addAction(open_selected_action)
file_menu.addSeparator()

close_library_action = QAction("&Close Library", menu_bar)
Expand Down
1 change: 1 addition & 0 deletions tagstudio/src/qt/widgets/item_thumb.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def __init__(
self.thumb_button.setContextMenuPolicy(Qt.ContextMenuPolicy.ActionsContextMenu)

self.opener = FileOpenerHelper("")
self.thumb_button.double_clicked.connect(lambda: self.opener.open_file())
open_file_action = QAction("Open file", self)
open_file_action.triggered.connect(self.opener.open_file)
open_explorer_action = QAction("Open file in explorer", self)
Expand Down
28 changes: 26 additions & 2 deletions tagstudio/src/qt/widgets/thumb_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@


from PySide6 import QtCore
from PySide6.QtCore import QEvent
from PySide6.QtGui import QColor, QEnterEvent, QPainter, QPainterPath, QPaintEvent, QPen
from PySide6.QtCore import QEvent, Signal
from PySide6.QtGui import (
QColor,
QEnterEvent,
QMouseEvent,
QPainter,
QPainterPath,
QPaintEvent,
QPen,
)
from PySide6.QtWidgets import QWidget
from src.qt.helpers.qbutton_wrapper import QPushButtonWrapper


class ThumbButton(QPushButtonWrapper):
double_clicked = Signal()

def __init__(self, parent: QWidget, thumb_size: tuple[int, int]) -> None:
super().__init__(parent)
self.thumb_size: tuple[int, int] = thumb_size
self.hovered = False
self.selected = False

self.double_click = False

# self.clicked.connect(lambda checked: self.set_selected(True))

def paintEvent(self, event: QPaintEvent) -> None: # noqa: N802
Expand Down Expand Up @@ -81,3 +93,15 @@ def leaveEvent(self, event: QEvent) -> None: # noqa: N802
def set_selected(self, value: bool) -> None:
self.selected = value
self.repaint()

def mousePressEvent(self, e: QMouseEvent) -> None: # noqa: N802
self.double_click = False

def mouseDoubleClickEvent(self, e: QMouseEvent) -> None: # noqa: N802
self.double_click = True

def mouseReleaseEvent(self, e: QMouseEvent) -> None: # noqa: N802
if self.double_click:
self.double_clicked.emit()
else:
self.clicked.emit()
1 change: 1 addition & 0 deletions tagstudio/src/qt/widgets/video_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(self, driver: "QtDriver") -> None:

open_file_action = QAction("Open file", self)
open_file_action.triggered.connect(self.opener.open_file)

open_explorer_action = QAction("Open file in explorer", self)
open_explorer_action.triggered.connect(self.opener.open_explorer)
self.addAction(open_file_action)
Expand Down