Browse Source

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")
pull/218/head
Oliverpool 8 years ago
parent
commit
60f6060885
  1. 18
      patacrep/songs/chordpro/__init__.py

18
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]

Loading…
Cancel
Save