signature
stringlengths 8
3.44k
| body
stringlengths 0
1.41M
| docstring
stringlengths 1
122k
| id
stringlengths 5
17
|
|---|---|---|---|
def lookup(self, name):
|
if name not in self.cache or DEBUG:<EOL><INDENT>for path in self.path:<EOL><INDENT>fpath = os.path.join(path, name)<EOL>if os.path.isfile(fpath):<EOL><INDENT>if self.cachemode in ('<STR_LIT:all>', '<STR_LIT>'):<EOL><INDENT>self.cache[name] = fpath<EOL><DEDENT>return fpath<EOL><DEDENT><DEDENT>if self.cachemode == '<STR_LIT:all>':<EOL><INDENT>self.cache[name] = None<EOL><DEDENT><DEDENT>return self.cache[name]<EOL>
|
Search for a resource and return an absolute file path, or `None`.
The :attr:`path` list is searched in order. The first match is
returend. Symlinks are followed. The result is cached to speed up
future lookups.
|
f8968:c31:m3
|
def open(self, name, mode='<STR_LIT:r>', *args, **kwargs):
|
fname = self.lookup(name)<EOL>if not fname: raise IOError("<STR_LIT>" % name)<EOL>return self.opener(fname, mode=mode, *args, **kwargs)<EOL>
|
Find a resource and return a file object, or raise IOError.
|
f8968:c31:m4
|
def __init__(self, fileobj, name, filename, headers=None):
|
<EOL>self.file = fileobj<EOL>self.name = name<EOL>self.raw_filename = filename<EOL>self.headers = HeaderDict(headers) if headers else HeaderDict()<EOL>
|
Wrapper for file uploads.
|
f8968:c32:m0
|
def get_header(self, name, default=None):
|
return self.headers.get(name, default)<EOL>
|
Return the value of a header within the mulripart part.
|
f8968:c32:m1
|
@cached_property<EOL><INDENT>def filename(self):<DEDENT>
|
fname = self.raw_filename<EOL>if not isinstance(fname, unicode):<EOL><INDENT>fname = fname.decode('<STR_LIT:utf8>', '<STR_LIT:ignore>')<EOL><DEDENT>fname = normalize('<STR_LIT>', fname)<EOL>fname = fname.encode('<STR_LIT>', '<STR_LIT:ignore>').decode('<STR_LIT>')<EOL>fname = os.path.basename(fname.replace('<STR_LIT:\\>', os.path.sep))<EOL>fname = re.sub(r'<STR_LIT>', '<STR_LIT>', fname).strip()<EOL>fname = re.sub(r'<STR_LIT>', '<STR_LIT:->', fname).strip('<STR_LIT>')<EOL>return fname[:<NUM_LIT:255>] or '<STR_LIT>'<EOL>
|
Name of the file on the client file system, but normalized to ensure
file system compatibility. An empty filename is returned as 'empty'.
Only ASCII letters, digits, dashes, underscores and dots are
allowed in the final filename. Accents are removed, if possible.
Whitespace is replaced by a single dash. Leading or tailing dots
or dashes are removed. The filename is limited to 255 characters.
|
f8968:c32:m2
|
def save(self, destination, overwrite=False, chunk_size=<NUM_LIT:2> ** <NUM_LIT:16>):
|
if isinstance(destination, basestring): <EOL><INDENT>if os.path.isdir(destination):<EOL><INDENT>destination = os.path.join(destination, self.filename)<EOL><DEDENT>if not overwrite and os.path.exists(destination):<EOL><INDENT>raise IOError('<STR_LIT>')<EOL><DEDENT>with open(destination, '<STR_LIT:wb>') as fp:<EOL><INDENT>self._copy_file(fp, chunk_size)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self._copy_file(destination, chunk_size)<EOL><DEDENT>
|
Save file to disk or copy its content to an open file(-like) object.
If *destination* is a directory, :attr:`filename` is added to the
path. Existing files are not overwritten by default (IOError).
:param destination: File path, directory or file(-like) object.
:param overwrite: If True, replace existing files. (default: False)
:param chunk_size: Bytes to read at a time. (default: 64kb)
|
f8968:c32:m4
|
def __init__(self,<EOL>source=None,<EOL>name=None,<EOL>lookup=None,<EOL>encoding='<STR_LIT:utf8>', **settings):
|
self.name = name<EOL>self.source = source.read() if hasattr(source, '<STR_LIT>') else source<EOL>self.filename = source.filename if hasattr(source, '<STR_LIT:filename>') else None<EOL>self.lookup = [os.path.abspath(x) for x in lookup] if lookup else []<EOL>self.encoding = encoding<EOL>self.settings = self.settings.copy() <EOL>self.settings.update(settings) <EOL>if not self.source and self.name:<EOL><INDENT>self.filename = self.search(self.name, self.lookup)<EOL>if not self.filename:<EOL><INDENT>raise TemplateError('<STR_LIT>' % repr(name))<EOL><DEDENT><DEDENT>if not self.source and not self.filename:<EOL><INDENT>raise TemplateError('<STR_LIT>')<EOL><DEDENT>self.prepare(**self.settings)<EOL>
|
Create a new template.
If the source parameter (str or buffer) is missing, the name argument
is used to guess a template filename. Subclasses can assume that
self.source and/or self.filename are set. Both are strings.
The lookup, encoding and settings parameters are stored as instance
variables.
The lookup parameter stores a list containing directory paths.
The encoding parameter should be used to decode byte strings or files.
The settings parameter contains a dict for engine-specific settings.
|
f8968:c58:m0
|
@classmethod<EOL><INDENT>def search(cls, name, lookup=None):<DEDENT>
|
if not lookup:<EOL><INDENT>raise depr(<NUM_LIT:0>, <NUM_LIT:12>, "<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>if os.path.isabs(name):<EOL><INDENT>raise depr(<NUM_LIT:0>, <NUM_LIT:12>, "<STR_LIT>",<EOL>"<STR_LIT>")<EOL><DEDENT>for spath in lookup:<EOL><INDENT>spath = os.path.abspath(spath) + os.sep<EOL>fname = os.path.abspath(os.path.join(spath, name))<EOL>if not fname.startswith(spath): continue<EOL>if os.path.isfile(fname): return fname<EOL>for ext in cls.extensions:<EOL><INDENT>if os.path.isfile('<STR_LIT>' % (fname, ext)):<EOL><INDENT>return '<STR_LIT>' % (fname, ext)<EOL><DEDENT><DEDENT><DEDENT>
|
Search name in all directories specified in lookup.
First without, then with common extensions. Return first hit.
|
f8968:c58:m1
|
@classmethod<EOL><INDENT>def global_config(cls, key, *args):<DEDENT>
|
if args:<EOL><INDENT>cls.settings = cls.settings.copy() <EOL>cls.settings[key] = args[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>return cls.settings[key]<EOL><DEDENT>
|
This reads or sets the global settings stored in class.settings.
|
f8968:c58:m2
|
def prepare(self, **options):
|
raise NotImplementedError<EOL>
|
Run preparations (parsing, caching, ...).
It should be possible to call this again to refresh a template or to
update settings.
|
f8968:c58:m3
|
def render(self, *args, **kwargs):
|
raise NotImplementedError<EOL>
|
Render the template with the specified local variables and return
a single byte or unicode string. If it is a byte string, the encoding
must match self.encoding. This method must be thread-safe!
Local variables may be provided in dictionaries (args)
or directly, as keywords (kwargs).
|
f8968:c58:m4
|
def render(self, *args, **kwargs):
|
env = {}<EOL>stdout = []<EOL>for dictarg in args:<EOL><INDENT>env.update(dictarg)<EOL><DEDENT>env.update(kwargs)<EOL>self.execute(stdout, env)<EOL>return '<STR_LIT>'.join(stdout)<EOL>
|
Render the template using keyword arguments as local variables.
|
f8968:c62:m6
|
def get_syntax(self):
|
return self._syntax<EOL>
|
Tokens as a space separated string (default: <% %> % {{ }})
|
f8968:c64:m1
|
def get_next_token(string):
|
STOP_CHARS = "<STR_LIT>"<EOL>UNARY_CHARS = "<STR_LIT>"<EOL>if string[<NUM_LIT:0>] in STOP_CHARS:<EOL><INDENT>return string[<NUM_LIT:0>], string[<NUM_LIT:1>:]<EOL><DEDENT>expression = []<EOL>for i, c in enumerate(string):<EOL><INDENT>if c in STOP_CHARS:<EOL><INDENT>break<EOL><DEDENT>else:<EOL><INDENT>expression.append(c)<EOL><DEDENT><DEDENT>return "<STR_LIT>".join(expression), string[i:]<EOL>
|
"eats" up the string until it hits an ending character to get valid leaf expressions.
For example, given \\Phi_{z}(L) = \\sum_{i=1}^{N} \\frac{1}{C_{i} \\times V_{\\rm max, i}},
this function would pull out \\Phi, stopping at _
@ string: str
returns a tuple of (expression [ex: \\Phi], remaining_chars [ex: _{z}(L) = \\sum_{i=1}^{N}...])
|
f8970:m1
|
def on_play_speed(self, *args):
|
Clock.unschedule(self.play)<EOL>Clock.schedule_interval(self.play, <NUM_LIT:1.0> / self.play_speed)<EOL>
|
Change the interval at which ``self.play`` is called to match my
current ``play_speed``.
|
f8974:c5:m3
|
def remake_display(self, *args):
|
Builder.load_string(self.kv)<EOL>if hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.remove_widget(self._kv_layout)<EOL>del self._kv_layout<EOL><DEDENT>self._kv_layout = KvLayout()<EOL>self.add_widget(self._kv_layout)<EOL>
|
Remake any affected widgets after a change in my ``kv``.
|
f8974:c5:m4
|
def on_dummies(self, *args):
|
def renum_dummy(dummy, *args):<EOL><INDENT>dummy.num = dummynum(self.app.character, dummy.prefix) + <NUM_LIT:1><EOL><DEDENT>for dummy in self.dummies:<EOL><INDENT>if dummy is None or hasattr(dummy, '<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>if dummy == self.dummything:<EOL><INDENT>self.app.pawncfg.bind(imgpaths=self._propagate_thing_paths)<EOL><DEDENT>if dummy == self.dummyplace:<EOL><INDENT>self.app.spotcfg.bind(imgpaths=self._propagate_place_paths)<EOL><DEDENT>dummy.num = dummynum(self.app.character, dummy.prefix) + <NUM_LIT:1><EOL>Logger.debug("<STR_LIT>".format(dummy.num))<EOL>dummy.bind(prefix=partial(renum_dummy, dummy))<EOL>dummy._numbered = True<EOL><DEDENT>
|
Give the dummies numbers such that, when appended to their names,
they give a unique name for the resulting new
:class:`board.Pawn` or :class:`board.Spot`.
|
f8974:c5:m7
|
def play(self, *args):
|
if self.playbut.state == '<STR_LIT>':<EOL><INDENT>return<EOL><DEDENT>self.next_turn()<EOL>
|
If the 'play' button is pressed, advance a turn.
If you want to disable this, set ``engine.universal['block'] = True``
|
f8974:c5:m12
|
def next_turn(self, *args):
|
if self.tmp_block:<EOL><INDENT>return<EOL><DEDENT>eng = self.app.engine<EOL>dial = self.dialoglayout<EOL>if eng.universal.get('<STR_LIT>'):<EOL><INDENT>Logger.info("<STR_LIT>")<EOL>return<EOL><DEDENT>if dial.idx < len(dial.todo):<EOL><INDENT>Logger.info("<STR_LIT>")<EOL>return<EOL><DEDENT>self.tmp_block = True<EOL>self.app.unbind(<EOL>branch=self.app._push_time,<EOL>turn=self.app._push_time,<EOL>tick=self.app._push_time<EOL>)<EOL>eng.next_turn(cb=self._update_from_next_turn)<EOL>
|
Advance time by one turn, if it's not blocked.
Block time by setting ``engine.universal['block'] = True``
|
f8974:c5:m14
|
def try_load(loader, obj):
|
try:<EOL><INDENT>return loader(obj)<EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>return obj<EOL><DEDENT>
|
Return the JSON interpretation the object if possible, or just the
object otherwise.
|
f8975:m0
|
def dummynum(character, name):
|
num = <NUM_LIT:0><EOL>for nodename in character.node:<EOL><INDENT>nodename = str(nodename)<EOL>if not nodename.startswith(name):<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>nodenum = int(nodename.lstrip(name))<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT>num = max((nodenum, num))<EOL><DEDENT>return num<EOL>
|
Count how many nodes there already are in the character whose name
starts the same.
|
f8975:m1
|
def get_thin_rect_vertices(ox, oy, dx, dy, r):
|
if ox < dx:<EOL><INDENT>leftx = ox<EOL>rightx = dx<EOL>xco = <NUM_LIT:1><EOL><DEDENT>elif ox > dx:<EOL><INDENT>leftx = ox * -<NUM_LIT:1><EOL>rightx = dx * -<NUM_LIT:1><EOL>xco = -<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>return [<EOL>ox - r, oy,<EOL>ox + r, oy,<EOL>ox + r, dy,<EOL>ox - r, dy<EOL>]<EOL><DEDENT>if oy < dy:<EOL><INDENT>boty = oy<EOL>topy = dy<EOL>yco = <NUM_LIT:1><EOL><DEDENT>elif oy > dy:<EOL><INDENT>boty = oy * -<NUM_LIT:1><EOL>topy = dy * -<NUM_LIT:1><EOL>yco = -<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>return [<EOL>ox, oy - r,<EOL>dx, oy - r,<EOL>dx, oy + r,<EOL>ox, oy + r<EOL>]<EOL><DEDENT>rise = topy - boty<EOL>run = rightx - leftx<EOL>theta = atan(rise/run)<EOL>theta_prime = ninety - theta<EOL>xoff = cos(theta_prime) * r<EOL>yoff = sin(theta_prime) * r<EOL>x1 = leftx + xoff<EOL>y1 = boty - yoff<EOL>x2 = rightx + xoff<EOL>y2 = topy - yoff<EOL>x3 = rightx - xoff<EOL>y3 = topy + yoff<EOL>x4 = leftx - xoff<EOL>y4 = boty + yoff<EOL>return [<EOL>x1 * xco, y1 * yco,<EOL>x2 * xco, y2 * yco,<EOL>x3 * xco, y3 * yco,<EOL>x4 * xco, y4 * yco<EOL>]<EOL>
|
Given the starting point, ending point, and width, return a list of
vertex coordinates at the corners of the line segment
(really a thin rectangle).
|
f8975:m2
|
def get_pos_hint_x(poshints, sizehintx):
|
if '<STR_LIT:x>' in poshints:<EOL><INDENT>return poshints['<STR_LIT:x>']<EOL><DEDENT>elif sizehintx is not None:<EOL><INDENT>if '<STR_LIT>' in poshints:<EOL><INDENT>return (<EOL>poshints['<STR_LIT>'] -<EOL>sizehintx / <NUM_LIT:2><EOL>)<EOL><DEDENT>elif '<STR_LIT:right>' in poshints:<EOL><INDENT>return (<EOL>poshints['<STR_LIT:right>'] -<EOL>sizehintx<EOL>)<EOL><DEDENT><DEDENT>
|
Return ``poshints['x']`` if available, or its computed equivalent
otherwise.
|
f8977:m0
|
def get_pos_hint_y(poshints, sizehinty):
|
if '<STR_LIT:y>' in poshints:<EOL><INDENT>return poshints['<STR_LIT:y>']<EOL><DEDENT>elif sizehinty is not None:<EOL><INDENT>if '<STR_LIT>' in poshints:<EOL><INDENT>return (<EOL>poshints['<STR_LIT>'] -<EOL>sizehinty / <NUM_LIT:2><EOL>)<EOL><DEDENT>elif '<STR_LIT>' in poshints:<EOL><INDENT>return (<EOL>poshints['<STR_LIT>'] -<EOL>sizehinty<EOL>)<EOL><DEDENT><DEDENT>
|
Return ``poshints['y']`` if available, or its computed equivalent
otherwise.
|
f8977:m1
|
def get_pos_hint(poshints, sizehintx, sizehinty):
|
return (<EOL>get_pos_hint_x(poshints, sizehintx),<EOL>get_pos_hint_y(poshints, sizehinty)<EOL>)<EOL>
|
Return a tuple of ``(pos_hint_x, pos_hint_y)`` even if neither of
those keys are present in the provided ``poshints`` -- they can be
computed using the available keys together with ``size_hint_x``
and ``size_hint_y``.
|
f8977:m2
|
def on_background_source(self, *args):
|
if self.background_source:<EOL><INDENT>self.background_image = Image(source=self.background_source)<EOL><DEDENT>
|
When I get a new ``background_source``, load it as an
:class:`Image` and store that in ``background_image``.
|
f8977:c1:m0
|
def on_background_image(self, *args):
|
if self.background_image is not None:<EOL><INDENT>self.background_texture = self.background_image.texture<EOL><DEDENT>
|
When I get a new ``background_image``, store its texture in
``background_texture``.
|
f8977:c1:m1
|
def on_foreground_source(self, *args):
|
if self.foreground_source:<EOL><INDENT>self.foreground_image = Image(source=self.foreground_source)<EOL><DEDENT>
|
When I get a new ``foreground_source``, load it as an
:class:`Image` and store that in ``foreground_image``.
|
f8977:c1:m2
|
def on_foreground_image(self, *args):
|
if self.foreground_image is not None:<EOL><INDENT>self.foreground_texture = self.foreground_image.texture<EOL><DEDENT>
|
When I get a new ``foreground_image``, store its texture in my
``foreground_texture``.
|
f8977:c1:m3
|
def on_art_source(self, *args):
|
if self.art_source:<EOL><INDENT>self.art_image = Image(source=self.art_source)<EOL><DEDENT>
|
When I get a new ``art_source``, load it as an :class:`Image` and
store that in ``art_image``.
|
f8977:c1:m4
|
def on_art_image(self, *args):
|
if self.art_image is not None:<EOL><INDENT>self.art_texture = self.art_image.texture<EOL><DEDENT>
|
When I get a new ``art_image``, store its texture in
``art_texture``.
|
f8977:c1:m5
|
def on_touch_down(self, touch):
|
if not self.collide_point(*touch.pos):<EOL><INDENT>return<EOL><DEDENT>if '<STR_LIT>' in touch.ud:<EOL><INDENT>return<EOL><DEDENT>touch.grab(self)<EOL>self.dragging = True<EOL>touch.ud['<STR_LIT>'] = self<EOL>touch.ud['<STR_LIT>'] = self.idx<EOL>touch.ud['<STR_LIT>'] = self.deck<EOL>touch.ud['<STR_LIT>'] = self.parent<EOL>self.collide_x = touch.x - self.x<EOL>self.collide_y = touch.y - self.y<EOL>
|
If I'm the first card to collide this touch, grab it, store my
metadata in its userdict, and store the relative coords upon
me where the collision happened.
|
f8977:c1:m6
|
def on_touch_move(self, touch):
|
if not self.dragging:<EOL><INDENT>touch.ungrab(self)<EOL>return<EOL><DEDENT>self.pos = (<EOL>touch.x - self.collide_x,<EOL>touch.y - self.collide_y<EOL>)<EOL>
|
If I'm being dragged, move so as to be always positioned the same
relative to the touch.
|
f8977:c1:m7
|
def on_touch_up(self, touch):
|
if not self.dragging:<EOL><INDENT>return<EOL><DEDENT>touch.ungrab(self)<EOL>self.dragging = False<EOL>
|
Stop dragging if needed.
|
f8977:c1:m8
|
def copy(self):
|
d = {}<EOL>for att in (<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT:text>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>'<EOL>):<EOL><INDENT>v = getattr(self, att)<EOL>if v is not None:<EOL><INDENT>d[att] = v<EOL><DEDENT><DEDENT>return Card(**d)<EOL>
|
Return a new :class:`Card` just like me.
|
f8977:c1:m9
|
def upd_pos(self, *args):
|
self.pos = self.parent._get_foundation_pos(self.deck)<EOL>
|
Ask the foundation where I should be, based on what deck I'm
for.
|
f8977:c2:m0
|
def upd_size(self, *args):
|
self.size = (<EOL>self.parent.card_size_hint_x * self.parent.width,<EOL>self.parent.card_size_hint_y * self.parent.height<EOL>)<EOL>
|
I'm the same size as any given card in my :class:`DeckLayout`.
|
f8977:c2:m1
|
def __init__(self, **kwargs):
|
super().__init__(**kwargs)<EOL>self.bind(<EOL>card_size_hint=self._trigger_layout,<EOL>starting_pos_hint=self._trigger_layout,<EOL>card_hint_step=self._trigger_layout,<EOL>deck_hint_step=self._trigger_layout,<EOL>decks=self._trigger_layout,<EOL>deck_x_hint_offsets=self._trigger_layout,<EOL>deck_y_hint_offsets=self._trigger_layout,<EOL>insertion_deck=self._trigger_layout,<EOL>insertion_card=self._trigger_layout<EOL>)<EOL>
|
Bind most of my custom properties to ``_trigger_layout``.
|
f8977:c3:m0
|
def scroll_deck_x(self, decknum, scroll_x):
|
if decknum >= len(self.decks):<EOL><INDENT>raise IndexError("<STR_LIT>".format(decknum))<EOL><DEDENT>if decknum >= len(self.deck_x_hint_offsets):<EOL><INDENT>self.deck_x_hint_offsets = list(self.deck_x_hint_offsets) + [<NUM_LIT:0>] * (<EOL>decknum - len(self.deck_x_hint_offsets) + <NUM_LIT:1><EOL>)<EOL><DEDENT>self.deck_x_hint_offsets[decknum] += scroll_x<EOL>self._trigger_layout()<EOL>
|
Move a deck left or right.
|
f8977:c3:m1
|
def scroll_deck_y(self, decknum, scroll_y):
|
if decknum >= len(self.decks):<EOL><INDENT>raise IndexError("<STR_LIT>".format(decknum))<EOL><DEDENT>if decknum >= len(self.deck_y_hint_offsets):<EOL><INDENT>self.deck_y_hint_offsets = list(self.deck_y_hint_offsets) + [<NUM_LIT:0>] * (<EOL>decknum - len(self.deck_y_hint_offsets) + <NUM_LIT:1><EOL>)<EOL><DEDENT>self.deck_y_hint_offsets[decknum] += scroll_y<EOL>self._trigger_layout()<EOL>
|
Move a deck up or down.
|
f8977:c3:m2
|
def scroll_deck(self, decknum, scroll_x, scroll_y):
|
self.scroll_deck_x(decknum, scroll_x)<EOL>self.scroll_deck_y(decknum, scroll_y)<EOL>
|
Move a deck.
|
f8977:c3:m3
|
def _get_foundation_pos(self, i):
|
(phx, phy) = get_pos_hint(<EOL>self.starting_pos_hint, *self.card_size_hint<EOL>)<EOL>phx += self.deck_x_hint_step * i + self.deck_x_hint_offsets[i]<EOL>phy += self.deck_y_hint_step * i + self.deck_y_hint_offsets[i]<EOL>x = phx * self.width + self.x<EOL>y = phy * self.height + self.y<EOL>return (x, y)<EOL>
|
Private. Get the absolute coordinates to use for a deck's
foundation, based on the ``starting_pos_hint``, the
``deck_hint_step``, ``deck_x_hint_offsets``, and
``deck_y_hint_offsets``.
|
f8977:c3:m4
|
def _get_foundation(self, i):
|
if i >= len(self._foundations) or self._foundations[i] is None:<EOL><INDENT>oldfound = list(self._foundations)<EOL>extend = i - len(oldfound) + <NUM_LIT:1><EOL>if extend > <NUM_LIT:0>:<EOL><INDENT>oldfound += [None] * extend<EOL><DEDENT>width = self.card_size_hint_x * self.width<EOL>height = self.card_size_hint_y * self.height<EOL>found = Foundation(<EOL>pos=self._get_foundation_pos(i), size=(width, height), deck=i<EOL>)<EOL>self.bind(<EOL>pos=found.upd_pos,<EOL>card_size_hint=found.upd_pos,<EOL>deck_hint_step=found.upd_pos,<EOL>size=found.upd_pos,<EOL>deck_x_hint_offsets=found.upd_pos,<EOL>deck_y_hint_offsets=found.upd_pos<EOL>)<EOL>self.bind(<EOL>size=found.upd_size,<EOL>card_size_hint=found.upd_size<EOL>)<EOL>oldfound[i] = found<EOL>self._foundations = oldfound<EOL><DEDENT>return self._foundations[i]<EOL>
|
Return a :class:`Foundation` for some deck, creating it if
needed.
|
f8977:c3:m5
|
def on_decks(self, *args):
|
if None in (<EOL>self.canvas,<EOL>self.decks,<EOL>self.deck_x_hint_offsets,<EOL>self.deck_y_hint_offsets<EOL>):<EOL><INDENT>Clock.schedule_once(self.on_decks, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>self.clear_widgets()<EOL>decknum = <NUM_LIT:0><EOL>for deck in self.decks:<EOL><INDENT>cardnum = <NUM_LIT:0><EOL>for card in deck:<EOL><INDENT>if not isinstance(card, Card):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if card not in self.children:<EOL><INDENT>self.add_widget(card)<EOL><DEDENT>if card.deck != decknum:<EOL><INDENT>card.deck = decknum<EOL><DEDENT>if card.idx != cardnum:<EOL><INDENT>card.idx = cardnum<EOL><DEDENT>cardnum += <NUM_LIT:1><EOL><DEDENT>decknum += <NUM_LIT:1><EOL><DEDENT>if len(self.deck_x_hint_offsets) < len(self.decks):<EOL><INDENT>self.deck_x_hint_offsets = list(self.deck_x_hint_offsets) + [<NUM_LIT:0>] * (<EOL>len(self.decks) - len(self.deck_x_hint_offsets)<EOL>)<EOL><DEDENT>if len(self.deck_y_hint_offsets) < len(self.decks):<EOL><INDENT>self.deck_y_hint_offsets = list(self.deck_y_hint_offsets) + [<NUM_LIT:0>] * (<EOL>len(self.decks) - len(self.deck_y_hint_offsets)<EOL>)<EOL><DEDENT>self._trigger_layout()<EOL>
|
Inform the cards of their deck and their index within the deck;
extend the ``_hint_offsets`` properties as needed; and trigger
a layout.
|
f8977:c3:m6
|
def point_before_card(self, card, x, y):
|
def ycmp():<EOL><INDENT>if self.card_y_hint_step == <NUM_LIT:0>:<EOL><INDENT>return False<EOL><DEDENT>elif self.card_y_hint_step > <NUM_LIT:0>:<EOL><INDENT>return y < card.y<EOL><DEDENT>else:<EOL><INDENT>return y > card.top<EOL><DEDENT><DEDENT>if self.card_x_hint_step > <NUM_LIT:0>:<EOL><INDENT>if x < card.x:<EOL><INDENT>return True<EOL><DEDENT>return ycmp()<EOL><DEDENT>elif self.card_x_hint_step == <NUM_LIT:0>:<EOL><INDENT>return ycmp()<EOL><DEDENT>else:<EOL><INDENT>if x > card.right:<EOL><INDENT>return True<EOL><DEDENT>return ycmp()<EOL><DEDENT>
|
Return whether ``(x, y)`` is somewhere before ``card``, given how I
know cards to be arranged.
If the cards are being stacked down and to the right, that
means I'm testing whether ``(x, y)`` is above or to the left
of the card.
|
f8977:c3:m7
|
def point_after_card(self, card, x, y):
|
def ycmp():<EOL><INDENT>if self.card_y_hint_step == <NUM_LIT:0>:<EOL><INDENT>return False<EOL><DEDENT>elif self.card_y_hint_step > <NUM_LIT:0>:<EOL><INDENT>return y > card.top<EOL><DEDENT>else:<EOL><INDENT>return y < card.y<EOL><DEDENT><DEDENT>if self.card_x_hint_step > <NUM_LIT:0>:<EOL><INDENT>if x > card.right:<EOL><INDENT>return True<EOL><DEDENT>return ycmp()<EOL><DEDENT>elif self.card_x_hint_step == <NUM_LIT:0>:<EOL><INDENT>return ycmp()<EOL><DEDENT>else:<EOL><INDENT>if x < card.x:<EOL><INDENT>return True<EOL><DEDENT>return ycmp()<EOL><DEDENT>
|
Return whether ``(x, y)`` is somewhere after ``card``, given how I
know cards to be arranged.
If the cards are being stacked down and to the right, that
means I'm testing whether ``(x, y)`` is below or to the left
of ``card``.
|
f8977:c3:m8
|
def on_touch_move(self, touch):
|
if (<EOL>'<STR_LIT>' not in touch.ud or<EOL>'<STR_LIT>' not in touch.ud or<EOL>touch.ud['<STR_LIT>'] != self<EOL>):<EOL><INDENT>return<EOL><DEDENT>if (<EOL>touch.ud['<STR_LIT>'] == self and<EOL>not hasattr(touch.ud['<STR_LIT>'], '<STR_LIT>')<EOL>):<EOL><INDENT>touch.ud['<STR_LIT>']._topdecked = InstructionGroup()<EOL>touch.ud['<STR_LIT>']._topdecked.add(touch.ud['<STR_LIT>'].canvas)<EOL>self.canvas.after.add(touch.ud['<STR_LIT>']._topdecked)<EOL><DEDENT>for i, deck in enumerate(self.decks):<EOL><INDENT>cards = [card for card in deck if not card.dragging]<EOL>maxidx = max(card.idx for card in cards) if cards else <NUM_LIT:0><EOL>if self.direction == '<STR_LIT>':<EOL><INDENT>cards.reverse()<EOL><DEDENT>cards_collided = [<EOL>card for card in cards if card.collide_point(*touch.pos)<EOL>]<EOL>if cards_collided:<EOL><INDENT>collided = cards_collided.pop()<EOL>for card in cards_collided:<EOL><INDENT>if card.idx > collided.idx:<EOL><INDENT>collided = card<EOL><DEDENT><DEDENT>if collided.deck == touch.ud['<STR_LIT>']:<EOL><INDENT>self.insertion_card = (<EOL><NUM_LIT:1> if collided.idx == <NUM_LIT:0> else<EOL>maxidx + <NUM_LIT:1> if collided.idx == maxidx else<EOL>collided.idx + <NUM_LIT:1> if collided.idx > touch.ud['<STR_LIT>']<EOL>else collided.idx<EOL>)<EOL><DEDENT>else:<EOL><INDENT>dropdeck = self.decks[collided.deck]<EOL>maxidx = max(card.idx for card in dropdeck)<EOL>self.insertion_card = (<EOL><NUM_LIT:1> if collided.idx == <NUM_LIT:0> else<EOL>maxidx + <NUM_LIT:1> if collided.idx == maxidx else<EOL>collided.idx + <NUM_LIT:1><EOL>)<EOL><DEDENT>if self.insertion_deck != collided.deck:<EOL><INDENT>self.insertion_deck = collided.deck<EOL><DEDENT>return<EOL><DEDENT>else:<EOL><INDENT>if self.insertion_deck == i:<EOL><INDENT>if self.insertion_card in (<NUM_LIT:0>, len(deck)):<EOL><INDENT>pass<EOL><DEDENT>elif self.point_before_card(<EOL>cards[<NUM_LIT:0>], *touch.pos<EOL>):<EOL><INDENT>self.insertion_card = <NUM_LIT:0><EOL><DEDENT>elif self.point_after_card(<EOL>cards[-<NUM_LIT:1>], *touch.pos<EOL>):<EOL><INDENT>self.insertion_card = cards[-<NUM_LIT:1>].idx<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for j, found in enumerate(self._foundations):<EOL><INDENT>if (<EOL>found is not None and<EOL>found.collide_point(*touch.pos)<EOL>):<EOL><INDENT>self.insertion_deck = j<EOL>self.insertion_card = <NUM_LIT:0><EOL>return<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>
|
If a card is being dragged, move other cards out of the way to show
where the dragged card will go if you drop it.
|
f8977:c3:m9
|
def on_touch_up(self, touch):
|
if (<EOL>'<STR_LIT>' not in touch.ud or<EOL>'<STR_LIT>' not in touch.ud or<EOL>touch.ud['<STR_LIT>'] != self<EOL>):<EOL><INDENT>return<EOL><DEDENT>if hasattr(touch.ud['<STR_LIT>'], '<STR_LIT>'):<EOL><INDENT>self.canvas.after.remove(touch.ud['<STR_LIT>']._topdecked)<EOL>del touch.ud['<STR_LIT>']._topdecked<EOL><DEDENT>if None not in (self.insertion_deck, self.insertion_card):<EOL><INDENT>card = touch.ud['<STR_LIT>']<EOL>del card.parent.decks[card.deck][card.idx]<EOL>for i in range(<NUM_LIT:0>, len(card.parent.decks[card.deck])):<EOL><INDENT>card.parent.decks[card.deck][i].idx = i<EOL><DEDENT>deck = self.decks[self.insertion_deck]<EOL>if self.insertion_card >= len(deck):<EOL><INDENT>deck.append(card)<EOL><DEDENT>else:<EOL><INDENT>deck.insert(self.insertion_card, card)<EOL><DEDENT>card.deck = self.insertion_deck<EOL>card.idx = self.insertion_card<EOL>self.decks[self.insertion_deck] = deck<EOL>self.insertion_deck = self.insertion_card = None<EOL><DEDENT>self._trigger_layout()<EOL>
|
If a card is being dragged, put it in the place it was just dropped
and trigger a layout.
|
f8977:c3:m10
|
def on_insertion_card(self, *args):
|
if self.insertion_card is not None:<EOL><INDENT>self._trigger_layout()<EOL><DEDENT>
|
Trigger a layout
|
f8977:c3:m11
|
def do_layout(self, *args):
|
if self.size == [<NUM_LIT:1>, <NUM_LIT:1>]:<EOL><INDENT>return<EOL><DEDENT>for i in range(<NUM_LIT:0>, len(self.decks)):<EOL><INDENT>self.layout_deck(i)<EOL><DEDENT>
|
Layout each of my decks
|
f8977:c3:m12
|
def layout_deck(self, i):
|
def get_dragidx(cards):<EOL><INDENT>j = <NUM_LIT:0><EOL>for card in cards:<EOL><INDENT>if card.dragging:<EOL><INDENT>return j<EOL><DEDENT>j += <NUM_LIT:1><EOL><DEDENT><DEDENT>cards = list(self.decks[i])<EOL>dragidx = get_dragidx(cards)<EOL>if dragidx is not None:<EOL><INDENT>del cards[dragidx]<EOL><DEDENT>if self.insertion_deck == i and self.insertion_card is not None:<EOL><INDENT>insdx = self.insertion_card<EOL>if dragidx is not None and insdx > dragidx:<EOL><INDENT>insdx -= <NUM_LIT:1><EOL><DEDENT>cards.insert(insdx, None)<EOL><DEDENT>if self.direction == '<STR_LIT>':<EOL><INDENT>cards.reverse()<EOL><DEDENT>(phx, phy) = get_pos_hint(self.starting_pos_hint, *self.card_size_hint)<EOL>phx += self.deck_x_hint_step * i + self.deck_x_hint_offsets[i]<EOL>phy += self.deck_y_hint_step * i + self.deck_y_hint_offsets[i]<EOL>(w, h) = self.size<EOL>(x, y) = self.pos<EOL>found = self._get_foundation(i)<EOL>if found in self.children:<EOL><INDENT>self.remove_widget(found)<EOL><DEDENT>self.add_widget(found)<EOL>for card in cards:<EOL><INDENT>if card is not None:<EOL><INDENT>if card in self.children:<EOL><INDENT>self.remove_widget(card)<EOL><DEDENT>(shw, shh) = self.card_size_hint<EOL>card.pos = (<EOL>x + phx * w,<EOL>y + phy * h<EOL>)<EOL>card.size = (w * shw, h * shh)<EOL>self.add_widget(card)<EOL><DEDENT>phx += self.card_x_hint_step<EOL>phy += self.card_y_hint_step<EOL><DEDENT>
|
Stack the cards, starting at my deck's foundation, and proceeding
by ``card_pos_hint``
|
f8977:c3:m13
|
def on_touch_down(self, touch):
|
if self.parent is None:<EOL><INDENT>return<EOL><DEDENT>if self.collide_point(*touch.pos):<EOL><INDENT>self.parent.bar_touched(self, touch)<EOL><DEDENT>
|
Tell my parent if I've been touched
|
f8977:c5:m0
|
def __init__(self, **kwargs):
|
super().__init__(**kwargs)<EOL>self.bind(<EOL>_scroll=self._trigger_layout,<EOL>scroll_min=self._trigger_layout,<EOL>scroll_max=self._trigger_layout<EOL>)<EOL>
|
Arrange to be laid out whenever I'm scrolled or the range of my
scrolling changes.
|
f8977:c6:m4
|
def do_layout(self, *args):
|
if '<STR_LIT:bar>' not in self.ids:<EOL><INDENT>Clock.schedule_once(self.do_layout)<EOL>return<EOL><DEDENT>if self.orientation == '<STR_LIT>':<EOL><INDENT>self.ids.bar.size_hint_x = self.hbar[<NUM_LIT:1>]<EOL>self.ids.bar.pos_hint = {'<STR_LIT:x>': self.hbar[<NUM_LIT:0>], '<STR_LIT:y>': <NUM_LIT:0>}<EOL><DEDENT>else:<EOL><INDENT>self.ids.bar.size_hint_y = self.vbar[<NUM_LIT:1>]<EOL>self.ids.bar.pos_hint = {'<STR_LIT:x>': <NUM_LIT:0>, '<STR_LIT:y>': self.vbar[<NUM_LIT:0>]}<EOL><DEDENT>super().do_layout(*args)<EOL>
|
Put the bar where it's supposed to be, and size it in proportion to
the size of the scrollable area.
|
f8977:c6:m5
|
def upd_scroll(self, *args):
|
att = '<STR_LIT>'.format(<EOL>'<STR_LIT:x>' if self.orientation == '<STR_LIT>' else '<STR_LIT:y>'<EOL>)<EOL>self._scroll = getattr(self.deckbuilder, att)[self.deckidx]<EOL>
|
Update my own ``scroll`` property to where my deck is actually
scrolled.
|
f8977:c6:m6
|
def on_deckbuilder(self, *args):
|
if self.deckbuilder is None:<EOL><INDENT>return<EOL><DEDENT>att = '<STR_LIT>'.format(<EOL>'<STR_LIT:x>' if self.orientation == '<STR_LIT>' else '<STR_LIT:y>'<EOL>)<EOL>offs = getattr(self.deckbuilder, att)<EOL>if len(offs) <= self.deckidx:<EOL><INDENT>Clock.schedule_once(self.on_deckbuilder, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>self.bind(scroll=self.handle_scroll)<EOL>self.deckbuilder.bind(**{att: self.upd_scroll})<EOL>self.upd_scroll()<EOL>self.deckbuilder._trigger_layout()<EOL>
|
Bind my deckbuilder to update my ``scroll``, and my ``scroll`` to
update my deckbuilder.
|
f8977:c6:m7
|
def handle_scroll(self, *args):
|
if '<STR_LIT:bar>' not in self.ids:<EOL><INDENT>Clock.schedule_once(self.handle_scroll, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>att = '<STR_LIT>'.format(<EOL>'<STR_LIT:x>' if self.orientation == '<STR_LIT>' else '<STR_LIT:y>'<EOL>)<EOL>offs = list(getattr(self.deckbuilder, att))<EOL>if len(offs) <= self.deckidx:<EOL><INDENT>Clock.schedule_once(self.on_scroll, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>offs[self.deckidx] = self._scroll<EOL>setattr(self.deckbuilder, att, offs)<EOL>self.deckbuilder._trigger_layout()<EOL>
|
When my ``scroll`` changes, tell my deckbuilder how it's scrolled
now.
|
f8977:c6:m8
|
def bar_touched(self, bar, touch):
|
self.scrolling = True<EOL>self._start_bar_pos_hint = get_pos_hint(bar.pos_hint, *bar.size_hint)<EOL>self._start_touch_pos_hint = (<EOL>touch.x / self.width,<EOL>touch.y / self.height<EOL>)<EOL>self._start_bar_touch_hint = (<EOL>self._start_touch_pos_hint[<NUM_LIT:0>] - self._start_bar_pos_hint[<NUM_LIT:0>],<EOL>self._start_touch_pos_hint[<NUM_LIT:1>] - self._start_bar_pos_hint[<NUM_LIT:1>]<EOL>)<EOL>touch.grab(self)<EOL>
|
Start scrolling, and record where I started scrolling.
|
f8977:c6:m9
|
def on_touch_move(self, touch):
|
if not self.scrolling or '<STR_LIT:bar>' not in self.ids:<EOL><INDENT>touch.ungrab(self)<EOL>return<EOL><DEDENT>touch.push()<EOL>touch.apply_transform_2d(self.parent.to_local)<EOL>touch.apply_transform_2d(self.to_local)<EOL>if self.orientation == '<STR_LIT>':<EOL><INDENT>hint_right_of_bar = (touch.x - self.ids.bar.x) / self.width<EOL>hint_correction = hint_right_of_bar - self._start_bar_touch_hint[<NUM_LIT:0>]<EOL>self.scroll += hint_correction<EOL><DEDENT>else: <EOL><INDENT>hint_above_bar = (touch.y - self.ids.bar.y) / self.height<EOL>hint_correction = hint_above_bar - self._start_bar_touch_hint[<NUM_LIT:1>]<EOL>self.scroll += hint_correction<EOL><DEDENT>touch.pop()<EOL>
|
Move the scrollbar to the touch, and update my ``scroll``
accordingly.
|
f8977:c6:m10
|
def on_touch_up(self, touch):
|
self.scrolling = False<EOL>
|
Stop scrolling.
|
f8977:c6:m11
|
def munge_source(v):
|
lines = v.split('<STR_LIT:\n>')<EOL>if not lines:<EOL><INDENT>return tuple(), '<STR_LIT>'<EOL><DEDENT>firstline = lines[<NUM_LIT:0>].lstrip()<EOL>while firstline == '<STR_LIT>' or firstline[<NUM_LIT:0>] == '<STR_LIT:@>':<EOL><INDENT>del lines[<NUM_LIT:0>]<EOL>firstline = lines[<NUM_LIT:0>].lstrip()<EOL><DEDENT>if not lines:<EOL><INDENT>return tuple(), '<STR_LIT>'<EOL><DEDENT>params = tuple(<EOL>parm.strip() for parm in<EOL>sig_ex.match(lines[<NUM_LIT:0>]).group(<NUM_LIT:1>).split('<STR_LIT:U+002C>')<EOL>)<EOL>del lines[<NUM_LIT:0>]<EOL>if not lines:<EOL><INDENT>return params, '<STR_LIT>'<EOL><DEDENT>if lines and lines[-<NUM_LIT:1>].strip() == '<STR_LIT>':<EOL><INDENT>del lines[-<NUM_LIT:1>]<EOL><DEDENT>return params, dedent('<STR_LIT:\n>'.join(lines))<EOL>
|
Take Python source code, return a pair of its parameters and the rest of it dedented
|
f8978:m0
|
def redata(self, *args, **kwargs):
|
select_name = kwargs.get('<STR_LIT>')<EOL>if not self.store:<EOL><INDENT>Clock.schedule_once(self.redata)<EOL>return<EOL><DEDENT>self.data = list(map(self.munge, enumerate(self._iter_keys())))<EOL>if select_name:<EOL><INDENT>self._trigger_select_name(select_name)<EOL><DEDENT>
|
Update my ``data`` to match what's in my ``store``
|
f8978:c2:m6
|
def select_name(self, name, *args):
|
self.boxl.select_node(self._name2i[name])<EOL>
|
Select an item by its name, highlighting
|
f8978:c2:m8
|
def save(self, *args):
|
if self.name_wid is None or self.store is None:<EOL><INDENT>Logger.debug("<STR_LIT>".format(type(self).__name__))<EOL>return<EOL><DEDENT>if not (self.name_wid.text or self.name_wid.hint_text):<EOL><INDENT>Logger.debug("<STR_LIT>".format(type(self).__name__))<EOL>return<EOL><DEDENT>if self.name_wid.text and self.name_wid.text[<NUM_LIT:0>] in string.digits + string.whitespace + string.punctuation:<EOL><INDENT>Logger.warning("<STR_LIT>".format(type(self).__name__))<EOL>return<EOL><DEDENT>if hasattr(self, '<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>parse(self.source)<EOL><DEDENT>except SyntaxError:<EOL><INDENT>Logger.debug("<STR_LIT>".format(type(self).__name__))<EOL>return<EOL><DEDENT><DEDENT>do_redata = False<EOL>if self.name_wid.text:<EOL><INDENT>if (<EOL>self.name_wid.hint_text and<EOL>self.name_wid.hint_text != self.name_wid.text and<EOL>hasattr(self.store, self.name_wid.hint_text)<EOL>):<EOL><INDENT>delattr(self.store, self.name_wid.hint_text)<EOL>do_redata = True<EOL><DEDENT>if (<EOL>not hasattr(self.store, self.name_wid.text) or<EOL>getattr(self.store, self.name_wid.text) != self.source<EOL>):<EOL><INDENT>Logger.debug("<STR_LIT>".format(type(self).__name__))<EOL>setattr(self.store, self.name_wid.text, self.source)<EOL>do_redata = True<EOL><DEDENT><DEDENT>elif self.name_wid.hint_text:<EOL><INDENT>if (<EOL>not hasattr(self.store, self.name_wid.hint_text) or<EOL>getattr(self.store, self.name_wid.hint_text) != self.source<EOL>):<EOL><INDENT>Logger.debug("<STR_LIT>".format(type(self).__name__))<EOL>setattr(self.store, self.name_wid.hint_text, self.source)<EOL>do_redata = True<EOL><DEDENT><DEDENT>return do_redata<EOL>
|
Put text in my store, return True if it changed
|
f8978:c5:m0
|
def delete(self, *args):
|
key = self.name_wid.text or self.name_wid.hint_text<EOL>if not hasattr(self.store, key):<EOL><INDENT>return<EOL><DEDENT>delattr(self.store, key)<EOL>try:<EOL><INDENT>return min(kee for kee in dir(self.store) if kee > key)<EOL><DEDENT>except ValueError:<EOL><INDENT>return '<STR_LIT:+>'<EOL><DEDENT>
|
Remove the currently selected item from my store
|
f8978:c5:m1
|
def upd_textures(self, *args):
|
if self.canvas is None:<EOL><INDENT>Clock.schedule_once(self.upd_textures, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>for name in list(self.swatches.keys()):<EOL><INDENT>if name not in self.atlas.textures:<EOL><INDENT>self.remove_widget(self.swatches[name])<EOL>del self.swatches[name]<EOL><DEDENT><DEDENT>for (name, tex) in self.atlas.textures.items():<EOL><INDENT>if name in self.swatches and self.swatches[name] != tex:<EOL><INDENT>self.remove_widget(self.swatches[name])<EOL><DEDENT>if name not in self.swatches or self.swatches[name] != tex:<EOL><INDENT>self.swatches[name] = SwatchButton(<EOL>name=name,<EOL>tex=tex,<EOL>size_hint=(None, None),<EOL>size=self.swatch_size<EOL>)<EOL>self.add_widget(self.swatches[name])<EOL><DEDENT><DEDENT>
|
Create one :class:`SwatchButton` for each texture
|
f8981:c1:m3
|
def on_state(self, *args):
|
<EOL>if self.state == '<STR_LIT>':<EOL><INDENT>self.rulesview.rule = self.rule<EOL>for button in self.ruleslist.children[<NUM_LIT:0>].children:<EOL><INDENT>if button != self:<EOL><INDENT>button.state = '<STR_LIT>'<EOL><DEDENT><DEDENT><DEDENT>
|
If I'm pressed, unpress all other buttons in the ruleslist
|
f8982:c0:m0
|
def on_rulebook(self, *args):
|
if self.rulebook is None:<EOL><INDENT>return<EOL><DEDENT>self.rulebook.connect(self._trigger_redata, weak=False)<EOL>self.redata()<EOL>
|
Make sure to update when the rulebook changes
|
f8982:c1:m0
|
def redata(self, *args):
|
if self.rulesview is None:<EOL><INDENT>Clock.schedule_once(self.redata, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>data = [<EOL>{'<STR_LIT>': self.rulesview, '<STR_LIT>': rule, '<STR_LIT:index>': i, '<STR_LIT>': self}<EOL>for i, rule in enumerate(self.rulebook)<EOL>]<EOL>self.data = data<EOL>
|
Make my data represent what's in my rulebook right now
|
f8982:c1:m1
|
def on_rule(self, *args):
|
if self.rule is None:<EOL><INDENT>return<EOL><DEDENT>self.rule.connect(self._listen_to_rule)<EOL>
|
Make sure to update when the rule changes
|
f8982:c2:m0
|
def finalize(self, *args):
|
if not self.canvas:<EOL><INDENT>Clock.schedule_once(self.finalize, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>deck_builder_kwargs = {<EOL>'<STR_LIT>': {'<STR_LIT:x>': <NUM_LIT:0>, '<STR_LIT:y>': <NUM_LIT:0>},<EOL>'<STR_LIT>': {'<STR_LIT:x>': <NUM_LIT>, '<STR_LIT>': <NUM_LIT>},<EOL>'<STR_LIT>': (<NUM_LIT>, <NUM_LIT>),<EOL>'<STR_LIT>': (<NUM_LIT:0>, -<NUM_LIT:0.1>),<EOL>'<STR_LIT>': <NUM_LIT><EOL>}<EOL>self._tabs = TabbedPanel(<EOL>size=self.size,<EOL>pos=self.pos,<EOL>do_default_tab=False<EOL>)<EOL>self.bind(<EOL>size=self._tabs.setter('<STR_LIT:size>'),<EOL>pos=self._tabs.setter('<STR_LIT>')<EOL>)<EOL>self.add_widget(self._tabs)<EOL>for functyp in '<STR_LIT>', '<STR_LIT>', '<STR_LIT:action>':<EOL><INDENT>tab = TabbedPanelItem(text=functyp.capitalize())<EOL>setattr(self, '<STR_LIT>'.format(functyp), tab)<EOL>self._tabs.add_widget(getattr(self, '<STR_LIT>'.format(functyp)))<EOL>builder = DeckBuilderView(**deck_builder_kwargs)<EOL>setattr(self, '<STR_LIT>'.format(functyp), builder)<EOL>builder.bind(decks=getattr(self, '<STR_LIT>'.format(functyp)))<EOL>scroll_left = DeckBuilderScrollBar(<EOL>size_hint_x=<NUM_LIT>,<EOL>pos_hint={'<STR_LIT:x>': <NUM_LIT:0>, '<STR_LIT:y>': <NUM_LIT:0>},<EOL>deckbuilder=builder,<EOL>deckidx=<NUM_LIT:0>,<EOL>scroll_min=<NUM_LIT:0><EOL>)<EOL>setattr(self, '<STR_LIT>' + functyp, scroll_left)<EOL>scroll_right = DeckBuilderScrollBar(<EOL>size_hint_x=<NUM_LIT>,<EOL>pos_hint={'<STR_LIT:right>': <NUM_LIT:1>, '<STR_LIT:y>': <NUM_LIT:0>},<EOL>deckbuilder=builder,<EOL>deckidx=<NUM_LIT:1>,<EOL>scroll_min=<NUM_LIT:0><EOL>)<EOL>setattr(self, '<STR_LIT>' + functyp, scroll_right)<EOL>layout = FloatLayout()<EOL>setattr(self, '<STR_LIT>'.format(functyp), layout)<EOL>tab.add_widget(layout)<EOL>layout.add_widget(builder)<EOL>layout.add_widget(scroll_left)<EOL>layout.add_widget(scroll_right)<EOL>layout.add_widget(<EOL>Label(<EOL>text='<STR_LIT>',<EOL>pos_hint={'<STR_LIT>': <NUM_LIT:0.1>, '<STR_LIT>': <NUM_LIT>},<EOL>size_hint=(None, None)<EOL>)<EOL>)<EOL>layout.add_widget(<EOL>Label(<EOL>text='<STR_LIT>',<EOL>pos_hint={'<STR_LIT>': <NUM_LIT:0.5>, '<STR_LIT>': <NUM_LIT>},<EOL>size_hint=(None, None)<EOL>)<EOL>)<EOL>self.bind(rule=getattr(self, '<STR_LIT>'.format(functyp)))<EOL><DEDENT>
|
Add my tabs
|
f8982:c2:m3
|
def get_functions_cards(self, what, allfuncs):
|
if not self.rule:<EOL><INDENT>return [], []<EOL><DEDENT>rulefuncnames = getattr(self.rule, what+'<STR_LIT:s>')<EOL>unused = [<EOL>Card(<EOL>ud={<EOL>'<STR_LIT:type>': what,<EOL>'<STR_LIT>': name,<EOL>'<STR_LIT>': sig<EOL>},<EOL>headline_text=name,<EOL>show_art=False,<EOL>midline_text=what.capitalize(),<EOL>text=source<EOL>)<EOL>for (name, source, sig) in allfuncs if name not in rulefuncnames<EOL>]<EOL>used = [<EOL>Card(<EOL>ud={<EOL>'<STR_LIT:type>': what,<EOL>'<STR_LIT>': name,<EOL>},<EOL>headline_text=name,<EOL>show_art=False,<EOL>midline_text=what.capitalize(),<EOL>text=str(getattr(getattr(self.engine, what), name))<EOL>)<EOL>for name in rulefuncnames<EOL>]<EOL>return used, unused<EOL>
|
Return a pair of lists of Card widgets for used and unused functions.
:param what: a string: 'trigger', 'prereq', or 'action'
:param allfuncs: a sequence of functions' (name, sourcecode, signature)
|
f8982:c2:m4
|
def set_functions(self, what, allfuncs):
|
setattr(getattr(self, '<STR_LIT>'.format(what)), '<STR_LIT>', self.get_functions_cards(what, allfuncs))<EOL>
|
Set the cards in the ``what`` builder to ``allfuncs``
:param what: a string, 'trigger', 'prereq', or 'action'
:param allfuncs: a sequence of triples of (name, sourcecode, signature) as taken by my
``get_function_cards`` method.
|
f8982:c2:m5
|
def pull_triggers(self, *args):
|
self._trigger_builder.decks = self._pull_functions('<STR_LIT>')<EOL>
|
Refresh the cards in the trigger builder
|
f8982:c2:m7
|
def pull_prereqs(self, *args):
|
self._prereq_builder.decks = self._pull_functions('<STR_LIT>')<EOL>
|
Refresh the cards in the prereq builder
|
f8982:c2:m8
|
def pull_actions(self, *args):
|
self._action_builder.decks = self._pull_functions('<STR_LIT:action>')<EOL>
|
Refresh the cards in the action builder
|
f8982:c2:m9
|
def inspect_func(self, namesrc):
|
(name, src) = namesrc<EOL>glbls = {}<EOL>lcls = {}<EOL>exec(src, glbls, lcls)<EOL>assert name in lcls<EOL>func = lcls[name]<EOL>return name, src, signature(func)<EOL>
|
Take a function's (name, sourcecode) and return a triple of (name, sourcecode, signature)
|
f8982:c2:m10
|
def _upd_unused(self, what):
|
builder = getattr(self, '<STR_LIT>'.format(what))<EOL>updtrig = getattr(self, '<STR_LIT>'.format(what))<EOL>builder.unbind(decks=updtrig)<EOL>funcs = OrderedDict()<EOL>cards = list(self._action_builder.decks[<NUM_LIT:1>])<EOL>cards.reverse()<EOL>for card in cards:<EOL><INDENT>funcs[card.ud['<STR_LIT>']] = card<EOL><DEDENT>for card in self._action_builder.decks[<NUM_LIT:0>]:<EOL><INDENT>if card.ud['<STR_LIT>'] not in funcs:<EOL><INDENT>funcs[card.ud['<STR_LIT>']] = card.copy()<EOL><DEDENT><DEDENT>unused = list(funcs.values())<EOL>unused.reverse()<EOL>builder.decks[<NUM_LIT:1>] = unused<EOL>builder.bind(decks=updtrig)<EOL>
|
Make sure to have exactly one copy of every valid function in the
"unused" pile on the right.
Doesn't read from the database.
:param what: a string, 'trigger', 'prereq', or 'action'
|
f8982:c2:m12
|
def disable_input(self, cb=None):
|
self.disabled = True<EOL>if cb:<EOL><INDENT>cb()<EOL><DEDENT>
|
Set ``self.disabled`` to ``True``, then call ``cb`` if provided
:param cb: callback function for after disabling
:return: ``None``
|
f8983:c0:m0
|
def enable_input(self, cb=None):
|
if cb:<EOL><INDENT>cb()<EOL><DEDENT>self.disabled = False<EOL>
|
Call ``cb`` if provided, then set ``self.disabled`` to ``False``
:param cb: callback function for before enabling
:return: ``None``
|
f8983:c0:m1
|
def wait_travel(self, character, thing, dest, cb=None):
|
self.disable_input()<EOL>self.app.wait_travel(character, thing, dest, cb=partial(self.enable_input, cb))<EOL>
|
Schedule a thing to travel someplace, then wait for it to finish.
:param character: name of the character
:param thing: name of the thing that will travel
:param dest: name of the place it will travel to
:param cb: callback function for when it's done, optional
:return: ``None``
|
f8983:c0:m2
|
def wait_turns(self, turns, cb=None):
|
self.disable_input()<EOL>self.app.wait_turns(turns, cb=partial(self.enable_input, cb))<EOL>
|
Call ``self.app.engine.next_turn()`` ``n`` times, waiting ``self.app.turn_length`` in between
Disables input for the duration.
:param turns: number of turns to wait
:param cb: function to call when done waiting, optional
:return: ``None``
|
f8983:c0:m3
|
def wait_command(self, start_func, turns=<NUM_LIT:1>, end_func=None):
|
self.disable_input()<EOL>start_func()<EOL>self.app.wait_turns(turns, cb=partial(self.enable_input, end_func))<EOL>
|
Call ``start_func``, wait ``turns``, and then call ``end_func`` if provided
Disables input for the duration.
:param start_func: function to call just after disabling input
:param turns: number of turns to wait
:param end_func: function to call just before re-enabling input
:return: ``None``
|
f8983:c0:m4
|
def wait_travel_command(self, character, thing, dest, start_func, turns=<NUM_LIT:1>, end_func=lambda: None):
|
self.disable_input()<EOL>self.app.wait_travel_command(character, thing, dest, start_func, turns, partial(self.enable_input, end_func))<EOL>
|
Schedule a thing to travel someplace and do something, then wait for it to finish.
Input will be disabled for the duration.
:param character: name of the character
:param thing: name of the thing
:param dest: name of the destination (a place)
:param start_func: function to call when the thing gets to dest
:param turns: number of turns to wait after start_func before re-enabling input
:param end_func: optional. Function to call after waiting ``turns`` after start_func
:return: ``None``
|
f8983:c0:m5
|
def wait_turns(self, turns, dt=None, *, cb=None):
|
if turns == <NUM_LIT:0>:<EOL><INDENT>if cb:<EOL><INDENT>cb()<EOL><DEDENT>return<EOL><DEDENT>self.engine.next_turn()<EOL>turns -= <NUM_LIT:1><EOL>Clock.schedule_once(partial(self.wait_turns, turns, cb=cb), self.turn_length)<EOL>
|
Call ``self.engine.next_turn()`` ``n`` times, waiting ``self.turn_length`` in between
If provided, call ``cb`` when done.
:param turns: number of turns to wait
:param dt: unused, just satisfies the clock
:param cb: callback function to call when done, optional
:return: ``None``
|
f8983:c2:m0
|
def wait_travel(self, character, thing, dest, cb=None):
|
self.wait_turns(self.engine.character[character].thing[thing].travel_to(dest), cb=cb)<EOL>
|
Schedule a thing to travel someplace, then wait for it to finish, and call ``cb`` if provided
:param character: name of the character
:param thing: name of the thing
:param dest: name of the destination (a place)
:param cb: function to be called when I'm done
:return: ``None``
|
f8983:c2:m1
|
def wait_command(self, start_func, turns=<NUM_LIT:1>, end_func=None):
|
start_func()<EOL>self.wait_turns(turns, cb=end_func)<EOL>
|
Call ``start_func``, and wait to call ``end_func`` after simulating ``turns`` (default 1)
:param start_func: function to call before waiting
:param turns: number of turns to wait
:param end_func: function to call after waiting
:return: ``None``
|
f8983:c2:m2
|
def wait_travel_command(self, character, thing, dest, start_func, turns=<NUM_LIT:1>, end_func=None):
|
self.wait_travel(character, thing, dest, cb=partial(<EOL>self.wait_command, start_func, turns, end_func)<EOL>)<EOL>
|
Schedule a thing to travel someplace and do something, then wait for it to finish.
:param character: name of the character
:param thing: name of the thing
:param dest: name of the destination (a place)
:param start_func: function to call when the thing gets to dest
:param turns: number of turns to wait after start_func before re-enabling input
:param end_func: optional. Function to call after waiting ``turns`` after start_func
:return: ``None``
|
f8983:c2:m3
|
def on_pause(self):
|
self.engine.commit()<EOL>self.config.write()<EOL>
|
Sync the database with the current state of the game.
|
f8983:c2:m9
|
def on_stop(self, *largs):
|
self.procman.shutdown()<EOL>self.config.write()<EOL>
|
Sync the database, wrap up the game, and halt.
|
f8983:c2:m10
|
def new_stat(self):
|
key = self.ids.newstatkey.text<EOL>value = self.ids.newstatval.text<EOL>if not (key and value):<EOL><INDENT>return<EOL><DEDENT>try:<EOL><INDENT>self.proxy[key] = self.engine.unpack(value)<EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>self.proxy[key] = value<EOL><DEDENT>self.ids.newstatkey.text = '<STR_LIT>'<EOL>self.ids.newstatval.text = '<STR_LIT>'<EOL>
|
Look at the key and value that the user has entered into the stat
configurator, and set them on the currently selected
entity.
|
f8984:c7:m0
|
def __repr__(self):
|
return '<STR_LIT>'.format(<EOL>self.name,<EOL>self.loc_name,<EOL>id(self)<EOL>)<EOL>
|
Give my ``thing``'s name and its location's name.
|
f8987:c0:m10
|
def normalize_layout(l):
|
xs = []<EOL>ys = []<EOL>ks = []<EOL>for (k, (x, y)) in l.items():<EOL><INDENT>xs.append(x)<EOL>ys.append(y)<EOL>ks.append(k)<EOL><DEDENT>minx = np.min(xs)<EOL>maxx = np.max(xs)<EOL>try:<EOL><INDENT>xco = <NUM_LIT> / (maxx - minx)<EOL>xnorm = np.multiply(np.subtract(xs, [minx] * len(xs)), xco)<EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>xnorm = np.array([<NUM_LIT:0.5>] * len(xs))<EOL><DEDENT>miny = np.min(ys)<EOL>maxy = np.max(ys)<EOL>try:<EOL><INDENT>yco = <NUM_LIT> / (maxy - miny)<EOL>ynorm = np.multiply(np.subtract(ys, [miny] * len(ys)), yco)<EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>ynorm = np.array([<NUM_LIT:0.5>] * len(ys))<EOL><DEDENT>return dict(zip(ks, zip(map(float, xnorm), map(float, ynorm))))<EOL>
|
Make sure all the spots in a layout are where you can click.
Returns a copy of the layout with all spot coordinates are
normalized to within (0.0, 0.98).
|
f8988:m0
|
def on_touch_down(self, touch):
|
if hasattr(self, '<STR_LIT>') and self._lasttouch == touch:<EOL><INDENT>return<EOL><DEDENT>if not self.collide_point(*touch.pos):<EOL><INDENT>return<EOL><DEDENT>touch.push()<EOL>touch.apply_transform_2d(self.to_local)<EOL>if self.app.selection:<EOL><INDENT>if self.app.selection.collide_point(*touch.pos):<EOL><INDENT>Logger.debug("<STR_LIT>")<EOL>touch.grab(self.app.selection)<EOL><DEDENT><DEDENT>pawns = list(self.pawns_at(*touch.pos))<EOL>if pawns:<EOL><INDENT>Logger.debug("<STR_LIT>".format(len(pawns)))<EOL>self.selection_candidates = pawns<EOL>if self.app.selection in self.selection_candidates:<EOL><INDENT>self.selection_candidates.remove(self.app.selection)<EOL><DEDENT>touch.pop()<EOL>return True<EOL><DEDENT>spots = list(self.spots_at(*touch.pos))<EOL>if spots:<EOL><INDENT>Logger.debug("<STR_LIT>".format(len(spots)))<EOL>self.selection_candidates = spots<EOL>if self.adding_portal:<EOL><INDENT>self.origspot = self.selection_candidates.pop(<NUM_LIT:0>)<EOL>self.protodest = Dummy(<EOL>name='<STR_LIT>',<EOL>pos=touch.pos,<EOL>size=(<NUM_LIT:0>, <NUM_LIT:0>)<EOL>)<EOL>self.add_widget(self.protodest)<EOL>self.protodest.on_touch_down(touch)<EOL>self.protoportal = self.proto_arrow_cls(<EOL>origin=self.origspot,<EOL>destination=self.protodest<EOL>)<EOL>self.add_widget(self.protoportal)<EOL>if self.reciprocal_portal:<EOL><INDENT>self.protoportal2 = self.proto_arrow_cls(<EOL>destination=self.origspot,<EOL>origin=self.protodest<EOL>)<EOL>self.add_widget(self.protoportal2)<EOL><DEDENT><DEDENT>touch.pop()<EOL>return True<EOL><DEDENT>arrows = list(self.arrows_at(*touch.pos))<EOL>if arrows:<EOL><INDENT>Logger.debug("<STR_LIT>".format(len(arrows)))<EOL>self.selection_candidates = arrows<EOL>if self.app.selection in self.selection_candidates:<EOL><INDENT>self.selection_candidates.remove(self.app.selection)<EOL><DEDENT>touch.pop()<EOL>return True<EOL><DEDENT>touch.pop()<EOL>
|
Check for collisions and select an appropriate entity.
|
f8988:c3:m1
|
def on_touch_move(self, touch):
|
if hasattr(self, '<STR_LIT>') and self._lasttouch == touch:<EOL><INDENT>return<EOL><DEDENT>if self.app.selection in self.selection_candidates:<EOL><INDENT>self.selection_candidates.remove(self.app.selection)<EOL><DEDENT>if self.app.selection:<EOL><INDENT>if not self.selection_candidates:<EOL><INDENT>self.keep_selection = True<EOL><DEDENT>ret = super().on_touch_move(touch)<EOL>return ret<EOL><DEDENT>elif self.selection_candidates:<EOL><INDENT>for cand in self.selection_candidates:<EOL><INDENT>if cand.collide_point(*touch.pos):<EOL><INDENT>self.app.selection = cand<EOL>cand.selected = True<EOL>touch.grab(cand)<EOL>ret = super().on_touch_move(touch)<EOL>return ret<EOL><DEDENT><DEDENT><DEDENT>
|
If an entity is selected, drag it.
|
f8988:c3:m2
|
def portal_touch_up(self, touch):
|
try:<EOL><INDENT>destspot = next(self.spots_at(*touch.pos))<EOL>orig = self.origspot.proxy<EOL>dest = destspot.proxy<EOL>if not(<EOL>orig.name in self.character.portal and<EOL>dest.name in self.character.portal[orig.name]<EOL>):<EOL><INDENT>port = self.character.new_portal(<EOL>orig.name,<EOL>dest.name<EOL>)<EOL>self.arrowlayout.add_widget(<EOL>self.make_arrow(port)<EOL>)<EOL>if (<EOL>hasattr(self, '<STR_LIT>') and not(<EOL>orig.name in self.character.preportal and<EOL>dest.name in self.character.preportal[orig.name]<EOL>)<EOL>):<EOL><INDENT>deport = self.character.new_portal(<EOL>dest.name,<EOL>orig.name<EOL>)<EOL>self.arrowlayout.add_widget(<EOL>self.make_arrow(deport)<EOL>)<EOL><DEDENT><DEDENT><DEDENT>except StopIteration:<EOL><INDENT>pass<EOL><DEDENT>self.remove_widget(self.protoportal)<EOL>if hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.remove_widget(self.protoportal2)<EOL>del self.protoportal2<EOL><DEDENT>self.remove_widget(self.protodest)<EOL>del self.protoportal<EOL>del self.protodest<EOL>
|
Try to create a portal between the spots the user chose.
|
f8988:c3:m3
|
def on_touch_up(self, touch):
|
if hasattr(self, '<STR_LIT>') and self._lasttouch == touch:<EOL><INDENT>return<EOL><DEDENT>self._lasttouch = touch<EOL>touch.push()<EOL>touch.apply_transform_2d(self.to_local)<EOL>if hasattr(self, '<STR_LIT>'):<EOL><INDENT>Logger.debug("<STR_LIT>")<EOL>touch.ungrab(self)<EOL>ret = self.portal_touch_up(touch)<EOL>touch.pop()<EOL>return ret<EOL><DEDENT>if self.app.selection and hasattr(self.app.selection, '<STR_LIT>'):<EOL><INDENT>self.app.selection.dispatch('<STR_LIT>', touch)<EOL><DEDENT>for candidate in self.selection_candidates:<EOL><INDENT>if candidate == self.app.selection:<EOL><INDENT>continue<EOL><DEDENT>if candidate.collide_point(*touch.pos):<EOL><INDENT>Logger.debug("<STR_LIT>" + repr(candidate))<EOL>if hasattr(candidate, '<STR_LIT>'):<EOL><INDENT>candidate.selected = True<EOL><DEDENT>if hasattr(self.app.selection, '<STR_LIT>'):<EOL><INDENT>self.app.selection.selected = False<EOL><DEDENT>self.app.selection = candidate<EOL>self.keep_selection = True<EOL>parent = candidate.parent<EOL>parent.remove_widget(candidate)<EOL>parent.add_widget(candidate)<EOL>break<EOL><DEDENT><DEDENT>if not self.keep_selection:<EOL><INDENT>Logger.debug("<STR_LIT>" + repr(self.app.selection))<EOL>if hasattr(self.app.selection, '<STR_LIT>'):<EOL><INDENT>self.app.selection.selected = False<EOL><DEDENT>self.app.selection = None<EOL><DEDENT>self.keep_selection = False<EOL>touch.ungrab(self)<EOL>touch.pop()<EOL>return<EOL>
|
Delegate touch handling if possible, else select something.
|
f8988:c3:m4
|
def on_parent(self, *args):
|
if not self.parent or hasattr(self, '<STR_LIT>'):<EOL><INDENT>return<EOL><DEDENT>if not self.wallpaper_path:<EOL><INDENT>Logger.debug("<STR_LIT>")<EOL>Clock.schedule_once(self.on_parent, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>self._parented = True<EOL>self.wallpaper = Image(source=self.wallpaper_path)<EOL>self.bind(wallpaper_path=self._pull_image)<EOL>self._pull_size()<EOL>self.kvlayoutback = KvLayoutBack(**self.widkwargs)<EOL>self.arrowlayout = ArrowLayout(**self.widkwargs)<EOL>self.spotlayout = FinalLayout(**self.widkwargs)<EOL>self.kvlayoutfront = KvLayoutFront(**self.widkwargs)<EOL>for wid in self.wids:<EOL><INDENT>self.add_widget(wid)<EOL>wid.pos = <NUM_LIT:0>, <NUM_LIT:0><EOL>wid.size = self.size<EOL>if wid is not self.wallpaper:<EOL><INDENT>self.bind(size=wid.setter('<STR_LIT:size>'))<EOL><DEDENT><DEDENT>self.update()<EOL>
|
Create some subwidgets and trigger the first update.
|
f8988:c3:m7
|
def make_pawn(self, thing):
|
if thing["<STR_LIT:name>"] in self.pawn:<EOL><INDENT>raise KeyError("<STR_LIT>")<EOL><DEDENT>r = self.pawn_cls(<EOL>board=self,<EOL>thing=thing<EOL>)<EOL>self.pawn[thing["<STR_LIT:name>"]] = r<EOL>return r<EOL>
|
Make a :class:`Pawn` to represent a :class:`Thing`, store it, and
return it.
|
f8988:c3:m12
|
def make_spot(self, place):
|
if place["<STR_LIT:name>"] in self.spot:<EOL><INDENT>raise KeyError("<STR_LIT>")<EOL><DEDENT>r = self.spot_cls(<EOL>board=self,<EOL>place=place<EOL>)<EOL>self.spot[place["<STR_LIT:name>"]] = r<EOL>if '<STR_LIT>' in place and '<STR_LIT>' in place:<EOL><INDENT>r.pos = (<EOL>self.width * place['<STR_LIT>'],<EOL>self.height * place['<STR_LIT>']<EOL>)<EOL><DEDENT>return r<EOL>
|
Make a :class:`Spot` to represent a :class:`Place`, store it, and
return it.
|
f8988:c3:m13
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.