[scribus-dev] Cleaned up code in the "ColorChart.py" script.

Jonas Møller jonasmo441 at gmail.com
Thu Nov 14 21:07:47 UTC 2013


I made a few revisions to the "ColorChart.py" script, which are all 
described here.

Firstly I changed the rbghex() function; Instead of being defined to 
take (r,g,b) it now takes (*rgb) which alllows for cleaner, more 
flexible and less repetitive code (In  the current version, a segment is 
repeated three times in a row on each argument given to the function; 
now this is done with a for loop). I've attached a python script 
containing this function as well as some doctests, to show you that it's 
working.

Then there's another small change further down in the drawColor() 
function. I've simply changed this:
"""
     #get rgb color
     rgbcolor=scribus.getColorAsRGB(colorname)
     r=rgbcolor[0]
     g=rgbcolor[1]
     b=rgbcolor[2]
     #get webcolor
     webcolor=rgbhex(r, g, b)
"""

To this:
"""
     ## Get rgb color and convert it to a HTML/CSS style webcolor.
     r, g, b = scribus.getColorAsRGB(colorname)
     webcolor = rgbToHexString(r, g, b)
"""
The reason I unpack the output of scribus.getColorAsRGB() into the 
variables r, g, and b instead of just unpacking it directly in 
rgbToHexString() is because those variables are needed further on in the 
function (and it also looks a lot clearer.)

Lastly, there were a lot of strange unnecessary pass statements thrown 
around; including a couple of these:
"""
     ...
     else:
         pass
"""
I'm assuming they were automatically inserted by an IDE and left there.

The full patch for ColorChart.py has been added as an attachment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rbghex_revision.py
Type: text/x-python
Size: 2012 bytes
Desc: not available
URL: <http://lists.scribus.net/pipermail/scribus-dev/attachments/20131114/e2a1e545/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ColorChart.py.patch
Type: text/x-patch
Size: 1980 bytes
Desc: not available
URL: <http://lists.scribus.net/pipermail/scribus-dev/attachments/20131114/e2a1e545/attachment.bin>


More information about the scribus-dev mailing list