|
7 | 7 | import sys
|
8 | 8 | import traceback
|
9 | 9 | from pathlib import Path
|
| 10 | +from typing import override |
10 | 11 |
|
11 | 12 | import structlog
|
12 | 13 | from PySide6.QtCore import Qt
|
13 |
| -from PySide6.QtWidgets import QLabel |
| 14 | +from PySide6.QtGui import QMouseEvent |
| 15 | +from PySide6.QtWidgets import QLabel, QWidget |
14 | 16 |
|
15 | 17 | from tagstudio.qt.helpers.silent_popen import silent_Popen
|
16 | 18 |
|
@@ -115,36 +117,40 @@ def open_explorer(self):
|
115 | 117 |
|
116 | 118 |
|
117 | 119 | class FileOpenerLabel(QLabel):
|
118 |
| - def __init__(self, parent=None): |
| 120 | + def __init__(self, parent: QWidget | None = None) -> None: |
119 | 121 | """Initialize the FileOpenerLabel.
|
120 | 122 |
|
121 | 123 | Args:
|
122 | 124 | parent (QWidget, optional): The parent widget. Defaults to None.
|
123 | 125 | """
|
| 126 | + self.filepath: str | Path | None = None |
| 127 | + |
124 | 128 | super().__init__(parent)
|
125 | 129 |
|
126 |
| - def set_file_path(self, filepath): |
| 130 | + def set_file_path(self, filepath: str | Path) -> None: |
127 | 131 | """Set the filepath to open.
|
128 | 132 |
|
129 | 133 | Args:
|
130 | 134 | filepath (str): The path to the file to open.
|
131 | 135 | """
|
132 | 136 | self.filepath = filepath
|
133 | 137 |
|
134 |
| - def mousePressEvent(self, event): # noqa: N802 |
| 138 | + @override |
| 139 | + def mousePressEvent(self, ev: QMouseEvent) -> None: |
135 | 140 | """Handle mouse press events.
|
136 | 141 |
|
137 | 142 | On a left click, open the file in the default file explorer.
|
138 | 143 | On a right click, show a context menu.
|
139 | 144 |
|
140 | 145 | Args:
|
141 |
| - event (QMouseEvent): The mouse press event. |
| 146 | + ev (QMouseEvent): The mouse press event. |
142 | 147 | """
|
143 |
| - super().mousePressEvent(event) |
144 |
| - |
145 |
| - if event.button() == Qt.MouseButton.LeftButton: |
| 148 | + if ev.button() == Qt.MouseButton.LeftButton: |
| 149 | + assert self.filepath is not None, "File path is not set" |
146 | 150 | opener = FileOpenerHelper(self.filepath)
|
147 | 151 | opener.open_explorer()
|
148 |
| - elif event.button() == Qt.MouseButton.RightButton: |
| 152 | + elif ev.button() == Qt.MouseButton.RightButton: |
149 | 153 | # Show context menu
|
150 | 154 | pass
|
| 155 | + else: |
| 156 | + super().mousePressEvent(ev) |
0 commit comments