32
32
from classes .app import get_app
33
33
34
34
35
- # Get project data reference
36
- app = get_app ()
37
- project = app .project
38
-
39
-
40
35
class QueryObject :
41
36
""" This class allows one or more project data objects to be queried """
42
37
@@ -56,7 +51,7 @@ def save(self, OBJECT_TYPE):
56
51
if not self .id and self .type == "insert" :
57
52
58
53
# Insert record, and Generate id
59
- self .id = project .generate_id ()
54
+ self .id = get_app (). project .generate_id ()
60
55
61
56
# save id in data (if attribute found)
62
57
self .data ["id" ] = copy .deepcopy (self .id )
@@ -67,23 +62,23 @@ def save(self, OBJECT_TYPE):
67
62
self .key .append ({"id" : self .id })
68
63
69
64
# Insert into project data
70
- app .updates .insert (copy .deepcopy (OBJECT_TYPE .object_key ), copy .deepcopy (self .data ))
65
+ get_app () .updates .insert (copy .deepcopy (OBJECT_TYPE .object_key ), copy .deepcopy (self .data ))
71
66
72
67
# Mark record as 'update' now... so another call to this method won't insert it again
73
68
self .type = "update"
74
69
75
70
elif self .id and self .type == "update" :
76
71
77
72
# Update existing project data
78
- app .updates .update (self .key , self .data )
73
+ get_app () .updates .update (self .key , self .data )
79
74
80
75
def delete (self , OBJECT_TYPE ):
81
76
""" Delete the object from the project data store """
82
77
83
78
# Delete if object found and not pending insert
84
79
if self .id and self .type == "update" :
85
80
# Delete from project data store
86
- app .updates .delete (self .key )
81
+ get_app () .updates .delete (self .key )
87
82
self .type = "delete"
88
83
89
84
def title (self ):
@@ -95,7 +90,7 @@ def filter(OBJECT_TYPE, **kwargs):
95
90
""" Take any arguments given as filters, and find a list of matching objects """
96
91
97
92
# Get a list of all objects of this type
98
- parent = project .get (OBJECT_TYPE .object_key )
93
+ parent = get_app (). project .get (OBJECT_TYPE .object_key )
99
94
100
95
if not parent :
101
96
return []
@@ -242,30 +237,25 @@ def get(**kwargs):
242
237
def absolute_path (self ):
243
238
""" Get absolute file path of file """
244
239
245
- # Get project folder (if any)
246
- project_folder = None
247
- if project .current_filepath :
248
- project_folder = os .path .dirname (project .current_filepath )
249
-
250
- # Convert relative file path into absolute (if needed)
251
240
file_path = self .data ["path" ]
252
- if not os .path .isabs (file_path ) and project_folder :
253
- file_path = os .path .abspath (os .path .join (project_folder , self .data ["path" ]))
241
+ if os .path .isabs (file_path ):
242
+ return file_path
243
+
244
+ # Try to expand path relative to project folder
245
+ app = get_app ()
246
+ if (app and hasattr ("project" , app )
247
+ and hasattr ("current_filepath" , app .project )):
248
+ project_folder = os .path .dirname (app .project .current_filepath )
249
+ file_path = os .path .abspath (os .path .join (project_folder , file_path ))
254
250
255
- # Return absolute path of file
256
251
return file_path
257
252
258
253
def relative_path (self ):
259
254
""" Get relative path (based on the current working directory) """
260
255
261
- # Get absolute file path
262
256
file_path = self .absolute_path ()
263
-
264
257
# Convert path to relative (based on current working directory of Python)
265
- file_path = os .path .relpath (file_path , info .CWD )
266
-
267
- # Return relative path
268
- return file_path
258
+ return os .path .relpath (file_path , info .CWD )
269
259
270
260
271
261
class Marker (QueryObject ):
@@ -317,6 +307,7 @@ def __lt__(self, other):
317
307
def __gt__ (self , other ):
318
308
return self .data .get ('number' , 0 ) > other .data .get ('number' , 0 )
319
309
310
+
320
311
class Effect (QueryObject ):
321
312
""" This class allows Effects to be queried, updated, and deleted from the project data. """
322
313
object_name = "effects" # Derived classes should define this
@@ -334,7 +325,7 @@ def filter(**kwargs):
334
325
""" Take any arguments given as filters, and find a list of matching objects """
335
326
336
327
# Get a list of clips
337
- clips = project .get ("clips" )
328
+ clips = get_app (). project .get ("clips" )
338
329
matching_objects = []
339
330
340
331
# Loop through all clips
0 commit comments