stabilised a bit the replay by using the live page instead of the archive when not found
This commit is contained in:
parent
3d120dab2d
commit
0e7ddd4c53
6 changed files with 40 additions and 26 deletions
21
setup.py
21
setup.py
|
@ -22,16 +22,25 @@ setup(
|
||||||
"build_exe": {
|
"build_exe": {
|
||||||
"include_msvcr": True,
|
"include_msvcr": True,
|
||||||
"include_files": [
|
"include_files": [
|
||||||
|
("./tools/", "./tools/"),
|
||||||
("./assets/", "./assets/"),
|
("./assets/", "./assets/"),
|
||||||
("./README.md", "./README.md"),
|
("./README.md", "./README.md"),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
executables=[Executable(
|
executables=[
|
||||||
"main.py",
|
Executable(
|
||||||
base=base,
|
"main.py",
|
||||||
target_name=__appname__,
|
base=base,
|
||||||
icon=__icon_ico__
|
target_name=__appname__,
|
||||||
)]
|
icon=__icon_ico__
|
||||||
|
),
|
||||||
|
Executable(
|
||||||
|
"tools/web_replay/main.py",
|
||||||
|
base=base,
|
||||||
|
target_name="tools/web_replay/main",
|
||||||
|
icon=__icon_ico__
|
||||||
|
),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
0
tools/__init__.py
Normal file
0
tools/__init__.py
Normal file
0
tools/web_replay/__init__.py
Normal file
0
tools/web_replay/__init__.py
Normal file
|
@ -1,10 +1,8 @@
|
||||||
import json
|
|
||||||
import sys
|
import sys
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from PyQt6.QtWidgets import QApplication, QFileDialog
|
from PyQt6.QtWidgets import QApplication
|
||||||
|
|
||||||
from tools.web_replay.ui import ReplayWindow
|
from ui import ReplayWindow
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -7,7 +7,7 @@ from PyQt6.QtGui import QKeyEvent, QMouseEvent
|
||||||
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QApplication, QLabel
|
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QApplication, QLabel
|
||||||
|
|
||||||
from source.utils import compress
|
from source.utils import compress
|
||||||
from tools.web_replay.ui import ReplayWebEngineView, ReplayNavigation
|
from . import ReplayWebEngineView, ReplayNavigation
|
||||||
|
|
||||||
|
|
||||||
class ReplayEngine(QWidget):
|
class ReplayEngine(QWidget):
|
||||||
|
@ -186,6 +186,6 @@ class ReplayEngine(QWidget):
|
||||||
|
|
||||||
# prepare the timer to play the event at the corresponding time
|
# prepare the timer to play the event at the corresponding time
|
||||||
self.timer.singleShot(
|
self.timer.singleShot(
|
||||||
round((next_time - self.replay_time) / 1000),
|
round((next_time - self.replay_time) / 200),
|
||||||
self.next
|
self.next
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from PyQt6.QtCore import QObject, QEvent, QUrl
|
from PyQt6.QtCore import QObject, QEvent, QUrl
|
||||||
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
||||||
|
@ -9,21 +10,25 @@ class ReplayWebEngineView(QWebEngineView):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.start_time = start_time
|
self.start_time = start_time
|
||||||
|
self._last_url: Optional[QUrl] = None
|
||||||
|
|
||||||
self.loadFinished.connect(self._initialize_proxy_event) # NOQA: connect exist
|
self.loadFinished.connect(self._initialize_proxy_event) # NOQA: connect exist
|
||||||
|
|
||||||
# event filter
|
# event filter
|
||||||
|
|
||||||
def setUrl(self, url: QUrl) -> None:
|
def setUrl(self, url: QUrl, archive: bool = True) -> None:
|
||||||
# get the archive.org link corresponding to that time
|
if archive:
|
||||||
archive_time: str = self.start_time.strftime("%Y%m%d%H%M%S")
|
# get the archive.org link corresponding to that time
|
||||||
archive_url = f"https://web.archive.org/web/{archive_time}/{url.toString()}"
|
archive_time: str = self.start_time.strftime("%Y%m%d%H%M%S")
|
||||||
|
url = QUrl(f"https://web.archive.org/web/{archive_time}/{url.toString()}")
|
||||||
|
|
||||||
|
self._last_url = url
|
||||||
|
|
||||||
# call the super function with the archive url instead
|
# call the super function with the archive url instead
|
||||||
super().setUrl(QUrl(archive_url))
|
super().setUrl(url)
|
||||||
|
|
||||||
# clean the archive header popup that will appear
|
# clean the archive header popup that will appear
|
||||||
self.loadFinished.connect(self._clean_archive_header) # NOQA: connect exist
|
self.loadFinished.connect(self._on_load_finished) # NOQA: connect exist
|
||||||
|
|
||||||
def eventFilter(self, obj: QObject, event: QEvent) -> bool:
|
def eventFilter(self, obj: QObject, event: QEvent) -> bool:
|
||||||
match event.type():
|
match event.type():
|
||||||
|
@ -44,16 +49,18 @@ class ReplayWebEngineView(QWebEngineView):
|
||||||
|
|
||||||
# events
|
# events
|
||||||
|
|
||||||
def _initialize_proxy_event(self, ok: bool):
|
def _initialize_proxy_event(self):
|
||||||
# prevent the event from being enabled another time
|
|
||||||
self.loadFinished.disconnect(self._initialize_proxy_event) # NOQA: disconnect exist
|
|
||||||
|
|
||||||
# make self.eventFilter intercept all focusProxy events
|
# make self.eventFilter intercept all focusProxy events
|
||||||
self.focusProxy().installEventFilter(self)
|
self.focusProxy().installEventFilter(self)
|
||||||
|
|
||||||
def _clean_archive_header(self, ok: bool):
|
def _on_load_finished(self, ok: bool):
|
||||||
# prevent the event from being enabled another time
|
# prevent the event from being enabled another time
|
||||||
self.loadFinished.disconnect(self._clean_archive_header) # NOQA: disconnect exist
|
self.loadFinished.disconnect(self._on_load_finished) # NOQA: disconnect exist
|
||||||
|
|
||||||
# hide archive.org header to avoid mouse movement being shifted
|
if ok:
|
||||||
self.page().runJavaScript("document.getElementById('wm-ipp-base').style.display = 'none';")
|
# hide archive.org header to avoid mouse movement being shifted
|
||||||
|
self.page().runJavaScript("document.getElementById('wm-ipp-base').style.display = 'none';")
|
||||||
|
self._initialize_proxy_event()
|
||||||
|
|
||||||
|
else:
|
||||||
|
self.setUrl(self._last_url, archive=False)
|
||||||
|
|
Loading…
Reference in a new issue