12
12
import saveUtils
13
13
import listerFuncs
14
14
15
+ # derivative modules
16
+
15
17
16
18
class ExternalFiles :
17
19
"""
18
- The ExternalFiles class is used to handle working with both
19
- externalizing files, as well as ingesting files that were previously
20
- externalized. This helps to minimize the amount of manual work that
21
- might need to otherwise be use for handling external files.
20
+ The ExternalFiles class is used to handle working with both
21
+ externalizing files, as well as ingesting files that were previously
22
+ externalized. This helps to minimize the amount of manual work that
23
+ might need to otherwise be use for handling external files.
22
24
"""
23
25
FLASH_DURATION = 14
24
26
UNLOCK_TAGS = [
25
27
"unlockOnSave"
26
28
]
27
29
28
30
def __init__ (self , my_op : callable ) -> None :
29
- """Stands in place of an execute dat - ensures all elements start-up
31
+ """Stands in place of an execute dat - ensures all elements start-up
30
32
correctly
31
33
32
34
Notes
@@ -39,7 +41,7 @@ def __init__(self, my_op: callable) -> None:
39
41
40
42
Returns
41
43
---------
42
- none
44
+ none
43
45
"""
44
46
45
47
self .my_op = my_op
@@ -49,6 +51,7 @@ def __init__(self, my_op: callable) -> None:
49
51
0.5450000166893005 ,
50
52
0.5450000166893005 )
51
53
self .Ext_ops_DAT = my_op .op ('script_external_ops' )
54
+ self .popDialog = my_op .op ('popDialog' )
52
55
53
56
self ._ops_manager = saveOp .SaveOpManager (self .Ext_ops_DAT )
54
57
@@ -173,28 +176,25 @@ def Prompt_to_save(self) -> None:
173
176
Args
174
177
---------
175
178
current_loc (str):
176
- > the operator that's related to the currently focused
179
+ > the operator that's related to the currently focused
177
180
> pane object. This is required to ensure that we correctly
178
181
> grab the appropriate COMP and check to see if needs to be saved
179
182
180
183
Returns
181
184
---------
182
- none
185
+ none
183
186
"""
184
187
current_loc = self .get_current_location
185
188
186
189
external_op_color = self .Colors_map .get (
187
190
"TouchDesigner" ).get ("external_op" ).get ("color" )
188
191
msg_box_title = "TOX Save"
189
192
msg_box_msg = "Replacing External\n \n You are about to overwrite an external TOX"
190
- msg_box_buttons = ["Cancel" , "Continue " ]
193
+ msg_box_buttons = ["Cancel" , "Save " ]
191
194
192
195
sav_msg_box_title = "Externalize Tox"
193
- sav_msg_box_msg = "This TOX is not yet externalized\n \n Would you like to externalize this TOX?"
194
- sav_msg_box_buttons = ["No" , "Yes" ]
195
-
196
- save_msg_buttons_parent_too = [
197
- "No" , "This COMP Only" , "This COMP and the Parent" ]
196
+ sav_msg_box_msg = "This TOX is not yet externalized.\n \n Would you like to externalize this TOX?\n \n Dir - save TOX with a directory\n Solo - save only TOX"
197
+ sav_msg_box_buttons = ["Cancel" , "Dir" , "Solo" ]
198
198
199
199
# check if location is the root of the project
200
200
if current_loc == '/' :
@@ -206,61 +206,90 @@ def Prompt_to_save(self) -> None:
206
206
207
207
# check if external
208
208
if current_loc .par .externaltox != '' :
209
- confirmation = ui .messageBox (
210
- msg_box_title , msg_box_msg ,
211
- buttons = msg_box_buttons )
212
209
213
- if confirmation :
210
+ def dialog_choice (info ):
211
+ choice = info .get ('buttonNum' )
212
+ current_loc = info .get ('details' ).get ('current_loc' )
214
213
215
- # save external file
216
- self .Save_over_tox (current_loc )
214
+ match choice :
217
215
218
- else :
219
- # if the user presses "cancel" we pass
220
- pass
216
+ case 2 :
217
+ self .Save_over_tox (current_loc )
218
+ case 1 :
219
+ pass
220
+ case _:
221
+ pass
222
+
223
+ self .popDialog .Open (
224
+ title = msg_box_title ,
225
+ text = msg_box_msg ,
226
+ buttons = msg_box_buttons ,
227
+ escButton = 1 ,
228
+ details = {'current_loc' : current_loc },
229
+ callback = dialog_choice ,
230
+ textEntry = False )
221
231
222
232
# in this case we are not external, so let's ask if we want to
223
233
# externalize the file
224
234
else :
225
235
226
236
# check if the parent is externalized
227
237
if current_loc .parent ().par .externaltox != '' :
228
- save_ext = ui .messageBox (
229
- sav_msg_box_title ,
230
- sav_msg_box_msg ,
231
- buttons = save_msg_buttons_parent_too )
232
-
233
- # save this comp only
234
- if save_ext == 1 :
235
- self .Save_tox (current_loc )
236
-
237
- # save this comp and the parent
238
- elif save_ext == 2 :
239
- self .Save_tox (current_loc )
240
- self .Logtotextport ("save this tox" )
241
-
242
- # save parent() COMP
243
- self .Save_over_tox (current_loc .parent ())
244
- self .Logtotextport ("Save the parent too!" )
245
-
246
- # user selected 'No' or 'X' button
247
- else :
248
- pass
238
+ def dialog_choice (info ):
239
+ choice = info .get ('buttonNum' )
240
+ current_loc = info .get ('details' ).get ('current_loc' )
241
+
242
+ match choice :
243
+ case 3 :
244
+ # save COMP
245
+ self .Save_tox (current_loc , include_dir = False )
246
+ # save parent() COMP
247
+ self .Save_over_tox (current_loc .parent ())
248
+ case 2 :
249
+ # save COMP
250
+ self .Save_tox (current_loc )
251
+ # save parent() COMP
252
+ self .Save_over_tox (current_loc .parent ())
253
+ case 1 :
254
+ pass
255
+ case _:
256
+ pass
257
+
258
+ self .popDialog .Open (
259
+ title = sav_msg_box_title ,
260
+ text = sav_msg_box_msg ,
261
+ buttons = sav_msg_box_buttons ,
262
+ escButton = 1 ,
263
+ details = {'current_loc' : current_loc },
264
+ callback = dialog_choice ,
265
+ textEntry = False )
249
266
250
267
# the parent is not external, so let's ask about externalizing
251
268
# the tox
252
269
else :
253
- save_ext = ui .messageBox (
254
- sav_msg_box_title ,
255
- sav_msg_box_msg ,
256
- buttons = sav_msg_box_buttons )
257
-
258
- if save_ext == 1 :
259
- self .Save_tox (current_loc )
260
-
261
- else :
262
- # the user selected "No" or 'X' button
263
- pass
270
+
271
+ def dialog_choice (info ):
272
+ choice = info .get ('buttonNum' )
273
+ current_loc = info .get ('details' ).get ('current_loc' )
274
+
275
+ match choice :
276
+ case 3 :
277
+ self .Save_tox (current_loc , include_dir = False )
278
+ case 2 :
279
+ self .Save_tox (current_loc )
280
+ case 1 :
281
+ pass
282
+ case _:
283
+ pass
284
+
285
+ self .popDialog .Open (
286
+ title = sav_msg_box_title ,
287
+ text = sav_msg_box_msg ,
288
+ buttons = sav_msg_box_buttons ,
289
+ details = {'current_loc' : current_loc },
290
+ escButton = 1 ,
291
+ callback = dialog_choice ,
292
+ textEntry = False )
264
293
265
294
return
266
295
@@ -278,69 +307,74 @@ def Save_over_tox(self, current_loc, specify_version: str = ''):
278
307
self ._save_tox (current_loc )
279
308
return
280
309
281
- def Save_tox (self , current_loc ):
310
+ def Save_tox (self , current_loc , include_dir : bool = True ):
311
+ # get the external op color
282
312
ext_color = self .Colors_map .get (
283
313
"TouchDesigner" ).get ("external_op" ).get ("color" )
284
314
285
315
# ask user for a save location
286
316
save_loc = ui .chooseFolder (title = "TOX Location" , start = project .folder )
287
317
288
- # construct a relative path and relative loaction for our elements
318
+ # construct a relative path and relative location for our elements
289
319
rel_path = tdu .collapsePath (save_loc )
290
320
291
- # check to see if the location is at the root of the project folder structure
292
- if rel_path == "$TOUCH" :
293
- rel_loc = '{new_tox}/{new_tox}.tox' .format (
294
- new_tox = current_loc .name )
321
+ # build paths that include a directory
322
+ if include_dir :
323
+ # check to see if the location is at the root of the project folder structure
324
+ if rel_path == "$TOUCH" :
325
+ # build a save location that includes a directory with the same name as the COMP
326
+ rel_loc = f'{ current_loc .name } /{ current_loc .name } .tox'
295
327
296
- # save path is not in the root of the project
297
- else :
298
- rel_loc = '{new_module}/{new_tox}/{new_tox}.tox' . format (
299
- new_module = rel_path , new_tox = current_loc .name )
328
+ # save path is not in the root of the project
329
+ else :
330
+ # build a save location that includes a directory with the same name as the COMP
331
+ rel_loc = f' { rel_path } / { current_loc .name } / { current_loc . name } .tox'
300
332
301
- # create path and directory in the OS
302
- new_path = '{selected_path}/{new_module}' .format (
303
- selected_path = save_loc , new_module = current_loc .name )
333
+ # create path and directory in the OS
334
+ new_path = f'{ save_loc } /{ current_loc .name } '
304
335
305
- try :
306
- os .mkdir (new_path )
307
- valid_external_path = True
308
- except :
309
- self .alert_failed_dir_creation (
310
- new_path = new_path , current_loc = current_loc )
311
- valid_external_path = False
312
-
313
- if valid_external_path :
314
- # format our tox path
315
- tox_path = '{dir_path}/{tox}.tox' .format (
316
- dir_path = new_path , tox = current_loc .name )
336
+ # build paths that do not include a directory
337
+ else :
338
+ # check to see if the location is at the root of the project folder structure
339
+ if rel_path == "$TOUCH" :
340
+ # build a save location that includes a directory with the same name as the COMP
341
+ rel_loc = f'{ current_loc .name } .tox'
317
342
318
- # setup our module correctly
319
- current_loc .par .externaltox = '' if current_loc .par ['Sudotool' ] else rel_loc
320
- current_loc .par .savebackup = False
343
+ # save path is not in the root of the project
344
+ else :
345
+ # build a save location that includes a directory with the same name as the COMP
346
+ rel_loc = f'{ rel_path } /{ current_loc .name } .tox'
321
347
322
- # set color for COMP
323
- current_loc .color = self .op_none_color if current_loc .par ['Sudotool' ] else (
324
- ext_color [0 ], ext_color [1 ], ext_color [2 ])
348
+ # create path and directory in the OS
349
+ new_path = f'{ save_loc } /{ current_loc .name } '
325
350
326
- # setup about page - allow user to supress about page at creation
327
- if self .my_op .par .Includeaboutpage :
328
- self .custom_page_setup (current_loc )
329
- else :
330
- pass
351
+ # format our tox path
352
+ tox_path = f'{ new_path } /{ current_loc .name } .tox'
331
353
332
- # private save method
333
- self ._save_tox (current_loc )
354
+ # setup our module correctly
355
+ current_loc .par .enableexternaltox = True
356
+ current_loc .par .externaltox = '' if current_loc .par ['Sudotool' ] else rel_loc
357
+ current_loc .par .savebackup = False
334
358
335
- # track new SaveOp
336
- self ._ops_manager .Check_external_ops ()
359
+ # set color for COMP
360
+ current_loc .color = self .op_none_color if current_loc .par ['Sudotool' ] else (
361
+ ext_color [0 ], ext_color [1 ], ext_color [2 ])
337
362
363
+ # setup about page - allow user to supress about page at creation
364
+ if self .my_op .par .Includeaboutpage :
365
+ self .custom_page_setup (current_loc )
338
366
else :
339
367
pass
340
368
369
+ # private save method
370
+ self ._save_tox (current_loc )
371
+
372
+ # track new SaveOp
373
+ self ._ops_manager .Check_external_ops ()
374
+
341
375
return
342
376
343
- def _save_tox (self , current_loc : str ) -> None :
377
+ def _save_tox (self , current_loc ) -> None :
344
378
ext_color = self .Colors_map .get (
345
379
"TouchDesigner" ).get ("external_op" ).get ("color" )
346
380
external_path = current_loc .par .externaltox
@@ -349,7 +383,7 @@ def _save_tox(self, current_loc: str) -> None:
349
383
self .preToxSave (current_loc )
350
384
351
385
# save tox
352
- current_loc .save (external_path )
386
+ current_loc .save (external_path , createFolders = True )
353
387
354
388
# Run post-save event
355
389
self .postToxSave (current_loc )
0 commit comments