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_... | 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:\\>... | 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.
Whitesp... | 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><INDE... | 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 ov... | 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... | 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
... | 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(... | 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... | "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) = \\s... | 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=sel... | 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... | 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>re... | 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 < d... | 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['<... | 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_LI... | 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<E... | 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>'<S... | 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._tri... | 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.dec... | 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.dec... | 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 * sel... | 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 ... | 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><INDE... | 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><... | 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>t... | 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>i... | 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.inser... | 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:<E... | 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... | 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><INDEN... | 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._s... | 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) /... | 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 l... | 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_wi... | 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 se... | 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>'<ST... | 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<... | 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><DED... | 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
:ret... | 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... | 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:... | 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>'<E... | 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 ZeroDiv... | 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>Lo... | 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... | 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.a... | 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.... | 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(wallpa... | 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.heigh... | 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.