def write(self, output, tabs): inner_xml = [] for (name,), window in zip(self.owner.tabs, self.owner.children): # XXX what happens with empty pages? if window: inner_xml += common.format_xml_tag(u'tab', name, tabs+1, window=window.name) output.extend( common.format_xml_tag(u'tabs', inner_xml, tabs, is_xml=True) )
def write(self, output, tabs): arguments = self.get() if arguments: inner_xml = [] for argument in arguments: inner_xml += common.format_xml_tag(u'argument', argument, tabs+1) output.extend( common.format_xml_tag( u'arguments', inner_xml, tabs, is_xml=True) )
def _format_bitmap_property(self, name, val): """\ Return formatted bitmap/icon XRC property. @rtype: str | None """ if val.startswith('art:'): content = val[4:] elements = [item.strip() for item in content.split(',')] art_id = elements[0] art_client = elements[1] if art_client != 'wxART_OTHER': prop = common.format_xml_tag(name, '', stock_id=art_id, stock_client=art_client) else: prop = common.format_xml_tag(name, u'', stock_id=art_id) elif val.startswith('code:') or val.startswith('empty:') or \ val.startswith('var:'): self._logger.warn( _('XRC: Unsupported bitmap statement "%s" for %s "%s"'), val, self.klass, self.name) prop = None else: prop = common.format_xml_tag(name, val) return prop
def write(self, output, tabs): value = self.get() if value: inner_xml = [] for label, size in value: inner_xml += common.format_xml_tag(u'column', label, tabs+1, size=size) output.extend( common.format_xml_tag(u'columns', inner_xml, tabs, is_xml=True) )
def write(self, output, tabs): inner_xml = [] for event, handler in self.get(): if handler: inner_xml += common.format_xml_tag('handler', handler, tabs+1, event=event) if inner_xml: output.extend( common.format_xml_tag(u'events', inner_xml, tabs, is_xml=True) )
def write(self, output, tabs): outer_tab = u' ' * tabs stmt = [u'%s<templatedata>\n' % outer_tab] stmt += common.format_xml_tag(u'author', self.author, tabs + 1) stmt += common.format_xml_tag(u'description', self.description, tabs + 1) stmt += common.format_xml_tag(u'instructions', self.instructions, tabs + 1) stmt.append( u'%s</templatedata>\n' % outer_tab ) output.extend(stmt)
def write(self, outfile, tabs): outer_tab = u' ' * tabs stmt = u'%s<templatedata>\n' % outer_tab stmt += common.format_xml_tag(u'author', self.author, tabs + 1) stmt += common.format_xml_tag(u'description', self.description, tabs + 1) stmt += common.format_xml_tag(u'instructions', self.instructions, tabs + 1) stmt += u'%s</templatedata>\n' % outer_tab outfile.write(stmt)
def write(self, output, tabs): inner_xml = [] for label, width in self.value: inner_xml += common.format_xml_tag(u'field', label, tabs + 1, width=width) output.extend( common.format_xml_tag(u'fields', inner_xml, tabs, is_xml=True))
def write(self, outfile, tabs): if not self.value: return inner_xml = u'' for name, value in self.value: if value: inner_xml += common.format_xml_tag( u'property', value.strip(), tabs+1, name=name ) if inner_xml: stmt = common.format_xml_tag( u'extraproperties', inner_xml, tabs, is_xml=True ) outfile.write(stmt)
def write(self, outfile, tabs): inner_xml = u'' for label, size in self.get(): inner_xml += common.format_xml_tag(u'column', label, tabs + 1, size=size) stmt = common.format_xml_tag(u'columns', inner_xml, tabs, is_xml=True) outfile.write(stmt)
def write(self, outfile, tabs): inner_xml = u'' for (name, ), window in zip(self.owner.tabs, self.owner.pages): # XXX what happens with empty pages? if window: inner_xml += common.format_xml_tag(u'tab', name, tabs + 1, window=window.name) stmt = common.format_xml_tag(u'tabs', inner_xml, tabs, is_xml=True) outfile.write(stmt)
def write(self, outfile, tabs): arguments = self.get() if arguments: inner_xml = u'' for argument in arguments: inner_xml += common.format_xml_tag(u'argument', argument[0], tabs + 1) stmt = common.format_xml_tag(u'arguments', inner_xml, tabs, is_xml=True) outfile.write(stmt)
def write(self, output, tabs): inner_xml = [] #for val in self.get_value(): for val in self.get(): value = common.encode_to_unicode(val[0]) # only first column is used try: checked = int(val[1]) except (IndexError, ValueError): checked = None if checked is None: inner_xml += common.format_xml_tag(u'choice', value, tabs+1) else: inner_xml += common.format_xml_tag(u'choice', value, tabs+1, checked="%s" % checked) output.extend( common.format_xml_tag(u'choices', inner_xml, tabs, is_xml=True) )
def write(self, output, tabs): is_default = True inner_xml = [] rows = self.get() for i, (label, size) in enumerate(rows): if size!=-1 or label!=str(i): is_default=False inner_xml += common.format_xml_tag(u'row', label, tabs+1, size=size) if not is_default: # actually write labels and sizes output.extend( common.format_xml_tag(u'rows', inner_xml, tabs, is_xml=True) ) else: # just write the number of rows output.extend( common.format_xml_tag(u'rows_number', str(len(rows)), tabs) )
def write(self, output, tabs): inner_xml = format_xml_tag(u'id', self.id, tabs + 1) inner_xml += format_xml_tag(u'label', self.label, tabs + 1) inner_xml += format_xml_tag(u'type', self.type, tabs + 1) inner_xml += format_xml_tag(u'short_help', self.short_help, tabs + 1) inner_xml += format_xml_tag(u'long_help', self.long_help, tabs + 1) inner_xml += format_xml_tag(u'bitmap1', self.bitmap1, tabs + 1) inner_xml += format_xml_tag(u'bitmap2', self.bitmap2, tabs + 1) if self.handler: inner_xml += format_xml_tag(u'handler', self.handler, tabs + 1) output.extend(format_xml_tag(u'tool', inner_xml, tabs, is_xml=True))
def write(self, outfile, tabs): inner_xml = u'' for event, handler in self.get(): handler = handler.strip() if handler: inner_xml += common.format_xml_tag('handler', handler, tabs + 1, event=event) if inner_xml: stmt = common.format_xml_tag(u'events', inner_xml, tabs, is_xml=True) outfile.write(stmt)
def write(self, output, tabs=0): """Writes the xml equivalent of this tree to the given output file. This function writes unicode to the outfile.""" # XXX move this to application.Application timestring = time.asctime() if not config.testing else 'XXX XXX NN NN:NN:NN NNNN' output.append( u'<?xml version="1.0"?>\n' u'<!-- generated by wxGlade %s on %s -->\n\n' % (config.version, timestring) ) attrs = ["name","class","language","top_window","encoding","use_gettext", "overwrite", "mark_blocks", "for_version","is_template","indent_amount"] props = [self.properties[attr] for attr in attrs] attrs = dict( (attr,prop.get_string_value()) for attr,prop in zip(attrs,props) if not prop.deactivated ) top_window_p = self.properties["top_window"] if top_window_p.deactivated and top_window_p.value: attrs["top_window"] = top_window_p.value attrs["option"] = self.properties["multiple_files"].get_string_value() attrs["indent_symbol"] = self.properties["indent_mode"].get_string_value() attrs["path"] = self.properties["output_path"].get_string_value() attrs['use_new_namespace'] = 1 # add a . to the file extensions attrs["source_extension"] = '.' + self.properties["source_extension"].get_string_value() attrs["header_extension"] = '.' + self.properties["header_extension"].get_string_value() inner_xml = [] if self.is_template and getattr(self, 'template_data', None): self.template_data.write(inner_xml, tabs+1) for c in self.children: c.write(inner_xml, tabs+1) output.extend( common.format_xml_tag( u'application', inner_xml, is_xml=True, **attrs ) )
def write(self, outfile, tabs, class_names=None): "Writes the xml code for the widget to the given output file" # XXX move this to the widget import edit_sizers fwrite = outfile.write assert self.widget is not None # write object tag, including class, name, base classname = getattr(self.widget, '_classname', self.widget.__class__.__name__) # to disable custom class code generation (for panels...) if getattr(self.widget, 'no_custom_class', False): no_custom = u' no_custom_class="1"' else: no_custom = "" outer_tabs = u' ' * tabs fwrite(u'%s<object %s %s %s%s>\n' % (outer_tabs, common.format_xml_attrs(**{'class': self.widget.klass}), common.format_xml_attrs(name=self.widget.name), common.format_xml_attrs(base=classname), no_custom)) # write properties, but without name and class # XXX be 100% compatible to 0.7.2, where option is written into the object; remove later properties = self.widget.get_properties( without=set(edit_sizers.SizerBase.MANAGED_PROPERTIES)) #properties = self.widget.get_properties(without=set(["pos","flag","border"])) for prop in properties: prop.write(outfile, tabs + 1) if class_names is not None and self.widget.__class__.__name__ != 'CustomWidget': class_names.add(self.widget.klass) if isinstance(self.widget, edit_sizers.SizerBase): for child in self.children or []: if not isinstance(child, SlotNode): # hasattr(child, 'widget'): inner_xml = compat.StringIO() for name in edit_sizers.SizerBase.MANAGED_PROPERTIES: name = child.widget.properties[name] if name is not None: name.write(inner_xml, tabs + 2) child.write(inner_xml, tabs + 2, class_names) stmt = common.format_xml_tag(u'object', inner_xml.getvalue(), tabs + 1, is_xml=True, **{'class': 'sizeritem'}) fwrite(stmt) else: child.write(outfile, tabs + 1) elif self.children is not None: for child in self.children: child.write(outfile, tabs + 1, class_names) fwrite(u'%s</object>\n' % outer_tabs)
def write(self, output, tabs, top=False): inner_xml = [] if not top and not self.children: if self.label: inner_xml += format_xml_tag(u'label', self.label, tabs + 1) if self.id: inner_xml += format_xml_tag(u'id', self.id, tabs + 1) if self.name: inner_xml += format_xml_tag(u'name', self.name, tabs + 1) if self.help_str: inner_xml += format_xml_tag(u'help_str', self.help_str, tabs + 1) try: checkable = int(self.checkable) except ValueError: checkable = 0 if checkable: inner_xml += format_xml_tag(u'checkable', checkable, tabs + 1) try: radio = int(self.radio) except ValueError: radio = 0 if radio: inner_xml += format_xml_tag(u'radio', radio, tabs + 1) if self.handler: inner_xml += format_xml_tag(u'handler', self.handler, tabs + 1) output.extend( format_xml_tag(u'item', inner_xml, tabs, is_xml=True)) else: attrs = {'name': self.name} if self.id: attrs[u'itemid'] = self.id if self.handler: attrs[u'handler'] = self.handler attrs[u'label'] = self.label inner_xml = [] for c in self.children: c.write(inner_xml, tabs + 1) output.extend( format_xml_tag(u'menu', inner_xml, tabs, is_xml=True, **attrs))
def write(self, output, tabs): "Writes the xml code for the widget to the given output file" # write object tag, including class, name, base classname = self.get_editor_name() # to disable custom class code generation (for panels...) outer_tabs = u' ' * tabs instance_class = '' if "class" in self.properties: klass = self.get_prop_value("class", default=self.WX_CLASS) if self.check_prop_truth("instance_class"): instance_class = " " + common.format_xml_attrs( instance_class=self.instance_class) else: klass = self.get_prop_value("instance_class", default=self.WX_CLASS) output.append( u'%s<object %s %s %s%s>\n' % (outer_tabs, common.format_xml_attrs(**{'class': klass}), common.format_xml_attrs(name=self.name), common.format_xml_attrs(base=classname), instance_class)) if config.debugging and getattr(self, "_restore_properties", None): raise ValueError("properties not restored") self.restore_properties() # write properties, but without name and class # XXX be 100% compatible to 0.7.2, where option is written into the object; remove later properties = self.get_properties(without=set(MANAGED_PROPERTIES)) for prop in properties: prop.write(output, tabs + 1) if self.IS_SIZER: for child in self.children or []: if not child.IS_SLOT: inner_xml = [] for name in MANAGED_PROPERTIES: name = child.properties[name] if name is not None: name.write(inner_xml, tabs + 2) child.write(inner_xml, tabs + 2) stmt = common.format_xml_tag(u'object', inner_xml, tabs + 1, is_xml=True, **{'class': 'sizeritem'}) output.extend(stmt) else: child.write(output, tabs + 1) elif self.children is not None or self.ATT_CHILDREN is not None: for child in self.get_all_children(): assert not config.debugging or child is not None child.write(output, tabs + 1) output.append(u'%s</object>\n' % outer_tabs)
def write_property(self, name, val, outfile, ntabs): if not val: return if name in ['icon', 'bitmap']: prop = self._format_bitmap_property(name, val) else: prop = common.format_xml_tag(name, val) if prop: line = '%s%s' % (self.tabs(ntabs), prop) outfile.write(line)
def write(self, outfile, tabs, top=False): inner_xml = u'' if not top and not self.children: if self.label: inner_xml += format_xml_tag( u'label', self.label, tabs + 1) if self.id: inner_xml += format_xml_tag(u'id', self.id, tabs+1) if self.name: inner_xml += format_xml_tag(u'name', self.name, tabs+1) if self.help_str: inner_xml += format_xml_tag(u'help_str', self.help_str, tabs+1) try: checkable = int(self.checkable) except ValueError: checkable = 0 if checkable: inner_xml += format_xml_tag( u'checkable', checkable, tabs + 1) try: radio = int(self.radio) except ValueError: radio = 0 if radio: inner_xml += format_xml_tag(u'radio', radio, tabs+1) if self.handler: inner_xml += format_xml_tag(u'handler', self.handler, tabs+1) stmt = format_xml_tag(u'item', inner_xml, tabs, is_xml=True) else: attrs = {'name': self.name} if self.id: attrs[u'itemid'] = self.id if self.handler: attrs[u'handler'] = self.handler attrs[u'label'] = self.label value = compat.StringIO() for c in self.children: c.write(value, tabs + 1) inner_xml = value.getvalue() stmt = format_xml_tag( u'menu', inner_xml, tabs, is_xml=True, **attrs ) outfile.write(stmt)
def write(self, output, tabs): "Writes the xml code for the widget to the given output file" # write object tag, including class, name, base #classname = getattr(self, '_classname', self.__class__.__name__) #if classname=="EditToplevelMenuBar": classname = "EditMenuBar" classname = self.get_editor_name() # to disable custom class code generation (for panels...) if getattr(self, 'no_custom_class', False): no_custom = u' no_custom_class="1"' else: no_custom = "" outer_tabs = u' ' * tabs output.append( u'%s<object %s %s %s%s>\n' % (outer_tabs, common.format_xml_attrs(**{'class': self.klass}), common.format_xml_attrs(name=self.name), common.format_xml_attrs(base=classname), no_custom)) if config.debugging and getattr(self, "_restore_properties", None): raise ValueError("properties not restored") self.restore_properties() # write properties, but without name and class # XXX be 100% compatible to 0.7.2, where option is written into the object; remove later properties = self.get_properties(without=set(MANAGED_PROPERTIES)) for prop in properties: prop.write(output, tabs + 1) if self.IS_SIZER: for child in self.children or []: if not child.IS_SLOT: inner_xml = [] for name in MANAGED_PROPERTIES: name = child.properties[name] if name is not None: name.write(inner_xml, tabs + 2) child.write(inner_xml, tabs + 2) stmt = common.format_xml_tag(u'object', inner_xml, tabs + 1, is_xml=True, **{'class': 'sizeritem'}) output.extend(stmt) else: child.write(output, tabs + 1) elif self.children is not None or self.ATT_CHILDREN is not None: for child in self.get_all_children(): assert not config.debugging or child is not None child.write(output, tabs + 1) output.append(u'%s</object>\n' % outer_tabs)
def write(self, outfile=None, tabs=0): """Writes the xml equivalent of this tree to the given output file. This function writes unicode to the outfile.""" # XXX move this to application.Application if outfile is None: outfile = sys.stdout outfile.write(u'<?xml version="1.0"?>\n' u'<!-- generated by wxGlade %s on %s -->\n\n' % (config.version, time.asctime())) outpath = os.path.normpath( os.path.expanduser(self.app.output_path.strip())) attrs = [ "name", "class", "language", "top_window", "encoding", "use_gettext", "overwrite", "for_version", "is_template", "indent_amount" ] attrs = dict((prop, self.app.properties[prop].get_str_value()) for prop in attrs) attrs["option"] = self.app.properties["multiple_files"].get_str_value() attrs["indent_symbol"] = self.app.properties[ "indent_mode"].get_str_value() attrs["path"] = outpath attrs['use_new_namespace'] = 1 # add a . to the file extensions attrs["source_extension"] = '.' + self.app.properties[ "source_extension"].get_str_value() attrs["header_extension"] = '.' + self.app.properties[ "header_extension"].get_str_value() inner_xml = compat.StringIO() if self.app.is_template and getattr(self.app, 'template_data', None): self.app.template_data.write(inner_xml, tabs + 1) class_names = set() if self.root.children is not None: for c in self.root.children: c.write(inner_xml, tabs + 1, class_names) stmt = common.format_xml_tag(u'application', inner_xml.getvalue(), is_xml=True, **attrs) outfile.write(stmt) return class_names
def write(self, output, tabs, class_names=None): if self.widget.sizer is None or self.widget.sizer.is_virtual(): return output.extend( common.format_xml_tag(u'object', '', tabs, **{'class': 'sizerslot'}))
def write(self, outfile, tabs=0): value = self.get() if value is not None: stmt = common.format_xml_tag(self.name, value, tabs) outfile.write(stmt)
def write(self, output, tabs): if self.parent.CHILDREN == -1: output.extend( common.format_xml_tag(u'object', '', tabs, **{'class': 'slot'}))
def write(self, output, tabs=0): value = self.get() if value is not None: output.extend(common.format_xml_tag(self.name, value, tabs))
def write(self, output, tabs): inner_xml = [] for tool in self.get(): tool.write(inner_xml, tabs+1) output.extend( common.format_xml_tag( u'tools', inner_xml, tabs, is_xml=True) )
def write(self, output, tabs): inner_xml = [] for menu in self.get(): menu.write(inner_xml, tabs + 1) output.extend( common.format_xml_tag(u'menus', inner_xml, tabs, is_xml=True))