Commit 855e3ac4 authored by Etienne Nadji's avatar Etienne Nadji
Browse files

Linter and black reformat

	modifié :         colors.py
	modifié :         dimensions.py
	modifié :         document.py
	modifié :         exceptions.py
	modifié :         itemattribute.py
	modifié :         logs.py
	modifié :         marks.py
	modifié :         notes.py
	modifié :         pageobjects.py
	modifié :         pages.py
	modifié :         patterns.py
	modifié :         printing.py
	modifié :         sla.py
	modifié :         stories.py
	modifié :         styles.py
	modifié :         toc.py
parent 5ed4da8f
......@@ -57,66 +57,46 @@ class Color(xmlc.PyScribusElement):
"""
defaults = {
"Black": {
"space": "cmyk",
"colors": [0, 0, 0, 100]
},
"Blue": {
"space": "rgb",
"colors": [0, 0, 255]
},
"Cool Black": {
"space": "cmyk",
"colors": [60, 0, 0, 100]
},
"Cyan": {
"space": "cmyk",
"colors": [100, 0, 0, 0]
},
"Green": {
"space": "rgb",
"colors": [0, 255, 0]
},
"Magenta": {
"space": "cmyk",
"colors": [0, 100, 0, 0]
},
"Red": {
"space": "rgb",
"colors": [255, 0, 0]
},
"Black": {"space": "cmyk", "colors": [0, 0, 0, 100]},
"Blue": {"space": "rgb", "colors": [0, 0, 255]},
"Cool Black": {"space": "cmyk", "colors": [60, 0, 0, 100]},
"Cyan": {"space": "cmyk", "colors": [100, 0, 0, 0]},
"Green": {"space": "rgb", "colors": [0, 255, 0]},
"Magenta": {"space": "cmyk", "colors": [0, 100, 0, 0]},
"Red": {"space": "rgb", "colors": [255, 0, 0]},
"Registration": {
"space": "cmyk",
"colors": [100, 100, 100, 100],
"register": True
},
"Rich Black": {
"space": "cmyk",
"colors": [60, 40, 40, 100]
"register": True,
},
"Rich Black": {"space": "cmyk", "colors": [60, 40, 40, 100]},
"Warm Black": {
"space": "cmyk",
"colors": [0, 60, 29.8039215686275, 100]
},
"White": {
"space": "cmyk",
"colors": [0, 0, 0, 0]
},
"Yellow": {
"space": "cmyk",
"colors": [0, 0, 100, 0]
"colors": [0, 60, 29.8039215686275, 100],
},
"White": {"space": "cmyk", "colors": [0, 0, 0, 0]},
"Yellow": {"space": "cmyk", "colors": [0, 0, 100, 0]},
}
def __init__(
self, name="Black", space="CMYK", colors=[0, 0, 0, 100],
register="0", **kwargs):
self,
name="Black",
space="CMYK",
colors=[0, 0, 0, 100],
register="0",
**kwargs,
):
super().__init__()
self.pyscribus_defaults = [k for k in Color.defaults.keys()]
self.name = name
self.register = register
self.colors = {}
self.is_cmyk = False
self.is_rvb = False
self.set_space_colors(space, colors)
self._quick_setup(kwargs)
......@@ -170,7 +150,7 @@ class Color(xmlc.PyScribusElement):
"C": float(colors[0]),
"M": float(colors[1]),
"Y": float(colors[2]),
"K": float(colors[3])
"K": float(colors[3]),
}
# Avoid invalid values
......@@ -187,7 +167,7 @@ class Color(xmlc.PyScribusElement):
self.colors = {
"R": float(colors[0]),
"G": float(colors[1]),
"B": float(colors[2])
"B": float(colors[2]),
}
# Avoid invalid values
......@@ -257,7 +237,7 @@ class Color(xmlc.PyScribusElement):
self.set_space_colors(
Color.defaults[default]["space"],
Color.defaults[default]["colors"]
Color.defaults[default]["colors"],
)
if "register" in Color.defaults[default]:
......@@ -277,50 +257,49 @@ class Color(xmlc.PyScribusElement):
space = xml.get("SPACE")
if space is not None:
# Name -------------------------------------------------------
if space is None:
return False
if (name := xml.get("NAME")) is not None:
self.name = name
# Name -------------------------------------------------------
# Space ------------------------------------------------------
if (name := xml.get("NAME")) is not None:
self.name = name
if space.lower() in ["cmyk", "rgb"]:
self.set_space(space)
# Space ------------------------------------------------------
# Colors -------------------------------------------------
if space.lower() in ["cmyk", "rgb"]:
self.set_space(space)
if self.is_cmyk:
colors = [xml.get(c) for c in ["C", "M", "Y", "K"]]
else:
colors = [xml.get(c) for c in ["R", "G", "B"]]
# Colors -------------------------------------------------
if colors:
if None in colors:
raise exceptions.InvalidColor(
"Invalid inks <{}>.".format(",".join(colors))
)
else:
self.set_colors(colors)
else:
raise exceptions.InvalidColor("No inks.")
if self.is_cmyk:
colors = [xml.get(c) for c in ["C", "M", "Y", "K"]]
else:
colors = [xml.get(c) for c in ["R", "G", "B"]]
# Register ---------------------------------------------------
if not colors:
raise exceptions.InvalidColor("No inks.")
if (reg := xml.get("Register")) is None:
self.register = False
else:
if int(reg):
self.register = True
else:
self.register = False
if None in colors:
raise exceptions.InvalidColor(
"Invalid inks <{}>.".format(",".join(colors))
)
# ------------------------------------------------------------
self.set_colors(colors)
return True
# Register ---------------------------------------------------
if (reg := xml.get("Register")) is None:
self.register = False
else:
return False
if int(reg):
self.register = True
else:
self.register = False
# ------------------------------------------------------------
return True
def toxml(self):
"""
......@@ -363,6 +342,7 @@ class Color(xmlc.PyScribusElement):
xmlc.PyScribusElement._quick_setup(self, settings)
for setting_name, setting_value in settings.items():
# TODO
pass
# Python __ methods ----------------------------------------
......@@ -401,25 +381,19 @@ class Color(xmlc.PyScribusElement):
return True
def __repr__(self):
if self.is_cmyk:
s = "CMYK"
inks = ["C", "M", "Y", "K"]
else:
s = "RGB"
inks = ["R", "G", "B"]
r = "{}:{}:{}:{}".format(
self.name, s,
";".join(
[
str(self.colors[ink])
for ink in inks
]
),
self.register
space_name = {True: "CMYK", False: "RGB"}[self.is_cmyk]
inks = {True: ["C", "M", "Y", "K"], False: ["R", "G", "B"]}[
self.is_cmyk
]
repr_value = "{}:{}:{}:{}".format(
self.name,
space_name,
";".join([str(self.colors[ink]) for ink in inks]),
self.register,
)
return r
return repr_value
class GradientColorStop(xmlc.PyScribusElement):
......@@ -526,9 +500,7 @@ class GradientColorStop(xmlc.PyScribusElement):
)
if setting_name == "shade":
self.shade = dimensions.Dim(
float(setting_value), "pc"
)
self.shade = dimensions.Dim(float(setting_value), "pc")
def fromdefault(self):
self.opacity = dimensions.Dim(100, "pc")
......@@ -602,7 +574,7 @@ class Gradient(xmlc.PyScribusElement):
if element.tag == "CSTOP":
grs = GradientColorStop()
if (success := grs.fromxml(element)):
if (success := grs.fromxml(element)) :
self.stops.append(grs)
return True
......@@ -654,4 +626,5 @@ class Gradient(xmlc.PyScribusElement):
return xml
# vim:set shiftwidth=4 softtabstop=4 spl=en:
......@@ -87,12 +87,16 @@ class Dim:
"deg": ["deg"],
"dpi": ["dpi", "ppp", "ppi"],
"lpi": ["lpi"],
"sec": ["s", "sec"]
"sec": ["s", "sec"],
}
def __init__(
self, value, unit: str = "pica", is_int: bool = False,
original_unit: bool = False):
self,
value,
unit: str = "pica",
is_int: bool = False,
original_unit: bool = False,
):
self.is_int = False
if is_int:
......@@ -139,9 +143,7 @@ class Dim:
if self.unit == "lpi":
if self.value < 0:
raise exceptions.InvalidDim(
"LPI must be a positive number"
)
raise exceptions.InvalidDim("LPI must be a positive number")
if self.unit == "sec":
if int(float(self.value)) != float(self.value):
......@@ -154,30 +156,25 @@ class Dim:
if self.value >= 0:
if self.value <= 180:
return True
else:
raise exceptions.InvalidDim(
"Calligraph pen angle must range from 0 to 180"
)
else:
raise exceptions.InvalidDim(
"Calligraph pen angle must range from 0 to 180"
)
raise exceptions.InvalidDim(
"Calligraph pen angle must range from 0 to 180"
)
if self.unit == "deg":
if self.value >= 0:
if self.value <= 360:
return True
else:
raise exceptions.InvalidDim(
"Angle must range from 0 to 360"
)
else:
raise exceptions.InvalidDim(
"Angle must range from 0 to 360"
)
raise exceptions.InvalidDim("Angle must range from 0 to 360")
raise exceptions.InvalidDim("Angle must range from 0 to 360")
return True
......@@ -248,29 +245,30 @@ class Dim:
def decimals(n):
if float(n) == int(n):
return int(n)
else:
return n
return n
if self.unit not in ["perc", "pcdecim", "cdeg", "deg", "lpi", "dpi"]:
if no_useless_decimals:
pica = self.topica()
return str(decimals(pica))
else:
return str(self.topica())
return str(self.topica())
else:
if self.unit == "pcdecim":
if self.value == 1.0:
return "1"
else:
if no_useless_decimals:
return str(decimals(self.value))
else:
return str(self.value)
else:
if no_useless_decimals:
return str(decimals(self.value))
else:
return str(self.value)
return str(self.value)
if no_useless_decimals:
return str(decimals(self.value))
return str(self.value)
def toxml(self):
"""
......@@ -300,8 +298,8 @@ class Dim:
if ceil:
return math.ceil(value)
else:
return value
return value
def _convertorval(self, obj, value, unit: str):
"""
......@@ -313,8 +311,8 @@ class Dim:
if obj:
return Dim(value, unit)
else:
return value
return value
def is_convertable_length(self):
"""
......@@ -365,13 +363,9 @@ class Dim:
"""
if self.unit == "lpi":
return self._convertorval(
obj, self._ceil(self.value * 16), "dpi"
)
else:
raise exceptions.IncompatibleDim(
"Can't convert that into DPI"
)
return self._convertorval(obj, self._ceil(self.value * 16), "dpi")
raise exceptions.IncompatibleDim("Can't convert that into DPI")
def topc(self, ceil: bool, obj: bool = False):
"""
......@@ -385,13 +379,9 @@ class Dim:
"""
if self.unit == "pcdecim":
return self._convertorval(
obj, self._ceil(self.value * 100), "pc"
)
else:
raise exceptions.IncompatibleDim(
"Can't convert that into percentage"
)
return self._convertorval(obj, self._ceil(self.value * 100), "pc")
raise exceptions.IncompatibleDim("Can't convert that into percentage")
def tolpi(self, ceil: bool = False, obj: bool = False):
"""
......@@ -405,13 +395,9 @@ class Dim:
"""
if self.unit == "dpi":
return self._convertorval(
obj, self._ceil(self.value / 16), "lpi"
)
else:
raise exceptions.IncompatibleDim(
"Can't convert that into LPI"
)
return self._convertorval(obj, self._ceil(self.value / 16), "lpi")
raise exceptions.IncompatibleDim("Can't convert that into LPI")
def tomm(self, ceil: bool = False, obj: bool = False):
"""
......@@ -434,9 +420,7 @@ class Dim:
)
if self.unit == "mm":
return self._convertorval(
obj, self._ceil(self.value, ceil), "mm"
)
return self._convertorval(obj, self._ceil(self.value, ceil), "mm")
# Defaults -----------------------------------------------------------
......@@ -618,8 +602,11 @@ class DimBox:
def _setxy(self, corner, value, xy, rotated: bool = False):
if corner.lower() in [
"top-left", "top-right",
"bottom-left", "bottom-right"]:
"top-left",
"top-right",
"bottom-left",
"bottom-right",
]:
if xy == "x":
if rotated:
......@@ -638,18 +625,21 @@ class DimBox:
def _getxy(self, corner, xy, rotated: bool = False):
if corner.lower() in [
"top-left", "top-right",
"bottom-left", "bottom-right"]:
"top-left",
"top-right",
"bottom-left",
"bottom-right",
]:
if xy == "x":
if rotated:
return self.rotated_coords[corner][0].value
else:
return self.coords[corner][0].value
return self.coords[corner][0].value
else:
if rotated:
return self.rotated_coords[corner][1].value
else:
return self.coords[corner][1].value
return self.coords[corner][1].value
else:
raise KeyError()
......@@ -668,8 +658,8 @@ class DimBox:
# Box modification ---------------------------------------------------
def move(
self, posx: float = 0, posy: float = 0,
refpoint: str = "top-left"):
self, posx: float = 0, posy: float = 0, refpoint: str = "top-left"
):
"""
Move the box at posx, posy position.
......@@ -695,7 +685,8 @@ class DimBox:
if refpoint == "top-left":
self.set_box(
top_lx=posx, top_ly=posy,
top_lx=posx,
top_ly=posy,
width=self.dims["width"].value,
height=self.dims["height"].value,
)
......@@ -710,8 +701,11 @@ class DimBox:
return False
def translate(
self, amountx: float = 0, amounty: float = 0,
refpoint: str = "top-left"):
self,
amountx: float = 0,
amounty: float = 0,
refpoint: str = "top-left",
):
"""
Move the box by an amount of amountx, amounty
......@@ -724,7 +718,7 @@ class DimBox:
:rtype: boolean
"""
origin_x, origin_y = None,None
origin_x, origin_y = None, None
if refpoint in self.coords.keys():
origin_x = self.coords[refpoint][0].value
......@@ -739,7 +733,8 @@ class DimBox:
npy = self.coords["top-left"][1].value + amounty
self.set_box(
top_lx=npx, top_ly=npy,
top_lx=npx,
top_ly=npy,
width=self.dims["width"].value,
height=self.dims["height"].value,
)
......@@ -936,8 +931,8 @@ class DimBox:
self.rotate(rotation_deg)
return True
else:
return False
return False
else:
return False
......@@ -981,8 +976,8 @@ class DimBox:
self.sety("bottom-right", nby)
return True
else:
return False
return False
def rotate(self, degree: float):
"""
......@@ -1088,4 +1083,5 @@ class LocalDimBox(DimBox):
DimBox.__init__(self)
self.visible = True
# vim:set shiftwidth=4 softtabstop=4 spl=en:
This diff is collapsed.
......@@ -37,7 +37,6 @@ class InsaneSLAValue(Exception):
For example, a list can't be a numeroted and bullet one, Scribus UI
doesn't allow that but manual SLA editing does.
"""
pass
class MissingSLAAttribute(Exception):
......@@ -46,7 +45,6 @@ class MissingSLAAttribute(Exception):
An exception more precise than InsaneSLAValue.
"""
pass
class ConflictingLayer(Exception):
......@@ -54,7 +52,7 @@ class ConflictingLayer(Exception):
Exception raised if a document Layer have same attributes that an other
one.
"""
pass
# --- Items attributes -----------------------------------------
......@@ -65,7 +63,7 @@ class UnknownOrEmptyItemAttributeType(Exception):
classes) has a unknown or empty type, as it is not in
``itemattribute.ItemAttribute.attrib_types``
"""
pass
# --- Quick setup ----------------------------------------------
......@@ -74,7 +72,7 @@ class QuickSetupInvalidValue(Exception):
"""
Exception raised when a quick setup value is invalid.
"""
pass
# --- Unknown SLA references -----------------------------------
......@@ -84,7 +82,6 @@ class UnknownLayer(Exception):