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
|
||||
from PySide6.QtWidgets import (
|
||||
QMainWindow, QToolBar, QMenu, QMessageBox, QFileDialog, QInputDialog
|
||||
QMainWindow, QToolBar, QMenu, QMessageBox, QFileDialog, QInputDialog, QLineEdit
|
||||
)
|
||||
from PySide6.QtGui import QAction
|
||||
|
||||
|
|
@ -42,6 +42,15 @@ class BrowserWindow(QMainWindow):
|
|||
capture_act.triggered.connect(self.capture_screenshot)
|
||||
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 -------------------------------------------------
|
||||
self.view.urlChanged.connect(self.on_url_changed)
|
||||
self.view.loadFinished.connect(self.on_load_finished)
|
||||
|
|
@ -57,6 +66,12 @@ class BrowserWindow(QMainWindow):
|
|||
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):
|
||||
"""Remember the URL; HTML will be saved once the page finishes loading."""
|
||||
self.pending_url = url.toString()
|
||||
|
|
@ -89,17 +104,19 @@ class BrowserWindow(QMainWindow):
|
|||
self.prompt_tag(screenshot_id)
|
||||
|
||||
# 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):
|
||||
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))
|
||||
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))
|
||||
|
||||
def tag_image(self, ctx: QWebEngineContextMenuRequest):
|
||||
# Download the image data, then store it as a screenshot for tagging
|
||||
|
|
@ -120,6 +137,7 @@ class BrowserWindow(QMainWindow):
|
|||
def _store_image_tag(self, request, url):
|
||||
# request.reply() is a QIODevice; read all bytes
|
||||
data = request.reply().readAll().data()
|
||||
if self.current_page_id:
|
||||
screenshot_id = save_screenshot(self.current_page_id, data)
|
||||
self.prompt_tag(screenshot_id)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue