Skip to content

Commit

Permalink
改BUG
Browse files Browse the repository at this point in the history
1、OCR取词无法使用;
2、界面上的一些错误;
3、解决无法输入中文的问题;
4、优化取词界面。
5、解决系统通知不显示的问题。
  • Loading branch information
Allan committed Oct 29, 2021
1 parent 9105b71 commit f48d7c9
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 77 deletions.
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ tar -czf my_dict_linux_x64_${version}.tar.gz 我的词典 LICENSE

cd ..
cp LICENSE deb/opt/my_dict
sed -i "s/^Version:.*/Version:${version}/g" deb/DEBIAN/control
dpkg -b deb dist/mydict_linux_x64_${version}.deb
rm deb/opt/my_dict/我的词典
rm deb/opt/my_dict/LICENSE
sed -i "s/^Version:.*/Version:0.0.0/g" deb/DEBIAN/control
2 changes: 1 addition & 1 deletion deb/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package:mydict
Version:0.2.2
Version:0.0.0
Section:free
Priority:optional
Architecture:amd64
Expand Down
Binary file modified readme.assets/clipboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PyQt5==5.14.0
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
Expand Down
24 changes: 24 additions & 0 deletions src/UI/BaseWidget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPainter, QColor
from PyQt5.QtWidgets import QWidget


class BaseWidget(QWidget):
"""圆角边框类"""
def __init__(self, parent=None):
super().__init__(parent)
# 设置 窗口无边框和背景透明 *必须
self.setAttribute(Qt.WA_TranslucentBackground)
self.color_background = QColor(128, 128, 128, 0.7 * 255)

def paintEvent(self, event):
pat = QPainter(self)
pat.setRenderHint(pat.Antialiasing)
pat.setPen(self.color_background)
pat.setBrush(self.color_background)
rect = self.rect()
rect.setLeft(5)
rect.setTop(5)
rect.setWidth(rect.width() - 5)
rect.setHeight(rect.height() - 5)
pat.drawRoundedRect(rect, 4, 4)
31 changes: 5 additions & 26 deletions src/UI/ocr_mask.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
from PyQt5.QtCore import Qt, QRect, QPoint, QRectF, QSize
from PyQt5.QtGui import QScreen, QPainter, QPixmap, QColor, QImage, QIcon, QBrush, QPainterPath
from PyQt5.QtWidgets import QDialog, QPushButton, QWidget
from PyQt5.QtCore import Qt, QRect, QPoint, QSize
from PyQt5.QtGui import QScreen, QPainter, QPixmap, QColor, QImage
from PyQt5.QtWidgets import QDialog, QPushButton

from src.UI.BaseWidget import BaseWidget
from src.UI.util import create_line
from src.util import load_icon


class UiTools(QWidget):
"""圆角边框类"""
def __init__(self, parent=None):
super(UiTools, self).__init__(parent)
self.border_width = 8
# 设置 窗口无边框和背景透明 *必须
self.setAttribute(Qt.WA_TranslucentBackground)

def paintEvent(self, event):
pat = QPainter(self)
pat.setRenderHint(pat.Antialiasing)
color = QColor(128, 128, 128, 150)
pat.setPen(color)
pat.setBrush(color)
rect = self.rect()
rect.setLeft(5)
rect.setTop(5)
rect.setWidth(rect.width() - 5)
rect.setHeight(rect.height() - 5)
pat.drawRoundedRect(rect, 4, 4)


class UiOcrMask(QDialog):
def __init__(self, win_id, screen: QScreen):
super().__init__()
Expand All @@ -52,7 +31,7 @@ def __init__(self, win_id, screen: QScreen):
height=screen_rect.height(),
)
self.img: QImage = shot.toImage()
self.tools = UiTools(self)
self.tools = BaseWidget(self)
self.tools.setHidden(True)
self.tools.setFixedHeight(64)

