menucontext WIP
This commit is contained in:
parent
e6321920ec
commit
1167942774
1 changed files with 9 additions and 10 deletions
|
|
@ -111,14 +111,13 @@ class BrowserWindow(QMainWindow):
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def show_context_menu(self, pos):
|
def show_context_menu(self, pos):
|
||||||
pass
|
ctx: QWebEngineContextMenuRequest = self.view.page().lastContextMenuRequest()
|
||||||
# ctx: QWebEngineContextMenuRequest = self.view.page().contextMenuData()
|
if ctx.mediaType() == QWebEngineContextMenuRequest.MediaType.MediaTypeImage:
|
||||||
# if ctx.mediaType() == QWebEngineContextMenuRequest.MediaTypeImage:
|
menu = QMenu(self)
|
||||||
# menu = QMenu(self)
|
tag_act = QAction("Add tag to image", self)
|
||||||
# tag_act = QAction("Add tag to image", self)
|
tag_act.triggered.connect(lambda: self.tag_image(ctx))
|
||||||
# tag_act.triggered.connect(lambda: self.tag_image(ctx))
|
menu.addAction(tag_act)
|
||||||
# menu.addAction(tag_act)
|
menu.exec_(self.view.mapToGlobal(pos))
|
||||||
# menu.exec_(self.view.mapToGlobal(pos))
|
|
||||||
|
|
||||||
def tag_image(self, ctx: QWebEngineContextMenuRequest):
|
def tag_image(self, ctx: QWebEngineContextMenuRequest):
|
||||||
# Download the image data, then store it as a screenshot for tagging
|
# 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
|
# Use the download API to fetch the image bytes
|
||||||
profile = self.view.page().profile()
|
profile = self.view.page().profile()
|
||||||
profile.downloadRequested.connect(
|
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)
|
# Trigger a temporary download request via JS (creates the request)
|
||||||
self.view.page().runJavaScript(f'new Image().src="{img_url}";')
|
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
|
# Accept the request; when finished we can read its data
|
||||||
request.accept()
|
request.accept()
|
||||||
request.finished.connect(lambda: self._store_image_tag(request, expected_url))
|
request.finished.connect(lambda: self._store_image_tag(request, expected_url))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue