partition stringclasses 3 values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1 value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
valid | Matrix.drawLine | Draw a between x0, y0 and x1, y1 in an RGB color.
:param colorFunc: a function that takes an integer from x0 to x1 and
returns a color corresponding to that point
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm | bibliopixel/layout/matrix.py | def drawLine(self, x0, y0, x1, y1, color=None, colorFunc=None, aa=False):
"""
Draw a between x0, y0 and x1, y1 in an RGB color.
:param colorFunc: a function that takes an integer from x0 to x1 and
returns a color corresponding to that point
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.draw_line(self.set, x0, y0, x1, y1, color, colorFunc, aa) | def drawLine(self, x0, y0, x1, y1, color=None, colorFunc=None, aa=False):
"""
Draw a between x0, y0 and x1, y1 in an RGB color.
:param colorFunc: a function that takes an integer from x0 to x1 and
returns a color corresponding to that point
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.draw_line(self.set, x0, y0, x1, y1, color, colorFunc, aa) | [
"Draw",
"a",
"between",
"x0",
"y0",
"and",
"x1",
"y1",
"in",
"an",
"RGB",
"color",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix.py#L234-L243 | [
"def",
"drawLine",
"(",
"self",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"color",
"=",
"None",
",",
"colorFunc",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"md",
".",
"draw_line",
"(",
"self",
".",
"set",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"color",
",",
"colorFunc",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Matrix.bresenham_line | Draw line from point x0, y0 to x1, y1 using Bresenham's algorithm.
Will draw beyond matrix bounds. | bibliopixel/layout/matrix.py | def bresenham_line(self, x0, y0, x1, y1, color=None, colorFunc=None):
"""
Draw line from point x0, y0 to x1, y1 using Bresenham's algorithm.
Will draw beyond matrix bounds.
"""
md.bresenham_line(self.set, x0, y0, x1, y1, color, colorFunc) | def bresenham_line(self, x0, y0, x1, y1, color=None, colorFunc=None):
"""
Draw line from point x0, y0 to x1, y1 using Bresenham's algorithm.
Will draw beyond matrix bounds.
"""
md.bresenham_line(self.set, x0, y0, x1, y1, color, colorFunc) | [
"Draw",
"line",
"from",
"point",
"x0",
"y0",
"to",
"x1",
"y1",
"using",
"Bresenham",
"s",
"algorithm",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix.py#L246-L252 | [
"def",
"bresenham_line",
"(",
"self",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"color",
"=",
"None",
",",
"colorFunc",
"=",
"None",
")",
":",
"md",
".",
"bresenham_line",
"(",
"self",
".",
"set",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"color",
",",
"colorFunc",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Matrix.drawRect | Draw rectangle with top-left corner at x,y, width w and height h
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm | bibliopixel/layout/matrix.py | def drawRect(self, x, y, w, h, color=None, aa=False):
"""
Draw rectangle with top-left corner at x,y, width w and height h
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.draw_rect(self.set, x, y, w, h, color, aa) | def drawRect(self, x, y, w, h, color=None, aa=False):
"""
Draw rectangle with top-left corner at x,y, width w and height h
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.draw_rect(self.set, x, y, w, h, color, aa) | [
"Draw",
"rectangle",
"with",
"top",
"-",
"left",
"corner",
"at",
"x",
"y",
"width",
"w",
"and",
"height",
"h"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix.py#L266-L273 | [
"def",
"drawRect",
"(",
"self",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"md",
".",
"draw_rect",
"(",
"self",
".",
"set",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"color",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Matrix.fillRect | Draw a solid rectangle with top-left corner at (x, y), width w and
height h.
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm | bibliopixel/layout/matrix.py | def fillRect(self, x, y, w, h, color=None, aa=False):
"""
Draw a solid rectangle with top-left corner at (x, y), width w and
height h.
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.fill_rect(self.set, x, y, w, h, color, aa) | def fillRect(self, x, y, w, h, color=None, aa=False):
"""
Draw a solid rectangle with top-left corner at (x, y), width w and
height h.
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.fill_rect(self.set, x, y, w, h, color, aa) | [
"Draw",
"a",
"solid",
"rectangle",
"with",
"top",
"-",
"left",
"corner",
"at",
"(",
"x",
"y",
")",
"width",
"w",
"and",
"height",
"h",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix.py#L275-L283 | [
"def",
"fillRect",
"(",
"self",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"md",
".",
"fill_rect",
"(",
"self",
".",
"set",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"color",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Matrix.fillScreen | Fill the matrix with the given RGB color | bibliopixel/layout/matrix.py | def fillScreen(self, color=None):
"""Fill the matrix with the given RGB color"""
md.fill_rect(self.set, 0, 0, self.width, self.height, color) | def fillScreen(self, color=None):
"""Fill the matrix with the given RGB color"""
md.fill_rect(self.set, 0, 0, self.width, self.height, color) | [
"Fill",
"the",
"matrix",
"with",
"the",
"given",
"RGB",
"color"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix.py#L285-L287 | [
"def",
"fillScreen",
"(",
"self",
",",
"color",
"=",
"None",
")",
":",
"md",
".",
"fill_rect",
"(",
"self",
".",
"set",
",",
"0",
",",
"0",
",",
"self",
".",
"width",
",",
"self",
".",
"height",
",",
"color",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Matrix.drawRoundRect | Draw a rounded rectangle with top-left corner at (x, y), width w,
height h, and corner radius r
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm | bibliopixel/layout/matrix.py | def drawRoundRect(self, x, y, w, h, r, color=None, aa=False):
"""
Draw a rounded rectangle with top-left corner at (x, y), width w,
height h, and corner radius r
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.draw_round_rect(self.set, x, y, w, h, r, color, aa) | def drawRoundRect(self, x, y, w, h, r, color=None, aa=False):
"""
Draw a rounded rectangle with top-left corner at (x, y), width w,
height h, and corner radius r
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.draw_round_rect(self.set, x, y, w, h, r, color, aa) | [
"Draw",
"a",
"rounded",
"rectangle",
"with",
"top",
"-",
"left",
"corner",
"at",
"(",
"x",
"y",
")",
"width",
"w",
"height",
"h",
"and",
"corner",
"radius",
"r"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix.py#L289-L297 | [
"def",
"drawRoundRect",
"(",
"self",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"r",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"md",
".",
"draw_round_rect",
"(",
"self",
".",
"set",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"r",
",",
"color",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Matrix.fillRoundRect | Draw a rounded rectangle with top-left corner at (x, y), width w,
height h, and corner radius r
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm | bibliopixel/layout/matrix.py | def fillRoundRect(self, x, y, w, h, r, color=None, aa=False):
"""
Draw a rounded rectangle with top-left corner at (x, y), width w,
height h, and corner radius r
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.fill_round_rect(self.set, x, y, w, h, r, color, aa) | def fillRoundRect(self, x, y, w, h, r, color=None, aa=False):
"""
Draw a rounded rectangle with top-left corner at (x, y), width w,
height h, and corner radius r
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.fill_round_rect(self.set, x, y, w, h, r, color, aa) | [
"Draw",
"a",
"rounded",
"rectangle",
"with",
"top",
"-",
"left",
"corner",
"at",
"(",
"x",
"y",
")",
"width",
"w",
"height",
"h",
"and",
"corner",
"radius",
"r"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix.py#L299-L307 | [
"def",
"fillRoundRect",
"(",
"self",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"r",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"md",
".",
"fill_round_rect",
"(",
"self",
".",
"set",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"r",
",",
"color",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Matrix.drawTriangle | Draw triangle with vertices (x0, y0), (x1, y1) and (x2, y2)
:param aa: if True, use Bresenham's algorithm for line drawing;
Otherwise use Xiaolin Wu's algorithm | bibliopixel/layout/matrix.py | def drawTriangle(self, x0, y0, x1, y1, x2, y2, color=None, aa=False):
"""
Draw triangle with vertices (x0, y0), (x1, y1) and (x2, y2)
:param aa: if True, use Bresenham's algorithm for line drawing;
Otherwise use Xiaolin Wu's algorithm
"""
md.draw_triangle(self.set, x0, y0, x1, y1, x2, y2, color, aa) | def drawTriangle(self, x0, y0, x1, y1, x2, y2, color=None, aa=False):
"""
Draw triangle with vertices (x0, y0), (x1, y1) and (x2, y2)
:param aa: if True, use Bresenham's algorithm for line drawing;
Otherwise use Xiaolin Wu's algorithm
"""
md.draw_triangle(self.set, x0, y0, x1, y1, x2, y2, color, aa) | [
"Draw",
"triangle",
"with",
"vertices",
"(",
"x0",
"y0",
")",
"(",
"x1",
"y1",
")",
"and",
"(",
"x2",
"y2",
")"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix.py#L309-L316 | [
"def",
"drawTriangle",
"(",
"self",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"md",
".",
"draw_triangle",
"(",
"self",
".",
"set",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
",",
"color",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Matrix.fillTriangle | Draw filled triangle with points x0,y0 - x1,y1 - x2,y2
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm | bibliopixel/layout/matrix.py | def fillTriangle(self, x0, y0, x1, y1, x2, y2, color=None, aa=False):
"""
Draw filled triangle with points x0,y0 - x1,y1 - x2,y2
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.fill_triangle(self.set, x0, y0, x1, y1, x2, y2, color, aa) | def fillTriangle(self, x0, y0, x1, y1, x2, y2, color=None, aa=False):
"""
Draw filled triangle with points x0,y0 - x1,y1 - x2,y2
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.fill_triangle(self.set, x0, y0, x1, y1, x2, y2, color, aa) | [
"Draw",
"filled",
"triangle",
"with",
"points",
"x0",
"y0",
"-",
"x1",
"y1",
"-",
"x2",
"y2"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix.py#L318-L325 | [
"def",
"fillTriangle",
"(",
"self",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"md",
".",
"fill_triangle",
"(",
"self",
".",
"set",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
",",
"color",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Matrix.drawChar | Draw a single character c at at (x, y) in an RGB color. | bibliopixel/layout/matrix.py | def drawChar(self, x, y, c, color, bg,
aa=False, font=font.default_font, font_scale=1):
"""
Draw a single character c at at (x, y) in an RGB color.
"""
md.draw_char(self.fonts, self.set, self.width, self.height,
x, y, c, color, bg, aa, font, font_scale) | def drawChar(self, x, y, c, color, bg,
aa=False, font=font.default_font, font_scale=1):
"""
Draw a single character c at at (x, y) in an RGB color.
"""
md.draw_char(self.fonts, self.set, self.width, self.height,
x, y, c, color, bg, aa, font, font_scale) | [
"Draw",
"a",
"single",
"character",
"c",
"at",
"at",
"(",
"x",
"y",
")",
"in",
"an",
"RGB",
"color",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix.py#L330-L336 | [
"def",
"drawChar",
"(",
"self",
",",
"x",
",",
"y",
",",
"c",
",",
"color",
",",
"bg",
",",
"aa",
"=",
"False",
",",
"font",
"=",
"font",
".",
"default_font",
",",
"font_scale",
"=",
"1",
")",
":",
"md",
".",
"draw_char",
"(",
"self",
".",
"fonts",
",",
"self",
".",
"set",
",",
"self",
".",
"width",
",",
"self",
".",
"height",
",",
"x",
",",
"y",
",",
"c",
",",
"color",
",",
"bg",
",",
"aa",
",",
"font",
",",
"font_scale",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Matrix.drawText | Draw a line of text starting at (x, y) in an RGB color.
:param colorFunc: a function that takes an integer from x0 to x1 and
returns a color corresponding to that point
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm | bibliopixel/layout/matrix.py | def drawText(self, text, x=0, y=0, color=None,
bg=colors.COLORS.Off, aa=False, font=font.default_font,
font_scale=1):
"""
Draw a line of text starting at (x, y) in an RGB color.
:param colorFunc: a function that takes an integer from x0 to x1 and
returns a color corresponding to that point
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.draw_text(self.fonts, self.set, text, self.width, self.height,
x, y, color, bg, aa, font, font_scale) | def drawText(self, text, x=0, y=0, color=None,
bg=colors.COLORS.Off, aa=False, font=font.default_font,
font_scale=1):
"""
Draw a line of text starting at (x, y) in an RGB color.
:param colorFunc: a function that takes an integer from x0 to x1 and
returns a color corresponding to that point
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.draw_text(self.fonts, self.set, text, self.width, self.height,
x, y, color, bg, aa, font, font_scale) | [
"Draw",
"a",
"line",
"of",
"text",
"starting",
"at",
"(",
"x",
"y",
")",
"in",
"an",
"RGB",
"color",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix.py#L338-L350 | [
"def",
"drawText",
"(",
"self",
",",
"text",
",",
"x",
"=",
"0",
",",
"y",
"=",
"0",
",",
"color",
"=",
"None",
",",
"bg",
"=",
"colors",
".",
"COLORS",
".",
"Off",
",",
"aa",
"=",
"False",
",",
"font",
"=",
"font",
".",
"default_font",
",",
"font_scale",
"=",
"1",
")",
":",
"md",
".",
"draw_text",
"(",
"self",
".",
"fonts",
",",
"self",
".",
"set",
",",
"text",
",",
"self",
".",
"width",
",",
"self",
".",
"height",
",",
"x",
",",
"y",
",",
"color",
",",
"bg",
",",
"aa",
",",
"font",
",",
"font_scale",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Routing.set_project | Set the base project for routing. | bibliopixel/control/routing.py | def set_project(self, project):
"""Set the base project for routing."""
def visit(x):
# Try to set_project, then recurse through any values()
set_project = getattr(x, 'set_project', None)
if set_project:
set_project(project)
values = getattr(x, 'values', lambda: ())
for v in values():
visit(v)
visit(self.routing) | def set_project(self, project):
"""Set the base project for routing."""
def visit(x):
# Try to set_project, then recurse through any values()
set_project = getattr(x, 'set_project', None)
if set_project:
set_project(project)
values = getattr(x, 'values', lambda: ())
for v in values():
visit(v)
visit(self.routing) | [
"Set",
"the",
"base",
"project",
"for",
"routing",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/control/routing.py#L40-L51 | [
"def",
"set_project",
"(",
"self",
",",
"project",
")",
":",
"def",
"visit",
"(",
"x",
")",
":",
"# Try to set_project, then recurse through any values()",
"set_project",
"=",
"getattr",
"(",
"x",
",",
"'set_project'",
",",
"None",
")",
"if",
"set_project",
":",
"set_project",
"(",
"project",
")",
"values",
"=",
"getattr",
"(",
"x",
",",
"'values'",
",",
"lambda",
":",
"(",
")",
")",
"for",
"v",
"in",
"values",
"(",
")",
":",
"visit",
"(",
"v",
")",
"visit",
"(",
"self",
".",
"routing",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Routing.receive | Returns a (receiver, msg) pair, where receiver is `None` if no route for
the message was found, or otherwise an object with a `receive` method
that can accept that `msg`. | bibliopixel/control/routing.py | def receive(self, msg):
"""
Returns a (receiver, msg) pair, where receiver is `None` if no route for
the message was found, or otherwise an object with a `receive` method
that can accept that `msg`.
"""
x = self.routing
while not isinstance(x, ActionList):
if not x or not msg:
return None, msg
if not isinstance(x, dict):
raise ValueError('Unexpected type %s' % type(x))
_, value = msg.popitem(last=False)
x = x.get(str(value))
return x, msg | def receive(self, msg):
"""
Returns a (receiver, msg) pair, where receiver is `None` if no route for
the message was found, or otherwise an object with a `receive` method
that can accept that `msg`.
"""
x = self.routing
while not isinstance(x, ActionList):
if not x or not msg:
return None, msg
if not isinstance(x, dict):
raise ValueError('Unexpected type %s' % type(x))
_, value = msg.popitem(last=False)
x = x.get(str(value))
return x, msg | [
"Returns",
"a",
"(",
"receiver",
"msg",
")",
"pair",
"where",
"receiver",
"is",
"None",
"if",
"no",
"route",
"for",
"the",
"message",
"was",
"found",
"or",
"otherwise",
"an",
"object",
"with",
"a",
"receive",
"method",
"that",
"can",
"accept",
"that",
"msg",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/control/routing.py#L53-L70 | [
"def",
"receive",
"(",
"self",
",",
"msg",
")",
":",
"x",
"=",
"self",
".",
"routing",
"while",
"not",
"isinstance",
"(",
"x",
",",
"ActionList",
")",
":",
"if",
"not",
"x",
"or",
"not",
"msg",
":",
"return",
"None",
",",
"msg",
"if",
"not",
"isinstance",
"(",
"x",
",",
"dict",
")",
":",
"raise",
"ValueError",
"(",
"'Unexpected type %s'",
"%",
"type",
"(",
"x",
")",
")",
"_",
",",
"value",
"=",
"msg",
".",
"popitem",
"(",
"last",
"=",
"False",
")",
"x",
"=",
"x",
".",
"get",
"(",
"str",
"(",
"value",
")",
")",
"return",
"x",
",",
"msg"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Circle.set | Set pixel to RGB color tuple | bibliopixel/layout/circle.py | def set(self, ring, angle, color):
"""Set pixel to RGB color tuple"""
pixel = self.angleToPixel(angle, ring)
self._set_base(pixel, color) | def set(self, ring, angle, color):
"""Set pixel to RGB color tuple"""
pixel = self.angleToPixel(angle, ring)
self._set_base(pixel, color) | [
"Set",
"pixel",
"to",
"RGB",
"color",
"tuple"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/circle.py#L83-L86 | [
"def",
"set",
"(",
"self",
",",
"ring",
",",
"angle",
",",
"color",
")",
":",
"pixel",
"=",
"self",
".",
"angleToPixel",
"(",
"angle",
",",
"ring",
")",
"self",
".",
"_set_base",
"(",
"pixel",
",",
"color",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Circle.get | Get RGB color tuple of color at index pixel | bibliopixel/layout/circle.py | def get(self, ring, angle):
"""Get RGB color tuple of color at index pixel"""
pixel = self.angleToPixel(angle, ring)
return self._get_base(pixel) | def get(self, ring, angle):
"""Get RGB color tuple of color at index pixel"""
pixel = self.angleToPixel(angle, ring)
return self._get_base(pixel) | [
"Get",
"RGB",
"color",
"tuple",
"of",
"color",
"at",
"index",
"pixel"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/circle.py#L88-L91 | [
"def",
"get",
"(",
"self",
",",
"ring",
",",
"angle",
")",
":",
"pixel",
"=",
"self",
".",
"angleToPixel",
"(",
"angle",
",",
"ring",
")",
"return",
"self",
".",
"_get_base",
"(",
"pixel",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | run | Create input, output queues, call `function` in a subprocess or a thread.
``function`` is called like this: ``function(input, output, *args, **kwds)``
:param use_subprocess: if true, create a new multiprocess;
if false, create a new thread
:param function: the function to call
:param daemon: is the thread or subprocess run as a daemon or not?
:param args: positional arguments to the function
:param kwds: keyword arguments to the function
:returns: a tuple with three elements: the subprocess or thread, an input
queue, and an output queue. | bibliopixel/util/threads/sub.py | def run(function, *args, use_subprocess=False, daemon=True, **kwds):
"""
Create input, output queues, call `function` in a subprocess or a thread.
``function`` is called like this: ``function(input, output, *args, **kwds)``
:param use_subprocess: if true, create a new multiprocess;
if false, create a new thread
:param function: the function to call
:param daemon: is the thread or subprocess run as a daemon or not?
:param args: positional arguments to the function
:param kwds: keyword arguments to the function
:returns: a tuple with three elements: the subprocess or thread, an input
queue, and an output queue.
"""
if use_subprocess:
Creator, Queue = multiprocessing.Process, multiprocessing.Queue
else:
Creator, Queue = threading.Thread, queue.Queue
input, output = Queue(), Queue()
args = input, output, function, args
sub = Creator(target=_run_locally, args=args, kwargs=kwds, daemon=daemon)
sub.start()
return sub, input, output | def run(function, *args, use_subprocess=False, daemon=True, **kwds):
"""
Create input, output queues, call `function` in a subprocess or a thread.
``function`` is called like this: ``function(input, output, *args, **kwds)``
:param use_subprocess: if true, create a new multiprocess;
if false, create a new thread
:param function: the function to call
:param daemon: is the thread or subprocess run as a daemon or not?
:param args: positional arguments to the function
:param kwds: keyword arguments to the function
:returns: a tuple with three elements: the subprocess or thread, an input
queue, and an output queue.
"""
if use_subprocess:
Creator, Queue = multiprocessing.Process, multiprocessing.Queue
else:
Creator, Queue = threading.Thread, queue.Queue
input, output = Queue(), Queue()
args = input, output, function, args
sub = Creator(target=_run_locally, args=args, kwargs=kwds, daemon=daemon)
sub.start()
return sub, input, output | [
"Create",
"input",
"output",
"queues",
"call",
"function",
"in",
"a",
"subprocess",
"or",
"a",
"thread",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/threads/sub.py#L12-L38 | [
"def",
"run",
"(",
"function",
",",
"*",
"args",
",",
"use_subprocess",
"=",
"False",
",",
"daemon",
"=",
"True",
",",
"*",
"*",
"kwds",
")",
":",
"if",
"use_subprocess",
":",
"Creator",
",",
"Queue",
"=",
"multiprocessing",
".",
"Process",
",",
"multiprocessing",
".",
"Queue",
"else",
":",
"Creator",
",",
"Queue",
"=",
"threading",
".",
"Thread",
",",
"queue",
".",
"Queue",
"input",
",",
"output",
"=",
"Queue",
"(",
")",
",",
"Queue",
"(",
")",
"args",
"=",
"input",
",",
"output",
",",
"function",
",",
"args",
"sub",
"=",
"Creator",
"(",
"target",
"=",
"_run_locally",
",",
"args",
"=",
"args",
",",
"kwargs",
"=",
"kwds",
",",
"daemon",
"=",
"daemon",
")",
"sub",
".",
"start",
"(",
")",
"return",
"sub",
",",
"input",
",",
"output"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | color_scale | Scale RGB tuple by level, 0 - 256 | bibliopixel/colors/arithmetic.py | def color_scale(color, level):
"""
Scale RGB tuple by level, 0 - 256
"""
return tuple([int(i * level) >> 8 for i in list(color)]) | def color_scale(color, level):
"""
Scale RGB tuple by level, 0 - 256
"""
return tuple([int(i * level) >> 8 for i in list(color)]) | [
"Scale",
"RGB",
"tuple",
"by",
"level",
"0",
"-",
"256"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/arithmetic.py#L10-L14 | [
"def",
"color_scale",
"(",
"color",
",",
"level",
")",
":",
"return",
"tuple",
"(",
"[",
"int",
"(",
"i",
"*",
"level",
")",
">>",
"8",
"for",
"i",
"in",
"list",
"(",
"color",
")",
"]",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | SavedDescription.load | Load/reload the description from a YML file. Prompt if no file given. | bibliopixel/builder/saved_description.py | def load(self, project_file=''):
"""Load/reload the description from a YML file. Prompt if no file given."""
self._request_project_file(project_file)
self.clear()
self.desc.update(data_file.load(self._project_file)) | def load(self, project_file=''):
"""Load/reload the description from a YML file. Prompt if no file given."""
self._request_project_file(project_file)
self.clear()
self.desc.update(data_file.load(self._project_file)) | [
"Load",
"/",
"reload",
"the",
"description",
"from",
"a",
"YML",
"file",
".",
"Prompt",
"if",
"no",
"file",
"given",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/builder/saved_description.py#L19-L23 | [
"def",
"load",
"(",
"self",
",",
"project_file",
"=",
"''",
")",
":",
"self",
".",
"_request_project_file",
"(",
"project_file",
")",
"self",
".",
"clear",
"(",
")",
"self",
".",
"desc",
".",
"update",
"(",
"data_file",
".",
"load",
"(",
"self",
".",
"_project_file",
")",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | SavedDescription.save | Save the description as a YML file. Prompt if no file given. | bibliopixel/builder/saved_description.py | def save(self, project_file=''):
"""Save the description as a YML file. Prompt if no file given."""
self._request_project_file(project_file)
data_file.dump(self.desc.as_dict(), self.project_file) | def save(self, project_file=''):
"""Save the description as a YML file. Prompt if no file given."""
self._request_project_file(project_file)
data_file.dump(self.desc.as_dict(), self.project_file) | [
"Save",
"the",
"description",
"as",
"a",
"YML",
"file",
".",
"Prompt",
"if",
"no",
"file",
"given",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/builder/saved_description.py#L25-L28 | [
"def",
"save",
"(",
"self",
",",
"project_file",
"=",
"''",
")",
":",
"self",
".",
"_request_project_file",
"(",
"project_file",
")",
"data_file",
".",
"dump",
"(",
"self",
".",
"desc",
".",
"as_dict",
"(",
")",
",",
"self",
".",
"project_file",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Palette.get | Return a color interpolated from the Palette.
In the case where continuous=False, serpentine=False, scale=1,
autoscale=False, and offset=0, this is exactly the same as plain old []
indexing, but with a wrap-around.
The constructor parameters affect this result as documented in the
constructor.
Arguments:
``position``:
May be any integer or floating point number | bibliopixel/colors/palette.py | def get(self, position=0):
"""
Return a color interpolated from the Palette.
In the case where continuous=False, serpentine=False, scale=1,
autoscale=False, and offset=0, this is exactly the same as plain old []
indexing, but with a wrap-around.
The constructor parameters affect this result as documented in the
constructor.
Arguments:
``position``:
May be any integer or floating point number
"""
n = len(self)
if n == 1:
return self[0]
pos = position
if self.length and self.autoscale:
pos *= len(self)
pos /= self.length
pos *= self.scale
pos += self.offset
if not self.continuous:
if not self.serpentine:
return self[int(pos % n)]
# We want a color sequence of length 2n-2
# e.g. for n=5: a b c d | e d c b | a b c d ...
m = (2 * n) - 2
pos %= m
if pos < n:
return self[int(pos)]
else:
return self[int(m - pos)]
if self.serpentine:
pos %= (2 * n)
if pos > n:
pos = (2 * n) - pos
else:
pos %= n
# p is a number in [0, n): scale it to be in [0, n-1)
pos *= n - 1
pos /= n
index = int(pos)
fade = pos - index
if not fade:
return self[index]
r1, g1, b1 = self[index]
r2, g2, b2 = self[(index + 1) % len(self)]
dr, dg, db = r2 - r1, g2 - g1, b2 - b1
return r1 + fade * dr, g1 + fade * dg, b1 + fade * db | def get(self, position=0):
"""
Return a color interpolated from the Palette.
In the case where continuous=False, serpentine=False, scale=1,
autoscale=False, and offset=0, this is exactly the same as plain old []
indexing, but with a wrap-around.
The constructor parameters affect this result as documented in the
constructor.
Arguments:
``position``:
May be any integer or floating point number
"""
n = len(self)
if n == 1:
return self[0]
pos = position
if self.length and self.autoscale:
pos *= len(self)
pos /= self.length
pos *= self.scale
pos += self.offset
if not self.continuous:
if not self.serpentine:
return self[int(pos % n)]
# We want a color sequence of length 2n-2
# e.g. for n=5: a b c d | e d c b | a b c d ...
m = (2 * n) - 2
pos %= m
if pos < n:
return self[int(pos)]
else:
return self[int(m - pos)]
if self.serpentine:
pos %= (2 * n)
if pos > n:
pos = (2 * n) - pos
else:
pos %= n
# p is a number in [0, n): scale it to be in [0, n-1)
pos *= n - 1
pos /= n
index = int(pos)
fade = pos - index
if not fade:
return self[index]
r1, g1, b1 = self[index]
r2, g2, b2 = self[(index + 1) % len(self)]
dr, dg, db = r2 - r1, g2 - g1, b2 - b1
return r1 + fade * dr, g1 + fade * dg, b1 + fade * db | [
"Return",
"a",
"color",
"interpolated",
"from",
"the",
"Palette",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/palette.py#L56-L117 | [
"def",
"get",
"(",
"self",
",",
"position",
"=",
"0",
")",
":",
"n",
"=",
"len",
"(",
"self",
")",
"if",
"n",
"==",
"1",
":",
"return",
"self",
"[",
"0",
"]",
"pos",
"=",
"position",
"if",
"self",
".",
"length",
"and",
"self",
".",
"autoscale",
":",
"pos",
"*=",
"len",
"(",
"self",
")",
"pos",
"/=",
"self",
".",
"length",
"pos",
"*=",
"self",
".",
"scale",
"pos",
"+=",
"self",
".",
"offset",
"if",
"not",
"self",
".",
"continuous",
":",
"if",
"not",
"self",
".",
"serpentine",
":",
"return",
"self",
"[",
"int",
"(",
"pos",
"%",
"n",
")",
"]",
"# We want a color sequence of length 2n-2",
"# e.g. for n=5: a b c d | e d c b | a b c d ...",
"m",
"=",
"(",
"2",
"*",
"n",
")",
"-",
"2",
"pos",
"%=",
"m",
"if",
"pos",
"<",
"n",
":",
"return",
"self",
"[",
"int",
"(",
"pos",
")",
"]",
"else",
":",
"return",
"self",
"[",
"int",
"(",
"m",
"-",
"pos",
")",
"]",
"if",
"self",
".",
"serpentine",
":",
"pos",
"%=",
"(",
"2",
"*",
"n",
")",
"if",
"pos",
">",
"n",
":",
"pos",
"=",
"(",
"2",
"*",
"n",
")",
"-",
"pos",
"else",
":",
"pos",
"%=",
"n",
"# p is a number in [0, n): scale it to be in [0, n-1)",
"pos",
"*=",
"n",
"-",
"1",
"pos",
"/=",
"n",
"index",
"=",
"int",
"(",
"pos",
")",
"fade",
"=",
"pos",
"-",
"index",
"if",
"not",
"fade",
":",
"return",
"self",
"[",
"index",
"]",
"r1",
",",
"g1",
",",
"b1",
"=",
"self",
"[",
"index",
"]",
"r2",
",",
"g2",
",",
"b2",
"=",
"self",
"[",
"(",
"index",
"+",
"1",
")",
"%",
"len",
"(",
"self",
")",
"]",
"dr",
",",
"dg",
",",
"db",
"=",
"r2",
"-",
"r1",
",",
"g2",
"-",
"g1",
",",
"b2",
"-",
"b1",
"return",
"r1",
"+",
"fade",
"*",
"dr",
",",
"g1",
"+",
"fade",
"*",
"dg",
",",
"b1",
"+",
"fade",
"*",
"db"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Task.run | Wait for the event, run the task, trigger the next task. | bibliopixel/util/threads/task_thread.py | def run(self, next_task):
"""Wait for the event, run the task, trigger the next task."""
self.event.wait()
self.task()
self.event.clear()
next_task.event.set() | def run(self, next_task):
"""Wait for the event, run the task, trigger the next task."""
self.event.wait()
self.task()
self.event.clear()
next_task.event.set() | [
"Wait",
"for",
"the",
"event",
"run",
"the",
"task",
"trigger",
"the",
"next",
"task",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/threads/task_thread.py#L10-L16 | [
"def",
"run",
"(",
"self",
",",
"next_task",
")",
":",
"self",
".",
"event",
".",
"wait",
"(",
")",
"self",
".",
"task",
"(",
")",
"self",
".",
"event",
".",
"clear",
"(",
")",
"next_task",
".",
"event",
".",
"set",
"(",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | report | Run a function, catch, report and discard exceptions | bibliopixel/util/exception.py | def report(function, *args, **kwds):
"""Run a function, catch, report and discard exceptions"""
try:
function(*args, **kwds)
except Exception:
traceback.print_exc() | def report(function, *args, **kwds):
"""Run a function, catch, report and discard exceptions"""
try:
function(*args, **kwds)
except Exception:
traceback.print_exc() | [
"Run",
"a",
"function",
"catch",
"report",
"and",
"discard",
"exceptions"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/exception.py#L19-L24 | [
"def",
"report",
"(",
"function",
",",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
":",
"try",
":",
"function",
"(",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
"except",
"Exception",
":",
"traceback",
".",
"print_exc",
"(",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Control._receive | Receive a message from the input source and perhaps raise an Exception. | bibliopixel/control/control.py | def _receive(self, msg):
"""
Receive a message from the input source and perhaps raise an Exception.
"""
msg = self._convert(msg)
if msg is None:
return
str_msg = self.verbose and self._msg_to_str(msg)
if self.verbose and log.is_debug():
log.debug('Message %s', str_msg)
if self.pre_routing:
self.pre_routing.receive(msg)
receiver, msg = self.routing.receive(msg)
if receiver:
receiver.receive(msg)
if self.verbose:
log.info('Routed message %s (%s) to %s', str_msg[:128], msg,
repr(receiver)) | def _receive(self, msg):
"""
Receive a message from the input source and perhaps raise an Exception.
"""
msg = self._convert(msg)
if msg is None:
return
str_msg = self.verbose and self._msg_to_str(msg)
if self.verbose and log.is_debug():
log.debug('Message %s', str_msg)
if self.pre_routing:
self.pre_routing.receive(msg)
receiver, msg = self.routing.receive(msg)
if receiver:
receiver.receive(msg)
if self.verbose:
log.info('Routed message %s (%s) to %s', str_msg[:128], msg,
repr(receiver)) | [
"Receive",
"a",
"message",
"from",
"the",
"input",
"source",
"and",
"perhaps",
"raise",
"an",
"Exception",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/control/control.py#L49-L69 | [
"def",
"_receive",
"(",
"self",
",",
"msg",
")",
":",
"msg",
"=",
"self",
".",
"_convert",
"(",
"msg",
")",
"if",
"msg",
"is",
"None",
":",
"return",
"str_msg",
"=",
"self",
".",
"verbose",
"and",
"self",
".",
"_msg_to_str",
"(",
"msg",
")",
"if",
"self",
".",
"verbose",
"and",
"log",
".",
"is_debug",
"(",
")",
":",
"log",
".",
"debug",
"(",
"'Message %s'",
",",
"str_msg",
")",
"if",
"self",
".",
"pre_routing",
":",
"self",
".",
"pre_routing",
".",
"receive",
"(",
"msg",
")",
"receiver",
",",
"msg",
"=",
"self",
".",
"routing",
".",
"receive",
"(",
"msg",
")",
"if",
"receiver",
":",
"receiver",
".",
"receive",
"(",
"msg",
")",
"if",
"self",
".",
"verbose",
":",
"log",
".",
"info",
"(",
"'Routed message %s (%s) to %s'",
",",
"str_msg",
"[",
":",
"128",
"]",
",",
"msg",
",",
"repr",
"(",
"receiver",
")",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | APA102.set_device_brightness | APA102 & SK9822 support on-chip brightness control, allowing greater
color depth.
APA102 superimposes a 440Hz PWM on the 19kHz base PWM to control
brightness. SK9822 uses a base 4.7kHz PWM but controls brightness with a
variable current source.
Because of this SK9822 will have much less flicker at lower levels.
Either way, this option is better and faster than scaling in
BiblioPixel. | bibliopixel/drivers/SPI/APA102.py | def set_device_brightness(self, val):
"""
APA102 & SK9822 support on-chip brightness control, allowing greater
color depth.
APA102 superimposes a 440Hz PWM on the 19kHz base PWM to control
brightness. SK9822 uses a base 4.7kHz PWM but controls brightness with a
variable current source.
Because of this SK9822 will have much less flicker at lower levels.
Either way, this option is better and faster than scaling in
BiblioPixel.
"""
# bitshift to scale from 8 bit to 5
self._chipset_brightness = (val >> 3)
self._brightness_list = [0xE0 + self._chipset_brightness] * self.numLEDs
self._packet[self._start_frame:self._pixel_stop:4] = (
self._brightness_list) | def set_device_brightness(self, val):
"""
APA102 & SK9822 support on-chip brightness control, allowing greater
color depth.
APA102 superimposes a 440Hz PWM on the 19kHz base PWM to control
brightness. SK9822 uses a base 4.7kHz PWM but controls brightness with a
variable current source.
Because of this SK9822 will have much less flicker at lower levels.
Either way, this option is better and faster than scaling in
BiblioPixel.
"""
# bitshift to scale from 8 bit to 5
self._chipset_brightness = (val >> 3)
self._brightness_list = [0xE0 + self._chipset_brightness] * self.numLEDs
self._packet[self._start_frame:self._pixel_stop:4] = (
self._brightness_list) | [
"APA102",
"&",
"SK9822",
"support",
"on",
"-",
"chip",
"brightness",
"control",
"allowing",
"greater",
"color",
"depth",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/drivers/SPI/APA102.py#L30-L47 | [
"def",
"set_device_brightness",
"(",
"self",
",",
"val",
")",
":",
"# bitshift to scale from 8 bit to 5",
"self",
".",
"_chipset_brightness",
"=",
"(",
"val",
">>",
"3",
")",
"self",
".",
"_brightness_list",
"=",
"[",
"0xE0",
"+",
"self",
".",
"_chipset_brightness",
"]",
"*",
"self",
".",
"numLEDs",
"self",
".",
"_packet",
"[",
"self",
".",
"_start_frame",
":",
"self",
".",
"_pixel_stop",
":",
"4",
"]",
"=",
"(",
"self",
".",
"_brightness_list",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | _addLoggingLevel | Comprehensively adds a new logging level to the `logging` module and the
currently configured logging class.
`levelName` becomes an attribute of the `logging` module with the value
`levelNum`. `methodName` becomes a convenience method for both `logging`
itself and the class returned by `logging.getLoggerClass()` (usually just
`logging.Logger`). If `methodName` is not specified, `levelName.lower()` is
used.
To avoid accidental clobberings of existing attributes, this method will
raise an `AttributeError` if the level name is already an attribute of the
`logging` module or if the method name is already present
Example
-------
>>> addLoggingLevel('TRACE', logging.DEBUG - 5)
>>> logging.getLogger(__name__).setLevel("TRACE")
>>> logging.getLogger(__name__).trace('that worked')
>>> logging.trace('so did this')
>>> logging.TRACE
5 | bibliopixel/util/log.py | def _addLoggingLevel(levelName, levelNum, methodName=None):
"""
Comprehensively adds a new logging level to the `logging` module and the
currently configured logging class.
`levelName` becomes an attribute of the `logging` module with the value
`levelNum`. `methodName` becomes a convenience method for both `logging`
itself and the class returned by `logging.getLoggerClass()` (usually just
`logging.Logger`). If `methodName` is not specified, `levelName.lower()` is
used.
To avoid accidental clobberings of existing attributes, this method will
raise an `AttributeError` if the level name is already an attribute of the
`logging` module or if the method name is already present
Example
-------
>>> addLoggingLevel('TRACE', logging.DEBUG - 5)
>>> logging.getLogger(__name__).setLevel("TRACE")
>>> logging.getLogger(__name__).trace('that worked')
>>> logging.trace('so did this')
>>> logging.TRACE
5
"""
if not methodName:
methodName = levelName.lower()
if hasattr(logging, levelName):
raise AttributeError(
'{} already defined in logging module'.format(levelName))
if hasattr(logging, methodName):
raise AttributeError(
'{} already defined in logging module'.format(methodName))
if hasattr(logging.getLoggerClass(), methodName):
raise AttributeError(
'{} already defined in logger class'.format(methodName))
# This method was inspired by the answers to Stack Overflow post
# http://stackoverflow.com/q/2183233/2988730, especially
# http://stackoverflow.com/a/13638084/2988730
def logForLevel(self, message, *args, **kwargs):
if self.isEnabledFor(levelNum):
self._log(levelNum, message, args, **kwargs)
def logToRoot(message, *args, **kwargs):
logging.log(levelNum, message, *args, **kwargs)
logging.addLevelName(levelNum, levelName)
setattr(logging, levelName, levelNum)
setattr(logging.getLoggerClass(), methodName, logForLevel)
setattr(logging, methodName, logToRoot) | def _addLoggingLevel(levelName, levelNum, methodName=None):
"""
Comprehensively adds a new logging level to the `logging` module and the
currently configured logging class.
`levelName` becomes an attribute of the `logging` module with the value
`levelNum`. `methodName` becomes a convenience method for both `logging`
itself and the class returned by `logging.getLoggerClass()` (usually just
`logging.Logger`). If `methodName` is not specified, `levelName.lower()` is
used.
To avoid accidental clobberings of existing attributes, this method will
raise an `AttributeError` if the level name is already an attribute of the
`logging` module or if the method name is already present
Example
-------
>>> addLoggingLevel('TRACE', logging.DEBUG - 5)
>>> logging.getLogger(__name__).setLevel("TRACE")
>>> logging.getLogger(__name__).trace('that worked')
>>> logging.trace('so did this')
>>> logging.TRACE
5
"""
if not methodName:
methodName = levelName.lower()
if hasattr(logging, levelName):
raise AttributeError(
'{} already defined in logging module'.format(levelName))
if hasattr(logging, methodName):
raise AttributeError(
'{} already defined in logging module'.format(methodName))
if hasattr(logging.getLoggerClass(), methodName):
raise AttributeError(
'{} already defined in logger class'.format(methodName))
# This method was inspired by the answers to Stack Overflow post
# http://stackoverflow.com/q/2183233/2988730, especially
# http://stackoverflow.com/a/13638084/2988730
def logForLevel(self, message, *args, **kwargs):
if self.isEnabledFor(levelNum):
self._log(levelNum, message, args, **kwargs)
def logToRoot(message, *args, **kwargs):
logging.log(levelNum, message, *args, **kwargs)
logging.addLevelName(levelNum, levelName)
setattr(logging, levelName, levelNum)
setattr(logging.getLoggerClass(), methodName, logForLevel)
setattr(logging, methodName, logToRoot) | [
"Comprehensively",
"adds",
"a",
"new",
"logging",
"level",
"to",
"the",
"logging",
"module",
"and",
"the",
"currently",
"configured",
"logging",
"class",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/log.py#L31-L82 | [
"def",
"_addLoggingLevel",
"(",
"levelName",
",",
"levelNum",
",",
"methodName",
"=",
"None",
")",
":",
"if",
"not",
"methodName",
":",
"methodName",
"=",
"levelName",
".",
"lower",
"(",
")",
"if",
"hasattr",
"(",
"logging",
",",
"levelName",
")",
":",
"raise",
"AttributeError",
"(",
"'{} already defined in logging module'",
".",
"format",
"(",
"levelName",
")",
")",
"if",
"hasattr",
"(",
"logging",
",",
"methodName",
")",
":",
"raise",
"AttributeError",
"(",
"'{} already defined in logging module'",
".",
"format",
"(",
"methodName",
")",
")",
"if",
"hasattr",
"(",
"logging",
".",
"getLoggerClass",
"(",
")",
",",
"methodName",
")",
":",
"raise",
"AttributeError",
"(",
"'{} already defined in logger class'",
".",
"format",
"(",
"methodName",
")",
")",
"# This method was inspired by the answers to Stack Overflow post",
"# http://stackoverflow.com/q/2183233/2988730, especially",
"# http://stackoverflow.com/a/13638084/2988730",
"def",
"logForLevel",
"(",
"self",
",",
"message",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"isEnabledFor",
"(",
"levelNum",
")",
":",
"self",
".",
"_log",
"(",
"levelNum",
",",
"message",
",",
"args",
",",
"*",
"*",
"kwargs",
")",
"def",
"logToRoot",
"(",
"message",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"logging",
".",
"log",
"(",
"levelNum",
",",
"message",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"logging",
".",
"addLevelName",
"(",
"levelNum",
",",
"levelName",
")",
"setattr",
"(",
"logging",
",",
"levelName",
",",
"levelNum",
")",
"setattr",
"(",
"logging",
".",
"getLoggerClass",
"(",
")",
",",
"methodName",
",",
"logForLevel",
")",
"setattr",
"(",
"logging",
",",
"methodName",
",",
"logToRoot",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | set_log_level | :param level: the level to set - either a string level name from
'frame', 'debug', 'info', 'warning', 'error'
or an integer log level from:
log.FRAME, log.DEBUG, log.INFO, log.WARNING, log.ERROR | bibliopixel/util/log.py | def set_log_level(level):
"""
:param level: the level to set - either a string level name from
'frame', 'debug', 'info', 'warning', 'error'
or an integer log level from:
log.FRAME, log.DEBUG, log.INFO, log.WARNING, log.ERROR
"""
if isinstance(level, str):
level = LOG_NAMES[level.lower()]
logger.setLevel(level) | def set_log_level(level):
"""
:param level: the level to set - either a string level name from
'frame', 'debug', 'info', 'warning', 'error'
or an integer log level from:
log.FRAME, log.DEBUG, log.INFO, log.WARNING, log.ERROR
"""
if isinstance(level, str):
level = LOG_NAMES[level.lower()]
logger.setLevel(level) | [
":",
"param",
"level",
":",
"the",
"level",
"to",
"set",
"-",
"either",
"a",
"string",
"level",
"name",
"from",
"frame",
"debug",
"info",
"warning",
"error",
"or",
"an",
"integer",
"log",
"level",
"from",
":",
"log",
".",
"FRAME",
"log",
".",
"DEBUG",
"log",
".",
"INFO",
"log",
".",
"WARNING",
"log",
".",
"ERROR"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/log.py#L115-L125 | [
"def",
"set_log_level",
"(",
"level",
")",
":",
"if",
"isinstance",
"(",
"level",
",",
"str",
")",
":",
"level",
"=",
"LOG_NAMES",
"[",
"level",
".",
"lower",
"(",
")",
"]",
"logger",
".",
"setLevel",
"(",
"level",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Layout.construct | Construct a layout.
SHOULD BE PRIVATE | bibliopixel/layout/layout.py | def construct(cls, project, **desc):
"""Construct a layout.
SHOULD BE PRIVATE
"""
return cls(project.drivers, maker=project.maker, **desc) | def construct(cls, project, **desc):
"""Construct a layout.
SHOULD BE PRIVATE
"""
return cls(project.drivers, maker=project.maker, **desc) | [
"Construct",
"a",
"layout",
".",
"SHOULD",
"BE",
"PRIVATE"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/layout.py#L29-L33 | [
"def",
"construct",
"(",
"cls",
",",
"project",
",",
"*",
"*",
"desc",
")",
":",
"return",
"cls",
"(",
"project",
".",
"drivers",
",",
"maker",
"=",
"project",
".",
"maker",
",",
"*",
"*",
"desc",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Layout.clone | Return an independent copy of this layout with a completely separate
color_list and no drivers. | bibliopixel/layout/layout.py | def clone(self):
"""
Return an independent copy of this layout with a completely separate
color_list and no drivers.
"""
args = {k: getattr(self, k) for k in self.CLONE_ATTRS}
args['color_list'] = copy.copy(self.color_list)
return self.__class__([], **args) | def clone(self):
"""
Return an independent copy of this layout with a completely separate
color_list and no drivers.
"""
args = {k: getattr(self, k) for k in self.CLONE_ATTRS}
args['color_list'] = copy.copy(self.color_list)
return self.__class__([], **args) | [
"Return",
"an",
"independent",
"copy",
"of",
"this",
"layout",
"with",
"a",
"completely",
"separate",
"color_list",
"and",
"no",
"drivers",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/layout.py#L93-L100 | [
"def",
"clone",
"(",
"self",
")",
":",
"args",
"=",
"{",
"k",
":",
"getattr",
"(",
"self",
",",
"k",
")",
"for",
"k",
"in",
"self",
".",
"CLONE_ATTRS",
"}",
"args",
"[",
"'color_list'",
"]",
"=",
"copy",
".",
"copy",
"(",
"self",
".",
"color_list",
")",
"return",
"self",
".",
"__class__",
"(",
"[",
"]",
",",
"*",
"*",
"args",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Layout.set_color_list | Set the internal colors starting at an optional offset.
If `color_list` is a list or other 1-dimensional array, it is reshaped
into an N x 3 list.
If `color_list` too long it is truncated; if it is too short then only
the initial colors are set. | bibliopixel/layout/layout.py | def set_color_list(self, color_list, offset=0):
"""
Set the internal colors starting at an optional offset.
If `color_list` is a list or other 1-dimensional array, it is reshaped
into an N x 3 list.
If `color_list` too long it is truncated; if it is too short then only
the initial colors are set.
"""
if not len(color_list):
return
color_list = make.colors(color_list)
size = len(self._colors) - offset
if len(color_list) > size:
color_list = color_list[:size]
self._colors[offset:offset + len(color_list)] = color_list | def set_color_list(self, color_list, offset=0):
"""
Set the internal colors starting at an optional offset.
If `color_list` is a list or other 1-dimensional array, it is reshaped
into an N x 3 list.
If `color_list` too long it is truncated; if it is too short then only
the initial colors are set.
"""
if not len(color_list):
return
color_list = make.colors(color_list)
size = len(self._colors) - offset
if len(color_list) > size:
color_list = color_list[:size]
self._colors[offset:offset + len(color_list)] = color_list | [
"Set",
"the",
"internal",
"colors",
"starting",
"at",
"an",
"optional",
"offset",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/layout.py#L124-L141 | [
"def",
"set_color_list",
"(",
"self",
",",
"color_list",
",",
"offset",
"=",
"0",
")",
":",
"if",
"not",
"len",
"(",
"color_list",
")",
":",
"return",
"color_list",
"=",
"make",
".",
"colors",
"(",
"color_list",
")",
"size",
"=",
"len",
"(",
"self",
".",
"_colors",
")",
"-",
"offset",
"if",
"len",
"(",
"color_list",
")",
">",
"size",
":",
"color_list",
"=",
"color_list",
"[",
":",
"size",
"]",
"self",
".",
"_colors",
"[",
"offset",
":",
"offset",
"+",
"len",
"(",
"color_list",
")",
"]",
"=",
"color_list"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Layout.setRGB | Set single pixel using individual RGB values instead of tuple | bibliopixel/layout/layout.py | def setRGB(self, pixel, r, g, b):
"""Set single pixel using individual RGB values instead of tuple"""
self._set_base(pixel, (r, g, b)) | def setRGB(self, pixel, r, g, b):
"""Set single pixel using individual RGB values instead of tuple"""
self._set_base(pixel, (r, g, b)) | [
"Set",
"single",
"pixel",
"using",
"individual",
"RGB",
"values",
"instead",
"of",
"tuple"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/layout.py#L186-L188 | [
"def",
"setRGB",
"(",
"self",
",",
"pixel",
",",
"r",
",",
"g",
",",
"b",
")",
":",
"self",
".",
"_set_base",
"(",
"pixel",
",",
"(",
"r",
",",
"g",
",",
"b",
")",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Layout.setHSV | Set single pixel to HSV tuple | bibliopixel/layout/layout.py | def setHSV(self, pixel, hsv):
"""Set single pixel to HSV tuple"""
color = conversions.hsv2rgb(hsv)
self._set_base(pixel, color) | def setHSV(self, pixel, hsv):
"""Set single pixel to HSV tuple"""
color = conversions.hsv2rgb(hsv)
self._set_base(pixel, color) | [
"Set",
"single",
"pixel",
"to",
"HSV",
"tuple"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/layout.py#L190-L193 | [
"def",
"setHSV",
"(",
"self",
",",
"pixel",
",",
"hsv",
")",
":",
"color",
"=",
"conversions",
".",
"hsv2rgb",
"(",
"hsv",
")",
"self",
".",
"_set_base",
"(",
"pixel",
",",
"color",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Layout.fill | Fill the entire strip with RGB color tuple | bibliopixel/layout/layout.py | def fill(self, color, start=0, end=-1):
"""Fill the entire strip with RGB color tuple"""
start = max(start, 0)
if end < 0 or end >= self.numLEDs:
end = self.numLEDs - 1
for led in range(start, end + 1): # since 0-index include end in range
self._set_base(led, color) | def fill(self, color, start=0, end=-1):
"""Fill the entire strip with RGB color tuple"""
start = max(start, 0)
if end < 0 or end >= self.numLEDs:
end = self.numLEDs - 1
for led in range(start, end + 1): # since 0-index include end in range
self._set_base(led, color) | [
"Fill",
"the",
"entire",
"strip",
"with",
"RGB",
"color",
"tuple"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/layout.py#L205-L211 | [
"def",
"fill",
"(",
"self",
",",
"color",
",",
"start",
"=",
"0",
",",
"end",
"=",
"-",
"1",
")",
":",
"start",
"=",
"max",
"(",
"start",
",",
"0",
")",
"if",
"end",
"<",
"0",
"or",
"end",
">=",
"self",
".",
"numLEDs",
":",
"end",
"=",
"self",
".",
"numLEDs",
"-",
"1",
"for",
"led",
"in",
"range",
"(",
"start",
",",
"end",
"+",
"1",
")",
":",
"# since 0-index include end in range",
"self",
".",
"_set_base",
"(",
"led",
",",
"color",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Layout.fillRGB | Fill entire strip by giving individual RGB values instead of tuple | bibliopixel/layout/layout.py | def fillRGB(self, r, g, b, start=0, end=-1):
"""Fill entire strip by giving individual RGB values instead of tuple"""
self.fill((r, g, b), start, end) | def fillRGB(self, r, g, b, start=0, end=-1):
"""Fill entire strip by giving individual RGB values instead of tuple"""
self.fill((r, g, b), start, end) | [
"Fill",
"entire",
"strip",
"by",
"giving",
"individual",
"RGB",
"values",
"instead",
"of",
"tuple"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/layout.py#L214-L216 | [
"def",
"fillRGB",
"(",
"self",
",",
"r",
",",
"g",
",",
"b",
",",
"start",
"=",
"0",
",",
"end",
"=",
"-",
"1",
")",
":",
"self",
".",
"fill",
"(",
"(",
"r",
",",
"g",
",",
"b",
")",
",",
"start",
",",
"end",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Layout.fillHSV | Fill the entire strip with HSV color tuple | bibliopixel/layout/layout.py | def fillHSV(self, hsv, start=0, end=-1):
"""Fill the entire strip with HSV color tuple"""
self.fill(conversions.hsv2rgb(hsv), start, end) | def fillHSV(self, hsv, start=0, end=-1):
"""Fill the entire strip with HSV color tuple"""
self.fill(conversions.hsv2rgb(hsv), start, end) | [
"Fill",
"the",
"entire",
"strip",
"with",
"HSV",
"color",
"tuple"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/layout.py#L219-L221 | [
"def",
"fillHSV",
"(",
"self",
",",
"hsv",
",",
"start",
"=",
"0",
",",
"end",
"=",
"-",
"1",
")",
":",
"self",
".",
"fill",
"(",
"conversions",
".",
"hsv2rgb",
"(",
"hsv",
")",
",",
"start",
",",
"end",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | MultiLayout.set_colors | DEPRECATED: use self.color_list
Use with extreme caution!
Directly sets the internal buffer and bypasses all brightness and
rotation control buf must also be in the exact format required by the
display type. | bibliopixel/layout/layout.py | def set_colors(self, buf):
"""
DEPRECATED: use self.color_list
Use with extreme caution!
Directly sets the internal buffer and bypasses all brightness and
rotation control buf must also be in the exact format required by the
display type.
"""
deprecated.deprecated('layout.set_colors')
if len(self._colors) != len(buf):
raise IOError("Data buffer size incorrect! "
"Expected: {} bytes / Received: {} bytes"
.format(len(self._colors), len(buf)))
self._colors[:] = buf | def set_colors(self, buf):
"""
DEPRECATED: use self.color_list
Use with extreme caution!
Directly sets the internal buffer and bypasses all brightness and
rotation control buf must also be in the exact format required by the
display type.
"""
deprecated.deprecated('layout.set_colors')
if len(self._colors) != len(buf):
raise IOError("Data buffer size incorrect! "
"Expected: {} bytes / Received: {} bytes"
.format(len(self._colors), len(buf)))
self._colors[:] = buf | [
"DEPRECATED",
":",
"use",
"self",
".",
"color_list"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/layout.py#L242-L256 | [
"def",
"set_colors",
"(",
"self",
",",
"buf",
")",
":",
"deprecated",
".",
"deprecated",
"(",
"'layout.set_colors'",
")",
"if",
"len",
"(",
"self",
".",
"_colors",
")",
"!=",
"len",
"(",
"buf",
")",
":",
"raise",
"IOError",
"(",
"\"Data buffer size incorrect! \"",
"\"Expected: {} bytes / Received: {} bytes\"",
".",
"format",
"(",
"len",
"(",
"self",
".",
"_colors",
")",
",",
"len",
"(",
"buf",
")",
")",
")",
"self",
".",
"_colors",
"[",
":",
"]",
"=",
"buf"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Network.set_device_brightness | Hardware specific method to set the global brightness for
this driver's output. This method is required to be implemented,
however, users should call
:py:meth:`.driver_base.DriverBase.set_brightness`
instead of calling this method directly.
:param int brightness: 0-255 value representing the desired
brightness level | bibliopixel/drivers/network.py | def set_device_brightness(self, brightness):
"""Hardware specific method to set the global brightness for
this driver's output. This method is required to be implemented,
however, users should call
:py:meth:`.driver_base.DriverBase.set_brightness`
instead of calling this method directly.
:param int brightness: 0-255 value representing the desired
brightness level
"""
packet = util.generate_header(CMDTYPE.BRIGHTNESS, 1)
packet.append(self._brightness)
s = self._connect()
s.sendall(packet)
resp = ord(s.recv(1))
return resp == RETURN_CODES.SUCCESS | def set_device_brightness(self, brightness):
"""Hardware specific method to set the global brightness for
this driver's output. This method is required to be implemented,
however, users should call
:py:meth:`.driver_base.DriverBase.set_brightness`
instead of calling this method directly.
:param int brightness: 0-255 value representing the desired
brightness level
"""
packet = util.generate_header(CMDTYPE.BRIGHTNESS, 1)
packet.append(self._brightness)
s = self._connect()
s.sendall(packet)
resp = ord(s.recv(1))
return resp == RETURN_CODES.SUCCESS | [
"Hardware",
"specific",
"method",
"to",
"set",
"the",
"global",
"brightness",
"for",
"this",
"driver",
"s",
"output",
".",
"This",
"method",
"is",
"required",
"to",
"be",
"implemented",
"however",
"users",
"should",
"call",
":",
"py",
":",
"meth",
":",
".",
"driver_base",
".",
"DriverBase",
".",
"set_brightness",
"instead",
"of",
"calling",
"this",
"method",
"directly",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/drivers/network.py#L71-L86 | [
"def",
"set_device_brightness",
"(",
"self",
",",
"brightness",
")",
":",
"packet",
"=",
"util",
".",
"generate_header",
"(",
"CMDTYPE",
".",
"BRIGHTNESS",
",",
"1",
")",
"packet",
".",
"append",
"(",
"self",
".",
"_brightness",
")",
"s",
"=",
"self",
".",
"_connect",
"(",
")",
"s",
".",
"sendall",
"(",
"packet",
")",
"resp",
"=",
"ord",
"(",
"s",
".",
"recv",
"(",
"1",
")",
")",
"return",
"resp",
"==",
"RETURN_CODES",
".",
"SUCCESS"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | wheel_helper | Helper for wheel_color that distributes colors over length and
allows shifting position. | bibliopixel/colors/wheel.py | def wheel_helper(pos, length, cycle_step):
"""Helper for wheel_color that distributes colors over length and
allows shifting position."""
return wheel_color((pos * len(_WHEEL) / length) + cycle_step) | def wheel_helper(pos, length, cycle_step):
"""Helper for wheel_color that distributes colors over length and
allows shifting position."""
return wheel_color((pos * len(_WHEEL) / length) + cycle_step) | [
"Helper",
"for",
"wheel_color",
"that",
"distributes",
"colors",
"over",
"length",
"and",
"allows",
"shifting",
"position",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/wheel.py#L31-L34 | [
"def",
"wheel_helper",
"(",
"pos",
",",
"length",
",",
"cycle_step",
")",
":",
"return",
"wheel_color",
"(",
"(",
"pos",
"*",
"len",
"(",
"_WHEEL",
")",
"/",
"length",
")",
"+",
"cycle_step",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | single | Decorator for RestServer methods that take a single address | bibliopixel/control/rest/decorator.py | def single(method):
"""Decorator for RestServer methods that take a single address"""
@functools.wraps(method)
def single(self, address, value=None):
address = urllib.parse.unquote_plus(address)
try:
error = NO_PROJECT_ERROR
if not self.project:
raise ValueError
error = BAD_ADDRESS_ERROR
ed = editor.Editor(address, self.project)
if value is None:
error = BAD_GETTER_ERROR
result = method(self, ed)
else:
error = BAD_SETTER_ERROR
result = method(self, ed, value)
result = {'value': result}
except Exception as e:
traceback.print_exc()
msg = '%s\n%s' % (error.format(**locals()), e)
result = {'error': msg}
return flask.jsonify(result)
return single | def single(method):
"""Decorator for RestServer methods that take a single address"""
@functools.wraps(method)
def single(self, address, value=None):
address = urllib.parse.unquote_plus(address)
try:
error = NO_PROJECT_ERROR
if not self.project:
raise ValueError
error = BAD_ADDRESS_ERROR
ed = editor.Editor(address, self.project)
if value is None:
error = BAD_GETTER_ERROR
result = method(self, ed)
else:
error = BAD_SETTER_ERROR
result = method(self, ed, value)
result = {'value': result}
except Exception as e:
traceback.print_exc()
msg = '%s\n%s' % (error.format(**locals()), e)
result = {'error': msg}
return flask.jsonify(result)
return single | [
"Decorator",
"for",
"RestServer",
"methods",
"that",
"take",
"a",
"single",
"address"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/control/rest/decorator.py#L10-L37 | [
"def",
"single",
"(",
"method",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"method",
")",
"def",
"single",
"(",
"self",
",",
"address",
",",
"value",
"=",
"None",
")",
":",
"address",
"=",
"urllib",
".",
"parse",
".",
"unquote_plus",
"(",
"address",
")",
"try",
":",
"error",
"=",
"NO_PROJECT_ERROR",
"if",
"not",
"self",
".",
"project",
":",
"raise",
"ValueError",
"error",
"=",
"BAD_ADDRESS_ERROR",
"ed",
"=",
"editor",
".",
"Editor",
"(",
"address",
",",
"self",
".",
"project",
")",
"if",
"value",
"is",
"None",
":",
"error",
"=",
"BAD_GETTER_ERROR",
"result",
"=",
"method",
"(",
"self",
",",
"ed",
")",
"else",
":",
"error",
"=",
"BAD_SETTER_ERROR",
"result",
"=",
"method",
"(",
"self",
",",
"ed",
",",
"value",
")",
"result",
"=",
"{",
"'value'",
":",
"result",
"}",
"except",
"Exception",
"as",
"e",
":",
"traceback",
".",
"print_exc",
"(",
")",
"msg",
"=",
"'%s\\n%s'",
"%",
"(",
"error",
".",
"format",
"(",
"*",
"*",
"locals",
"(",
")",
")",
",",
"e",
")",
"result",
"=",
"{",
"'error'",
":",
"msg",
"}",
"return",
"flask",
".",
"jsonify",
"(",
"result",
")",
"return",
"single"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | multi | Decorator for RestServer methods that take multiple addresses | bibliopixel/control/rest/decorator.py | def multi(method):
"""Decorator for RestServer methods that take multiple addresses"""
@functools.wraps(method)
def multi(self, address=''):
values = flask.request.values
address = urllib.parse.unquote_plus(address)
if address and values and not address.endswith('.'):
address += '.'
result = {}
for a in values or '':
try:
if not self.project:
raise ValueError('No Project is currently loaded')
ed = editor.Editor(address + a, self.project)
result[address + a] = {'value': method(self, ed, a)}
except:
if self.project:
traceback.print_exc()
result[address + a] = {'error': 'Could not multi addr %s' % a}
return flask.jsonify(result)
return multi | def multi(method):
"""Decorator for RestServer methods that take multiple addresses"""
@functools.wraps(method)
def multi(self, address=''):
values = flask.request.values
address = urllib.parse.unquote_plus(address)
if address and values and not address.endswith('.'):
address += '.'
result = {}
for a in values or '':
try:
if not self.project:
raise ValueError('No Project is currently loaded')
ed = editor.Editor(address + a, self.project)
result[address + a] = {'value': method(self, ed, a)}
except:
if self.project:
traceback.print_exc()
result[address + a] = {'error': 'Could not multi addr %s' % a}
return flask.jsonify(result)
return multi | [
"Decorator",
"for",
"RestServer",
"methods",
"that",
"take",
"multiple",
"addresses"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/control/rest/decorator.py#L40-L64 | [
"def",
"multi",
"(",
"method",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"method",
")",
"def",
"multi",
"(",
"self",
",",
"address",
"=",
"''",
")",
":",
"values",
"=",
"flask",
".",
"request",
".",
"values",
"address",
"=",
"urllib",
".",
"parse",
".",
"unquote_plus",
"(",
"address",
")",
"if",
"address",
"and",
"values",
"and",
"not",
"address",
".",
"endswith",
"(",
"'.'",
")",
":",
"address",
"+=",
"'.'",
"result",
"=",
"{",
"}",
"for",
"a",
"in",
"values",
"or",
"''",
":",
"try",
":",
"if",
"not",
"self",
".",
"project",
":",
"raise",
"ValueError",
"(",
"'No Project is currently loaded'",
")",
"ed",
"=",
"editor",
".",
"Editor",
"(",
"address",
"+",
"a",
",",
"self",
".",
"project",
")",
"result",
"[",
"address",
"+",
"a",
"]",
"=",
"{",
"'value'",
":",
"method",
"(",
"self",
",",
"ed",
",",
"a",
")",
"}",
"except",
":",
"if",
"self",
".",
"project",
":",
"traceback",
".",
"print_exc",
"(",
")",
"result",
"[",
"address",
"+",
"a",
"]",
"=",
"{",
"'error'",
":",
"'Could not multi addr %s'",
"%",
"a",
"}",
"return",
"flask",
".",
"jsonify",
"(",
"result",
")",
"return",
"multi"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | advance_permutation | Advance a list of unique, ordered elements in-place, lexicographically
increasing or backward, by rightmost or leftmost digit.
Returns False if the permutation wrapped around - i.e. went from
lexicographically greatest to least, and True in all other cases.
If the length of the list is N, then this function will repeat values after
N! steps, and will return False exactly once.
See also https://stackoverflow.com/a/34325140/43839 | bibliopixel/util/permutation.py | def advance_permutation(a, increasing=True, forward=True):
"""
Advance a list of unique, ordered elements in-place, lexicographically
increasing or backward, by rightmost or leftmost digit.
Returns False if the permutation wrapped around - i.e. went from
lexicographically greatest to least, and True in all other cases.
If the length of the list is N, then this function will repeat values after
N! steps, and will return False exactly once.
See also https://stackoverflow.com/a/34325140/43839
"""
if not forward:
a.reverse()
cmp = operator.lt if increasing else operator.gt
try:
i = next(i for i in reversed(range(len(a) - 1)) if cmp(a[i], a[i + 1]))
j = next(j for j in reversed(range(i + 1, len(a))) if cmp(a[i], a[j]))
except StopIteration:
# This is the lexicographically last permutation.
if forward:
a.reverse()
return False
a[i], a[j] = a[j], a[i]
a[i + 1:] = reversed(a[i + 1:])
if not forward:
a.reverse()
return True | def advance_permutation(a, increasing=True, forward=True):
"""
Advance a list of unique, ordered elements in-place, lexicographically
increasing or backward, by rightmost or leftmost digit.
Returns False if the permutation wrapped around - i.e. went from
lexicographically greatest to least, and True in all other cases.
If the length of the list is N, then this function will repeat values after
N! steps, and will return False exactly once.
See also https://stackoverflow.com/a/34325140/43839
"""
if not forward:
a.reverse()
cmp = operator.lt if increasing else operator.gt
try:
i = next(i for i in reversed(range(len(a) - 1)) if cmp(a[i], a[i + 1]))
j = next(j for j in reversed(range(i + 1, len(a))) if cmp(a[i], a[j]))
except StopIteration:
# This is the lexicographically last permutation.
if forward:
a.reverse()
return False
a[i], a[j] = a[j], a[i]
a[i + 1:] = reversed(a[i + 1:])
if not forward:
a.reverse()
return True | [
"Advance",
"a",
"list",
"of",
"unique",
"ordered",
"elements",
"in",
"-",
"place",
"lexicographically",
"increasing",
"or",
"backward",
"by",
"rightmost",
"or",
"leftmost",
"digit",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/permutation.py#L4-L36 | [
"def",
"advance_permutation",
"(",
"a",
",",
"increasing",
"=",
"True",
",",
"forward",
"=",
"True",
")",
":",
"if",
"not",
"forward",
":",
"a",
".",
"reverse",
"(",
")",
"cmp",
"=",
"operator",
".",
"lt",
"if",
"increasing",
"else",
"operator",
".",
"gt",
"try",
":",
"i",
"=",
"next",
"(",
"i",
"for",
"i",
"in",
"reversed",
"(",
"range",
"(",
"len",
"(",
"a",
")",
"-",
"1",
")",
")",
"if",
"cmp",
"(",
"a",
"[",
"i",
"]",
",",
"a",
"[",
"i",
"+",
"1",
"]",
")",
")",
"j",
"=",
"next",
"(",
"j",
"for",
"j",
"in",
"reversed",
"(",
"range",
"(",
"i",
"+",
"1",
",",
"len",
"(",
"a",
")",
")",
")",
"if",
"cmp",
"(",
"a",
"[",
"i",
"]",
",",
"a",
"[",
"j",
"]",
")",
")",
"except",
"StopIteration",
":",
"# This is the lexicographically last permutation.",
"if",
"forward",
":",
"a",
".",
"reverse",
"(",
")",
"return",
"False",
"a",
"[",
"i",
"]",
",",
"a",
"[",
"j",
"]",
"=",
"a",
"[",
"j",
"]",
",",
"a",
"[",
"i",
"]",
"a",
"[",
"i",
"+",
"1",
":",
"]",
"=",
"reversed",
"(",
"a",
"[",
"i",
"+",
"1",
":",
"]",
")",
"if",
"not",
"forward",
":",
"a",
".",
"reverse",
"(",
")",
"return",
"True"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Indexed._on_index | Override this method to get called right after ``self.index`` is set.
:param int old_index: the previous index, before it was changed. | bibliopixel/animation/indexed.py | def _on_index(self, old_index):
"""
Override this method to get called right after ``self.index`` is set.
:param int old_index: the previous index, before it was changed.
"""
if self.animation:
log.debug('%s: %s',
self.__class__.__name__, self.current_animation.title)
self.frames = self.animation.generate_frames(False) | def _on_index(self, old_index):
"""
Override this method to get called right after ``self.index`` is set.
:param int old_index: the previous index, before it was changed.
"""
if self.animation:
log.debug('%s: %s',
self.__class__.__name__, self.current_animation.title)
self.frames = self.animation.generate_frames(False) | [
"Override",
"this",
"method",
"to",
"get",
"called",
"right",
"after",
"self",
".",
"index",
"is",
"set",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/animation/indexed.py#L34-L43 | [
"def",
"_on_index",
"(",
"self",
",",
"old_index",
")",
":",
"if",
"self",
".",
"animation",
":",
"log",
".",
"debug",
"(",
"'%s: %s'",
",",
"self",
".",
"__class__",
".",
"__name__",
",",
"self",
".",
"current_animation",
".",
"title",
")",
"self",
".",
"frames",
"=",
"self",
".",
"animation",
".",
"generate_frames",
"(",
"False",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Indexed.animation | :returns: the selected animation based on self.index, or None if
self.index is out of bounds | bibliopixel/animation/indexed.py | def animation(self):
"""
:returns: the selected animation based on self.index, or None if
self.index is out of bounds
"""
if 0 <= self._index < len(self.animations):
return self.animations[self._index] | def animation(self):
"""
:returns: the selected animation based on self.index, or None if
self.index is out of bounds
"""
if 0 <= self._index < len(self.animations):
return self.animations[self._index] | [
":",
"returns",
":",
"the",
"selected",
"animation",
"based",
"on",
"self",
".",
"index",
"or",
"None",
"if",
"self",
".",
"index",
"is",
"out",
"of",
"bounds"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/animation/indexed.py#L67-L73 | [
"def",
"animation",
"(",
"self",
")",
":",
"if",
"0",
"<=",
"self",
".",
"_index",
"<",
"len",
"(",
"self",
".",
"animations",
")",
":",
"return",
"self",
".",
"animations",
"[",
"self",
".",
"_index",
"]"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Cutter.apply | For each row or column in cuts, read a list of its colors,
apply the function to that list of colors, then write it back
to the layout. | bibliopixel/layout/cutter.py | def apply(self, function):
"""
For each row or column in cuts, read a list of its colors,
apply the function to that list of colors, then write it back
to the layout.
"""
for cut in self.cuts:
value = self.read(cut)
function(value)
self.write(cut, value) | def apply(self, function):
"""
For each row or column in cuts, read a list of its colors,
apply the function to that list of colors, then write it back
to the layout.
"""
for cut in self.cuts:
value = self.read(cut)
function(value)
self.write(cut, value) | [
"For",
"each",
"row",
"or",
"column",
"in",
"cuts",
"read",
"a",
"list",
"of",
"its",
"colors",
"apply",
"the",
"function",
"to",
"that",
"list",
"of",
"colors",
"then",
"write",
"it",
"back",
"to",
"the",
"layout",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/cutter.py#L23-L32 | [
"def",
"apply",
"(",
"self",
",",
"function",
")",
":",
"for",
"cut",
"in",
"self",
".",
"cuts",
":",
"value",
"=",
"self",
".",
"read",
"(",
"cut",
")",
"function",
"(",
"value",
")",
"self",
".",
"write",
"(",
"cut",
",",
"value",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Strip.setRGB | Set single pixel using individual RGB values instead of tuple | bibliopixel/layout/strip.py | def setRGB(self, pixel, r, g, b):
"""Set single pixel using individual RGB values instead of tuple"""
self.set(pixel, (r, g, b)) | def setRGB(self, pixel, r, g, b):
"""Set single pixel using individual RGB values instead of tuple"""
self.set(pixel, (r, g, b)) | [
"Set",
"single",
"pixel",
"using",
"individual",
"RGB",
"values",
"instead",
"of",
"tuple"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/strip.py#L73-L75 | [
"def",
"setRGB",
"(",
"self",
",",
"pixel",
",",
"r",
",",
"g",
",",
"b",
")",
":",
"self",
".",
"set",
"(",
"pixel",
",",
"(",
"r",
",",
"g",
",",
"b",
")",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Strip.setHSV | Set single pixel to HSV tuple | bibliopixel/layout/strip.py | def setHSV(self, pixel, hsv):
"""Set single pixel to HSV tuple"""
color = conversions.hsv2rgb(hsv)
self.set(pixel, color) | def setHSV(self, pixel, hsv):
"""Set single pixel to HSV tuple"""
color = conversions.hsv2rgb(hsv)
self.set(pixel, color) | [
"Set",
"single",
"pixel",
"to",
"HSV",
"tuple"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/strip.py#L77-L80 | [
"def",
"setHSV",
"(",
"self",
",",
"pixel",
",",
"hsv",
")",
":",
"color",
"=",
"conversions",
".",
"hsv2rgb",
"(",
"hsv",
")",
"self",
".",
"set",
"(",
"pixel",
",",
"color",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | compose_events | Compose a sequence of events into one event.
Arguments:
events: a sequence of objects looking like threading.Event
condition: a function taking a sequence of bools and returning a bool. | bibliopixel/util/threads/compose_events.py | def compose_events(events, condition=all):
"""
Compose a sequence of events into one event.
Arguments:
events: a sequence of objects looking like threading.Event
condition: a function taking a sequence of bools and returning a bool.
"""
events = list(events)
master_event = threading.Event()
def changed():
if condition(e.is_set() for e in events):
master_event.set()
else:
master_event.clear()
def add_changed(f):
@functools.wraps(f)
def wrapped():
f()
changed()
return wrapped
for e in events:
e.set = add_changed(e.set)
e.clear = add_changed(e.clear)
changed()
return master_event | def compose_events(events, condition=all):
"""
Compose a sequence of events into one event.
Arguments:
events: a sequence of objects looking like threading.Event
condition: a function taking a sequence of bools and returning a bool.
"""
events = list(events)
master_event = threading.Event()
def changed():
if condition(e.is_set() for e in events):
master_event.set()
else:
master_event.clear()
def add_changed(f):
@functools.wraps(f)
def wrapped():
f()
changed()
return wrapped
for e in events:
e.set = add_changed(e.set)
e.clear = add_changed(e.clear)
changed()
return master_event | [
"Compose",
"a",
"sequence",
"of",
"events",
"into",
"one",
"event",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/threads/compose_events.py#L4-L34 | [
"def",
"compose_events",
"(",
"events",
",",
"condition",
"=",
"all",
")",
":",
"events",
"=",
"list",
"(",
"events",
")",
"master_event",
"=",
"threading",
".",
"Event",
"(",
")",
"def",
"changed",
"(",
")",
":",
"if",
"condition",
"(",
"e",
".",
"is_set",
"(",
")",
"for",
"e",
"in",
"events",
")",
":",
"master_event",
".",
"set",
"(",
")",
"else",
":",
"master_event",
".",
"clear",
"(",
")",
"def",
"add_changed",
"(",
"f",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"f",
")",
"def",
"wrapped",
"(",
")",
":",
"f",
"(",
")",
"changed",
"(",
")",
"return",
"wrapped",
"for",
"e",
"in",
"events",
":",
"e",
".",
"set",
"=",
"add_changed",
"(",
"e",
".",
"set",
")",
"e",
".",
"clear",
"=",
"add_changed",
"(",
"e",
".",
"clear",
")",
"changed",
"(",
")",
"return",
"master_event"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | _add_redundant_arguments | These arguments are redundant with just using a project, and we should
encouraging that as you don't have to learn any dumb flags!
For example, instead of
bp foo.yml --animation=wombat --numbers=float
use
bp foo.yml + '{animation: wombat, numbers: float}' | bibliopixel/main/project_flags.py | def _add_redundant_arguments(parser):
"""
These arguments are redundant with just using a project, and we should
encouraging that as you don't have to learn any dumb flags!
For example, instead of
bp foo.yml --animation=wombat --numbers=float
use
bp foo.yml + '{animation: wombat, numbers: float}'
"""
parser.add_argument(
'-a', '--animation', default=None,
help='Default animation type if no animation is specified')
if deprecated.allowed(): # pragma: no cover
parser.add_argument(
'--dimensions', '--dim', default=None,
help='DEPRECATED: x, (x, y) or (x, y, z) dimensions for project')
parser.add_argument(
'--shape', default=None,
help='x, (x, y) or (x, y, z) dimensions for project')
parser.add_argument(
'-l', '--layout', default=None,
help='Default layout class if no layout is specified')
parser.add_argument(
'--numbers', '-n', default='python', choices=NUMBER_TYPES,
help=NUMBERS_HELP)
parser.add_argument('-p', '--path', default=None, help=PATH_HELP) | def _add_redundant_arguments(parser):
"""
These arguments are redundant with just using a project, and we should
encouraging that as you don't have to learn any dumb flags!
For example, instead of
bp foo.yml --animation=wombat --numbers=float
use
bp foo.yml + '{animation: wombat, numbers: float}'
"""
parser.add_argument(
'-a', '--animation', default=None,
help='Default animation type if no animation is specified')
if deprecated.allowed(): # pragma: no cover
parser.add_argument(
'--dimensions', '--dim', default=None,
help='DEPRECATED: x, (x, y) or (x, y, z) dimensions for project')
parser.add_argument(
'--shape', default=None,
help='x, (x, y) or (x, y, z) dimensions for project')
parser.add_argument(
'-l', '--layout', default=None,
help='Default layout class if no layout is specified')
parser.add_argument(
'--numbers', '-n', default='python', choices=NUMBER_TYPES,
help=NUMBERS_HELP)
parser.add_argument('-p', '--path', default=None, help=PATH_HELP) | [
"These",
"arguments",
"are",
"redundant",
"with",
"just",
"using",
"a",
"project",
"and",
"we",
"should",
"encouraging",
"that",
"as",
"you",
"don",
"t",
"have",
"to",
"learn",
"any",
"dumb",
"flags!"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/main/project_flags.py#L71-L106 | [
"def",
"_add_redundant_arguments",
"(",
"parser",
")",
":",
"parser",
".",
"add_argument",
"(",
"'-a'",
",",
"'--animation'",
",",
"default",
"=",
"None",
",",
"help",
"=",
"'Default animation type if no animation is specified'",
")",
"if",
"deprecated",
".",
"allowed",
"(",
")",
":",
"# pragma: no cover",
"parser",
".",
"add_argument",
"(",
"'--dimensions'",
",",
"'--dim'",
",",
"default",
"=",
"None",
",",
"help",
"=",
"'DEPRECATED: x, (x, y) or (x, y, z) dimensions for project'",
")",
"parser",
".",
"add_argument",
"(",
"'--shape'",
",",
"default",
"=",
"None",
",",
"help",
"=",
"'x, (x, y) or (x, y, z) dimensions for project'",
")",
"parser",
".",
"add_argument",
"(",
"'-l'",
",",
"'--layout'",
",",
"default",
"=",
"None",
",",
"help",
"=",
"'Default layout class if no layout is specified'",
")",
"parser",
".",
"add_argument",
"(",
"'--numbers'",
",",
"'-n'",
",",
"default",
"=",
"'python'",
",",
"choices",
"=",
"NUMBER_TYPES",
",",
"help",
"=",
"NUMBERS_HELP",
")",
"parser",
".",
"add_argument",
"(",
"'-p'",
",",
"'--path'",
",",
"default",
"=",
"None",
",",
"help",
"=",
"PATH_HELP",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | draw_circle | Draws a circle at point x0, y0 with radius r of the specified RGB color | bibliopixel/layout/matrix_drawing.py | def draw_circle(setter, x0, y0, r, color=None):
"""
Draws a circle at point x0, y0 with radius r of the specified RGB color
"""
f = 1 - r
ddF_x = 1
ddF_y = -2 * r
x = 0
y = r
setter(x0, y0 + r, color)
setter(x0, y0 - r, color)
setter(x0 + r, y0, color)
setter(x0 - r, y0, color)
while x < y:
if f >= 0:
y -= 1
ddF_y += 2
f += ddF_y
x += 1
ddF_x += 2
f += ddF_x
setter(x0 + x, y0 + y, color)
setter(x0 - x, y0 + y, color)
setter(x0 + x, y0 - y, color)
setter(x0 - x, y0 - y, color)
setter(x0 + y, y0 + x, color)
setter(x0 - y, y0 + x, color)
setter(x0 + y, y0 - x, color)
setter(x0 - y, y0 - x, color) | def draw_circle(setter, x0, y0, r, color=None):
"""
Draws a circle at point x0, y0 with radius r of the specified RGB color
"""
f = 1 - r
ddF_x = 1
ddF_y = -2 * r
x = 0
y = r
setter(x0, y0 + r, color)
setter(x0, y0 - r, color)
setter(x0 + r, y0, color)
setter(x0 - r, y0, color)
while x < y:
if f >= 0:
y -= 1
ddF_y += 2
f += ddF_y
x += 1
ddF_x += 2
f += ddF_x
setter(x0 + x, y0 + y, color)
setter(x0 - x, y0 + y, color)
setter(x0 + x, y0 - y, color)
setter(x0 - x, y0 - y, color)
setter(x0 + y, y0 + x, color)
setter(x0 - y, y0 + x, color)
setter(x0 + y, y0 - x, color)
setter(x0 - y, y0 - x, color) | [
"Draws",
"a",
"circle",
"at",
"point",
"x0",
"y0",
"with",
"radius",
"r",
"of",
"the",
"specified",
"RGB",
"color"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix_drawing.py#L13-L44 | [
"def",
"draw_circle",
"(",
"setter",
",",
"x0",
",",
"y0",
",",
"r",
",",
"color",
"=",
"None",
")",
":",
"f",
"=",
"1",
"-",
"r",
"ddF_x",
"=",
"1",
"ddF_y",
"=",
"-",
"2",
"*",
"r",
"x",
"=",
"0",
"y",
"=",
"r",
"setter",
"(",
"x0",
",",
"y0",
"+",
"r",
",",
"color",
")",
"setter",
"(",
"x0",
",",
"y0",
"-",
"r",
",",
"color",
")",
"setter",
"(",
"x0",
"+",
"r",
",",
"y0",
",",
"color",
")",
"setter",
"(",
"x0",
"-",
"r",
",",
"y0",
",",
"color",
")",
"while",
"x",
"<",
"y",
":",
"if",
"f",
">=",
"0",
":",
"y",
"-=",
"1",
"ddF_y",
"+=",
"2",
"f",
"+=",
"ddF_y",
"x",
"+=",
"1",
"ddF_x",
"+=",
"2",
"f",
"+=",
"ddF_x",
"setter",
"(",
"x0",
"+",
"x",
",",
"y0",
"+",
"y",
",",
"color",
")",
"setter",
"(",
"x0",
"-",
"x",
",",
"y0",
"+",
"y",
",",
"color",
")",
"setter",
"(",
"x0",
"+",
"x",
",",
"y0",
"-",
"y",
",",
"color",
")",
"setter",
"(",
"x0",
"-",
"x",
",",
"y0",
"-",
"y",
",",
"color",
")",
"setter",
"(",
"x0",
"+",
"y",
",",
"y0",
"+",
"x",
",",
"color",
")",
"setter",
"(",
"x0",
"-",
"y",
",",
"y0",
"+",
"x",
",",
"color",
")",
"setter",
"(",
"x0",
"+",
"y",
",",
"y0",
"-",
"x",
",",
"color",
")",
"setter",
"(",
"x0",
"-",
"y",
",",
"y0",
"-",
"x",
",",
"color",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | fill_circle | Draws a filled circle at point x0,y0 with radius r and specified color | bibliopixel/layout/matrix_drawing.py | def fill_circle(setter, x0, y0, r, color=None):
"""Draws a filled circle at point x0,y0 with radius r and specified color"""
_draw_fast_vline(setter, x0, y0 - r, 2 * r + 1, color)
_fill_circle_helper(setter, x0, y0, r, 3, 0, color) | def fill_circle(setter, x0, y0, r, color=None):
"""Draws a filled circle at point x0,y0 with radius r and specified color"""
_draw_fast_vline(setter, x0, y0 - r, 2 * r + 1, color)
_fill_circle_helper(setter, x0, y0, r, 3, 0, color) | [
"Draws",
"a",
"filled",
"circle",
"at",
"point",
"x0",
"y0",
"with",
"radius",
"r",
"and",
"specified",
"color"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix_drawing.py#L104-L107 | [
"def",
"fill_circle",
"(",
"setter",
",",
"x0",
",",
"y0",
",",
"r",
",",
"color",
"=",
"None",
")",
":",
"_draw_fast_vline",
"(",
"setter",
",",
"x0",
",",
"y0",
"-",
"r",
",",
"2",
"*",
"r",
"+",
"1",
",",
"color",
")",
"_fill_circle_helper",
"(",
"setter",
",",
"x0",
",",
"y0",
",",
"r",
",",
"3",
",",
"0",
",",
"color",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | bresenham_line | Draw line from point x0,y0 to x,1,y1. Will draw beyond matrix bounds. | bibliopixel/layout/matrix_drawing.py | def bresenham_line(setter, x0, y0, x1, y1, color=None, colorFunc=None):
"""Draw line from point x0,y0 to x,1,y1. Will draw beyond matrix bounds."""
steep = abs(y1 - y0) > abs(x1 - x0)
if steep:
x0, y0 = y0, x0
x1, y1 = y1, x1
if x0 > x1:
x0, x1 = x1, x0
y0, y1 = y1, y0
dx = x1 - x0
dy = abs(y1 - y0)
err = dx / 2
if y0 < y1:
ystep = 1
else:
ystep = -1
count = 0
for x in range(x0, x1 + 1):
if colorFunc:
color = colorFunc(count)
count += 1
if steep:
setter(y0, x, color)
else:
setter(x, y0, color)
err -= dy
if err < 0:
y0 += ystep
err += dx | def bresenham_line(setter, x0, y0, x1, y1, color=None, colorFunc=None):
"""Draw line from point x0,y0 to x,1,y1. Will draw beyond matrix bounds."""
steep = abs(y1 - y0) > abs(x1 - x0)
if steep:
x0, y0 = y0, x0
x1, y1 = y1, x1
if x0 > x1:
x0, x1 = x1, x0
y0, y1 = y1, y0
dx = x1 - x0
dy = abs(y1 - y0)
err = dx / 2
if y0 < y1:
ystep = 1
else:
ystep = -1
count = 0
for x in range(x0, x1 + 1):
if colorFunc:
color = colorFunc(count)
count += 1
if steep:
setter(y0, x, color)
else:
setter(x, y0, color)
err -= dy
if err < 0:
y0 += ystep
err += dx | [
"Draw",
"line",
"from",
"point",
"x0",
"y0",
"to",
"x",
"1",
"y1",
".",
"Will",
"draw",
"beyond",
"matrix",
"bounds",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix_drawing.py#L118-L153 | [
"def",
"bresenham_line",
"(",
"setter",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"color",
"=",
"None",
",",
"colorFunc",
"=",
"None",
")",
":",
"steep",
"=",
"abs",
"(",
"y1",
"-",
"y0",
")",
">",
"abs",
"(",
"x1",
"-",
"x0",
")",
"if",
"steep",
":",
"x0",
",",
"y0",
"=",
"y0",
",",
"x0",
"x1",
",",
"y1",
"=",
"y1",
",",
"x1",
"if",
"x0",
">",
"x1",
":",
"x0",
",",
"x1",
"=",
"x1",
",",
"x0",
"y0",
",",
"y1",
"=",
"y1",
",",
"y0",
"dx",
"=",
"x1",
"-",
"x0",
"dy",
"=",
"abs",
"(",
"y1",
"-",
"y0",
")",
"err",
"=",
"dx",
"/",
"2",
"if",
"y0",
"<",
"y1",
":",
"ystep",
"=",
"1",
"else",
":",
"ystep",
"=",
"-",
"1",
"count",
"=",
"0",
"for",
"x",
"in",
"range",
"(",
"x0",
",",
"x1",
"+",
"1",
")",
":",
"if",
"colorFunc",
":",
"color",
"=",
"colorFunc",
"(",
"count",
")",
"count",
"+=",
"1",
"if",
"steep",
":",
"setter",
"(",
"y0",
",",
"x",
",",
"color",
")",
"else",
":",
"setter",
"(",
"x",
",",
"y0",
",",
"color",
")",
"err",
"-=",
"dy",
"if",
"err",
"<",
"0",
":",
"y0",
"+=",
"ystep",
"err",
"+=",
"dx"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | draw_rect | Draw rectangle with top-left corner at x,y, width w and height h | bibliopixel/layout/matrix_drawing.py | def draw_rect(setter, x, y, w, h, color=None, aa=False):
"""Draw rectangle with top-left corner at x,y, width w and height h"""
_draw_fast_hline(setter, x, y, w, color, aa)
_draw_fast_hline(setter, x, y + h - 1, w, color, aa)
_draw_fast_vline(setter, x, y, h, color, aa)
_draw_fast_vline(setter, x + w - 1, y, h, color, aa) | def draw_rect(setter, x, y, w, h, color=None, aa=False):
"""Draw rectangle with top-left corner at x,y, width w and height h"""
_draw_fast_hline(setter, x, y, w, color, aa)
_draw_fast_hline(setter, x, y + h - 1, w, color, aa)
_draw_fast_vline(setter, x, y, h, color, aa)
_draw_fast_vline(setter, x + w - 1, y, h, color, aa) | [
"Draw",
"rectangle",
"with",
"top",
"-",
"left",
"corner",
"at",
"x",
"y",
"width",
"w",
"and",
"height",
"h"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix_drawing.py#L244-L249 | [
"def",
"draw_rect",
"(",
"setter",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"_draw_fast_hline",
"(",
"setter",
",",
"x",
",",
"y",
",",
"w",
",",
"color",
",",
"aa",
")",
"_draw_fast_hline",
"(",
"setter",
",",
"x",
",",
"y",
"+",
"h",
"-",
"1",
",",
"w",
",",
"color",
",",
"aa",
")",
"_draw_fast_vline",
"(",
"setter",
",",
"x",
",",
"y",
",",
"h",
",",
"color",
",",
"aa",
")",
"_draw_fast_vline",
"(",
"setter",
",",
"x",
"+",
"w",
"-",
"1",
",",
"y",
",",
"h",
",",
"color",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | fill_rect | Draw solid rectangle with top-left corner at x,y, width w and height h | bibliopixel/layout/matrix_drawing.py | def fill_rect(setter, x, y, w, h, color=None, aa=False):
"""Draw solid rectangle with top-left corner at x,y, width w and height h"""
for i in range(x, x + w):
_draw_fast_vline(setter, i, y, h, color, aa) | def fill_rect(setter, x, y, w, h, color=None, aa=False):
"""Draw solid rectangle with top-left corner at x,y, width w and height h"""
for i in range(x, x + w):
_draw_fast_vline(setter, i, y, h, color, aa) | [
"Draw",
"solid",
"rectangle",
"with",
"top",
"-",
"left",
"corner",
"at",
"x",
"y",
"width",
"w",
"and",
"height",
"h"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix_drawing.py#L252-L255 | [
"def",
"fill_rect",
"(",
"setter",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"for",
"i",
"in",
"range",
"(",
"x",
",",
"x",
"+",
"w",
")",
":",
"_draw_fast_vline",
"(",
"setter",
",",
"i",
",",
"y",
",",
"h",
",",
"color",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | draw_round_rect | Draw rectangle with top-left corner at x,y, width w, height h,
and corner radius r. | bibliopixel/layout/matrix_drawing.py | def draw_round_rect(setter, x, y, w, h, r, color=None, aa=False):
"""Draw rectangle with top-left corner at x,y, width w, height h,
and corner radius r.
"""
_draw_fast_hline(setter, x + r, y, w - 2 * r, color, aa) # Top
_draw_fast_hline(setter, x + r, y + h - 1, w - 2 * r, color, aa) # Bottom
_draw_fast_vline(setter, x, y + r, h - 2 * r, color, aa) # Left
_draw_fast_vline(setter, x + w - 1, y + r, h - 2 * r, color, aa) # Right
# draw four corners
_draw_circle_helper(setter, x + r, y + r, r, 1, color, aa)
_draw_circle_helper(setter, x + w - r - 1, y + r, r, 2, color, aa)
_draw_circle_helper(setter, x + w - r - 1, y + h - r - 1, r, 4, color, aa)
_draw_circle_helper(setter, x + r, y + h - r - 1, r, 8, color, aa) | def draw_round_rect(setter, x, y, w, h, r, color=None, aa=False):
"""Draw rectangle with top-left corner at x,y, width w, height h,
and corner radius r.
"""
_draw_fast_hline(setter, x + r, y, w - 2 * r, color, aa) # Top
_draw_fast_hline(setter, x + r, y + h - 1, w - 2 * r, color, aa) # Bottom
_draw_fast_vline(setter, x, y + r, h - 2 * r, color, aa) # Left
_draw_fast_vline(setter, x + w - 1, y + r, h - 2 * r, color, aa) # Right
# draw four corners
_draw_circle_helper(setter, x + r, y + r, r, 1, color, aa)
_draw_circle_helper(setter, x + w - r - 1, y + r, r, 2, color, aa)
_draw_circle_helper(setter, x + w - r - 1, y + h - r - 1, r, 4, color, aa)
_draw_circle_helper(setter, x + r, y + h - r - 1, r, 8, color, aa) | [
"Draw",
"rectangle",
"with",
"top",
"-",
"left",
"corner",
"at",
"x",
"y",
"width",
"w",
"height",
"h",
"and",
"corner",
"radius",
"r",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix_drawing.py#L258-L270 | [
"def",
"draw_round_rect",
"(",
"setter",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"r",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"_draw_fast_hline",
"(",
"setter",
",",
"x",
"+",
"r",
",",
"y",
",",
"w",
"-",
"2",
"*",
"r",
",",
"color",
",",
"aa",
")",
"# Top",
"_draw_fast_hline",
"(",
"setter",
",",
"x",
"+",
"r",
",",
"y",
"+",
"h",
"-",
"1",
",",
"w",
"-",
"2",
"*",
"r",
",",
"color",
",",
"aa",
")",
"# Bottom",
"_draw_fast_vline",
"(",
"setter",
",",
"x",
",",
"y",
"+",
"r",
",",
"h",
"-",
"2",
"*",
"r",
",",
"color",
",",
"aa",
")",
"# Left",
"_draw_fast_vline",
"(",
"setter",
",",
"x",
"+",
"w",
"-",
"1",
",",
"y",
"+",
"r",
",",
"h",
"-",
"2",
"*",
"r",
",",
"color",
",",
"aa",
")",
"# Right",
"# draw four corners",
"_draw_circle_helper",
"(",
"setter",
",",
"x",
"+",
"r",
",",
"y",
"+",
"r",
",",
"r",
",",
"1",
",",
"color",
",",
"aa",
")",
"_draw_circle_helper",
"(",
"setter",
",",
"x",
"+",
"w",
"-",
"r",
"-",
"1",
",",
"y",
"+",
"r",
",",
"r",
",",
"2",
",",
"color",
",",
"aa",
")",
"_draw_circle_helper",
"(",
"setter",
",",
"x",
"+",
"w",
"-",
"r",
"-",
"1",
",",
"y",
"+",
"h",
"-",
"r",
"-",
"1",
",",
"r",
",",
"4",
",",
"color",
",",
"aa",
")",
"_draw_circle_helper",
"(",
"setter",
",",
"x",
"+",
"r",
",",
"y",
"+",
"h",
"-",
"r",
"-",
"1",
",",
"r",
",",
"8",
",",
"color",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | fill_round_rect | Draw solid rectangle with top-left corner at x,y, width w, height h,
and corner radius r | bibliopixel/layout/matrix_drawing.py | def fill_round_rect(setter, x, y, w, h, r, color=None, aa=False):
"""Draw solid rectangle with top-left corner at x,y, width w, height h,
and corner radius r"""
fill_rect(setter, x + r, y, w - 2 * r, h, color, aa)
_fill_circle_helper(setter, x + w - r - 1, y + r, r,
1, h - 2 * r - 1, color, aa)
_fill_circle_helper(setter, x + r, y + r, r, 2, h - 2 * r - 1, color, aa) | def fill_round_rect(setter, x, y, w, h, r, color=None, aa=False):
"""Draw solid rectangle with top-left corner at x,y, width w, height h,
and corner radius r"""
fill_rect(setter, x + r, y, w - 2 * r, h, color, aa)
_fill_circle_helper(setter, x + w - r - 1, y + r, r,
1, h - 2 * r - 1, color, aa)
_fill_circle_helper(setter, x + r, y + r, r, 2, h - 2 * r - 1, color, aa) | [
"Draw",
"solid",
"rectangle",
"with",
"top",
"-",
"left",
"corner",
"at",
"x",
"y",
"width",
"w",
"height",
"h",
"and",
"corner",
"radius",
"r"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix_drawing.py#L273-L279 | [
"def",
"fill_round_rect",
"(",
"setter",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"r",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"fill_rect",
"(",
"setter",
",",
"x",
"+",
"r",
",",
"y",
",",
"w",
"-",
"2",
"*",
"r",
",",
"h",
",",
"color",
",",
"aa",
")",
"_fill_circle_helper",
"(",
"setter",
",",
"x",
"+",
"w",
"-",
"r",
"-",
"1",
",",
"y",
"+",
"r",
",",
"r",
",",
"1",
",",
"h",
"-",
"2",
"*",
"r",
"-",
"1",
",",
"color",
",",
"aa",
")",
"_fill_circle_helper",
"(",
"setter",
",",
"x",
"+",
"r",
",",
"y",
"+",
"r",
",",
"r",
",",
"2",
",",
"h",
"-",
"2",
"*",
"r",
"-",
"1",
",",
"color",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | draw_triangle | Draw triangle with points x0,y0 - x1,y1 - x2,y2 | bibliopixel/layout/matrix_drawing.py | def draw_triangle(setter, x0, y0, x1, y1, x2, y2, color=None, aa=False):
"""Draw triangle with points x0,y0 - x1,y1 - x2,y2"""
draw_line(setter, x0, y0, x1, y1, color, aa)
draw_line(setter, x1, y1, x2, y2, color, aa)
draw_line(setter, x2, y2, x0, y0, color, aa) | def draw_triangle(setter, x0, y0, x1, y1, x2, y2, color=None, aa=False):
"""Draw triangle with points x0,y0 - x1,y1 - x2,y2"""
draw_line(setter, x0, y0, x1, y1, color, aa)
draw_line(setter, x1, y1, x2, y2, color, aa)
draw_line(setter, x2, y2, x0, y0, color, aa) | [
"Draw",
"triangle",
"with",
"points",
"x0",
"y0",
"-",
"x1",
"y1",
"-",
"x2",
"y2"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix_drawing.py#L282-L286 | [
"def",
"draw_triangle",
"(",
"setter",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"draw_line",
"(",
"setter",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"color",
",",
"aa",
")",
"draw_line",
"(",
"setter",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
",",
"color",
",",
"aa",
")",
"draw_line",
"(",
"setter",
",",
"x2",
",",
"y2",
",",
"x0",
",",
"y0",
",",
"color",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | fill_triangle | Draw solid triangle with points x0,y0 - x1,y1 - x2,y2 | bibliopixel/layout/matrix_drawing.py | def fill_triangle(setter, x0, y0, x1, y1, x2, y2, color=None, aa=False):
"""Draw solid triangle with points x0,y0 - x1,y1 - x2,y2"""
a = b = y = last = 0
if y0 > y1:
y0, y1 = y1, y0
x0, x1 = x1, x0
if y1 > y2:
y2, y1 = y1, y2
x2, x1 = x1, x2
if y0 > y1:
y0, y1 = y1, y0
x0, x1 = x1, x0
if y0 == y2: # Handle awkward all-on-same-line case as its own thing
a = b = x0
if x1 < a:
a = x1
elif x1 > b:
b = x1
if x2 < a:
a = x2
elif x2 > b:
b = x2
_draw_fast_hline(setter, a, y0, b - a + 1, color, aa)
dx01 = x1 - x0
dy01 = y1 - y0
dx02 = x2 - x0
dy02 = y2 - y0
dx12 = x2 - x1
dy12 = y2 - y1
sa = 0
sb = 0
# For upper part of triangle, find scanline crossings for segments
# 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
# is included here (and second loop will be skipped, avoiding a /0
# error there), otherwise scanline y1 is skipped here and handled
# in the second loop...which also avoids a /0 error here if y0=y1
# (flat-topped triangle).
if y1 == y2:
last = y1 # include y1 scanline
else:
last = y1 - 1 # skip it
for y in range(y, last + 1):
a = x0 + sa / dy01
b = x0 + sb / dy02
sa += dx01
sb += dx02
if a > b:
a, b = b, a
_draw_fast_hline(setter, a, y, b - a + 1, color, aa)
# For lower part of triangle, find scanline crossings for segments
# 0-2 and 1-2. This loop is skipped if y1=y2.
sa = dx12 * (y - y1)
sb = dx02 * (y - y0)
for y in range(y, y2 + 1):
a = x1 + sa / dy12
b = x0 + sb / dy02
sa += dx12
sb += dx02
if a > b:
a, b = b, a
_draw_fast_hline(setter, a, y, b - a + 1, color, aa) | def fill_triangle(setter, x0, y0, x1, y1, x2, y2, color=None, aa=False):
"""Draw solid triangle with points x0,y0 - x1,y1 - x2,y2"""
a = b = y = last = 0
if y0 > y1:
y0, y1 = y1, y0
x0, x1 = x1, x0
if y1 > y2:
y2, y1 = y1, y2
x2, x1 = x1, x2
if y0 > y1:
y0, y1 = y1, y0
x0, x1 = x1, x0
if y0 == y2: # Handle awkward all-on-same-line case as its own thing
a = b = x0
if x1 < a:
a = x1
elif x1 > b:
b = x1
if x2 < a:
a = x2
elif x2 > b:
b = x2
_draw_fast_hline(setter, a, y0, b - a + 1, color, aa)
dx01 = x1 - x0
dy01 = y1 - y0
dx02 = x2 - x0
dy02 = y2 - y0
dx12 = x2 - x1
dy12 = y2 - y1
sa = 0
sb = 0
# For upper part of triangle, find scanline crossings for segments
# 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
# is included here (and second loop will be skipped, avoiding a /0
# error there), otherwise scanline y1 is skipped here and handled
# in the second loop...which also avoids a /0 error here if y0=y1
# (flat-topped triangle).
if y1 == y2:
last = y1 # include y1 scanline
else:
last = y1 - 1 # skip it
for y in range(y, last + 1):
a = x0 + sa / dy01
b = x0 + sb / dy02
sa += dx01
sb += dx02
if a > b:
a, b = b, a
_draw_fast_hline(setter, a, y, b - a + 1, color, aa)
# For lower part of triangle, find scanline crossings for segments
# 0-2 and 1-2. This loop is skipped if y1=y2.
sa = dx12 * (y - y1)
sb = dx02 * (y - y0)
for y in range(y, y2 + 1):
a = x1 + sa / dy12
b = x0 + sb / dy02
sa += dx12
sb += dx02
if a > b:
a, b = b, a
_draw_fast_hline(setter, a, y, b - a + 1, color, aa) | [
"Draw",
"solid",
"triangle",
"with",
"points",
"x0",
"y0",
"-",
"x1",
"y1",
"-",
"x2",
"y2"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix_drawing.py#L289-L359 | [
"def",
"fill_triangle",
"(",
"setter",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"a",
"=",
"b",
"=",
"y",
"=",
"last",
"=",
"0",
"if",
"y0",
">",
"y1",
":",
"y0",
",",
"y1",
"=",
"y1",
",",
"y0",
"x0",
",",
"x1",
"=",
"x1",
",",
"x0",
"if",
"y1",
">",
"y2",
":",
"y2",
",",
"y1",
"=",
"y1",
",",
"y2",
"x2",
",",
"x1",
"=",
"x1",
",",
"x2",
"if",
"y0",
">",
"y1",
":",
"y0",
",",
"y1",
"=",
"y1",
",",
"y0",
"x0",
",",
"x1",
"=",
"x1",
",",
"x0",
"if",
"y0",
"==",
"y2",
":",
"# Handle awkward all-on-same-line case as its own thing",
"a",
"=",
"b",
"=",
"x0",
"if",
"x1",
"<",
"a",
":",
"a",
"=",
"x1",
"elif",
"x1",
">",
"b",
":",
"b",
"=",
"x1",
"if",
"x2",
"<",
"a",
":",
"a",
"=",
"x2",
"elif",
"x2",
">",
"b",
":",
"b",
"=",
"x2",
"_draw_fast_hline",
"(",
"setter",
",",
"a",
",",
"y0",
",",
"b",
"-",
"a",
"+",
"1",
",",
"color",
",",
"aa",
")",
"dx01",
"=",
"x1",
"-",
"x0",
"dy01",
"=",
"y1",
"-",
"y0",
"dx02",
"=",
"x2",
"-",
"x0",
"dy02",
"=",
"y2",
"-",
"y0",
"dx12",
"=",
"x2",
"-",
"x1",
"dy12",
"=",
"y2",
"-",
"y1",
"sa",
"=",
"0",
"sb",
"=",
"0",
"# For upper part of triangle, find scanline crossings for segments",
"# 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1",
"# is included here (and second loop will be skipped, avoiding a /0",
"# error there), otherwise scanline y1 is skipped here and handled",
"# in the second loop...which also avoids a /0 error here if y0=y1",
"# (flat-topped triangle).",
"if",
"y1",
"==",
"y2",
":",
"last",
"=",
"y1",
"# include y1 scanline",
"else",
":",
"last",
"=",
"y1",
"-",
"1",
"# skip it",
"for",
"y",
"in",
"range",
"(",
"y",
",",
"last",
"+",
"1",
")",
":",
"a",
"=",
"x0",
"+",
"sa",
"/",
"dy01",
"b",
"=",
"x0",
"+",
"sb",
"/",
"dy02",
"sa",
"+=",
"dx01",
"sb",
"+=",
"dx02",
"if",
"a",
">",
"b",
":",
"a",
",",
"b",
"=",
"b",
",",
"a",
"_draw_fast_hline",
"(",
"setter",
",",
"a",
",",
"y",
",",
"b",
"-",
"a",
"+",
"1",
",",
"color",
",",
"aa",
")",
"# For lower part of triangle, find scanline crossings for segments",
"# 0-2 and 1-2. This loop is skipped if y1=y2.",
"sa",
"=",
"dx12",
"*",
"(",
"y",
"-",
"y1",
")",
"sb",
"=",
"dx02",
"*",
"(",
"y",
"-",
"y0",
")",
"for",
"y",
"in",
"range",
"(",
"y",
",",
"y2",
"+",
"1",
")",
":",
"a",
"=",
"x1",
"+",
"sa",
"/",
"dy12",
"b",
"=",
"x0",
"+",
"sb",
"/",
"dy02",
"sa",
"+=",
"dx12",
"sb",
"+=",
"dx02",
"if",
"a",
">",
"b",
":",
"a",
",",
"b",
"=",
"b",
",",
"a",
"_draw_fast_hline",
"(",
"setter",
",",
"a",
",",
"y",
",",
"b",
"-",
"a",
"+",
"1",
",",
"color",
",",
"aa",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | DriverBase.set_colors | Use with caution!
Directly set the pixel buffers.
:param colors: A list of color tuples
:param int pos: Position in color list to begin set operation. | bibliopixel/drivers/driver_base.py | def set_colors(self, colors, pos):
"""
Use with caution!
Directly set the pixel buffers.
:param colors: A list of color tuples
:param int pos: Position in color list to begin set operation.
"""
self._colors = colors
self._pos = pos
end = self._pos + self.numLEDs
if end > len(self._colors):
raise ValueError('Needed %d colors but found %d' % (
end, len(self._colors))) | def set_colors(self, colors, pos):
"""
Use with caution!
Directly set the pixel buffers.
:param colors: A list of color tuples
:param int pos: Position in color list to begin set operation.
"""
self._colors = colors
self._pos = pos
end = self._pos + self.numLEDs
if end > len(self._colors):
raise ValueError('Needed %d colors but found %d' % (
end, len(self._colors))) | [
"Use",
"with",
"caution!"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/drivers/driver_base.py#L80-L95 | [
"def",
"set_colors",
"(",
"self",
",",
"colors",
",",
"pos",
")",
":",
"self",
".",
"_colors",
"=",
"colors",
"self",
".",
"_pos",
"=",
"pos",
"end",
"=",
"self",
".",
"_pos",
"+",
"self",
".",
"numLEDs",
"if",
"end",
">",
"len",
"(",
"self",
".",
"_colors",
")",
":",
"raise",
"ValueError",
"(",
"'Needed %d colors but found %d'",
"%",
"(",
"end",
",",
"len",
"(",
"self",
".",
"_colors",
")",
")",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | DriverBase.update_colors | Apply any corrections to the current color list
and send the results to the driver output. This function primarily
provided as a wrapper for each driver's implementation of
:py:func:`_compute_packet` and :py:func:`_send_packet`. | bibliopixel/drivers/driver_base.py | def update_colors(self):
"""Apply any corrections to the current color list
and send the results to the driver output. This function primarily
provided as a wrapper for each driver's implementation of
:py:func:`_compute_packet` and :py:func:`_send_packet`.
"""
start = self.clock.time()
with self.brightness_lock:
# Swap in a new brightness.
brightness, self._waiting_brightness = (
self._waiting_brightness, None)
if brightness is not None:
self._brightness = brightness
if self.set_device_brightness:
self.set_device_brightness(brightness)
self._compute_packet()
self._send_packet()
self.lastUpdate = self.clock.time() - start | def update_colors(self):
"""Apply any corrections to the current color list
and send the results to the driver output. This function primarily
provided as a wrapper for each driver's implementation of
:py:func:`_compute_packet` and :py:func:`_send_packet`.
"""
start = self.clock.time()
with self.brightness_lock:
# Swap in a new brightness.
brightness, self._waiting_brightness = (
self._waiting_brightness, None)
if brightness is not None:
self._brightness = brightness
if self.set_device_brightness:
self.set_device_brightness(brightness)
self._compute_packet()
self._send_packet()
self.lastUpdate = self.clock.time() - start | [
"Apply",
"any",
"corrections",
"to",
"the",
"current",
"color",
"list",
"and",
"send",
"the",
"results",
"to",
"the",
"driver",
"output",
".",
"This",
"function",
"primarily",
"provided",
"as",
"a",
"wrapper",
"for",
"each",
"driver",
"s",
"implementation",
"of",
":",
"py",
":",
"func",
":",
"_compute_packet",
"and",
":",
"py",
":",
"func",
":",
"_send_packet",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/drivers/driver_base.py#L152-L173 | [
"def",
"update_colors",
"(",
"self",
")",
":",
"start",
"=",
"self",
".",
"clock",
".",
"time",
"(",
")",
"with",
"self",
".",
"brightness_lock",
":",
"# Swap in a new brightness.",
"brightness",
",",
"self",
".",
"_waiting_brightness",
"=",
"(",
"self",
".",
"_waiting_brightness",
",",
"None",
")",
"if",
"brightness",
"is",
"not",
"None",
":",
"self",
".",
"_brightness",
"=",
"brightness",
"if",
"self",
".",
"set_device_brightness",
":",
"self",
".",
"set_device_brightness",
"(",
"brightness",
")",
"self",
".",
"_compute_packet",
"(",
")",
"self",
".",
"_send_packet",
"(",
")",
"self",
".",
"lastUpdate",
"=",
"self",
".",
"clock",
".",
"time",
"(",
")",
"-",
"start"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | DriverBase._render | Typically called from :py:func:`_compute_packet` this applies
brightness and gamma correction to the pixels controlled by this
driver. | bibliopixel/drivers/driver_base.py | def _render(self):
"""Typically called from :py:func:`_compute_packet` this applies
brightness and gamma correction to the pixels controlled by this
driver.
"""
if self.set_device_brightness:
level = 1.0
else:
level = self._brightness / 255.0
gam, (r, g, b) = self.gamma.get, self.c_order
for i in range(min(self.numLEDs, len(self._buf) / 3)):
c = [int(level * x) for x in self._colors[i + self._pos]]
self._buf[i * 3:(i + 1) * 3] = gam(c[r]), gam(c[g]), gam(c[b]) | def _render(self):
"""Typically called from :py:func:`_compute_packet` this applies
brightness and gamma correction to the pixels controlled by this
driver.
"""
if self.set_device_brightness:
level = 1.0
else:
level = self._brightness / 255.0
gam, (r, g, b) = self.gamma.get, self.c_order
for i in range(min(self.numLEDs, len(self._buf) / 3)):
c = [int(level * x) for x in self._colors[i + self._pos]]
self._buf[i * 3:(i + 1) * 3] = gam(c[r]), gam(c[g]), gam(c[b]) | [
"Typically",
"called",
"from",
":",
"py",
":",
"func",
":",
"_compute_packet",
"this",
"applies",
"brightness",
"and",
"gamma",
"correction",
"to",
"the",
"pixels",
"controlled",
"by",
"this",
"driver",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/drivers/driver_base.py#L184-L196 | [
"def",
"_render",
"(",
"self",
")",
":",
"if",
"self",
".",
"set_device_brightness",
":",
"level",
"=",
"1.0",
"else",
":",
"level",
"=",
"self",
".",
"_brightness",
"/",
"255.0",
"gam",
",",
"(",
"r",
",",
"g",
",",
"b",
")",
"=",
"self",
".",
"gamma",
".",
"get",
",",
"self",
".",
"c_order",
"for",
"i",
"in",
"range",
"(",
"min",
"(",
"self",
".",
"numLEDs",
",",
"len",
"(",
"self",
".",
"_buf",
")",
"/",
"3",
")",
")",
":",
"c",
"=",
"[",
"int",
"(",
"level",
"*",
"x",
")",
"for",
"x",
"in",
"self",
".",
"_colors",
"[",
"i",
"+",
"self",
".",
"_pos",
"]",
"]",
"self",
".",
"_buf",
"[",
"i",
"*",
"3",
":",
"(",
"i",
"+",
"1",
")",
"*",
"3",
"]",
"=",
"gam",
"(",
"c",
"[",
"r",
"]",
")",
",",
"gam",
"(",
"c",
"[",
"g",
"]",
")",
",",
"gam",
"(",
"c",
"[",
"b",
"]",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | pointOnCircle | Calculates the coordinates of a point on a circle given the center point,
radius, and angle. | bibliopixel/util/util.py | def pointOnCircle(cx, cy, radius, angle):
"""
Calculates the coordinates of a point on a circle given the center point,
radius, and angle.
"""
angle = math.radians(angle) - (math.pi / 2)
x = cx + radius * math.cos(angle)
if x < cx:
x = math.ceil(x)
else:
x = math.floor(x)
y = cy + radius * math.sin(angle)
if y < cy:
y = math.ceil(y)
else:
y = math.floor(y)
return (int(x), int(y)) | def pointOnCircle(cx, cy, radius, angle):
"""
Calculates the coordinates of a point on a circle given the center point,
radius, and angle.
"""
angle = math.radians(angle) - (math.pi / 2)
x = cx + radius * math.cos(angle)
if x < cx:
x = math.ceil(x)
else:
x = math.floor(x)
y = cy + radius * math.sin(angle)
if y < cy:
y = math.ceil(y)
else:
y = math.floor(y)
return (int(x), int(y)) | [
"Calculates",
"the",
"coordinates",
"of",
"a",
"point",
"on",
"a",
"circle",
"given",
"the",
"center",
"point",
"radius",
"and",
"angle",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/util.py#L36-L55 | [
"def",
"pointOnCircle",
"(",
"cx",
",",
"cy",
",",
"radius",
",",
"angle",
")",
":",
"angle",
"=",
"math",
".",
"radians",
"(",
"angle",
")",
"-",
"(",
"math",
".",
"pi",
"/",
"2",
")",
"x",
"=",
"cx",
"+",
"radius",
"*",
"math",
".",
"cos",
"(",
"angle",
")",
"if",
"x",
"<",
"cx",
":",
"x",
"=",
"math",
".",
"ceil",
"(",
"x",
")",
"else",
":",
"x",
"=",
"math",
".",
"floor",
"(",
"x",
")",
"y",
"=",
"cy",
"+",
"radius",
"*",
"math",
".",
"sin",
"(",
"angle",
")",
"if",
"y",
"<",
"cy",
":",
"y",
"=",
"math",
".",
"ceil",
"(",
"y",
")",
"else",
":",
"y",
"=",
"math",
".",
"floor",
"(",
"y",
")",
"return",
"(",
"int",
"(",
"x",
")",
",",
"int",
"(",
"y",
")",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | genVector | Generates a map of vector lengths from the center point to each coordinate.
width - width of matrix to generate
height - height of matrix to generate
x_mult - value to scale x-axis by
y_mult - value to scale y-axis by | bibliopixel/util/util.py | def genVector(width, height, x_mult=1, y_mult=1):
"""
Generates a map of vector lengths from the center point to each coordinate.
width - width of matrix to generate
height - height of matrix to generate
x_mult - value to scale x-axis by
y_mult - value to scale y-axis by
"""
center_x = (width - 1) / 2
center_y = (height - 1) / 2
def length(x, y):
dx = math.pow(x - center_x, 2 * x_mult)
dy = math.pow(y - center_y, 2 * y_mult)
return int(math.sqrt(dx + dy))
return [[length(x, y) for x in range(width)] for y in range(height)] | def genVector(width, height, x_mult=1, y_mult=1):
"""
Generates a map of vector lengths from the center point to each coordinate.
width - width of matrix to generate
height - height of matrix to generate
x_mult - value to scale x-axis by
y_mult - value to scale y-axis by
"""
center_x = (width - 1) / 2
center_y = (height - 1) / 2
def length(x, y):
dx = math.pow(x - center_x, 2 * x_mult)
dy = math.pow(y - center_y, 2 * y_mult)
return int(math.sqrt(dx + dy))
return [[length(x, y) for x in range(width)] for y in range(height)] | [
"Generates",
"a",
"map",
"of",
"vector",
"lengths",
"from",
"the",
"center",
"point",
"to",
"each",
"coordinate",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/util.py#L58-L75 | [
"def",
"genVector",
"(",
"width",
",",
"height",
",",
"x_mult",
"=",
"1",
",",
"y_mult",
"=",
"1",
")",
":",
"center_x",
"=",
"(",
"width",
"-",
"1",
")",
"/",
"2",
"center_y",
"=",
"(",
"height",
"-",
"1",
")",
"/",
"2",
"def",
"length",
"(",
"x",
",",
"y",
")",
":",
"dx",
"=",
"math",
".",
"pow",
"(",
"x",
"-",
"center_x",
",",
"2",
"*",
"x_mult",
")",
"dy",
"=",
"math",
".",
"pow",
"(",
"y",
"-",
"center_y",
",",
"2",
"*",
"y_mult",
")",
"return",
"int",
"(",
"math",
".",
"sqrt",
"(",
"dx",
"+",
"dy",
")",
")",
"return",
"[",
"[",
"length",
"(",
"x",
",",
"y",
")",
"for",
"x",
"in",
"range",
"(",
"width",
")",
"]",
"for",
"y",
"in",
"range",
"(",
"height",
")",
"]"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | all_named_colors | Return an iteration over all name, color pairs in tables | bibliopixel/colors/tables.py | def all_named_colors():
"""Return an iteration over all name, color pairs in tables"""
yield from _TO_COLOR_USER.items()
for name, color in _TO_COLOR.items():
if name not in _TO_COLOR_USER:
yield name, color | def all_named_colors():
"""Return an iteration over all name, color pairs in tables"""
yield from _TO_COLOR_USER.items()
for name, color in _TO_COLOR.items():
if name not in _TO_COLOR_USER:
yield name, color | [
"Return",
"an",
"iteration",
"over",
"all",
"name",
"color",
"pairs",
"in",
"tables"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/tables.py#L40-L45 | [
"def",
"all_named_colors",
"(",
")",
":",
"yield",
"from",
"_TO_COLOR_USER",
".",
"items",
"(",
")",
"for",
"name",
",",
"color",
"in",
"_TO_COLOR",
".",
"items",
"(",
")",
":",
"if",
"name",
"not",
"in",
"_TO_COLOR_USER",
":",
"yield",
"name",
",",
"color"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | contains | Return true if this string or integer tuple appears in tables | bibliopixel/colors/tables.py | def contains(x):
"""Return true if this string or integer tuple appears in tables"""
if isinstance(x, str):
x = canonical_name(x)
return x in _TO_COLOR_USER or x in _TO_COLOR
else:
x = tuple(x)
return x in _TO_NAME_USER or x in _TO_NAME | def contains(x):
"""Return true if this string or integer tuple appears in tables"""
if isinstance(x, str):
x = canonical_name(x)
return x in _TO_COLOR_USER or x in _TO_COLOR
else:
x = tuple(x)
return x in _TO_NAME_USER or x in _TO_NAME | [
"Return",
"true",
"if",
"this",
"string",
"or",
"integer",
"tuple",
"appears",
"in",
"tables"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/tables.py#L48-L55 | [
"def",
"contains",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"str",
")",
":",
"x",
"=",
"canonical_name",
"(",
"x",
")",
"return",
"x",
"in",
"_TO_COLOR_USER",
"or",
"x",
"in",
"_TO_COLOR",
"else",
":",
"x",
"=",
"tuple",
"(",
"x",
")",
"return",
"x",
"in",
"_TO_NAME_USER",
"or",
"x",
"in",
"_TO_NAME"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | make_segments | Return a list of Segments that evenly split the strip. | bibliopixel/layout/geometry/segment.py | def make_segments(strip, length):
"""Return a list of Segments that evenly split the strip."""
if len(strip) % length:
raise ValueError('The length of strip must be a multiple of length')
s = []
try:
while True:
s.append(s[-1].next(length) if s else Segment(strip, length))
except ValueError:
return s | def make_segments(strip, length):
"""Return a list of Segments that evenly split the strip."""
if len(strip) % length:
raise ValueError('The length of strip must be a multiple of length')
s = []
try:
while True:
s.append(s[-1].next(length) if s else Segment(strip, length))
except ValueError:
return s | [
"Return",
"a",
"list",
"of",
"Segments",
"that",
"evenly",
"split",
"the",
"strip",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/geometry/segment.py#L41-L51 | [
"def",
"make_segments",
"(",
"strip",
",",
"length",
")",
":",
"if",
"len",
"(",
"strip",
")",
"%",
"length",
":",
"raise",
"ValueError",
"(",
"'The length of strip must be a multiple of length'",
")",
"s",
"=",
"[",
"]",
"try",
":",
"while",
"True",
":",
"s",
".",
"append",
"(",
"s",
"[",
"-",
"1",
"]",
".",
"next",
"(",
"length",
")",
"if",
"s",
"else",
"Segment",
"(",
"strip",
",",
"length",
")",
")",
"except",
"ValueError",
":",
"return",
"s"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Segment.next | Return a new segment starting right after self in the same buffer. | bibliopixel/layout/geometry/segment.py | def next(self, length):
"""Return a new segment starting right after self in the same buffer."""
return Segment(self.strip, length, self.offset + self.length) | def next(self, length):
"""Return a new segment starting right after self in the same buffer."""
return Segment(self.strip, length, self.offset + self.length) | [
"Return",
"a",
"new",
"segment",
"starting",
"right",
"after",
"self",
"in",
"the",
"same",
"buffer",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/geometry/segment.py#L27-L29 | [
"def",
"next",
"(",
"self",
",",
"length",
")",
":",
"return",
"Segment",
"(",
"self",
".",
"strip",
",",
"length",
",",
"self",
".",
"offset",
"+",
"self",
".",
"length",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | sender | :param str address: a pair (ip_address, port) to pass to socket.connect
:param bool use_queue: if True, run the connection in a different thread
with a queue | bibliopixel/util/udp.py | def sender(address, use_queue=True, **kwds):
"""
:param str address: a pair (ip_address, port) to pass to socket.connect
:param bool use_queue: if True, run the connection in a different thread
with a queue
"""
return QueuedSender(address, **kwds) if use_queue else Sender(address) | def sender(address, use_queue=True, **kwds):
"""
:param str address: a pair (ip_address, port) to pass to socket.connect
:param bool use_queue: if True, run the connection in a different thread
with a queue
"""
return QueuedSender(address, **kwds) if use_queue else Sender(address) | [
":",
"param",
"str",
"address",
":",
"a",
"pair",
"(",
"ip_address",
"port",
")",
"to",
"pass",
"to",
"socket",
".",
"connect",
":",
"param",
"bool",
"use_queue",
":",
"if",
"True",
"run",
"the",
"connection",
"in",
"a",
"different",
"thread",
"with",
"a",
"queue"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/udp.py#L48-L54 | [
"def",
"sender",
"(",
"address",
",",
"use_queue",
"=",
"True",
",",
"*",
"*",
"kwds",
")",
":",
"return",
"QueuedSender",
"(",
"address",
",",
"*",
"*",
"kwds",
")",
"if",
"use_queue",
"else",
"Sender",
"(",
"address",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Builder.start | Creates and starts the project. | bibliopixel/builder/builder.py | def start(self, threaded=None):
"""Creates and starts the project."""
if threaded is not None:
self.threaded = threaded
run = {'run': {'threaded': False}}
self.project = project.project(
self.desc, run, root_file=self.project_file)
self._run = self.project.run
self._runner.start(self.threaded) | def start(self, threaded=None):
"""Creates and starts the project."""
if threaded is not None:
self.threaded = threaded
run = {'run': {'threaded': False}}
self.project = project.project(
self.desc, run, root_file=self.project_file)
self._run = self.project.run
self._runner.start(self.threaded) | [
"Creates",
"and",
"starts",
"the",
"project",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/builder/builder.py#L29-L37 | [
"def",
"start",
"(",
"self",
",",
"threaded",
"=",
"None",
")",
":",
"if",
"threaded",
"is",
"not",
"None",
":",
"self",
".",
"threaded",
"=",
"threaded",
"run",
"=",
"{",
"'run'",
":",
"{",
"'threaded'",
":",
"False",
"}",
"}",
"self",
".",
"project",
"=",
"project",
".",
"project",
"(",
"self",
".",
"desc",
",",
"run",
",",
"root_file",
"=",
"self",
".",
"project_file",
")",
"self",
".",
"_run",
"=",
"self",
".",
"project",
".",
"run",
"self",
".",
"_runner",
".",
"start",
"(",
"self",
".",
"threaded",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Builder.stop | Stop the builder if it's running. | bibliopixel/builder/builder.py | def stop(self=None):
"""Stop the builder if it's running."""
if not self:
instance = getattr(Runner.instance(), 'builder', None)
self = instance and instance()
if not self:
return
self._runner.stop()
if self.project:
self.project.stop()
self.project = None | def stop(self=None):
"""Stop the builder if it's running."""
if not self:
instance = getattr(Runner.instance(), 'builder', None)
self = instance and instance()
if not self:
return
self._runner.stop()
if self.project:
self.project.stop()
self.project = None | [
"Stop",
"the",
"builder",
"if",
"it",
"s",
"running",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/builder/builder.py#L39-L50 | [
"def",
"stop",
"(",
"self",
"=",
"None",
")",
":",
"if",
"not",
"self",
":",
"instance",
"=",
"getattr",
"(",
"Runner",
".",
"instance",
"(",
")",
",",
"'builder'",
",",
"None",
")",
"self",
"=",
"instance",
"and",
"instance",
"(",
")",
"if",
"not",
"self",
":",
"return",
"self",
".",
"_runner",
".",
"stop",
"(",
")",
"if",
"self",
".",
"project",
":",
"self",
".",
"project",
".",
"stop",
"(",
")",
"self",
".",
"project",
"=",
"None"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Builder.simpixel | Open an instance of simpixel in the browser | bibliopixel/builder/builder.py | def simpixel(new=0, autoraise=True):
"""Open an instance of simpixel in the browser"""
simpixel_driver.open_browser(new=new, autoraise=autoraise) | def simpixel(new=0, autoraise=True):
"""Open an instance of simpixel in the browser"""
simpixel_driver.open_browser(new=new, autoraise=autoraise) | [
"Open",
"an",
"instance",
"of",
"simpixel",
"in",
"the",
"browser"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/builder/builder.py#L75-L77 | [
"def",
"simpixel",
"(",
"new",
"=",
"0",
",",
"autoraise",
"=",
"True",
")",
":",
"simpixel_driver",
".",
"open_browser",
"(",
"new",
"=",
"new",
",",
"autoraise",
"=",
"autoraise",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | recurse | Depth first recursion through a dictionary containing type constructors
The arguments pre, post and children are independently either:
* None, which means to do nothing
* a string, which means to use the static class method of that name on the
class being constructed, or
* a callable, to be called at each recursion
Arguments:
dictionary -- a project dictionary or one of its subdictionaries
pre -- called before children are visited node in the recursion
post -- called after children are visited in the recursion
python_path -- relative path to start resolving typenames | bibliopixel/project/recurse.py | def recurse(desc, pre='pre_recursion', post=None, python_path=None):
"""
Depth first recursion through a dictionary containing type constructors
The arguments pre, post and children are independently either:
* None, which means to do nothing
* a string, which means to use the static class method of that name on the
class being constructed, or
* a callable, to be called at each recursion
Arguments:
dictionary -- a project dictionary or one of its subdictionaries
pre -- called before children are visited node in the recursion
post -- called after children are visited in the recursion
python_path -- relative path to start resolving typenames
"""
def call(f, desc):
if isinstance(f, str):
# f is the name of a static class method on the datatype.
f = getattr(datatype, f, None)
return f and f(desc)
# Automatically load strings that look like JSON or Yaml filenames.
desc = load.load_if_filename(desc) or desc
desc = construct.to_type_constructor(desc, python_path)
datatype = desc.get('datatype')
desc = call(pre, desc) or desc
for child_name in getattr(datatype, 'CHILDREN', []):
child = desc.get(child_name)
if child:
is_plural = child_name.endswith('s')
remove_s = is_plural and child_name != 'drivers'
# This is because it's the "drivers" directory, whereas
# the others are animation, control, layout, project
# without the s. TODO: rename drivers/ to driver/ in v4
cname = child_name[:-1] if remove_s else child_name
new_path = python_path or ('bibliopixel.' + cname)
if is_plural:
if isinstance(child, (dict, str)):
child = [child]
for i, c in enumerate(child):
child[i] = recurse(c, pre, post, new_path)
desc[child_name] = child
else:
desc[child_name] = recurse(child, pre, post, new_path)
d = call(post, desc)
return desc if d is None else d | def recurse(desc, pre='pre_recursion', post=None, python_path=None):
"""
Depth first recursion through a dictionary containing type constructors
The arguments pre, post and children are independently either:
* None, which means to do nothing
* a string, which means to use the static class method of that name on the
class being constructed, or
* a callable, to be called at each recursion
Arguments:
dictionary -- a project dictionary or one of its subdictionaries
pre -- called before children are visited node in the recursion
post -- called after children are visited in the recursion
python_path -- relative path to start resolving typenames
"""
def call(f, desc):
if isinstance(f, str):
# f is the name of a static class method on the datatype.
f = getattr(datatype, f, None)
return f and f(desc)
# Automatically load strings that look like JSON or Yaml filenames.
desc = load.load_if_filename(desc) or desc
desc = construct.to_type_constructor(desc, python_path)
datatype = desc.get('datatype')
desc = call(pre, desc) or desc
for child_name in getattr(datatype, 'CHILDREN', []):
child = desc.get(child_name)
if child:
is_plural = child_name.endswith('s')
remove_s = is_plural and child_name != 'drivers'
# This is because it's the "drivers" directory, whereas
# the others are animation, control, layout, project
# without the s. TODO: rename drivers/ to driver/ in v4
cname = child_name[:-1] if remove_s else child_name
new_path = python_path or ('bibliopixel.' + cname)
if is_plural:
if isinstance(child, (dict, str)):
child = [child]
for i, c in enumerate(child):
child[i] = recurse(c, pre, post, new_path)
desc[child_name] = child
else:
desc[child_name] = recurse(child, pre, post, new_path)
d = call(post, desc)
return desc if d is None else d | [
"Depth",
"first",
"recursion",
"through",
"a",
"dictionary",
"containing",
"type",
"constructors"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/project/recurse.py#L20-L74 | [
"def",
"recurse",
"(",
"desc",
",",
"pre",
"=",
"'pre_recursion'",
",",
"post",
"=",
"None",
",",
"python_path",
"=",
"None",
")",
":",
"def",
"call",
"(",
"f",
",",
"desc",
")",
":",
"if",
"isinstance",
"(",
"f",
",",
"str",
")",
":",
"# f is the name of a static class method on the datatype.",
"f",
"=",
"getattr",
"(",
"datatype",
",",
"f",
",",
"None",
")",
"return",
"f",
"and",
"f",
"(",
"desc",
")",
"# Automatically load strings that look like JSON or Yaml filenames.",
"desc",
"=",
"load",
".",
"load_if_filename",
"(",
"desc",
")",
"or",
"desc",
"desc",
"=",
"construct",
".",
"to_type_constructor",
"(",
"desc",
",",
"python_path",
")",
"datatype",
"=",
"desc",
".",
"get",
"(",
"'datatype'",
")",
"desc",
"=",
"call",
"(",
"pre",
",",
"desc",
")",
"or",
"desc",
"for",
"child_name",
"in",
"getattr",
"(",
"datatype",
",",
"'CHILDREN'",
",",
"[",
"]",
")",
":",
"child",
"=",
"desc",
".",
"get",
"(",
"child_name",
")",
"if",
"child",
":",
"is_plural",
"=",
"child_name",
".",
"endswith",
"(",
"'s'",
")",
"remove_s",
"=",
"is_plural",
"and",
"child_name",
"!=",
"'drivers'",
"# This is because it's the \"drivers\" directory, whereas",
"# the others are animation, control, layout, project",
"# without the s. TODO: rename drivers/ to driver/ in v4",
"cname",
"=",
"child_name",
"[",
":",
"-",
"1",
"]",
"if",
"remove_s",
"else",
"child_name",
"new_path",
"=",
"python_path",
"or",
"(",
"'bibliopixel.'",
"+",
"cname",
")",
"if",
"is_plural",
":",
"if",
"isinstance",
"(",
"child",
",",
"(",
"dict",
",",
"str",
")",
")",
":",
"child",
"=",
"[",
"child",
"]",
"for",
"i",
",",
"c",
"in",
"enumerate",
"(",
"child",
")",
":",
"child",
"[",
"i",
"]",
"=",
"recurse",
"(",
"c",
",",
"pre",
",",
"post",
",",
"new_path",
")",
"desc",
"[",
"child_name",
"]",
"=",
"child",
"else",
":",
"desc",
"[",
"child_name",
"]",
"=",
"recurse",
"(",
"child",
",",
"pre",
",",
"post",
",",
"new_path",
")",
"d",
"=",
"call",
"(",
"post",
",",
"desc",
")",
"return",
"desc",
"if",
"d",
"is",
"None",
"else",
"d"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | class_name | :param c: either an object or a class
:return: the classname as a string | bibliopixel/util/class_name.py | def class_name(c):
"""
:param c: either an object or a class
:return: the classname as a string
"""
if not isinstance(c, type):
c = type(c)
return '%s.%s' % (c.__module__, c.__name__) | def class_name(c):
"""
:param c: either an object or a class
:return: the classname as a string
"""
if not isinstance(c, type):
c = type(c)
return '%s.%s' % (c.__module__, c.__name__) | [
":",
"param",
"c",
":",
"either",
"an",
"object",
"or",
"a",
"class",
":",
"return",
":",
"the",
"classname",
"as",
"a",
"string"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/class_name.py#L1-L9 | [
"def",
"class_name",
"(",
"c",
")",
":",
"if",
"not",
"isinstance",
"(",
"c",
",",
"type",
")",
":",
"c",
"=",
"type",
"(",
"c",
")",
"return",
"'%s.%s'",
"%",
"(",
"c",
".",
"__module__",
",",
"c",
".",
"__name__",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | to_type_constructor | Tries to convert a value to a type constructor.
If value is a string, then it used as the "typename" field.
If the "typename" field exists, the symbol for that name is imported and
added to the type constructor as a field "datatype".
Throws:
ImportError -- if "typename" is set but cannot be imported
ValueError -- if "typename" is malformed | bibliopixel/project/construct.py | def to_type_constructor(value, python_path=None):
""""
Tries to convert a value to a type constructor.
If value is a string, then it used as the "typename" field.
If the "typename" field exists, the symbol for that name is imported and
added to the type constructor as a field "datatype".
Throws:
ImportError -- if "typename" is set but cannot be imported
ValueError -- if "typename" is malformed
"""
if not value:
return value
if callable(value):
return {'datatype': value}
value = to_type(value)
typename = value.get('typename')
if typename:
r = aliases.resolve(typename)
try:
value['datatype'] = importer.import_symbol(
r, python_path=python_path)
del value['typename']
except Exception as e:
value['_exception'] = e
return value | def to_type_constructor(value, python_path=None):
""""
Tries to convert a value to a type constructor.
If value is a string, then it used as the "typename" field.
If the "typename" field exists, the symbol for that name is imported and
added to the type constructor as a field "datatype".
Throws:
ImportError -- if "typename" is set but cannot be imported
ValueError -- if "typename" is malformed
"""
if not value:
return value
if callable(value):
return {'datatype': value}
value = to_type(value)
typename = value.get('typename')
if typename:
r = aliases.resolve(typename)
try:
value['datatype'] = importer.import_symbol(
r, python_path=python_path)
del value['typename']
except Exception as e:
value['_exception'] = e
return value | [
"Tries",
"to",
"convert",
"a",
"value",
"to",
"a",
"type",
"constructor",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/project/construct.py#L31-L61 | [
"def",
"to_type_constructor",
"(",
"value",
",",
"python_path",
"=",
"None",
")",
":",
"if",
"not",
"value",
":",
"return",
"value",
"if",
"callable",
"(",
"value",
")",
":",
"return",
"{",
"'datatype'",
":",
"value",
"}",
"value",
"=",
"to_type",
"(",
"value",
")",
"typename",
"=",
"value",
".",
"get",
"(",
"'typename'",
")",
"if",
"typename",
":",
"r",
"=",
"aliases",
".",
"resolve",
"(",
"typename",
")",
"try",
":",
"value",
"[",
"'datatype'",
"]",
"=",
"importer",
".",
"import_symbol",
"(",
"r",
",",
"python_path",
"=",
"python_path",
")",
"del",
"value",
"[",
"'typename'",
"]",
"except",
"Exception",
"as",
"e",
":",
"value",
"[",
"'_exception'",
"]",
"=",
"e",
"return",
"value"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | fill | Fill a portion of a strip from start to stop by step with a given item.
If stop is not given, it defaults to the length of the strip. | bibliopixel/layout/geometry/strip.py | def fill(strip, item, start=0, stop=None, step=1):
"""Fill a portion of a strip from start to stop by step with a given item.
If stop is not given, it defaults to the length of the strip.
"""
if stop is None:
stop = len(strip)
for i in range(start, stop, step):
strip[i] = item | def fill(strip, item, start=0, stop=None, step=1):
"""Fill a portion of a strip from start to stop by step with a given item.
If stop is not given, it defaults to the length of the strip.
"""
if stop is None:
stop = len(strip)
for i in range(start, stop, step):
strip[i] = item | [
"Fill",
"a",
"portion",
"of",
"a",
"strip",
"from",
"start",
"to",
"stop",
"by",
"step",
"with",
"a",
"given",
"item",
".",
"If",
"stop",
"is",
"not",
"given",
"it",
"defaults",
"to",
"the",
"length",
"of",
"the",
"strip",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/geometry/strip.py#L22-L30 | [
"def",
"fill",
"(",
"strip",
",",
"item",
",",
"start",
"=",
"0",
",",
"stop",
"=",
"None",
",",
"step",
"=",
"1",
")",
":",
"if",
"stop",
"is",
"None",
":",
"stop",
"=",
"len",
"(",
"strip",
")",
"for",
"i",
"in",
"range",
"(",
"start",
",",
"stop",
",",
"step",
")",
":",
"strip",
"[",
"i",
"]",
"=",
"item"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | pop_legacy_palette | Older animations in BPA and other areas use all sorts of different names for
what we are now representing with palettes.
This function mutates a kwds dictionary to remove these legacy fields and
extract a palette from it, which it returns. | bibliopixel/colors/legacy_palette.py | def pop_legacy_palette(kwds, *color_defaults):
"""
Older animations in BPA and other areas use all sorts of different names for
what we are now representing with palettes.
This function mutates a kwds dictionary to remove these legacy fields and
extract a palette from it, which it returns.
"""
palette = kwds.pop('palette', None)
if palette:
legacy = [k for k, _ in color_defaults if k in kwds]
if legacy:
raise ValueError('Cannot set palette and ' + ', '.join(legacy))
return palette
values = [kwds.pop(k, v) for k, v in color_defaults]
if values and color_defaults[0][0] in ('colors', 'palette'):
values = values[0]
return make.colors(values or None) | def pop_legacy_palette(kwds, *color_defaults):
"""
Older animations in BPA and other areas use all sorts of different names for
what we are now representing with palettes.
This function mutates a kwds dictionary to remove these legacy fields and
extract a palette from it, which it returns.
"""
palette = kwds.pop('palette', None)
if palette:
legacy = [k for k, _ in color_defaults if k in kwds]
if legacy:
raise ValueError('Cannot set palette and ' + ', '.join(legacy))
return palette
values = [kwds.pop(k, v) for k, v in color_defaults]
if values and color_defaults[0][0] in ('colors', 'palette'):
values = values[0]
return make.colors(values or None) | [
"Older",
"animations",
"in",
"BPA",
"and",
"other",
"areas",
"use",
"all",
"sorts",
"of",
"different",
"names",
"for",
"what",
"we",
"are",
"now",
"representing",
"with",
"palettes",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/legacy_palette.py#L4-L23 | [
"def",
"pop_legacy_palette",
"(",
"kwds",
",",
"*",
"color_defaults",
")",
":",
"palette",
"=",
"kwds",
".",
"pop",
"(",
"'palette'",
",",
"None",
")",
"if",
"palette",
":",
"legacy",
"=",
"[",
"k",
"for",
"k",
",",
"_",
"in",
"color_defaults",
"if",
"k",
"in",
"kwds",
"]",
"if",
"legacy",
":",
"raise",
"ValueError",
"(",
"'Cannot set palette and '",
"+",
"', '",
".",
"join",
"(",
"legacy",
")",
")",
"return",
"palette",
"values",
"=",
"[",
"kwds",
".",
"pop",
"(",
"k",
",",
"v",
")",
"for",
"k",
",",
"v",
"in",
"color_defaults",
"]",
"if",
"values",
"and",
"color_defaults",
"[",
"0",
"]",
"[",
"0",
"]",
"in",
"(",
"'colors'",
",",
"'palette'",
")",
":",
"values",
"=",
"values",
"[",
"0",
"]",
"return",
"make",
".",
"colors",
"(",
"values",
"or",
"None",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | euclidean | Square of the euclidean distance | bibliopixel/colors/closest_colors.py | def euclidean(c1, c2):
"""Square of the euclidean distance"""
diffs = ((i - j) for i, j in zip(c1, c2))
return sum(x * x for x in diffs) | def euclidean(c1, c2):
"""Square of the euclidean distance"""
diffs = ((i - j) for i, j in zip(c1, c2))
return sum(x * x for x in diffs) | [
"Square",
"of",
"the",
"euclidean",
"distance"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/closest_colors.py#L19-L22 | [
"def",
"euclidean",
"(",
"c1",
",",
"c2",
")",
":",
"diffs",
"=",
"(",
"(",
"i",
"-",
"j",
")",
"for",
"i",
",",
"j",
"in",
"zip",
"(",
"c1",
",",
"c2",
")",
")",
"return",
"sum",
"(",
"x",
"*",
"x",
"for",
"x",
"in",
"diffs",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Writer._write | Write a series of frames as a single animated GIF.
:param str filename: the name of the GIF file to write
:param list frames: a list of filenames, each of which represents a single
frame of the animation. Each frame must have exactly the same
dimensions, and the code has only been tested with .gif files.
:param float fps:
The number of frames per second.
:param int loop:
The number of iterations. Default 0 (meaning loop indefinitely).
:param int palette:
The number of colors to quantize the image to. Is rounded to
the nearest power of two. Default 256. | bibliopixel/util/image/gif.py | def _write(self, filename, frames, fps, loop=0, palette=256):
"""
Write a series of frames as a single animated GIF.
:param str filename: the name of the GIF file to write
:param list frames: a list of filenames, each of which represents a single
frame of the animation. Each frame must have exactly the same
dimensions, and the code has only been tested with .gif files.
:param float fps:
The number of frames per second.
:param int loop:
The number of iterations. Default 0 (meaning loop indefinitely).
:param int palette:
The number of colors to quantize the image to. Is rounded to
the nearest power of two. Default 256.
"""
from PIL import Image
images = []
for f in frames:
data = open(f, 'rb').read()
images.append(Image.open(io.BytesIO(data)))
# GIF duration is only measured to a hundredth of a second
duration = round(1 / fps, 2)
im = images.pop(0)
im.save(filename,
save_all=True,
append_images=images,
duration=duration,
loop=loop,
palette=palette) | def _write(self, filename, frames, fps, loop=0, palette=256):
"""
Write a series of frames as a single animated GIF.
:param str filename: the name of the GIF file to write
:param list frames: a list of filenames, each of which represents a single
frame of the animation. Each frame must have exactly the same
dimensions, and the code has only been tested with .gif files.
:param float fps:
The number of frames per second.
:param int loop:
The number of iterations. Default 0 (meaning loop indefinitely).
:param int palette:
The number of colors to quantize the image to. Is rounded to
the nearest power of two. Default 256.
"""
from PIL import Image
images = []
for f in frames:
data = open(f, 'rb').read()
images.append(Image.open(io.BytesIO(data)))
# GIF duration is only measured to a hundredth of a second
duration = round(1 / fps, 2)
im = images.pop(0)
im.save(filename,
save_all=True,
append_images=images,
duration=duration,
loop=loop,
palette=palette) | [
"Write",
"a",
"series",
"of",
"frames",
"as",
"a",
"single",
"animated",
"GIF",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/image/gif.py#L7-L42 | [
"def",
"_write",
"(",
"self",
",",
"filename",
",",
"frames",
",",
"fps",
",",
"loop",
"=",
"0",
",",
"palette",
"=",
"256",
")",
":",
"from",
"PIL",
"import",
"Image",
"images",
"=",
"[",
"]",
"for",
"f",
"in",
"frames",
":",
"data",
"=",
"open",
"(",
"f",
",",
"'rb'",
")",
".",
"read",
"(",
")",
"images",
".",
"append",
"(",
"Image",
".",
"open",
"(",
"io",
".",
"BytesIO",
"(",
"data",
")",
")",
")",
"# GIF duration is only measured to a hundredth of a second",
"duration",
"=",
"round",
"(",
"1",
"/",
"fps",
",",
"2",
")",
"im",
"=",
"images",
".",
"pop",
"(",
"0",
")",
"im",
".",
"save",
"(",
"filename",
",",
"save_all",
"=",
"True",
",",
"append_images",
"=",
"images",
",",
"duration",
"=",
"duration",
",",
"loop",
"=",
"loop",
",",
"palette",
"=",
"palette",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | dumps | Dumps data into a nicely formatted JSON string.
:param dict data: a dictionary to dump
:param kwds: keywords to pass to json.dumps
:returns: a string with formatted data
:rtype: str | bibliopixel/util/data_file.py | def dumps(data, use_yaml=None, safe=True, **kwds):
"""
Dumps data into a nicely formatted JSON string.
:param dict data: a dictionary to dump
:param kwds: keywords to pass to json.dumps
:returns: a string with formatted data
:rtype: str
"""
if use_yaml is None:
use_yaml = ALWAYS_DUMP_YAML
if use_yaml:
dumps = yaml.safe_dump if safe else yaml.dump
else:
dumps = json.dumps
kwds.update(indent=4, sort_keys=True)
if not safe:
kwds.update(default=repr)
return dumps(data, **kwds) | def dumps(data, use_yaml=None, safe=True, **kwds):
"""
Dumps data into a nicely formatted JSON string.
:param dict data: a dictionary to dump
:param kwds: keywords to pass to json.dumps
:returns: a string with formatted data
:rtype: str
"""
if use_yaml is None:
use_yaml = ALWAYS_DUMP_YAML
if use_yaml:
dumps = yaml.safe_dump if safe else yaml.dump
else:
dumps = json.dumps
kwds.update(indent=4, sort_keys=True)
if not safe:
kwds.update(default=repr)
return dumps(data, **kwds) | [
"Dumps",
"data",
"into",
"a",
"nicely",
"formatted",
"JSON",
"string",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/data_file.py#L9-L28 | [
"def",
"dumps",
"(",
"data",
",",
"use_yaml",
"=",
"None",
",",
"safe",
"=",
"True",
",",
"*",
"*",
"kwds",
")",
":",
"if",
"use_yaml",
"is",
"None",
":",
"use_yaml",
"=",
"ALWAYS_DUMP_YAML",
"if",
"use_yaml",
":",
"dumps",
"=",
"yaml",
".",
"safe_dump",
"if",
"safe",
"else",
"yaml",
".",
"dump",
"else",
":",
"dumps",
"=",
"json",
".",
"dumps",
"kwds",
".",
"update",
"(",
"indent",
"=",
"4",
",",
"sort_keys",
"=",
"True",
")",
"if",
"not",
"safe",
":",
"kwds",
".",
"update",
"(",
"default",
"=",
"repr",
")",
"return",
"dumps",
"(",
"data",
",",
"*",
"*",
"kwds",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | dump | Dumps data as nicely formatted JSON string to a file or file handle
:param dict data: a dictionary to dump
:param file: a filename or file handle to write to
:param kwds: keywords to pass to json.dump | bibliopixel/util/data_file.py | def dump(data, file=sys.stdout, use_yaml=None, **kwds):
"""
Dumps data as nicely formatted JSON string to a file or file handle
:param dict data: a dictionary to dump
:param file: a filename or file handle to write to
:param kwds: keywords to pass to json.dump
"""
if use_yaml is None:
use_yaml = ALWAYS_DUMP_YAML
def dump(fp):
if use_yaml:
yaml.safe_dump(data, stream=fp, **kwds)
else:
json.dump(data, fp, indent=4, sort_keys=True, **kwds)
if not isinstance(file, str):
return dump(file)
if os.path.isabs(file):
parent = os.path.dirname(file)
if not os.path.exists(parent):
os.makedirs(parent, exist_ok=True)
with open(file, 'w') as fp:
return dump(fp) | def dump(data, file=sys.stdout, use_yaml=None, **kwds):
"""
Dumps data as nicely formatted JSON string to a file or file handle
:param dict data: a dictionary to dump
:param file: a filename or file handle to write to
:param kwds: keywords to pass to json.dump
"""
if use_yaml is None:
use_yaml = ALWAYS_DUMP_YAML
def dump(fp):
if use_yaml:
yaml.safe_dump(data, stream=fp, **kwds)
else:
json.dump(data, fp, indent=4, sort_keys=True, **kwds)
if not isinstance(file, str):
return dump(file)
if os.path.isabs(file):
parent = os.path.dirname(file)
if not os.path.exists(parent):
os.makedirs(parent, exist_ok=True)
with open(file, 'w') as fp:
return dump(fp) | [
"Dumps",
"data",
"as",
"nicely",
"formatted",
"JSON",
"string",
"to",
"a",
"file",
"or",
"file",
"handle"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/data_file.py#L31-L57 | [
"def",
"dump",
"(",
"data",
",",
"file",
"=",
"sys",
".",
"stdout",
",",
"use_yaml",
"=",
"None",
",",
"*",
"*",
"kwds",
")",
":",
"if",
"use_yaml",
"is",
"None",
":",
"use_yaml",
"=",
"ALWAYS_DUMP_YAML",
"def",
"dump",
"(",
"fp",
")",
":",
"if",
"use_yaml",
":",
"yaml",
".",
"safe_dump",
"(",
"data",
",",
"stream",
"=",
"fp",
",",
"*",
"*",
"kwds",
")",
"else",
":",
"json",
".",
"dump",
"(",
"data",
",",
"fp",
",",
"indent",
"=",
"4",
",",
"sort_keys",
"=",
"True",
",",
"*",
"*",
"kwds",
")",
"if",
"not",
"isinstance",
"(",
"file",
",",
"str",
")",
":",
"return",
"dump",
"(",
"file",
")",
"if",
"os",
".",
"path",
".",
"isabs",
"(",
"file",
")",
":",
"parent",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"file",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"parent",
")",
":",
"os",
".",
"makedirs",
"(",
"parent",
",",
"exist_ok",
"=",
"True",
")",
"with",
"open",
"(",
"file",
",",
"'w'",
")",
"as",
"fp",
":",
"return",
"dump",
"(",
"fp",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | load | Loads not only JSON files but also YAML files ending in .yml.
:param file: a filename or file handle to read from
:returns: the data loaded from the JSON or YAML file
:rtype: dict | bibliopixel/util/data_file.py | def load(file, use_yaml=None):
"""
Loads not only JSON files but also YAML files ending in .yml.
:param file: a filename or file handle to read from
:returns: the data loaded from the JSON or YAML file
:rtype: dict
"""
if isinstance(file, str):
fp = open(file)
filename = file
else:
fp = file
filename = getattr(fp, 'name', '')
try:
return loads(fp.read(), use_yaml, filename)
except Exception as e:
e.args = ('There was a error in the data file', filename) + e.args
raise | def load(file, use_yaml=None):
"""
Loads not only JSON files but also YAML files ending in .yml.
:param file: a filename or file handle to read from
:returns: the data loaded from the JSON or YAML file
:rtype: dict
"""
if isinstance(file, str):
fp = open(file)
filename = file
else:
fp = file
filename = getattr(fp, 'name', '')
try:
return loads(fp.read(), use_yaml, filename)
except Exception as e:
e.args = ('There was a error in the data file', filename) + e.args
raise | [
"Loads",
"not",
"only",
"JSON",
"files",
"but",
"also",
"YAML",
"files",
"ending",
"in",
".",
"yml",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/data_file.py#L79-L99 | [
"def",
"load",
"(",
"file",
",",
"use_yaml",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"file",
",",
"str",
")",
":",
"fp",
"=",
"open",
"(",
"file",
")",
"filename",
"=",
"file",
"else",
":",
"fp",
"=",
"file",
"filename",
"=",
"getattr",
"(",
"fp",
",",
"'name'",
",",
"''",
")",
"try",
":",
"return",
"loads",
"(",
"fp",
".",
"read",
"(",
")",
",",
"use_yaml",
",",
"filename",
")",
"except",
"Exception",
"as",
"e",
":",
"e",
".",
"args",
"=",
"(",
"'There was a error in the data file'",
",",
"filename",
")",
"+",
"e",
".",
"args",
"raise"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | load_if | Load either a filename, or a string representation of yml/json. | bibliopixel/util/data_file.py | def load_if(s):
"""Load either a filename, or a string representation of yml/json."""
is_data_file = s.endswith('.json') or s.endswith('.yml')
return load(s) if is_data_file else loads(s) | def load_if(s):
"""Load either a filename, or a string representation of yml/json."""
is_data_file = s.endswith('.json') or s.endswith('.yml')
return load(s) if is_data_file else loads(s) | [
"Load",
"either",
"a",
"filename",
"or",
"a",
"string",
"representation",
"of",
"yml",
"/",
"json",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/data_file.py#L102-L105 | [
"def",
"load_if",
"(",
"s",
")",
":",
"is_data_file",
"=",
"s",
".",
"endswith",
"(",
"'.json'",
")",
"or",
"s",
".",
"endswith",
"(",
"'.yml'",
")",
"return",
"load",
"(",
"s",
")",
"if",
"is_data_file",
"else",
"loads",
"(",
"s",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | adapt_animation_layout | Adapt the setter in an animation's layout so that Strip animations can run
on on Matrix, Cube, or Circle layout, and Matrix or Cube animations can run
on a Strip layout. | bibliopixel/animation/adaptor.py | def adapt_animation_layout(animation):
"""
Adapt the setter in an animation's layout so that Strip animations can run
on on Matrix, Cube, or Circle layout, and Matrix or Cube animations can run
on a Strip layout.
"""
layout = animation.layout
required = getattr(animation, 'LAYOUT_CLASS', None)
if not required or isinstance(layout, required):
return
msg = LAYOUT_WARNING % (
type(animation).__name__, required.__name__, type(layout).__name__)
setter = layout.set
adaptor = None
if required is strip.Strip:
if isinstance(layout, matrix.Matrix):
width = layout.width
def adaptor(pixel, color=None):
y, x = divmod(pixel, width)
setter(x, y, color or BLACK)
elif isinstance(layout, cube.Cube):
lx, ly = layout.x, layout.y
def adaptor(pixel, color=None):
yz, x = divmod(pixel, lx)
z, y = divmod(yz, ly)
setter(x, y, z, color or BLACK)
elif isinstance(layout, circle.Circle):
def adaptor(pixel, color=None):
layout._set_base(pixel, color or BLACK)
elif required is matrix.Matrix:
if isinstance(layout, strip.Strip):
width = animation.width
def adaptor(x, y, color=None):
setter(x + y * width, color or BLACK)
if not adaptor:
raise ValueError(msg)
log.warning(msg)
animation.layout.set = adaptor | def adapt_animation_layout(animation):
"""
Adapt the setter in an animation's layout so that Strip animations can run
on on Matrix, Cube, or Circle layout, and Matrix or Cube animations can run
on a Strip layout.
"""
layout = animation.layout
required = getattr(animation, 'LAYOUT_CLASS', None)
if not required or isinstance(layout, required):
return
msg = LAYOUT_WARNING % (
type(animation).__name__, required.__name__, type(layout).__name__)
setter = layout.set
adaptor = None
if required is strip.Strip:
if isinstance(layout, matrix.Matrix):
width = layout.width
def adaptor(pixel, color=None):
y, x = divmod(pixel, width)
setter(x, y, color or BLACK)
elif isinstance(layout, cube.Cube):
lx, ly = layout.x, layout.y
def adaptor(pixel, color=None):
yz, x = divmod(pixel, lx)
z, y = divmod(yz, ly)
setter(x, y, z, color or BLACK)
elif isinstance(layout, circle.Circle):
def adaptor(pixel, color=None):
layout._set_base(pixel, color or BLACK)
elif required is matrix.Matrix:
if isinstance(layout, strip.Strip):
width = animation.width
def adaptor(x, y, color=None):
setter(x + y * width, color or BLACK)
if not adaptor:
raise ValueError(msg)
log.warning(msg)
animation.layout.set = adaptor | [
"Adapt",
"the",
"setter",
"in",
"an",
"animation",
"s",
"layout",
"so",
"that",
"Strip",
"animations",
"can",
"run",
"on",
"on",
"Matrix",
"Cube",
"or",
"Circle",
"layout",
"and",
"Matrix",
"or",
"Cube",
"animations",
"can",
"run",
"on",
"a",
"Strip",
"layout",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/animation/adaptor.py#L13-L63 | [
"def",
"adapt_animation_layout",
"(",
"animation",
")",
":",
"layout",
"=",
"animation",
".",
"layout",
"required",
"=",
"getattr",
"(",
"animation",
",",
"'LAYOUT_CLASS'",
",",
"None",
")",
"if",
"not",
"required",
"or",
"isinstance",
"(",
"layout",
",",
"required",
")",
":",
"return",
"msg",
"=",
"LAYOUT_WARNING",
"%",
"(",
"type",
"(",
"animation",
")",
".",
"__name__",
",",
"required",
".",
"__name__",
",",
"type",
"(",
"layout",
")",
".",
"__name__",
")",
"setter",
"=",
"layout",
".",
"set",
"adaptor",
"=",
"None",
"if",
"required",
"is",
"strip",
".",
"Strip",
":",
"if",
"isinstance",
"(",
"layout",
",",
"matrix",
".",
"Matrix",
")",
":",
"width",
"=",
"layout",
".",
"width",
"def",
"adaptor",
"(",
"pixel",
",",
"color",
"=",
"None",
")",
":",
"y",
",",
"x",
"=",
"divmod",
"(",
"pixel",
",",
"width",
")",
"setter",
"(",
"x",
",",
"y",
",",
"color",
"or",
"BLACK",
")",
"elif",
"isinstance",
"(",
"layout",
",",
"cube",
".",
"Cube",
")",
":",
"lx",
",",
"ly",
"=",
"layout",
".",
"x",
",",
"layout",
".",
"y",
"def",
"adaptor",
"(",
"pixel",
",",
"color",
"=",
"None",
")",
":",
"yz",
",",
"x",
"=",
"divmod",
"(",
"pixel",
",",
"lx",
")",
"z",
",",
"y",
"=",
"divmod",
"(",
"yz",
",",
"ly",
")",
"setter",
"(",
"x",
",",
"y",
",",
"z",
",",
"color",
"or",
"BLACK",
")",
"elif",
"isinstance",
"(",
"layout",
",",
"circle",
".",
"Circle",
")",
":",
"def",
"adaptor",
"(",
"pixel",
",",
"color",
"=",
"None",
")",
":",
"layout",
".",
"_set_base",
"(",
"pixel",
",",
"color",
"or",
"BLACK",
")",
"elif",
"required",
"is",
"matrix",
".",
"Matrix",
":",
"if",
"isinstance",
"(",
"layout",
",",
"strip",
".",
"Strip",
")",
":",
"width",
"=",
"animation",
".",
"width",
"def",
"adaptor",
"(",
"x",
",",
"y",
",",
"color",
"=",
"None",
")",
":",
"setter",
"(",
"x",
"+",
"y",
"*",
"width",
",",
"color",
"or",
"BLACK",
")",
"if",
"not",
"adaptor",
":",
"raise",
"ValueError",
"(",
"msg",
")",
"log",
".",
"warning",
"(",
"msg",
")",
"animation",
".",
"layout",
".",
"set",
"=",
"adaptor"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | hsv2rgb_raw | Converts an HSV tuple to RGB. Intended for internal use.
You should use hsv2rgb_spectrum or hsv2rgb_rainbow instead. | bibliopixel/colors/conversions.py | def hsv2rgb_raw(hsv):
"""
Converts an HSV tuple to RGB. Intended for internal use.
You should use hsv2rgb_spectrum or hsv2rgb_rainbow instead.
"""
HSV_SECTION_3 = 0x40
h, s, v = hsv
# The brightness floor is minimum number that all of
# R, G, and B will be set to.
invsat = 255 - s
brightness_floor = (v * invsat) // 256
# The color amplitude is the maximum amount of R, G, and B
# that will be added on top of the brightness_floor to
# create the specific hue desired.
color_amplitude = v - brightness_floor
# figure out which section of the hue wheel we're in,
# and how far offset we are within that section
section = h // HSV_SECTION_3 # 0..2
offset = h % HSV_SECTION_3 # 0..63
rampup = offset
rampdown = (HSV_SECTION_3 - 1) - offset
# compute color-amplitude-scaled-down versions of rampup and rampdown
rampup_amp_adj = (rampup * color_amplitude) // (256 // 4)
rampdown_amp_adj = (rampdown * color_amplitude) // (256 // 4)
# add brightness_floor offset to everything
rampup_adj_with_floor = rampup_amp_adj + brightness_floor
rampdown_adj_with_floor = rampdown_amp_adj + brightness_floor
r, g, b = (0, 0, 0)
if section:
if section == 1:
# section 1: 0x40..0x7F
r = brightness_floor
g = rampdown_adj_with_floor
b = rampup_adj_with_floor
else:
# section 2; 0x80..0xBF
r = rampup_adj_with_floor
g = brightness_floor
b = rampdown_adj_with_floor
else:
# section 0: 0x00..0x3F
r = rampdown_adj_with_floor
g = rampup_adj_with_floor
b = brightness_floor
return (r, g, b) | def hsv2rgb_raw(hsv):
"""
Converts an HSV tuple to RGB. Intended for internal use.
You should use hsv2rgb_spectrum or hsv2rgb_rainbow instead.
"""
HSV_SECTION_3 = 0x40
h, s, v = hsv
# The brightness floor is minimum number that all of
# R, G, and B will be set to.
invsat = 255 - s
brightness_floor = (v * invsat) // 256
# The color amplitude is the maximum amount of R, G, and B
# that will be added on top of the brightness_floor to
# create the specific hue desired.
color_amplitude = v - brightness_floor
# figure out which section of the hue wheel we're in,
# and how far offset we are within that section
section = h // HSV_SECTION_3 # 0..2
offset = h % HSV_SECTION_3 # 0..63
rampup = offset
rampdown = (HSV_SECTION_3 - 1) - offset
# compute color-amplitude-scaled-down versions of rampup and rampdown
rampup_amp_adj = (rampup * color_amplitude) // (256 // 4)
rampdown_amp_adj = (rampdown * color_amplitude) // (256 // 4)
# add brightness_floor offset to everything
rampup_adj_with_floor = rampup_amp_adj + brightness_floor
rampdown_adj_with_floor = rampdown_amp_adj + brightness_floor
r, g, b = (0, 0, 0)
if section:
if section == 1:
# section 1: 0x40..0x7F
r = brightness_floor
g = rampdown_adj_with_floor
b = rampup_adj_with_floor
else:
# section 2; 0x80..0xBF
r = rampup_adj_with_floor
g = brightness_floor
b = rampdown_adj_with_floor
else:
# section 0: 0x00..0x3F
r = rampdown_adj_with_floor
g = rampup_adj_with_floor
b = brightness_floor
return (r, g, b) | [
"Converts",
"an",
"HSV",
"tuple",
"to",
"RGB",
".",
"Intended",
"for",
"internal",
"use",
".",
"You",
"should",
"use",
"hsv2rgb_spectrum",
"or",
"hsv2rgb_rainbow",
"instead",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/conversions.py#L5-L60 | [
"def",
"hsv2rgb_raw",
"(",
"hsv",
")",
":",
"HSV_SECTION_3",
"=",
"0x40",
"h",
",",
"s",
",",
"v",
"=",
"hsv",
"# The brightness floor is minimum number that all of",
"# R, G, and B will be set to.",
"invsat",
"=",
"255",
"-",
"s",
"brightness_floor",
"=",
"(",
"v",
"*",
"invsat",
")",
"//",
"256",
"# The color amplitude is the maximum amount of R, G, and B",
"# that will be added on top of the brightness_floor to",
"# create the specific hue desired.",
"color_amplitude",
"=",
"v",
"-",
"brightness_floor",
"# figure out which section of the hue wheel we're in,",
"# and how far offset we are within that section",
"section",
"=",
"h",
"//",
"HSV_SECTION_3",
"# 0..2",
"offset",
"=",
"h",
"%",
"HSV_SECTION_3",
"# 0..63",
"rampup",
"=",
"offset",
"rampdown",
"=",
"(",
"HSV_SECTION_3",
"-",
"1",
")",
"-",
"offset",
"# compute color-amplitude-scaled-down versions of rampup and rampdown",
"rampup_amp_adj",
"=",
"(",
"rampup",
"*",
"color_amplitude",
")",
"//",
"(",
"256",
"//",
"4",
")",
"rampdown_amp_adj",
"=",
"(",
"rampdown",
"*",
"color_amplitude",
")",
"//",
"(",
"256",
"//",
"4",
")",
"# add brightness_floor offset to everything",
"rampup_adj_with_floor",
"=",
"rampup_amp_adj",
"+",
"brightness_floor",
"rampdown_adj_with_floor",
"=",
"rampdown_amp_adj",
"+",
"brightness_floor",
"r",
",",
"g",
",",
"b",
"=",
"(",
"0",
",",
"0",
",",
"0",
")",
"if",
"section",
":",
"if",
"section",
"==",
"1",
":",
"# section 1: 0x40..0x7F",
"r",
"=",
"brightness_floor",
"g",
"=",
"rampdown_adj_with_floor",
"b",
"=",
"rampup_adj_with_floor",
"else",
":",
"# section 2; 0x80..0xBF",
"r",
"=",
"rampup_adj_with_floor",
"g",
"=",
"brightness_floor",
"b",
"=",
"rampdown_adj_with_floor",
"else",
":",
"# section 0: 0x00..0x3F",
"r",
"=",
"rampdown_adj_with_floor",
"g",
"=",
"rampup_adj_with_floor",
"b",
"=",
"brightness_floor",
"return",
"(",
"r",
",",
"g",
",",
"b",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | hsv2rgb_spectrum | Generates RGB values from HSV values in line with a typical light
spectrum. | bibliopixel/colors/conversions.py | def hsv2rgb_spectrum(hsv):
"""Generates RGB values from HSV values in line with a typical light
spectrum."""
h, s, v = hsv
return hsv2rgb_raw(((h * 192) >> 8, s, v)) | def hsv2rgb_spectrum(hsv):
"""Generates RGB values from HSV values in line with a typical light
spectrum."""
h, s, v = hsv
return hsv2rgb_raw(((h * 192) >> 8, s, v)) | [
"Generates",
"RGB",
"values",
"from",
"HSV",
"values",
"in",
"line",
"with",
"a",
"typical",
"light",
"spectrum",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/conversions.py#L63-L67 | [
"def",
"hsv2rgb_spectrum",
"(",
"hsv",
")",
":",
"h",
",",
"s",
",",
"v",
"=",
"hsv",
"return",
"hsv2rgb_raw",
"(",
"(",
"(",
"h",
"*",
"192",
")",
">>",
"8",
",",
"s",
",",
"v",
")",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | hsv2rgb_rainbow | Generates RGB values from HSV that have an even visual
distribution. Be careful as this method is only have as fast as
hsv2rgb_spectrum. | bibliopixel/colors/conversions.py | def hsv2rgb_rainbow(hsv):
"""Generates RGB values from HSV that have an even visual
distribution. Be careful as this method is only have as fast as
hsv2rgb_spectrum."""
def nscale8x3_video(r, g, b, scale):
nonzeroscale = 0
if scale != 0:
nonzeroscale = 1
if r != 0:
r = ((r * scale) >> 8) + nonzeroscale
if g != 0:
g = ((g * scale) >> 8) + nonzeroscale
if b != 0:
b = ((b * scale) >> 8) + nonzeroscale
return (r, g, b)
def scale8_video_LEAVING_R1_DIRTY(i, scale):
nonzeroscale = 0
if scale != 0:
nonzeroscale = 1
if i != 0:
i = ((i * scale) >> 8) + nonzeroscale
return i
h, s, v = hsv
offset = h & 0x1F # 0..31
offset8 = offset * 8
third = (offset8 * (256 // 3)) >> 8
r, g, b = (0, 0, 0)
if not (h & 0x80):
if not (h & 0x40):
if not (h & 0x20):
r = 255 - third
g = third
b = 0
else:
r = 171
g = 85 + third
b = 0x00
else:
if not (h & 0x20):
twothirds = (third << 1)
r = 171 - twothirds
g = 171 + third
b = 0
else:
r = 0
g = 255 - third
b = third
else:
if not (h & 0x40):
if not (h & 0x20):
r = 0x00
twothirds = (third << 1)
g = 171 - twothirds
b = 85 + twothirds
else:
r = third
g = 0
b = 255 - third
else:
if not (h & 0x20):
r = 85 + third
g = 0
b = 171 - third
else:
r = 171 + third
g = 0x00
b = 85 - third
if s != 255:
r, g, b = nscale8x3_video(r, g, b, s)
desat = 255 - s
desat = (desat * desat) >> 8
brightness_floor = desat
r = r + brightness_floor
g = g + brightness_floor
b = b + brightness_floor
if v != 255:
v = scale8_video_LEAVING_R1_DIRTY(v, v)
r, g, b = nscale8x3_video(r, g, b, v)
return (r, g, b) | def hsv2rgb_rainbow(hsv):
"""Generates RGB values from HSV that have an even visual
distribution. Be careful as this method is only have as fast as
hsv2rgb_spectrum."""
def nscale8x3_video(r, g, b, scale):
nonzeroscale = 0
if scale != 0:
nonzeroscale = 1
if r != 0:
r = ((r * scale) >> 8) + nonzeroscale
if g != 0:
g = ((g * scale) >> 8) + nonzeroscale
if b != 0:
b = ((b * scale) >> 8) + nonzeroscale
return (r, g, b)
def scale8_video_LEAVING_R1_DIRTY(i, scale):
nonzeroscale = 0
if scale != 0:
nonzeroscale = 1
if i != 0:
i = ((i * scale) >> 8) + nonzeroscale
return i
h, s, v = hsv
offset = h & 0x1F # 0..31
offset8 = offset * 8
third = (offset8 * (256 // 3)) >> 8
r, g, b = (0, 0, 0)
if not (h & 0x80):
if not (h & 0x40):
if not (h & 0x20):
r = 255 - third
g = third
b = 0
else:
r = 171
g = 85 + third
b = 0x00
else:
if not (h & 0x20):
twothirds = (third << 1)
r = 171 - twothirds
g = 171 + third
b = 0
else:
r = 0
g = 255 - third
b = third
else:
if not (h & 0x40):
if not (h & 0x20):
r = 0x00
twothirds = (third << 1)
g = 171 - twothirds
b = 85 + twothirds
else:
r = third
g = 0
b = 255 - third
else:
if not (h & 0x20):
r = 85 + third
g = 0
b = 171 - third
else:
r = 171 + third
g = 0x00
b = 85 - third
if s != 255:
r, g, b = nscale8x3_video(r, g, b, s)
desat = 255 - s
desat = (desat * desat) >> 8
brightness_floor = desat
r = r + brightness_floor
g = g + brightness_floor
b = b + brightness_floor
if v != 255:
v = scale8_video_LEAVING_R1_DIRTY(v, v)
r, g, b = nscale8x3_video(r, g, b, v)
return (r, g, b) | [
"Generates",
"RGB",
"values",
"from",
"HSV",
"that",
"have",
"an",
"even",
"visual",
"distribution",
".",
"Be",
"careful",
"as",
"this",
"method",
"is",
"only",
"have",
"as",
"fast",
"as",
"hsv2rgb_spectrum",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/conversions.py#L70-L155 | [
"def",
"hsv2rgb_rainbow",
"(",
"hsv",
")",
":",
"def",
"nscale8x3_video",
"(",
"r",
",",
"g",
",",
"b",
",",
"scale",
")",
":",
"nonzeroscale",
"=",
"0",
"if",
"scale",
"!=",
"0",
":",
"nonzeroscale",
"=",
"1",
"if",
"r",
"!=",
"0",
":",
"r",
"=",
"(",
"(",
"r",
"*",
"scale",
")",
">>",
"8",
")",
"+",
"nonzeroscale",
"if",
"g",
"!=",
"0",
":",
"g",
"=",
"(",
"(",
"g",
"*",
"scale",
")",
">>",
"8",
")",
"+",
"nonzeroscale",
"if",
"b",
"!=",
"0",
":",
"b",
"=",
"(",
"(",
"b",
"*",
"scale",
")",
">>",
"8",
")",
"+",
"nonzeroscale",
"return",
"(",
"r",
",",
"g",
",",
"b",
")",
"def",
"scale8_video_LEAVING_R1_DIRTY",
"(",
"i",
",",
"scale",
")",
":",
"nonzeroscale",
"=",
"0",
"if",
"scale",
"!=",
"0",
":",
"nonzeroscale",
"=",
"1",
"if",
"i",
"!=",
"0",
":",
"i",
"=",
"(",
"(",
"i",
"*",
"scale",
")",
">>",
"8",
")",
"+",
"nonzeroscale",
"return",
"i",
"h",
",",
"s",
",",
"v",
"=",
"hsv",
"offset",
"=",
"h",
"&",
"0x1F",
"# 0..31",
"offset8",
"=",
"offset",
"*",
"8",
"third",
"=",
"(",
"offset8",
"*",
"(",
"256",
"//",
"3",
")",
")",
">>",
"8",
"r",
",",
"g",
",",
"b",
"=",
"(",
"0",
",",
"0",
",",
"0",
")",
"if",
"not",
"(",
"h",
"&",
"0x80",
")",
":",
"if",
"not",
"(",
"h",
"&",
"0x40",
")",
":",
"if",
"not",
"(",
"h",
"&",
"0x20",
")",
":",
"r",
"=",
"255",
"-",
"third",
"g",
"=",
"third",
"b",
"=",
"0",
"else",
":",
"r",
"=",
"171",
"g",
"=",
"85",
"+",
"third",
"b",
"=",
"0x00",
"else",
":",
"if",
"not",
"(",
"h",
"&",
"0x20",
")",
":",
"twothirds",
"=",
"(",
"third",
"<<",
"1",
")",
"r",
"=",
"171",
"-",
"twothirds",
"g",
"=",
"171",
"+",
"third",
"b",
"=",
"0",
"else",
":",
"r",
"=",
"0",
"g",
"=",
"255",
"-",
"third",
"b",
"=",
"third",
"else",
":",
"if",
"not",
"(",
"h",
"&",
"0x40",
")",
":",
"if",
"not",
"(",
"h",
"&",
"0x20",
")",
":",
"r",
"=",
"0x00",
"twothirds",
"=",
"(",
"third",
"<<",
"1",
")",
"g",
"=",
"171",
"-",
"twothirds",
"b",
"=",
"85",
"+",
"twothirds",
"else",
":",
"r",
"=",
"third",
"g",
"=",
"0",
"b",
"=",
"255",
"-",
"third",
"else",
":",
"if",
"not",
"(",
"h",
"&",
"0x20",
")",
":",
"r",
"=",
"85",
"+",
"third",
"g",
"=",
"0",
"b",
"=",
"171",
"-",
"third",
"else",
":",
"r",
"=",
"171",
"+",
"third",
"g",
"=",
"0x00",
"b",
"=",
"85",
"-",
"third",
"if",
"s",
"!=",
"255",
":",
"r",
",",
"g",
",",
"b",
"=",
"nscale8x3_video",
"(",
"r",
",",
"g",
",",
"b",
",",
"s",
")",
"desat",
"=",
"255",
"-",
"s",
"desat",
"=",
"(",
"desat",
"*",
"desat",
")",
">>",
"8",
"brightness_floor",
"=",
"desat",
"r",
"=",
"r",
"+",
"brightness_floor",
"g",
"=",
"g",
"+",
"brightness_floor",
"b",
"=",
"b",
"+",
"brightness_floor",
"if",
"v",
"!=",
"255",
":",
"v",
"=",
"scale8_video_LEAVING_R1_DIRTY",
"(",
"v",
",",
"v",
")",
"r",
",",
"g",
",",
"b",
"=",
"nscale8x3_video",
"(",
"r",
",",
"g",
",",
"b",
",",
"v",
")",
"return",
"(",
"r",
",",
"g",
",",
"b",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | hsv2rgb_360 | Python default hsv to rgb conversion for when hue values in the
range 0-359 are preferred. Due to requiring float math, this method
is slower than hsv2rgb_rainbow and hsv2rgb_spectrum. | bibliopixel/colors/conversions.py | def hsv2rgb_360(hsv):
"""Python default hsv to rgb conversion for when hue values in the
range 0-359 are preferred. Due to requiring float math, this method
is slower than hsv2rgb_rainbow and hsv2rgb_spectrum."""
h, s, v = hsv
r, g, b = colorsys.hsv_to_rgb(h / 360.0, s, v)
return (int(r * 255.0), int(g * 255.0), int(b * 255.0)) | def hsv2rgb_360(hsv):
"""Python default hsv to rgb conversion for when hue values in the
range 0-359 are preferred. Due to requiring float math, this method
is slower than hsv2rgb_rainbow and hsv2rgb_spectrum."""
h, s, v = hsv
r, g, b = colorsys.hsv_to_rgb(h / 360.0, s, v)
return (int(r * 255.0), int(g * 255.0), int(b * 255.0)) | [
"Python",
"default",
"hsv",
"to",
"rgb",
"conversion",
"for",
"when",
"hue",
"values",
"in",
"the",
"range",
"0",
"-",
"359",
"are",
"preferred",
".",
"Due",
"to",
"requiring",
"float",
"math",
"this",
"method",
"is",
"slower",
"than",
"hsv2rgb_rainbow",
"and",
"hsv2rgb_spectrum",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/conversions.py#L158-L166 | [
"def",
"hsv2rgb_360",
"(",
"hsv",
")",
":",
"h",
",",
"s",
",",
"v",
"=",
"hsv",
"r",
",",
"g",
",",
"b",
"=",
"colorsys",
".",
"hsv_to_rgb",
"(",
"h",
"/",
"360.0",
",",
"s",
",",
"v",
")",
"return",
"(",
"int",
"(",
"r",
"*",
"255.0",
")",
",",
"int",
"(",
"g",
"*",
"255.0",
")",
",",
"int",
"(",
"b",
"*",
"255.0",
")",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | color_cmp | Order colors by hue, saturation and value, in that order.
Returns -1 if a < b, 0 if a == b and 1 if a < b. | bibliopixel/colors/conversions.py | def color_cmp(a, b):
"""Order colors by hue, saturation and value, in that order.
Returns -1 if a < b, 0 if a == b and 1 if a < b.
"""
if a == b:
return 0
a, b = rgb_to_hsv(a), rgb_to_hsv(b)
return -1 if a < b else 1 | def color_cmp(a, b):
"""Order colors by hue, saturation and value, in that order.
Returns -1 if a < b, 0 if a == b and 1 if a < b.
"""
if a == b:
return 0
a, b = rgb_to_hsv(a), rgb_to_hsv(b)
return -1 if a < b else 1 | [
"Order",
"colors",
"by",
"hue",
"saturation",
"and",
"value",
"in",
"that",
"order",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/conversions.py#L239-L248 | [
"def",
"color_cmp",
"(",
"a",
",",
"b",
")",
":",
"if",
"a",
"==",
"b",
":",
"return",
"0",
"a",
",",
"b",
"=",
"rgb_to_hsv",
"(",
"a",
")",
",",
"rgb_to_hsv",
"(",
"b",
")",
"return",
"-",
"1",
"if",
"a",
"<",
"b",
"else",
"1"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | ServerCache.get_server | Get a new or existing server for this key.
:param int key: key for the server to use | bibliopixel/util/server_cache.py | def get_server(self, key, **kwds):
"""
Get a new or existing server for this key.
:param int key: key for the server to use
"""
kwds = dict(self.kwds, **kwds)
server = self.servers.get(key)
if server:
# Make sure it's the right server.
server.check_keywords(self.constructor, kwds)
else:
# Make a new server
server = _CachedServer(self.constructor, key, kwds)
self.servers[key] = server
return server | def get_server(self, key, **kwds):
"""
Get a new or existing server for this key.
:param int key: key for the server to use
"""
kwds = dict(self.kwds, **kwds)
server = self.servers.get(key)
if server:
# Make sure it's the right server.
server.check_keywords(self.constructor, kwds)
else:
# Make a new server
server = _CachedServer(self.constructor, key, kwds)
self.servers[key] = server
return server | [
"Get",
"a",
"new",
"or",
"existing",
"server",
"for",
"this",
"key",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/server_cache.py#L44-L60 | [
"def",
"get_server",
"(",
"self",
",",
"key",
",",
"*",
"*",
"kwds",
")",
":",
"kwds",
"=",
"dict",
"(",
"self",
".",
"kwds",
",",
"*",
"*",
"kwds",
")",
"server",
"=",
"self",
".",
"servers",
".",
"get",
"(",
"key",
")",
"if",
"server",
":",
"# Make sure it's the right server.",
"server",
".",
"check_keywords",
"(",
"self",
".",
"constructor",
",",
"kwds",
")",
"else",
":",
"# Make a new server",
"server",
"=",
"_CachedServer",
"(",
"self",
".",
"constructor",
",",
"key",
",",
"kwds",
")",
"self",
".",
"servers",
"[",
"key",
"]",
"=",
"server",
"return",
"server"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | set_one | Set one section in a Project description | bibliopixel/builder/sections.py | def set_one(desc, name, value):
"""Set one section in a Project description"""
old_value = desc.get(name)
if old_value is None:
raise KeyError('No section "%s"' % name)
if value is None:
value = type(old_value)()
elif name in CLASS_SECTIONS:
if isinstance(value, str):
value = {'typename': aliases.resolve(value)}
elif isinstance(value, type):
value = {'typename': class_name.class_name(value)}
elif not isinstance(value, dict):
raise TypeError('Expected dict, str or type, got "%s"' % value)
typename = value.get('typename')
if typename:
s = 's' if name == 'driver' else ''
path = 'bibliopixel.' + name + s
importer.import_symbol(typename, path)
elif name == 'shape':
if not isinstance(value, (list, int, tuple, str)):
raise TypeError('Expected shape, got "%s"' % value)
elif type(old_value) is not type(value):
raise TypeError('Expected %s but got "%s" of type %s' %
(type(old_value), value, type(value)))
desc[name] = value | def set_one(desc, name, value):
"""Set one section in a Project description"""
old_value = desc.get(name)
if old_value is None:
raise KeyError('No section "%s"' % name)
if value is None:
value = type(old_value)()
elif name in CLASS_SECTIONS:
if isinstance(value, str):
value = {'typename': aliases.resolve(value)}
elif isinstance(value, type):
value = {'typename': class_name.class_name(value)}
elif not isinstance(value, dict):
raise TypeError('Expected dict, str or type, got "%s"' % value)
typename = value.get('typename')
if typename:
s = 's' if name == 'driver' else ''
path = 'bibliopixel.' + name + s
importer.import_symbol(typename, path)
elif name == 'shape':
if not isinstance(value, (list, int, tuple, str)):
raise TypeError('Expected shape, got "%s"' % value)
elif type(old_value) is not type(value):
raise TypeError('Expected %s but got "%s" of type %s' %
(type(old_value), value, type(value)))
desc[name] = value | [
"Set",
"one",
"section",
"in",
"a",
"Project",
"description"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/builder/sections.py#L8-L39 | [
"def",
"set_one",
"(",
"desc",
",",
"name",
",",
"value",
")",
":",
"old_value",
"=",
"desc",
".",
"get",
"(",
"name",
")",
"if",
"old_value",
"is",
"None",
":",
"raise",
"KeyError",
"(",
"'No section \"%s\"'",
"%",
"name",
")",
"if",
"value",
"is",
"None",
":",
"value",
"=",
"type",
"(",
"old_value",
")",
"(",
")",
"elif",
"name",
"in",
"CLASS_SECTIONS",
":",
"if",
"isinstance",
"(",
"value",
",",
"str",
")",
":",
"value",
"=",
"{",
"'typename'",
":",
"aliases",
".",
"resolve",
"(",
"value",
")",
"}",
"elif",
"isinstance",
"(",
"value",
",",
"type",
")",
":",
"value",
"=",
"{",
"'typename'",
":",
"class_name",
".",
"class_name",
"(",
"value",
")",
"}",
"elif",
"not",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"raise",
"TypeError",
"(",
"'Expected dict, str or type, got \"%s\"'",
"%",
"value",
")",
"typename",
"=",
"value",
".",
"get",
"(",
"'typename'",
")",
"if",
"typename",
":",
"s",
"=",
"'s'",
"if",
"name",
"==",
"'driver'",
"else",
"''",
"path",
"=",
"'bibliopixel.'",
"+",
"name",
"+",
"s",
"importer",
".",
"import_symbol",
"(",
"typename",
",",
"path",
")",
"elif",
"name",
"==",
"'shape'",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"(",
"list",
",",
"int",
",",
"tuple",
",",
"str",
")",
")",
":",
"raise",
"TypeError",
"(",
"'Expected shape, got \"%s\"'",
"%",
"value",
")",
"elif",
"type",
"(",
"old_value",
")",
"is",
"not",
"type",
"(",
"value",
")",
":",
"raise",
"TypeError",
"(",
"'Expected %s but got \"%s\" of type %s'",
"%",
"(",
"type",
"(",
"old_value",
")",
",",
"value",
",",
"type",
"(",
"value",
")",
")",
")",
"desc",
"[",
"name",
"]",
"=",
"value"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | update | Update sections in a Project description | bibliopixel/builder/sections.py | def update(desc, other=None, **kwds):
"""Update sections in a Project description"""
other = other and _as_dict(other) or {}
for i in other, kwds:
for k, v in i.items():
if isinstance(v, dict):
# Only for dicts, merge instead of overwriting
old_v = desc[k]
for k2, v2 in v.items():
if v2 is None:
old_v.pop(k2, None)
else:
old_v[k2] = v2
else:
set_one(desc, k, v) | def update(desc, other=None, **kwds):
"""Update sections in a Project description"""
other = other and _as_dict(other) or {}
for i in other, kwds:
for k, v in i.items():
if isinstance(v, dict):
# Only for dicts, merge instead of overwriting
old_v = desc[k]
for k2, v2 in v.items():
if v2 is None:
old_v.pop(k2, None)
else:
old_v[k2] = v2
else:
set_one(desc, k, v) | [
"Update",
"sections",
"in",
"a",
"Project",
"description"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/builder/sections.py#L42-L56 | [
"def",
"update",
"(",
"desc",
",",
"other",
"=",
"None",
",",
"*",
"*",
"kwds",
")",
":",
"other",
"=",
"other",
"and",
"_as_dict",
"(",
"other",
")",
"or",
"{",
"}",
"for",
"i",
"in",
"other",
",",
"kwds",
":",
"for",
"k",
",",
"v",
"in",
"i",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"v",
",",
"dict",
")",
":",
"# Only for dicts, merge instead of overwriting",
"old_v",
"=",
"desc",
"[",
"k",
"]",
"for",
"k2",
",",
"v2",
"in",
"v",
".",
"items",
"(",
")",
":",
"if",
"v2",
"is",
"None",
":",
"old_v",
".",
"pop",
"(",
"k2",
",",
"None",
")",
"else",
":",
"old_v",
"[",
"k2",
"]",
"=",
"v2",
"else",
":",
"set_one",
"(",
"desc",
",",
"k",
",",
"v",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | name_to_color | :param str name: a string identifying a color. It might be a color name
from the two lists of color names, juce and classic; or
it might be a list of numeric r, g, b values separated by
commas.
:returns: a color as an RGB 3-tuple | bibliopixel/colors/names.py | def name_to_color(name):
"""
:param str name: a string identifying a color. It might be a color name
from the two lists of color names, juce and classic; or
it might be a list of numeric r, g, b values separated by
commas.
:returns: a color as an RGB 3-tuple
"""
def to_color(name):
name = name.lower()
if ',' in name:
if name.startswith('(') and name.endswith(')'):
name = name[1:-1]
if name.startswith('[') and name.endswith(']'):
name = name[1:-1]
r, g, b = name.split(',')
return _from_number(r), _from_number(g), _from_number(b)
try:
n = _from_number(name)
except:
color = tables.get_color(name)
if color:
return color
raise ValueError
return tables.to_triplet(n)
try:
color = to_color(name)
except:
raise ValueError('Unknown color name %s' % str(name))
if not all(0 <= i <= 255 for i in color):
raise ValueError('Component out of range: %s' % color)
return color | def name_to_color(name):
"""
:param str name: a string identifying a color. It might be a color name
from the two lists of color names, juce and classic; or
it might be a list of numeric r, g, b values separated by
commas.
:returns: a color as an RGB 3-tuple
"""
def to_color(name):
name = name.lower()
if ',' in name:
if name.startswith('(') and name.endswith(')'):
name = name[1:-1]
if name.startswith('[') and name.endswith(']'):
name = name[1:-1]
r, g, b = name.split(',')
return _from_number(r), _from_number(g), _from_number(b)
try:
n = _from_number(name)
except:
color = tables.get_color(name)
if color:
return color
raise ValueError
return tables.to_triplet(n)
try:
color = to_color(name)
except:
raise ValueError('Unknown color name %s' % str(name))
if not all(0 <= i <= 255 for i in color):
raise ValueError('Component out of range: %s' % color)
return color | [
":",
"param",
"str",
"name",
":",
"a",
"string",
"identifying",
"a",
"color",
".",
"It",
"might",
"be",
"a",
"color",
"name",
"from",
"the",
"two",
"lists",
"of",
"color",
"names",
"juce",
"and",
"classic",
";",
"or",
"it",
"might",
"be",
"a",
"list",
"of",
"numeric",
"r",
"g",
"b",
"values",
"separated",
"by",
"commas",
".",
":",
"returns",
":",
"a",
"color",
"as",
"an",
"RGB",
"3",
"-",
"tuple"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/names.py#L10-L47 | [
"def",
"name_to_color",
"(",
"name",
")",
":",
"def",
"to_color",
"(",
"name",
")",
":",
"name",
"=",
"name",
".",
"lower",
"(",
")",
"if",
"','",
"in",
"name",
":",
"if",
"name",
".",
"startswith",
"(",
"'('",
")",
"and",
"name",
".",
"endswith",
"(",
"')'",
")",
":",
"name",
"=",
"name",
"[",
"1",
":",
"-",
"1",
"]",
"if",
"name",
".",
"startswith",
"(",
"'['",
")",
"and",
"name",
".",
"endswith",
"(",
"']'",
")",
":",
"name",
"=",
"name",
"[",
"1",
":",
"-",
"1",
"]",
"r",
",",
"g",
",",
"b",
"=",
"name",
".",
"split",
"(",
"','",
")",
"return",
"_from_number",
"(",
"r",
")",
",",
"_from_number",
"(",
"g",
")",
",",
"_from_number",
"(",
"b",
")",
"try",
":",
"n",
"=",
"_from_number",
"(",
"name",
")",
"except",
":",
"color",
"=",
"tables",
".",
"get_color",
"(",
"name",
")",
"if",
"color",
":",
"return",
"color",
"raise",
"ValueError",
"return",
"tables",
".",
"to_triplet",
"(",
"n",
")",
"try",
":",
"color",
"=",
"to_color",
"(",
"name",
")",
"except",
":",
"raise",
"ValueError",
"(",
"'Unknown color name %s'",
"%",
"str",
"(",
"name",
")",
")",
"if",
"not",
"all",
"(",
"0",
"<=",
"i",
"<=",
"255",
"for",
"i",
"in",
"color",
")",
":",
"raise",
"ValueError",
"(",
"'Component out of range: %s'",
"%",
"color",
")",
"return",
"color"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | color_to_name | :param tuple color: an RGB 3-tuple of integer colors
:returns: a string name for this color
``name_to_color(color_to_name(c)) == c`` is guaranteed to be true (but the
reverse is not true, because name_to_color is a many-to-one function). | bibliopixel/colors/names.py | def color_to_name(color, use_hex=False):
"""
:param tuple color: an RGB 3-tuple of integer colors
:returns: a string name for this color
``name_to_color(color_to_name(c)) == c`` is guaranteed to be true (but the
reverse is not true, because name_to_color is a many-to-one function).
"""
if isinstance(color, list):
color = tuple(color)
elif not isinstance(color, tuple):
raise ValueError('Not a color')
if use_hex:
return '#%02x%02x%02x' % color
return tables.get_name(color) or str(color) | def color_to_name(color, use_hex=False):
"""
:param tuple color: an RGB 3-tuple of integer colors
:returns: a string name for this color
``name_to_color(color_to_name(c)) == c`` is guaranteed to be true (but the
reverse is not true, because name_to_color is a many-to-one function).
"""
if isinstance(color, list):
color = tuple(color)
elif not isinstance(color, tuple):
raise ValueError('Not a color')
if use_hex:
return '#%02x%02x%02x' % color
return tables.get_name(color) or str(color) | [
":",
"param",
"tuple",
"color",
":",
"an",
"RGB",
"3",
"-",
"tuple",
"of",
"integer",
"colors",
":",
"returns",
":",
"a",
"string",
"name",
"for",
"this",
"color"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/names.py#L50-L66 | [
"def",
"color_to_name",
"(",
"color",
",",
"use_hex",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"color",
",",
"list",
")",
":",
"color",
"=",
"tuple",
"(",
"color",
")",
"elif",
"not",
"isinstance",
"(",
"color",
",",
"tuple",
")",
":",
"raise",
"ValueError",
"(",
"'Not a color'",
")",
"if",
"use_hex",
":",
"return",
"'#%02x%02x%02x'",
"%",
"color",
"return",
"tables",
".",
"get_name",
"(",
"color",
")",
"or",
"str",
"(",
"color",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | toggle | Toggle back and forth between a name and a tuple representation.
:param str s: a string which is either a text name, or a tuple-string:
a string with three numbers separated by commas
:returns: if the string was a text name, return a tuple. If it's a
tuple-string and it corresponds to a text name, return the text
name, else return the original tuple-string. | bibliopixel/colors/names.py | def toggle(s):
"""
Toggle back and forth between a name and a tuple representation.
:param str s: a string which is either a text name, or a tuple-string:
a string with three numbers separated by commas
:returns: if the string was a text name, return a tuple. If it's a
tuple-string and it corresponds to a text name, return the text
name, else return the original tuple-string.
"""
is_numeric = ',' in s or s.startswith('0x') or s.startswith('#')
c = name_to_color(s)
return color_to_name(c) if is_numeric else str(c) | def toggle(s):
"""
Toggle back and forth between a name and a tuple representation.
:param str s: a string which is either a text name, or a tuple-string:
a string with three numbers separated by commas
:returns: if the string was a text name, return a tuple. If it's a
tuple-string and it corresponds to a text name, return the text
name, else return the original tuple-string.
"""
is_numeric = ',' in s or s.startswith('0x') or s.startswith('#')
c = name_to_color(s)
return color_to_name(c) if is_numeric else str(c) | [
"Toggle",
"back",
"and",
"forth",
"between",
"a",
"name",
"and",
"a",
"tuple",
"representation",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/names.py#L69-L82 | [
"def",
"toggle",
"(",
"s",
")",
":",
"is_numeric",
"=",
"','",
"in",
"s",
"or",
"s",
".",
"startswith",
"(",
"'0x'",
")",
"or",
"s",
".",
"startswith",
"(",
"'#'",
")",
"c",
"=",
"name_to_color",
"(",
"s",
")",
"return",
"color_to_name",
"(",
"c",
")",
"if",
"is_numeric",
"else",
"str",
"(",
"c",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | to_color | Try to coerce the argument into a color - a 3-tuple of numbers- | bibliopixel/colors/names.py | def to_color(c):
"""Try to coerce the argument into a color - a 3-tuple of numbers-"""
if isinstance(c, numbers.Number):
return c, c, c
if not c:
raise ValueError('Cannot create color from empty "%s"' % c)
if isinstance(c, str):
return name_to_color(c)
if isinstance(c, list):
c = tuple(c)
if isinstance(c, tuple):
if len(c) > 3:
return c[:3]
while len(c) < 3:
c += (c[-1],)
return c
raise ValueError('Cannot create color from "%s"' % c) | def to_color(c):
"""Try to coerce the argument into a color - a 3-tuple of numbers-"""
if isinstance(c, numbers.Number):
return c, c, c
if not c:
raise ValueError('Cannot create color from empty "%s"' % c)
if isinstance(c, str):
return name_to_color(c)
if isinstance(c, list):
c = tuple(c)
if isinstance(c, tuple):
if len(c) > 3:
return c[:3]
while len(c) < 3:
c += (c[-1],)
return c
raise ValueError('Cannot create color from "%s"' % c) | [
"Try",
"to",
"coerce",
"the",
"argument",
"into",
"a",
"color",
"-",
"a",
"3",
"-",
"tuple",
"of",
"numbers",
"-"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/colors/names.py#L94-L115 | [
"def",
"to_color",
"(",
"c",
")",
":",
"if",
"isinstance",
"(",
"c",
",",
"numbers",
".",
"Number",
")",
":",
"return",
"c",
",",
"c",
",",
"c",
"if",
"not",
"c",
":",
"raise",
"ValueError",
"(",
"'Cannot create color from empty \"%s\"'",
"%",
"c",
")",
"if",
"isinstance",
"(",
"c",
",",
"str",
")",
":",
"return",
"name_to_color",
"(",
"c",
")",
"if",
"isinstance",
"(",
"c",
",",
"list",
")",
":",
"c",
"=",
"tuple",
"(",
"c",
")",
"if",
"isinstance",
"(",
"c",
",",
"tuple",
")",
":",
"if",
"len",
"(",
"c",
")",
">",
"3",
":",
"return",
"c",
"[",
":",
"3",
"]",
"while",
"len",
"(",
"c",
")",
"<",
"3",
":",
"c",
"+=",
"(",
"c",
"[",
"-",
"1",
"]",
",",
")",
"return",
"c",
"raise",
"ValueError",
"(",
"'Cannot create color from \"%s\"'",
"%",
"c",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Receiver.step | This may seem silly, but on a Receiver step() need not do anything.
Instead, receive the data on the receive thread and set it on the buffer
then call self._hold_for_data.set() | bibliopixel/animation/receiver.py | def step(self, amt=1):
"""
This may seem silly, but on a Receiver step() need not do anything.
Instead, receive the data on the receive thread and set it on the buffer
then call self._hold_for_data.set()
"""
if not self._stop_event.isSet():
self._hold_for_data.wait()
self._hold_for_data.clear() | def step(self, amt=1):
"""
This may seem silly, but on a Receiver step() need not do anything.
Instead, receive the data on the receive thread and set it on the buffer
then call self._hold_for_data.set()
"""
if not self._stop_event.isSet():
self._hold_for_data.wait()
self._hold_for_data.clear() | [
"This",
"may",
"seem",
"silly",
"but",
"on",
"a",
"Receiver",
"step",
"()",
"need",
"not",
"do",
"anything",
".",
"Instead",
"receive",
"the",
"data",
"on",
"the",
"receive",
"thread",
"and",
"set",
"it",
"on",
"the",
"buffer",
"then",
"call",
"self",
".",
"_hold_for_data",
".",
"set",
"()"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/animation/receiver.py#L59-L67 | [
"def",
"step",
"(",
"self",
",",
"amt",
"=",
"1",
")",
":",
"if",
"not",
"self",
".",
"_stop_event",
".",
"isSet",
"(",
")",
":",
"self",
".",
"_hold_for_data",
".",
"wait",
"(",
")",
"self",
".",
"_hold_for_data",
".",
"clear",
"(",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | Animation.construct | Construct an animation, set the runner, and add in the two
"reserved fields" `name` and `data`. | bibliopixel/animation/animation.py | def construct(cls, project, *, run=None, name=None, data=None, **desc):
"""
Construct an animation, set the runner, and add in the two
"reserved fields" `name` and `data`.
"""
from . failed import Failed
exception = desc.pop('_exception', None)
if exception:
a = Failed(project.layout, desc, exception)
else:
try:
a = cls(project.layout, **desc)
a._set_runner(run or {})
except Exception as e:
if cls.FAIL_ON_EXCEPTION:
raise
a = Failed(project.layout, desc, e)
a.name = name
a.data = data
return a | def construct(cls, project, *, run=None, name=None, data=None, **desc):
"""
Construct an animation, set the runner, and add in the two
"reserved fields" `name` and `data`.
"""
from . failed import Failed
exception = desc.pop('_exception', None)
if exception:
a = Failed(project.layout, desc, exception)
else:
try:
a = cls(project.layout, **desc)
a._set_runner(run or {})
except Exception as e:
if cls.FAIL_ON_EXCEPTION:
raise
a = Failed(project.layout, desc, e)
a.name = name
a.data = data
return a | [
"Construct",
"an",
"animation",
"set",
"the",
"runner",
"and",
"add",
"in",
"the",
"two",
"reserved",
"fields",
"name",
"and",
"data",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/animation/animation.py#L21-L41 | [
"def",
"construct",
"(",
"cls",
",",
"project",
",",
"*",
",",
"run",
"=",
"None",
",",
"name",
"=",
"None",
",",
"data",
"=",
"None",
",",
"*",
"*",
"desc",
")",
":",
"from",
".",
"failed",
"import",
"Failed",
"exception",
"=",
"desc",
".",
"pop",
"(",
"'_exception'",
",",
"None",
")",
"if",
"exception",
":",
"a",
"=",
"Failed",
"(",
"project",
".",
"layout",
",",
"desc",
",",
"exception",
")",
"else",
":",
"try",
":",
"a",
"=",
"cls",
"(",
"project",
".",
"layout",
",",
"*",
"*",
"desc",
")",
"a",
".",
"_set_runner",
"(",
"run",
"or",
"{",
"}",
")",
"except",
"Exception",
"as",
"e",
":",
"if",
"cls",
".",
"FAIL_ON_EXCEPTION",
":",
"raise",
"a",
"=",
"Failed",
"(",
"project",
".",
"layout",
",",
"desc",
",",
"e",
")",
"a",
".",
"name",
"=",
"name",
"a",
".",
"data",
"=",
"data",
"return",
"a"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | convert_mode | Return an image in the given mode. | bibliopixel/util/image/old_gif.py | def convert_mode(image, mode='RGB'):
"""Return an image in the given mode."""
deprecated.deprecated('util.gif.convert_model')
return image if (image.mode == mode) else image.convert(mode=mode) | def convert_mode(image, mode='RGB'):
"""Return an image in the given mode."""
deprecated.deprecated('util.gif.convert_model')
return image if (image.mode == mode) else image.convert(mode=mode) | [
"Return",
"an",
"image",
"in",
"the",
"given",
"mode",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/image/old_gif.py#L8-L12 | [
"def",
"convert_mode",
"(",
"image",
",",
"mode",
"=",
"'RGB'",
")",
":",
"deprecated",
".",
"deprecated",
"(",
"'util.gif.convert_model'",
")",
"return",
"image",
"if",
"(",
"image",
".",
"mode",
"==",
"mode",
")",
"else",
"image",
".",
"convert",
"(",
"mode",
"=",
"mode",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | image_to_colorlist | Given a PIL.Image, returns a ColorList of its pixels. | bibliopixel/util/image/old_gif.py | def image_to_colorlist(image, container=list):
"""Given a PIL.Image, returns a ColorList of its pixels."""
deprecated.deprecated('util.gif.image_to_colorlist')
return container(convert_mode(image).getdata()) | def image_to_colorlist(image, container=list):
"""Given a PIL.Image, returns a ColorList of its pixels."""
deprecated.deprecated('util.gif.image_to_colorlist')
return container(convert_mode(image).getdata()) | [
"Given",
"a",
"PIL",
".",
"Image",
"returns",
"a",
"ColorList",
"of",
"its",
"pixels",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/image/old_gif.py#L15-L19 | [
"def",
"image_to_colorlist",
"(",
"image",
",",
"container",
"=",
"list",
")",
":",
"deprecated",
".",
"deprecated",
"(",
"'util.gif.image_to_colorlist'",
")",
"return",
"container",
"(",
"convert_mode",
"(",
"image",
")",
".",
"getdata",
"(",
")",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | animated_gif_to_colorlists | Given an animated GIF, return a list with a colorlist for each frame. | bibliopixel/util/image/old_gif.py | def animated_gif_to_colorlists(image, container=list):
"""
Given an animated GIF, return a list with a colorlist for each frame.
"""
deprecated.deprecated('util.gif.animated_gif_to_colorlists')
from PIL import ImageSequence
it = ImageSequence.Iterator(image)
return [image_to_colorlist(i, container) for i in it] | def animated_gif_to_colorlists(image, container=list):
"""
Given an animated GIF, return a list with a colorlist for each frame.
"""
deprecated.deprecated('util.gif.animated_gif_to_colorlists')
from PIL import ImageSequence
it = ImageSequence.Iterator(image)
return [image_to_colorlist(i, container) for i in it] | [
"Given",
"an",
"animated",
"GIF",
"return",
"a",
"list",
"with",
"a",
"colorlist",
"for",
"each",
"frame",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/image/old_gif.py#L22-L31 | [
"def",
"animated_gif_to_colorlists",
"(",
"image",
",",
"container",
"=",
"list",
")",
":",
"deprecated",
".",
"deprecated",
"(",
"'util.gif.animated_gif_to_colorlists'",
")",
"from",
"PIL",
"import",
"ImageSequence",
"it",
"=",
"ImageSequence",
".",
"Iterator",
"(",
"image",
")",
"return",
"[",
"image_to_colorlist",
"(",
"i",
",",
"container",
")",
"for",
"i",
"in",
"it",
"]"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | parse | Parse a string representing a time interval or duration into seconds,
or raise an exception
:param str s: a string representation of a time interval
:raises ValueError: if ``s`` can't be interpreted as a duration | bibliopixel/util/duration.py | def parse(s):
"""
Parse a string representing a time interval or duration into seconds,
or raise an exception
:param str s: a string representation of a time interval
:raises ValueError: if ``s`` can't be interpreted as a duration
"""
parts = s.replace(',', ' ').split()
if not parts:
raise ValueError('Cannot parse empty string')
pieces = []
for part in parts:
m = PART_MATCH(part)
pieces.extend(m.groups() if m else [part])
if len(pieces) == 1:
pieces.append('s')
if len(pieces) % 2:
raise ValueError('Malformed duration %s: %s: %s' % (s, parts, pieces))
result = 0
for number, units in zip(*[iter(pieces)] * 2):
number = float(number)
if number < 0:
raise ValueError('Durations cannot have negative components')
result += number * _get_units(units)
return result | def parse(s):
"""
Parse a string representing a time interval or duration into seconds,
or raise an exception
:param str s: a string representation of a time interval
:raises ValueError: if ``s`` can't be interpreted as a duration
"""
parts = s.replace(',', ' ').split()
if not parts:
raise ValueError('Cannot parse empty string')
pieces = []
for part in parts:
m = PART_MATCH(part)
pieces.extend(m.groups() if m else [part])
if len(pieces) == 1:
pieces.append('s')
if len(pieces) % 2:
raise ValueError('Malformed duration %s: %s: %s' % (s, parts, pieces))
result = 0
for number, units in zip(*[iter(pieces)] * 2):
number = float(number)
if number < 0:
raise ValueError('Durations cannot have negative components')
result += number * _get_units(units)
return result | [
"Parse",
"a",
"string",
"representing",
"a",
"time",
"interval",
"or",
"duration",
"into",
"seconds",
"or",
"raise",
"an",
"exception"
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/util/duration.py#L81-L113 | [
"def",
"parse",
"(",
"s",
")",
":",
"parts",
"=",
"s",
".",
"replace",
"(",
"','",
",",
"' '",
")",
".",
"split",
"(",
")",
"if",
"not",
"parts",
":",
"raise",
"ValueError",
"(",
"'Cannot parse empty string'",
")",
"pieces",
"=",
"[",
"]",
"for",
"part",
"in",
"parts",
":",
"m",
"=",
"PART_MATCH",
"(",
"part",
")",
"pieces",
".",
"extend",
"(",
"m",
".",
"groups",
"(",
")",
"if",
"m",
"else",
"[",
"part",
"]",
")",
"if",
"len",
"(",
"pieces",
")",
"==",
"1",
":",
"pieces",
".",
"append",
"(",
"'s'",
")",
"if",
"len",
"(",
"pieces",
")",
"%",
"2",
":",
"raise",
"ValueError",
"(",
"'Malformed duration %s: %s: %s'",
"%",
"(",
"s",
",",
"parts",
",",
"pieces",
")",
")",
"result",
"=",
"0",
"for",
"number",
",",
"units",
"in",
"zip",
"(",
"*",
"[",
"iter",
"(",
"pieces",
")",
"]",
"*",
"2",
")",
":",
"number",
"=",
"float",
"(",
"number",
")",
"if",
"number",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"'Durations cannot have negative components'",
")",
"result",
"+=",
"number",
"*",
"_get_units",
"(",
"units",
")",
"return",
"result"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
valid | opener | Wait a little and then open a web browser page for the control panel. | bibliopixel/animation/remote/opener.py | def opener(ip_address, port, delay=1):
"""
Wait a little and then open a web browser page for the control panel.
"""
global WEBPAGE_OPENED
if WEBPAGE_OPENED:
return
WEBPAGE_OPENED = True
raw_opener(ip_address, port, delay) | def opener(ip_address, port, delay=1):
"""
Wait a little and then open a web browser page for the control panel.
"""
global WEBPAGE_OPENED
if WEBPAGE_OPENED:
return
WEBPAGE_OPENED = True
raw_opener(ip_address, port, delay) | [
"Wait",
"a",
"little",
"and",
"then",
"open",
"a",
"web",
"browser",
"page",
"for",
"the",
"control",
"panel",
"."
] | ManiacalLabs/BiblioPixel | python | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/animation/remote/opener.py#L7-L15 | [
"def",
"opener",
"(",
"ip_address",
",",
"port",
",",
"delay",
"=",
"1",
")",
":",
"global",
"WEBPAGE_OPENED",
"if",
"WEBPAGE_OPENED",
":",
"return",
"WEBPAGE_OPENED",
"=",
"True",
"raw_opener",
"(",
"ip_address",
",",
"port",
",",
"delay",
")"
] | fd97e6c651a4bbcade64733847f4eec8f7704b7c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.