Write docs for sugar3.graphics.xocolor

This commit is contained in:
radicalonion 2015-12-27 20:36:55 -05:00
parent 51057baef5
commit 79d11c3a28

View File

@ -15,9 +15,10 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
""" '''
STABLE. This class represents all of the colors that the XO can take on.
""" Each pair of colors represents the fill color and the stroke color
'''
import random import random
import logging import logging
@ -207,6 +208,12 @@ colors = [['#B20008', '#FF2B34'],
def _parse_string(color_string): def _parse_string(color_string):
'''
Returns array of length 2 of two colors in standard html form of [stroke color, fill color]
Args:
color_string (string): two html format strings separated by a comma
'''
if not isinstance(color_string, (str, unicode)): if not isinstance(color_string, (str, unicode)):
logging.error('Invalid color string: %r', color_string) logging.error('Invalid color string: %r', color_string)
return None return None
@ -224,7 +231,15 @@ def _parse_string(color_string):
class XoColor: class XoColor:
'''
Defines color for XO
Args:
color_string (string): two html format strings separated
by a comma, "white", or "insensitive". If color_string
is None, the user's color will be created. If parsed_color
cannot be created, a random color will be used
'''
def __init__(self, color_string=None): def __init__(self, color_string=None):
parsed_color = None parsed_color = None
@ -242,18 +257,34 @@ class XoColor:
[self.stroke, self.fill] = parsed_color [self.stroke, self.fill] = parsed_color
def __cmp__(self, other): def __cmp__(self, other):
'''
Compares two XO colors by their stroke and fill color
Returns 0 if they are equal and -1 if they are unequal
Args:
other (object): other XO color to compare
'''
if isinstance(other, XoColor): if isinstance(other, XoColor):
if self.stroke == other.stroke and self.fill == other.fill: if self.stroke == other.stroke and self.fill == other.fill:
return 0 return 0
return -1 return -1
def get_stroke_color(self): def get_stroke_color(self):
'''
Returns stroke color in standard HTML format (#FFFFFF)
'''
return self.stroke return self.stroke
def get_fill_color(self): def get_fill_color(self):
'''
Returns fill color in standard HTML format (#FFFFFF)
'''
return self.fill return self.fill
def to_string(self): def to_string(self):
'''
Returns a formatted string in the format #STROKEHEX,#FILLHEX
'''
return '%s,%s' % (self.stroke, self.fill) return '%s,%s' % (self.stroke, self.fill)