Skip to content

Commit fb9904b

Browse files
author
ny
committed
web engine
1 parent a9d2871 commit fb9904b

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

FFxivPythonTrigger/QT.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from PyQt5.QtCore import QTimer
77
from PyQt5.QtWidgets import QApplication, QWidget
88
from PyQt5.Qt import Qt
9+
import PyQt5.QtWebEngineWidgets
910

1011
from FFxivPythonTrigger.Utils import Counter
1112

@@ -17,15 +18,25 @@
1718

1819

1920
class FloatWidget(QWidget):
21+
allow_frameless = False
22+
2023
def __init__(self):
2124
super().__init__()
22-
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.Tool)
25+
self.setWindowFlags(Qt.WindowStaysOnTopHint)
26+
# self.setAttribute(Qt.WA_TranslucentBackground, True)
2327

2428
def is_frameless(self):
2529
return self.windowFlags() & Qt.FramelessWindowHint
2630

31+
def mousePressEvent(self, QMouseEvent):
32+
if QMouseEvent.button() == Qt.RightButton and self.allow_frameless:
33+
self.switch_frameless()
34+
2735
def switch_frameless(self):
36+
self.resize(self.width(), self.height())
37+
self.move(self.pos())
2838
self.setWindowFlags(self.windowFlags() ^ Qt.FramelessWindowHint)
39+
self.show()
2940

3041
def full_close(self):
3142
self.hide()

plugins/CombatMonitor/__init__.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import sqlite3
2+
from json import dumps
23

3-
from PyQt5.QtCore import QTimer
4-
from PyQt5.QtGui import QFont
5-
from PyQt5.QtWidgets import QGridLayout, QLabel
4+
from PyQt5.QtCore import QTimer, QUrl
5+
from PyQt5.QtWidgets import QVBoxLayout, QWidget
6+
from PyQt5.QtWebEngineWidgets import QWebEngineView
67

78
from FFxivPythonTrigger import *
89
from FFxivPythonTrigger.QT import FloatWidget, ui_loop_exec
@@ -42,6 +43,8 @@
4243

4344
owners = dict()
4445

46+
web_path = str(Path(__file__).parent / 'dist' / 'index.html')
47+
4548

4649
class CombatMonitor(PluginBase):
4750
name = "Combat Monitor"
@@ -55,27 +58,32 @@ def __init__(self):
5558
# self.conn = get_con(self.storage.path / 'data.db')
5659

5760
class DpsWindow(FloatWidget):
61+
allow_frameless=True
5862
def __init__(self):
5963
super().__init__()
6064
self.setWindowTitle("Dps")
61-
self.label = QLabel('No Data')
62-
self.label.setFont(QFont('Times', 20))
63-
self.layout = QGridLayout()
64-
self.layout.addWidget(self.label)
65-
self.setLayout(self.layout)
65+
self.browser = QWebEngineView()
66+
self.browser.load(QUrl.fromLocalFile(web_path))
67+
_layout = QVBoxLayout(self)
68+
_layout.addWidget(self.browser)
69+
self.setLayout(_layout)
70+
71+
self.last_update = 0
72+
6673
self.timer = QTimer()
67-
self.timer.setInterval(UPDATE_PERIOD * 1000)
74+
self.timer.setInterval(UPDATE_PERIOD * 2000)
6875
self.timer.timeout.connect(self.update)
6976
self.timer.start()
7077

7178
def update(_self):
7279
me = api.XivMemory.actor_table.get_me()
73-
if me is None: return
80+
if me is None or _self.last_update>self.last_record_time: return
7481
party = [actor for actor in api.XivMemory.party.main_party()]
7582
if not party: party = [me]
76-
data = [(a, self.actor_dps(a.id, 0)) for a in party]
77-
data.sort(key=lambda x: x[1], reverse=True)
78-
_self.label.setText("\n".join([f"{a.job.value()}\t{a.Name}\t{d:,.0f}" for a, d in data]))
83+
data = [{'job':a.job.value(), 'name':a.Name, 'dps':self.actor_dps(a.id, 0)} for a in party]
84+
_self.browser.page().runJavaScript(f"window.set_data({dumps(data)})")
85+
_self.last_update = time()*1000
86+
7987

8088
self.conn = get_con()
8189
self.conn_lock = Lock()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ Shapely~=1.7.1
1616
pywin32
1717
requests~=2.25.1
1818
PyQt5~=5.15.4
19+
PyQtWebEngine~=5.15.4

0 commit comments

Comments
 (0)