Commit 5ed4da8f authored by Etienne Nadji's avatar Etienne Nadji
Browse files

Styling

	modifié :         source/pyscribus/colors.py
	modifié :         source/pyscribus/common/math.py
	modifié :         source/pyscribus/common/xml.py
	modifié :         source/pyscribus/dimensions.py
	modifié :         source/pyscribus/document.py
	modifié :         source/pyscribus/exceptions.py
	modifié :         source/pyscribus/extra/wireframe.py
	modifié :         source/pyscribus/itemattribute.py
	modifié :         source/pyscribus/logs.py
	modifié :         source/pyscribus/marks.py
	modifié :         source/pyscribus/notes.py
	modifié :         source/pyscribus/pageobjects.py
	modifié :         source/pyscribus/pages.py
	modifié :         source/pyscribus/papers/afnor.py
	modifié :         source/pyscribus/papers/ansi.py
	modifié :         source/pyscribus/papers/iso216.py
	modifié :         source/pyscribus/papers/iso269.py
	modifié :         source/pyscribus/papers/newspaper.py
	modifié :         source/pyscribus/patterns.py
	modifié :         source/pyscribus/printing.py
	modifié :         source/pyscribus/sla.py
	modifié :         source/pyscribus/stories.py
	modifié :         source/pyscribus/styles.py
	modifié :         source/pyscribus/toc.py
