Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
CberYellowstone committed Mar 30, 2022
1 parent cd1fa15 commit d70157c
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 23 deletions.
32 changes: 16 additions & 16 deletions GUI.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
from system_hotkey import SystemHotkey
from PyQt6 import QtWidgets
from PyQt6.QtCore import pyqtSignal, QThread, QMutex, Qt
from OCR_style import Ui_OCR_Window
Expand All @@ -9,6 +8,7 @@
from MojiAPI import searchWord, fetchWord
from Segmentation import splitWords
from dict_style import Ui_dict_Window
import keyboard
# from var_dump import var_dump
import logging
#QGuiApplication::screens
Expand Down Expand Up @@ -64,8 +64,8 @@ def keymap_replace(
This function takes a string a dictionary of
replacement mappings. For example, if I supplied
the string "Hello world.", and the mappings
{"H": "J", ".": "!"}, it would return "Jello world!".
the string "Hello.", and the mappings
{"He": "Cia", ".": "!"}, it would return " Ciallo!".
Keyword arguments:
string -- The string to replace characters in.
Expand Down Expand Up @@ -112,7 +112,8 @@ def searchWord(self):
self.wordsList.clear()
source = self.inputLineEdit.text()
if(source):
tempItemList = (each[0] for each in searchWord(source))
self._wordList = searchWord(source)
tempItemList = tuple(each[0] for each in self._wordList)
self.wordsList.addItems(tempItemList)
self.wordsList.setCurrentItem(self.wordsList.item(0))

Expand Down Expand Up @@ -145,6 +146,8 @@ def fromtHtml(self,sourceList) -> str:
def showWordDetails(self,index):
self.resultText.setHtml(self.fromtHtml(fetchWord(self._wordList[index][1])))



MutexList = [QMutex(),QMutex(),QMutex(),QMutex()]

class TranslatorThread(QThread):
Expand Down Expand Up @@ -184,7 +187,7 @@ def __init__(self):
self.selectionText = str()
self.OCRText = str()
self.SplitMode = "sudachi"
self.Hotkey_OCR = ["control", "space"]
self.Hotkey_OCR = "control + space"
self.registerHotkey(self.Hotkey_OCR)
Dict_Window = dictWindow_class()
self.selectionTextChange = Dict_Window.selectionTextChange
Expand All @@ -196,10 +199,7 @@ def __init__(self):
self.autoTrans = True

def registerHotkey(self,hotkeys):
SystemHotkey().register(
hotkeys,
callback=lambda x: self.sendHotkeyPressedSig(hotkeys),
)
keyboard.add_hotkey(hotkeys,lambda: self.sendHotkeyPressedSig(hotkeys))

def print(self,text):
print(self.OCRKeyEdit._string)
Expand Down Expand Up @@ -235,8 +235,8 @@ def getScreenPos(self):
print('非法选区,请重选!')
else:
self.AreaInit = True
self.OCRButton.setEnabled(self.AreaInit)
self.OCRButtonPlus.setEnabled(self.AreaInit)
self.OCRButton.setEnabled(self.AreaInit)
self.OCRButtonPlus.setEnabled(self.AreaInit)

def doAutoTrans(self):
if(self.autoTrans):
Expand All @@ -246,7 +246,7 @@ def getOCRText(self):
if(self.AreaInit):
self.OCRText = getOCRResult(getScreenshot(self.ScreenPos))
self.OCRResultTextEdit.setPlainText(self.OCRText)
self.doAutoTrans()
self.doAutoTrans()

def updateOCRText(self):
self.OCRText = self.OCRResultTextEdit.toPlainText()
Expand All @@ -255,7 +255,7 @@ def appendOCRText(self):
if(self.AreaInit):
self.OCRText += getOCRResult(getScreenshot(self.ScreenPos))
self.OCRResultTextEdit.setPlainText(self.OCRText)
self.doAutoTrans()
self.doAutoTrans()

def updateResultTextEdit(self,aimTextEdit:int,text:str):
text = nameReplace(text,True)
Expand All @@ -282,9 +282,9 @@ def updateSplitTextEdit(self,Force=False):
if(source and (Force or self.SplitMode != 'kuromoji')):
self.splitTextEdit.setPlainText(splitWords(source, self.SplitMode))

def updateOCRHotkey(self, text):
print(text)
self.keyPressEvent
# def updateOCRHotkey(self, text):
# print(text)
# self.keyPressEvent

def showDictWindow(self):
self.selectionTextChange.emit(self.selectionText)
Expand Down
28 changes: 26 additions & 2 deletions OCR_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def setupUi(self, OCR_Window):
OCR_Window.setObjectName("OCR_Window")
OCR_Window.setEnabled(True)
OCR_Window.resize(864, 546)
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
OCR_Window.setFont(font)
OCR_Window.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.DefaultContextMenu)
OCR_Window.setAnimated(True)
self.centralwidget = QtWidgets.QWidget(OCR_Window)
Expand Down Expand Up @@ -48,31 +51,38 @@ def setupUi(self, OCR_Window):
self.ChooseAreaButton = QtWidgets.QPushButton(self.centralwidget)
self.ChooseAreaButton.setGeometry(QtCore.QRect(530, 20, 111, 31))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(11)
self.ChooseAreaButton.setFont(font)
self.ChooseAreaButton.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
self.ChooseAreaButton.setStatusTip("")
self.ChooseAreaButton.setWhatsThis("")
self.ChooseAreaButton.setAccessibleDescription("")
self.ChooseAreaButton.setObjectName("ChooseAreaButton")
self.ChosenTitleTitle = QtWidgets.QLabel(self.centralwidget)
self.ChosenTitleTitle.setGeometry(QtCore.QRect(700, 10, 81, 20))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(10)
self.ChosenTitleTitle.setFont(font)
self.ChosenTitleTitle.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.ChosenTitleTitle.setObjectName("ChosenTitleTitle")
self.PosText = QtWidgets.QLabel(self.centralwidget)
self.PosText.setGeometry(QtCore.QRect(650, 30, 181, 20))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei")
font.setPointSize(10)
font.setKerning(True)
self.PosText.setFont(font)
self.PosText.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.PosText.setObjectName("PosText")
self.OCRButton = QtWidgets.QPushButton(self.centralwidget)
self.OCRButton.setGeometry(QtCore.QRect(30, 20, 111, 31))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(14)
self.OCRButton.setFont(font)
self.OCRButton.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
self.OCRButton.setObjectName("OCRButton")
self.splitTextEdit = betterSelectionQPlainTextEdit(self.centralwidget)
self.splitTextEdit.setGeometry(QtCore.QRect(30, 130, 721, 41))
Expand All @@ -86,6 +96,7 @@ def setupUi(self, OCR_Window):
self.SplitChooseBox = QtWidgets.QComboBox(self.centralwidget)
self.SplitChooseBox.setGeometry(QtCore.QRect(760, 150, 91, 21))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(10)
self.SplitChooseBox.setFont(font)
self.SplitChooseBox.setObjectName("SplitChooseBox")
Expand All @@ -95,20 +106,23 @@ def setupUi(self, OCR_Window):
self.SplitChooseTitle = QtWidgets.QLabel(self.centralwidget)
self.SplitChooseTitle.setGeometry(QtCore.QRect(770, 130, 71, 16))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(10)
self.SplitChooseTitle.setFont(font)
self.SplitChooseTitle.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.SplitChooseTitle.setObjectName("SplitChooseTitle")
self.ShortcutKeyTitle = QtWidgets.QLabel(self.centralwidget)
self.ShortcutKeyTitle.setGeometry(QtCore.QRect(280, 10, 151, 20))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(11)
self.ShortcutKeyTitle.setFont(font)
self.ShortcutKeyTitle.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.ShortcutKeyTitle.setObjectName("ShortcutKeyTitle")
self.ShortcutKeyText = QtWidgets.QLabel(self.centralwidget)
self.ShortcutKeyText.setGeometry(QtCore.QRect(290, 30, 131, 20))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(11)
font.setUnderline(True)
self.ShortcutKeyText.setFont(font)
Expand All @@ -133,33 +147,43 @@ def setupUi(self, OCR_Window):
self.OCRButtonPlus = QtWidgets.QPushButton(self.centralwidget)
self.OCRButtonPlus.setGeometry(QtCore.QRect(150, 20, 111, 31))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(14)
self.OCRButtonPlus.setFont(font)
self.OCRButtonPlus.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
self.OCRButtonPlus.setObjectName("OCRButtonPlus")
self.showDictWindowButton = QtWidgets.QPushButton(self.centralwidget)
self.showDictWindowButton.setGeometry(QtCore.QRect(760, 60, 91, 31))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(11)
self.showDictWindowButton.setFont(font)
self.showDictWindowButton.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
self.showDictWindowButton.setObjectName("showDictWindowButton")
self.autoDictCheckBox = QtWidgets.QCheckBox(self.centralwidget)
self.autoDictCheckBox.setGeometry(QtCore.QRect(760, 90, 91, 21))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(10)
self.autoDictCheckBox.setFont(font)
self.autoDictCheckBox.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
self.autoDictCheckBox.setObjectName("autoDictCheckBox")
self.autoTransCheckBox = QtWidgets.QCheckBox(self.centralwidget)
self.autoTransCheckBox.setGeometry(QtCore.QRect(760, 220, 91, 21))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(10)
self.autoTransCheckBox.setFont(font)
self.autoTransCheckBox.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
self.autoTransCheckBox.setChecked(True)
self.autoTransCheckBox.setObjectName("autoTransCheckBox")
self.doTransButton = QtWidgets.QPushButton(self.centralwidget)
self.doTransButton.setGeometry(QtCore.QRect(760, 190, 91, 31))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(11)
self.doTransButton.setFont(font)
self.doTransButton.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
self.doTransButton.setObjectName("doTransButton")
self.OCRKeyEdit = oneKeyQKeySequenceEdit(self.centralwidget)
self.OCRKeyEdit.setGeometry(QtCore.QRect(292, 30, 131, 20))
Expand All @@ -171,6 +195,7 @@ def setupUi(self, OCR_Window):
font.setFamily("Microsoft YaHei UI")
font.setPointSize(11)
self.changeHotKeyButton.setFont(font)
self.changeHotKeyButton.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
self.changeHotKeyButton.setStatusTip("")
self.changeHotKeyButton.setWhatsThis("")
self.changeHotKeyButton.setAccessibleDescription("")
Expand Down Expand Up @@ -251,5 +276,4 @@ def retranslateUi(self, OCR_Window):
self.doTransButton.setText(_translate("OCR_Window", "翻译"))
self.changeHotKeyButton.setToolTip(_translate("OCR_Window", "<html><head/><body><p><span style=\" font-size:10pt;\">按Enter确认选取区域</span></p></body></html>"))
self.changeHotKeyButton.setText(_translate("OCR_Window", "√"))
from betterSelectionQPlainTextEdit import betterSelectionQPlainTextEdit
from oneKeyQKeySequenceEdit import oneKeyQKeySequenceEdit
from customerDefineQtClass import betterSelectionQPlainTextEdit, oneKeyQKeySequenceEdit
Loading

0 comments on commit d70157c

Please sign in to comment.