Control.ControlProxy Class Reference

Proxy class for a DocumentObjectGroupPython Control instance. More...

Public Member Functions

def __init__ (self, fp)
 Initialization method for ControlProxy. More...
 
def onDocumentRestored (self, fp)
 Method called when document is restored to make sure everything is as it was. More...
 
def onBeforeChange (self, fp, prop)
 Method called before DocumentObjectGroupPython Control is changed. More...
 
def onChanged (self, fp, prop)
 Method called after DocumentObjectGroupPython Control was changed. More...
 
def setProperties (self, fp)
 Method to set properties during initialization or document restoration. More...
 

Public Attributes

 temporary_export_path
 A str path to an export folder. More...
 
 updated
 

Static Public Attributes

bool updated = False
 A bool - True if a property was changed by a class and not user. More...
 

Detailed Description

Proxy class for a DocumentObjectGroupPython Control instance.

A ControlProxy instance adds properties to a DocumentObjectGroupPython Control instance and responds to their changes. It provides a control panel to control animations.

To access such a dialog double-click Control in Tree View or right click and select Show control panel option from a context menu.

To connect this Proxy object to a DocumentObjectGroupPython Control do:

a = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython",
"Control")
ControlProxy(a)

Definition at line 1051 of file Control.py.

Constructor & Destructor Documentation

◆ __init__()

def Control.ControlProxy.__init__ (   self,
  fp 
)

Initialization method for ControlProxy.

A class instance is created and made a Proxy for a generic DocumentObjectGroupPython Control object. During initialization number of properties are specified and preset.

Parameters
fpA barebone DocumentObjectGroupPython Control object to be extended.

Definition at line 1071 of file Control.py.

1071  def __init__(self, fp):
1072  self.setProperties(fp)
1073  fp.Proxy = self
1074 

Member Function Documentation

◆ onBeforeChange()

def Control.ControlProxy.onBeforeChange (   self,
  fp,
  prop 
)

Method called before DocumentObjectGroupPython Control is changed.

An old export path is stored for a case in which a new export path is not a valid path.

Parameters
fpA DocumentObjectGroupPython Control object.
propA str name of a property about to change.

Definition at line 1099 of file Control.py.

1099  def onBeforeChange(self, fp, prop):
1100  # Save an export path before it's changed to restore it if new
1101  # path is invalid
1102  if prop == "ExportPath" and hasattr(fp, "ExportPath") and \
1103  not self.updated:
1104  self.temporary_export_path = fp.ExportPath
1105 

◆ onChanged()

def Control.ControlProxy.onChanged (   self,
  fp,
  prop 
)

Method called after DocumentObjectGroupPython Control was changed.

Values of changed properties (start time, step time, stop time, export path) are checked for validity and edited if they are not.

Parameters
fpA DocumentObjectGroupPython Control object.
propA str name of a changed property.

Definition at line 1116 of file Control.py.

1116  def onChanged(self, fp, prop):
1117  # Don't do anything if a value was updated because another property
1118  # had changed
1119  if self.updated:
1120  self.updated = False
1121  return
1122 
1123  # Control animation range so that step size is less than range size
1124  elif prop == "StartTime" and hasattr(fp, "StopTime") and \
1125  hasattr(fp, "StepTime"):
1126  self.updated = True
1127  fp.StopTime = (fp.StopTime, fp.StartTime + fp.StepTime,
1128  float("inf"), 0.5)
1129  self.updated = True
1130  fp.StepTime = (fp.StepTime, 0.01, fp.StopTime - fp.StartTime, 0.1)
1131  elif prop == "StepTime" and hasattr(fp, "StartTime") and \
1132  hasattr(fp, "StopTime"):
1133  self.updated = True
1134  fp.StopTime = (fp.StopTime, fp.StartTime + fp.StepTime,
1135  float("inf"), 0.5)
1136  self.updated = True
1137  fp.StartTime = (fp.StartTime, -float("inf"),
1138  fp.StopTime - fp.StepTime, 0.5)
1139  elif prop == "StopTime" and hasattr(fp, "StartTime") and \
1140  hasattr(fp, "StepTime"):
1141  self.updated = True
1142  fp.StartTime = (fp.StartTime, -float("inf"),
1143  fp.StopTime - fp.StepTime, 0.5)
1144  self.updated = True
1145  fp.StepTime = (fp.StepTime, 0.01, fp.StopTime - fp.StartTime, 0.1)
1146 
1147  # Return to previous export path if the new one is invalid
1148  elif prop == "ExportPath":
1149  # Test access right in the folder an show warning if they are not
1150  # sufficient
1151  if not os.access(fp.ExportPath, os.W_OK | os.R_OK):
1152  QMessageBox.warning(None, 'Error while setting Export Path',
1153  "You don't have access to read and write "
1154  + "in this folder.")
1155  self.updated = True
1156  fp.ExportPath = self.temporary_export_path
1157  del self.temporary_export_path
1158 

