From 70c8ff15ba875fe2cfca283da9f6e8000cbb3a3c Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Thu, 15 Jul 2021 08:33:16 +0200 Subject: [PATCH] Material Editor, code formating --- src/Mod/Material/MaterialEditor.py | 106 ++++++++++++++--------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/src/Mod/Material/MaterialEditor.py b/src/Mod/Material/MaterialEditor.py index 51cf4ab14c..4c8e74239e 100644 --- a/src/Mod/Material/MaterialEditor.py +++ b/src/Mod/Material/MaterialEditor.py @@ -39,7 +39,7 @@ if sys.version_info.major >= 3: class MaterialEditor: - def __init__(self, obj=None, prop=None, material=None, card_path=''): + def __init__(self, obj=None, prop=None, material=None, card_path=""): """Initializes, optionally with an object name and a material property name to edit, or directly with a material dictionary.""" @@ -139,7 +139,7 @@ class MaterialEditor: def implementModel(self): - '''implements the model with the material attribute structure.''' + """implements the model with the material attribute structure.""" p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Material") widget = self.widget @@ -163,13 +163,13 @@ class MaterialEditor: for properName in group[gg]: pp = properName # property name item = QtGui.QStandardItem(pp) - item.setToolTip(group[gg][properName]['Description']) + item.setToolTip(group[gg][properName]["Description"]) self.internalprops.append(pp) it = QtGui.QStandardItem() - it.setToolTip(group[gg][properName]['Description']) + it.setToolTip(group[gg][properName]["Description"]) - tt = group[gg][properName]['Type'] + tt = group[gg][properName]["Type"] itType = QtGui.QStandardItem(tt) top.appendRow([item, it, itType]) @@ -180,9 +180,9 @@ class MaterialEditor: def updateMatParamsInTree(self, data): - '''updates the contents of the editor with the given dictionary + """updates the contents of the editor with the given dictionary the material property keys where added to the editor already - not known material property keys will be added to the user defined group''' + not known material property keys will be added to the user defined group""" # print(data) model = self.widget.treeView.model() @@ -223,8 +223,8 @@ class MaterialEditor: return self.card_path = self.widget.ComboMaterial.itemData(index) FreeCAD.Console.PrintMessage( - 'choose_material in material editor:\n' - ' {}\n'.format(self.card_path) + "choose_material in material editor:\n" + " {}\n".format(self.card_path) ) if os.path.isfile(self.card_path): from importFCMat import read @@ -234,11 +234,11 @@ class MaterialEditor: # the card could be updated the dict not self.widget.ComboMaterial.setCurrentIndex(index) # set after tree params else: - FreeCAD.Console.PrintError('material card not found: {}\n'.format(self.card_path)) + FreeCAD.Console.PrintError("material card not found: {}\n".format(self.card_path)) def updateCardsInCombo(self): - '''updates the contents of the materials combo with existing material cards''' + """updates the contents of the materials combo with existing material cards""" mat_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Material/Cards") sort_by_resources = mat_prefs.GetBool("SortByResources", False) @@ -260,13 +260,13 @@ class MaterialEditor: a_path = card_names_tmp[a_name] card_name_list.append([a_name, a_path, self.icons[a_path]]) - card_name_list.insert(0, [None, '', '']) + card_name_list.insert(0, [None, "", ""]) for mat in card_name_list: self.widget.ComboMaterial.addItem(QtGui.QIcon(mat[2]), mat[0], mat[1]) def openProductURL(self): - '''opens the contents of the ProductURL field in an external browser.''' + """opens the contents of the ProductURL field in an external browser.""" model = self.widget.treeView.model() item = model.findItems(translate("Material", "Product URL"), @@ -340,8 +340,8 @@ class MaterialEditor: def deleteCustomProperty(self, key=None): - '''Deletes a custom property from the editor, - or deletes the value of an internal property.''' + """Deletes a custom property from the editor, + or deletes the value of an internal property.""" widget = self.widget treeView = widget.treeView @@ -377,8 +377,8 @@ class MaterialEditor: def onClickTree(self, index): - '''Checks if the current item is a custom or an internal property, - and enable the delete property or delete value button.''' + """Checks if the current item is a custom or an internal property, + and enable the delete property or delete value button.""" widget = self.widget buttonDeleteProperty = widget.ButtonDeleteProperty @@ -428,18 +428,18 @@ class MaterialEditor: # since text(0) could be translated matkey = self.collapseKey(str(kk)) matvalue = unicode(ii) - if matvalue or (matkey == 'Name'): + if matvalue or (matkey == "Name"): # use only keys which are not empty and the name even if empty d[matkey] = matvalue # self.outputDict(d) return d def outputDict(self, d): - print('MaterialEditor dictionary') + print("MaterialEditor dictionary") for param in d: - print(' {} : {}'.format(param, d[param])) + print(" {} : {}".format(param, d[param])) - ''' + """ def setTexture(self, pattern): "displays a texture preview if needed" self.widget.PreviewVector.hide() @@ -453,7 +453,7 @@ class MaterialEditor: if pattern: self.widget.PreviewVector.setPixmap(QtGui.QPixmap(pattern)) self.widget.PreviewVector.show() - ''' + """ def updatePreviews(self, mat=None): "updates the preview images from the content of the editor" @@ -505,9 +505,9 @@ class MaterialEditor: "Opens a FCMat file" filetuple = QtGui.QFileDialog.getOpenFileName( QtGui.QApplication.activeWindow(), - 'Open FreeCAD Material file', + "Open FreeCAD Material file", self.directory, - '*.FCMat' + "*.FCMat" ) self.card_path = filetuple[0] index = self.widget.ComboMaterial.findData(self.card_path) @@ -518,8 +518,8 @@ class MaterialEditor: if os.path.isfile(self.card_path): if index == -1: FreeCAD.Console.PrintMessage( - 'Card path: {} not found in known cards.' - 'The material parameter only are loaded.\n' + "Card path: {} not found in known cards." + "The material parameter only are loaded.\n" .format(self.card_path) ) from importFCMat import read @@ -548,9 +548,9 @@ class MaterialEditor: name = "Material" filetuple = QtGui.QFileDialog.getSaveFileName( QtGui.QApplication.activeWindow(), - 'Save FreeCAD Material file', - self.directory + '/' + name + '.FCMat', - '*.FCMat' + "Save FreeCAD Material file", + self.directory + "/" + name + ".FCMat", + "*.FCMat" ) # a tuple of two empty strings returns True, so use the filename directly filename = filetuple[0] @@ -573,7 +573,7 @@ class MaterialEditor: class MaterialsDelegate(QtGui.QStyledItemDelegate): - '''provides display and editing facilities for data items from a model.''' + """provides display and editing facilities for data items from a model.""" def __init__(self): "" @@ -582,7 +582,7 @@ class MaterialsDelegate(QtGui.QStyledItemDelegate): def createEditor(self, parent, option, index): - '''returns the widget used to change data from the model.''' + """returns the widget used to change data from the model.""" model = index.model() column = index.column() @@ -628,16 +628,16 @@ class MaterialsDelegate(QtGui.QStyledItemDelegate): def setEditorData(self, editor, index): - '''provides the widget with data to manipulate.''' + """provides the widget with data to manipulate.""" - Type = editor.property('Type') + Type = editor.property("Type") model = index.model() item = model.itemFromIndex(index) print("item1={}".format(item.text())) if Type == "Color": - color = editor.property('color') + color = editor.property("color") color = tuple([v/255.0 for v in color.getRgb()]) item.setText(str(color)) @@ -658,7 +658,7 @@ ui = FreeCADGui.UiLoader() def matProperWidget(parent=None, matproperty=None, Type="String", Value=None, minimum=None, maximum=None, stepsize=None, precision=12): - '''customs widgets for the material stuff.''' + """customs widgets for the material stuff.""" # FIXME # Workaround for problem from here: @@ -688,7 +688,7 @@ def matProperWidget(parent=None, matproperty=None, Type="String", Value=None, if hasattr(FreeCAD.Units, matproperty): unit = getattr(FreeCAD.Units, matproperty) quantity = FreeCAD.Units.Quantity(1, unit) - widget.setProperty('unit', quantity.getUserPreferred()[2]) + widget.setProperty("unit", quantity.getUserPreferred()[2]) else: FreeCAD.Console.PrintWarning( "Not known unit for property: {}. Probably the Quantity does not have a unit.\n" @@ -714,7 +714,7 @@ def matProperWidget(parent=None, matproperty=None, Type="String", Value=None, elif Type == "Boolean": widget = ui.createWidget("Gui::PrefComboBox") - widget.insertItems(0, ['', 'False', 'True']) + widget.insertItems(0, ["", "False", "True"]) elif Type == "Vector": @@ -727,22 +727,22 @@ def matProperWidget(parent=None, matproperty=None, Type="String", Value=None, value = string2tuple(Value) color = QtGui.QColor() color.setRgb(value[0], value[1], value[2], value[3]) - widget.setProperty('color', color) + widget.setProperty("color", color) else: widget = QtGui.QLineEdit() if minimum is not None: - widget.setProperty('minimum', minimum) + widget.setProperty("minimum", minimum) if maximum is not None: - widget.setProperty('maximum', maximum) + widget.setProperty("maximum", maximum) if stepsize is not None: - widget.setProperty('stepsize', stepsize) + widget.setProperty("stepsize", stepsize) if precision is not None: - widget.setProperty('precision', precision) + widget.setProperty("precision", precision) - widget.setProperty('Type', Type) + widget.setProperty("Type", Type) widget.setParent(parent) @@ -752,7 +752,7 @@ def matProperWidget(parent=None, matproperty=None, Type="String", Value=None, def string2tuple(string): "provisionally" value = string[1:-1] - value = value.split(',') + value = value.split(",") value = [int(float(v)*255) for v in value] value = tuple(value) return value @@ -789,26 +789,26 @@ def editMaterial(material=None, card_path=None): return {} -''' +""" # some examples how to open the material editor in Python: import MaterialEditor MaterialEditor.openEditor() doc = FreeCAD.open( - FreeCAD.ConfigGet("AppHomePath") + 'data/examples/FemCalculixCantilever3D.FCStd' + FreeCAD.ConfigGet("AppHomePath") + "data/examples/FemCalculixCantilever3D.FCStd" ) import MaterialEditor -MaterialEditor.openEditor('SolidMaterial', 'Material') +MaterialEditor.openEditor("SolidMaterial", "Material") import MaterialEditor MaterialEditor.editMaterial({ - 'Density': '1234.0 kg/m^3', - 'Name': 'My-Material-Data', - 'PoissonRatio': '0.66', - 'YoungsModulus': '123456 MPa' + "Density": "1234.0 kg/m^3", + "Name": "My-Material-Data", + "PoissonRatio": "0.66", + "YoungsModulus": "123456 MPa" }) import MaterialEditor -MaterialEditor.editMaterial('ABS') +MaterialEditor.editMaterial("ABS") -''' +"""