forked from JonasCaetanoSz/maturador-de-chips
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdashboard.py
94 lines (86 loc) · 4.42 KB
/
dashboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile , QWebEnginePage
from PyQt5.QtWebChannel import QWebChannel
from PyQt5.QtCore import QUrl, QSettings
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtGui import QIcon
from PyQt5 import QtWidgets
from controller import Controller
import shutil
import os
class Webview(QWebEngineView):
def __init__(self, parent: QtWidgets.QWidget | None = ...) -> None:
self.controller_channel:QWebChannel = None
super().__init__(parent)
def reload(self) -> None:
self.page().setWebChannel(self.controller_channel)
return super().reload()
# sobrescreve as funções de log javascript do QWebEnginePage para que as saídas geradas ignoradas
# é assim que o programa consegue executar sem precisar de stdout do terminal
class LogCapturingPage(QWebEnginePage):
def consoleMessage(self, level, message, lineNumber, sourceID):
pass
def javaScriptConsoleMessage(self, level, message, lineNumber, sourceID):
pass
class MainWindow(QMainWindow):
def __init__(self, accounts_page, signals, app, controller:Controller):
super().__init__()
self.app = app
self.settings = QSettings("maturador", "cache")
try:
self.move(self.settings.value('win_dashboard_position'))
accounts_page.move(self.settings.value('win_accounts_position'))
except:
pass
self.accounts_page = accounts_page
self.signals = signals
self.setWindowTitle("Maturador de chips - Dashboard")
self.main_engine:QWebEnginePage
self.setFixedSize(767, 620)
self.webview = Webview(self)
cache_dir = os.getcwd() + "/sessions/cache"
profile = QWebEngineProfile("gui_cache", self.webview)
profile.setCachePath(cache_dir)
profile.setPersistentStoragePath(cache_dir)
profile.setDownloadPath(cache_dir)
profile.setPersistentCookiesPolicy(QWebEngineProfile.AllowPersistentCookies)
profile.setHttpAcceptLanguage("pt-br")
engine = LogCapturingPage(profile, self.webview)
channel = QWebChannel(engine)
channel.registerObject("controller",controller)
self.webview.controller_channel = channel
engine.setWebChannel(channel)
self.webview.setPage(engine)
self.webview.load(QUrl.fromLocalFile("/pages/dashboard.html"))
self.webview.page().action(QWebEnginePage.Back).setVisible(False)
self.webview.page().action(QWebEnginePage.Reload).setVisible(False)
self.webview.page().action(QWebEnginePage.WebAction.SavePage).setVisible(False)
self.webview.page().action(QWebEnginePage.WebAction.CopyImageToClipboard).setVisible(False)
self.webview.page().action(QWebEnginePage.WebAction.CopyImageUrlToClipboard).setVisible(False)
self.webview.page().action(QWebEnginePage.WebAction.Forward).setVisible(False)
self.webview.page().action(QWebEnginePage.WebAction.ViewSource).setVisible(False)
self.webview.page().action(QWebEnginePage.WebAction.CopyLinkToClipboard).setVisible(False)
self.webview.page().action(QWebEnginePage.WebAction.OpenLinkInNewTab).setVisible(False)
self.webview.page().action(QWebEnginePage.WebAction.OpenLinkInThisWindow).setVisible(False)
self.webview.page().action(QWebEnginePage.WebAction.DownloadLinkToDisk).setVisible(False)
self.webview.page().action(QWebEnginePage.WebAction.OpenLinkInNewBackgroundTab).setVisible(False)
self.webview.page().action(QWebEnginePage.WebAction.OpenLinkInNewWindow).setVisible(False)
self.setWindowIcon(QIcon("pages/assets/medias/icon.ico"))
self.setCentralWidget(self.webview)
self.main_engine = engine
def closeEvent(self, event):
self.signals.stop_maturation.emit()
{engine.deleteLater() for engine in self.accounts_page.webs_engine}
self.accounts_page.close()
self.main_engine.deleteLater()
self.app.destroyed.connect(
lambda _: [shutil.rmtree(session_path) for session_path in self.accounts_page.sessions_waiting_to_be_disconnected]
)
self.settings.setValue(
'win_dashboard_position',
self.pos()
)
self.settings.setValue(
'win_accounts_position',
self.accounts_page.pos()
)
event.accept()