Преглед изворни кода

Toggle all polygons menu with shortcuts

(cherry picked from commit 46311d5fee6a5772207c00d31bdfe677ef2e95c9)
Michael Litvin пре 3 година
родитељ
комит
f30ad5a197
4 измењених фајлова са 42 додато и 2 уклоњено
  1. 16 2
      labelme/app.py
  2. 4 0
      labelme/config/default_config.yaml
  3. 11 0
      labelme/translate/empty.ts
  4. 11 0
      labelme/translate/zh_CN.ts

+ 16 - 2
labelme/app.py

@@ -460,6 +460,7 @@ class MainWindow(QtWidgets.QMainWindow):
         hideAll = action(
             self.tr("&Hide\nPolygons"),
             functools.partial(self.togglePolygons, False),
+            shortcuts["hide_all_polygons"],
             icon="eye",
             tip=self.tr("Hide all polygons"),
             enabled=False,
@@ -467,10 +468,19 @@ class MainWindow(QtWidgets.QMainWindow):
         showAll = action(
             self.tr("&Show\nPolygons"),
             functools.partial(self.togglePolygons, True),
+            shortcuts["show_all_polygons"],
             icon="eye",
             tip=self.tr("Show all polygons"),
             enabled=False,
         )
+        toggleAll = action(
+            self.tr("&Toggle\nPolygons"),
+            functools.partial(self.togglePolygons, None),
+            shortcuts["toggle_all_polygons"],
+            icon="eye",
+            tip=self.tr("Toggle all polygons"),
+            enabled=False,
+        )
 
         help = action(
             self.tr("&Tutorial"),
@@ -692,7 +702,7 @@ class MainWindow(QtWidgets.QMainWindow):
                 editMode,
                 brightnessContrast,
             ),
-            onShapesPresent=(saveAs, hideAll, showAll),
+            onShapesPresent=(saveAs, hideAll, showAll, toggleAll),
         )
 
         self.canvas.vertexSelected.connect(self.actions.removePoint.setEnabled)
@@ -738,6 +748,7 @@ class MainWindow(QtWidgets.QMainWindow):
                 None,
                 hideAll,
                 showAll,
+                toggleAll,
                 None,
                 zoomIn,
                 zoomOut,
@@ -1496,8 +1507,11 @@ class MainWindow(QtWidgets.QMainWindow):
         self.brightnessContrast_values[self.filename] = (brightness, contrast)
 
     def togglePolygons(self, value):
+        flag = value
         for item in self.labelList:
-            item.setCheckState(Qt.Checked if value else Qt.Unchecked)
+            if value is None:
+                flag = (item.checkState() == Qt.Unchecked)
+            item.setCheckState(Qt.Checked if flag else Qt.Unchecked)
 
     def loadFile(self, filename=None):
         """Load the specified file, or the last opened file if None."""

+ 4 - 0
labelme/config/default_config.yaml

@@ -118,3 +118,7 @@ shortcuts:
   edit_label: Ctrl+E
   toggle_keep_prev_mode: Ctrl+P
   remove_selected_point: [Meta+H, Backspace]
+
+  show_all_polygons: G
+  hide_all_polygons: H
+  toggle_all_polygons: T

+ 11 - 0
labelme/translate/empty.ts

@@ -332,6 +332,17 @@ Polygons</source>
         <source>Show all polygons</source>
         <translation type="unfinished"></translation>
     </message>
+    <message>
+        <location filename="../app.py" line="329"/>
+        <source>&amp;Toggle
+Polygons</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../app.py" line="329"/>
+        <source>Toggle all polygons</source>
+        <translation type="unfinished"></translation>
+    </message>
     <message>
         <location filename="../app.py" line="331"/>
         <source>&amp;Tutorial</source>

+ 11 - 0
labelme/translate/zh_CN.ts

@@ -332,6 +332,17 @@ Polygons</source>
         <source>Show all polygons</source>
         <translation>显示所有多边形</translation>
     </message>
+    <message>
+        <location filename="../app.py" line="329"/>
+        <source>&amp;Toggle
+Polygons</source>
+        <translation>开关多边形(&amp;S)</translation>
+    </message>
+    <message>
+        <location filename="../app.py" line="329"/>
+        <source>Toggle all polygons</source>
+        <translation>开关所有多边形</translation>
+    </message>
     <message>
         <location filename="../app.py" line="331"/>
         <source>&amp;Tutorial</source>