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