Expand Down
18 changes: 14 additions & 4 deletions src/UI/result.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from PyQt5.QtCore import QUrl
from PyQt5.QtCore import QUrl, Qt
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
from PyQt5.QtWidgets import QWidget, QLabel, QTextEdit, QPushButton, QHBoxLayout, QVBoxLayout, QMessageBox

Expand All @@ -18,7 +18,7 @@ class ResultWindow(QWidget):
'}\n' \
'</style>'

def __init__(self, parent):
def __init__(self, parent, translucent=False):
super().__init__(parent)

self.edit_res = QTextEdit()
Expand All @@ -30,14 +30,14 @@ def __init__(self, parent):
self.label_uksm.hide()

self.media_player_us = QMediaPlayer()
self.btn_us = QPushButton("美音")
self.btn_us = QPushButton(" 美音 ")
self.btn_us.setParent(self)
self.btn_us.setIcon(load_icon("voice"))
self.btn_us.hide()
self.btn_us.setFlat(True)
self.btn_us.clicked.connect(lambda: self.on_play(self.media_player_us))
self.media_player_uk = QMediaPlayer()
self.btn_uk = QPushButton("英音")
self.btn_uk = QPushButton(" 英音 ")
self.btn_uk.setParent(self)
self.btn_uk.setIcon(load_icon("voice"))
self.btn_uk.hide()
Expand All @@ -55,6 +55,16 @@ def __init__(self, parent):
vbox = QVBoxLayout()
vbox.addItem(hbox)
vbox.addWidget(self.edit_res)
if translucent:
self.label_uksm.setAttribute(Qt.WA_TranslucentBackground)
self.label_ussm.setAttribute(Qt.WA_TranslucentBackground)
self.btn_uk.setAttribute(Qt.WA_TranslucentBackground)
self.edit_res.setAttribute(Qt.WA_TranslucentBackground)
for i in range(0, hbox.count()):
w = hbox.itemAt(i)
if isinstance(w, QWidget):
print(i, "Qt.WA_TranslucentBackground")
w.setAttribute(Qt.WA_TranslucentBackground)
self.setLayout(vbox)

@staticmethod
Expand Down
69 changes: 57 additions & 12 deletions src/UI/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import threading

import pystardict
from PyQt5.QtCore import QSize, pyqtSignal
from PyQt5.QtCore import QSize, pyqtSignal, Qt
from PyQt5.QtGui import QKeyEvent
from PyQt5.QtWidgets import QWidget, QCheckBox, QPushButton, QLineEdit, QFileDialog, \
QListWidget, QListWidgetItem, QMessageBox, QDialog, QTextEdit
QListWidget, QListWidgetItem, QMessageBox, QDialog, QTextEdit, QLabel

from src.UI.download_dict import DownloadDialog
from src.UI.util import create_grid, create_line, create_multi_line
Expand All @@ -16,6 +17,42 @@
from src.util import run_app


class GetHotkey(QDialog):
hotkey = []

def __init__(self, parent, hotkey):
super().__init__(parent)
self.label = QLabel(hotkey)
self.btn = QPushButton("OK")
self.btn.setFixedWidth(80)
self.btn.clicked.connect(self.accept)
layout = create_multi_line([
create_line([1, self.label, 1]),
create_line([1, self.btn, 1])
])
self.setWindowTitle("更改热键")
self.setLayout(layout)

def keyPressEvent(self, event: QKeyEvent):
m = event.modifiers()
hotkey = []
if m & Qt.ShiftModifier:
hotkey.append("shift")
if m & Qt.ControlModifier:
hotkey.append("control")
if m & Qt.AltModifier:
hotkey.append("alt")
k = event.key()
if 48 <= k <= 57 or 65 <= k <= 90 or 97 <= k <= 122:
hotkey.append(chr(k).lower())

if k == Qt.Key_Escape:
hotkey = []

self.label.setText(' - '.join(hotkey).upper() if len(hotkey) > 0 else '禁用')
self.hotkey = hotkey


