def endElement(self, name): if name == 'application': self._appl_started = False if self.app_attrs: self.code_writer.add_app(self.app_attrs, self.top_win) # call the finalization function of the code writer self.code_writer.finalize() return if name == 'object': obj = self.pop() if obj.klass in ('sizeritem', 'sizerslot'): return # at the end of the object, we have all the information to add it # to its toplevel parent, or to generate the code for the custom # class if obj.is_toplevel and not obj.in_sizers: self.code_writer.add_class(obj) topl = self._toplevels.top() if topl: self.code_writer.add_object(topl, obj) # if the object is not a sizeritem, check whether it # belongs to some sizer (in this case, # self._sizer_item.top() doesn't return None): if so, # write the code to add it to the sizer at the top of # the stack si = self._sizer_item.top() if si is not None and si.parent == obj.parent: szr = self._sizers.top() if not szr: return self.code_writer.add_sizeritem(topl, szr, obj, si.obj.option, si.obj.flag_str(), si.obj.border) else: # end of a property or error # 1: set _curr_prop value try: encoding = self.app_attrs['encoding'] unicode('a', encoding) except (KeyError, LookupError): encoding = 'ISO-8859-1' data = common._encode_from_xml(u"".join(self._curr_prop_val), encoding) if data: handler = self.top().prop_handlers.top() if not handler or handler.char_data(data): # if char_data returned False, # we don't have to call add_property self.top().add_property(self._curr_prop, data) # 2: call custom end_elem handler try: # if there is a custom handler installed for this property, # call its end_elem function: if this returns True, remove # the handler from the stack obj = self.top() handler = obj.prop_handlers.top() if handler.end_elem(name, obj): obj.prop_handlers.pop() except AttributeError: pass self._curr_prop = None self._curr_prop_val = []
def endElement(self, name): if name == 'application': self._appl_started = False if hasattr(self, 'top_window'): common.app_tree.app.top_window = self.top_window common.app_tree.app.top_win_prop.SetStringSelection( self.top_window) return if name == 'object': # remove last object from the stack obj = self.pop() if obj.klass in ('sizeritem', 'sizerslot'): return si = self._sizer_item.top() if si is not None and si.parent == obj.parent: sprop = obj.obj.sizer_properties # update the values sprop['option'].set_value(si.obj.option) sprop['flag'].set_value(si.obj.flag_str()) sprop['border'].set_value(si.obj.border) # call the setter functions obj.obj['option'][1](si.obj.option) obj.obj['flag'][1](si.obj.flag_str()) obj.obj['border'][1](si.obj.border) else: # end of a property or error # 1: set _curr_prop value data = common._encode_from_xml("".join(self._curr_prop_val)) if data: try: handler = self.top().prop_handlers.top() if not handler or handler.char_data(data): # if char_data returned False, # we don't have to call add_property self.top().add_property(self._curr_prop, data) except AttributeError: pass # 2: call custom end_elem handler try: # if there is a custom handler installed for this property, # call its end_elem function: if this returns True, remove # the handler from the Stack handler = self.top().prop_handlers.top() if handler.end_elem(name): self.top().prop_handlers.pop() except AttributeError: pass self._curr_prop = None self._curr_prop_val = []
def endElement(self, name): if name == 'application': self._appl_started = False if hasattr(self, 'top_window'): common.app_tree.app.top_window = self.top_window common.app_tree.app.top_win_prop.SetStringSelection( self.top_window) return if name == 'object': # remove last object from the stack obj = self.pop() if obj.klass in ('sizeritem', 'sizerslot'): return si = self._sizer_item.top() if si is not None and si.parent == obj.parent: sprop = obj.obj.sizer_properties # update the values sprop['option'].set_value(si.obj.option) sprop['flag'].set_value(si.obj.flag_str()) sprop['border'].set_value(si.obj.border) # call the setter functions obj.obj['option'][1](si.obj.option) obj.obj['flag'][1](si.obj.flag_str()) obj.obj['border'][1](si.obj.border) else: # end of a property or error # 1: set _curr_prop value data = common._encode_from_xml("".join(self._curr_prop_val)) if data: try: handler = self.top().prop_handlers.top() if not handler or handler.char_data(data): # if char_data returned False, # we don't have to call add_property self.top().add_property(self._curr_prop, data) except AttributeError: pass # 2: call custom end_elem handler try: # if there is a custom handler installed for this property, # call its end_elem function: if this returns True, remove # the handler from the Stack handler = self.top().prop_handlers.top() if handler.end_elem(name): self.top().prop_handlers.pop() except AttributeError: pass self._curr_prop = None self._curr_prop_val = []
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 startElement(self, name, attrs_impl): attrs = {} try: encoding = self.app_attrs['encoding'] unicode('a', encoding) except (KeyError, LookupError): if name == 'application': encoding = str(attrs_impl.get( 'encoding', config.default_encoding )) else: encoding = config.default_encoding # turn all the attribute values from unicode to str objects for attr, val in attrs_impl.items(): attrs[attr] = common._encode_from_xml(val, encoding) if name == 'application': # get the code generation options self._appl_started = True self.app_attrs = attrs try: attrs['option'] = bool(int(attrs['option'])) use_multiple_files = attrs['option'] except (KeyError, ValueError): use_multiple_files = attrs['option'] = \ config.default_multiple_files if self.out_path is None: try: self.out_path = attrs['path'] except KeyError: raise XmlParsingError(_("'path' attribute missing: could " "not generate code")) else: attrs['path'] = self.out_path # Prevent empty output path if not self.out_path: raise XmlParsingError( _("'path' attribute empty: could not generate code") ) # Check if the values of use_multiple_files and out_path agree if use_multiple_files: if not os.path.isdir(self.out_path): raise errors.WxgOutputDirectoryNotExist(self.out_path) if not os.access(self.out_path, os.W_OK): raise errors.WxgOutputDirectoryNotWritable(self.out_path) else: if os.path.isdir(self.out_path): raise errors.WxgOutputPathIsDirectory(self.out_path) directory = os.path.dirname(self.out_path) if directory: if not os.path.isdir(directory): raise errors.WxgOutputDirectoryNotExist(directory) if not os.access(directory, os.W_OK): raise errors.WxgOutputDirectoryNotWritable(directory) # initialize the writer self.code_writer.initialize(attrs) return if not self._appl_started: raise XmlParsingError( _("the root of the tree must be <application>") ) if name == 'object': # create the CodeObject which stores info about the current widget CodeObject(attrs, self, preview=self.preview) if attrs.has_key('name') and \ attrs['name'] == self.app_attrs.get('top_window', ''): self.top_win = attrs['class'] else: # handling of the various properties try: # look for a custom handler to push on the stack w = self.top() handler = self.code_writer.get_property_handler(name, w.base) if handler: w.prop_handlers.push(handler) # get the top custom handler and use it if there's one handler = w.prop_handlers.top() if handler: handler.start_elem(name, attrs) except AttributeError: common.message.exception(_('ATTRIBUTE ERROR!!')) self._curr_prop = name
def endElement(self, name): if name == 'application': self._appl_started = False if self.app_attrs: self.code_writer.add_app(self.app_attrs, self.top_win) # call the finalization function of the code writer self.code_writer.finalize() return if name == 'object': obj = self.pop() if obj.klass in ('sizeritem', 'sizerslot'): return # at the end of the object, we have all the information to add it # to its toplevel parent, or to generate the code for the custom # class if obj.is_toplevel and not obj.in_sizers: self.code_writer.add_class(obj) topl = self._toplevels.top() if topl: self.code_writer.add_object(topl, obj) # if the object is not a sizeritem, check whether it # belongs to some sizer (in this case, # self._sizer_item.top() doesn't return None): if so, # write the code to add it to the sizer at the top of # the stack si = self._sizer_item.top() if si is not None and si.parent == obj.parent: szr = self._sizers.top() if not szr: return self.code_writer.add_sizeritem(topl, szr, obj, si.obj.option, si.obj.flag_str(), si.obj.border) else: # end of a property or error # 1: set _curr_prop value try: encoding = self.app_attrs['encoding'] unicode('a', encoding) except (KeyError, LookupError): encoding = 'ISO-8859-1' data = common._encode_from_xml(u"".join(self._curr_prop_val), encoding) if data: handler = self.top().prop_handlers.top() if not handler or handler.char_data(data): # if char_data returned False, # we don't have to call add_property self.top().add_property(self._curr_prop, data) # 2: call custom end_elem handler try: # if there is a custom handler installed for this property, # call its end_elem function: if this returns True, remove # the handler from the stack obj = self.top() handler = obj.prop_handlers.top() if handler.end_elem(name, obj): obj.prop_handlers.pop() except AttributeError: pass self._curr_prop = None self._curr_prop_val = []
def startElement(self, name, attrs_impl): attrs = {} try: encoding = self.app_attrs['encoding'] unicode('a', encoding) except (KeyError, LookupError): if name == 'application': encoding = str(attrs_impl.get('encoding', 'ISO-8859-1')) else: encoding = 'ISO-8859-1' # turn all the attribute values from unicode to str objects for attr, val in attrs_impl.items(): attrs[attr] = common._encode_from_xml(val, encoding) if name == 'application': # get the code generation options self._appl_started = True self.app_attrs = attrs try: attrs['option'] = bool(int(attrs['option'])) use_multiple_files = attrs['option'] except (KeyError, ValueError): use_multiple_files = attrs['option'] = False if self.out_path is None: try: self.out_path = attrs['path'] except KeyError: raise XmlParsingError( _("'path' attribute missing: could " "not generate code")) else: attrs['path'] = self.out_path # ALB 2004-11-01: check if the values of # use_multiple_files and out_path agree if use_multiple_files: if not os.path.isdir(self.out_path): raise IOError( _("Output path must be an existing directory" " when generating multiple files")) else: if os.path.isdir(self.out_path): raise IOError( _("Output path can't be a directory when " "generating a single file")) # initialize the writer self.code_writer.initialize(attrs) return if not self._appl_started: raise XmlParsingError( _("the root of the tree must be <application>")) if name == 'object': # create the CodeObject which stores info about the current widget CodeObject(attrs, self, preview=self.preview) if attrs.has_key('name') and \ attrs['name'] == self.app_attrs.get('top_window', ''): self.top_win = attrs['class'] else: # handling of the various properties try: # look for a custom handler to push on the stack w = self.top() handler = self.code_writer.get_property_handler(name, w.base) if handler: w.prop_handlers.push(handler) # get the top custom handler and use it if there's one handler = w.prop_handlers.top() if handler: handler.start_elem(name, attrs) except AttributeError: print 'ATTRIBUTE ERROR!!' traceback.print_exc() self._curr_prop = name
def startElement(self, name, attrs_impl): attrs = {} try: encoding = self.app_attrs['encoding'] unicode('a', encoding) except (KeyError, LookupError): if name == 'application': encoding = str(attrs_impl.get('encoding', 'ISO-8859-1')) else: encoding = 'ISO-8859-1' # turn all the attribute values from unicode to str objects for attr, val in attrs_impl.items(): attrs[attr] = common._encode_from_xml(val, encoding) if name == 'application': # get the code generation options self._appl_started = True self.app_attrs = attrs try: attrs['option'] = bool(int(attrs['option'])) use_multiple_files = attrs['option'] except (KeyError, ValueError): use_multiple_files = attrs['option'] = False if self.out_path is None: try: self.out_path = attrs['path'] except KeyError: raise XmlParsingError(_("'path' attribute missing: could " "not generate code")) else: attrs['path'] = self.out_path # ALB 2004-11-01: check if the values of # use_multiple_files and out_path agree if use_multiple_files: if not os.path.isdir(self.out_path): raise IOError(_("Output path must be an existing directory" " when generating multiple files")) else: if os.path.isdir(self.out_path): raise IOError(_("Output path can't be a directory when " "generating a single file")) # initialize the writer self.code_writer.initialize(attrs) return if not self._appl_started: raise XmlParsingError(_("the root of the tree must be <application>")) if name == 'object': # create the CodeObject which stores info about the current widget CodeObject(attrs, self, preview=self.preview) if attrs.has_key('name') and \ attrs['name'] == self.app_attrs.get('top_window', ''): self.top_win = attrs['class'] else: # handling of the various properties try: # look for a custom handler to push on the stack w = self.top() handler = self.code_writer.get_property_handler(name, w.base) if handler: w.prop_handlers.push(handler) # get the top custom handler and use it if there's one handler = w.prop_handlers.top() if handler: handler.start_elem(name, attrs) except AttributeError: print 'ATTRIBUTE ERROR!!' traceback.print_exc() self._curr_prop = name