This commit is contained in:
恍兮惚兮 2024-06-21 19:17:21 +08:00
parent 5fa8f1a8a6
commit f6014cf9a8
6 changed files with 40 additions and 35 deletions

View File

@ -24,15 +24,19 @@ if __name__ == "__main__":
from qtsymbols import * from qtsymbols import *
if isqt5: if isqt5:
QApplication.addLibraryPath( # 中文字符下不能自动加载
"./LunaTranslator/runtime/PyQt5/Qt5/plugins" QApplication.addLibraryPath("./LunaTranslator/runtime/PyQt5/Qt5/plugins")
) # 中文字符下不能自动加载
QApplication.setAttribute(Qt.ApplicationAttribute.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.ApplicationAttribute.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseHighDpiPixmaps) QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseHighDpiPixmaps)
if gobject.testuseqwebengine(): if gobject.testuseqwebengine():
# maybe use qwebengine
QApplication.setAttribute(Qt.ApplicationAttribute.AA_ShareOpenGLContexts)
if not isqt5:
# devtool
QApplication.setAttribute( QApplication.setAttribute(
Qt.ApplicationAttribute.AA_ShareOpenGLContexts Qt.ApplicationAttribute.AA_DontCreateNativeWidgetSiblings
) # maybe use qwebengine )
QApplication.setHighDpiScaleFactorRoundingPolicy( QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough Qt.HighDpiScaleFactorRoundingPolicy.PassThrough

View File

@ -266,8 +266,8 @@ class MySwitch(QWidget):
x + self.sizeHint().height() // 2 + offset, x + self.sizeHint().height() // 2 + offset,
y + self.sizeHint().height() // 2, y + self.sizeHint().height() // 2,
), ),
self.sizeHint().height() * 0.35, int(self.sizeHint().height() * 0.35),
self.sizeHint().height() * 0.35, int(self.sizeHint().height() * 0.35),
) )
def mouseReleaseEvent(self, event) -> None: def mouseReleaseEvent(self, event) -> None:
@ -475,12 +475,9 @@ class resizableframeless(saveposwindow):
super().resizeEvent(e) super().resizeEvent(e)
def mousePressEvent(self, event: QMouseEvent): def mousePressEvent(self, event: QMouseEvent):
if isqt5:
gpos = event.globalPos()
else:
gpos = event.globalPosition().toPoint()
if event.button() != Qt.MouseButton.LeftButton: if event.button() != Qt.MouseButton.LeftButton:
return return
gpos = QCursor.pos()
self.startxp = gpos - self.pos() self.startxp = gpos - self.pos()
self.starty = gpos.y() self.starty = gpos.y()
self.startx = gpos.x() self.startx = gpos.x()
@ -513,11 +510,7 @@ class resizableframeless(saveposwindow):
def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):
pos = event.pos() pos = event.pos()
if isqt5: gpos = QCursor.pos()
gpos = event.globalPos()
else:
gpos = event.globalPosition().toPoint()
if isinrect(pos, self._corner_youxia): if isinrect(pos, self._corner_youxia):
self.setCursor(Qt.CursorShape.SizeFDiagCursor) self.setCursor(Qt.CursorShape.SizeFDiagCursor)
elif isinrect(pos, self._corner_zuoshang): elif isinrect(pos, self._corner_zuoshang):
@ -1059,8 +1052,10 @@ class QWebWrap(abstractwebview):
def __init__(self, p=None) -> None: def __init__(self, p=None) -> None:
super().__init__(p) super().__init__(p)
if isqt5:
from PyQt5.QtWebEngineWidgets import QWebEngineView from PyQt5.QtWebEngineWidgets import QWebEngineView
else:
from PyQt6.QtWebEngineWidgets import QWebEngineView
self.internal = QWebEngineView(self) self.internal = QWebEngineView(self)
# self.internal.page().urlChanged.connect( # self.internal.page().urlChanged.connect(
# lambda qurl: self.on_load.emit(qurl.url()) # lambda qurl: self.on_load.emit(qurl.url())

View File

