diff --git a/src/browser_window.py b/src/browser_window.py index 82ecad8..95eb81f 100644 --- a/src/browser_window.py +++ b/src/browser_window.py @@ -111,14 +111,13 @@ class BrowserWindow(QMainWindow): # ------------------------------------------------------------------ def show_context_menu(self, pos): - pass - # ctx: QWebEngineContextMenuRequest = self.view.page().contextMenuData() - # if ctx.mediaType() == QWebEngineContextMenuRequest.MediaTypeImage: - # menu = QMenu(self) - # tag_act = QAction("Add tag to image", self) - # tag_act.triggered.connect(lambda: self.tag_image(ctx)) - # menu.addAction(tag_act) - # menu.exec_(self.view.mapToGlobal(pos)) + ctx: QWebEngineContextMenuRequest = self.view.page().lastContextMenuRequest() + if ctx.mediaType() == QWebEngineContextMenuRequest.MediaType.MediaTypeImage: + menu = QMenu(self) + tag_act = QAction("Add tag to image", self) + tag_act.triggered.connect(lambda: self.tag_image(ctx)) + menu.addAction(tag_act) + menu.exec_(self.view.mapToGlobal(pos)) def tag_image(self, ctx: QWebEngineContextMenuRequest): # Download the image data, then store it as a screenshot for tagging @@ -126,12 +125,12 @@ class BrowserWindow(QMainWindow): # Use the download API to fetch the image bytes profile = self.view.page().profile() profile.downloadRequested.connect( - lambda req: self._handle_image_download(req, img_url) + lambda req: self.handle_image_download(req, img_url) ) # Trigger a temporary download request via JS (creates the request) self.view.page().runJavaScript(f'new Image().src="{img_url}";') - def _handle_image_download(self, request, expected_url): + def handle_image_download(self, request, expected_url): # Accept the request; when finished we can read its data request.accept() request.finished.connect(lambda: self._store_image_tag(request, expected_url))