contextMenu disable WIP
This commit is contained in:
parent
b0aca671fa
commit
97833345a8
2 changed files with 32 additions and 12 deletions
|
|
@ -1,2 +1,4 @@
|
||||||
# Web Scraping App with Forensic Features
|
## WebScraping
|
||||||
|
|
||||||
|
Web Scraping App with Forensic Features
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# src/browser_window.py
|
# src/browser_window.py
|
||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QMainWindow, QToolBar, QMenu, QMessageBox, QFileDialog, QInputDialog
|
QMainWindow, QToolBar, QMenu, QMessageBox, QFileDialog, QInputDialog, QLineEdit
|
||||||
)
|
)
|
||||||
from PySide6.QtGui import QAction
|
from PySide6.QtGui import QAction
|
||||||
|
|
||||||
|
|
@ -42,6 +42,15 @@ class BrowserWindow(QMainWindow):
|
||||||
capture_act.triggered.connect(self.capture_screenshot)
|
capture_act.triggered.connect(self.capture_screenshot)
|
||||||
toolbar.addAction(capture_act)
|
toolbar.addAction(capture_act)
|
||||||
|
|
||||||
|
# ---- New URL input field and Go button ----
|
||||||
|
self.url_input = QLineEdit()
|
||||||
|
self.url_input.setPlaceholderText("Enter URL")
|
||||||
|
toolbar.addWidget(self.url_input)
|
||||||
|
|
||||||
|
go_act = QAction("Go", self)
|
||||||
|
go_act.triggered.connect(self.go_to_url)
|
||||||
|
toolbar.addAction(go_act)
|
||||||
|
|
||||||
# ---- Signals -------------------------------------------------
|
# ---- Signals -------------------------------------------------
|
||||||
self.view.urlChanged.connect(self.on_url_changed)
|
self.view.urlChanged.connect(self.on_url_changed)
|
||||||
self.view.loadFinished.connect(self.on_load_finished)
|
self.view.loadFinished.connect(self.on_load_finished)
|
||||||
|
|
@ -57,6 +66,12 @@ class BrowserWindow(QMainWindow):
|
||||||
self.pending_url = ""
|
self.pending_url = ""
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
def go_to_url(self):
|
||||||
|
"""Navigate the view to the URL typed in the toolbar."""
|
||||||
|
url_text = self.url_input.text().strip()
|
||||||
|
if url_text:
|
||||||
|
self.view.load(QUrl(url_text))
|
||||||
|
|
||||||
def on_url_changed(self, url: QUrl):
|
def on_url_changed(self, url: QUrl):
|
||||||
"""Remember the URL; HTML will be saved once the page finishes loading."""
|
"""Remember the URL; HTML will be saved once the page finishes loading."""
|
||||||
self.pending_url = url.toString()
|
self.pending_url = url.toString()
|
||||||
|
|
@ -89,17 +104,19 @@ class BrowserWindow(QMainWindow):
|
||||||
self.prompt_tag(screenshot_id)
|
self.prompt_tag(screenshot_id)
|
||||||
|
|
||||||
# grab() returns a QPixmap wrapped in a QFuture – use then() callback
|
# grab() returns a QPixmap wrapped in a QFuture – use then() callback
|
||||||
self.view.grab().then(handle_pixmap)
|
pix = self.view.grab()
|
||||||
|
handle_pixmap(pix)
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def show_context_menu(self, pos):
|
def show_context_menu(self, pos):
|
||||||
ctx: QWebEngineContextMenuRequest = self.view.page().contextMenuData()
|
pass
|
||||||
if ctx.mediaType() == QWebEngineContextMenuRequest.MediaTypeImage:
|
# ctx: QWebEngineContextMenuRequest = self.view.page().contextMenuData()
|
||||||
menu = QMenu(self)
|
# if ctx.mediaType() == QWebEngineContextMenuRequest.MediaTypeImage:
|
||||||
tag_act = QAction("Add tag to image", self)
|
# menu = QMenu(self)
|
||||||
tag_act.triggered.connect(lambda: self.tag_image(ctx))
|
# tag_act = QAction("Add tag to image", self)
|
||||||
menu.addAction(tag_act)
|
# tag_act.triggered.connect(lambda: self.tag_image(ctx))
|
||||||
menu.exec_(self.view.mapToGlobal(pos))
|
# menu.addAction(tag_act)
|
||||||
|
# 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
|
||||||
|
|
@ -120,8 +137,9 @@ class BrowserWindow(QMainWindow):
|
||||||
def _store_image_tag(self, request, url):
|
def _store_image_tag(self, request, url):
|
||||||
# request.reply() is a QIODevice; read all bytes
|
# request.reply() is a QIODevice; read all bytes
|
||||||
data = request.reply().readAll().data()
|
data = request.reply().readAll().data()
|
||||||
screenshot_id = save_screenshot(self.current_page_id, data)
|
if self.current_page_id:
|
||||||
self.prompt_tag(screenshot_id)
|
screenshot_id = save_screenshot(self.current_page_id, data)
|
||||||
|
self.prompt_tag(screenshot_id)
|
||||||
|
|
||||||
def prompt_tag(self, screenshot_id: int):
|
def prompt_tag(self, screenshot_id: int):
|
||||||
tag, ok = QInputDialog.getText(self, "Tag image", "Enter tag:")
|
tag, ok = QInputDialog.getText(self, "Tag image", "Enter tag:")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue