BridgesUNCC / bridges-python

Python client library for Bridges
http://bridgesuncc.github.io
MIT License
3 stars 4 forks source link

Color rework #28

Closed AlecGoncharow closed 5 years ago

AlecGoncharow commented 5 years ago

I have refactored constructor and set_color function to use python args and kwargs to allow for a much more flexible API. Previously to instantiate a Color from RGBA we had to:

my_color = Color(None, 0, 0, 255, 1.0)

to allow for

my_color = Color("blue")

to just work. I did not like this so I reordered the arguments to be rgba first, however that required the user to do

my_color = Color(col_name="blue")
# or
my_color = Color(0, 0, 0, 0, "blue")

which was not really optimal either. So I present the new and improved constructor:

my_color = Color(0, 0, 255)
my_color = Color(0, 0, 255, 1.0)
my_color = Color("blue")
my_color = Color(col_name="blue")
my_color = Color(r=0, g=0, b=255)
my_color = Color(red=0, green=0, blue=255)
my_color = Color(r=0, g=0, b=255, a=1.0)
my_color = Color(red=0, green=0, blue=255, alpha=1.0)
my_color = Color(b=255)
my_color = Color(blue=255)

All of the above lines create the exact same RGBA value of 0, 0, 255, 1.0. All of these changes apply to the set_color() function as well.

Along with this addition I have done away with the stacked if statements for named color parsing and added webcolors to our required packages, a small library that will be installed along side the package when installing from pip. This handles all of our named color concerns for now, including exceptions for invalid names. https://pypi.org/project/webcolors/ It also supports python 2.x, so we shouldn't run into any issues with older versions of 3.x

Along side with this, I've made the element and link visualizers pass off color setting to the Color class, to keep the code DRY.

This code passes all tests in the current Bridges_Testing repo, I just wanted to add a writeup here to keep everyone in the loop.