-
Notifications
You must be signed in to change notification settings - Fork 2
/
old_JSE.py
1711 lines (1323 loc) · 75.2 KB
/
old_JSE.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import maya.cmds as c
from re import match
from maya.mel import eval as melEval
from copy import deepcopy
import logging
logger = logging.getLogger("JSE")
'''
=== TERMINOLOGY GUIDE ===
Input = The pane section with the tabs and command line
Output = The pane section with the output console
'''
currentInputTabType = [] # List of tabs' languages
currentInputTabLabels = [] # List of tabs' label/name
currentInputTabFiles = [] # List of tabs' associated file location
currentInputTabs = [] # List of cmdScrollFieldExecuters, will be in order of the tabs (left to right I presume)
currentInputTabLayouts = [] # List of all tab layout in the various input pane sections
currentPaneScematic = ["V50","I1","O"] # e.g. ["V50","V30","O","V10","I1","I2","H50","I3","O"]
currentAllSchematic = [] # e.g. [ ["V50", "window4|paneLayout19|paneLayout20",
# "O" , "window4|paneLayout19|paneLayout20|cmdScrollFieldReporter8"],
# "I1" , "window4|paneLayout19|paneLayout20|formLayout123"],
# ["V31", "window5|paneLayout21|paneLayout22",
# "O" , "window5|paneLayout21|paneLayout22|cmdScrollFieldReporter10"],
# "I3" , "window5|paneLayout21|paneLayout22|formLayout343"]
# ]
engaged = False # If True, JSE had ran in this instance of Maya
InputBuffersPath = ""
OutputSnapshotsPath = ""
''' Global Input/Output Settings:
--- Executer ---
commandCompletion
showLineNumbers
objectPathCompletion
showTooltipHelp
--- Reporter ---
'''
# Procedure to save up retyping the same debug text formatting
def defStart(text): return "{:\\<80}".format(str(text)+" ")
def defEnd(text): return "{:/>80}".format(" "+str(text))
def head1(text): return "{:=^80}".format(" "+str(text)+" ")
def head2(text): return "{:-^80}".format(" "+str(text)+" ")
def var1(inText,inVar): return "{:>30} -- {!s}".format(str(inText) , str(inVar) )
def var2(inText,inVar): return "{:>31} - {!s}".format("("+str(inText)+")" , str(inVar) )
################################################ PaneRelated ################################################
def navigateToParentPaneLayout(paneSection):
"""
------------Internal useage------------
Find the paneLayout above the current control/layout.
This is done through assigning and reassigning the parent
and child, shuffling up the levels of parents until the
a paneLayout is identified
paneSection : child right underneath the paneLayout that the
(returned) input/output section belong to.
The returned value can be different to the parameter
value that was passed in
parentPaneLayout : paneLayout that is the parent of the pane that
(returned) called the split, initially initialised to paneSection
in order to start the parent traversal algorithm
"""
logger.debug(defStart("Navigating to parent paneLayout"))
logger.debug(var1("paneSection",paneSection))
try: parentPaneLayout = c.control(paneSection, query=True, parent=True)
except: parentPaneLayout = c.layout(paneSection, query=True, parent=True)
logger.debug(var1( "parentPaneLayout",parentPaneLayout))
logger.debug(head1("Traversing to get parent paneLayout"))
while not( c.paneLayout( parentPaneLayout, query=True, exists=True) ):
paneSection = parentPaneLayout
logger.debug(var1( "parentPaneLayout",parentPaneLayout))
logger.debug(var1( "paneSection becomes",paneSection))
parentPaneLayout = c.control(parentPaneLayout, query=True, parent=True)
logger.debug(var1("parentPaneLayout becomes",parentPaneLayout))
logger.debug(head2("After traversal debug"))
logger.debug(var1( "parent paneLayout is",parentPaneLayout ) )
logger.debug(var1( "child is (paneSection)",paneSection))
logger.debug(var1( "(exist?)",c.control(paneSection,q=1,ex=1)) )
logger.debug(defEnd("Navigated to parent paneLayout"))
return paneSection,parentPaneLayout
def constructJSE( paneSection, buildSchematic ):
"""
Procedure to split the current pane into 2 panes, or set up the default
script editor panels if this is the first time it is run
buildSchematic, ---Need to write description for it---
"""
global currentInputTabLayouts
global currentAllSchematic
def constructSplits(paneCfgTxt, paneEditSize, buildSchematic=buildSchematic):
newPaneLayout = c.paneLayout(configuration=paneCfgTxt,parent=paneSection,
separatorMovedCommand="JSE.refreshAllScematic()")
currentAllSchematic[-1].append(newPaneLayout)
logger.debug(var1("currentAllSchematic[-1]",currentAllSchematic[-1]) )
logger.debug( var1("buildSchematic[0]",buildSchematic[0]))
if (buildSchematic[0][0]=="V") or (buildSchematic[0][0]=="H"):
paneChild1,buildSchematic = constructJSE( newPaneLayout, buildSchematic)
logger.debug(var1("buildSchematic becomes",buildSchematic))
logger.debug(var1("paneChild1",paneChild1))
elif buildSchematic[0][0]=="I":
currentAllSchematic[-1].append(buildSchematic[0])
paneChild1 = createInput(newPaneLayout, int(buildSchematic.pop(0)[1:]))
logger.debug(var1("buildSchematic becomes",buildSchematic))
currentAllSchematic[-1].append(paneChild1)
logger.debug(var1("currentAllSchematic[-1]",currentAllSchematic[-1]) )
elif buildSchematic[0][0]=="O":
currentAllSchematic[-1].append( buildSchematic.pop(0) )
paneChild1 = createOutput(newPaneLayout)
logger.debug(var1("buildSchematic becomes",buildSchematic))
currentAllSchematic[-1].append(paneChild1)
logger.debug(var1("currentAllSchematic[-1]",currentAllSchematic[-1]) )
logger.debug( var1("buildSchematic[0]",buildSchematic[0]))
if (buildSchematic[0][0]=="V") or (buildSchematic[0][0]=="H"):
paneChild2,buildSchematic = constructJSE( newPaneLayout, buildSchematic)
logger.debug(var1("buildSchematic becomes",buildSchematic))
logger.debug(var1("paneChild2",paneChild2))
elif buildSchematic[0][0]=="I":
currentAllSchematic[-1].append(buildSchematic[0])
paneChild2 = createInput(newPaneLayout, int(buildSchematic.pop(0)[1:]))
logger.debug(var1("buildSchematic becomes",buildSchematic))
currentAllSchematic[-1].append(paneChild2)
logger.debug(var1("currentAllSchematic[-1]",currentAllSchematic[-1]) )
elif buildSchematic[0][0]=="O":
currentAllSchematic[-1].append( buildSchematic.pop(0) )
paneChild2 = createOutput(newPaneLayout)
logger.debug(var1("buildSchematic becomes",buildSchematic))
currentAllSchematic[-1].append(paneChild2)
logger.debug(var1("currentAllSchematic[-1]",currentAllSchematic[-1]) )
logger.debug(var1("newPaneLayout",newPaneLayout) )
c.paneLayout(newPaneLayout, edit=True,
paneSize=paneEditSize,
setPane=[ (paneChild1 , 1),
(paneChild2 , 2) ] )
logger.debug(defEnd("Constructed current split"))
logger.debug("")
return newPaneLayout,buildSchematic
logger.debug(defStart("Constructing"))
logger.debug(var1("paneSection",paneSection) )
logger.debug(var1("buildSchematic",buildSchematic) )
'''
If just initialising --- Create new vertical 2 pane layout
--- Create output and input pane and assign
it to the new pane layout
--- Return the pane layout so formLayout can
snap it to the window's edges
'''
logger.debug(head2("Popping out the first element"))
paneCfg = buildSchematic.pop(0)
logger.debug(var1("buildSchematic (popped)",buildSchematic) )
logger.debug(var1("paneCfg",paneCfg) )
currentAllSchematic[-1].append(paneCfg)
logger.debug(var1("currentAllSchematic[-1]",currentAllSchematic[-1]) )
if paneCfg.startswith("V") :
newPaneLayout,buildSchematic = constructSplits( "vertical2", [1, int(paneCfg[1:]), 100] )
logger.debug(defEnd("Constructed"))
logger.debug("")
return newPaneLayout, buildSchematic
elif paneCfg.startswith("H") :
newPaneLayout,buildSchematic = constructSplits( "horizontal2", [1, 100, int(paneCfg[1:])] )
logger.debug(defEnd("Constructed"))
logger.debug("")
return newPaneLayout, buildSchematic
elif paneCfg.startswith("O") :
newPane = createOutput(paneSection)
currentAllSchematic[-1].append(newPane)
c.paneLayout(paneSection, edit=True, setPane=[ ( newPane, 1)] )
logger.debug(defEnd("Constructed"))
logger.debug("")
return paneSection, buildSchematic
elif paneCfg.startswith("I") :
newPane = createInput(createInput)
currentAllSchematic[-1].append(newPane)
c.paneLayout(paneSection, edit=True, setPane=[ ( newPane , 1)] )
logger.debug(defEnd("Constructed"))
logger.debug("")
return paneSection, buildSchematic
def split( paneSection, re_assign_position, newPaneIsInput):
"""
Procedure to split the current pane into 2 panes, or set up the default
script editor panels if this is the first time it is run
re_assign_position, New pane position for existing pane, which will then be
used to figure out the pane number for setPane flag and
horizontal/vertical for configuration flag for c.paneLayout()
"""
global currentInputTabLayouts
global currentAllSchematic
logger.debug(defStart("Splitting"))
logger.debug(var1("paneSection",paneSection) )
logger.debug(var1("re_assign_position",re_assign_position) )
''' --- FIRST ---
Find the paneLayout above the current control/layout.
This is done through assigning and reassigning the parent
and child, shuffling up the levels of parents until the
a paneLayout is identified
paneSection : child right underneath the paneLayout that the
input/output section belong to
parentPaneLayout : paneLayout that is the parent of the pane that
called the split, initially initialised to paneSection
in order to start the parent traversal algorithm
'''
paneSection,parentPaneLayout = navigateToParentPaneLayout(paneSection)
paneSectionShortName = paneSection.rsplit("|",1)[-1]
logger.debug(var1( "(shortName)",paneSectionShortName ) )
parentPaneLayoutChildArray = c.paneLayout( parentPaneLayout, query=True, ca=True)
logger.debug(var1("parentPaneLayout children",parentPaneLayoutChildArray ))
logger.debug(var1( "child index number",parentPaneLayoutChildArray.index(paneSectionShortName) ))
window_IndicesInSchematic = ""
pane_IndicesInSchematic = ""
try: paneSection = c.control(paneSectionShortName, q=1, fullPathName=1)
except: paneSection = c.layout( paneSectionShortName, q=1, fullPathName=1)
for i in xrange(len(currentAllSchematic)):
for j in xrange(0, len(currentAllSchematic[i]), 2):
if currentAllSchematic[i][j+1] == paneSection:
window_IndicesInSchematic = i
pane_IndicesInSchematic = j
break
if pane_IndicesInSchematic: break
newSchematicStart = currentAllSchematic[window_IndicesInSchematic][:pane_IndicesInSchematic]
logger.debug(var1("newSchematicStart",newSchematicStart))
newSchematicEnding = currentAllSchematic[window_IndicesInSchematic][pane_IndicesInSchematic+2:]
logger.debug(var1("newSchematicEnding",newSchematicEnding))
''' --- SECOND ---
Figure out which index of the pane that called split is in.
This is done by retrieving the child array, where it's index is in the
same order as the pane index, and then finding the index of the element
that matches the paneSection's short name (that is, not including the
full path)
paneSectionShortName : name of the control/layout immediately under the
parentPaneLayout that the split was called from
(dis-includes the full object path)
paneSectionNumber : pane index is the index of the child element + 1
'''
# paneSectionShortName = paneSection.rsplit("|",1)[-1] # strip the short name from the full name
paneSectionNumber = c.paneLayout( parentPaneLayout, query=True, ca=True).index(paneSectionShortName)+1
''' --- FINALLY ---
Setup values for new paneLayout setup and assingment of new/existing panes
to the newly created paneLayout depending on direction.
paneConfig : paneLayout flag value for the configuration flag,
how the pane layout is split basically
newPaneLayout : name of the new pane layout created using the
specified configuration
newSectionPaneIndex : Pane number for the new section to be created
in the new paneLayout
oldSectionPaneIndex : Pane number for the previously existing section
that was "split" in this new paneLayout
'''
if re_assign_position == "top":
paneConfig = 'horizontal2'
newSectionPaneIndex = 1
oldSectionPaneIndex = 2
elif re_assign_position == "bottom":
paneConfig = 'horizontal2'
newSectionPaneIndex = 2
oldSectionPaneIndex = 1
elif re_assign_position == "left":
paneConfig = 'vertical2'
newSectionPaneIndex = 1
oldSectionPaneIndex = 2
elif re_assign_position == "right":
paneConfig = 'vertical2'
newSectionPaneIndex = 2
oldSectionPaneIndex = 1
else:
logger.critical("re_assign_position not matched with top, bottom, left or right!")
logger.critical(var1("re_assign_position",re_assign_position))
logger.debug(var1( "paneConfig",paneConfig ))
logger.debug(var1("newSectionPaneIndex",newSectionPaneIndex ))
logger.debug(var1("oldSectionPaneIndex",oldSectionPaneIndex ))
logger.debug(head2("Setting values for new paneLayouts" ) )
newPaneLayout = c.paneLayout(configuration=paneConfig, parent=parentPaneLayout,
separatorMovedCommand="JSE.refreshAllScematic()")
logger.debug(var1("parentPaneLayout",parentPaneLayout ))
logger.debug(var1( "paneSection",paneSection ))
logger.debug(var1( "newPaneLayout",newPaneLayout ))
logger.debug(var1( "(exist?)",c.paneLayout(newPaneLayout, q=1,ex=1) ) )
c.paneLayout(parentPaneLayout, edit=True,
setPane=[( newPaneLayout, paneSectionNumber )] )
logger.debug(head2("Assigning new split to current pane" ) )
c.control(paneSection, edit=True, parent=newPaneLayout)
if newPaneIsInput: newPane = createInput( newPaneLayout )
else: newPane = createOutput( newPaneLayout )
c.paneLayout(newPaneLayout, edit=True,
setPane=[ ( newPane , newSectionPaneIndex),
( paneSection , oldSectionPaneIndex) ] )
newPaneSchematic = [ paneConfig[0].capitalize()+"50", newPaneLayout ]
logger.debug(var1("newPaneSchematic",newPaneSchematic))
newSchematic = deepcopy(newSchematicStart)
logger.debug(var1("newSchematic",newSchematic))
newSchematic.extend( deepcopy(newPaneSchematic) )
logger.debug(var1("newSchematic",newSchematic))
if newPaneIsInput: newSectionSchematic = "I1"
else: newSectionSchematic = "O"
if oldSectionPaneIndex > newSectionPaneIndex:
newSchematic.extend( deepcopy([newSectionSchematic, newPane]) )
newSchematic.extend( deepcopy(currentAllSchematic[window_IndicesInSchematic][pane_IndicesInSchematic:pane_IndicesInSchematic+2]) )
else:
newSchematic.extend( deepcopy(currentAllSchematic[window_IndicesInSchematic][pane_IndicesInSchematic:pane_IndicesInSchematic+2] ))
newSchematic.extend( deepcopy([newSectionSchematic, newPane] ))
logger.debug(var1("newSchematic",newSchematic))
newSchematic.extend( deepcopy(newSchematicEnding) )
logger.debug(var1("newSchematic",newSchematic))
currentAllSchematic[window_IndicesInSchematic] = deepcopy(newSchematic)
refreshAllScematic()
logger.debug(defEnd("Splitted"))
logger.debug("")
def deletePane(paneSection):
global currentAllSchematic
'''
This procedure removes the pane specified in the parameter, effectively
re-merging the other pane in the shared pane layout to the pane layout
above it. The following is a rough outline of what happens
1 --- Find Parent Layout
2 --- Find other secion's name and number, this will be kept
3 --- Find grand parent layout
4 --- Find section number of parent layout under grand parent layout
5 --- Re-parent other section --> grand parent layout, same section number as parent layout
6 --- Delete parent layout, which also deletes the current section (parent layout's child)
'''
logger.debug(defStart("Deleting Pane"))
logger.debug(var1("paneSection",paneSection))
logger.debug(var1("currentAllSchematic",currentAllSchematic))
''' --- FIRST ---
Find the paneLayout above the current control/layout.
This is done through assigning and reassigning the parent
and child, shuffling up the levels of parents until the
a paneLayout is identified
paneSection : child right underneath the paneLayout that the
input/output section belong to
parentPaneLayout : paneLayout that is the parent of the pane that
called the split, initially initialised to paneSection
in order to start the parent traversal algorithm
'''
paneSection,parentPaneLayout = navigateToParentPaneLayout(paneSection)
''' --- SECOND ---
Figure out which indices the various children of the different pane layouts
are, as well as the grand parent layout. Can't forget about the grannies
'''
logger.debug(var1( "paneSection",paneSection))
logger.debug(var1( "parentPaneLayout",parentPaneLayout))
parentPaneLayoutChildren = c.paneLayout( parentPaneLayout, query=True, childArray=True)
logger.debug(var1( "parentPaneLayoutChildren",parentPaneLayoutChildren))
grandParentPaneLayout = c.paneLayout( parentPaneLayout, query=True, parent=True)
logger.debug(var1( "grandParentPaneLayout",grandParentPaneLayout))
logger.debug(var1( "objectTypeUI",c.objectTypeUI(grandParentPaneLayout)))
if "indow" in c.objectTypeUI(grandParentPaneLayout):
c.deleteUI(grandParentPaneLayout)
logger.debug(head2("Grand Parent is a window, closing window") )
logger.debug(defEnd("Deleted Pane") )
logger.debug("")
return
grandParentPaneLayoutChildren = c.paneLayout( grandParentPaneLayout, query=True, childArray=True)
logger.debug(var1("grandParentPaneLayoutChildren",grandParentPaneLayoutChildren))
paneSectionShortName = paneSection.rsplit("|",1)[-1] # strip the short name from the full name
logger.debug(var1( "paneSectionShortName",paneSectionShortName))
parentPaneLayoutShortName = parentPaneLayout.rsplit("|",1)[-1] # strip the short name from the full name
logger.debug(var1( "parentPaneLayoutShortName",parentPaneLayoutShortName))
parentPaneLayoutSectionNumber = grandParentPaneLayoutChildren.index(parentPaneLayoutShortName)+1
logger.debug(var1("parentPaneLayoutSectionNumber",parentPaneLayoutSectionNumber))
otherPaneChildNum = ( parentPaneLayoutChildren.index(paneSectionShortName)+1 ) % 2
logger.debug(var1( "otherPaneChildNum",otherPaneChildNum))
otherParentPaneSectionNum = (parentPaneLayoutSectionNumber % 2) + 1
logger.debug(var1( "otherParentPaneSectionNum",otherParentPaneSectionNum))
window_IndicesInSchematic = ""
pane_IndicesInSchematic = ""
surv__IndicesInSchematic = ""
for i in xrange(len(currentAllSchematic)):
logger.debug(var1("Looking for", parentPaneLayout+"|"+parentPaneLayoutChildren[otherPaneChildNum] ))
for j in xrange(0, len(currentAllSchematic[i]), 2):
logger.debug(var1("currentAllSchematic[i][j+1]", currentAllSchematic[i][j+1] ))
logger.debug(var1("Match?", (currentAllSchematic[i][j+1] == parentPaneLayout+"|"+parentPaneLayoutChildren[otherPaneChildNum]) ))
logger.debug(var1("Match2?", currentAllSchematic[i][j+1].endswith(parentPaneLayoutChildren[otherPaneChildNum]) ))
if currentAllSchematic[i][j+1] == parentPaneLayout:
window_IndicesInSchematic = i
pane_IndicesInSchematic = j
logger.debug(var1("window_IndicesInSchematic",window_IndicesInSchematic))
logger.debug(var1("pane_IndicesInSchematic",pane_IndicesInSchematic))
elif currentAllSchematic[i][j+1] == parentPaneLayout+"|"+parentPaneLayoutChildren[otherPaneChildNum]:
surv__IndicesInSchematic = j
logger.debug(var1("surv__IndicesInSchematic",surv__IndicesInSchematic))
break
if surv__IndicesInSchematic: break
''' --- FINALLY ---
Re-parenting and assigning the control to the grand parent layout
and deleting the pane layout that it previously resided under
'''
c.control( parentPaneLayoutChildren[otherPaneChildNum], edit=True, parent=grandParentPaneLayout)
c.paneLayout( grandParentPaneLayout, edit=True,
setPane=[ parentPaneLayoutChildren[otherPaneChildNum], parentPaneLayoutSectionNumber ])
# c.deleteUI( parentPaneLayout ) # Segmentation fault causer in 2014 SP2 Linux
newSchematicStart = currentAllSchematic[window_IndicesInSchematic][:pane_IndicesInSchematic]
logger.debug(var1( "newSchematicStart",newSchematicStart))
newSchematicSurvivor = currentAllSchematic[window_IndicesInSchematic][surv__IndicesInSchematic:surv__IndicesInSchematic+2]
logger.debug(var1("newSchematicSurvivor",newSchematicSurvivor))
newSchematicEnding = currentAllSchematic[window_IndicesInSchematic][pane_IndicesInSchematic+6:]
logger.debug(var1( "newSchematicEnding",newSchematicEnding))
newSchematic = []
newSchematic.extend( deepcopy(newSchematicStart) )
newSchematic.extend( deepcopy(newSchematicSurvivor) )
newSchematic.extend( deepcopy(newSchematicEnding) )
currentAllSchematic[window_IndicesInSchematic] = deepcopy(newSchematic)
refreshAllScematic()
logger.debug(defEnd("Deleted Pane") )
logger.debug("")
def setPane( paneType ):
logger.debug(defStart("Setting Pane"))
logger.debug(var1("paneType",paneType))
logger.debug(defEnd("Set Pane"))
logger.debug("")
def createOutput( parentPanelLayout ):
logger.debug(defStart("Creating output"))
logger.debug(var1("parentPanelLayout",parentPanelLayout))
output = c.cmdScrollFieldReporter( parent = parentPanelLayout,
backgroundColor=[0.1,0.1,0.1],
stackTrace=True,
lineNumbers=True )
logger.debug(var1("output",output))
createPaneMenu( output )
createDebugMenu( output )
createOutputMenu( output )
logger.debug(defEnd("Created output!"))
logger.debug("")
return output
def createInput( parentUI, activeTabIndex=1 ):
global currentInputTabType
global currentInputTabLabels
global currentInputTabFiles
global currentInputTabs
global InputBuffersPath
logger.debug(defStart("Creating input"))
logger.debug(var1("parentUI",parentUI))
inputLayout = c.formLayout(parent = parentUI) # formLayout that will hold all the tabs and command line text field
inputTabsLay = c.tabLayout(changeCommand="JSE.refreshAllScematic()",
visibleChangeCommand="JSE.logger.debug('visibility changed')") # tabLayout that will hold all the input tab buffers
logger.debug(var1("inputLayout",inputLayout))
logger.debug(var1("inputTabsLay",inputTabsLay ))
#==========================================================================================================================
#= See if previous JSE Tab settings exist, otherwise hijack Maya's current ones
#==========================================================================================================================
if c.optionVar(exists="JSE_input_tabLangs"): # Has JSE been used before? (It would have stored this variable)
# (YES)
logger.debug("Previous JSE existed, loading previous setting from optionVars")
syncGlobals("retrieve")
else: # (NO)
logger.debug("No previous JSE optionVars found, must be fresh run of JSE eh?!")
logger.debug("Hijacking settings and contents from Maya's script editor...")
if melEval("$workaroundToGetVariables = $gCommandExecuterType"): # What about Maya's own script editor, was it used?
# (YES) Retrieve existing tabs' languages from the latest Maya script editor state
# Here we use a workaround to get a variable from MEL (http://help.autodesk.com/cloudhelp/2015/ENU/Maya-Tech-Docs/CommandsPython/eval.html, example section)
currentInputTabType = melEval("$workaroundToGetVariables = $gCommandExecuterType")
currentInputTabLabels = melEval("$workaroundToGetVariables = $gCommandExecuterName")
cmdExecutersList = melEval("$workaroundToGetVariables = $gCommandExecuter")
for i in xrange( len(cmdExecutersList) ):
logger.debug(head2("appending"))
if currentInputTabType[i] == "python": fileExt = "py"
else: fileExt = "mel"
logger.debug(var1("cmdExecutersList[i]",cmdExecutersList[i]) )
logger.debug(var1("saving to","JSE-Tab-"+str(i)+"-"+currentInputTabLabels[i]+"."+fileExt) )
logger.debug("cmdExecutersList[i] text\n"+c.cmdScrollFieldExecuter(cmdExecutersList[i], q=1, text=1) )
c.cmdScrollFieldExecuter( cmdExecutersList[i], e=1, storeContents=InputBuffersPath+"JSE-Tab-"+str(i)+"-"+str(currentInputTabLabels[i])+"."+str(fileExt) )
c.cmdScrollFieldExecuter( cmdExecutersList[i], e=1, select=[0,0] )
# It definitely will not have file locations, so we create one
for i in range( len(currentInputTabType) ):
currentInputTabFiles.append("")
else: # (NO)
try:
logger.debug(head2("Looks like Maya's script editor haven't loaded in current session"))
logger.debug(head2("Grabbing optionVars from previous session"))
currentInputTabType = c.optionVar(q="ScriptEditorExecuterTypeArray")
currentInputTabLabels = c.optionVar(q="ScriptEditorExecuterLabelArray")
for i in range( len(currentInputTabType) ):
if i == 0: currentInputTabFiles.append( c.about(preferences=True)+"/prefs/scriptEditorTemp/commandExecuter")
else : currentInputTabFiles.append( c.about(preferences=True)+"/prefs/scriptEditorTemp/commandExecuter-"+str(i-1))
# Still need to sort out the code stored when SE haven't been loaded in current session of Maya
except:
logger.critical( "=== Maya's own script editor, wasn't used!! NUTS! THIS SHOULD NOT BE HAPPENING ===" )
logger.critical( "=== Default to standard [MEL, PYTHON] tab ===" )
currentInputTabType = ["mel","python"]
currentInputTabLabels = ["mel","python"]
# It definitely will not have file locations, so we create one
for i in range( len(currentInputTabType) ):
currentInputTabFiles.append("")
# Store the settings
for i in currentInputTabType : c.optionVar(stringValueAppend=["JSE_input_tabLangs" ,i])
for i in currentInputTabLabels: c.optionVar(stringValueAppend=["JSE_input_tabLabels",i])
for i in currentInputTabFiles : c.optionVar(stringValueAppend=["JSE_input_tabFiles" ,i])
logger.debug(var1( "currentInputTabType",currentInputTabType))
logger.debug(var1("currentInputTabLabels",currentInputTabLabels))
logger.debug(var1( "currentInputTabFiles",currentInputTabFiles))
#=============================================================
#= Create the tabs
#=============================================================
if len(currentInputTabType) != len(currentInputTabLabels):
logger.critical("You're fucked!, len(currentInputTabType) should equal len(currentInputTabLabels)")
logger.critical(" currentInputTabType (len,value)",len(currentInputTabType) , currentInputTabType)
logger.critical(" currentInputTabLabels (len,value)",len(currentInputTabLabels), currentInputTabLabels)
logger.critical(" currentInputTabFiles (len,value)",len(currentInputTabFiles), currentInputTabFiles)
else:
logger.debug(var1("len(currentInputTabLabels)",len(currentInputTabLabels)))
logger.debug(var1( "len(currentInputTabFiles)",len(currentInputTabFiles)))
logger.debug(head2("Making the script editor tabs"))
for i in xrange( len(currentInputTabLabels) ):
if currentInputTabType[i] == "python": fileExt = "py"
else: fileExt = "mel"
logger.debug(var1( "currentInputTabFiles[i]",currentInputTabFiles[i]))
if match(".*/commandExecuter(-[0-9]+)?$",currentInputTabFiles[i]):
fileLocation = currentInputTabFiles[i]
currentInputTabFiles[i] = ""
logger.debug(var1("new currentInputTabFiles[i]",currentInputTabFiles[i]))
else:
fileLocation = InputBuffersPath+"JSE-Tab-"+str(i)+"-"+currentInputTabLabels[i]+"."+fileExt
currentInputTabs.append(
makeInputTab( currentInputTabType[i],
inputTabsLay,
currentInputTabLabels[i],
fileLocation )
)
logger.debug(head2("Making the expression editor tabs"))
for i in c.ls(type="expression"):
currentExpr = {}
currentExpr["string"] = c.expression(i,q=1,string=1)
currentExpr["name"] = c.expression(i,q=1,name=1)
currentExpr["object"] = c.expression(i,q=1,object=1)
currentExpr["alwaysEvaluate"] = c.expression(i,q=1,alwaysEvaluate=1)
currentExpr["unitConversion"] = c.expression(i,q=1,unitConversion=1)
logger.debug(var1( 'currentExpr["string"]', currentExpr["string"] ) )
logger.debug(var1( 'currentExpr["name"]', currentExpr["name"] ) )
logger.debug(var1( 'currentExpr["object"]', currentExpr["object"] ) )
logger.debug(var1('currentExpr["alwaysEvaluate"]', currentExpr["alwaysEvaluate"] ) )
logger.debug(var1('currentExpr["unitConversion"]', currentExpr["unitConversion"] ) )
currentInputTabs.append( # Append a test expression layout for the time being
makeInputTab( "expr", inputTabsLay, "testExpression" , "")
)
''' Now this should be a text base interface for using the scipt editor, much like the command mode of vim #
Right now this is disabled so I can focus on more imprtant stuff
'''
inputCmdLine = c.textField(parent= inputLayout, manage=False)
logger.debug( var1("activeTabIndex",activeTabIndex))
logger.debug( var1("inputTabsLay tabLabels",c.tabLayout(inputTabsLay,q=1,tabLabel=1)) )
c.tabLayout(inputTabsLay, edit=True, selectTabIndex=activeTabIndex)
c.formLayout(inputLayout, edit=True,
attachForm=[ (inputTabsLay, "top", 0), # Snapping the top, left and right edges
(inputTabsLay, "left", 0), # of the tabLayout to the edges of the
(inputTabsLay, "right", 0), # formLayout
(inputCmdLine, "left", 0), # Snapping the bottom, left and right edges
(inputCmdLine, "right", 0), # of the cmdLine to the edges of the
(inputCmdLine, "bottom", 0) ],# formLayout
attachControl=(inputTabsLay, "bottom", 0, inputCmdLine) )
# Snap the bottom of the tabLayout to the top of cmdLine
createDebugMenu(inputTabsLay)
logger.debug(defEnd("Created input"))
logger.debug("")
return inputLayout
def refreshAllScematic():
global currentAllSchematic
global currentPaneScematic
schematicForDeletion = []
logger.debug(defStart("Refreshing all schematics"))
logger.debug(var1("currentAllSchematic",currentAllSchematic))
if len(currentAllSchematic[-1]):
for i in xrange(len(currentAllSchematic)):
logger.debug( head2("Schematic "+str(i)) )
windowSchematic = currentAllSchematic[i]
logger.debug(var1("windowSchematic",windowSchematic))
fullPathSplit = windowSchematic[1].split("|")
logger.debug(var1("fullPathSplit",fullPathSplit))
if not c.layout( fullPathSplit[1], q=1, exists=1):
logger.debug( head1("Schematic primary paneLayout doesn't exist"))
schematicForDeletion.append( i )
logger.debug(var1("schematicForDeletion",schematicForDeletion))
else:
for j in xrange(0 , len(windowSchematic), 2):
treeNodeType = windowSchematic[j][0]
logger.debug(var1("treeNodeType",treeNodeType))
ctrlOrLayOnly = windowSchematic[j+1].rsplit("|",1)[-1]
try: ctrlOrLayNew = c.control(ctrlOrLayOnly, q=1, fullPathName=1)
except: ctrlOrLayNew = c.layout( ctrlOrLayOnly, q=1, fullPathName=1)
logger.debug(var1("ctrlOrLayNew",ctrlOrLayNew))
windowSchematic[j+1] = ctrlOrLayNew
if treeNodeType == "V":
windowSchematic[j] = treeNodeType+str(c.paneLayout( ctrlOrLayNew , q=1, paneSize=1)[0])
elif treeNodeType == "H":
windowSchematic[j] = treeNodeType+str(c.paneLayout( ctrlOrLayNew , q=1, paneSize=1)[1])
elif treeNodeType == "I":
childTabLay = c.layout(ctrlOrLayNew,q=1,childArray=1)[0]
windowSchematic[j] = treeNodeType+str(c.tabLayout( childTabLay , q=1, selectTabIndex=1) )
logger.debug( head2("Deleting schematics marked for deletion") )
logger.debug(var1("schematicForDeletion",schematicForDeletion))
# Remove lists from the back to front to avoid out of range issues
for i in reversed(schematicForDeletion):
currentAllSchematic.pop(i)
logger.debug(var1("schematicForDeletion",schematicForDeletion))
logger.debug(var1("currentAllSchematic",currentAllSchematic))
logger.debug(var1("final currentAllSchematic",currentAllSchematic))
currentPaneScematic = []
for i in xrange(0,len(currentAllSchematic[-1]),2):
currentPaneScematic.append( currentAllSchematic[-1][i] )
logger.debug(var1("new currentPaneScematic",currentPaneScematic))
logger.debug(defStart("Refreshed all schematics"))
def createPaneMenu( ctrl ):
logger.debug(defStart("Creating Pane Menu"))
logger.debug(var1("ctrl",ctrl))
c.popupMenu( parent=ctrl , altModifier=True, markingMenu=True) # markingMenu = Enable pie style menu
c.menuItem( label="New Right", radialPosition="E",
command="JSE.split('"+ctrl+"','right',True)" )
c.menuItem( label="New Right", radialPosition="E", optionBox=True,
command="JSE.split('"+ctrl+"','right',False)" )
c.menuItem( label="New Left", radialPosition="W",
command="JSE.split('"+ctrl+"','left',True)" )
c.menuItem( label="New Left", radialPosition="W", optionBox=True,
command="JSE.split('"+ctrl+"','left', False)" )
c.menuItem( label="New Below", radialPosition="S",
command="JSE.split('"+ctrl+"','bottom',True)" )
c.menuItem( label="New Below", radialPosition="S", optionBox=True,
command="JSE.split('"+ctrl+"','bottom', False)" )
c.menuItem( label="New Above", radialPosition="N",
command="JSE.split('"+ctrl+"','top',True)" )
c.menuItem( label="New Above", radialPosition="N", optionBox=True,
command="JSE.split('"+ctrl+"','top', False)" )
c.menuItem( label="---Pane Menu (Alt)---", enable=False)
c.menuItem( label="Remove This Pane!",
command="JSE.deletePane('"+ctrl+"')")
logger.debug(defEnd("Created Pane Menu"))
logger.debug("")
################################################ InputRelated ################################################
def inputPaneMethods(ctrl, method):
global OutputSnapshotsPath
logger.debug(defStart("Input method processing"))
logger.debug(var1("ctrl",ctrl))
logger.debug(var1("method",method))
if method[:12] == "createScript":
print "---Navigate tree and create tab on all layouts---"
# c.cmdScrollFieldExecuter(sourceType=method[12:])
elif method == "createExpression":
print "---Need to create expression---"
logger.debug(defEnd("Input method processed"))
logger.debug("")
def makeInputTab(tabUsage, pTabLayout, tabLabel, fileLocation, exprDic={}):
'''
If there is no text then load from file
'''
logger.debug(defStart("Making input tab"))
logger.debug(var1( "tabUsage",tabUsage))
logger.debug(var1( "pTabLayout",pTabLayout))
logger.debug(var1( "tabLabel",tabLabel))
logger.debug(var1("fileLocation",fileLocation))
inputField = ""
if tabUsage == "mel" : bkgndColour = [0.16, 0.16, 0.16]
if tabUsage == "expr" : bkgndColour = [0.16, 0.13, 0.13]
if tabUsage == "python" : bkgndColour = [0.12, 0.14, 0.15]
logger.debug(var1( "bkgndColour",bkgndColour))
if tabUsage == "python" : tabLang = "python"
else : tabLang = "mel"
logger.debug(var1( "tabLang",tabLang))
if tabUsage == "expr":
exprPanelayout = c.paneLayout( parent = pTabLayout, configuration='vertical2')
#========================================================================================================
exprForm = c.formLayout( parent = exprPanelayout)
#--------------------------------------------------------
angleOption = c.optionMenu( parent = exprForm)
option_All = c.menuItem(label="Convert All Units")
option_Non = c.menuItem(label="None")
option_Ang = c.menuItem(label="Angular only")
#--------------------------------------------------------
evalOption = c.optionMenu( parent = exprForm)
option_OnD = c.menuItem(label="On Demand")
option_Alw = c.menuItem(label="Always Evaluate")
option_AfC = c.menuItem(label="After Cloth")
c.optionMenu( evalOption, e=1, select = 2)
#--------------------------------------------------
defObject = c.textField( parent = exprForm, placeholderText="Default Obj. e.g.pCube", w=150 )
#--------------------------------------------------------
inputField = c.cmdScrollFieldExecuter( sourceType= "mel",
backgroundColor = bkgndColour,
parent=exprForm,
showLineNumbers=True )
logger.debug(var1("inputField",inputField))
c.formLayout(exprForm, e=1, attachForm=([angleOption, "top", 0],
[evalOption, "top", 0],
[defObject, "top", 0],
[defObject, "right", 0],
[inputField, "bottom", 0],
[inputField, "right", 0],
[inputField, "left", 0]),
attachControl=([inputField, "top", 0, defObject],
[defObject, "left", 0, evalOption],
[evalOption, "left", 0, angleOption]) )
#========================================================================================================
attrForm = c.formLayout( parent = exprPanelayout)
#--------------------------------------------------------
objSearchField = c.textFieldGrp( parent = attrForm, placeholderText="Search obj for attr", w=120 )
attrList = c.textScrollList( parent = attrForm, append=["--NOTHING FOUND--"], enable=False)
c.textFieldGrp( objSearchField, e=1, textChangedCommand="JSE.listObjAttr('"+objSearchField+"','"+attrList+"')" )
c.textScrollList( attrList, e=1, doubleClickCommand="JSE.attrInsert('"+inputField+"','"+objSearchField+"','"+attrList+"')" )
logger.debug(var1("textChangedCommand","JSE.listObjAttr('"+objSearchField+"','"+attrList+"')"))
c.formLayout(attrForm, e=1, attachForm=([objSearchField, "top", 0],
[objSearchField, "left", 0],
[objSearchField, "right", 0],
[attrList, "left", 0],
[attrList, "right", 0],
[attrList, "bottom", 0] ),
attachControl=([attrList, "top", 0, objSearchField]) )
tabLabel = c.expression(n=tabLabel)
createExpressionMenu(exprPanelayout)
createInputMenu(exprPanelayout)
createPaneMenu(exprPanelayout)
else:
inputField = c.cmdScrollFieldExecuter( sourceType= tabLang,
backgroundColor = bkgndColour,
parent=pTabLayout,
showLineNumbers=True,
spacesPerTab=4,
autoCloseBraces=True,
showTooltipHelp=True,
objectPathCompletion=True,
commandCompletion=True )
logger.debug(var1("inputField",inputField))
with open(fileLocation,"r") as bufferFile:
c.cmdScrollFieldExecuter(inputField, e=1, text=bufferFile.read() )
# make sure the text is not selected
c.cmdScrollFieldExecuter(inputField, e=1, select=[0,0] )
createScriptEditorMenu(inputField)
createInputMenu(inputField)
createPaneMenu(inputField)
c.tabLayout(pTabLayout, e=1, tabLabel= [c.tabLayout(pTabLayout,
q=1, childArray=1)[-1] ,# Get the name of the newest tab child created
tabLabel ] ) # and rename that tab with our label
logger.debug(defEnd("Made input tab"))
return inputField
def createInputMenu( ctrl ):
logger.debug(defStart("Creating Input Menu"))
logger.debug(var1("ctrl",ctrl))
c.popupMenu( parent=ctrl , shiftModifier=True, markingMenu=True) # markingMenu = Enable pie style menu
c.menuItem( label="Create Tab...", radialPosition="N", subMenu=True)
c.menuItem( label="Create Python", radialPosition="E",
command="JSE.inputPaneMethods('"+ctrl+"','createScriptpython')" )
c.menuItem( label="Create MEL", radialPosition="W",
command="JSE.inputPaneMethods('"+ctrl+"','createScriptmel')" )
c.menuItem( label="Create Expression", radialPosition="N",
command="JSE.inputPaneMethods('"+ctrl+"','createExpression')" )
c.setParent("..", menu=True)
c.menuItem( label="---Input Menu (Shift)---", enable=False)
c.menuItem( label="Close this tab", radialPosition="N",
command="" )
c.menuItem( label="", command="")
logger.debug(defEnd("Created Input Menu"))
logger.debug("")
################################################ ExpressionRelated ################################################
def attrInsert(cmdField, objSearchField, attrField):
logger.debug(defStart("Inserting attribute to expression field"))
logger.debug(var1( "cmdField",cmdField))
logger.debug(var1("objSearchField",objSearchField))
logger.debug(var1( "attrField",attrField))
logger.debug(head2("Get selected attributes and combine with object string"))
attrText = c.textScrollList(attrField, q=1, selectItem=1)[0].split(" ")[0]
objText = c.textFieldGrp(objSearchField, q=1, text=1)
logger.debug( var1("attrText",attrText))
logger.debug( var1( "objText",objText))
logger.debug(head2("Insert it into the expression field (at current cursor pos)"))
c.cmdScrollFieldExecuter(cmdField, e=1, insertText="{0}.{1}".format(objText, attrText))
logger.debug(defEnd("Inserted attribute to expression field"))
logger.debug("")
def listObjAttr(objTextField, scrollListToOutput):
# If the current object is not valid then get outta here
logger.debug(defStart("Listing object attributes") )
logger.debug(var1( "objTextField",objTextField))
logger.debug(var1("scrollListToOutput",scrollListToOutput))
c.textScrollList( scrollListToOutput, e=1, removeAll=1)
objInQuestion = c.textFieldGrp( objTextField, q=1, text=1)
logger.debug(var1( "objInQuestion",objInQuestion))
try: attrLong = c.listAttr(objInQuestion)
except:
c.textScrollList( scrollListToOutput, e=1, append=["--NOTHING FOUND--"], enable=False)
return
attrShrt = c.listAttr(objInQuestion, shortNames=1)