From 60f6060885c8e9aa54062a49ee745cb8ba8feffd Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sun, 8 May 2016 18:59:42 +0200 Subject: [PATCH] Try to be more pythonic for size checks Slight behoavior differences between all() and != (None,None): - all() requires ALL terms to be not None (where (None, "cm") would pass != (None,None)) - all() checks for None or 0 or empty string No empty unit is supported (yet) A size of 0 does not really makes sense (and currently is passed since it is the string "0") --- patacrep/songs/chordpro/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/patacrep/songs/chordpro/__init__.py b/patacrep/songs/chordpro/__init__.py index 2f53005e..cbb09792 100644 --- a/patacrep/songs/chordpro/__init__.py +++ b/patacrep/songs/chordpro/__init__.py @@ -210,10 +210,11 @@ class Chordpro2LatexSong(ChordproSong): return "" if size[0] == "size": sizelist = [] - if size[1] != (None, None): - sizelist.append("width=" + "".join(size[1])) - if size[2] != (None, None): - sizelist.append("height=" + "".join(size[2])) + width, height = size[1:3] + if all(width): + sizelist.append("width=" + "".join(width)) + if all(height): + sizelist.append("height=" + "".join(height)) return ", ".join(sizelist) if size[0] == "scale": return "scale=" + size[1] @@ -251,11 +252,12 @@ class Chordpro2ChordproSong(ChordproSong): return "" if size[0] == "size": text = "size=" - if size[1] != (None, None): - text += "".join(size[1]) + width, height = size[1:3] + if all(width): + text += "".join(width) text += "x" - if size[2] != (None, None): - text += "".join(size[2]) + if all(height): + text += "".join(height) return text if size[0] == "scale": return "scale=" + size[1]