def _load_layout(self, layout_filename, parent_item=None): self._svg_cache = {} layout = None try: f = open_utf8(layout_filename) except FileNotFoundError as ex: _logger.warning("Failed to open '{}': {}".format( layout_filename, unicode_str(ex))) return None # make sure unlink is called with minidom.parse(f).documentElement as dom: # check layout format, no format version means legacy layout format = self.LAYOUT_FORMAT_LEGACY if dom.hasAttribute("format"): format = Version.from_string(dom.attributes["format"].value) self._format = format root = LayoutPanel() # root, representing the 'keyboard' tag root.set_id("__root__") # id for debug prints # Init included root with the parent item's svg filename. # -> Allows to skip specifying svg filenames in includes. if parent_item: root.filename = parent_item.filename if format >= self.LAYOUT_FORMAT_LAYOUT_TREE: self._parse_dom_node(dom, root) layout = root else: _logger.warning( _format( "Loading legacy layout, format '{}'. " "Please consider upgrading to current format '{}'", format, self.LAYOUT_FORMAT)) items = self._parse_legacy_layout(dom) if items: root.set_items(items) layout = root f.close() self._svg_cache = {} # Free the memory return layout
def _load_layout(self, layout_filename, parent_item = None): self._svg_cache = {} layout = None f = open_utf8(layout_filename) # make sure unlink is called with minidom.parse(f).documentElement as dom: # check layout format, no format version means legacy layout format = self.LAYOUT_FORMAT_LEGACY if dom.hasAttribute("format"): format = Version.from_string(dom.attributes["format"].value) self._format = format root = LayoutPanel() # root, representing the 'keyboard' tag root.set_id("__root__") # id for debug prints # Init included root with the parent item's svg filename. # -> Allows to skip specifying svg filenames in includes. if parent_item: root.filename = parent_item.filename if format >= self.LAYOUT_FORMAT_LAYOUT_TREE: self._parse_dom_node(dom, root) layout = root else: _logger.warning(_format("Loading legacy layout, format '{}'. " "Please consider upgrading to current format '{}'", format, self.LAYOUT_FORMAT)) items = self._parse_legacy_layout(dom) if items: root.set_items(items) layout = root f.close() self._svg_cache = {} # Free the memory return layout