From 814e8a877398f77ab8b27d776049fa172ea471bc Mon Sep 17 00:00:00 2001 From: HinGwenWoong Date: Sun, 20 Feb 2022 12:41:41 +0800 Subject: [PATCH] Delete useless part in key dialog, translate tip --- PPOCRLabel/PPOCRLabel.py | 9 ++++--- PPOCRLabel/libs/keyDialog.py | 25 +++---------------- .../resources/strings/strings-en.properties | 3 ++- .../strings/strings-zh-CN.properties | 3 ++- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/PPOCRLabel/PPOCRLabel.py b/PPOCRLabel/PPOCRLabel.py index 51865e32..6376173b 100644 --- a/PPOCRLabel/PPOCRLabel.py +++ b/PPOCRLabel/PPOCRLabel.py @@ -80,6 +80,7 @@ class MainWindow(QMainWindow): settings = self.settings self.lang = lang self.kie_mode = kie_mode + self.key_previous_text = "" # Load string bundle for i18n if lang not in ['ch', 'en']: lang = 'en' @@ -428,6 +429,7 @@ class MainWindow(QMainWindow): # key list dialog if kie_mode: self.keyDialog = KeyDialog( + text=getStr('keyDialogTip'), parent=self, labels=None, sort_labels=True, @@ -1219,10 +1221,9 @@ class MainWindow(QMainWindow): self.canvas.resetAllLines() if self.kie_mode: - previous_text = self.keyDialog.edit.text() - text, flags, group_id = self.keyDialog.popUp(text) - if not text: - self.keyDialog.edit.setText(previous_text) + self.key_previous_text, flags = self.keyDialog.popUp(self.key_previous_text) + if not self.key_previous_text: + self.keyDialog.edit.setText(self.key_previous_text) def scrollRequest(self, delta, orientation): units = - delta / (8 * 15) diff --git a/PPOCRLabel/libs/keyDialog.py b/PPOCRLabel/libs/keyDialog.py index 2332354c..028227aa 100644 --- a/PPOCRLabel/libs/keyDialog.py +++ b/PPOCRLabel/libs/keyDialog.py @@ -1,13 +1,10 @@ import re -import sys from PyQt5 import QtCore from PyQt5 import QtGui from PyQt5 import QtWidgets - from libs.utils import newIcon, labelValidator - QT5 = True @@ -49,16 +46,11 @@ class KeyDialog(QtWidgets.QDialog): self.edit.editingFinished.connect(self.postProcess) if flags: self.edit.textChanged.connect(self.updateFlags) - self.edit_group_id = QtWidgets.QLineEdit() - self.edit_group_id.setPlaceholderText("Group ID") - self.edit_group_id.setValidator( - QtGui.QRegExpValidator(QtCore.QRegExp(r"\d*"), None) - ) + layout = QtWidgets.QVBoxLayout() if show_text_field: layout_edit = QtWidgets.QHBoxLayout() layout_edit.addWidget(self.edit, 6) - layout_edit.addWidget(self.edit_group_id, 2) layout.addLayout(layout_edit) # buttons self.buttonBox = bb = QtWidgets.QDialogButtonBox( @@ -189,13 +181,7 @@ class KeyDialog(QtWidgets.QDialog): flags[item.text()] = item.isChecked() return flags - def getGroupId(self): - group_id = self.edit_group_id.text() - if group_id: - return int(group_id) - return None - - def popUp(self, text=None, move=True, flags=None, group_id=None): + def popUp(self, text=None, move=True, flags=None): if self._fit_to_content["row"]: self.labelList.setMinimumHeight( self.labelList.sizeHintForRow(0) * self.labelList.count() + 2 @@ -213,10 +199,7 @@ class KeyDialog(QtWidgets.QDialog): self.resetFlags(text) self.edit.setText(text) self.edit.setSelection(0, len(text)) - if group_id is None: - self.edit_group_id.clear() - else: - self.edit_group_id.setText(str(group_id)) + items = self.labelList.findItems(text, QtCore.Qt.MatchFixedString) if items: if len(items) != 1: @@ -227,6 +210,6 @@ class KeyDialog(QtWidgets.QDialog): if move: self.move(QtGui.QCursor.pos()) if self.exec_(): - return self.edit.text(), self.getFlags(), self.getGroupId() + return self.edit.text(), self.getFlags() else: return None, None, None diff --git a/PPOCRLabel/resources/strings/strings-en.properties b/PPOCRLabel/resources/strings/strings-en.properties index eee25ec1..a32979aa 100644 --- a/PPOCRLabel/resources/strings/strings-en.properties +++ b/PPOCRLabel/resources/strings/strings-en.properties @@ -107,4 +107,5 @@ undoLastPoint=Undo Last Point autoSaveMode=Auto Export Label Mode lockBox=Lock selected box/Unlock all box lockBoxDetail=Lock selected box/Unlock all box -keyListTitle=Key List \ No newline at end of file +keyListTitle=Key List +keyDialogTip=Enter object label \ No newline at end of file diff --git a/PPOCRLabel/resources/strings/strings-zh-CN.properties b/PPOCRLabel/resources/strings/strings-zh-CN.properties index bb411bfd..1694d568 100644 --- a/PPOCRLabel/resources/strings/strings-zh-CN.properties +++ b/PPOCRLabel/resources/strings/strings-zh-CN.properties @@ -107,4 +107,5 @@ undoLastPoint=撤销上个点 autoSaveMode=自动导出标记结果 lockBox=锁定框/解除锁定框 lockBoxDetail=若当前没有框处于锁定状态则锁定选中的框,若存在锁定框则解除所有锁定框的锁定状态 -keyListTitle=关键词列表 \ No newline at end of file +keyListTitle=关键词列表 +keyDialogTip=请输入类型名称 \ No newline at end of file -- GitLab