84 lines
2 KiB
Python
84 lines
2 KiB
Python
class BaseObject:
|
|
EXTENSIONS = []
|
|
TYPE = None
|
|
|
|
save_keys = []
|
|
|
|
def __init__(self, feature):
|
|
self.feature = feature
|
|
|
|
feature.Proxy = self
|
|
|
|
self.setup_properties(feature)
|
|
self.setup_extensions(feature)
|
|
|
|
feature.Type = self.TYPE
|
|
|
|
self.sync_from()
|
|
|
|
def execute(self, feature):
|
|
# TODO this might not be the right move
|
|
print(self, 'BaseObject.execute')
|
|
#self.onDocumentRestored(feature)
|
|
|
|
def get_api(self):
|
|
p = self.feature
|
|
|
|
while p:
|
|
if p.Type == 'KiConnect::Project':
|
|
return [ o for o in p.Group if hasattr(o, 'Type') and o.Type == 'KiConnect::API' ][0].Proxy
|
|
p = p.getParent()
|
|
|
|
return None
|
|
|
|
def isChildOf(self, parent):
|
|
p = self.feature
|
|
|
|
while p:
|
|
if p == parent:
|
|
return True
|
|
p = p.getParent()
|
|
|
|
return False
|
|
|
|
def onBeforeChange(self, feature, prop):
|
|
pass
|
|
|
|
def onChanged(self, feature, prop):
|
|
pass
|
|
|
|
def onDocumentRestored(self, feature):
|
|
self.feature = feature
|
|
|
|
def setup_extensions(self, feature):
|
|
if hasattr(self, 'EXTENSIONS'):
|
|
for ext in self.EXTENSIONS:
|
|
self.feature.addExtension(ext)
|
|
|
|
def setup_properties(self, feature):
|
|
feature.addProperty('App::PropertyString', 'Type', 'KiConnect', 'Internal KiConnect Type', hidden=True)
|
|
|
|
def sync_from(self):
|
|
pass
|
|
|
|
def sync_to(self):
|
|
pass
|
|
|
|
def dumps(self):
|
|
data = [ getattr(self, 'TYPE') ]
|
|
|
|
if len(self.save_keys) > 0:
|
|
for key in self.save_keys:
|
|
try:
|
|
data.append(getattr(self, key))
|
|
except Exception as e:
|
|
#XXX logging
|
|
print(e)
|
|
|
|
return tuple(data)
|
|
|
|
def loads(self, state):
|
|
self.Type = state[0]
|
|
|
|
for idx, key in enumerate(self.save_keys):
|
|
setattr(self, key, state[idx + 1])
|