Kaynağa Gözat

- updated the UI in Geometry Editor

Marius Stanciu 5 yıl önce
ebeveyn
işleme
bac37865e9
3 değiştirilmiş dosya ile 48 ekleme ve 19 silme
  1. 1 0
      README.md
  2. 23 19
      flatcamEditors/FlatCAMGeoEditor.py
  3. 24 0
      flatcamGUI/GUIElements.py

+ 1 - 0
README.md

@@ -12,6 +12,7 @@ CAD program, and create G-Code for Isolation routing.
 01.03.2020
 
 - updated the CutOut Tool such that while adding manual gaps, the cutting geometry is updated on-the-fly if the gap size or tool diameter parameters are adjusted
+- updated the UI in Geometry Editor
 
 29.02.2020
 

+ 23 - 19
flatcamEditors/FlatCAMGeoEditor.py

@@ -3252,15 +3252,17 @@ class FlatCAMGeoEditor(QtCore.QObject):
         self.title_box.addWidget(self.title_label, stretch=1)
         self.title_box.addWidget(QtWidgets.QLabel(''))
 
-        self.tw = FCTree(extended_sel=True)
+        self.tw = FCTree(columns=3, header_hidden=False, protected_column=[0, 1], extended_sel=True)
+        self.tw.setHeaderLabels(["ID", _("Type"), _("Name")])
+        self.tw.setIndentation(0)
+        self.tw.header().setStretchLastSection(True)
+        self.tw.header().setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
         self.tools_box.addWidget(self.tw)
 
         self.geo_font = QtGui.QFont()
         self.geo_font.setBold(True)
 
-        parent = self.tw.invisibleRootItem()
-        self.geo_parent = self.tw.addParent(
-            parent, _('Geometry Elements'), expanded=True, color=QtGui.QColor("#000000"), font=self.geo_font)
+        self.geo_parent = self.tw.invisibleRootItem()
 
         # ## Toolbar events and properties
         self.tools = {
@@ -3494,29 +3496,33 @@ class FlatCAMGeoEditor(QtCore.QObject):
 
         for elem in self.storage.get_objects():
             geo_type = type(elem.geo)
-            title = None
+            el_type = None
             if geo_type is LinearRing:
-                title = _('ID Ring')
+                el_type = _('Ring')
             elif geo_type is LineString:
-                title = _('ID Line')
+                el_type = _('Line')
             elif geo_type is Polygon:
-                title = _('ID Polygon')
+                el_type = _('Polygon')
             elif geo_type is MultiLineString:
-                title = _('ID Multi-Line')
+                el_type = _('Multi-Line')
             elif geo_type is MultiPolygon:
-                title = _('ID Multi-Polygon')
+                el_type = _('Multi-Polygon')
 
-            self.tw.addChild(
+            self.tw.addParentEditable(
                 self.geo_parent,
                 [
-                    '%s:' % title,
-                    str(id(elem))
+                    str(id(elem)),
+                    '%s' % el_type,
+                    _("Geo Elem")
                 ],
-                True,
                 font=self.geo_font,
-                font_items=1
+                font_items=2,
+                # color=QtGui.QColor("#FF0000"),
+                editable=True
             )
 
+        self.tw.resize_sig.emit()
+
     def on_geo_elem_selected(self):
         pass
 
@@ -3526,7 +3532,7 @@ class FlatCAMGeoEditor(QtCore.QObject):
         for sel in selected_tree_items:
             for obj_shape in self.storage.get_objects():
                 try:
-                    if id(obj_shape) == int(sel.text(1)):
+                    if id(obj_shape) == int(sel.text(0)):
                         self.selected.append(obj_shape)
                 except ValueError:
                     pass
@@ -3686,9 +3692,7 @@ class FlatCAMGeoEditor(QtCore.QObject):
 
         # clear the Tree
         self.tw.clear()
-        parent = self.tw.invisibleRootItem()
-        self.geo_parent = self.tw.addParent(
-            parent, _('Geometry Elements'), expanded=True, color=QtGui.QColor("#000000"), font=self.geo_font)
+        self.geo_parent = self.tw.invisibleRootItem()
 
         # hide the UI
         self.geo_frame.hide()

+ 24 - 0
flatcamGUI/GUIElements.py

@@ -153,6 +153,7 @@ class RadioSet(QtWidgets.QWidget):
 
 
 class FCTree(QtWidgets.QTreeWidget):
+    resize_sig = QtCore.pyqtSignal()
 
     def __init__(self, parent=None, columns=2, header_hidden=True, extended_sel=False, protected_column=None):
         super(FCTree, self).__init__(parent)
@@ -167,6 +168,8 @@ class FCTree(QtWidgets.QTreeWidget):
 
         self.protected_column = protected_column
         self.itemDoubleClicked.connect(self.on_double_click)
+        self.header().sectionDoubleClicked.connect(self.on_header_double_click)
+        self.resize_sig.connect(self.on_resize)
 
     def on_double_click(self, item, column):
         # from here: https://stackoverflow.com/questions/2801959/making-only-one-column-of-a-qtreewidgetitem-editable
@@ -176,6 +179,13 @@ class FCTree(QtWidgets.QTreeWidget):
         elif tmp_flags & QtCore.Qt.ItemIsEditable:
             item.setFlags(tmp_flags ^ QtCore.Qt.ItemIsEditable)
 
+    def on_header_double_click(self, column):
+        header = self.header()
+        header.setSectionResizeMode(column, QtWidgets.QHeaderView.ResizeToContents)
+        width = header.sectionSize(column)
+        header.setSectionResizeMode(column, QtWidgets.QHeaderView.Interactive)
+        header.resizeSection(column, width)
+
     def is_editable(self, tested_col):
         return False if tested_col in self.protected_column else True
 
@@ -228,6 +238,20 @@ class FCTree(QtWidgets.QTreeWidget):
             except TypeError:
                 item.setFont(font_items, font)
 
+    def resizeEvent(self, event):
+        """ Resize all sections to content and user interactive """
+
+        super(FCTree, self).resizeEvent(event)
+        self.on_resize()
+
+    def on_resize(self):
+        header = self.header()
+        for column in range(header.count()):
+            header.setSectionResizeMode(column, QtWidgets.QHeaderView.ResizeToContents)
+            width = header.sectionSize(column)
+            header.setSectionResizeMode(column, QtWidgets.QHeaderView.Interactive)
+            header.resizeSection(column, width)
+
 
 class LengthEntry(QtWidgets.QLineEdit):
     def __init__(self, output_units='IN', decimals=None, parent=None):