Skip to content

Commit

Permalink
完善对高清屏的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
xxNull-lsk committed Oct 4, 2022
1 parent 233452b commit edad087
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 24 deletions.
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
pyqt5-tools==5.15.1.3.2
PyQt5==5.15.1
PyQt5-sip==12.8.1
requests==2.26.0
QDarkStyle==3.0.2
pystardict==0.8
opencv-python==4.2.0.32
numpy==1.18.5
pyqt5-tools
PyQt5
PyQt5-sip
requests
QDarkStyle
pystardict
opencv-python
numpy
system_hotkey
xcffib
xpybutil
pyzmq~=22.3.0
pyzmq
googletrans>=4.0.0rc1
22 changes: 14 additions & 8 deletions src/UI/ocr_mask.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from PyQt5.QtCore import Qt, QRect, QPoint, QSize
from PyQt5.QtGui import QScreen, QPainter, QPixmap, QColor, QImage
from PyQt5.QtGui import QScreen, QPainter, QPixmap, QColor, QImage, QCursor
from PyQt5.QtWidgets import QDialog, QPushButton

from src.UI.BaseWidget import BaseWidget
Expand All @@ -19,9 +19,12 @@ def __init__(self, win_id, screen: QScreen):
self.setAttribute(Qt.WA_TranslucentBackground) # 窗体背景透明
# 窗口置顶,无边框,在任务栏不显示图标
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.BypassWindowManagerHint | Qt.FramelessWindowHint | Qt.Tool)
screen_rect: QRect = screen.geometry()
screen_rect: QRect = screen.availableGeometry()

screen_rect.setWidth(screen_rect.width())
screen_rect.setHeight(screen_rect.height())
self.devicePixelRatio = screen.devicePixelRatio()
print(screen_rect, screen.devicePixelRatio())
self.setGeometry(screen_rect)
shot: QPixmap = screen.grabWindow(
win_id,
Expand All @@ -33,15 +36,15 @@ def __init__(self, win_id, screen: QScreen):
self.img: QImage = shot.toImage()
self.tools = BaseWidget(self)
self.tools.setHidden(True)
self.tools.setFixedHeight(64)
self.tools.setFixedHeight(64/self.devicePixelRatio)

btn_ok = QPushButton("", self.tools)
btn_ok.setIcon(load_icon("ok"))
btn_ok.setIconSize(QSize(32, 32))
btn_ok.setIconSize(QSize(32/self.devicePixelRatio, 32/self.devicePixelRatio))
btn_ok.clicked.connect(self.accept)
btn_ok.setFlat(True)
btn_cancel = QPushButton("", self.tools)
btn_cancel.setIconSize(QSize(32, 32))
btn_cancel.setIconSize(QSize(32/self.devicePixelRatio, 32/self.devicePixelRatio))
btn_cancel.setIcon(load_icon("cancel"))
btn_cancel.setFlat(True)
btn_cancel.clicked.connect(self.reject)
Expand All @@ -65,19 +68,22 @@ def mousePressEvent(self, event):
self.is_draw = True
self.setCursor(Qt.CrossCursor)

self.pt1 = self.pt2 = event.pos()
self.pt1 = self.pt2 = QCursor.pos()
self.update()

def mouseMoveEvent(self, event):
if self.is_draw:
self.pt2 = event.pos()
self.pt2 = QCursor.pos()
pt1 = QPoint(min(self.pt1.x(), self.pt2.x()), min(self.pt1.y(), self.pt2.y()))
pt2 = QPoint(max(self.pt1.x(), self.pt2.x()), max(self.pt1.y(), self.pt2.y()))
rect = QRect(pt1, pt2)
if rect.width() > 3 and rect.height() > 3:
self.select_rect = rect
self.select_pt = pt1
self.select_image = self.img.copy(self.select_rect)
self.select_image = self.img.copy(self.select_rect.x() * self.devicePixelRatio,
self.select_rect.y() * self.devicePixelRatio,
self.select_rect.width() * self.devicePixelRatio,
self.select_rect.height() * self.devicePixelRatio)
# 计算工具条位置
# 最优先的是左下角,防止显示在屏幕外
y = pt2.y() + 2
Expand Down
7 changes: 2 additions & 5 deletions src/UI/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,10 @@ def __init__(self, parent, star_dict: StartDict):
[self.checkbox_support_ocr],
[" 取词热键:", create_line([self.edit_ocr_hotkey])],
[" 取词服务器:", create_line([self.edit_ocr_server, self.button_ocr_server, self.button_ocr_server_help])],
["离线词典目录:", create_line([self.edit_dict_folder, self.btn_select_dict_folder, self.btn_open_dict_folder])],
[create_line(["离线词典目录:", self.edit_dict_folder, self.btn_select_dict_folder, self.btn_open_dict_folder])],
[line_dicts],
[create_line([self.btn_create_desktop, self.btn_download_dict, self.btn_reset])],
[""],
["项目地址:", url_project],
["文档地址:", url_doc],
["", url_email, ""]
[create_line(["项目地址:", url_project, "文档地址:", url_doc, "", url_email])]
]

self.init_data()
Expand Down
1 change: 1 addition & 0 deletions src/UI/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from PyQt5 import QtCore
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QGridLayout, QFormLayout, QLabel, QHBoxLayout, QLayout, QVBoxLayout, QWidget


Expand Down
4 changes: 3 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os
import sys

from PyQt5.QtCore import Qt

from src.util import version

flock = None
Expand Down Expand Up @@ -34,7 +36,7 @@ def main():
from src.setting import setting
from PyQt5.QtWidgets import QApplication
# os.environ['QT_DEBUG_PLUGINS'] = '1'
# QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
app = QApplication(sys.argv)
app.setApplicationName("MyDict")
app.setQuitOnLastWindowClosed(False)
Expand Down
2 changes: 1 addition & 1 deletion src/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DefaultSetting:
"name": "有道翻译"
},
"google": {
"name": "谷歌翻译"
"name": "有道翻译"
}
}

Expand Down

0 comments on commit edad087

Please sign in to comment.