Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 86 additions & 1 deletion PPOCRLabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def get_str(str_id):
use_chart_recognition=False,
use_region_detection=False,
device=self.gpu,
enable_mkldnn=False,
)

if os.path.exists("./data/paddle.png"):
Expand Down Expand Up @@ -460,13 +461,43 @@ def get_str(str_id):
labelListContainer.setLayout(listLayout)
self.labelList.itemSelectionChanged.connect(self.labelSelectionChanged)
self.labelList.clicked.connect(self.labelList.item_clicked)
self.labelList.navigateRequested.connect(self.navigateShapes)
self.labelList.editRequested.connect(self.editCurrentLabelInline)
self.labelList.setToolTip(
"Tab / Shift+Tab: next / previous box\n"
"F2 or Enter: edit the selected box\n"
"Esc: confirm the edit"
)

# Connect to itemChanged to detect checkbox changes.
self.labelList.itemChanged.connect(self.labelItemChanged)
self.labelListDockName = get_str("recognitionResult")
self.labelListDock = QDockWidget(self.labelListDockName, self)
self.labelListDock.setWidget(self.labelList)
self.labelListDock.setFeatures(QDockWidget.NoDockWidgetFeatures)

self.shortcutInfoButton = QToolButton()
self.shortcutInfoButton.setText("i")
self.shortcutInfoButton.setAutoRaise(True)
self.shortcutInfoButton.setCursor(Qt.PointingHandCursor)
self.shortcutInfoButton.setFixedSize(18, 18)
self.shortcutInfoButton.setStyleSheet(
"QToolButton { border: 1px solid palette(mid); border-radius: 9px;"
" font-weight: bold; }"
"QToolButton:hover { background-color: palette(highlight);"
" color: palette(highlighted-text); }"
)
self.shortcutInfoButton.setToolTip(self.shortcutTooltip())
self.shortcutInfoButton.clicked.connect(self.showKeysDialog)

titleBar = QWidget()
titleLayout = QHBoxLayout(titleBar)
titleLayout.setContentsMargins(6, 2, 6, 2)
titleLayout.addWidget(QLabel(self.labelListDockName))
titleLayout.addWidget(self.shortcutInfoButton)
titleLayout.addStretch()
self.labelListDock.setTitleBarWidget(titleBar)

labelIndexListlBox.addWidget(
self.labelListDock, 10
) # label list is wider than index list
Expand Down Expand Up @@ -608,6 +639,13 @@ def get_str(str_id):
self.canvas.shapeMoved.connect(self.updateBoxlist) # self.setDirty
self.canvas.selectionChanged.connect(self.shapeSelectionChanged)
self.canvas.drawingPolygon.connect(self.toggleDrawingSensitive)
self.canvas.navigationRequested.connect(self.navigateShapes)
self.canvas.editRequested.connect(self.editCurrentLabelInline)
self.canvas.setToolTip(
"Tab / Shift+Tab: next / previous box\n"
"F2 or Enter: edit the selected box\n"
"Esc: confirm the edit"
)

centerLayout = QVBoxLayout()
centerLayout.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -1291,7 +1329,10 @@ def get_str(str_id):
# Custom context menu for the canvas widget:
addActions(self.canvas.menus[0], self.actions.beginnerContext)

self.statusBar().showMessage("%s started." % __appname__)
self.statusBar().showMessage(
"%s started. Tip: Tab / Shift+Tab switches boxes, "
"F2 or Enter edits, Esc confirms." % __appname__
)
self.statusBar().show()

# Application state.
Expand Down Expand Up @@ -1457,6 +1498,31 @@ def currentBox(self):
return items[0]
return None

def navigateShapes(self, step):
"""Move the selection to the next/previous detection box."""
count = self.labelList.count()
if count == 0:
return
items = self.labelList.selectedItems()
row = self.labelList.row(items[0]) if items else -1
if row < 0:
row = 0 if step > 0 else count - 1
else:
row = (row + step) % count
self.labelList.setCurrentRow(row)
item = self.labelList.item(row)
if item is not None:
self.labelList.scrollToItem(item, QAbstractItemView.PositionAtCenter)
self.labelList.setFocus()

def editCurrentLabelInline(self):
"""Open the inline editor for the currently selected detection box."""
if not self.canvas.editing() or self.labelList.count() == 0:
return
if not self.labelList.selectedItems():
self.labelList.setCurrentRow(0)
self.labelList.open_editor()

def addRecentFile(self, filePath):
if filePath in self.recentFiles:
self.recentFiles.remove(filePath)
Expand Down Expand Up @@ -1501,6 +1567,22 @@ def showKeysDialog(self):
msg = keysInfo(self.lang)
QMessageBox.information(self, "Information", msg)

def shortcutTooltip(self):
return (
"Keyboard shortcuts\n"
"Tab / Shift+Tab: next / previous box\n"
"F2 or Enter: edit the selected box\n"
"Esc: confirm the edit and return to navigation\n"
"W: create rectangle box\n"
"Q or Home: create four-point box\n"
"Ctrl+E: edit label\n"
"Ctrl+R: re-recognize selected box\n"
"Ctrl+Shift+R: re-recognize all boxes\n"
"A / D: previous / next image\n"
"Delete / Backspace: delete selected box\n"
"Click for the full shortcut list"
)

def applyFontSize(self, fontSize):
# 1. Update standard font objects
f = self.font()
Expand Down Expand Up @@ -3161,6 +3243,8 @@ def autoRecognition(self):

self.autoDialog = AutoDialog(
parent=self,
text=self.stringBundle.getString("autoRecognitionNotice"),
title=self.stringBundle.getString("autoRecognition"),
ocr=self.ocr,
image_list=uncheckedList,
len_bar=len(uncheckedList),
Expand Down Expand Up @@ -3710,6 +3794,7 @@ def modelChoose(self):
use_chart_recognition=False,
use_region_detection=False,
device=self.gpu,
enable_mkldnn=False,
)
self.model_lang = choose_lang
else:
Expand Down
Loading