Skip to content

Commit a8ba356

Browse files
committed
Behavior Updates
Allows for saving in a Dir Allows for saving as single TOX Fixes up about behavior
1 parent a56c271 commit a8ba356

File tree

5 files changed

+131
-97
lines changed

5 files changed

+131
-97
lines changed

TouchDesigner/project.toe

11 KB
Binary file not shown.
414 Bytes
Binary file not shown.
398 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

TouchDesigner/td-python/saveTox.py

Lines changed: 131 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@
1212
import saveUtils
1313
import listerFuncs
1414

15+
# derivative modules
16+
1517

1618
class ExternalFiles:
1719
"""
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.
2224
"""
2325
FLASH_DURATION = 14
2426
UNLOCK_TAGS = [
2527
"unlockOnSave"
2628
]
2729

2830
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
3032
correctly
3133
3234
Notes
@@ -39,7 +41,7 @@ def __init__(self, my_op: callable) -> None:
3941
4042
Returns
4143
---------
42-
none
44+
none
4345
"""
4446

4547
self.my_op = my_op
@@ -49,6 +51,7 @@ def __init__(self, my_op: callable) -> None:
4951
0.5450000166893005,
5052
0.5450000166893005)
5153
self.Ext_ops_DAT = my_op.op('script_external_ops')
54+
self.popDialog = my_op.op('popDialog')
5255

5356
self._ops_manager = saveOp.SaveOpManager(self.Ext_ops_DAT)
5457

@@ -173,28 +176,25 @@ def Prompt_to_save(self) -> None:
173176
Args
174177
---------
175178
current_loc (str):
176-
> the operator that's related to the currently focused
179+
> the operator that's related to the currently focused
177180
> pane object. This is required to ensure that we correctly
178181
> grab the appropriate COMP and check to see if needs to be saved
179182
180183
Returns
181184
---------
182-
none
185+
none
183186
"""
184187
current_loc = self.get_current_location
185188

186189
external_op_color = self.Colors_map.get(
187190
"TouchDesigner").get("external_op").get("color")
188191
msg_box_title = "TOX Save"
189192
msg_box_msg = "Replacing External\n\nYou are about to overwrite an external TOX"
190-
msg_box_buttons = ["Cancel", "Continue"]
193+
msg_box_buttons = ["Cancel", "Save"]
191194

192195
sav_msg_box_title = "Externalize Tox"
193-
sav_msg_box_msg = "This TOX is not yet externalized\n\nWould 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\nWould you like to externalize this TOX?\n\nDir - save TOX with a directory\nSolo - save only TOX"
197+
sav_msg_box_buttons = ["Cancel", "Dir", "Solo"]
198198

199199
# check if location is the root of the project
200200
if current_loc == '/':
@@ -206,61 +206,90 @@ def Prompt_to_save(self) -> None:
206206

207207
# check if external
208208
if current_loc.par.externaltox != '':
209-
confirmation = ui.messageBox(
210-
msg_box_title, msg_box_msg,
211-
buttons=msg_box_buttons)
212209

213-
if confirmation:
210+
def dialog_choice(info):
211+
choice = info.get('buttonNum')
212+
current_loc = info.get('details').get('current_loc')
214213

215-
# save external file
216-
self.Save_over_tox(current_loc)
214+
match choice:
217215

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)
221231

222232
# in this case we are not external, so let's ask if we want to
223233
# externalize the file
224234
else:
225235

226236
# check if the parent is externalized
227237
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)
249266

250267
# the parent is not external, so let's ask about externalizing
251268
# the tox
252269
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)
264293

265294
return
266295

@@ -278,69 +307,74 @@ def Save_over_tox(self, current_loc, specify_version: str = ''):
278307
self._save_tox(current_loc)
279308
return
280309

281-
def Save_tox(self, current_loc):
310+
def Save_tox(self, current_loc, include_dir: bool = True):
311+
# get the external op color
282312
ext_color = self.Colors_map.get(
283313
"TouchDesigner").get("external_op").get("color")
284314

285315
# ask user for a save location
286316
save_loc = ui.chooseFolder(title="TOX Location", start=project.folder)
287317

288-
# construct a relative path and relative loaction for our elements
318+
# construct a relative path and relative location for our elements
289319
rel_path = tdu.collapsePath(save_loc)
290320

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'
295327

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'
300332

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}'
304335

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'
317342

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'
321347

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}'
325350

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'
331353

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
334358

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])
337362

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)
338366
else:
339367
pass
340368

369+
# private save method
370+
self._save_tox(current_loc)
371+
372+
# track new SaveOp
373+
self._ops_manager.Check_external_ops()
374+
341375
return
342376

343-
def _save_tox(self, current_loc: str) -> None:
377+
def _save_tox(self, current_loc) -> None:
344378
ext_color = self.Colors_map.get(
345379
"TouchDesigner").get("external_op").get("color")
346380
external_path = current_loc.par.externaltox
@@ -349,7 +383,7 @@ def _save_tox(self, current_loc: str) -> None:
349383
self.preToxSave(current_loc)
350384

351385
# save tox
352-
current_loc.save(external_path)
386+
current_loc.save(external_path, createFolders=True)
353387

354388
# Run post-save event
355389
self.postToxSave(current_loc)

0 commit comments

Comments
 (0)