@ -4,6 +4,9 @@ try:
from PyQt5.QtGui import QIconEngine,QIntValidator,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent,QWheelEvent,QPaintEvent from PyQt5.QtGui import QIconEngine,QIntValidator,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent,QWheelEvent,QPaintEvent
from PyQt5.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex,QTimer,QRectF,QVariantAnimation,QUrl from PyQt5.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex,QTimer,QRectF,QVariantAnimation,QUrl
isqt5 = True isqt5 = True
class LineHeightTypes:
LineDistanceHeight=QTextBlockFormat.LineHeightTypes.LineDistanceHeight
FixedHeight=QTextBlockFormat.LineHeightTypes.FixedHeight
except: except:
#from traceback import print_exc #from traceback import print_exc
#print_exc() #print_exc()
@ -12,3 +15,7 @@ except:
from PyQt6.QtGui import QIconEngine,QIntValidator,QAction,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent,QWheelEvent,QPaintEvent from PyQt6.QtGui import QIconEngine,QIntValidator,QAction,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent,QWheelEvent,QPaintEvent
from PyQt6.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex,QTimer,QRectF,QVariantAnimation,QUrl from PyQt6.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex,QTimer,QRectF,QVariantAnimation,QUrl
isqt5 = False isqt5 = False
class LineHeightTypes:
LineDistanceHeight=QTextBlockFormat.LineHeightTypes.LineDistanceHeight.value
FixedHeight=QTextBlockFormat.LineHeightTypes.FixedHeight.value

View File

@ -1,4 +1,3 @@
from PyQt5.QtWidgets import QWidget
from qtsymbols import * from qtsymbols import *
from myutils.config import globalconfig from myutils.config import globalconfig
from rendertext.somefunctions import dataget from rendertext.somefunctions import dataget
@ -263,11 +262,7 @@ class TextBrowser(QWidget, dataget):
for i in range(self.blockcount, self.textbrowser.document().blockCount()): for i in range(self.blockcount, self.textbrowser.document().blockCount()):
b = self.textbrowser.document().findBlockByNumber(i) b = self.textbrowser.document().findBlockByNumber(i)
tf = b.blockFormat() tf = b.blockFormat()
if isqt5: tf.setLineHeight(fh, LineHeightTypes.LineDistanceHeight)
lht = QTextBlockFormat.LineHeightTypes.LineDistanceHeight
else:
lht = 4
tf.setLineHeight(fh, lht)
self.textcursor.setPosition(b.position()) self.textcursor.setPosition(b.position())
self.textcursor.setBlockFormat(tf) self.textcursor.setBlockFormat(tf)
self.textbrowser.setTextCursor(self.textcursor) self.textbrowser.setTextCursor(self.textcursor)
@ -552,11 +547,7 @@ class TextBrowser(QWidget, dataget):
b = self.textbrowser.document().findBlockByNumber(i) b = self.textbrowser.document().findBlockByNumber(i)
tf = b.blockFormat() tf = b.blockFormat()
if isqt5: tf.setLineHeight(fasall + fha, LineHeightTypes.FixedHeight)
lht = QTextBlockFormat.LineHeightTypes.FixedHeight
else:
lht = 2
tf.setLineHeight(fasall + fha, lht)
self.textcursor.setPosition(b.position()) self.textcursor.setPosition(b.position())
self.textcursor.setBlockFormat(tf) self.textcursor.setBlockFormat(tf)
self.textbrowser.setTextCursor(self.textcursor) self.textbrowser.setTextCursor(self.textcursor)

View File

@ -1,4 +1,3 @@
from PyQt5.QtWidgets import QWidget
from qtsymbols import * from qtsymbols import *
from rendertext.somefunctions import dataget from rendertext.somefunctions import dataget
import gobject, uuid, json, os, functools import gobject, uuid, json, os, functools
@ -49,10 +48,17 @@ class TextBrowser(QWidget, dataget):
self._qweb_query_word() self._qweb_query_word()
def _qwmenu(self, pos): def _qwmenu(self, pos):
if isqt5:
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
loadinspector = QAction("Inspect")
web_menu = self.webivewwidget.internal.page().createStandardContextMenu() web_menu = self.webivewwidget.internal.page().createStandardContextMenu()
else:
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtWebEngineCore import QWebEnginePage
web_menu = self.webivewwidget.internal.createStandardContextMenu()
loadinspector = QAction("Inspect")
if ( if (
self.webivewwidget.internal.page().action( self.webivewwidget.internal.page().action(
QWebEnginePage.WebAction.InspectElement QWebEnginePage.WebAction.InspectElement
@ -60,7 +66,7 @@ class TextBrowser(QWidget, dataget):
not in web_menu.actions() not in web_menu.actions()
): ):
web_menu.addAction(loadinspector) web_menu.addAction(loadinspector)
action = web_menu.exec_(self.webivewwidget.mapToGlobal(pos)) action = web_menu.exec(self.webivewwidget.mapToGlobal(pos))
if action == loadinspector: if action == loadinspector:

View File

@ -0,0 +1,2 @@
python.exe -B LunaTranslator\LunaTranslator_main.py test
pause