Set the executable property on the script.
[mirror_edk2.git] / Tools / Python / ContextTool.py
1 #!/usr/bin/env python
2
3 # The EDK II Build System Context Tool Utility maintains Target.txt settings in an EDK II Workspace.
4
5 import wx, os, sys, copy
6 from EdkIIWorkspace import *
7
8 class ContextToolModel(EdkIIWorkspace):
9 def __init__(self):
10 self.WorkspaceStatus = EdkIIWorkspace.__init__(self)
11 self.Database = {}
12 self.OriginalDatabase = {}
13
14 def LoadTargetTxtFile(self):
15 self.ConvertTextFileToDictionary('Tools/Conf/Target.txt', self.TargetTxtDictionary, '#', '=', True, None)
16 if self.TargetTxtDictionary['ACTIVE_PLATFORM'] == []:
17 self.TargetTxtDictionary['ACTIVE_PLATFORM'] = ['']
18 else:
19 self.TargetTxtDictionary['ACTIVE_PLATFORM'] = [self.TargetTxtDictionary['ACTIVE_PLATFORM'][0]]
20 self.TargetTxtDictionary['TOOL_CHAIN_CONF'] = [self.TargetTxtDictionary['TOOL_CHAIN_CONF'][0]]
21 self.TargetTxtDictionary['MULTIPLE_THREAD'] = [self.TargetTxtDictionary['MULTIPLE_THREAD'][0]]
22 self.TargetTxtDictionary['MAX_CONCURRENT_THREAD_NUMBER'] = [self.TargetTxtDictionary['MAX_CONCURRENT_THREAD_NUMBER'][0]]
23 self.TargetTxtDictionary['TARGET'] = list(set(self.TargetTxtDictionary['TARGET']))
24 self.TargetTxtDictionary['TOOL_CHAIN_TAG'] = list(set(self.TargetTxtDictionary['TOOL_CHAIN_TAG']))
25 self.TargetTxtDictionary['TARGET_ARCH'] = list(set(self.TargetTxtDictionary['TARGET_ARCH']))
26 if self.TargetTxtDictionary['TARGET'] == []:
27 self.TargetTxtDictionary['TARGET'] = ['']
28 if self.TargetTxtDictionary['TOOL_CHAIN_TAG'] == []:
29 self.TargetTxtDictionary['TOOL_CHAIN_TAG'] = ['']
30 if self.TargetTxtDictionary['TARGET_ARCH'] == []:
31 self.TargetTxtDictionary['TARGET_ARCH'] = ['']
32 self.TargetTxtDictionary['TARGET'].sort()
33 self.TargetTxtDictionary['TOOL_CHAIN_TAG'].sort()
34 self.TargetTxtDictionary['TARGET_ARCH'].sort()
35 self.OriginalTargetTxtDictionary = copy.deepcopy(self.TargetTxtDictionary)
36
37 def LoadToolsDefTxtFile(self):
38 self.ToolsDefTxtDictionary = {}
39 if self.TargetTxtDictionary['TOOL_CHAIN_CONF'] != ['']:
40 self.ConvertTextFileToDictionary(self.TargetTxtDictionary['TOOL_CHAIN_CONF'][0], self.ToolsDefTxtDictionary, '#', '=', False, None)
41
42 def LoadFrameworkDatabase(self):
43 self.PlatformDatabase = {}
44 Fd = self.XmlParseFile ('Tools/Conf/FrameworkDatabase.db')
45 PlatformList = XmlList (Fd, '/FrameworkDatabase/PlatformList/Filename')
46 for File in PlatformList:
47 FpdFileName = XmlElementData(File)
48 FpdPlatformHeader = self.XmlParseFileSection (FpdFileName, 'PlatformHeader')
49 FpdPlatformDefinitions = self.XmlParseFileSection (FpdFileName,'PlatformDefinitions')
50 PlatformName = XmlElement (FpdPlatformHeader, '/PlatformHeader/PlatformName')
51 PlatformVersion = XmlElement (FpdPlatformHeader, '/PlatformHeader/Version')
52 PlatformUiName = PlatformName + '[' + PlatformVersion + ']'
53 if PlatformUiName not in self.PlatformDatabase:
54 self.PlatformDatabase[PlatformUiName] = {}
55 self.PlatformDatabase[PlatformUiName]['XmlFileName'] = FpdFileName
56 self.PlatformDatabase[PlatformUiName]['SupportedArchitectures'] = set(XmlElement (FpdPlatformDefinitions, '/PlatformSurfaceArea/PlatformDefinitions/SupportedArchitectures').split(' '))
57 self.PlatformDatabase[PlatformUiName]['BuildTargets'] = set(XmlElement (FpdPlatformDefinitions, '/PlatformSurfaceArea/PlatformDefinitions/BuildTargets').split(' '))
58
59 def ComputeToolsDefTxtDatabase(self):
60 self.ToolsDefTxtDatabase = {
61 'TARGET' : [],
62 'TOOL_CHAIN_TAG' : [],
63 'TARGET_ARCH' : []
64 }
65 for Key in dict(self.ToolsDefTxtDictionary):
66 List = Key.split('_')
67 if len(List) != 5:
68 del self.ToolsDefTxtDictionary[Key]
69 elif List[4] == '*':
70 del self.ToolsDefTxtDictionary[Key]
71 else:
72 if List[0] != '*':
73 self.ToolsDefTxtDatabase['TARGET'] += [List[0]]
74 if List[1] != '*':
75 self.ToolsDefTxtDatabase['TOOL_CHAIN_TAG'] += [List[1]]
76 if List[2] != '*':
77 self.ToolsDefTxtDatabase['TARGET_ARCH'] += [List[2]]
78 self.ToolsDefTxtDatabase['TARGET'] = list(set(self.ToolsDefTxtDatabase['TARGET']))
79 self.ToolsDefTxtDatabase['TOOL_CHAIN_TAG'] = list(set(self.ToolsDefTxtDatabase['TOOL_CHAIN_TAG']))
80 self.ToolsDefTxtDatabase['TARGET_ARCH'] = list(set(self.ToolsDefTxtDatabase['TARGET_ARCH']))
81 self.ToolsDefTxtDatabase['TARGET'].sort()
82 self.ToolsDefTxtDatabase['TOOL_CHAIN_TAG'].sort()
83 self.ToolsDefTxtDatabase['TARGET_ARCH'].sort()
84
85 def NewModel(self):
86 self.TargetTxtDictionary = {
87 'ACTIVE_PLATFORM' : [''],
88 'TOOL_CHAIN_CONF' : [''],
89 'MULTIPLE_THREAD' : ['Disable'],
90 'MAX_CONCURRENT_THREAD_NUMBER' : ['2'],
91 'TARGET' : [''],
92 'TOOL_CHAIN_TAG' : [''],
93 'TARGET_ARCH' : ['']
94 }
95
96 def RevertModel(self):
97 self.TargetTxtDictionary = copy.deepcopy(self.OriginalTargetTxtDictionary)
98
99 def RescanModel(self):
100 self.NewModel()
101 self.LoadTargetTxtFile()
102
103 def RefreshModel(self):
104 self.LoadFrameworkDatabase()
105 self.LoadToolsDefTxtFile()
106 self.ComputeToolsDefTxtDatabase()
107
108 if self.Verbose:
109 print self.TargetTxtDictionary
110 print 'ActivePlatform = ', self.TargetTxtDictionary['ACTIVE_PLATFORM'][0]
111 print 'ToolChainConf = ', self.TargetTxtDictionary['TOOL_CHAIN_CONF'][0]
112 print 'MultipleThread = ', self.TargetTxtDictionary['MULTIPLE_THREAD'][0]
113 print 'MaxThreads = ', self.TargetTxtDictionary['MAX_CONCURRENT_THREAD_NUMBER'][0]
114 print 'TargetSet = ', self.TargetTxtDictionary['TARGET']
115 print 'ToolChainSet = ', self.TargetTxtDictionary['TOOL_CHAIN_TAG']
116 print 'TargetArchSet = ', self.TargetTxtDictionary['TARGET_ARCH']
117 Platforms = self.PlatformDatabase.keys()
118 print 'Possible Settings:'
119 print ' Platforms = ', Platforms
120 print ' TargetSet = ', self.ToolsDefTxtDatabase['TARGET']
121 print ' ToolChainSet = ', self.ToolsDefTxtDatabase['TOOL_CHAIN_TAG']
122 print ' TargetArchSet = ', self.ToolsDefTxtDatabase['TARGET_ARCH']
123 return True
124
125 def ModelModified(self):
126 if self.TargetTxtDictionary != self.OriginalTargetTxtDictionary:
127 return True
128 return False
129
130 def SaveModel(self, Filename='Tools/Conf/Target.txt'):
131 if self.Verbose:
132 for Item in self.TargetTxtDictionary:
133 print Item,'=',self.TargetTxtDictionary[Item]
134 self.ConvertDictionaryToTextFile(Filename, self.TargetTxtDictionary, '#', '=', True, None)
135 self.OriginalTargetTxtDictionary = copy.deepcopy(self.TargetTxtDictionary)
136
137 def CloseModel(self):
138 pass
139
140 class Frame(wx.Frame):
141 def __init__(self):
142 wx.Frame.__init__(self,None,-1,'EDK II Build System Context Tool')
143 panel = wx.Panel(self, style=wx.SUNKEN_BORDER | wx.TAB_TRAVERSAL)
144 wx.HelpProvider_Set(wx.SimpleHelpProvider())
145 self.Model = ContextToolModel()
146 if not self.Model.WorkspaceStatus:
147 self.Close()
148 return
149
150 #
151 # Help text
152 #
153 ActivePlatformHelpText = (
154 "Specifies the Platform Name and Platform Version of the platform that will be "
155 "used for build. If set to [Build Directory] and the current directory contains "
156 "an FPD file, then a plaform build on that FPD file will be performed. If set "
157 "to [Build Directory] and there is no FPD file in the current directory, then no "
158 "build will be performed."
159 )
160
161 ToolChainConfHelpText = (
162 "Specifies the name of the file that declares all the tools and flag settings "
163 "required to complete a build. This is typically set to Tools/Conf/tools_def.txt."
164 )
165
166 MultipleThreadHelpText = (
167 "Flag to enable or disable multi-thread builds. If your computer is multi-core "
168 "or contans multiple CPUs, enabling this feature will improve build performance. "
169 "For multi-thread builds, a log will be written to ${BUILD_DIR}/build.log. This "
170 "feature is only for platform builds. Clean, cleanall, and stand-alone module "
171 "builds only use one thread."
172 )
173
174 ThreadsHelpText = (
175 "The number of concurrent threads. The best performance is achieved if this "
176 "value is set to one greater than the number or cores or CPUs in the build system."
177 )
178
179 TargetHelpText = (
180 "Specifies the set of targets to build. If set to All, then all build targets "
181 "are built. Otherwise, the subset of enabled build targets are built. The "
182 "standard build targets are RELEASE and DEBUG, but additional user-defined build "
183 "targets may be declared in the TOOL_CHAIN_CONF file. The DEBUG builds with "
184 "source level debugging enabled. RELEASE builds with source level debugging "
185 "disabled and results in smaller firmware images."
186 )
187
188 ToolChainTagHelpText = (
189 "Specifies the set of tool chains to use during a build. If set to All, then "
190 "all of the supported tools chains are used. Otherwise, only the subset of "
191 "enabled tool chains are used. The TOOL_CHAIN_CONF file declares one or more "
192 "tool chains that may be used."
193 )
194
195 TargetArchHelpText = (
196 "Specifies the set of CPU architectures to build. If set to All, then all the "
197 "CPU architectures supported by the platform FPD file are built. Otherwise, "
198 "only the subset of enabled CPU architectures are built. The standard CPU "
199 "architectures are IA32, X64, IPF, and EBC, but additional CPU architectures "
200 "may be declared in the TOOL_CHAIN_CONF file."
201 )
202
203 #
204 # Status Bar
205 #
206 self.CreateStatusBar()
207
208 #
209 # Build Menus
210 #
211 MenuBar = wx.MenuBar()
212
213 FileMenu = wx.Menu()
214 NewMenuItem = FileMenu.Append(-1, "&New\tCtrl+N", "New target.txt")
215 SaveMenuItem = FileMenu.Append(-1, "&Save\tCtrl+S", "Save target.txt")
216 SaveAsMenuItem = FileMenu.Append(-1, "Save &As...", "Save target.txt as...")
217 RevertMenuItem = FileMenu.Append(-1, "&Revert", "Revert to the original target.txt")
218 ExitMenuItem = FileMenu.Append(-1, "E&xit\tAlt+F4", "Exit ContextTool")
219 MenuBar.Append(FileMenu, "&File")
220 self.Bind(wx.EVT_MENU, self.OnSaveClick, SaveMenuItem)
221 self.Bind(wx.EVT_MENU, self.OnSaveAsClick, SaveAsMenuItem)
222 self.Bind(wx.EVT_MENU, self.OnRevertClick, RevertMenuItem)
223 self.Bind(wx.EVT_MENU, self.OnExitClick, ExitMenuItem)
224
225 ViewMenu = wx.Menu()
226 RefreshMenuItem = ViewMenu.Append (-1, "&Refresh\tF5", "Rescan target.txt")
227 ShowToolBarMenuItem = ViewMenu.AppendCheckItem (-1, "Show &Toolbar", "Shows or hides the toolbar")
228 ShowToolBarMenuItem.Check(True)
229 MenuBar.Append(ViewMenu, "&View")
230 self.Bind(wx.EVT_MENU, self.OnViewRefreshClick, RefreshMenuItem)
231 self.Bind(wx.EVT_MENU, self.OnShowToolBarClick, ShowToolBarMenuItem)
232
233 HelpMenu = wx.Menu()
234 AboutMenuItem = HelpMenu.Append (-1, "&About...", "About")
235 MenuBar.Append(HelpMenu, "&Help")
236 self.Bind(wx.EVT_MENU, self.OnAboutClick, AboutMenuItem)
237
238 self.SetMenuBar (MenuBar)
239
240 #
241 # Build Toolbar
242 #
243 self.ShowToolBar = False
244 self.OnShowToolBarClick(self)
245
246 #
247 # Active Platform Combo Box
248 #
249 ActivePlatformLabel = wx.StaticText(panel, -1, 'ACTIVE_PLATFORM')
250 ActivePlatformLabel.SetHelpText(ActivePlatformHelpText)
251 self.ActivePlatformText = wx.ComboBox(panel,-1, style=wx.CB_DROPDOWN | wx.CB_SORT | wx.CB_READONLY)
252 self.ActivePlatformText.SetHelpText(ActivePlatformHelpText)
253 self.ActivePlatformText.Bind(wx.EVT_TEXT, self.OnActivePlatformClick)
254
255 #
256 # Tool Chain Configuration Text Control and Browse Button for a File Dialog Box
257 #
258 ToolChainConfFileLabel = wx.StaticText(panel, -1, 'TOOL_CHAIN_CONF')
259 ToolChainConfFileLabel.SetHelpText(ToolChainConfHelpText)
260 self.ToolChainConfFileText = wx.TextCtrl(panel, -1, style=wx.TE_PROCESS_ENTER)
261 self.ToolChainConfFileText.Bind(wx.EVT_TEXT_ENTER, self.OnToolChainConfClick)
262 self.ToolChainConfFileText.Bind(wx.EVT_KILL_FOCUS, self.OnToolChainConfClick)
263 self.ToolChainConfFileText.SetHelpText(ToolChainConfHelpText)
264 self.BrowseButton = wx.Button(panel, -1, 'Browse...')
265 self.BrowseButton.Bind(wx.EVT_BUTTON, self.OnBrowseButtonClick)
266
267 #
268 # Multiple Thread enable/disable radio button
269 #
270 MultipleThreadLabel = wx.StaticText(panel, -1, 'MULTIPLE_THREAD')
271 MultipleThreadLabel.SetHelpText(MultipleThreadHelpText)
272 self.MultipleThreadRadioBox = wx.RadioBox(panel, -1, choices=['Enable','Disable'], style=wx.RA_SPECIFY_COLS)
273 self.MultipleThreadRadioBox.Bind(wx.EVT_RADIOBOX, self.OnMultipleThreadRadioBox)
274 self.MultipleThreadRadioBox.SetHelpText(MultipleThreadHelpText)
275
276 #
277 # Thread count spin control
278 #
279 ThreadsLabel = wx.StaticText(panel, -1, 'THREADS')
280 ThreadsLabel.SetHelpText(ThreadsHelpText)
281 self.ThreadsSpinCtrl = wx.SpinCtrl(panel, -1, size=(50, -1), min=2)
282 self.ThreadsSpinCtrl.Bind(wx.EVT_TEXT, self.OnThreadsSpinCtrl)
283 self.ThreadsSpinCtrl.SetHelpText(ThreadsHelpText)
284
285 #
286 # Target, ToolChain, and Arch Check List Boxes
287 #
288 TargetLabel = wx.StaticText(panel, -1, 'TARGET')
289 TargetLabel.SetHelpText(TargetHelpText)
290
291 ToolChainTagLabel = wx.StaticText(panel, -1, 'TOOL_CHAIN_TAG')
292 ToolChainTagLabel.SetHelpText(ToolChainTagHelpText)
293
294 TargetArchLabel = wx.StaticText(panel, -1, 'TARGET_ARCH')
295 TargetArchLabel.SetHelpText(TargetArchHelpText)
296
297 self.TargetCheckListBox = wx.CheckListBox(panel, -1)
298 self.TargetCheckListBox.Bind(wx.EVT_CHECKLISTBOX, self.OnTargetCheckListClick)
299 self.TargetCheckListBox.Bind(wx.EVT_SET_FOCUS, self.OnTargetSetFocus)
300 self.TargetCheckListBox.Bind(wx.EVT_KILL_FOCUS, self.OnTargetKillFocus)
301 self.TargetCheckListBox.SetHelpText(TargetHelpText)
302
303 self.ToolChainTagCheckListBox = wx.CheckListBox(panel, -1)
304 self.ToolChainTagCheckListBox.Bind(wx.EVT_CHECKLISTBOX, self.OnToolChainTagCheckListClick)
305 self.ToolChainTagCheckListBox.Bind(wx.EVT_SET_FOCUS, self.OnToolChainTagSetFocus)
306 self.ToolChainTagCheckListBox.Bind(wx.EVT_KILL_FOCUS, self.OnToolChainTagKillFocus)
307 self.ToolChainTagCheckListBox.SetHelpText(ToolChainTagHelpText)
308
309 self.TargetArchCheckListBox = wx.CheckListBox(panel, -1)
310 self.TargetArchCheckListBox.Bind(wx.EVT_CHECKLISTBOX, self.OnTargetArchCheckListClick)
311 self.TargetArchCheckListBox.Bind(wx.EVT_SET_FOCUS, self.OnTargetArchSetFocus)
312 self.TargetArchCheckListBox.Bind(wx.EVT_KILL_FOCUS, self.OnTargetArchKillFocus)
313 self.TargetArchCheckListBox.SetHelpText(TargetArchHelpText)
314
315 #
316 # Define layout using sizers
317 #
318 self.mainSizer = wx.BoxSizer(wx.VERTICAL)
319
320 flexSizer = wx.FlexGridSizer(cols=3, hgap=5, vgap=5)
321 flexSizer.AddGrowableCol(1)
322 flexSizer.Add(ActivePlatformLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
323 flexSizer.Add(self.ActivePlatformText, 0, wx.EXPAND)
324 flexSizer.Add((0,0), wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
325
326 flexSizer.Add(ToolChainConfFileLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
327 flexSizer.Add(self.ToolChainConfFileText, 0, wx.EXPAND)
328 flexSizer.Add(self.BrowseButton, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
329
330 self.mainSizer.Add (flexSizer, 0, wx.EXPAND | wx.ALL, 10)
331
332 threadsSizer = wx.FlexGridSizer(cols = 5, hgap=5, vgap=5)
333 threadsSizer.Add(MultipleThreadLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
334 threadsSizer.Add(self.MultipleThreadRadioBox, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
335 threadsSizer.Add(ThreadsLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
336 threadsSizer.Add(self.ThreadsSpinCtrl, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
337
338 self.mainSizer.Add (threadsSizer, 0, wx.ALL, 10)
339
340 listSizer = wx.FlexGridSizer(rows = 2, cols = 3, hgap=5, vgap=5)
341 listSizer.AddGrowableRow(1)
342 listSizer.AddGrowableCol(0)
343 listSizer.AddGrowableCol(1)
344 listSizer.AddGrowableCol(2)
345 listSizer.Add(TargetLabel, 0, wx.ALIGN_CENTER)
346 listSizer.Add(ToolChainTagLabel, 0, wx.ALIGN_CENTER)
347 listSizer.Add(TargetArchLabel, 0, wx.ALIGN_CENTER)
348 listSizer.Add(self.TargetCheckListBox, 0, wx.ALL | wx.EXPAND)
349 listSizer.Add(self.ToolChainTagCheckListBox, 0, wx.ALL | wx.EXPAND)
350 listSizer.Add(self.TargetArchCheckListBox, 0, wx.ALL | wx.EXPAND)
351
352 self.mainSizer.Add (listSizer, wx.EXPAND | wx.ALL, wx.EXPAND | wx.ALL, 10)
353
354 panel.SetSizer (self.mainSizer)
355
356 self.Model.RescanModel()
357 self.OnRefreshClick(self)
358
359 def OnActivePlatformClick(self, event):
360 Platform = self.ActivePlatformText.GetValue()
361 if Platform == ' [Build Directory]':
362 self.Model.TargetTxtDictionary['ACTIVE_PLATFORM'][0] = ''
363 else:
364 self.Model.TargetTxtDictionary['ACTIVE_PLATFORM'][0] = self.Model.PlatformDatabase[Platform]['XmlFileName']
365
366 def OnToolChainConfClick(self, event):
367 if self.Model.TargetTxtDictionary['TOOL_CHAIN_CONF'][0] != self.ToolChainConfFileText.GetValue():
368 self.Model.TargetTxtDictionary['TOOL_CHAIN_CONF'][0] = self.ToolChainConfFileText.GetValue()
369 self.OnRefreshClick(self)
370
371 def OnBrowseButtonClick(self, event):
372 wildcard = "Text Documents (*.txt)|*.txt|" \
373 "All files (*.*)|*.*"
374 dialog = wx.FileDialog (None, 'Choose a Tool Chain Configuration File', self.Model.WorkspaceFile('Tools/Conf'), '', wildcard, wx.OPEN)
375 if dialog.ShowModal() == wx.ID_OK:
376 print dialog.GetPath()
377 ToolChainConfFile = self.Model.WorkspaceRelativePath(dialog.GetPath())
378 self.ToolChainConfFileText.SetValue(ToolChainConfFile)
379 self.Model.TargetTxtDictionary['TOOL_CHAIN_CONF'][0] = self.ToolChainConfFileText.GetValue()
380 self.OnRefreshClick(self)
381 dialog.Destroy()
382
383 def OnMultipleThreadRadioBox (self, event):
384 self.Model.TargetTxtDictionary['MULTIPLE_THREAD'] = [self.MultipleThreadRadioBox.GetStringSelection()]
385 if self.MultipleThreadRadioBox.GetStringSelection() == 'Disable':
386 self.ThreadsSpinCtrl.Disable()
387 else:
388 self.ThreadsSpinCtrl.Enable()
389
390 def OnThreadsSpinCtrl(self, event):
391 self.Model.TargetTxtDictionary['MAX_CONCURRENT_THREAD_NUMBER'] = [str(self.ThreadsSpinCtrl.GetValue())]
392
393 def CheckListFocus(self, CheckListBox, Set):
394 Index = 0
395 while Index < CheckListBox.GetCount():
396 CheckListBox.SetSelection(Index, False)
397 Index += 1
398 if Set:
399 CheckListBox.SetSelection(0, True)
400
401 def CheckListClick(self, CheckListBox, Name):
402 if CheckListBox.IsChecked(0):
403 Index = 1
404 while Index < CheckListBox.GetCount():
405 CheckListBox.Check(Index, False)
406 Index += 1
407 if CheckListBox.IsChecked(0):
408 self.Model.TargetTxtDictionary[Name] = ['']
409 else:
410 self.Model.TargetTxtDictionary[Name] = []
411 Index = 1
412 while Index < CheckListBox.GetCount():
413 if CheckListBox.IsChecked(Index):
414 self.Model.TargetTxtDictionary[Name] += [CheckListBox.GetString(Index)]
415 Index += 1
416 if self.Model.TargetTxtDictionary[Name] == []:
417 self.Model.TargetTxtDictionary[Name] = ['']
418
419 def OnTargetCheckListClick(self, event):
420 self.CheckListClick(self.TargetCheckListBox, 'TARGET')
421
422 def OnTargetSetFocus(self, event):
423 self.CheckListFocus(self.TargetCheckListBox, True)
424
425 def OnTargetKillFocus(self, event):
426 self.CheckListFocus(self.TargetCheckListBox, False)
427
428 def OnToolChainTagCheckListClick(self, event):
429 self.CheckListClick(self.ToolChainTagCheckListBox, 'TOOL_CHAIN_TAG')
430
431 def OnToolChainTagSetFocus(self, event):
432 self.CheckListFocus(self.ToolChainTagCheckListBox, True)
433
434 def OnToolChainTagKillFocus(self, event):
435 self.CheckListFocus(self.ToolChainTagCheckListBox, False)
436
437 def OnTargetArchCheckListClick(self, event):
438 self.CheckListClick(self.TargetArchCheckListBox, 'TARGET_ARCH')
439
440 def OnTargetArchSetFocus(self, event):
441 self.CheckListFocus(self.TargetArchCheckListBox, True)
442
443 def OnTargetArchKillFocus(self, event):
444 self.CheckListFocus(self.TargetArchCheckListBox, False)
445
446 def OnRevertClick(self, event):
447 self.Model.RevertModel()
448 self.OnRefreshClick(self)
449
450 def RefreshCheckListBox(self, CheckListBox, Name):
451 CheckListBox.Set(['All'] + self.Model.ToolsDefTxtDatabase[Name])
452 Index = 0
453 MaximumString = ''
454 while Index < CheckListBox.GetCount():
455 String = CheckListBox.GetString(Index)
456 if len(String) > len(MaximumString):
457 MaximumString = String
458 if String in self.Model.TargetTxtDictionary[Name]:
459 CheckListBox.Check(Index, True)
460 else:
461 CheckListBox.Check(Index, False)
462 Index += 1
463 if self.Model.TargetTxtDictionary[Name] == ['']:
464 CheckListBox.Check(0, True)
465 Extents = CheckListBox.GetFullTextExtent (MaximumString)
466 CheckListBox.SetMinSize((Extents[0],(CheckListBox.GetCount()+1) * (Extents[1]+Extents[2])))
467
468 def OnRefreshClick(self, event):
469 self.Model.RefreshModel()
470 Platforms = self.Model.PlatformDatabase.keys()
471 Platforms.sort()
472 self.ActivePlatformText.SetItems([' [Build Directory]'] + Platforms)
473 self.ActivePlatformText.SetValue(' [Build Directory]')
474 for Platform in self.Model.PlatformDatabase:
475 if self.Model.PlatformDatabase[Platform]['XmlFileName'] == self.Model.TargetTxtDictionary['ACTIVE_PLATFORM'][0]:
476 self.ActivePlatformText.SetValue(Platform)
477 if self.ActivePlatformText.GetValue() == ' [Build Directory]':
478 self.Model.TargetTxtDictionary['ACTIVE_PLATFORM'][0] = ''
479 MaximumString = ' [Build Directory]'
480 for String in Platforms:
481 if len(String) > len(MaximumString):
482 MaximumString = String
483 Extents = self.ActivePlatformText.GetFullTextExtent (MaximumString)
484 self.ActivePlatformText.SetMinSize((Extents[0] + 24,-1))
485
486 self.ToolChainConfFileText.SetValue(self.Model.TargetTxtDictionary['TOOL_CHAIN_CONF'][0])
487 Extents = self.ToolChainConfFileText.GetFullTextExtent (self.Model.TargetTxtDictionary['TOOL_CHAIN_CONF'][0])
488 self.ToolChainConfFileText.SetMinSize((Extents[0] + 24,-1))
489
490 self.MultipleThreadRadioBox.SetStringSelection(self.Model.TargetTxtDictionary['MULTIPLE_THREAD'][0])
491 if self.MultipleThreadRadioBox.GetStringSelection() == 'Disable':
492 self.ThreadsSpinCtrl.Disable()
493 self.ThreadsSpinCtrl.SetValue(int(self.Model.TargetTxtDictionary['MAX_CONCURRENT_THREAD_NUMBER'][0]))
494
495 self.RefreshCheckListBox (self.TargetCheckListBox, 'TARGET')
496 self.RefreshCheckListBox (self.ToolChainTagCheckListBox, 'TOOL_CHAIN_TAG')
497 self.RefreshCheckListBox (self.TargetArchCheckListBox, 'TARGET_ARCH')
498
499 self.mainSizer.SetSizeHints(self)
500 self.mainSizer.Fit(self)
501
502 def OnViewRefreshClick(self, event):
503 self.Model.RescanModel()
504 self.OnRefreshClick(self)
505
506 def AddTool (self, Handler, ArtId, Label, HelpText):
507 Tool = self.ToolBar.AddSimpleTool(
508 -1,
509 wx.ArtProvider.GetBitmap(ArtId, wx.ART_TOOLBAR, self.ToolSize),
510 Label,
511 HelpText
512 )
513 self.Bind(wx.EVT_MENU, Handler, Tool)
514
515 def OnShowToolBarClick(self, event):
516 if self.ShowToolBar:
517 self.ShowToolBar = False
518 self.ToolBar.Destroy()
519 else:
520 self.ShowToolBar = True
521 self.ToolBar = self.CreateToolBar()
522 self.ToolSize = (24,24)
523 self.ToolBar.SetToolBitmapSize(self.ToolSize)
524 self.AddTool (self.OnNewClick, wx.ART_NEW, "New", "New target.txt")
525 self.AddTool (self.OnSaveClick, wx.ART_FILE_SAVE, "Save", "Save target.txt")
526 self.AddTool (self.OnSaveAsClick, wx.ART_FILE_SAVE_AS, "Save As...", "Save target.txt as...")
527 self.AddTool (self.OnRevertClick, wx.ART_UNDO, "Revert", "Revert to original target.txt")
528 self.AddTool (self.OnHelpClick, wx.ART_HELP, "Help", "Context Sensitive Help")
529 self.AddTool (self.OnExitClick, wx.ART_QUIT, "Exit", "Exit Context Tool application")
530 self.ToolBar.Realize()
531
532 def OnNewClick(self, event):
533 self.Model.NewModel()
534 self.OnRefreshClick(self)
535
536 def OnSaveClick(self, event):
537 self.Model.SaveModel()
538
539 def OnSaveAsClick(self, event):
540 wildcard = "Text Documents (*.txt)|*.txt|" \
541 "All files (*.*)|*.*"
542 dialog = wx.FileDialog (None, 'Save As', self.Model.WorkspaceFile('Tools/Conf'), '', wildcard, wx.SAVE | wx.OVERWRITE_PROMPT)
543 if dialog.ShowModal() == wx.ID_OK:
544 TargetTxtFile = self.Model.WorkspaceRelativePath(dialog.GetPath())
545 if TargetTxtFile != '':
546 self.Model.SaveModel(TargetTxtFile)
547 dialog.Destroy()
548
549 def OnExitClick(self, event):
550 if self.Model.ModelModified():
551 dialog = wx.MessageDialog(None, 'The contents have changed.\nDo you want to save changes?', 'EDK II Build System Context Tool', style = wx.YES_NO | wx.YES_DEFAULT | wx.CANCEL | wx.ICON_EXCLAMATION)
552 Status = dialog.ShowModal()
553 dialog.Destroy()
554 if Status == wx.ID_YES:
555 self.OnSaveClick (self)
556 elif Status == wx.ID_CANCEL:
557 return
558 self.Model.CloseModel()
559 self.Close()
560
561 def OnHelpClick(self, event):
562 wx.ContextHelp().BeginContextHelp()
563
564 def OnAboutClick(self, event):
565 AboutInfo = wx.AboutDialogInfo()
566 AboutInfo.Name = 'EDK II Build System Context Tool'
567 AboutInfo.Version = '0.3'
568 AboutInfo.Copyright = 'Copyright (c) 2006, Intel Corporation'
569 AboutInfo.Description = """
570 The EDK II Build System Context Tool maintains the target.txt
571 settings in an EDK II Workspace."""
572 AboutInfo.WebSite = ("http://tianocore.org", "Tiano Core home page")
573 AboutInfo.License = """
574 All rights reserved. This program and the accompanying materials are
575 licensed and made available under the terms and conditions of the BSD
576 License which accompanies this distribution. The full text of the
577 license may be found at http://opensource.org/licenses/bsd-license.php
578
579 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
580 BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
581 EITHER EXPRESS OR IMPLIED."""
582 if self.Model.Icon != None:
583 AboutInfo.Icon = self.Model.Icon
584 wx.AboutBox(AboutInfo)
585
586 if __name__ == '__main__':
587 app = wx.PySimpleApp()
588 frame = Frame()
589 frame.Show()
590 app.MainLoop()