Skip to content

Commit

Permalink
improve: 窗体大小随翻译源数量改变; 翻译源配置要求至少一个; 翻译源列表重复;
Browse files Browse the repository at this point in the history
  • Loading branch information
CberYellowstone committed Apr 24, 2022
1 parent b511c70 commit c6805dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
23 changes: 18 additions & 5 deletions GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def setupUi(self, Config):
Config.setWindowFlags(Qt.WindowType.WindowStaysOnTopHint)

def replaceWithCurrentConfig(self):
self.ListWidget_SelectableSource.clear()
self.ListWidget_SelectedSource.clear()
self.Label_ShortcutKeyText.setText(self.parent.Hotkey_OCR)
configDict = readConfig()
for each in self.LineEditMapping:
Expand Down Expand Up @@ -141,6 +143,9 @@ def cancelHotKey(self):
print('已取消更改热键')

def saveConfig(self):
if(not self.getCurrentSelectedTranslator()):
QtWidgets.QMessageBox.critical(self,"配置有误","至少选择一个翻译源!")
return
data = {each: self.LineEditMapping[each].text() for each in self.LineEditMapping}
data['SELECTED_TRANSLATORS'] = self.getCurrentSelectedTranslator()
data['Hotkey_OCR'] = self.Hotkey_OCR
Expand Down Expand Up @@ -251,6 +256,8 @@ def __init__(self):
self.selectionText = str()
self.OCRText = str()
self.setupUi(self)
self.defaultWidth, self.defaultHeight = self.width(), self.height()
self.defaultX, self.defaultY = self.geometry().x(), self.geometry().y()
self.OCRResultTextEdit.setPlainText('')
self.SplitMode = "sudachi"
self.Hotkey_OCR = self.ConfigDict['Hotkey_OCR']
Expand Down Expand Up @@ -321,7 +328,7 @@ def getScreenPos(self):
self.AreaInit = False
print('非法选区,请重选!')
QtWidgets.QMessageBox.critical(self,"非法选区","选区不合法,请重选!")
self.OCRResultTextEdit.setPlaceholderText('')
if self.AreaInit: self.OCRResultTextEdit.setPlaceholderText('')
self.OCRButton.setEnabled(self.AreaInit)
self.OCRButtonPlus.setEnabled(self.AreaInit)

Expand Down Expand Up @@ -361,11 +368,17 @@ def updateResults(self):
def updateTranslatorList(self, _list:list):
self.TranslatorList = _list
print(f'当前翻译源为:{self.TranslatorList}')
n = _list.__len__()
if n < 4:
(each.setEnabled(False) for each in self.resultTextEditList[n-4:])
[self.resultTextEditList[n].setPlaceholderText(eachTranslator) for n, eachTranslator in enumerate(self.TranslatorList)]
_len = _list.__len__()
if _len < 4:
[each.setVisible(False) for each in self.resultTextEditList[_len-4:]]
n = 80*(4-_list.__len__())
self.setFixedSize(self.defaultWidth, self.defaultHeight-n)
self.move(self.defaultX, self.defaultY+n)
else:
(each.setEnabled(True) for each in self.resultTextEditList)
[each.setVisible(True) for each in self.resultTextEditList]
self.setFixedSize(self.defaultWidth, self.defaultHeight)
self.move(self.defaultX, self.defaultY)

def updateSplitMode(self, mode):
self.SplitMode = mode
Expand Down
1 change: 0 additions & 1 deletion OCR_style.ui
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,6 @@
<slot>updateAutoTransBool(bool)</slot>
<slot>doAutoTrans()</slot>
<slot>updateSplitTextEdit()</slot>
<slot>print()</slot>
<slot>updateOCRText()</slot>
<slot>getIntoHotKeyChangeMode()</slot>
<slot>confirmHotkey()</slot>
Expand Down

0 comments on commit c6805dc

Please sign in to comment.