TemplatePyMod: fix regression due to locked=True mod

Fix regression caused by:
https://github.com/FreeCAD/FreeCAD/commit/a7331cbb43876b14e5e84d1fde1b673e8c381bb7
This commit is contained in:
Roy-043
2026-02-15 12:48:53 -06:00
committed by Chris Hennes
parent 562cac277c
commit 62700a5f12
3 changed files with 620 additions and 620 deletions
+8 -8
View File
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
# FreeCAD module providing base classes for document objects and view provider
# FreeCAD module providing base classes for document objects and view provider
# (c) 2011 Werner Mayer LGPL
import FreeCAD
@@ -57,9 +57,9 @@ class DocumentObject(object):
self.init()
self.initialised = True
self.propertyChanged(prop)
def addProperty(self,typ,name='',group='',doc='',attr=0,readonly=False,hidden=False):
def addProperty(self,typ,name='',group='',doc='',attr=0,readonly=False,hidden=False,locked=True):
"adds a new property to this object"
return self.__object__.addProperty(typ,name,group,doc,attr,readonly,hidden)
return self.__object__.addProperty(typ,name,group,doc,attr,readonly,hidden,locked)
def supportedProperties(self):
"lists the property types supported by this object"
return self.__object__.supportedProperties()
@@ -181,9 +181,9 @@ class ViewProvider(object):
# return []
#def setDisplayMode(self,mode):
# return mode
def addProperty(self,type,name='',group='',doc='',attr=0,readonly=False,hidden=False):
def addProperty(self,type,name='',group='',doc='',attr=0,readonly=False,hidden=False,locked=True):
"adds a new property to this object"
self.__vobject__.addProperty(type,name,group,doc,attr,readonly,hidden)
self.__vobject__.addProperty(type,name,group,doc,attr,readonly,hidden,locked)
def update(self):
"this method is executed whenever any of the properties of this ViewProvider changes"
self.__vobject__.update()
@@ -279,9 +279,9 @@ class Box(DocumentObject):
#-----------------------------INIT----------------------------------------
def init(self):
self.addProperty("App::PropertyLength","Length","Box","Length of the box", locked=True).Length=1.0
self.addProperty("App::PropertyLength","Width","Box","Width of the box", locked=True).Width=1.0
self.addProperty("App::PropertyLength","Height","Box", "Height of the box", locked=True).Height=1.0
self.addProperty("App::PropertyLength","Length","Box","Length of the box").Length=1.0
self.addProperty("App::PropertyLength","Width","Box","Width of the box").Width=1.0
self.addProperty("App::PropertyLength","Height","Box", "Height of the box").Height=1.0
#-----------------------------BEHAVIOR------------------------------------
def propertyChanged(self,prop):
File diff suppressed because it is too large Load Diff
+50 -50
View File
@@ -6,67 +6,67 @@ import FreeCAD, FreeCADGui
from pivy import coin
class Texture:
def __init__(self, obj, source):
"Add some custom properties to our box feature"
obj.addProperty("App::PropertyLink","Source","Texture", "Link to the shape", locked=True).Source = source
obj.Proxy = self
def __init__(self, obj, source):
"Add some custom properties to our box feature"
obj.addProperty("App::PropertyLink","Source","Texture", "Link to the shape", locked=True).Source = source
obj.Proxy = self
def onChanged(self, fp, prop):
return
def onChanged(self, fp, prop):
return
def execute(self, fp):
return
def execute(self, fp):
return
class ViewProviderTexture:
def __init__(self, obj):
obj.addProperty("App::PropertyPath","File","Texture", "File name to the texture resource", locked=True)
self.obj = obj
obj.Proxy = self
def __init__(self, obj):
obj.addProperty("App::PropertyPath","File","Texture", "File name to the texture resource", locked=True)
self.obj = obj
obj.Proxy = self
def onChanged(self, obj, prop):
if prop == "File":
self.tex.filename = str(obj.File)
return
def onChanged(self, obj, prop):
if prop == "File":
self.tex.filename = str(obj.File)
return
def updateData(self, fp, prop):
return
def updateData(self, fp, prop):
return
def getDisplayModes(self,obj):
''' Return a list of display modes. '''
modes=["Texture"]
return modes
def getDisplayModes(self,obj):
''' Return a list of display modes. '''
modes=["Texture"]
return modes
def attach(self, obj):
self.grp = coin.SoGroup()
self.tex = coin.SoTexture2()
#self.env = coin.SoTextureCoordinateEnvironment()
def attach(self, obj):
self.grp = coin.SoGroup()
self.tex = coin.SoTexture2()
#self.env = coin.SoTextureCoordinateEnvironment()
self.grp.addChild(self.tex)
#self.grp.addChild(self.env)
root = obj.Object.Source.ViewObject.RootNode
self.grp.addChild(root)
obj.addDisplayMode(self.grp,"Texture")
# move the original node
doc = obj.Object.Document
doc = FreeCADGui.getDocument(doc.Name)
graph = doc.ActiveView.getSceneGraph()
graph.removeChild(root)
self.grp.addChild(self.tex)
#self.grp.addChild(self.env)
root = obj.Object.Source.ViewObject.RootNode
self.grp.addChild(root)
obj.addDisplayMode(self.grp,"Texture")
# move the original node
doc = obj.Object.Document
doc = FreeCADGui.getDocument(doc.Name)
graph = doc.ActiveView.getSceneGraph()
graph.removeChild(root)
def claimChildren(self):
return [self.obj.Object.Source]
def claimChildren(self):
return [self.obj.Object.Source]
def __getstate__(self):
return None
def __getstate__(self):
return None
def __setstate__(self,state):
return None
def __setstate__(self,state):
return None
def makeTexture():
FreeCAD.newDocument()
box = FreeCAD.ActiveDocument.addObject("Part::Box","Box")
tex=FreeCAD.ActiveDocument.addObject("App::FeaturePython","Texture")
Texture(tex, box)
box.ViewObject.Selectable = False
ViewProviderTexture(tex.ViewObject)
box.touch()
FreeCAD.ActiveDocument.recompute()
FreeCAD.newDocument()
box = FreeCAD.ActiveDocument.addObject("Part::Box","Box")
tex=FreeCAD.ActiveDocument.addObject("App::FeaturePython","Texture")
Texture(tex, box)
box.ViewObject.Selectable = False
ViewProviderTexture(tex.ViewObject)
box.touch()
FreeCAD.ActiveDocument.recompute()