def testPseudoControl(self): grd = grd_reader.Parse( StringIO('''<?xml version="1.0" encoding="UTF-8"?> <grit latest_public_release="1" source_lang_id="en-US" current_release="2" base_dir="."> <release seq="1" allow_pseudo="false"> <messages> <message name="IDS_HELLO"> Hello </message> </messages> <structures> <structure type="dialog" name="IDD_ABOUTBOX" encoding="utf-16" file="klonk.rc" /> </structures> </release> <release seq="2"> <messages> <message name="IDS_BINGO"> Bingo </message> </messages> <structures> <structure type="menu" name="IDC_KLONKMENU" encoding="utf-16" file="klonk.rc" /> </structures> </release> </grit>'''), util.PathFromRoot('grit/testdata')) grd.SetOutputLanguage('en') grd.RunGatherers() hello = grd.GetNodeById('IDS_HELLO') aboutbox = grd.GetNodeById('IDD_ABOUTBOX') bingo = grd.GetNodeById('IDS_BINGO') menu = grd.GetNodeById('IDC_KLONKMENU') for node in [hello, aboutbox]: self.failUnless(not node.PseudoIsAllowed()) for node in [bingo, menu]: self.failUnless(node.PseudoIsAllowed()) # TODO(benrg): There was a test here that formatting hello and aboutbox with # a pseudo language should fail, but they do not fail and the test was # broken and failed to catch it. Fix this. # Should not raise an exception since pseudo is allowed rc.FormatMessage(bingo, 'xyz-pseudo') rc.FormatStructure(menu, 'xyz-pseudo', '.')
def Process(self, grd, dialog_ids): '''Outputs an RC file and header file for the dialog 'dialog_id' stored in resource tree 'grd', to self.base_folder, as discussed in this class's documentation. Arguments: grd: grd = grd_reader.Parse(...); grd.RunGatherers() dialog_ids: ['IDD_MYDIALOG', 'IDD_OTHERDIALOG'] ''' grd.SetOutputLanguage(self.lang) grd.SetDefines(self.defines) project_name = dialog_ids[0] dir_path = os.path.join(self.base_folder, project_name) if not os.path.isdir(dir_path): os.mkdir(dir_path) # If this fails then we're not on Windows (or you don't have the required # win32all Python libraries installed), so what are you doing mucking # about with RC files anyway? :) import pythoncom # Create the .vcproj file project_text = PROJECT_TEMPLATE.replace( '[[PROJECT_GUID]]', str(pythoncom.CreateGuid())).replace('[[DIALOG_NAME]]', project_name) fname = os.path.join(dir_path, '%s.vcproj' % project_name) self.WriteFile(fname, project_text) print("Wrote %s" % fname) # Create the .rc file # Output all <include> nodes since the dialogs might depend on them (e.g. # for icons and bitmaps). include_items = [] for node in grd.ActiveDescendants(): if isinstance(node, include.IncludeNode): include_items.append(rc.FormatInclude(node, self.lang, '.')) rc_text = RC_TEMPLATE.replace('[[CODEPAGE_NUM]]', str(self.codepage_number)) rc_text = rc_text.replace('[[INCLUDES]]', ''.join(include_items)) # Then output the dialogs we have been asked to output. dialogs = [] for dialog_id in dialog_ids: node = grd.GetNodeById(dialog_id) assert node.name == 'structure' and node.attrs['type'] == 'dialog' # TODO(joi) Add exception handling for better error reporting dialogs.append(rc.FormatStructure(node, self.lang, '.')) rc_text = rc_text.replace('[[DIALOGS]]', ''.join(dialogs)) fname = os.path.join(dir_path, '%s.rc' % project_name) self.WriteFile(fname, rc_text, self.GetEncoding()) print("Wrote %s" % fname) # Create the resource.h file header_defines = ''.join(rc_header.FormatDefines(grd)) header_text = HEADER_TEMPLATE.replace('[[DEFINES]]', header_defines) fname = os.path.join(dir_path, 'resource.h') self.WriteFile(fname, header_text) print("Wrote %s" % fname)