def fromxml(self, xml): self.side = False # Find the side of the table border ------------------------- if xml.tag in TableBorder.sides_xml.values(): for h, x in TableBorder.sides_xml.items(): if x == xml.tag: self.side = h break if not self.side: msg = "Invalid side for TableBorder" if self.style_type == "table": msg += " in TableStyle" if self.style_type == "cell": msg += " in CellStyle" raise exceptions.InsaneSLAValue(msg) # If the table border's side was found ---------------------- # ------------------------------------------------- if (width := xml.get("Width")) is not None: self.width = dimensions.Dim(float(width))
def fromxml(self, xml): if xml == "FOOTNOTEFRAME": note_style = xml.get("NSname") own_frame = xml.get("myID") story_frame = xml.get("MasterID") if note_style is not None: self.note_style = note_style if own_frame is not None: self.own_frame_id = own_frame if story_frame is not None: self.story_frame_id = story_frame if story_frame is None or own_frame is None: raise exceptions.InsaneSLAValue( "Note frame has no page object ID or\ no parent page object ID.") return True return False
def toxml(self): """ :rtype: lxml.etree._Element :returns: XML representation of document mark """ global mark_type_xml xml = ET.Element("Mark") if self.type: # --- Label ----------------------------------------------------- # When @type is "3" (variable text), @str acts as @label # in other @types, and @label acts as a mark identifier. # # So : # DocumentMark.name = @label if @type == "3" # DocumentMark.label = @label if @type != "3" if self.type == "variable": xml.attrib["label"] = self.name else: xml.attrib["label"] = self.label # --------------------------------------------------------------- xml.attrib["type"] = mark_type_xml[self.type] if self.type == "variable": xml.attrib["str"] = self.label if self.type == "objectref": xml.attrib["ItemID"] = self.target_object if self.type == "markref": xml.attrib["MARKlabel"] = self.target_mark["label"] xml.attrib["MARKtype"] = mark_type_xml[ self.target_mark["type"]] else: raise exceptions.InsaneSLAValue("Invalid Marks/Mark @type") return xml
def toxml(self, optional: bool = True): """ Return SLA as lxml.etree._Element :type optional: bool :param optional: Includes optional attributes (True by default) :returns: xml :rtype: lxml.etree._Element """ xml = ET.Element("SCRIBUSUTF8NEW") xml.attrib["Version"] = ".".join(self.version) if self.document is None: raise exceptions.InsaneSLAValue( "SLA file has no SCRIBUSUTF8NEW/DOCUMENT" ) else: dx = self.document.toxml(optional) xml.append(dx) return xml
# --------------------------------------------------------------- if self.type == "objectref": if (mitem := xml.get("ItemID")) is not None: self.target_object = mitem if self.type == "markref": if (mtarget_label := xml.get("MARKlabel")) is not None: self.target_mark["label"] = mtarget_label if (mtarget_type := xml.get("MARKtype")) is not None: if mtarget_type in mark_type_xml.values(): self.target_mark["type"] = mark_type_xml[mtarget_type] else: raise exceptions.InsaneSLAValue( "Invalid Marks/Mark @type") return True else: return False class StoryMarkAbstract(xmlc.PyScribusElement): """ Abstract class for MARK elements in Scribus stories. :type mark_type: str :param mark_type: Type of mark :type label: str :param label: Mark label
#--- Lists ------------------------------------------------------ is_ul, is_ol = False, False if (is_bullet := xml.get("Bullet")) is not None: if is_bullet == "1": self.listing["type"] = "ul" is_ul = True if (is_numeroted := xml.get("Numeration")) is not None: if is_numeroted == "1": self.listing["type"] = "ol" is_ol = True if is_ol and is_ul: raise exceptions.InsaneSLAValue( "Style {} is both bullet and numeroted list.".format(name)) if (bullet_char := xml.get("BulletStr")) is not None: self.listing["char"] = bullet_char #--- Parent character style ------------------------------------- if (character_parent := xml.get("CPARENT")) is not None: self.character_parent = character_parent #--- Leading ---------------------------------------------------- if (leading := xml.get("LINESPMode")) is not None: for human, code in ParagraphStyle.leading_xml.items(): if leading == code: