def write(self, outfile, tabs): fwrite = outfile.write t1 = ' ' * tabs t2 = ' ' * (tabs+1) fwrite(t1 + '<templatedata>\n') fwrite(t2 + '<author>%s</author>\n' % \ saxutils.escape(common._encode_to_xml(self.author))) fwrite(t2 + '<description>%s</description>\n' % \ saxutils.escape(common._encode_to_xml(self.description))) fwrite(t2 + '<instructions>%s</instructions>\n' % \ saxutils.escape(common._encode_to_xml(self.instructions))) fwrite(t1 + '</templatedata>\n')
def write(self, outfile, tabs): fwrite = outfile.write t1 = ' ' * tabs t2 = ' ' * (tabs + 1) fwrite(t1 + '<templatedata>\n') fwrite(t2 + '<author>%s</author>\n' % \ saxutils.escape(common._encode_to_xml(self.author))) fwrite(t2 + '<description>%s</description>\n' % \ saxutils.escape(common._encode_to_xml(self.description))) fwrite(t2 + '<instructions>%s</instructions>\n' % \ saxutils.escape(common._encode_to_xml(self.instructions))) fwrite(t1 + '</templatedata>\n')
def save_preferences(): # let the exception be raised if 'WXGLADE_CONFIG_PATH' in os.environ: path = os.path.expandvars('$WXGLADE_CONFIG_PATH') else: path = _get_appdatapath() if path != common.wxglade_path: path = os.path.join(path, '.wxglade') if not os.path.isdir(path): os.mkdir(path) # always save the file history if _use_file_history: fh = common.palette.file_history if misc.check_wx_version(2, 5): count = fh.GetCount() else: count = fh.GetNoHistoryFiles() encoding = 'utf-8' filenames = [ common._encode_to_xml(fh.GetHistoryFile(i), encoding) for i in range(min(preferences.number_history, count)) ] outfile = open(os.path.join(path, 'file_history.txt'), 'w') print >> outfile, "# -*- coding: %s -*-" % encoding for filename in filenames: print >> outfile, filename outfile.close() if preferences.changed: outfile = open(os.path.join(path, _rc_name), 'w') # let the exception be raised to signal abnormal behaviour preferences.write(outfile) outfile.close()
def save_preferences(): # let the exception be raised if 'WXGLADE_CONFIG_PATH' in os.environ: path = os.path.expandvars('$WXGLADE_CONFIG_PATH') else: path = _get_appdatapath() if path != common.wxglade_path: path = os.path.join(path, '.wxglade') if not os.path.isdir(path): os.mkdir(path) # always save the file history if _use_file_history: fh = common.palette.file_history if misc.check_wx_version(2, 5): count = fh.GetCount() else: count = fh.GetNoHistoryFiles() encoding = 'utf-8' filenames = [common._encode_to_xml(fh.GetHistoryFile(i), encoding) for i in range(min(preferences.number_history, count))] outfile = open(os.path.join(path, 'file_history.txt'), 'w') print >> outfile, "# -*- coding: %s -*-" % encoding for filename in filenames: print >> outfile, filename outfile.close() if preferences.changed: outfile = open(os.path.join(path, _rc_name), 'w') # let the exception be raised to signal abnormal behaviour preferences.write(outfile) outfile.close()
def write(self, outfile, tabs, top=False): from xml.sax.saxutils import escape, quoteattr import common fwrite = outfile.write tstr = ' ' * (tabs + 1) label = common._encode_to_xml(self.label) help_str = common._encode_to_xml(self.help_str) if not top and not self.children: fwrite('%s<item>\n' % (' ' * tabs)) label = escape(label) if label: fwrite('%s<label>%s</label>\n' % (tstr, label)) id = escape(self.id) if id: fwrite('%s<id>%s</id>\n' % (tstr, id)) name = escape(self.name) if name: fwrite('%s<name>%s</name>\n' % (tstr, name)) help_str = escape(help_str) if help_str: fwrite('%s<help_str>%s</help_str>\n' % (tstr, help_str)) try: checkable = int(self.checkable) except: checkable = 0 if checkable: fwrite('%s<checkable>%s</checkable>\n' % (tstr, checkable)) try: radio = int(self.radio) except: radio = 0 if radio: fwrite('%s<radio>%s</radio>\n' % (tstr, radio)) # ALB 2004-12-05 handler = escape(self.handler.strip()) if handler: fwrite('%s<handler>%s</handler>\n' % (tstr, handler)) fwrite('%s</item>\n' % (' ' * tabs)) else: name = quoteattr(self.name) fwrite(' ' * tabs + '<menu name=%s ' % name) if self.id: fwrite('itemid=%s ' % quoteattr(self.id)) if self.handler: fwrite('handler=%s ' % quoteattr(self.handler)) fwrite('label=%s>\n' % (quoteattr(label))) for c in self.children: c.write(outfile, tabs + 1) fwrite(' ' * tabs + '</menu>\n')
def write(self, outfile, tabs, top=False): from xml.sax.saxutils import escape, quoteattr import common fwrite = outfile.write tstr = ' ' * (tabs+1) label = common._encode_to_xml(self.label) help_str = common._encode_to_xml(self.help_str) if not top and not self.children: fwrite('%s<item>\n' % (' ' * tabs)) label = escape(label) if label: fwrite('%s<label>%s</label>\n' % (tstr, label)) id = escape(self.id) if id: fwrite('%s<id>%s</id>\n' % (tstr, id)) name = escape(self.name) if name: fwrite('%s<name>%s</name>\n' % (tstr, name)) help_str = escape(help_str) if help_str: fwrite('%s<help_str>%s</help_str>\n' % (tstr, help_str)) try: checkable = int(self.checkable) except: checkable = 0 if checkable: fwrite('%s<checkable>%s</checkable>\n' % (tstr, checkable)) try: radio = int(self.radio) except: radio = 0 if radio: fwrite('%s<radio>%s</radio>\n' % (tstr, radio)) # ALB 2004-12-05 handler = escape(self.handler.strip()) if handler: fwrite('%s<handler>%s</handler>\n' % (tstr, handler)) fwrite('%s</item>\n' % (' ' * tabs)) else: name = quoteattr(self.name) fwrite(' ' * tabs + '<menu name=%s ' % name) if self.id: fwrite('itemid=%s ' % quoteattr(self.id)) if self.handler: fwrite('handler=%s ' % quoteattr(self.handler)) fwrite('label=%s>\n' % (quoteattr(label))) for c in self.children: c.write(outfile, tabs+1) fwrite(' ' * tabs + '</menu>\n')
def write(self, outfile=None, tabs=0): """\ Writes the xml equivalent of this tree to the given output file """ if outfile is None: import sys outfile = sys.stdout from time import asctime outfile.write('<?xml version="1.0"?>\n<!-- generated by wxGlade %s ' \ 'on %s -->\n\n' % (common.version, asctime())) outpath = os.path.expanduser(self.app.output_path.strip()) name = self.app.get_name() klass = self.app.get_class() option = str(self.app.codegen_opt) top_window = self.app.get_top_window() language = self.app.get_language() encoding = self.app.get_encoding() use_gettext = str(int(self.app.use_gettext)) is_template = str(int(self.app.is_template)) overwrite = str(int(self.app.overwrite)) indent_amount = str(int(self.app.indent_amount)) indent_symbol = int(self.app.indent_mode) if indent_symbol == 0: indent_symbol = "tab" else: indent_symbol = "space" source_ext = '.' + self.app.source_ext header_ext = '.' + self.app.header_ext # ALB 2004-01-18 #use_new_namespace = str(int(self.app.get_use_new_namespace())) use_new_namespace = str(int(not self.app.get_use_old_namespace())) # ALB 2004-12-05 for_version = str(self.app.for_version) outfile.write('<application path=%s name=%s class=%s option=%s ' \ 'language=%s top_window=%s encoding=%s ' \ 'use_gettext=%s overwrite=%s ' 'use_new_namespace=%s for_version=%s is_template=%s '\ 'indent_amount=%s indent_symbol=%s '\ 'source_extension=%s header_extension=%s>\n' \ % tuple([quoteattr(common._encode_to_xml(i)) for i in (outpath, name, klass, option, language, top_window, encoding, use_gettext, overwrite, use_new_namespace, for_version, is_template, indent_amount, indent_symbol, source_ext, header_ext)])) if self.app.is_template and getattr(self.app, 'template_data', None): self.app.template_data.write(outfile, tabs+1) class_names = set() if self.root.children is not None: for c in self.root.children: c.write(outfile, tabs+1, class_names) outfile.write('</application>\n') return class_names
def get_relative_path(path, for_preview=False): """\ Get an absolute path relative to the current output directory (where the code is generated). """ if os.path.isabs(path): return path p = common.app_tree.app.output_path if for_preview: p = getattr(common.app_tree.app, 'real_output_path', '') p = common._encode_from_xml(common._encode_to_xml(p)) d = os.path.dirname(p) if d: path = os.path.join(d, path) else: path = os.path.abspath(path) return path
def get_relative_path(path, for_preview=False): """\ Get an absolute path relative to the current output directory (where the code is generated). """ import os if os.path.isabs(path): return path p = common.app_tree.app.output_path if for_preview: p = getattr(common.app_tree.app, 'real_output_path', '') p = common._encode_from_xml(common._encode_to_xml(p)) d = os.path.dirname(p) if d: path = os.path.join(d, path) else: path = os.path.abspath(path) return path
def write(self, outfile=None, tabs=0): """\ Writes the xml equivalent of this tree to the given output file """ if outfile is None: import sys outfile = sys.stdout from time import asctime import common outfile.write('<?xml version="1.0"?>\n<!-- generated by wxGlade %s ' \ 'on %s -->\n\n' % (common.version, asctime())) outpath = os.path.expanduser(self.app.output_path.strip()) name = self.app.get_name() klass = self.app.get_class() option = str(self.app.codegen_opt) top_window = self.app.get_top_window() language = self.app.get_language() encoding = self.app.get_encoding() use_gettext = str(int(self.app.use_gettext)) is_template = str(int(self.app.is_template)) overwrite = str(int(self.app.overwrite)) # ALB 2004-01-18 #use_new_namespace = str(int(self.app.get_use_new_namespace())) use_new_namespace = str(int(not self.app.get_use_old_namespace())) # ALB 2004-12-05 for_version = str(self.app.for_version) outfile.write('<application path=%s name=%s class=%s option=%s ' \ 'language=%s top_window=%s encoding=%s ' \ 'use_gettext=%s overwrite=%s ' 'use_new_namespace=%s for_version=%s is_template=%s>\n' \ % tuple([quoteattr(common._encode_to_xml(i)) for i in (outpath, name, klass, option, language, top_window, encoding, use_gettext, overwrite, use_new_namespace, for_version, is_template)])) if self.app.is_template and getattr(self.app, 'template_data', None): self.app.template_data.write(outfile, tabs+1) class_names = set() if self.root.children is not None: for c in self.root.children: c.write(outfile, tabs+1, class_names) outfile.write('</application>\n') return class_names
def write(self, outfile, tabs): fwrite = outfile.write fwrite(" " * tabs + '<tool>\n') tab_s = " " * (tabs+1) fwrite(tab_s + '<id>%s</id>\n' % escape(_encode_to_xml(self.id))) fwrite(tab_s + '<label>%s</label>\n' % \ escape(_encode_to_xml(self.label))) fwrite(tab_s + '<type>%s</type>\n' % escape(str(self.type))) fwrite(tab_s + '<short_help>%s</short_help>\n' % \ escape(_encode_to_xml(self.short_help))) fwrite(tab_s + '<long_help>%s</long_help>\n' % \ escape(_encode_to_xml(self.long_help))) fwrite(tab_s + '<bitmap1>%s</bitmap1>\n' % \ escape(_encode_to_xml(self.bitmap1))) fwrite(tab_s + '<bitmap2>%s</bitmap2>\n' % \ escape(_encode_to_xml(self.bitmap2))) if self.handler: fwrite(tab_s + '<handler>%s</handler>\n' % \ escape(_encode_to_xml(self.handler.strip()))) fwrite(" " * tabs + '</tool>\n')