Package qubx :: Module types
[hide private]
[frames] | no frames]

Module types

General-purpose types and utilities.

Copyright 2007-2012 Research Foundation State University of New York This file is part of QUB Express.

QUB Express is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

QUB Express is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License, named LICENSE.txt, in the QUB Express program directory. If not, see <http://www.gnu.org/licenses/>.

Classes [hide private]
  Anon
An object whose fields are the constructor keyword arguments.
  DeathRattle
Prints to stdout when it is finally freed, presumably at the same time as its owner.
  Event
Usage:
  JsonAnon
  OverridingDict
"Overrides" the base dict so keys are looked up first here, then if not found, in base dict.
  Product
  Reffer
Holds references to keep objects alive.
  WeakCall
Like WeakEvent, except there's at most one listener, and it can return a value.
  WeakEvent
Usage:
Functions [hide private]
 
ADDALPHA(tup, a)
 
COLOR_CLASS(c)
modelGTK.class[%i]
 
HSVtoRGB(h, s, v)
Returns (r,g,b) color coordinates corresponding to the hue, saturation and value.
 
INVERT_COLOR(tup)
 
NOALPHA(tup)
 
RGBtoHSV(r, g, b)
Returns the (hue, saturation, value) color coordinates corresponding to the RGB color.
 
SETALPHA(tup, a)
 
ScaleToColor(x, saturation=1.0)
Returns r,g,b corresponding to x in [-1..1].
 
WITHALPHA(tup)
 
add_ext_if_none(path, ext)
Returns path unmodified if it already has an extension, otherwise appends ext.
 
bind(callback, *args, **kw)
Returns a function f which, when called, discards its own args and returns callback(*args, **kw).
 
bind_with_args(callback, *args, **kw)
Like bind, but it appends the callback's positional args after the bound positional args; returns callback(*(args+cb_args), **kw).
 
bind_with_args_before(callback, *args, **kw)
Like bind, but it prepends the callback's positional args before the bound positional args; returns callback(*(args+cb_args), **kw).
 
breduce(func, seq)
like builtin reduce(), but recursing by splitting in half.
 
heapq_sink(heap, k)
 
heapq_swim(heap, k)
 
memoize(func, lbl='')
Returns wrapped func that caches return values for specific args.
 
memoize_heapq(func, max_weight=1000000, weigh=<function <lambda> at 0xbf173e4>, lbl='')
Returns wrapped func that caches return values for specific args.
 
nested_break(*args, **kwds)
 
path_splits(s)
Returns the list of all path components '/a/b/c' -> ['/', 'a', 'b', 'c']
 
printer(*xx)
Prints and returns its argument(s).
 
scrolled_digits(val, offset, fine=False, coarse=False, lo=None, hi=None)
 
scrolled_float(val, offset, fine=False, coarse=False, lo=None, hi=None)
Returns val scrolled according to offset direction and modifiers.
 
scrolled_int(val, offset, fine=False, coarse=False, lo=None, hi=None)
Variables [hide private]
  COLOR = defaultdict(<function <lambda> at 0xbf1772c>, {0: (0, ...
  ShowDropped = False
  UNSET_VALUE = 86738.82583
  VERSION = '1.3.9'
  __package__ = 'qubx'
  c = (1, 0, 1)
  e = 2.71828182846
  i = 19
  offset = 7
  pi = 3.14159265359
Function Details [hide private]

HSVtoRGB(h, s, v)

 

Returns (r,g,b) color coordinates corresponding to the hue, saturation and value. All coordinates are between 0 and 1.

RGBtoHSV(r, g, b)

 

Returns the (hue, saturation, value) color coordinates corresponding to the RGB color. All coordinates are between 0 and 1.

ScaleToColor(x, saturation=1.0)

 

Returns r,g,b corresponding to x in [-1..1]. The scale moves smoothly around the color wheel from pink (-) to red (+), with brightness proportional to abs(x).

bind(callback, *args, **kw)

 

Returns a function f which, when called, discards its own args and returns callback(*args, **kw).

Lambda can be useful to share one message handler among many sources, but there's a limitation:

>>> for i in xrange(N):
        chk[i].OnToggle += self__ref(lambda chk: self.__onToggle(i))

Here, the lambda binds not the value of i, but the stack location whose contents are repeatedly changed by the for loop. So all the lambdas are effectively doing self.__onToggle(N-1).

Instead:

>>> for i in xrange(N):
        chk[i].OnToggle += self.__ref(bind(self.__onToggle, i))

This creates a unique stack frame for your unique i, so it does what you expect.

breduce(func, seq)

 

like builtin reduce(), but recursing by splitting in half. Doesn't seem to make a difference.

memoize(func, lbl='')

 

Returns wrapped func that caches return values for specific args. All args must be immutable (e.g. tuples not lists).

Example:

>>> def factorial(n):
>>>     if n > 1:
>>>        return n * fast_fac(n-1)
>>>     else:
>>>        return 1
>>> fast_fac = memoize(factorial)

memoize_heapq(func, max_weight=1000000, weigh=<function <lambda> at 0xbf173e4>, lbl='')

 

Returns wrapped func that caches return values for specific args. All args must be immutable (e.g. tuples not lists).

Example:

>>> def factorial(n):
>>>     if n > 1:
>>>        return n * fast_fac(n-1)
>>>     else:
>>>        return 1
>>> fast_fac = memoize(factorial)

printer(*xx)

 

Prints and returns its argument(s). Handy for testing callbacks.


Variables Details [hide private]

COLOR

Value:
defaultdict(<function <lambda> at 0xbf1772c>, {0: (0, 0, 0), 1: (1, 0,\
 0), 2: (0, 0, 1), 3: (0, 1, 0), 4: (0, 1, 1), 5: (1, 1, 0), 6: (1, 0,\
 1), 7: (0.5, 0.0, 0.0), 8: (0.52500000000000002, 0.32024999999999998,\
 0.013125000000000012), 9: (0.44550000000000006, 0.55000000000000004, \
0.027500000000000028), 10: (0.14949999999999994, 0.57499999999999996, \
0.043124999999999969), 11: (0.059999999999999984, 0.59999999999999998,\
 0.27599999999999991), 12: (0.078125, 0.625, 0.625), 13: (0.0975000000\
00000017, 0.31850000000000001, 0.65000000000000002), 14: (0.2294999999\
...