◆ onDocumentRestored()

def Control.ControlProxy.onDocumentRestored (   self,
  fp 
)

Method called when document is restored to make sure everything is as it was.

Reinitialization it creates properties and sets them to default, if they were not restored automatically. Properties of connected ViewObject are also recreated and reset if necessary.

Parameters
fpA restored DocumentObjectGroupPython Control object.

Definition at line 1085 of file Control.py.

1085  def onDocumentRestored(self, fp):
1086  fp.ViewObject.Proxy.setProperties(fp.ViewObject)
1087  self.setProperties(fp)
1088 

◆ setProperties()

def Control.ControlProxy.setProperties (   self,
  fp 
)

Method to set properties during initialization or document restoration.

The properties are set if they are not already present and an AnimateDocumentObserver is recreated.

Parameters
fpA restored or barebone DocumentObjectGroupPython Control object.

Definition at line 1168 of file Control.py.

1168  def setProperties(self, fp):
1169  # Add (and preset) properties
1170  if not hasattr(fp, "StartTime"):
1171  fp.addProperty(
1172  "App::PropertyFloatConstraint", "StartTime", "Timing",
1173  "Animation start time. \nRange is "
1174  "< - inf | Stop Time - Step Time >."
1175  ).StartTime = (0, -float("inf"), 9.5, 0.5)
1176  elif hasattr(fp, "StepTime") and hasattr(fp, "StopTime"):
1177  fp.StartTime = (fp.StartTime, -float("inf"),
1178  fp.StopTime - fp.StepTime, 0.5)
1179  if not hasattr(fp, "StepTime"):
1180  fp.addProperty(
1181  "App::PropertyFloatConstraint", "StepTime", "Timing",
1182  "Animation step time. \nRange is "
1183  "< 0.01 | Stop Time - Start Time >."
1184  ).StepTime = (0.5, 0.01, 10, 0.1)
1185  elif hasattr(fp, "StartTime") and hasattr(fp, "StopTime"):
1186  fp.StepTime = (fp.StepTime, 0.01, fp.StopTime - fp.StartTime, 0.1)
1187  if not hasattr(fp, "StopTime"):
1188  fp.addProperty(
1189  "App::PropertyFloatConstraint", "StopTime", "Timing",
1190  "Animation stop time. \nRange is "
1191  + "< Start Time + Step Time | inf >."
1192  ).StopTime = (10, 0.5, float("inf"), 0.5)
1193  elif hasattr(fp, "StartTime") and hasattr(fp, "StepTime"):
1194  fp.StopTime = (fp.StopTime, fp.StartTime + fp.StepTime,
1195  float("inf"), 0.5)
1196 
1197  if not hasattr(fp, "ExportPath"):
1198  fp.addProperty(
1199  "App::PropertyPath", "ExportPath", "Record & Export",
1200  "Path to a folder, where recorded rendered images will be "
1201  "saved to be converted into a video.")
1202  if not hasattr(fp, "VideoWidth"):
1203  fp.addProperty(
1204  "App::PropertyIntegerConstraint", "VideoWidth",
1205  "Record & Export", "Width of the exported video in pixels.\n"
1206  + "Range is < 32 | 7680 >.").VideoWidth = (1280, 32, 7680, 10)
1207  else:
1208  fp.VideoWidth = (fp.VideoWidth, 32, 7680, 10)
1209  if not hasattr(fp, "VideoHeight"):
1210  fp.addProperty(
1211  "App::PropertyIntegerConstraint", "VideoHeight",
1212  "Record & Export", "Height of the exported video in pixels.\n"
1213  + "Range is < 32 | 4320 >.").VideoHeight = (720, 32, 4320, 10)
1214  else:
1215  fp.VideoHeight = (fp.VideoHeight, 32, 4320, 10)
1216 
1217  # Add an document observer to control the structure
1218  import AnimateDocumentObserver
1220 
1221 
def addObserver()
Adds an AnimateDocumentObserver between FreeCAD's document observers safely.

Member Data Documentation

◆ temporary_export_path

Control.ControlProxy.temporary_export_path

A str path to an export folder.

Definition at line 1104 of file Control.py.

◆ updated

Control.ControlProxy.updated = False
static

A bool - True if a property was changed by a class and not user.

Definition at line 1059 of file Control.py.


The documentation for this class was generated from the following file: