Merge branch 'xocolor-docs' of https://github.com/ndefilippis/sugar-toolkit-gtk3
This commit is contained in:
commit
a62ddb1d87
@ -15,9 +15,10 @@
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# 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 logging
|
||||
@ -207,6 +208,12 @@ colors = [['#B20008', '#FF2B34'],
|
||||
|
||||
|
||||
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)):
|
||||
logging.error('Invalid color string: %r', color_string)
|
||||
return None
|
||||
@ -224,7 +231,15 @@ def _parse_string(color_string):
|
||||
|
||||
|
||||
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):
|
||||
parsed_color = None
|
||||
|
||||
@ -242,18 +257,34 @@ class XoColor:
|
||||
[self.stroke, self.fill] = parsed_color
|
||||
|
||||
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 self.stroke == other.stroke and self.fill == other.fill:
|
||||
return 0
|
||||
return -1
|
||||
|
||||
def get_stroke_color(self):
|
||||
'''
|
||||
Returns stroke color in standard HTML format (#FFFFFF)
|
||||
'''
|
||||
return self.stroke
|
||||
|
||||
def get_fill_color(self):
|
||||
'''
|
||||
Returns fill color in standard HTML format (#FFFFFF)
|
||||
'''
|
||||
return self.fill
|
||||
|
||||
def to_string(self):
|
||||
'''
|
||||
Returns a formatted string in the format #STROKEHEX,#FILLHEX
|
||||
'''
|
||||
return '%s,%s' % (self.stroke, self.fill)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user