From 97833345a8ce4342fb30e61ba9855e6a39e0853a Mon Sep 17 00:00:00 2001 From: Dr Marc Date: Thu, 25 Sep 2025 15:38:10 +0200 Subject: [PATCH] contextMenu disable WIP --- README.md | 4 +++- src/browser_window.py | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index de509e2..83ab057 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ -# Web Scraping App with Forensic Features +## WebScraping + +Web Scraping App with Forensic Features diff --git a/src/browser_window.py b/src/browser_window.py index a638f27..bf8e53c 100644 --- a/src/browser_window.py +++ b/src/browser_window.py @@ -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,8 +137,9 @@ class BrowserWindow(QMainWindow): def _store_image_tag(self, request, url): # request.reply() is a QIODevice; read all bytes data = request.reply().readAll().data() - screenshot_id = save_screenshot(self.current_page_id, data) - self.prompt_tag(screenshot_id) + if self.current_page_id: + screenshot_id = save_screenshot(self.current_page_id, data) + self.prompt_tag(screenshot_id) def prompt_tag(self, screenshot_id: int): tag, ok = QInputDialog.getText(self, "Tag image", "Enter tag:")