parent 65a66b3d
......@@ -37,6 +37,7 @@ __author__ = "Etienne Nadji <etnadji@eml.cc>"
# Classes ===============================================================#
class Color(xmlc.PyScribusElement):
"""
SLA Color (COLOR)
......@@ -108,7 +109,7 @@ class Color(xmlc.PyScribusElement):
}
def __init__(
self, name="Black", space="CMYK", colors=[0,0,0,100],
self, name="Black", space="CMYK", colors=[0, 0, 0, 100],
register="0", **kwargs):
super().__init__()
......@@ -120,7 +121,7 @@ class Color(xmlc.PyScribusElement):
self._quick_setup(kwargs)
#--- Color management --------------------------------------
# Color management -----------------------------------------
def set_space_colors(self, space: str, colors: list):
"""
......@@ -224,7 +225,7 @@ class Color(xmlc.PyScribusElement):
return False
#--- PyScribus standard methods ----------------------------
# PyScribus standard methods -------------------------------
def fromdefault(self, default: str = "Black"):
"""
......@@ -242,10 +243,10 @@ class Color(xmlc.PyScribusElement):
blue = Color(default="Blue")
.. seealso::
**For fromdefault explanation**:
**For fromdefault explanation**:
`pyscribus.common.xml.PyScribusElement.fromdefault`
**For current class default sets**:
**For current class default sets**:
`pyscribus.colors.Color.listdefaults`
"""
......@@ -364,7 +365,7 @@ class Color(xmlc.PyScribusElement):
for setting_name, setting_value in settings.items():
pass
#--- Python __ methods -------------------------------------
# Python __ methods ----------------------------------------
def __eq__(self, other):
"""
......
......@@ -29,12 +29,14 @@ import enum
__author__ = "Etienne Nadji <etnadji@eml.cc>"
# 1 pica point = 25,4/72 milimeters
PICA_TO_MM = (25.4 / 72)
INCH_TO_MM = 25.4
# Classes ===============================================================#
class FloatEnum(enum.Enum):
"""
Enum class usable with float() function / method.
......@@ -48,6 +50,7 @@ class FloatEnum(enum.Enum):
# Fonctions =============================================================#
def necessary_float(f: float):
"""
Return **integer** if float f has no decimals, else returns **float**.
......@@ -63,6 +66,7 @@ def necessary_float(f: float):
else:
return float(f)
def mm(milimeters):
"""
Returns milimeters in pica points.
......
......@@ -59,12 +59,13 @@ alignment = {
# Classes ===============================================================#
class PyScribusElement:
"""
Abstract class for any element that must implement PyScribus
common methods.
:ivar list pyscribus_defaults: Names of default settings for
:ivar list pyscribus_defaults: Names of default settings for
fromdefault
.. warning:: except listdefaults, all methods must be redefined by
......@@ -74,7 +75,7 @@ class PyScribusElement:
def __init__(self):
self.pyscribus_defaults = []
#--- Quick setup ---------------------------------
# Quick setup ------------------------------------
def _quick_setup(self, settings: dict):
"""
......@@ -82,7 +83,7 @@ class PyScribusElement:
instanciation kwargs.
In the inherited classes, the redefined method is called
at class instanciation and PyScribusElement._quick_setup
at class instanciation and PyScribusElement._quick_setup
is called in the redefined method.
Document settings keys in class docstring.
......@@ -103,11 +104,11 @@ class PyScribusElement:
else:
self.fromdefault(settings["default"])
#--- Default(s) ----------------------------------
# Default(s) -------------------------------------
def fromdefault(self):
"""
Modify PyScribus element attributes according to a set of
Modify PyScribus element attributes according to a set of
defaults.
If fromdefault() has not other argument than self, there is
......@@ -146,7 +147,7 @@ class PyScribusElement:
return self.pyscribus_defaults
#--- XML import / export -------------------------
# XML import / export ----------------------------
def toxml(self):
"""
......@@ -166,7 +167,7 @@ class PyScribusElement:
return False
#--- Copy ----------------------------------------
# Copy -------------------------------------------
def copy(self, **kwargs):
"""
......@@ -258,6 +259,7 @@ class OrphanElement(PyScribusElement):
# From PyScribus to XML ========================================#
def float_or_int_string(f):
if float(f) == int(f):
......@@ -265,6 +267,7 @@ def float_or_int_string(f):
else:
return str(f)
def str_or_nonestr(v: str):
"""
Returns v if v is a non-empty string, else returns 'None'.
......@@ -277,6 +280,7 @@ def str_or_nonestr(v: str):
else:
return "None"
def bool_to_num(b: bool):
"""
Returns '1' if b is true, returns '0' if b is false.
......@@ -289,6 +293,7 @@ def bool_to_num(b: bool):
else:
return "0"
def bool_or_else_to_num(b):
"""
Returns '0' if b is False, else return b as string.
......@@ -301,6 +306,7 @@ def bool_or_else_to_num(b):
else:
return "0"
def none_or_str(v):
"""
If v is None, return empty string, else return v as string.
......@@ -315,6 +321,7 @@ def none_or_str(v):
# From XML to PyScribus ========================================#
def num_to_bool(n: str):
"""
Return True if n == '1', else returns False.
......@@ -329,6 +336,7 @@ def num_to_bool(n: str):
# Undocumented attributes ======================================#
def undocumented_to_python(xml: ET._Element, attributes: list):
"""
Function to manage the import of undocumented
......@@ -341,8 +349,8 @@ def undocumented_to_python(xml: ET._Element, attributes: list):
:param xml: XML element
:type attributes: list
:param attributes: List of attributes' names
:returns: Dictionnary with attributes names as
keys and attribute values as values.
:returns: Dictionnary with attributes names as keys and attribute values
as values.
:rtype: dict
Use lxml.etree._Element.get() to get attributes values,
......@@ -358,6 +366,7 @@ def undocumented_to_python(xml: ET._Element, attributes: list):
return undocumented
def undocumented_to_xml(
xml: ET._Element, undocumented: dict, no_none: bool = False):
"""
......@@ -396,6 +405,7 @@ def undocumented_to_xml(
return xml
def all_undocumented_to_python(xml: ET._Element):
"""
Function to manage the import of undocumented
......@@ -428,6 +438,7 @@ def all_undocumented_to_python(xml: ET._Element):
return undocumented
def all_undocumented_to_xml(
xml: ET._Element, undocumented: dict,
report: bool = True, msg: str = "", passattr: list = [], logger=False):
......@@ -446,12 +457,12 @@ def all_undocumented_to_xml(
:type report: bool
:param report: Print all undocumented attributes found in xml element.
:type msg: str
:param msg: Human readable name for the xml element when report parameter
:param msg: Human readable name for the xml element when report parameter
is True.
:type passattr: list
:param passattr: List of SLA attributes names to not report. For debug.
:type logger: logging.Logger, bool
:param logger: Logger object to use if report. If False, report is printed
:param logger: Logger object to use if report. If False, report is printed
in STDOUT.
:returns: List containing LXML element and undocumented attributes
names list.
......@@ -487,7 +498,6 @@ def all_undocumented_to_xml(
print(undocstr)
pprint.pprint(undoc_attribs, width=80, compact=True)
return [xml, undoc_attribs]
# vim:set shiftwidth=4 softtabstop=4 spl=en:
......@@ -24,7 +24,7 @@ PyScribus classes for measures and geometrical manipulations.
import copy
import math
from pyscribus.common.math import PICA_TO_MM,INCH_TO_MM
from pyscribus.common.math import PICA_TO_MM, INCH_TO_MM
import pyscribus.logs as logs
import pyscribus.exceptions as exceptions
......@@ -40,6 +40,7 @@ __author__ = "Etienne Nadji <etnadji@eml.cc>"
# Classes ===============================================================#
class Dim:
"""
Dimension object. Allows to convert and export in the correct unit.
......@@ -77,9 +78,6 @@ class Dim:
+-------------------------+---------------+
"""
# 1 pica point = 25,4/72 milimeters
PICA_TO_MM = (25.4 / 72)
UNIT_ARGS = {
"mm": ["mm"],
"pica": ["pica", "pt"],
......@@ -110,7 +108,7 @@ class Dim:
self.check_value()
#--- Checking, setting the unit --------------------------------------
# Checking, setting the unit -----------------------------------------
def from_original_unit(self, original_unit):
pass
......@@ -221,7 +219,7 @@ class Dim:
tmp_unit = unit.lower()
valid_unit = False
for code,args in Dim.UNIT_ARGS.items():
for code, args in Dim.UNIT_ARGS.items():
if tmp_unit in args:
self.unit = code
......@@ -234,7 +232,7 @@ class Dim:
return valid_unit
#--- XML export ------------------------------------------------------
# XML export ---------------------------------------------------------
def toxmlstr(self, no_useless_decimals: bool = False):
"""
......@@ -286,7 +284,7 @@ class Dim:
return self.toxmlstr()
#--- Conversion into other units -------------------------------------
# Conversion into other units ----------------------------------------
def _ceil(self, value, ceil: bool = False):
"""
......@@ -352,7 +350,7 @@ class Dim:
if self.unit == "mm":
return self._convertorval(
obj, self._ceil(self.value / Dim.PICA_TO_MM, ceil), "pica"
obj, self._ceil(self.value / PICA_TO_MM, ceil), "pica"
)
def todpi(self, ceil: bool = False, obj: bool = False):
......@@ -432,7 +430,7 @@ class Dim:
if self.unit == "pica":
return self._convertorval(
obj, self._ceil(self.value * Dim.PICA_TO_MM, ceil), "mm"
obj, self._ceil(self.value * PICA_TO_MM, ceil), "mm"
)
if self.unit == "mm":
......@@ -440,7 +438,7 @@ class Dim:
obj, self._ceil(self.value, ceil), "mm"
)
#--- Defaults --------------------------------------------------------
# Defaults -----------------------------------------------------------
def fromdefault(self, default: str):
"""
......@@ -472,13 +470,13 @@ class Dim:
return True
#--- Python __ methods -----------------------------------------------
# Python __ methods --------------------------------------------------
def __bool__(self):
return bool(self.value)
def __str__(self):
r,u = str(self.value),""
r, u = str(self.value), ""
if self.unit in Dim.UNIT_ARGS.keys():
short = {"mm": "mm", "perc": "%", "pica": "pt", "lpi": "lpi"}
......@@ -588,7 +586,7 @@ class DimBox:
+-------------------------+------------+
"""
def __init__(self,**kwargs):
def __init__(self, **kwargs):
# X,Y coordinates for each corner
# Use setx, sety, getx, gety methods as shorthands
self.coords = {
......@@ -616,7 +614,7 @@ class DimBox:
self.set_box(kwargs=kwargs)
#--- Shorthands for corners coordinates ------------------------------
# Shorthands for corners coordinates ---------------------------------
def _setxy(self, corner, value, xy, rotated: bool = False):
if corner.lower() in [
......@@ -667,9 +665,11 @@ class DimBox:
def gety(self, corner, rotated: bool = False):
return self._getxy(corner, "y", rotated)
#--- Box modification ------------------------------------------------
# Box modification ---------------------------------------------------
def move(self, posx: float = 0, posy: float = 0, refpoint: str = "top-left"):
def move(
self, posx: float = 0, posy: float = 0,
refpoint: str = "top-left"):
"""
Move the box at posx, posy position.
......@@ -682,7 +682,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
......@@ -724,7 +724,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
......@@ -790,8 +790,8 @@ class DimBox:
rtype: pyscribus.dimensions.DimBox
"""
tlx,tly = kwargs["top_lx"],kwargs["top_ly"]
brx,bry = kwargs["bottom_rx"],kwargs["bottom_ry"]
tlx, tly = kwargs["top_lx"], kwargs["top_ly"]
brx, bry = kwargs["bottom_rx"], kwargs["bottom_ry"]
obj.dims["width"].value = brx - tlx
obj.dims["height"].value = bry - tly
......@@ -883,7 +883,7 @@ class DimBox:
case = False
if casename == "set_from_all":
case = ["top_lx", "top_ly", "bottom_rx", "bottom_ry"]
case = ["top_lx", "top_ly", "bottom_rx", "bottom_ry"]
if casename == "set_from_tl":
case = ["top_lx", "top_ly", "width", "height"]
......@@ -946,7 +946,7 @@ class DimBox:
Resize the box from a side.
:type side: str
:param side: Side of the box to resize from.
:param side: Side of the box to resize from.
Must be "left", "right", "top", "bottom".
:type value: float
:param value: Resize value
......@@ -1011,7 +1011,7 @@ class DimBox:
# FIXME Remove that after implementation -------
logger=logs.getLogger()
logger = logs.getLogger()
if logger:
logger.debug("Box rotation not implemented.")
......@@ -1029,12 +1029,12 @@ class DimBox:
return True
#--- Python __ methods -----------------------------------------------
# Python __ methods --------------------------------------------------
def __eq__(self, other):
for cname in self.coords.keys():
for idx in [0,1]:
for idx in [0, 1]:
a = self.coords[cname][idx].value
b = other.coords[cname][idx].value
......
This diff is collapsed.
......@@ -25,6 +25,7 @@ __author__ = "Etienne Nadji <etnadji@eml.cc>"
# Classes ===============================================================#
class InsaneSLAValue(Exception):
"""
Exception raised if a XML value or a set of XML values is/are
......@@ -50,12 +51,14 @@ class MissingSLAAttribute(Exception):
class ConflictingLayer(Exception):
"""
Exception raised if a document Layer have same attributes that an other one.
Exception raised if a document Layer have same attributes that an other
one.
"""
pass
# --- Items attributes -----------------------------------------
class UnknownOrEmptyItemAttributeType(Exception):
"""
Exception raised when a ``itemattribute.ItemAttribute`` (and inherited
......@@ -66,6 +69,7 @@ class UnknownOrEmptyItemAttributeType(Exception):
# --- Quick setup ----------------------------------------------
class QuickSetupInvalidValue(Exception):
"""
Exception raised when a quick setup value is invalid.
......@@ -74,16 +78,19 @@ class QuickSetupInvalidValue(Exception):
# --- Unknown SLA references -----------------------------------
class UnknownLayer(Exception):
"""
Exception raised if a SLA element points to a layer unknown to the document.
Exception raised if a SLA element points to a layer unknown to the
document.
"""
pass
class UnknownStyleInStory(Exception):
"""
Exception raised if a SLA element points to a style unknown to the document.
Exception raised if a SLA element points to a style unknown to the
document.
"""
pass
......@@ -107,6 +114,7 @@ class UnknownRenderBufferProperty(Exception):
# --- dimensions -----------------------------------------------
class UnknownDimUnit(Exception):
pass
......
......@@ -24,8 +24,6 @@ and page objects.
# Imports ===============================================================#
import math
from PIL import Image, ImageDraw
import pyscribus.dimensions as dimensions
......@@ -38,6 +36,7 @@ __author__ = "Etienne Nadji <etnadji@eml.cc>"
# Classes ===============================================================#
class WireframeObject:
"""
Wireframe object : something to draw on the wireframe, like pages,
......@@ -219,7 +218,7 @@ class Wireframe:
else:
self = add(self, WireframeObject(sla_object))
def _image_size(self, margins=[0,0]):
def _image_size(self, margins=[0, 0]):
max_x = float()
max_y = float()
......@@ -284,7 +283,7 @@ class Wireframe:
out_file = False
canvas_margins = [0,0]
canvas_margins = [0, 0]
background_color = "grey"
default_outline = "black"
......@@ -294,7 +293,7 @@ class Wireframe:
# --- Options processing ------------------------------------
for opt_name,opt_value in kwargs.items():
for opt_name, opt_value in kwargs.items():
if opt_name == "layers":
draw_layers = opt_value
......@@ -352,8 +351,8 @@ class Wireframe:
# --- Drawing landmark --------------------------------------
if draw_landmark:
canvas.line(((-5,0),(5,0)), fill="red")
canvas.line(((0,-5),(0,-5)), fill="red")
canvas.line(((-5, 0), (5, 0)), fill="red")
canvas.line(((0, -5), (0, -5)), fill="red")
# --- Using default_outline or stylesheet -------------------
......
......@@ -36,16 +36,17 @@ __author__ = "Etienne Nadji <etnadji@eml.cc>"
# Classes ===============================================================#
class ItemAttribute(PyScribusElement):
attrib_types = ["boolean", "integer", "double", "string", "none"]
#--- FIXME Not documented -----------------------------
# FIXME Not documented --------------------------------
# Parameter=""
# Relationship="none"
# RelationshipTo=""
# AutoAddTo="none"
#--- NOTE Examples in SLA -----------------------------
# NOTE Examples in SLA --------------------------------
# Name="entier" Type="integer" Value="1"
# Name="reel" Type="double" Value="-5"
# Name="chaine" Type="string" Value="&quot;Test&quot;"
......@@ -111,7 +112,7 @@ class ItemAttribute(PyScribusElement):
else:
raise exceptions.UnknownOrEmptyItemAttributeType()
#--- PyScribus standard methods ----------------------------
# PyScribus standard methods -------------------------------
def fromxml(self, xml: ET._Element):
name = xml.get("Name")
......
......@@ -34,6 +34,7 @@ USE_LOG = False
# Fonctions =============================================================#
def init_logging(
filepath="test.log",
formatstr="%(asctime)s:%(levelname)s:%(message)s"):
......@@ -51,6 +52,7 @@ def init_logging(
USE_LOG = True
def getLogger():
global USE_LOG
......
......@@ -43,6 +43,7 @@ mark_type_xml = {
# Classes ===============================================================#
class DocumentMark(xmlc.PyScribusElement):
"""
Mark element (DOCUMENT/Marks/Mark)
......@@ -150,7 +151,7 @@ class DocumentMark(xmlc.PyScribusElement):
mtype = xml.get("type")
if mtype is not None:
for h,x in mark_type_xml.items():
for h, x in mark_type_xml.items():
if mtype == x:
self.type = h
break
......@@ -239,7 +240,7 @@ class StoryMarkAbstract(xmlc.PyScribusElement):
if xml.tag == "MARK":
if (mtype := xml.get("type")) is not None:
for h,x in mark_type_xml.items():
for h, x in mark_type_xml.items():
if mtype == x:
self.type = h