1+ import inkex
2+ from inkex import command
3+ import os
4+ from conduct import conduct
5+ import subprocess
6+
7+ class ConductCreateSetup (inkex .EffectExtension ):
8+
9+ def add_arguments (self , pars ):
10+ pars .add_argument ("-m" , "--manifest" , default = "" , help = "Manifest File Path" )
11+
12+ def effect (self ):
13+ path = self .options .manifest
14+ c = conduct .get_from_manifest_path (path , "inkscape" )
15+ result = c .setup ()
16+
17+ if result ['result' ] != 'ok' :
18+ return
19+
20+ dialog_data = result ['data' ]
21+ path = os .path .join (dialog_data ['path' ], dialog_data ['file_name' ] + ".svg" )
22+
23+ self .svg .set ("com.lagmachine.conduct.asset" , dialog_data ['asset' ])
24+ self .svg .set ("com.lagmachine.conduct.department" , dialog_data ['department' ])
25+ if dialog_data ['shot' ] is not None :
26+ self .svg .set ("com.lagmachine.conduct.shot" , dialog_data ['shot' ])
27+
28+ # write to new file, and open it in a new instance of inkscape
29+ # this is the best i can do, there is no function for changing the current file to a different location
30+ data = self .svg .tostring ().decode ('utf-8' )
31+
32+ with open (path , mode = 'w' ) as f :
33+ f .write (data )
34+
35+ exe = inkex .command .which ('inkscape' )
36+
37+ #if we could find a good way to kill the original inkscape instance after starting the new one, that would be ideal
38+ if os .name == 'nt' :
39+ creation_flags = subprocess .CREATE_NEW_PROCESS_GROUP | subprocess .DETACHED_PROCESS
40+ proc = subprocess .Popen ([exe , path ], creationflags = creation_flags , start_new_session = True )
41+ else :
42+ proc = subprocess .Popen ([exe , path ], stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL , stdin = subprocess .DEVNULL )
43+
44+ if __name__ == '__main__' :
45+ ConductCreateSetup ().run ()
0 commit comments