15 from pyfbsdk_additions
import *
21 TOOL_NAME =
"Action Script Manager"
22 ACTION_SCRIPT_PATH = os.path.join(mbutils.GetConfigPath(),
"Scripts")
23 ACTION_SCRIPT_FILE = os.path.join(ACTION_SCRIPT_PATH,
"ActionScript.txt")
25 class ActionScriptMgr(
FBTool):
26 def RowClicked(self,control,event):
28 if self.path_spread.GetRow(event.Row).RowSelected:
29 self.current_row = event.Row
32 path = self.path_spread.GetCellValue(event.Row, 0)
37 self.path_edit.Text = path
39 def Browse(self,control,event):
40 filepopup = pyfbsdk.FBFilePopup()
41 filepopup.Caption =
"Select a script"
42 filepopup.Style = pyfbsdk.FBFilePopupStyle.kFBFilePopupOpen
43 filepopup.Filter =
"*.py"
44 result = filepopup.Execute()
46 self.path_edit.Text = os.path.join(filepopup.Path,filepopup.FileName)
49 def Add(self,control,event):
50 if self.current_row == -1:
52 self.path_spread.SetCellValue(self.current_row,0,self.path_edit.Text)
53 self.UpdateScript(self.current_row)
55 def Remove(self,control,event):
57 if self.current_row == -1:
59 self.path_spread.SetCellValue(self.current_row,0,
"")
60 self.UpdateScript(self.current_row)
62 def UpdateScript(self,row):
63 config =
FBConfigFile(
"ActionScript.txt",ACTION_SCRIPT_PATH)
65 spread_row = self.path_spread.GetRow(row)
66 key = spread_row.Caption
67 value = self.path_spread.GetCellValue(row,0)
71 value = os.path.relpath(value,ACTION_SCRIPT_PATH)
72 config.Set(
"ScriptFiles",key,value)
74 def CellChanged(self,control,event):
76 self.UpdateScript(event.Row)
82 os.chdir(ACTION_SCRIPT_PATH)
86 config =
FBConfigFile(
"ActionScript.txt",ACTION_SCRIPT_PATH)
88 key =
"Script%d" % (i + 1)
89 value = config.Get(
"ScriptFiles",key)
90 self.path_spread.RowAdd(key,self.nb_row)
92 self.path_spread.SetCellValue(self.nb_row,0,os.path.abspath(value))
106 self.AddRegion(
"main",
"main", x, y, w, h)
109 self.SetControl(
"main",vbox)
115 l.Caption =
"Action Scripts"
116 vbox.Add(l, widget_height)
119 self.path_spread.Caption =
"Actions"
120 self.path_spread.ColumnAdd(
"Path")
121 self.path_spread.GetColumn(0).Width = 550
122 self.path_spread.OnRowClick.Add(self.RowClicked)
123 self.path_spread.OnCellChange.Add(self.CellChanged)
124 vbox.AddRelative(self.path_spread,1.0)
129 hbox.AddRelative(self.path_edit,1.0)
132 b.Caption =
"Browse..."
133 b.OnClick.Add(self.Browse)
134 hbox.Add(b, button_width)
136 vbox.Add(hbox,widget_height)
141 b.OnClick.Add(self.Add)
142 hbox.Add(b, button_width)
146 b.OnClick.Add(self.Remove)
147 hbox.Add(b, button_width)
151 l.Caption =
"You will need to restart MotionBuilder for changes to takes place!"
152 l.Style = FBTextStyle.kFBTextStyleBold
155 vbox.Add(hbox,widget_height)
157 self.StartSizeX = 800
158 self.StartSizeY = 425
168 if TOOL_NAME
in FBToolList:
169 tool = FBToolList[TOOL_NAME]
172 tool=ActionScriptMgr()