class InstallOcrWindow(QDialog):
signal_log = pyqtSignal(str)
signal_finish = pyqtSignal(int)
Expand Down Expand Up @@ -73,21 +110,23 @@ def __init__(self, parent, star_dict: StartDict):
self.checkbox_use_dark_skin.setChecked(setting.use_dark_skin)
self.checkbox_use_dark_skin.clicked.connect(self.on_save)

self.checkbox_support_clipboard = QCheckBox("剪贴板取词(复制两次触发取词)")
self.checkbox_support_clipboard = QCheckBox("剪贴板取词(复制3次触发取词)")
self.checkbox_support_clipboard.setToolTip("复制3次触发取词")
self.checkbox_support_clipboard.clicked.connect(self.on_save)

self.checkbox_support_ocr = QCheckBox("OCR取词")
self.checkbox_support_ocr.clicked.connect(self.on_save)

self.edit_ocr_hotkey = QLineEdit()
self.edit_ocr_hotkey.setReadOnly(True)
self.edit_ocr_hotkey.setPlaceholderText("OCR取词热键")
self.edit_ocr_hotkey.textChanged.connect(self.on_save)
self.edit_ocr_hotkey = QPushButton(
" - ".join(setting.ocr_hotkey).upper() if len(setting.ocr_hotkey) > 0 else '禁用'
)
self.edit_ocr_hotkey.clicked.connect(self.on_change_hotkey)
self.edit_ocr_hotkey.setFlat(True)

self.edit_ocr_server = QLineEdit()
self.edit_ocr_server.setReadOnly(True)
self.edit_ocr_server.setPlaceholderText("OCR取词服务器")
self.edit_ocr_server.setPlaceholderText("取词服务器")
self.edit_ocr_server.setText(setting.ocr_server)
self.edit_ocr_server.textChanged.connect(self.on_save)

self.button_ocr_server = QPushButton("安装")
Expand Down Expand Up @@ -118,8 +157,6 @@ def __init__(self, parent, star_dict: StartDict):

self.checkbox_support_clipboard.setChecked(setting.support_clipboard)
self.checkbox_support_ocr.setChecked(setting.support_ocr)
self.edit_ocr_hotkey.setText("-".join(setting.ocr_hotkey))
self.edit_ocr_server.setText(setting.ocr_server)
self.checkbox_show_main_window_when_startup.setChecked(setting.show_main_window_when_startup)
self.checkbox_auto_startup.setChecked(self.is_auto_startup())

Expand All @@ -134,8 +171,8 @@ def __init__(self, parent, star_dict: StartDict):
[self.checkbox_use_dark_skin],
[self.checkbox_support_clipboard],
[self.checkbox_support_ocr],
[" OCR取词热键:", create_line([self.edit_ocr_hotkey])],
[" OCR取词服务器:", create_line([self.edit_ocr_server, self.button_ocr_server])],
[" 取词热键:", create_line([self.edit_ocr_hotkey])],
[" 取词服务器:", create_line([self.edit_ocr_server, self.button_ocr_server])],
[self.checkbox_show_main_window_when_startup],
[self.checkbox_auto_startup],
["词典目录:", create_line([self.edit_dict_folder, self.btn_select_dict_folder, self.btn_open_dict_folder])],
Expand Down Expand Up @@ -245,3 +282,11 @@ def on_download_dict(self):
def on_install_ocr_server(self):
dd = InstallOcrWindow(self)
dd.exec_()

def on_change_hotkey(self):
dd = GetHotkey(self, self.edit_ocr_hotkey.text())
ret = dd.exec_()
if ret == 1:
self.edit_ocr_hotkey.setText(' - '.join(dd.hotkey).upper() if len(dd.hotkey) > 0 else '禁用')
setting.ocr_hotkey = dd.hotkey
setting.save()
Loading

0 comments on commit f48d7c9

Please sign in to comment.