repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1 value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
LogicalDash/LiSE | LiSE/LiSE/handle.py | EngineHandle.node_stat_copy | def node_stat_copy(self, node_or_char, node=None):
"""Return a node's stats, prepared for pickling, in a dictionary."""
if node is None:
node = node_or_char
else:
node = self._real.character[node_or_char].node[node]
return {
k: v.unwrap() if hasattr(v, 'unwrap') and not hasattr(v, 'no_unwrap') else v
for (k, v) in node.items() if k not in {
'character',
'name',
'arrival_time',
'next_arrival_time'
}
} | python | def node_stat_copy(self, node_or_char, node=None):
"""Return a node's stats, prepared for pickling, in a dictionary."""
if node is None:
node = node_or_char
else:
node = self._real.character[node_or_char].node[node]
return {
k: v.unwrap() if hasattr(v, 'unwrap') and not hasattr(v, 'no_unwrap') else v
for (k, v) in node.items() if k not in {
'character',
'name',
'arrival_time',
'next_arrival_time'
}
} | [
"def",
"node_stat_copy",
"(",
"self",
",",
"node_or_char",
",",
"node",
"=",
"None",
")",
":",
"if",
"node",
"is",
"None",
":",
"node",
"=",
"node_or_char",
"else",
":",
"node",
"=",
"self",
".",
"_real",
".",
"character",
"[",
"node_or_char",
"]",
"."... | Return a node's stats, prepared for pickling, in a dictionary. | [
"Return",
"a",
"node",
"s",
"stats",
"prepared",
"for",
"pickling",
"in",
"a",
"dictionary",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/handle.py#L691-L705 | train | 32,900 |
LogicalDash/LiSE | LiSE/LiSE/handle.py | EngineHandle.node_stat_delta | def node_stat_delta(self, char, node, *, store=True):
"""Return a dictionary describing changes to a node's stats since the
last time you looked at it.
Deleted keys have the value ``None``. If the node's been deleted, this
returns ``None``.
"""
try:
old = self._node_stat_cache[char].get(node, {})
new = self.node_stat_copy(self._real.character[char].node[node])
if store:
self._node_stat_cache[char][node] = new
r = dict_delta(old, new)
return r
except KeyError:
return None | python | def node_stat_delta(self, char, node, *, store=True):
"""Return a dictionary describing changes to a node's stats since the
last time you looked at it.
Deleted keys have the value ``None``. If the node's been deleted, this
returns ``None``.
"""
try:
old = self._node_stat_cache[char].get(node, {})
new = self.node_stat_copy(self._real.character[char].node[node])
if store:
self._node_stat_cache[char][node] = new
r = dict_delta(old, new)
return r
except KeyError:
return None | [
"def",
"node_stat_delta",
"(",
"self",
",",
"char",
",",
"node",
",",
"*",
",",
"store",
"=",
"True",
")",
":",
"try",
":",
"old",
"=",
"self",
".",
"_node_stat_cache",
"[",
"char",
"]",
".",
"get",
"(",
"node",
",",
"{",
"}",
")",
"new",
"=",
... | Return a dictionary describing changes to a node's stats since the
last time you looked at it.
Deleted keys have the value ``None``. If the node's been deleted, this
returns ``None``. | [
"Return",
"a",
"dictionary",
"describing",
"changes",
"to",
"a",
"node",
"s",
"stats",
"since",
"the",
"last",
"time",
"you",
"looked",
"at",
"it",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/handle.py#L707-L723 | train | 32,901 |
LogicalDash/LiSE | LiSE/LiSE/handle.py | EngineHandle.character_nodes_stat_delta | def character_nodes_stat_delta(self, char, *, store=True):
"""Return a dictionary of ``node_stat_delta`` output for each node in a
character.
"""
r = {}
nodes = set(self._real.character[char].node.keys())
for node in nodes:
delta = self.node_stat_delta(char, node, store=store)
if delta:
r[node] = delta
nsc = self._node_stat_cache[char]
for node in list(nsc.keys()):
if node not in nodes:
del nsc[node]
return r | python | def character_nodes_stat_delta(self, char, *, store=True):
"""Return a dictionary of ``node_stat_delta`` output for each node in a
character.
"""
r = {}
nodes = set(self._real.character[char].node.keys())
for node in nodes:
delta = self.node_stat_delta(char, node, store=store)
if delta:
r[node] = delta
nsc = self._node_stat_cache[char]
for node in list(nsc.keys()):
if node not in nodes:
del nsc[node]
return r | [
"def",
"character_nodes_stat_delta",
"(",
"self",
",",
"char",
",",
"*",
",",
"store",
"=",
"True",
")",
":",
"r",
"=",
"{",
"}",
"nodes",
"=",
"set",
"(",
"self",
".",
"_real",
".",
"character",
"[",
"char",
"]",
".",
"node",
".",
"keys",
"(",
"... | Return a dictionary of ``node_stat_delta`` output for each node in a
character. | [
"Return",
"a",
"dictionary",
"of",
"node_stat_delta",
"output",
"for",
"each",
"node",
"in",
"a",
"character",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/handle.py#L725-L740 | train | 32,902 |
LogicalDash/LiSE | LiSE/LiSE/handle.py | EngineHandle.update_node | def update_node(self, char, node, patch):
"""Change a node's stats according to a dictionary.
The ``patch`` dictionary should hold the new values of stats,
keyed by the stats' names; a value of ``None`` deletes the
stat.
"""
character = self._real.character[char]
if patch is None:
del character.node[node]
elif node not in character.node:
character.node[node] = patch
return
else:
character.node[node].update(patch) | python | def update_node(self, char, node, patch):
"""Change a node's stats according to a dictionary.
The ``patch`` dictionary should hold the new values of stats,
keyed by the stats' names; a value of ``None`` deletes the
stat.
"""
character = self._real.character[char]
if patch is None:
del character.node[node]
elif node not in character.node:
character.node[node] = patch
return
else:
character.node[node].update(patch) | [
"def",
"update_node",
"(",
"self",
",",
"char",
",",
"node",
",",
"patch",
")",
":",
"character",
"=",
"self",
".",
"_real",
".",
"character",
"[",
"char",
"]",
"if",
"patch",
"is",
"None",
":",
"del",
"character",
".",
"node",
"[",
"node",
"]",
"e... | Change a node's stats according to a dictionary.
The ``patch`` dictionary should hold the new values of stats,
keyed by the stats' names; a value of ``None`` deletes the
stat. | [
"Change",
"a",
"node",
"s",
"stats",
"according",
"to",
"a",
"dictionary",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/handle.py#L746-L761 | train | 32,903 |
LogicalDash/LiSE | LiSE/LiSE/handle.py | EngineHandle.update_nodes | def update_nodes(self, char, patch, backdate=False):
"""Change the stats of nodes in a character according to a
dictionary.
"""
if backdate:
parbranch, parrev = self._real._parentbranch_rev.get(
self._real.branch, ('trunk', 0)
)
tick_now = self._real.tick
self._real.tick = parrev
for i, (n, npatch) in enumerate(patch.items(), 1):
self.update_node(char, n, npatch)
if backdate:
self._real.tick = tick_now | python | def update_nodes(self, char, patch, backdate=False):
"""Change the stats of nodes in a character according to a
dictionary.
"""
if backdate:
parbranch, parrev = self._real._parentbranch_rev.get(
self._real.branch, ('trunk', 0)
)
tick_now = self._real.tick
self._real.tick = parrev
for i, (n, npatch) in enumerate(patch.items(), 1):
self.update_node(char, n, npatch)
if backdate:
self._real.tick = tick_now | [
"def",
"update_nodes",
"(",
"self",
",",
"char",
",",
"patch",
",",
"backdate",
"=",
"False",
")",
":",
"if",
"backdate",
":",
"parbranch",
",",
"parrev",
"=",
"self",
".",
"_real",
".",
"_parentbranch_rev",
".",
"get",
"(",
"self",
".",
"_real",
".",
... | Change the stats of nodes in a character according to a
dictionary. | [
"Change",
"the",
"stats",
"of",
"nodes",
"in",
"a",
"character",
"according",
"to",
"a",
"dictionary",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/handle.py#L764-L778 | train | 32,904 |
LogicalDash/LiSE | LiSE/LiSE/handle.py | EngineHandle.del_node | def del_node(self, char, node):
"""Remove a node from a character."""
del self._real.character[char].node[node]
for cache in (
self._char_nodes_rulebooks_cache,
self._node_stat_cache,
self._node_successors_cache
):
try:
del cache[char][node]
except KeyError:
pass
if char in self._char_nodes_cache and node in self._char_nodes_cache[char]:
self._char_nodes_cache[char] = self._char_nodes_cache[char] - frozenset([node])
if char in self._portal_stat_cache:
portal_stat_cache_char = self._portal_stat_cache[char]
if node in portal_stat_cache_char:
del portal_stat_cache_char[node]
for charo in portal_stat_cache_char.values():
if node in charo:
del charo[node]
if char in self._char_portals_rulebooks_cache:
portal_rulebook_cache_char = self._char_portals_rulebooks_cache[char]
if node in portal_rulebook_cache_char:
del portal_rulebook_cache_char[node]
for porto in portal_rulebook_cache_char.values():
if node in porto:
del porto[node] | python | def del_node(self, char, node):
"""Remove a node from a character."""
del self._real.character[char].node[node]
for cache in (
self._char_nodes_rulebooks_cache,
self._node_stat_cache,
self._node_successors_cache
):
try:
del cache[char][node]
except KeyError:
pass
if char in self._char_nodes_cache and node in self._char_nodes_cache[char]:
self._char_nodes_cache[char] = self._char_nodes_cache[char] - frozenset([node])
if char in self._portal_stat_cache:
portal_stat_cache_char = self._portal_stat_cache[char]
if node in portal_stat_cache_char:
del portal_stat_cache_char[node]
for charo in portal_stat_cache_char.values():
if node in charo:
del charo[node]
if char in self._char_portals_rulebooks_cache:
portal_rulebook_cache_char = self._char_portals_rulebooks_cache[char]
if node in portal_rulebook_cache_char:
del portal_rulebook_cache_char[node]
for porto in portal_rulebook_cache_char.values():
if node in porto:
del porto[node] | [
"def",
"del_node",
"(",
"self",
",",
"char",
",",
"node",
")",
":",
"del",
"self",
".",
"_real",
".",
"character",
"[",
"char",
"]",
".",
"node",
"[",
"node",
"]",
"for",
"cache",
"in",
"(",
"self",
".",
"_char_nodes_rulebooks_cache",
",",
"self",
".... | Remove a node from a character. | [
"Remove",
"a",
"node",
"from",
"a",
"character",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/handle.py#L781-L808 | train | 32,905 |
LogicalDash/LiSE | LiSE/LiSE/handle.py | EngineHandle.thing_travel_to | def thing_travel_to(self, char, thing, dest, weight=None, graph=None):
"""Make something find a path to ``dest`` and follow it.
Optional argument ``weight`` is the portal stat to use to schedule movement times.
Optional argument ``graph`` is an alternative graph to use for pathfinding.
Should resemble a networkx DiGraph.
"""
return self._real.character[char].thing[thing].travel_to(dest, weight, graph) | python | def thing_travel_to(self, char, thing, dest, weight=None, graph=None):
"""Make something find a path to ``dest`` and follow it.
Optional argument ``weight`` is the portal stat to use to schedule movement times.
Optional argument ``graph`` is an alternative graph to use for pathfinding.
Should resemble a networkx DiGraph.
"""
return self._real.character[char].thing[thing].travel_to(dest, weight, graph) | [
"def",
"thing_travel_to",
"(",
"self",
",",
"char",
",",
"thing",
",",
"dest",
",",
"weight",
"=",
"None",
",",
"graph",
"=",
"None",
")",
":",
"return",
"self",
".",
"_real",
".",
"character",
"[",
"char",
"]",
".",
"thing",
"[",
"thing",
"]",
"."... | Make something find a path to ``dest`` and follow it.
Optional argument ``weight`` is the portal stat to use to schedule movement times.
Optional argument ``graph`` is an alternative graph to use for pathfinding.
Should resemble a networkx DiGraph. | [
"Make",
"something",
"find",
"a",
"path",
"to",
"dest",
"and",
"follow",
"it",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/handle.py#L917-L926 | train | 32,906 |
LogicalDash/LiSE | ELiDE/ELiDE/statlist.py | StatRowListItemContainer.remake | def remake(self, *args):
"""Replace any existing child widget with the one described by my ``config``.
This doesn't need arguments, but accepts any positional arguments provided,
so that you can use this in kvlang
"""
if not self.config:
return
if not all((self.key, self.gett, self.sett, self.listen, self.unlisten)):
Clock.schedule_once(self.remake, 0)
return
if not hasattr(self, 'label'):
self.label = Label(text=str(self.key))
def updlabel(*args):
self.label.text = str(self.key)
self.bind(key=updlabel)
self.add_widget(self.label)
if hasattr(self, 'wid'):
self.remove_widget(self.wid)
del self.wid
control = self.config['control']
widkwargs = {
'key': self.key,
'gett': self.gett,
'sett': self.sett,
'listen': self.listen,
'unlisten': self.unlisten
}
if control == 'slider':
cls = StatRowSlider
try:
widkwargs['value'] = float(self.gett(self.key))
widkwargs['min'] = float(self.config['min'])
widkwargs['max'] = float(self.config['max'])
except (KeyError, ValueError):
return
elif control == 'togglebutton':
cls = StatRowToggleButton
try:
widkwargs['true_text'] = self.config['true_text']
widkwargs['false_text'] = self.config['false_text']
except KeyError:
return
elif control == 'textinput':
cls = StatRowTextInput
else:
cls = StatRowLabel
self.wid = cls(**widkwargs)
self.bind(
key=self.wid.setter('key'),
gett=self.wid.setter('gett'),
sett=self.wid.setter('sett'),
listen=self.wid.setter('listen'),
unlisten=self.wid.setter('unlisten')
)
if control == 'slider':
self.unbind(config=self._toggle_update_config)
self.bind(config=self._slider_update_config)
elif control == 'togglebutton':
self.unbind(config=self._slider_update_config)
self.bind(config=self._toggle_update_config)
else:
self.unbind(config=self._slider_update_config)
self.unbind(config=self._toggle_update_config)
self.add_widget(self.wid) | python | def remake(self, *args):
"""Replace any existing child widget with the one described by my ``config``.
This doesn't need arguments, but accepts any positional arguments provided,
so that you can use this in kvlang
"""
if not self.config:
return
if not all((self.key, self.gett, self.sett, self.listen, self.unlisten)):
Clock.schedule_once(self.remake, 0)
return
if not hasattr(self, 'label'):
self.label = Label(text=str(self.key))
def updlabel(*args):
self.label.text = str(self.key)
self.bind(key=updlabel)
self.add_widget(self.label)
if hasattr(self, 'wid'):
self.remove_widget(self.wid)
del self.wid
control = self.config['control']
widkwargs = {
'key': self.key,
'gett': self.gett,
'sett': self.sett,
'listen': self.listen,
'unlisten': self.unlisten
}
if control == 'slider':
cls = StatRowSlider
try:
widkwargs['value'] = float(self.gett(self.key))
widkwargs['min'] = float(self.config['min'])
widkwargs['max'] = float(self.config['max'])
except (KeyError, ValueError):
return
elif control == 'togglebutton':
cls = StatRowToggleButton
try:
widkwargs['true_text'] = self.config['true_text']
widkwargs['false_text'] = self.config['false_text']
except KeyError:
return
elif control == 'textinput':
cls = StatRowTextInput
else:
cls = StatRowLabel
self.wid = cls(**widkwargs)
self.bind(
key=self.wid.setter('key'),
gett=self.wid.setter('gett'),
sett=self.wid.setter('sett'),
listen=self.wid.setter('listen'),
unlisten=self.wid.setter('unlisten')
)
if control == 'slider':
self.unbind(config=self._toggle_update_config)
self.bind(config=self._slider_update_config)
elif control == 'togglebutton':
self.unbind(config=self._slider_update_config)
self.bind(config=self._toggle_update_config)
else:
self.unbind(config=self._slider_update_config)
self.unbind(config=self._toggle_update_config)
self.add_widget(self.wid) | [
"def",
"remake",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"not",
"self",
".",
"config",
":",
"return",
"if",
"not",
"all",
"(",
"(",
"self",
".",
"key",
",",
"self",
".",
"gett",
",",
"self",
".",
"sett",
",",
"self",
".",
"listen",
",",
... | Replace any existing child widget with the one described by my ``config``.
This doesn't need arguments, but accepts any positional arguments provided,
so that you can use this in kvlang | [
"Replace",
"any",
"existing",
"child",
"widget",
"with",
"the",
"one",
"described",
"by",
"my",
"config",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/statlist.py#L234-L300 | train | 32,907 |
LogicalDash/LiSE | ELiDE/ELiDE/statlist.py | BaseStatListView.del_key | def del_key(self, k):
"""Delete the key and any configuration for it"""
if k not in self.mirror:
raise KeyError
del self.proxy[k]
if '_config' in self.proxy and k in self.proxy['_config']:
del self.proxy['_config'][k] | python | def del_key(self, k):
"""Delete the key and any configuration for it"""
if k not in self.mirror:
raise KeyError
del self.proxy[k]
if '_config' in self.proxy and k in self.proxy['_config']:
del self.proxy['_config'][k] | [
"def",
"del_key",
"(",
"self",
",",
"k",
")",
":",
"if",
"k",
"not",
"in",
"self",
".",
"mirror",
":",
"raise",
"KeyError",
"del",
"self",
".",
"proxy",
"[",
"k",
"]",
"if",
"'_config'",
"in",
"self",
".",
"proxy",
"and",
"k",
"in",
"self",
".",
... | Delete the key and any configuration for it | [
"Delete",
"the",
"key",
"and",
"any",
"configuration",
"for",
"it"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/statlist.py#L339-L345 | train | 32,908 |
LogicalDash/LiSE | ELiDE/ELiDE/statlist.py | BaseStatListView.set_value | def set_value(self, k, v):
"""Set a value on the proxy, parsing it to a useful datatype if possible"""
from ast import literal_eval
if self.engine is None or self.proxy is None:
self._trigger_set_value(k, v)
return
if v is None:
del self.proxy[k]
else:
try:
vv = literal_eval(v)
except (TypeError, ValueError):
vv = v
self.proxy[k] = vv | python | def set_value(self, k, v):
"""Set a value on the proxy, parsing it to a useful datatype if possible"""
from ast import literal_eval
if self.engine is None or self.proxy is None:
self._trigger_set_value(k, v)
return
if v is None:
del self.proxy[k]
else:
try:
vv = literal_eval(v)
except (TypeError, ValueError):
vv = v
self.proxy[k] = vv | [
"def",
"set_value",
"(",
"self",
",",
"k",
",",
"v",
")",
":",
"from",
"ast",
"import",
"literal_eval",
"if",
"self",
".",
"engine",
"is",
"None",
"or",
"self",
".",
"proxy",
"is",
"None",
":",
"self",
".",
"_trigger_set_value",
"(",
"k",
",",
"v",
... | Set a value on the proxy, parsing it to a useful datatype if possible | [
"Set",
"a",
"value",
"on",
"the",
"proxy",
"parsing",
"it",
"to",
"a",
"useful",
"datatype",
"if",
"possible"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/statlist.py#L347-L360 | train | 32,909 |
LogicalDash/LiSE | ELiDE/ELiDE/statlist.py | BaseStatListView.set_config | def set_config(self, key, option, value):
"""Set a configuration option for a key"""
if '_config' not in self.proxy:
newopt = dict(default_cfg)
newopt[option] = value
self.proxy['_config'] = {key: newopt}
else:
if key in self.proxy['_config']:
self.proxy['_config'][key][option] = value
else:
newopt = dict(default_cfg)
newopt[option] = value
self.proxy['_config'][key] = newopt | python | def set_config(self, key, option, value):
"""Set a configuration option for a key"""
if '_config' not in self.proxy:
newopt = dict(default_cfg)
newopt[option] = value
self.proxy['_config'] = {key: newopt}
else:
if key in self.proxy['_config']:
self.proxy['_config'][key][option] = value
else:
newopt = dict(default_cfg)
newopt[option] = value
self.proxy['_config'][key] = newopt | [
"def",
"set_config",
"(",
"self",
",",
"key",
",",
"option",
",",
"value",
")",
":",
"if",
"'_config'",
"not",
"in",
"self",
".",
"proxy",
":",
"newopt",
"=",
"dict",
"(",
"default_cfg",
")",
"newopt",
"[",
"option",
"]",
"=",
"value",
"self",
".",
... | Set a configuration option for a key | [
"Set",
"a",
"configuration",
"option",
"for",
"a",
"key"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/statlist.py#L371-L383 | train | 32,910 |
LogicalDash/LiSE | ELiDE/ELiDE/statlist.py | BaseStatListView.set_configs | def set_configs(self, key, d):
"""Set the whole configuration for a key"""
if '_config' in self.proxy:
self.proxy['_config'][key] = d
else:
self.proxy['_config'] = {key: d} | python | def set_configs(self, key, d):
"""Set the whole configuration for a key"""
if '_config' in self.proxy:
self.proxy['_config'][key] = d
else:
self.proxy['_config'] = {key: d} | [
"def",
"set_configs",
"(",
"self",
",",
"key",
",",
"d",
")",
":",
"if",
"'_config'",
"in",
"self",
".",
"proxy",
":",
"self",
".",
"proxy",
"[",
"'_config'",
"]",
"[",
"key",
"]",
"=",
"d",
"else",
":",
"self",
".",
"proxy",
"[",
"'_config'",
"]... | Set the whole configuration for a key | [
"Set",
"the",
"whole",
"configuration",
"for",
"a",
"key"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/statlist.py#L385-L390 | train | 32,911 |
LogicalDash/LiSE | ELiDE/ELiDE/statlist.py | BaseStatListView.iter_data | def iter_data(self):
"""Iterate over key-value pairs that are really meant to be displayed"""
for (k, v) in self.proxy.items():
if (
not (isinstance(k, str) and k[0] == '_') and
k not in (
'character',
'name',
'location'
)
):
yield k, v | python | def iter_data(self):
"""Iterate over key-value pairs that are really meant to be displayed"""
for (k, v) in self.proxy.items():
if (
not (isinstance(k, str) and k[0] == '_') and
k not in (
'character',
'name',
'location'
)
):
yield k, v | [
"def",
"iter_data",
"(",
"self",
")",
":",
"for",
"(",
"k",
",",
"v",
")",
"in",
"self",
".",
"proxy",
".",
"items",
"(",
")",
":",
"if",
"(",
"not",
"(",
"isinstance",
"(",
"k",
",",
"str",
")",
"and",
"k",
"[",
"0",
"]",
"==",
"'_'",
")",... | Iterate over key-value pairs that are really meant to be displayed | [
"Iterate",
"over",
"key",
"-",
"value",
"pairs",
"that",
"are",
"really",
"meant",
"to",
"be",
"displayed"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/statlist.py#L392-L403 | train | 32,912 |
LogicalDash/LiSE | ELiDE/ELiDE/statlist.py | BaseStatListView.munge | def munge(self, k, v):
"""Turn a key and value into a dictionary describing a widget to show"""
if '_config' in self.proxy and k in self.proxy['_config']:
config = self.proxy['_config'][k].unwrap()
else:
config = default_cfg
return {
'key': k,
'reg': self._reg_widget,
'unreg': self._unreg_widget,
'gett': self.proxy.__getitem__,
'sett': self.set_value,
'listen': self.proxy.connect,
'unlisten': self.proxy.disconnect,
'config': config
} | python | def munge(self, k, v):
"""Turn a key and value into a dictionary describing a widget to show"""
if '_config' in self.proxy and k in self.proxy['_config']:
config = self.proxy['_config'][k].unwrap()
else:
config = default_cfg
return {
'key': k,
'reg': self._reg_widget,
'unreg': self._unreg_widget,
'gett': self.proxy.__getitem__,
'sett': self.set_value,
'listen': self.proxy.connect,
'unlisten': self.proxy.disconnect,
'config': config
} | [
"def",
"munge",
"(",
"self",
",",
"k",
",",
"v",
")",
":",
"if",
"'_config'",
"in",
"self",
".",
"proxy",
"and",
"k",
"in",
"self",
".",
"proxy",
"[",
"'_config'",
"]",
":",
"config",
"=",
"self",
".",
"proxy",
"[",
"'_config'",
"]",
"[",
"k",
... | Turn a key and value into a dictionary describing a widget to show | [
"Turn",
"a",
"key",
"and",
"value",
"into",
"a",
"dictionary",
"describing",
"a",
"widget",
"to",
"show"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/statlist.py#L405-L420 | train | 32,913 |
LogicalDash/LiSE | ELiDE/ELiDE/statlist.py | BaseStatListView.upd_data | def upd_data(self, *args):
"""Update to match new entity data"""
data = [self.munge(k, v) for k, v in self.iter_data()]
self.data = sorted(data, key=lambda d: d['key']) | python | def upd_data(self, *args):
"""Update to match new entity data"""
data = [self.munge(k, v) for k, v in self.iter_data()]
self.data = sorted(data, key=lambda d: d['key']) | [
"def",
"upd_data",
"(",
"self",
",",
"*",
"args",
")",
":",
"data",
"=",
"[",
"self",
".",
"munge",
"(",
"k",
",",
"v",
")",
"for",
"k",
",",
"v",
"in",
"self",
".",
"iter_data",
"(",
")",
"]",
"self",
".",
"data",
"=",
"sorted",
"(",
"data",... | Update to match new entity data | [
"Update",
"to",
"match",
"new",
"entity",
"data"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/statlist.py#L422-L425 | train | 32,914 |
LogicalDash/LiSE | ELiDE/ELiDE/game.py | GameScreen.wait_travel | def wait_travel(self, character, thing, dest, cb=None):
"""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``
"""
self.disable_input()
self.app.wait_travel(character, thing, dest, cb=partial(self.enable_input, cb)) | python | def wait_travel(self, character, thing, dest, cb=None):
"""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``
"""
self.disable_input()
self.app.wait_travel(character, thing, dest, cb=partial(self.enable_input, cb)) | [
"def",
"wait_travel",
"(",
"self",
",",
"character",
",",
"thing",
",",
"dest",
",",
"cb",
"=",
"None",
")",
":",
"self",
".",
"disable_input",
"(",
")",
"self",
".",
"app",
".",
"wait_travel",
"(",
"character",
",",
"thing",
",",
"dest",
",",
"cb",
... | 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`` | [
"Schedule",
"a",
"thing",
"to",
"travel",
"someplace",
"then",
"wait",
"for",
"it",
"to",
"finish",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/game.py#L78-L89 | train | 32,915 |
LogicalDash/LiSE | ELiDE/ELiDE/game.py | GameScreen.wait_command | def wait_command(self, start_func, turns=1, end_func=None):
"""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``
"""
self.disable_input()
start_func()
self.app.wait_turns(turns, cb=partial(self.enable_input, end_func)) | python | def wait_command(self, start_func, turns=1, end_func=None):
"""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``
"""
self.disable_input()
start_func()
self.app.wait_turns(turns, cb=partial(self.enable_input, end_func)) | [
"def",
"wait_command",
"(",
"self",
",",
"start_func",
",",
"turns",
"=",
"1",
",",
"end_func",
"=",
"None",
")",
":",
"self",
".",
"disable_input",
"(",
")",
"start_func",
"(",
")",
"self",
".",
"app",
".",
"wait_turns",
"(",
"turns",
",",
"cb",
"="... | 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`` | [
"Call",
"start_func",
"wait",
"turns",
"and",
"then",
"call",
"end_func",
"if",
"provided"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/game.py#L104-L117 | train | 32,916 |
LogicalDash/LiSE | ELiDE/ELiDE/game.py | GameApp.wait_travel | def wait_travel(self, character, thing, dest, cb=None):
"""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``
"""
self.wait_turns(self.engine.character[character].thing[thing].travel_to(dest), cb=cb) | python | def wait_travel(self, character, thing, dest, cb=None):
"""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``
"""
self.wait_turns(self.engine.character[character].thing[thing].travel_to(dest), cb=cb) | [
"def",
"wait_travel",
"(",
"self",
",",
"character",
",",
"thing",
",",
"dest",
",",
"cb",
"=",
"None",
")",
":",
"self",
".",
"wait_turns",
"(",
"self",
".",
"engine",
".",
"character",
"[",
"character",
"]",
".",
"thing",
"[",
"thing",
"]",
".",
... | 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`` | [
"Schedule",
"a",
"thing",
"to",
"travel",
"someplace",
"then",
"wait",
"for",
"it",
"to",
"finish",
"and",
"call",
"cb",
"if",
"provided"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/game.py#L177-L187 | train | 32,917 |
LogicalDash/LiSE | ELiDE/ELiDE/rulesview.py | RuleButton.on_state | def on_state(self, *args):
"""If I'm pressed, unpress all other buttons in the ruleslist"""
# This really ought to be done with the selection behavior
if self.state == 'down':
self.rulesview.rule = self.rule
for button in self.ruleslist.children[0].children:
if button != self:
button.state = 'normal' | python | def on_state(self, *args):
"""If I'm pressed, unpress all other buttons in the ruleslist"""
# This really ought to be done with the selection behavior
if self.state == 'down':
self.rulesview.rule = self.rule
for button in self.ruleslist.children[0].children:
if button != self:
button.state = 'normal' | [
"def",
"on_state",
"(",
"self",
",",
"*",
"args",
")",
":",
"# This really ought to be done with the selection behavior",
"if",
"self",
".",
"state",
"==",
"'down'",
":",
"self",
".",
"rulesview",
".",
"rule",
"=",
"self",
".",
"rule",
"for",
"button",
"in",
... | If I'm pressed, unpress all other buttons in the ruleslist | [
"If",
"I",
"m",
"pressed",
"unpress",
"all",
"other",
"buttons",
"in",
"the",
"ruleslist"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/rulesview.py#L52-L59 | train | 32,918 |
LogicalDash/LiSE | ELiDE/ELiDE/rulesview.py | RulesList.on_rulebook | def on_rulebook(self, *args):
"""Make sure to update when the rulebook changes"""
if self.rulebook is None:
return
self.rulebook.connect(self._trigger_redata, weak=False)
self.redata() | python | def on_rulebook(self, *args):
"""Make sure to update when the rulebook changes"""
if self.rulebook is None:
return
self.rulebook.connect(self._trigger_redata, weak=False)
self.redata() | [
"def",
"on_rulebook",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"rulebook",
"is",
"None",
":",
"return",
"self",
".",
"rulebook",
".",
"connect",
"(",
"self",
".",
"_trigger_redata",
",",
"weak",
"=",
"False",
")",
"self",
".",
"red... | Make sure to update when the rulebook changes | [
"Make",
"sure",
"to",
"update",
"when",
"the",
"rulebook",
"changes"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/rulesview.py#L71-L76 | train | 32,919 |
LogicalDash/LiSE | ELiDE/ELiDE/rulesview.py | RulesList.redata | def redata(self, *args):
"""Make my data represent what's in my rulebook right now"""
if self.rulesview is None:
Clock.schedule_once(self.redata, 0)
return
data = [
{'rulesview': self.rulesview, 'rule': rule, 'index': i, 'ruleslist': self}
for i, rule in enumerate(self.rulebook)
]
self.data = data | python | def redata(self, *args):
"""Make my data represent what's in my rulebook right now"""
if self.rulesview is None:
Clock.schedule_once(self.redata, 0)
return
data = [
{'rulesview': self.rulesview, 'rule': rule, 'index': i, 'ruleslist': self}
for i, rule in enumerate(self.rulebook)
]
self.data = data | [
"def",
"redata",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"rulesview",
"is",
"None",
":",
"Clock",
".",
"schedule_once",
"(",
"self",
".",
"redata",
",",
"0",
")",
"return",
"data",
"=",
"[",
"{",
"'rulesview'",
":",
"self",
".",... | Make my data represent what's in my rulebook right now | [
"Make",
"my",
"data",
"represent",
"what",
"s",
"in",
"my",
"rulebook",
"right",
"now"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/rulesview.py#L78-L87 | train | 32,920 |
LogicalDash/LiSE | ELiDE/ELiDE/rulesview.py | RulesView.on_rule | def on_rule(self, *args):
"""Make sure to update when the rule changes"""
if self.rule is None:
return
self.rule.connect(self._listen_to_rule) | python | def on_rule(self, *args):
"""Make sure to update when the rule changes"""
if self.rule is None:
return
self.rule.connect(self._listen_to_rule) | [
"def",
"on_rule",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"rule",
"is",
"None",
":",
"return",
"self",
".",
"rule",
".",
"connect",
"(",
"self",
".",
"_listen_to_rule",
")"
] | Make sure to update when the rule changes | [
"Make",
"sure",
"to",
"update",
"when",
"the",
"rule",
"changes"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/rulesview.py#L106-L110 | train | 32,921 |
LogicalDash/LiSE | ELiDE/ELiDE/rulesview.py | RulesView.finalize | def finalize(self, *args):
"""Add my tabs"""
if not self.canvas:
Clock.schedule_once(self.finalize, 0)
return
deck_builder_kwargs = {
'pos_hint': {'x': 0, 'y': 0},
'starting_pos_hint': {'x': 0.05, 'top': 0.95},
'card_size_hint': (0.3, 0.4),
'card_hint_step': (0, -0.1),
'deck_x_hint_step': 0.4
}
self._tabs = TabbedPanel(
size=self.size,
pos=self.pos,
do_default_tab=False
)
self.bind(
size=self._tabs.setter('size'),
pos=self._tabs.setter('pos')
)
self.add_widget(self._tabs)
for functyp in 'trigger', 'prereq', 'action':
tab = TabbedPanelItem(text=functyp.capitalize())
setattr(self, '_{}_tab'.format(functyp), tab)
self._tabs.add_widget(getattr(self, '_{}_tab'.format(functyp)))
builder = DeckBuilderView(**deck_builder_kwargs)
setattr(self, '_{}_builder'.format(functyp), builder)
builder.bind(decks=getattr(self, '_trigger_push_{}s'.format(functyp)))
scroll_left = DeckBuilderScrollBar(
size_hint_x=0.01,
pos_hint={'x': 0, 'y': 0},
deckbuilder=builder,
deckidx=0,
scroll_min=0
)
setattr(self, '_scroll_left_' + functyp, scroll_left)
scroll_right = DeckBuilderScrollBar(
size_hint_x=0.01,
pos_hint={'right': 1, 'y': 0},
deckbuilder=builder,
deckidx=1,
scroll_min=0
)
setattr(self, '_scroll_right_' + functyp, scroll_right)
layout = FloatLayout()
setattr(self, '_{}_layout'.format(functyp), layout)
tab.add_widget(layout)
layout.add_widget(builder)
layout.add_widget(scroll_left)
layout.add_widget(scroll_right)
layout.add_widget(
Label(
text='Used',
pos_hint={'center_x': 0.1, 'center_y': 0.98},
size_hint=(None, None)
)
)
layout.add_widget(
Label(
text='Unused',
pos_hint={'center_x': 0.5, 'center_y': 0.98},
size_hint=(None, None)
)
)
self.bind(rule=getattr(self, '_trigger_pull_{}s'.format(functyp))) | python | def finalize(self, *args):
"""Add my tabs"""
if not self.canvas:
Clock.schedule_once(self.finalize, 0)
return
deck_builder_kwargs = {
'pos_hint': {'x': 0, 'y': 0},
'starting_pos_hint': {'x': 0.05, 'top': 0.95},
'card_size_hint': (0.3, 0.4),
'card_hint_step': (0, -0.1),
'deck_x_hint_step': 0.4
}
self._tabs = TabbedPanel(
size=self.size,
pos=self.pos,
do_default_tab=False
)
self.bind(
size=self._tabs.setter('size'),
pos=self._tabs.setter('pos')
)
self.add_widget(self._tabs)
for functyp in 'trigger', 'prereq', 'action':
tab = TabbedPanelItem(text=functyp.capitalize())
setattr(self, '_{}_tab'.format(functyp), tab)
self._tabs.add_widget(getattr(self, '_{}_tab'.format(functyp)))
builder = DeckBuilderView(**deck_builder_kwargs)
setattr(self, '_{}_builder'.format(functyp), builder)
builder.bind(decks=getattr(self, '_trigger_push_{}s'.format(functyp)))
scroll_left = DeckBuilderScrollBar(
size_hint_x=0.01,
pos_hint={'x': 0, 'y': 0},
deckbuilder=builder,
deckidx=0,
scroll_min=0
)
setattr(self, '_scroll_left_' + functyp, scroll_left)
scroll_right = DeckBuilderScrollBar(
size_hint_x=0.01,
pos_hint={'right': 1, 'y': 0},
deckbuilder=builder,
deckidx=1,
scroll_min=0
)
setattr(self, '_scroll_right_' + functyp, scroll_right)
layout = FloatLayout()
setattr(self, '_{}_layout'.format(functyp), layout)
tab.add_widget(layout)
layout.add_widget(builder)
layout.add_widget(scroll_left)
layout.add_widget(scroll_right)
layout.add_widget(
Label(
text='Used',
pos_hint={'center_x': 0.1, 'center_y': 0.98},
size_hint=(None, None)
)
)
layout.add_widget(
Label(
text='Unused',
pos_hint={'center_x': 0.5, 'center_y': 0.98},
size_hint=(None, None)
)
)
self.bind(rule=getattr(self, '_trigger_pull_{}s'.format(functyp))) | [
"def",
"finalize",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"not",
"self",
".",
"canvas",
":",
"Clock",
".",
"schedule_once",
"(",
"self",
".",
"finalize",
",",
"0",
")",
"return",
"deck_builder_kwargs",
"=",
"{",
"'pos_hint'",
":",
"{",
"'x'",
... | Add my tabs | [
"Add",
"my",
"tabs"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/rulesview.py#L127-L195 | train | 32,922 |
LogicalDash/LiSE | ELiDE/ELiDE/rulesview.py | RulesView.get_functions_cards | def get_functions_cards(self, what, allfuncs):
"""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)
"""
if not self.rule:
return [], []
rulefuncnames = getattr(self.rule, what+'s')
unused = [
Card(
ud={
'type': what,
'funcname': name,
'signature': sig
},
headline_text=name,
show_art=False,
midline_text=what.capitalize(),
text=source
)
for (name, source, sig) in allfuncs if name not in rulefuncnames
]
used = [
Card(
ud={
'type': what,
'funcname': name,
},
headline_text=name,
show_art=False,
midline_text=what.capitalize(),
text=str(getattr(getattr(self.engine, what), name))
)
for name in rulefuncnames
]
return used, unused | python | def get_functions_cards(self, what, allfuncs):
"""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)
"""
if not self.rule:
return [], []
rulefuncnames = getattr(self.rule, what+'s')
unused = [
Card(
ud={
'type': what,
'funcname': name,
'signature': sig
},
headline_text=name,
show_art=False,
midline_text=what.capitalize(),
text=source
)
for (name, source, sig) in allfuncs if name not in rulefuncnames
]
used = [
Card(
ud={
'type': what,
'funcname': name,
},
headline_text=name,
show_art=False,
midline_text=what.capitalize(),
text=str(getattr(getattr(self.engine, what), name))
)
for name in rulefuncnames
]
return used, unused | [
"def",
"get_functions_cards",
"(",
"self",
",",
"what",
",",
"allfuncs",
")",
":",
"if",
"not",
"self",
".",
"rule",
":",
"return",
"[",
"]",
",",
"[",
"]",
"rulefuncnames",
"=",
"getattr",
"(",
"self",
".",
"rule",
",",
"what",
"+",
"'s'",
")",
"u... | 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) | [
"Return",
"a",
"pair",
"of",
"lists",
"of",
"Card",
"widgets",
"for",
"used",
"and",
"unused",
"functions",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/rulesview.py#L197-L234 | train | 32,923 |
LogicalDash/LiSE | ELiDE/ELiDE/rulesview.py | RulesView.set_functions | def set_functions(self, what, allfuncs):
"""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.
"""
setattr(getattr(self, '_{}_builder'.format(what)), 'decks', self.get_functions_cards(what, allfuncs)) | python | def set_functions(self, what, allfuncs):
"""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.
"""
setattr(getattr(self, '_{}_builder'.format(what)), 'decks', self.get_functions_cards(what, allfuncs)) | [
"def",
"set_functions",
"(",
"self",
",",
"what",
",",
"allfuncs",
")",
":",
"setattr",
"(",
"getattr",
"(",
"self",
",",
"'_{}_builder'",
".",
"format",
"(",
"what",
")",
")",
",",
"'decks'",
",",
"self",
".",
"get_functions_cards",
"(",
"what",
",",
... | 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. | [
"Set",
"the",
"cards",
"in",
"the",
"what",
"builder",
"to",
"allfuncs"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/rulesview.py#L236-L244 | train | 32,924 |
LogicalDash/LiSE | ELiDE/ELiDE/rulesview.py | RulesView._upd_unused | def _upd_unused(self, what):
"""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'
"""
builder = getattr(self, '_{}_builder'.format(what))
updtrig = getattr(self, '_trigger_upd_unused_{}s'.format(what))
builder.unbind(decks=updtrig)
funcs = OrderedDict()
cards = list(self._action_builder.decks[1])
cards.reverse()
for card in cards:
funcs[card.ud['funcname']] = card
for card in self._action_builder.decks[0]:
if card.ud['funcname'] not in funcs:
funcs[card.ud['funcname']] = card.copy()
unused = list(funcs.values())
unused.reverse()
builder.decks[1] = unused
builder.bind(decks=updtrig) | python | def _upd_unused(self, what):
"""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'
"""
builder = getattr(self, '_{}_builder'.format(what))
updtrig = getattr(self, '_trigger_upd_unused_{}s'.format(what))
builder.unbind(decks=updtrig)
funcs = OrderedDict()
cards = list(self._action_builder.decks[1])
cards.reverse()
for card in cards:
funcs[card.ud['funcname']] = card
for card in self._action_builder.decks[0]:
if card.ud['funcname'] not in funcs:
funcs[card.ud['funcname']] = card.copy()
unused = list(funcs.values())
unused.reverse()
builder.decks[1] = unused
builder.bind(decks=updtrig) | [
"def",
"_upd_unused",
"(",
"self",
",",
"what",
")",
":",
"builder",
"=",
"getattr",
"(",
"self",
",",
"'_{}_builder'",
".",
"format",
"(",
"what",
")",
")",
"updtrig",
"=",
"getattr",
"(",
"self",
",",
"'_trigger_upd_unused_{}s'",
".",
"format",
"(",
"w... | 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' | [
"Make",
"sure",
"to",
"have",
"exactly",
"one",
"copy",
"of",
"every",
"valid",
"function",
"in",
"the",
"unused",
"pile",
"on",
"the",
"right",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/rulesview.py#L293-L316 | train | 32,925 |
LogicalDash/LiSE | LiSE/LiSE/rule.py | Rule._fun_names_iter | def _fun_names_iter(self, functyp, val):
"""Iterate over the names of the functions in ``val``,
adding them to ``funcstore`` if they are missing;
or if the items in ``val`` are already the names of functions
in ``funcstore``, iterate over those.
"""
funcstore = getattr(self.engine, functyp)
for v in val:
if callable(v):
# Overwrites anything already on the funcstore, is that bad?
setattr(funcstore, v.__name__, v)
yield v.__name__
elif v not in funcstore:
raise KeyError("Function {} not present in {}".format(
v, funcstore._tab
))
else:
yield v | python | def _fun_names_iter(self, functyp, val):
"""Iterate over the names of the functions in ``val``,
adding them to ``funcstore`` if they are missing;
or if the items in ``val`` are already the names of functions
in ``funcstore``, iterate over those.
"""
funcstore = getattr(self.engine, functyp)
for v in val:
if callable(v):
# Overwrites anything already on the funcstore, is that bad?
setattr(funcstore, v.__name__, v)
yield v.__name__
elif v not in funcstore:
raise KeyError("Function {} not present in {}".format(
v, funcstore._tab
))
else:
yield v | [
"def",
"_fun_names_iter",
"(",
"self",
",",
"functyp",
",",
"val",
")",
":",
"funcstore",
"=",
"getattr",
"(",
"self",
".",
"engine",
",",
"functyp",
")",
"for",
"v",
"in",
"val",
":",
"if",
"callable",
"(",
"v",
")",
":",
"# Overwrites anything already ... | Iterate over the names of the functions in ``val``,
adding them to ``funcstore`` if they are missing;
or if the items in ``val`` are already the names of functions
in ``funcstore``, iterate over those. | [
"Iterate",
"over",
"the",
"names",
"of",
"the",
"functions",
"in",
"val",
"adding",
"them",
"to",
"funcstore",
"if",
"they",
"are",
"missing",
";",
"or",
"if",
"the",
"items",
"in",
"val",
"are",
"already",
"the",
"names",
"of",
"functions",
"in",
"funcs... | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/rule.py#L260-L278 | train | 32,926 |
LogicalDash/LiSE | LiSE/LiSE/rule.py | Rule.duplicate | def duplicate(self, newname):
"""Return a new rule that's just like this one, but under a new
name.
"""
if self.engine.rule.query.haverule(newname):
raise KeyError("Already have a rule called {}".format(newname))
return Rule(
self.engine,
newname,
list(self.triggers),
list(self.prereqs),
list(self.actions)
) | python | def duplicate(self, newname):
"""Return a new rule that's just like this one, but under a new
name.
"""
if self.engine.rule.query.haverule(newname):
raise KeyError("Already have a rule called {}".format(newname))
return Rule(
self.engine,
newname,
list(self.triggers),
list(self.prereqs),
list(self.actions)
) | [
"def",
"duplicate",
"(",
"self",
",",
"newname",
")",
":",
"if",
"self",
".",
"engine",
".",
"rule",
".",
"query",
".",
"haverule",
"(",
"newname",
")",
":",
"raise",
"KeyError",
"(",
"\"Already have a rule called {}\"",
".",
"format",
"(",
"newname",
")",... | Return a new rule that's just like this one, but under a new
name. | [
"Return",
"a",
"new",
"rule",
"that",
"s",
"just",
"like",
"this",
"one",
"but",
"under",
"a",
"new",
"name",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/rule.py#L298-L311 | train | 32,927 |
LogicalDash/LiSE | LiSE/LiSE/rule.py | AllRules.new_empty | def new_empty(self, name):
"""Make a new rule with no actions or anything, and return it."""
if name in self:
raise KeyError("Already have rule {}".format(name))
new = Rule(self.engine, name)
self._cache[name] = new
self.send(self, rule=new, active=True)
return new | python | def new_empty(self, name):
"""Make a new rule with no actions or anything, and return it."""
if name in self:
raise KeyError("Already have rule {}".format(name))
new = Rule(self.engine, name)
self._cache[name] = new
self.send(self, rule=new, active=True)
return new | [
"def",
"new_empty",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"in",
"self",
":",
"raise",
"KeyError",
"(",
"\"Already have rule {}\"",
".",
"format",
"(",
"name",
")",
")",
"new",
"=",
"Rule",
"(",
"self",
".",
"engine",
",",
"name",
")",
"se... | Make a new rule with no actions or anything, and return it. | [
"Make",
"a",
"new",
"rule",
"with",
"no",
"actions",
"or",
"anything",
"and",
"return",
"it",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/rule.py#L693-L700 | train | 32,928 |
LogicalDash/LiSE | LiSE/LiSE/query.py | slow_iter_turns_eval_cmp | def slow_iter_turns_eval_cmp(qry, oper, start_branch=None, engine=None):
"""Iterate over all turns on which a comparison holds.
This is expensive. It evaluates the query for every turn in history.
"""
def mungeside(side):
if isinstance(side, Query):
return side.iter_turns
elif isinstance(side, StatusAlias):
return EntityStatAccessor(
side.entity, side.stat, side.engine,
side.branch, side.turn, side.tick, side.current, side.mungers
)
elif isinstance(side, EntityStatAccessor):
return side
else:
return lambda: side
leftside = mungeside(qry.leftside)
rightside = mungeside(qry.rightside)
engine = engine or leftside.engine or rightside.engine
for (branch, _, _) in engine._iter_parent_btt(start_branch or engine.branch):
if branch is None:
return
parent, turn_start, tick_start, turn_end, tick_end = engine._branches[branch]
for turn in range(turn_start, engine.turn + 1):
if oper(leftside(branch, turn), rightside(branch, turn)):
yield branch, turn | python | def slow_iter_turns_eval_cmp(qry, oper, start_branch=None, engine=None):
"""Iterate over all turns on which a comparison holds.
This is expensive. It evaluates the query for every turn in history.
"""
def mungeside(side):
if isinstance(side, Query):
return side.iter_turns
elif isinstance(side, StatusAlias):
return EntityStatAccessor(
side.entity, side.stat, side.engine,
side.branch, side.turn, side.tick, side.current, side.mungers
)
elif isinstance(side, EntityStatAccessor):
return side
else:
return lambda: side
leftside = mungeside(qry.leftside)
rightside = mungeside(qry.rightside)
engine = engine or leftside.engine or rightside.engine
for (branch, _, _) in engine._iter_parent_btt(start_branch or engine.branch):
if branch is None:
return
parent, turn_start, tick_start, turn_end, tick_end = engine._branches[branch]
for turn in range(turn_start, engine.turn + 1):
if oper(leftside(branch, turn), rightside(branch, turn)):
yield branch, turn | [
"def",
"slow_iter_turns_eval_cmp",
"(",
"qry",
",",
"oper",
",",
"start_branch",
"=",
"None",
",",
"engine",
"=",
"None",
")",
":",
"def",
"mungeside",
"(",
"side",
")",
":",
"if",
"isinstance",
"(",
"side",
",",
"Query",
")",
":",
"return",
"side",
".... | Iterate over all turns on which a comparison holds.
This is expensive. It evaluates the query for every turn in history. | [
"Iterate",
"over",
"all",
"turns",
"on",
"which",
"a",
"comparison",
"holds",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/query.py#L312-L340 | train | 32,929 |
LogicalDash/LiSE | ELiDE/ELiDE/menu.py | MenuTextInput.on_enter | def on_enter(self, *args):
"""Call the setter and blank myself out so that my hint text shows
up. It will be the same you just entered if everything's
working.
"""
if self.text == '':
return
self.setter(self.text)
self.text = ''
self.focus = False | python | def on_enter(self, *args):
"""Call the setter and blank myself out so that my hint text shows
up. It will be the same you just entered if everything's
working.
"""
if self.text == '':
return
self.setter(self.text)
self.text = ''
self.focus = False | [
"def",
"on_enter",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"text",
"==",
"''",
":",
"return",
"self",
".",
"setter",
"(",
"self",
".",
"text",
")",
"self",
".",
"text",
"=",
"''",
"self",
".",
"focus",
"=",
"False"
] | Call the setter and blank myself out so that my hint text shows
up. It will be the same you just entered if everything's
working. | [
"Call",
"the",
"setter",
"and",
"blank",
"myself",
"out",
"so",
"that",
"my",
"hint",
"text",
"shows",
"up",
".",
"It",
"will",
"be",
"the",
"same",
"you",
"just",
"entered",
"if",
"everything",
"s",
"working",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/menu.py#L30-L40 | train | 32,930 |
LogicalDash/LiSE | ELiDE/ELiDE/menu.py | MenuIntInput.insert_text | def insert_text(self, s, from_undo=False):
"""Natural numbers only."""
return super().insert_text(
''.join(c for c in s if c in '0123456789'),
from_undo
) | python | def insert_text(self, s, from_undo=False):
"""Natural numbers only."""
return super().insert_text(
''.join(c for c in s if c in '0123456789'),
from_undo
) | [
"def",
"insert_text",
"(",
"self",
",",
"s",
",",
"from_undo",
"=",
"False",
")",
":",
"return",
"super",
"(",
")",
".",
"insert_text",
"(",
"''",
".",
"join",
"(",
"c",
"for",
"c",
"in",
"s",
"if",
"c",
"in",
"'0123456789'",
")",
",",
"from_undo",... | Natural numbers only. | [
"Natural",
"numbers",
"only",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/menu.py#L54-L59 | train | 32,931 |
LogicalDash/LiSE | LiSE/LiSE/character.py | AbstractCharacter.do | def do(self, func, *args, **kwargs):
"""Apply the function to myself, and return myself.
Look up the function in the database if needed. Pass it any
arguments given, keyword or positional.
Useful chiefly when chaining.
"""
if not callable(func):
func = getattr(self.engine.function, func)
func(self, *args, **kwargs)
return self | python | def do(self, func, *args, **kwargs):
"""Apply the function to myself, and return myself.
Look up the function in the database if needed. Pass it any
arguments given, keyword or positional.
Useful chiefly when chaining.
"""
if not callable(func):
func = getattr(self.engine.function, func)
func(self, *args, **kwargs)
return self | [
"def",
"do",
"(",
"self",
",",
"func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"callable",
"(",
"func",
")",
":",
"func",
"=",
"getattr",
"(",
"self",
".",
"engine",
".",
"function",
",",
"func",
")",
"func",
"(",
"sel... | Apply the function to myself, and return myself.
Look up the function in the database if needed. Pass it any
arguments given, keyword or positional.
Useful chiefly when chaining. | [
"Apply",
"the",
"function",
"to",
"myself",
"and",
"return",
"myself",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/character.py#L221-L233 | train | 32,932 |
LogicalDash/LiSE | LiSE/LiSE/character.py | AbstractCharacter.copy_from | def copy_from(self, g):
"""Copy all nodes and edges from the given graph into this.
Return myself.
"""
renamed = {}
for k, v in g.node.items():
ok = k
if k in self.place:
n = 0
while k in self.place:
k = ok + (n,) if isinstance(ok, tuple) else (ok, n)
n += 1
renamed[ok] = k
self.place[k] = v
if type(g) is nx.MultiDiGraph:
g = nx.DiGraph(g)
elif type(g) is nx.MultiGraph:
g = nx.Graph(g)
if type(g) is nx.DiGraph:
for u, v in g.edges:
self.edge[renamed[u]][renamed[v]] = g.adj[u][v]
else:
assert type(g) is nx.Graph
for u, v, d in g.edges.data():
self.add_portal(renamed[u], renamed[v], symmetrical=True, **d)
return self | python | def copy_from(self, g):
"""Copy all nodes and edges from the given graph into this.
Return myself.
"""
renamed = {}
for k, v in g.node.items():
ok = k
if k in self.place:
n = 0
while k in self.place:
k = ok + (n,) if isinstance(ok, tuple) else (ok, n)
n += 1
renamed[ok] = k
self.place[k] = v
if type(g) is nx.MultiDiGraph:
g = nx.DiGraph(g)
elif type(g) is nx.MultiGraph:
g = nx.Graph(g)
if type(g) is nx.DiGraph:
for u, v in g.edges:
self.edge[renamed[u]][renamed[v]] = g.adj[u][v]
else:
assert type(g) is nx.Graph
for u, v, d in g.edges.data():
self.add_portal(renamed[u], renamed[v], symmetrical=True, **d)
return self | [
"def",
"copy_from",
"(",
"self",
",",
"g",
")",
":",
"renamed",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"g",
".",
"node",
".",
"items",
"(",
")",
":",
"ok",
"=",
"k",
"if",
"k",
"in",
"self",
".",
"place",
":",
"n",
"=",
"0",
"while",
... | Copy all nodes and edges from the given graph into this.
Return myself. | [
"Copy",
"all",
"nodes",
"and",
"edges",
"from",
"the",
"given",
"graph",
"into",
"this",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/character.py#L352-L379 | train | 32,933 |
LogicalDash/LiSE | LiSE/LiSE/character.py | AbstractCharacter.grid_2d_8graph | def grid_2d_8graph(self, m, n):
"""Make a 2d graph that's connected 8 ways, enabling diagonal movement"""
me = nx.Graph()
node = me.node
add_node = me.add_node
add_edge = me.add_edge
for i in range(m):
for j in range(n):
add_node((i, j))
if i > 0:
add_edge((i, j), (i-1, j))
if j > 0:
add_edge((i, j), (i-1, j-1))
if j > 0:
add_edge((i, j), (i, j-1))
if (i - 1, j + 1) in node:
add_edge((i, j), (i-1, j+1))
return self.copy_from(me) | python | def grid_2d_8graph(self, m, n):
"""Make a 2d graph that's connected 8 ways, enabling diagonal movement"""
me = nx.Graph()
node = me.node
add_node = me.add_node
add_edge = me.add_edge
for i in range(m):
for j in range(n):
add_node((i, j))
if i > 0:
add_edge((i, j), (i-1, j))
if j > 0:
add_edge((i, j), (i-1, j-1))
if j > 0:
add_edge((i, j), (i, j-1))
if (i - 1, j + 1) in node:
add_edge((i, j), (i-1, j+1))
return self.copy_from(me) | [
"def",
"grid_2d_8graph",
"(",
"self",
",",
"m",
",",
"n",
")",
":",
"me",
"=",
"nx",
".",
"Graph",
"(",
")",
"node",
"=",
"me",
".",
"node",
"add_node",
"=",
"me",
".",
"add_node",
"add_edge",
"=",
"me",
".",
"add_edge",
"for",
"i",
"in",
"range"... | Make a 2d graph that's connected 8 ways, enabling diagonal movement | [
"Make",
"a",
"2d",
"graph",
"that",
"s",
"connected",
"8",
"ways",
"enabling",
"diagonal",
"movement"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/character.py#L413-L430 | train | 32,934 |
LogicalDash/LiSE | LiSE/LiSE/character.py | CharacterSense.func | def func(self):
"""Return the function most recently associated with this sense."""
fn = self.engine.query.sense_func_get(
self.observer.name,
self.sensename,
*self.engine._btt()
)
if fn is not None:
return SenseFuncWrap(self.observer, fn) | python | def func(self):
"""Return the function most recently associated with this sense."""
fn = self.engine.query.sense_func_get(
self.observer.name,
self.sensename,
*self.engine._btt()
)
if fn is not None:
return SenseFuncWrap(self.observer, fn) | [
"def",
"func",
"(",
"self",
")",
":",
"fn",
"=",
"self",
".",
"engine",
".",
"query",
".",
"sense_func_get",
"(",
"self",
".",
"observer",
".",
"name",
",",
"self",
".",
"sensename",
",",
"*",
"self",
".",
"engine",
".",
"_btt",
"(",
")",
")",
"i... | Return the function most recently associated with this sense. | [
"Return",
"the",
"function",
"most",
"recently",
"associated",
"with",
"this",
"sense",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/character.py#L838-L846 | train | 32,935 |
LogicalDash/LiSE | LiSE/LiSE/character.py | Character.place2thing | def place2thing(self, name, location):
"""Turn a Place into a Thing with the given location.
It will keep all its attached Portals.
"""
self.engine._set_thing_loc(
self.name, name, location
)
if (self.name, name) in self.engine._node_objs:
obj = self.engine._node_objs[self.name, name]
thing = Thing(self, name)
for port in obj.portals():
port.origin = thing
for port in obj.preportals():
port.destination = thing
self.engine._node_objs[self.name, name] = thing | python | def place2thing(self, name, location):
"""Turn a Place into a Thing with the given location.
It will keep all its attached Portals.
"""
self.engine._set_thing_loc(
self.name, name, location
)
if (self.name, name) in self.engine._node_objs:
obj = self.engine._node_objs[self.name, name]
thing = Thing(self, name)
for port in obj.portals():
port.origin = thing
for port in obj.preportals():
port.destination = thing
self.engine._node_objs[self.name, name] = thing | [
"def",
"place2thing",
"(",
"self",
",",
"name",
",",
"location",
")",
":",
"self",
".",
"engine",
".",
"_set_thing_loc",
"(",
"self",
".",
"name",
",",
"name",
",",
"location",
")",
"if",
"(",
"self",
".",
"name",
",",
"name",
")",
"in",
"self",
".... | Turn a Place into a Thing with the given location.
It will keep all its attached Portals. | [
"Turn",
"a",
"Place",
"into",
"a",
"Thing",
"with",
"the",
"given",
"location",
".",
"It",
"will",
"keep",
"all",
"its",
"attached",
"Portals",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/character.py#L2010-L2026 | train | 32,936 |
LogicalDash/LiSE | LiSE/LiSE/character.py | Character.thing2place | def thing2place(self, name):
"""Unset a Thing's location, and thus turn it into a Place."""
self.engine._set_thing_loc(
self.name, name, None
)
if (self.name, name) in self.engine._node_objs:
thing = self.engine._node_objs[self.name, name]
place = Place(self, name)
for port in thing.portals():
port.origin = place
for port in thing.preportals():
port.destination = place
self.engine._node_objs[self.name, name] = place | python | def thing2place(self, name):
"""Unset a Thing's location, and thus turn it into a Place."""
self.engine._set_thing_loc(
self.name, name, None
)
if (self.name, name) in self.engine._node_objs:
thing = self.engine._node_objs[self.name, name]
place = Place(self, name)
for port in thing.portals():
port.origin = place
for port in thing.preportals():
port.destination = place
self.engine._node_objs[self.name, name] = place | [
"def",
"thing2place",
"(",
"self",
",",
"name",
")",
":",
"self",
".",
"engine",
".",
"_set_thing_loc",
"(",
"self",
".",
"name",
",",
"name",
",",
"None",
")",
"if",
"(",
"self",
".",
"name",
",",
"name",
")",
"in",
"self",
".",
"engine",
".",
"... | Unset a Thing's location, and thus turn it into a Place. | [
"Unset",
"a",
"Thing",
"s",
"location",
"and",
"thus",
"turn",
"it",
"into",
"a",
"Place",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/character.py#L2028-L2040 | train | 32,937 |
LogicalDash/LiSE | LiSE/LiSE/character.py | Character.del_avatar | def del_avatar(self, a, b=None):
"""This is no longer my avatar, though it still exists on its own."""
if self.engine._planning:
raise NotImplementedError("Currently can't remove avatars within a plan")
if b is None:
if not isinstance(a, Node):
raise TypeError(
"In single argument form, "
"del_avatar requires a Node object "
"(Thing or Place)."
)
g = a.character.name
n = a.name
else:
g = a.name if isinstance(a, Character) else a
n = b.name if isinstance(b, Node) else b
self.engine._remember_avatarness(
self.character.name, g, n, False
) | python | def del_avatar(self, a, b=None):
"""This is no longer my avatar, though it still exists on its own."""
if self.engine._planning:
raise NotImplementedError("Currently can't remove avatars within a plan")
if b is None:
if not isinstance(a, Node):
raise TypeError(
"In single argument form, "
"del_avatar requires a Node object "
"(Thing or Place)."
)
g = a.character.name
n = a.name
else:
g = a.name if isinstance(a, Character) else a
n = b.name if isinstance(b, Node) else b
self.engine._remember_avatarness(
self.character.name, g, n, False
) | [
"def",
"del_avatar",
"(",
"self",
",",
"a",
",",
"b",
"=",
"None",
")",
":",
"if",
"self",
".",
"engine",
".",
"_planning",
":",
"raise",
"NotImplementedError",
"(",
"\"Currently can't remove avatars within a plan\"",
")",
"if",
"b",
"is",
"None",
":",
"if",... | This is no longer my avatar, though it still exists on its own. | [
"This",
"is",
"no",
"longer",
"my",
"avatar",
"though",
"it",
"still",
"exists",
"on",
"its",
"own",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/character.py#L2135-L2153 | train | 32,938 |
LogicalDash/LiSE | LiSE/LiSE/character.py | Character.portals | def portals(self):
"""Iterate over all portals."""
char = self.character
make_edge = self.engine._get_edge
for (o, d) in self.engine._edges_cache.iter_keys(
self.character.name, *self.engine._btt()
):
yield make_edge(char, o, d) | python | def portals(self):
"""Iterate over all portals."""
char = self.character
make_edge = self.engine._get_edge
for (o, d) in self.engine._edges_cache.iter_keys(
self.character.name, *self.engine._btt()
):
yield make_edge(char, o, d) | [
"def",
"portals",
"(",
"self",
")",
":",
"char",
"=",
"self",
".",
"character",
"make_edge",
"=",
"self",
".",
"engine",
".",
"_get_edge",
"for",
"(",
"o",
",",
"d",
")",
"in",
"self",
".",
"engine",
".",
"_edges_cache",
".",
"iter_keys",
"(",
"self"... | Iterate over all portals. | [
"Iterate",
"over",
"all",
"portals",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/character.py#L2155-L2162 | train | 32,939 |
LogicalDash/LiSE | LiSE/LiSE/character.py | Character.avatars | def avatars(self):
"""Iterate over all my avatars, regardless of what character they are
in.
"""
charname = self.character.name
branch, turn, tick = self.engine._btt()
charmap = self.engine.character
avit = self.engine._avatarness_cache.iter_entities
makenode = self.engine._get_node
for graph in avit(
charname, branch, turn, tick
):
for node in avit(
charname, graph, branch, turn, tick
):
try:
yield makenode(charmap[graph], node)
except KeyError:
continue | python | def avatars(self):
"""Iterate over all my avatars, regardless of what character they are
in.
"""
charname = self.character.name
branch, turn, tick = self.engine._btt()
charmap = self.engine.character
avit = self.engine._avatarness_cache.iter_entities
makenode = self.engine._get_node
for graph in avit(
charname, branch, turn, tick
):
for node in avit(
charname, graph, branch, turn, tick
):
try:
yield makenode(charmap[graph], node)
except KeyError:
continue | [
"def",
"avatars",
"(",
"self",
")",
":",
"charname",
"=",
"self",
".",
"character",
".",
"name",
"branch",
",",
"turn",
",",
"tick",
"=",
"self",
".",
"engine",
".",
"_btt",
"(",
")",
"charmap",
"=",
"self",
".",
"engine",
".",
"character",
"avit",
... | Iterate over all my avatars, regardless of what character they are
in. | [
"Iterate",
"over",
"all",
"my",
"avatars",
"regardless",
"of",
"what",
"character",
"they",
"are",
"in",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/character.py#L2164-L2183 | train | 32,940 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.sql | def sql(self, stringname, *args, **kwargs):
"""Wrapper for the various prewritten or compiled SQL calls.
First argument is the name of the query, either a key in
``sqlite.json`` or a method name in
``allegedb.alchemy.Alchemist``. The rest of the arguments are
parameters to the query.
"""
if hasattr(self, 'alchemist'):
return getattr(self.alchemist, stringname)(*args, **kwargs)
else:
s = self.strings[stringname]
return self.connection.cursor().execute(
s.format(**kwargs) if kwargs else s, args
) | python | def sql(self, stringname, *args, **kwargs):
"""Wrapper for the various prewritten or compiled SQL calls.
First argument is the name of the query, either a key in
``sqlite.json`` or a method name in
``allegedb.alchemy.Alchemist``. The rest of the arguments are
parameters to the query.
"""
if hasattr(self, 'alchemist'):
return getattr(self.alchemist, stringname)(*args, **kwargs)
else:
s = self.strings[stringname]
return self.connection.cursor().execute(
s.format(**kwargs) if kwargs else s, args
) | [
"def",
"sql",
"(",
"self",
",",
"stringname",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'alchemist'",
")",
":",
"return",
"getattr",
"(",
"self",
".",
"alchemist",
",",
"stringname",
")",
"(",
"*",
"ar... | Wrapper for the various prewritten or compiled SQL calls.
First argument is the name of the query, either a key in
``sqlite.json`` or a method name in
``allegedb.alchemy.Alchemist``. The rest of the arguments are
parameters to the query. | [
"Wrapper",
"for",
"the",
"various",
"prewritten",
"or",
"compiled",
"SQL",
"calls",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L155-L170 | train | 32,941 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.sqlmany | def sqlmany(self, stringname, *args):
"""Wrapper for executing many SQL calls on my connection.
First arg is the name of a query, either a key in the
precompiled JSON or a method name in
``allegedb.alchemy.Alchemist``. Remaining arguments should be
tuples of argument sequences to be passed to the query.
"""
if hasattr(self, 'alchemist'):
return getattr(self.alchemist.many, stringname)(*args)
s = self.strings[stringname]
return self.connection.cursor().executemany(s, args) | python | def sqlmany(self, stringname, *args):
"""Wrapper for executing many SQL calls on my connection.
First arg is the name of a query, either a key in the
precompiled JSON or a method name in
``allegedb.alchemy.Alchemist``. Remaining arguments should be
tuples of argument sequences to be passed to the query.
"""
if hasattr(self, 'alchemist'):
return getattr(self.alchemist.many, stringname)(*args)
s = self.strings[stringname]
return self.connection.cursor().executemany(s, args) | [
"def",
"sqlmany",
"(",
"self",
",",
"stringname",
",",
"*",
"args",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'alchemist'",
")",
":",
"return",
"getattr",
"(",
"self",
".",
"alchemist",
".",
"many",
",",
"stringname",
")",
"(",
"*",
"args",
")",
... | Wrapper for executing many SQL calls on my connection.
First arg is the name of a query, either a key in the
precompiled JSON or a method name in
``allegedb.alchemy.Alchemist``. Remaining arguments should be
tuples of argument sequences to be passed to the query. | [
"Wrapper",
"for",
"executing",
"many",
"SQL",
"calls",
"on",
"my",
"connection",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L172-L184 | train | 32,942 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.have_graph | def have_graph(self, graph):
"""Return whether I have a graph by this name."""
graph = self.pack(graph)
return bool(self.sql('graphs_named', graph).fetchone()[0]) | python | def have_graph(self, graph):
"""Return whether I have a graph by this name."""
graph = self.pack(graph)
return bool(self.sql('graphs_named', graph).fetchone()[0]) | [
"def",
"have_graph",
"(",
"self",
",",
"graph",
")",
":",
"graph",
"=",
"self",
".",
"pack",
"(",
"graph",
")",
"return",
"bool",
"(",
"self",
".",
"sql",
"(",
"'graphs_named'",
",",
"graph",
")",
".",
"fetchone",
"(",
")",
"[",
"0",
"]",
")"
] | Return whether I have a graph by this name. | [
"Return",
"whether",
"I",
"have",
"a",
"graph",
"by",
"this",
"name",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L186-L189 | train | 32,943 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.new_graph | def new_graph(self, graph, typ):
"""Declare a new graph by this name of this type."""
graph = self.pack(graph)
return self.sql('new_graph', graph, typ) | python | def new_graph(self, graph, typ):
"""Declare a new graph by this name of this type."""
graph = self.pack(graph)
return self.sql('new_graph', graph, typ) | [
"def",
"new_graph",
"(",
"self",
",",
"graph",
",",
"typ",
")",
":",
"graph",
"=",
"self",
".",
"pack",
"(",
"graph",
")",
"return",
"self",
".",
"sql",
"(",
"'new_graph'",
",",
"graph",
",",
"typ",
")"
] | Declare a new graph by this name of this type. | [
"Declare",
"a",
"new",
"graph",
"by",
"this",
"name",
"of",
"this",
"type",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L191-L194 | train | 32,944 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.del_graph | def del_graph(self, graph):
"""Delete all records to do with the graph"""
g = self.pack(graph)
self.sql('del_edge_val_graph', g)
self.sql('del_node_val_graph', g)
self.sql('del_edge_val_graph', g)
self.sql('del_edges_graph', g)
self.sql('del_nodes_graph', g)
self.sql('del_graph', g) | python | def del_graph(self, graph):
"""Delete all records to do with the graph"""
g = self.pack(graph)
self.sql('del_edge_val_graph', g)
self.sql('del_node_val_graph', g)
self.sql('del_edge_val_graph', g)
self.sql('del_edges_graph', g)
self.sql('del_nodes_graph', g)
self.sql('del_graph', g) | [
"def",
"del_graph",
"(",
"self",
",",
"graph",
")",
":",
"g",
"=",
"self",
".",
"pack",
"(",
"graph",
")",
"self",
".",
"sql",
"(",
"'del_edge_val_graph'",
",",
"g",
")",
"self",
".",
"sql",
"(",
"'del_node_val_graph'",
",",
"g",
")",
"self",
".",
... | Delete all records to do with the graph | [
"Delete",
"all",
"records",
"to",
"do",
"with",
"the",
"graph"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L196-L204 | train | 32,945 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.graph_type | def graph_type(self, graph):
"""What type of graph is this?"""
graph = self.pack(graph)
return self.sql('graph_type', graph).fetchone()[0] | python | def graph_type(self, graph):
"""What type of graph is this?"""
graph = self.pack(graph)
return self.sql('graph_type', graph).fetchone()[0] | [
"def",
"graph_type",
"(",
"self",
",",
"graph",
")",
":",
"graph",
"=",
"self",
".",
"pack",
"(",
"graph",
")",
"return",
"self",
".",
"sql",
"(",
"'graph_type'",
",",
"graph",
")",
".",
"fetchone",
"(",
")",
"[",
"0",
"]"
] | What type of graph is this? | [
"What",
"type",
"of",
"graph",
"is",
"this?"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L206-L209 | train | 32,946 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.global_get | def global_get(self, key):
"""Return the value for the given key in the ``globals`` table."""
key = self.pack(key)
r = self.sql('global_get', key).fetchone()
if r is None:
raise KeyError("Not set")
return self.unpack(r[0]) | python | def global_get(self, key):
"""Return the value for the given key in the ``globals`` table."""
key = self.pack(key)
r = self.sql('global_get', key).fetchone()
if r is None:
raise KeyError("Not set")
return self.unpack(r[0]) | [
"def",
"global_get",
"(",
"self",
",",
"key",
")",
":",
"key",
"=",
"self",
".",
"pack",
"(",
"key",
")",
"r",
"=",
"self",
".",
"sql",
"(",
"'global_get'",
",",
"key",
")",
".",
"fetchone",
"(",
")",
"if",
"r",
"is",
"None",
":",
"raise",
"Key... | Return the value for the given key in the ``globals`` table. | [
"Return",
"the",
"value",
"for",
"the",
"given",
"key",
"in",
"the",
"globals",
"table",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L222-L228 | train | 32,947 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.global_del | def global_del(self, key):
"""Delete the global record for the key."""
key = self.pack(key)
return self.sql('global_del', key) | python | def global_del(self, key):
"""Delete the global record for the key."""
key = self.pack(key)
return self.sql('global_del', key) | [
"def",
"global_del",
"(",
"self",
",",
"key",
")",
":",
"key",
"=",
"self",
".",
"pack",
"(",
"key",
")",
"return",
"self",
".",
"sql",
"(",
"'global_del'",
",",
"key",
")"
] | Delete the global record for the key. | [
"Delete",
"the",
"global",
"record",
"for",
"the",
"key",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L246-L249 | train | 32,948 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.new_branch | def new_branch(self, branch, parent, parent_turn, parent_tick):
"""Declare that the ``branch`` is descended from ``parent`` at
``parent_turn``, ``parent_tick``
"""
return self.sql('branches_insert', branch, parent, parent_turn, parent_tick, parent_turn, parent_tick) | python | def new_branch(self, branch, parent, parent_turn, parent_tick):
"""Declare that the ``branch`` is descended from ``parent`` at
``parent_turn``, ``parent_tick``
"""
return self.sql('branches_insert', branch, parent, parent_turn, parent_tick, parent_turn, parent_tick) | [
"def",
"new_branch",
"(",
"self",
",",
"branch",
",",
"parent",
",",
"parent_turn",
",",
"parent_tick",
")",
":",
"return",
"self",
".",
"sql",
"(",
"'branches_insert'",
",",
"branch",
",",
"parent",
",",
"parent_turn",
",",
"parent_tick",
",",
"parent_turn"... | Declare that the ``branch`` is descended from ``parent`` at
``parent_turn``, ``parent_tick`` | [
"Declare",
"that",
"the",
"branch",
"is",
"descended",
"from",
"parent",
"at",
"parent_turn",
"parent_tick"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L251-L256 | train | 32,949 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.graph_val_dump | def graph_val_dump(self):
"""Yield the entire contents of the graph_val table."""
self._flush_graph_val()
for (graph, key, branch, turn, tick, value) in self.sql('graph_val_dump'):
yield (
self.unpack(graph),
self.unpack(key),
branch,
turn,
tick,
self.unpack(value)
) | python | def graph_val_dump(self):
"""Yield the entire contents of the graph_val table."""
self._flush_graph_val()
for (graph, key, branch, turn, tick, value) in self.sql('graph_val_dump'):
yield (
self.unpack(graph),
self.unpack(key),
branch,
turn,
tick,
self.unpack(value)
) | [
"def",
"graph_val_dump",
"(",
"self",
")",
":",
"self",
".",
"_flush_graph_val",
"(",
")",
"for",
"(",
"graph",
",",
"key",
",",
"branch",
",",
"turn",
",",
"tick",
",",
"value",
")",
"in",
"self",
".",
"sql",
"(",
"'graph_val_dump'",
")",
":",
"yiel... | Yield the entire contents of the graph_val table. | [
"Yield",
"the",
"entire",
"contents",
"of",
"the",
"graph_val",
"table",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L282-L293 | train | 32,950 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine._flush_graph_val | def _flush_graph_val(self):
"""Send all new and changed graph values to the database."""
if not self._graphvals2set:
return
delafter = {}
for graph, key, branch, turn, tick, value in self._graphvals2set:
if (graph, key, branch) in delafter:
delafter[graph, key, branch] = min((
(turn, tick),
delafter[graph, key, branch]
))
else:
delafter[graph, key, branch] = (turn, tick)
self.sqlmany(
'del_graph_val_after',
*((graph, key, branch, turn, turn, tick)
for ((graph, key, branch), (turn, tick)) in delafter.items())
)
self.sqlmany('graph_val_insert', *self._graphvals2set)
self._graphvals2set = [] | python | def _flush_graph_val(self):
"""Send all new and changed graph values to the database."""
if not self._graphvals2set:
return
delafter = {}
for graph, key, branch, turn, tick, value in self._graphvals2set:
if (graph, key, branch) in delafter:
delafter[graph, key, branch] = min((
(turn, tick),
delafter[graph, key, branch]
))
else:
delafter[graph, key, branch] = (turn, tick)
self.sqlmany(
'del_graph_val_after',
*((graph, key, branch, turn, turn, tick)
for ((graph, key, branch), (turn, tick)) in delafter.items())
)
self.sqlmany('graph_val_insert', *self._graphvals2set)
self._graphvals2set = [] | [
"def",
"_flush_graph_val",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_graphvals2set",
":",
"return",
"delafter",
"=",
"{",
"}",
"for",
"graph",
",",
"key",
",",
"branch",
",",
"turn",
",",
"tick",
",",
"value",
"in",
"self",
".",
"_graphvals2se... | Send all new and changed graph values to the database. | [
"Send",
"all",
"new",
"and",
"changed",
"graph",
"values",
"to",
"the",
"database",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L295-L314 | train | 32,951 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.exist_node | def exist_node(self, graph, node, branch, turn, tick, extant):
"""Declare that the node exists or doesn't.
Inserts a new record or updates an old one, as needed.
"""
if (branch, turn, tick) in self._btts:
raise TimeError
self._btts.add((branch, turn, tick))
self._nodes2set.append((self.pack(graph), self.pack(node), branch, turn, tick, extant)) | python | def exist_node(self, graph, node, branch, turn, tick, extant):
"""Declare that the node exists or doesn't.
Inserts a new record or updates an old one, as needed.
"""
if (branch, turn, tick) in self._btts:
raise TimeError
self._btts.add((branch, turn, tick))
self._nodes2set.append((self.pack(graph), self.pack(node), branch, turn, tick, extant)) | [
"def",
"exist_node",
"(",
"self",
",",
"graph",
",",
"node",
",",
"branch",
",",
"turn",
",",
"tick",
",",
"extant",
")",
":",
"if",
"(",
"branch",
",",
"turn",
",",
"tick",
")",
"in",
"self",
".",
"_btts",
":",
"raise",
"TimeError",
"self",
".",
... | Declare that the node exists or doesn't.
Inserts a new record or updates an old one, as needed. | [
"Declare",
"that",
"the",
"node",
"exists",
"or",
"doesn",
"t",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L348-L357 | train | 32,952 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.nodes_dump | def nodes_dump(self):
"""Dump the entire contents of the nodes table."""
self._flush_nodes()
for (graph, node, branch, turn,tick, extant) in self.sql('nodes_dump'):
yield (
self.unpack(graph),
self.unpack(node),
branch,
turn,
tick,
bool(extant)
) | python | def nodes_dump(self):
"""Dump the entire contents of the nodes table."""
self._flush_nodes()
for (graph, node, branch, turn,tick, extant) in self.sql('nodes_dump'):
yield (
self.unpack(graph),
self.unpack(node),
branch,
turn,
tick,
bool(extant)
) | [
"def",
"nodes_dump",
"(",
"self",
")",
":",
"self",
".",
"_flush_nodes",
"(",
")",
"for",
"(",
"graph",
",",
"node",
",",
"branch",
",",
"turn",
",",
"tick",
",",
"extant",
")",
"in",
"self",
".",
"sql",
"(",
"'nodes_dump'",
")",
":",
"yield",
"(",... | Dump the entire contents of the nodes table. | [
"Dump",
"the",
"entire",
"contents",
"of",
"the",
"nodes",
"table",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L364-L375 | train | 32,953 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.node_val_dump | def node_val_dump(self):
"""Yield the entire contents of the node_val table."""
self._flush_node_val()
for (
graph, node, key, branch, turn, tick, value
) in self.sql('node_val_dump'):
yield (
self.unpack(graph),
self.unpack(node),
self.unpack(key),
branch,
turn,
tick,
self.unpack(value)
) | python | def node_val_dump(self):
"""Yield the entire contents of the node_val table."""
self._flush_node_val()
for (
graph, node, key, branch, turn, tick, value
) in self.sql('node_val_dump'):
yield (
self.unpack(graph),
self.unpack(node),
self.unpack(key),
branch,
turn,
tick,
self.unpack(value)
) | [
"def",
"node_val_dump",
"(",
"self",
")",
":",
"self",
".",
"_flush_node_val",
"(",
")",
"for",
"(",
"graph",
",",
"node",
",",
"key",
",",
"branch",
",",
"turn",
",",
"tick",
",",
"value",
")",
"in",
"self",
".",
"sql",
"(",
"'node_val_dump'",
")",
... | Yield the entire contents of the node_val table. | [
"Yield",
"the",
"entire",
"contents",
"of",
"the",
"node_val",
"table",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L377-L391 | train | 32,954 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.node_val_set | def node_val_set(self, graph, node, key, branch, turn, tick, value):
"""Set a key-value pair on a node at a specific branch and revision"""
if (branch, turn, tick) in self._btts:
raise TimeError
self._btts.add((branch, turn, tick))
graph, node, key, value = map(self.pack, (graph, node, key, value))
self._nodevals2set.append((graph, node, key, branch, turn, tick, value)) | python | def node_val_set(self, graph, node, key, branch, turn, tick, value):
"""Set a key-value pair on a node at a specific branch and revision"""
if (branch, turn, tick) in self._btts:
raise TimeError
self._btts.add((branch, turn, tick))
graph, node, key, value = map(self.pack, (graph, node, key, value))
self._nodevals2set.append((graph, node, key, branch, turn, tick, value)) | [
"def",
"node_val_set",
"(",
"self",
",",
"graph",
",",
"node",
",",
"key",
",",
"branch",
",",
"turn",
",",
"tick",
",",
"value",
")",
":",
"if",
"(",
"branch",
",",
"turn",
",",
"tick",
")",
"in",
"self",
".",
"_btts",
":",
"raise",
"TimeError",
... | Set a key-value pair on a node at a specific branch and revision | [
"Set",
"a",
"key",
"-",
"value",
"pair",
"on",
"a",
"node",
"at",
"a",
"specific",
"branch",
"and",
"revision"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L415-L421 | train | 32,955 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.edges_dump | def edges_dump(self):
"""Dump the entire contents of the edges table."""
self._flush_edges()
for (
graph, orig, dest, idx, branch, turn, tick, extant
) in self.sql('edges_dump'):
yield (
self.unpack(graph),
self.unpack(orig),
self.unpack(dest),
idx,
branch,
turn,
tick,
bool(extant)
) | python | def edges_dump(self):
"""Dump the entire contents of the edges table."""
self._flush_edges()
for (
graph, orig, dest, idx, branch, turn, tick, extant
) in self.sql('edges_dump'):
yield (
self.unpack(graph),
self.unpack(orig),
self.unpack(dest),
idx,
branch,
turn,
tick,
bool(extant)
) | [
"def",
"edges_dump",
"(",
"self",
")",
":",
"self",
".",
"_flush_edges",
"(",
")",
"for",
"(",
"graph",
",",
"orig",
",",
"dest",
",",
"idx",
",",
"branch",
",",
"turn",
",",
"tick",
",",
"extant",
")",
"in",
"self",
".",
"sql",
"(",
"'edges_dump'"... | Dump the entire contents of the edges table. | [
"Dump",
"the",
"entire",
"contents",
"of",
"the",
"edges",
"table",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L428-L443 | train | 32,956 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.exist_edge | def exist_edge(self, graph, orig, dest, idx, branch, turn, tick, extant):
"""Declare whether or not this edge exists."""
if (branch, turn, tick) in self._btts:
raise TimeError
self._btts.add((branch, turn, tick))
graph, orig, dest = map(self.pack, (graph, orig, dest))
self._edges2set.append((graph, orig, dest, idx, branch, turn, tick, extant)) | python | def exist_edge(self, graph, orig, dest, idx, branch, turn, tick, extant):
"""Declare whether or not this edge exists."""
if (branch, turn, tick) in self._btts:
raise TimeError
self._btts.add((branch, turn, tick))
graph, orig, dest = map(self.pack, (graph, orig, dest))
self._edges2set.append((graph, orig, dest, idx, branch, turn, tick, extant)) | [
"def",
"exist_edge",
"(",
"self",
",",
"graph",
",",
"orig",
",",
"dest",
",",
"idx",
",",
"branch",
",",
"turn",
",",
"tick",
",",
"extant",
")",
":",
"if",
"(",
"branch",
",",
"turn",
",",
"tick",
")",
"in",
"self",
".",
"_btts",
":",
"raise",
... | Declare whether or not this edge exists. | [
"Declare",
"whether",
"or",
"not",
"this",
"edge",
"exists",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L468-L474 | train | 32,957 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.edge_val_dump | def edge_val_dump(self):
"""Yield the entire contents of the edge_val table."""
self._flush_edge_val()
for (
graph, orig, dest, idx, key, branch, turn, tick, value
) in self.sql('edge_val_dump'):
yield (
self.unpack(graph),
self.unpack(orig),
self.unpack(dest),
idx,
self.unpack(key),
branch,
turn,
tick,
self.unpack(value)
) | python | def edge_val_dump(self):
"""Yield the entire contents of the edge_val table."""
self._flush_edge_val()
for (
graph, orig, dest, idx, key, branch, turn, tick, value
) in self.sql('edge_val_dump'):
yield (
self.unpack(graph),
self.unpack(orig),
self.unpack(dest),
idx,
self.unpack(key),
branch,
turn,
tick,
self.unpack(value)
) | [
"def",
"edge_val_dump",
"(",
"self",
")",
":",
"self",
".",
"_flush_edge_val",
"(",
")",
"for",
"(",
"graph",
",",
"orig",
",",
"dest",
",",
"idx",
",",
"key",
",",
"branch",
",",
"turn",
",",
"tick",
",",
"value",
")",
"in",
"self",
".",
"sql",
... | Yield the entire contents of the edge_val table. | [
"Yield",
"the",
"entire",
"contents",
"of",
"the",
"edge_val",
"table",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L481-L497 | train | 32,958 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.edge_val_set | def edge_val_set(self, graph, orig, dest, idx, key, branch, turn, tick, value):
"""Set this key of this edge to this value."""
if (branch, turn, tick) in self._btts:
raise TimeError
self._btts.add((branch, turn, tick))
graph, orig, dest, key, value = map(self.pack, (graph, orig, dest, key, value))
self._edgevals2set.append(
(graph, orig, dest, idx, key, branch, turn, tick, value)
) | python | def edge_val_set(self, graph, orig, dest, idx, key, branch, turn, tick, value):
"""Set this key of this edge to this value."""
if (branch, turn, tick) in self._btts:
raise TimeError
self._btts.add((branch, turn, tick))
graph, orig, dest, key, value = map(self.pack, (graph, orig, dest, key, value))
self._edgevals2set.append(
(graph, orig, dest, idx, key, branch, turn, tick, value)
) | [
"def",
"edge_val_set",
"(",
"self",
",",
"graph",
",",
"orig",
",",
"dest",
",",
"idx",
",",
"key",
",",
"branch",
",",
"turn",
",",
"tick",
",",
"value",
")",
":",
"if",
"(",
"branch",
",",
"turn",
",",
"tick",
")",
"in",
"self",
".",
"_btts",
... | Set this key of this edge to this value. | [
"Set",
"this",
"key",
"of",
"this",
"edge",
"to",
"this",
"value",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L520-L528 | train | 32,959 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.initdb | def initdb(self):
"""Create tables and indices as needed."""
if hasattr(self, 'alchemist'):
self.alchemist.meta.create_all(self.engine)
if 'branch' not in self.globl:
self.globl['branch'] = 'trunk'
if 'rev' not in self.globl:
self.globl['rev'] = 0
return
from sqlite3 import OperationalError
cursor = self.connection.cursor()
try:
cursor.execute('SELECT * FROM global;')
except OperationalError:
cursor.execute(self.strings['create_global'])
if 'branch' not in self.globl:
self.globl['branch'] = 'trunk'
if 'turn' not in self.globl:
self.globl['turn'] = 0
if 'tick' not in self.globl:
self.globl['tick'] = 0
for table in (
'branches',
'turns',
'graphs',
'graph_val',
'nodes',
'node_val',
'edges',
'edge_val',
'plans',
'plan_ticks'
):
try:
cursor.execute('SELECT * FROM ' + table + ';')
except OperationalError:
cursor.execute(self.strings['create_' + table]) | python | def initdb(self):
"""Create tables and indices as needed."""
if hasattr(self, 'alchemist'):
self.alchemist.meta.create_all(self.engine)
if 'branch' not in self.globl:
self.globl['branch'] = 'trunk'
if 'rev' not in self.globl:
self.globl['rev'] = 0
return
from sqlite3 import OperationalError
cursor = self.connection.cursor()
try:
cursor.execute('SELECT * FROM global;')
except OperationalError:
cursor.execute(self.strings['create_global'])
if 'branch' not in self.globl:
self.globl['branch'] = 'trunk'
if 'turn' not in self.globl:
self.globl['turn'] = 0
if 'tick' not in self.globl:
self.globl['tick'] = 0
for table in (
'branches',
'turns',
'graphs',
'graph_val',
'nodes',
'node_val',
'edges',
'edge_val',
'plans',
'plan_ticks'
):
try:
cursor.execute('SELECT * FROM ' + table + ';')
except OperationalError:
cursor.execute(self.strings['create_' + table]) | [
"def",
"initdb",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'alchemist'",
")",
":",
"self",
".",
"alchemist",
".",
"meta",
".",
"create_all",
"(",
"self",
".",
"engine",
")",
"if",
"'branch'",
"not",
"in",
"self",
".",
"globl",
":",
... | Create tables and indices as needed. | [
"Create",
"tables",
"and",
"indices",
"as",
"needed",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L553-L589 | train | 32,960 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.flush | def flush(self):
"""Put all pending changes into the SQL transaction."""
self._flush_nodes()
self._flush_edges()
self._flush_graph_val()
self._flush_node_val()
self._flush_edge_val() | python | def flush(self):
"""Put all pending changes into the SQL transaction."""
self._flush_nodes()
self._flush_edges()
self._flush_graph_val()
self._flush_node_val()
self._flush_edge_val() | [
"def",
"flush",
"(",
"self",
")",
":",
"self",
".",
"_flush_nodes",
"(",
")",
"self",
".",
"_flush_edges",
"(",
")",
"self",
".",
"_flush_graph_val",
"(",
")",
"self",
".",
"_flush_node_val",
"(",
")",
"self",
".",
"_flush_edge_val",
"(",
")"
] | Put all pending changes into the SQL transaction. | [
"Put",
"all",
"pending",
"changes",
"into",
"the",
"SQL",
"transaction",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L591-L597 | train | 32,961 |
LogicalDash/LiSE | allegedb/allegedb/query.py | QueryEngine.commit | def commit(self):
"""Commit the transaction"""
self.flush()
if hasattr(self, 'transaction') and self.transaction.is_active:
self.transaction.commit()
elif hasattr(self, 'connection'):
self.connection.commit() | python | def commit(self):
"""Commit the transaction"""
self.flush()
if hasattr(self, 'transaction') and self.transaction.is_active:
self.transaction.commit()
elif hasattr(self, 'connection'):
self.connection.commit() | [
"def",
"commit",
"(",
"self",
")",
":",
"self",
".",
"flush",
"(",
")",
"if",
"hasattr",
"(",
"self",
",",
"'transaction'",
")",
"and",
"self",
".",
"transaction",
".",
"is_active",
":",
"self",
".",
"transaction",
".",
"commit",
"(",
")",
"elif",
"h... | Commit the transaction | [
"Commit",
"the",
"transaction"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/query.py#L599-L605 | train | 32,962 |
LogicalDash/LiSE | LiSE/LiSE/node.py | Node.path_exists | def path_exists(self, dest, weight=None):
"""Return whether there is a path leading from me to ``dest``.
With ``weight``, only consider edges that have a stat by the
given name.
Raise ``ValueError`` if ``dest`` is not a node in my character
or the name of one.
"""
try:
return bool(self.shortest_path_length(dest, weight))
except KeyError:
return False | python | def path_exists(self, dest, weight=None):
"""Return whether there is a path leading from me to ``dest``.
With ``weight``, only consider edges that have a stat by the
given name.
Raise ``ValueError`` if ``dest`` is not a node in my character
or the name of one.
"""
try:
return bool(self.shortest_path_length(dest, weight))
except KeyError:
return False | [
"def",
"path_exists",
"(",
"self",
",",
"dest",
",",
"weight",
"=",
"None",
")",
":",
"try",
":",
"return",
"bool",
"(",
"self",
".",
"shortest_path_length",
"(",
"dest",
",",
"weight",
")",
")",
"except",
"KeyError",
":",
"return",
"False"
] | Return whether there is a path leading from me to ``dest``.
With ``weight``, only consider edges that have a stat by the
given name.
Raise ``ValueError`` if ``dest`` is not a node in my character
or the name of one. | [
"Return",
"whether",
"there",
"is",
"a",
"path",
"leading",
"from",
"me",
"to",
"dest",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/node.py#L439-L452 | train | 32,963 |
LogicalDash/LiSE | LiSE/LiSE/node.py | Node.delete | def delete(self):
"""Get rid of this, starting now.
Apart from deleting the node, this also informs all its users
that it doesn't exist and therefore can't be their avatar
anymore.
"""
if self.name in self.character.portal:
del self.character.portal[self.name]
if self.name in self.character.preportal:
del self.character.preportal[self.name]
for contained in list(self.contents()):
contained.delete()
for user in list(self.users.values()):
user.del_avatar(self.character.name, self.name)
branch, turn, tick = self.engine._nbtt()
self.engine._nodes_cache.store(
self.character.name, self.name,
branch, turn, tick, False
)
self.engine.query.exist_node(
self.character.name, self.name,
branch, turn, tick, False
)
self.character.node.send(self.character.node, key=self.name, val=None) | python | def delete(self):
"""Get rid of this, starting now.
Apart from deleting the node, this also informs all its users
that it doesn't exist and therefore can't be their avatar
anymore.
"""
if self.name in self.character.portal:
del self.character.portal[self.name]
if self.name in self.character.preportal:
del self.character.preportal[self.name]
for contained in list(self.contents()):
contained.delete()
for user in list(self.users.values()):
user.del_avatar(self.character.name, self.name)
branch, turn, tick = self.engine._nbtt()
self.engine._nodes_cache.store(
self.character.name, self.name,
branch, turn, tick, False
)
self.engine.query.exist_node(
self.character.name, self.name,
branch, turn, tick, False
)
self.character.node.send(self.character.node, key=self.name, val=None) | [
"def",
"delete",
"(",
"self",
")",
":",
"if",
"self",
".",
"name",
"in",
"self",
".",
"character",
".",
"portal",
":",
"del",
"self",
".",
"character",
".",
"portal",
"[",
"self",
".",
"name",
"]",
"if",
"self",
".",
"name",
"in",
"self",
".",
"c... | Get rid of this, starting now.
Apart from deleting the node, this also informs all its users
that it doesn't exist and therefore can't be their avatar
anymore. | [
"Get",
"rid",
"of",
"this",
"starting",
"now",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/node.py#L461-L486 | train | 32,964 |
LogicalDash/LiSE | LiSE/LiSE/node.py | Node.one_way_portal | def one_way_portal(self, other, **stats):
"""Connect a portal from here to another node, and return it."""
return self.character.new_portal(
self, other, symmetrical=False, **stats
) | python | def one_way_portal(self, other, **stats):
"""Connect a portal from here to another node, and return it."""
return self.character.new_portal(
self, other, symmetrical=False, **stats
) | [
"def",
"one_way_portal",
"(",
"self",
",",
"other",
",",
"*",
"*",
"stats",
")",
":",
"return",
"self",
".",
"character",
".",
"new_portal",
"(",
"self",
",",
"other",
",",
"symmetrical",
"=",
"False",
",",
"*",
"*",
"stats",
")"
] | Connect a portal from here to another node, and return it. | [
"Connect",
"a",
"portal",
"from",
"here",
"to",
"another",
"node",
"and",
"return",
"it",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/node.py#L488-L492 | train | 32,965 |
LogicalDash/LiSE | LiSE/LiSE/node.py | Node.two_way_portal | def two_way_portal(self, other, **stats):
"""Connect these nodes with a two-way portal and return it."""
return self.character.new_portal(
self, other, symmetrical=True, **stats
) | python | def two_way_portal(self, other, **stats):
"""Connect these nodes with a two-way portal and return it."""
return self.character.new_portal(
self, other, symmetrical=True, **stats
) | [
"def",
"two_way_portal",
"(",
"self",
",",
"other",
",",
"*",
"*",
"stats",
")",
":",
"return",
"self",
".",
"character",
".",
"new_portal",
"(",
"self",
",",
"other",
",",
"symmetrical",
"=",
"True",
",",
"*",
"*",
"stats",
")"
] | Connect these nodes with a two-way portal and return it. | [
"Connect",
"these",
"nodes",
"with",
"a",
"two",
"-",
"way",
"portal",
"and",
"return",
"it",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/node.py#L498-L502 | train | 32,966 |
LogicalDash/LiSE | LiSE/LiSE/node.py | Node.new_thing | def new_thing(self, name, **stats):
"""Create a new thing, located here, and return it."""
return self.character.new_thing(
name, self.name, **stats
) | python | def new_thing(self, name, **stats):
"""Create a new thing, located here, and return it."""
return self.character.new_thing(
name, self.name, **stats
) | [
"def",
"new_thing",
"(",
"self",
",",
"name",
",",
"*",
"*",
"stats",
")",
":",
"return",
"self",
".",
"character",
".",
"new_thing",
"(",
"name",
",",
"self",
".",
"name",
",",
"*",
"*",
"stats",
")"
] | Create a new thing, located here, and return it. | [
"Create",
"a",
"new",
"thing",
"located",
"here",
"and",
"return",
"it",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/node.py#L508-L512 | train | 32,967 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | Card.on_background_image | def on_background_image(self, *args):
"""When I get a new ``background_image``, store its texture in
``background_texture``.
"""
if self.background_image is not None:
self.background_texture = self.background_image.texture | python | def on_background_image(self, *args):
"""When I get a new ``background_image``, store its texture in
``background_texture``.
"""
if self.background_image is not None:
self.background_texture = self.background_image.texture | [
"def",
"on_background_image",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"background_image",
"is",
"not",
"None",
":",
"self",
".",
"background_texture",
"=",
"self",
".",
"background_image",
".",
"texture"
] | When I get a new ``background_image``, store its texture in
``background_texture``. | [
"When",
"I",
"get",
"a",
"new",
"background_image",
"store",
"its",
"texture",
"in",
"background_texture",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L209-L215 | train | 32,968 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | Card.on_foreground_image | def on_foreground_image(self, *args):
"""When I get a new ``foreground_image``, store its texture in my
``foreground_texture``.
"""
if self.foreground_image is not None:
self.foreground_texture = self.foreground_image.texture | python | def on_foreground_image(self, *args):
"""When I get a new ``foreground_image``, store its texture in my
``foreground_texture``.
"""
if self.foreground_image is not None:
self.foreground_texture = self.foreground_image.texture | [
"def",
"on_foreground_image",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"foreground_image",
"is",
"not",
"None",
":",
"self",
".",
"foreground_texture",
"=",
"self",
".",
"foreground_image",
".",
"texture"
] | When I get a new ``foreground_image``, store its texture in my
``foreground_texture``. | [
"When",
"I",
"get",
"a",
"new",
"foreground_image",
"store",
"its",
"texture",
"in",
"my",
"foreground_texture",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L225-L231 | train | 32,969 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | Card.on_art_image | def on_art_image(self, *args):
"""When I get a new ``art_image``, store its texture in
``art_texture``.
"""
if self.art_image is not None:
self.art_texture = self.art_image.texture | python | def on_art_image(self, *args):
"""When I get a new ``art_image``, store its texture in
``art_texture``.
"""
if self.art_image is not None:
self.art_texture = self.art_image.texture | [
"def",
"on_art_image",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"art_image",
"is",
"not",
"None",
":",
"self",
".",
"art_texture",
"=",
"self",
".",
"art_image",
".",
"texture"
] | When I get a new ``art_image``, store its texture in
``art_texture``. | [
"When",
"I",
"get",
"a",
"new",
"art_image",
"store",
"its",
"texture",
"in",
"art_texture",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L241-L247 | train | 32,970 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | Card.on_touch_down | def on_touch_down(self, touch):
"""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.
"""
if not self.collide_point(*touch.pos):
return
if 'card' in touch.ud:
return
touch.grab(self)
self.dragging = True
touch.ud['card'] = self
touch.ud['idx'] = self.idx
touch.ud['deck'] = self.deck
touch.ud['layout'] = self.parent
self.collide_x = touch.x - self.x
self.collide_y = touch.y - self.y | python | def on_touch_down(self, touch):
"""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.
"""
if not self.collide_point(*touch.pos):
return
if 'card' in touch.ud:
return
touch.grab(self)
self.dragging = True
touch.ud['card'] = self
touch.ud['idx'] = self.idx
touch.ud['deck'] = self.deck
touch.ud['layout'] = self.parent
self.collide_x = touch.x - self.x
self.collide_y = touch.y - self.y | [
"def",
"on_touch_down",
"(",
"self",
",",
"touch",
")",
":",
"if",
"not",
"self",
".",
"collide_point",
"(",
"*",
"touch",
".",
"pos",
")",
":",
"return",
"if",
"'card'",
"in",
"touch",
".",
"ud",
":",
"return",
"touch",
".",
"grab",
"(",
"self",
"... | 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. | [
"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",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L249-L266 | train | 32,971 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | Card.on_touch_move | def on_touch_move(self, touch):
"""If I'm being dragged, move so as to be always positioned the same
relative to the touch.
"""
if not self.dragging:
touch.ungrab(self)
return
self.pos = (
touch.x - self.collide_x,
touch.y - self.collide_y
) | python | def on_touch_move(self, touch):
"""If I'm being dragged, move so as to be always positioned the same
relative to the touch.
"""
if not self.dragging:
touch.ungrab(self)
return
self.pos = (
touch.x - self.collide_x,
touch.y - self.collide_y
) | [
"def",
"on_touch_move",
"(",
"self",
",",
"touch",
")",
":",
"if",
"not",
"self",
".",
"dragging",
":",
"touch",
".",
"ungrab",
"(",
"self",
")",
"return",
"self",
".",
"pos",
"=",
"(",
"touch",
".",
"x",
"-",
"self",
".",
"collide_x",
",",
"touch"... | If I'm being dragged, move so as to be always positioned the same
relative to the touch. | [
"If",
"I",
"m",
"being",
"dragged",
"move",
"so",
"as",
"to",
"be",
"always",
"positioned",
"the",
"same",
"relative",
"to",
"the",
"touch",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L268-L279 | train | 32,972 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | Card.on_touch_up | def on_touch_up(self, touch):
"""Stop dragging if needed."""
if not self.dragging:
return
touch.ungrab(self)
self.dragging = False | python | def on_touch_up(self, touch):
"""Stop dragging if needed."""
if not self.dragging:
return
touch.ungrab(self)
self.dragging = False | [
"def",
"on_touch_up",
"(",
"self",
",",
"touch",
")",
":",
"if",
"not",
"self",
".",
"dragging",
":",
"return",
"touch",
".",
"ungrab",
"(",
"self",
")",
"self",
".",
"dragging",
"=",
"False"
] | Stop dragging if needed. | [
"Stop",
"dragging",
"if",
"needed",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L281-L286 | train | 32,973 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | Foundation.upd_pos | def upd_pos(self, *args):
"""Ask the foundation where I should be, based on what deck I'm
for.
"""
self.pos = self.parent._get_foundation_pos(self.deck) | python | def upd_pos(self, *args):
"""Ask the foundation where I should be, based on what deck I'm
for.
"""
self.pos = self.parent._get_foundation_pos(self.deck) | [
"def",
"upd_pos",
"(",
"self",
",",
"*",
"args",
")",
":",
"self",
".",
"pos",
"=",
"self",
".",
"parent",
".",
"_get_foundation_pos",
"(",
"self",
".",
"deck",
")"
] | Ask the foundation where I should be, based on what deck I'm
for. | [
"Ask",
"the",
"foundation",
"where",
"I",
"should",
"be",
"based",
"on",
"what",
"deck",
"I",
"m",
"for",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L349-L354 | train | 32,974 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderLayout.scroll_deck_x | def scroll_deck_x(self, decknum, scroll_x):
"""Move a deck left or right."""
if decknum >= len(self.decks):
raise IndexError("I have no deck at {}".format(decknum))
if decknum >= len(self.deck_x_hint_offsets):
self.deck_x_hint_offsets = list(self.deck_x_hint_offsets) + [0] * (
decknum - len(self.deck_x_hint_offsets) + 1
)
self.deck_x_hint_offsets[decknum] += scroll_x
self._trigger_layout() | python | def scroll_deck_x(self, decknum, scroll_x):
"""Move a deck left or right."""
if decknum >= len(self.decks):
raise IndexError("I have no deck at {}".format(decknum))
if decknum >= len(self.deck_x_hint_offsets):
self.deck_x_hint_offsets = list(self.deck_x_hint_offsets) + [0] * (
decknum - len(self.deck_x_hint_offsets) + 1
)
self.deck_x_hint_offsets[decknum] += scroll_x
self._trigger_layout() | [
"def",
"scroll_deck_x",
"(",
"self",
",",
"decknum",
",",
"scroll_x",
")",
":",
"if",
"decknum",
">=",
"len",
"(",
"self",
".",
"decks",
")",
":",
"raise",
"IndexError",
"(",
"\"I have no deck at {}\"",
".",
"format",
"(",
"decknum",
")",
")",
"if",
"dec... | Move a deck left or right. | [
"Move",
"a",
"deck",
"left",
"or",
"right",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L451-L460 | train | 32,975 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderLayout.scroll_deck_y | def scroll_deck_y(self, decknum, scroll_y):
"""Move a deck up or down."""
if decknum >= len(self.decks):
raise IndexError("I have no deck at {}".format(decknum))
if decknum >= len(self.deck_y_hint_offsets):
self.deck_y_hint_offsets = list(self.deck_y_hint_offsets) + [0] * (
decknum - len(self.deck_y_hint_offsets) + 1
)
self.deck_y_hint_offsets[decknum] += scroll_y
self._trigger_layout() | python | def scroll_deck_y(self, decknum, scroll_y):
"""Move a deck up or down."""
if decknum >= len(self.decks):
raise IndexError("I have no deck at {}".format(decknum))
if decknum >= len(self.deck_y_hint_offsets):
self.deck_y_hint_offsets = list(self.deck_y_hint_offsets) + [0] * (
decknum - len(self.deck_y_hint_offsets) + 1
)
self.deck_y_hint_offsets[decknum] += scroll_y
self._trigger_layout() | [
"def",
"scroll_deck_y",
"(",
"self",
",",
"decknum",
",",
"scroll_y",
")",
":",
"if",
"decknum",
">=",
"len",
"(",
"self",
".",
"decks",
")",
":",
"raise",
"IndexError",
"(",
"\"I have no deck at {}\"",
".",
"format",
"(",
"decknum",
")",
")",
"if",
"dec... | Move a deck up or down. | [
"Move",
"a",
"deck",
"up",
"or",
"down",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L462-L471 | train | 32,976 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderLayout.scroll_deck | def scroll_deck(self, decknum, scroll_x, scroll_y):
"""Move a deck."""
self.scroll_deck_x(decknum, scroll_x)
self.scroll_deck_y(decknum, scroll_y) | python | def scroll_deck(self, decknum, scroll_x, scroll_y):
"""Move a deck."""
self.scroll_deck_x(decknum, scroll_x)
self.scroll_deck_y(decknum, scroll_y) | [
"def",
"scroll_deck",
"(",
"self",
",",
"decknum",
",",
"scroll_x",
",",
"scroll_y",
")",
":",
"self",
".",
"scroll_deck_x",
"(",
"decknum",
",",
"scroll_x",
")",
"self",
".",
"scroll_deck_y",
"(",
"decknum",
",",
"scroll_y",
")"
] | Move a deck. | [
"Move",
"a",
"deck",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L473-L476 | train | 32,977 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderLayout._get_foundation_pos | def _get_foundation_pos(self, i):
"""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``.
"""
(phx, phy) = get_pos_hint(
self.starting_pos_hint, *self.card_size_hint
)
phx += self.deck_x_hint_step * i + self.deck_x_hint_offsets[i]
phy += self.deck_y_hint_step * i + self.deck_y_hint_offsets[i]
x = phx * self.width + self.x
y = phy * self.height + self.y
return (x, y) | python | def _get_foundation_pos(self, i):
"""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``.
"""
(phx, phy) = get_pos_hint(
self.starting_pos_hint, *self.card_size_hint
)
phx += self.deck_x_hint_step * i + self.deck_x_hint_offsets[i]
phy += self.deck_y_hint_step * i + self.deck_y_hint_offsets[i]
x = phx * self.width + self.x
y = phy * self.height + self.y
return (x, y) | [
"def",
"_get_foundation_pos",
"(",
"self",
",",
"i",
")",
":",
"(",
"phx",
",",
"phy",
")",
"=",
"get_pos_hint",
"(",
"self",
".",
"starting_pos_hint",
",",
"*",
"self",
".",
"card_size_hint",
")",
"phx",
"+=",
"self",
".",
"deck_x_hint_step",
"*",
"i",
... | 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``. | [
"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",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L478-L492 | train | 32,978 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderLayout.on_decks | def on_decks(self, *args):
"""Inform the cards of their deck and their index within the deck;
extend the ``_hint_offsets`` properties as needed; and trigger
a layout.
"""
if None in (
self.canvas,
self.decks,
self.deck_x_hint_offsets,
self.deck_y_hint_offsets
):
Clock.schedule_once(self.on_decks, 0)
return
self.clear_widgets()
decknum = 0
for deck in self.decks:
cardnum = 0
for card in deck:
if not isinstance(card, Card):
raise TypeError("You must only put Card in decks")
if card not in self.children:
self.add_widget(card)
if card.deck != decknum:
card.deck = decknum
if card.idx != cardnum:
card.idx = cardnum
cardnum += 1
decknum += 1
if len(self.deck_x_hint_offsets) < len(self.decks):
self.deck_x_hint_offsets = list(self.deck_x_hint_offsets) + [0] * (
len(self.decks) - len(self.deck_x_hint_offsets)
)
if len(self.deck_y_hint_offsets) < len(self.decks):
self.deck_y_hint_offsets = list(self.deck_y_hint_offsets) + [0] * (
len(self.decks) - len(self.deck_y_hint_offsets)
)
self._trigger_layout() | python | def on_decks(self, *args):
"""Inform the cards of their deck and their index within the deck;
extend the ``_hint_offsets`` properties as needed; and trigger
a layout.
"""
if None in (
self.canvas,
self.decks,
self.deck_x_hint_offsets,
self.deck_y_hint_offsets
):
Clock.schedule_once(self.on_decks, 0)
return
self.clear_widgets()
decknum = 0
for deck in self.decks:
cardnum = 0
for card in deck:
if not isinstance(card, Card):
raise TypeError("You must only put Card in decks")
if card not in self.children:
self.add_widget(card)
if card.deck != decknum:
card.deck = decknum
if card.idx != cardnum:
card.idx = cardnum
cardnum += 1
decknum += 1
if len(self.deck_x_hint_offsets) < len(self.decks):
self.deck_x_hint_offsets = list(self.deck_x_hint_offsets) + [0] * (
len(self.decks) - len(self.deck_x_hint_offsets)
)
if len(self.deck_y_hint_offsets) < len(self.decks):
self.deck_y_hint_offsets = list(self.deck_y_hint_offsets) + [0] * (
len(self.decks) - len(self.deck_y_hint_offsets)
)
self._trigger_layout() | [
"def",
"on_decks",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"None",
"in",
"(",
"self",
".",
"canvas",
",",
"self",
".",
"decks",
",",
"self",
".",
"deck_x_hint_offsets",
",",
"self",
".",
"deck_y_hint_offsets",
")",
":",
"Clock",
".",
"schedule_o... | Inform the cards of their deck and their index within the deck;
extend the ``_hint_offsets`` properties as needed; and trigger
a layout. | [
"Inform",
"the",
"cards",
"of",
"their",
"deck",
"and",
"their",
"index",
"within",
"the",
"deck",
";",
"extend",
"the",
"_hint_offsets",
"properties",
"as",
"needed",
";",
"and",
"trigger",
"a",
"layout",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L525-L562 | train | 32,979 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderLayout.on_touch_move | def on_touch_move(self, touch):
"""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.
"""
if (
'card' not in touch.ud or
'layout' not in touch.ud or
touch.ud['layout'] != self
):
return
if (
touch.ud['layout'] == self and
not hasattr(touch.ud['card'], '_topdecked')
):
touch.ud['card']._topdecked = InstructionGroup()
touch.ud['card']._topdecked.add(touch.ud['card'].canvas)
self.canvas.after.add(touch.ud['card']._topdecked)
for i, deck in enumerate(self.decks):
cards = [card for card in deck if not card.dragging]
maxidx = max(card.idx for card in cards) if cards else 0
if self.direction == 'descending':
cards.reverse()
cards_collided = [
card for card in cards if card.collide_point(*touch.pos)
]
if cards_collided:
collided = cards_collided.pop()
for card in cards_collided:
if card.idx > collided.idx:
collided = card
if collided.deck == touch.ud['deck']:
self.insertion_card = (
1 if collided.idx == 0 else
maxidx + 1 if collided.idx == maxidx else
collided.idx + 1 if collided.idx > touch.ud['idx']
else collided.idx
)
else:
dropdeck = self.decks[collided.deck]
maxidx = max(card.idx for card in dropdeck)
self.insertion_card = (
1 if collided.idx == 0 else
maxidx + 1 if collided.idx == maxidx else
collided.idx + 1
)
if self.insertion_deck != collided.deck:
self.insertion_deck = collided.deck
return
else:
if self.insertion_deck == i:
if self.insertion_card in (0, len(deck)):
pass
elif self.point_before_card(
cards[0], *touch.pos
):
self.insertion_card = 0
elif self.point_after_card(
cards[-1], *touch.pos
):
self.insertion_card = cards[-1].idx
else:
for j, found in enumerate(self._foundations):
if (
found is not None and
found.collide_point(*touch.pos)
):
self.insertion_deck = j
self.insertion_card = 0
return | python | def on_touch_move(self, touch):
"""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.
"""
if (
'card' not in touch.ud or
'layout' not in touch.ud or
touch.ud['layout'] != self
):
return
if (
touch.ud['layout'] == self and
not hasattr(touch.ud['card'], '_topdecked')
):
touch.ud['card']._topdecked = InstructionGroup()
touch.ud['card']._topdecked.add(touch.ud['card'].canvas)
self.canvas.after.add(touch.ud['card']._topdecked)
for i, deck in enumerate(self.decks):
cards = [card for card in deck if not card.dragging]
maxidx = max(card.idx for card in cards) if cards else 0
if self.direction == 'descending':
cards.reverse()
cards_collided = [
card for card in cards if card.collide_point(*touch.pos)
]
if cards_collided:
collided = cards_collided.pop()
for card in cards_collided:
if card.idx > collided.idx:
collided = card
if collided.deck == touch.ud['deck']:
self.insertion_card = (
1 if collided.idx == 0 else
maxidx + 1 if collided.idx == maxidx else
collided.idx + 1 if collided.idx > touch.ud['idx']
else collided.idx
)
else:
dropdeck = self.decks[collided.deck]
maxidx = max(card.idx for card in dropdeck)
self.insertion_card = (
1 if collided.idx == 0 else
maxidx + 1 if collided.idx == maxidx else
collided.idx + 1
)
if self.insertion_deck != collided.deck:
self.insertion_deck = collided.deck
return
else:
if self.insertion_deck == i:
if self.insertion_card in (0, len(deck)):
pass
elif self.point_before_card(
cards[0], *touch.pos
):
self.insertion_card = 0
elif self.point_after_card(
cards[-1], *touch.pos
):
self.insertion_card = cards[-1].idx
else:
for j, found in enumerate(self._foundations):
if (
found is not None and
found.collide_point(*touch.pos)
):
self.insertion_deck = j
self.insertion_card = 0
return | [
"def",
"on_touch_move",
"(",
"self",
",",
"touch",
")",
":",
"if",
"(",
"'card'",
"not",
"in",
"touch",
".",
"ud",
"or",
"'layout'",
"not",
"in",
"touch",
".",
"ud",
"or",
"touch",
".",
"ud",
"[",
"'layout'",
"]",
"!=",
"self",
")",
":",
"return",
... | 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. | [
"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",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L626-L695 | train | 32,980 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderLayout.on_touch_up | def on_touch_up(self, touch):
"""If a card is being dragged, put it in the place it was just dropped
and trigger a layout.
"""
if (
'card' not in touch.ud or
'layout' not in touch.ud or
touch.ud['layout'] != self
):
return
if hasattr(touch.ud['card'], '_topdecked'):
self.canvas.after.remove(touch.ud['card']._topdecked)
del touch.ud['card']._topdecked
if None not in (self.insertion_deck, self.insertion_card):
# need to sync to adapter.data??
card = touch.ud['card']
del card.parent.decks[card.deck][card.idx]
for i in range(0, len(card.parent.decks[card.deck])):
card.parent.decks[card.deck][i].idx = i
deck = self.decks[self.insertion_deck]
if self.insertion_card >= len(deck):
deck.append(card)
else:
deck.insert(self.insertion_card, card)
card.deck = self.insertion_deck
card.idx = self.insertion_card
self.decks[self.insertion_deck] = deck
self.insertion_deck = self.insertion_card = None
self._trigger_layout() | python | def on_touch_up(self, touch):
"""If a card is being dragged, put it in the place it was just dropped
and trigger a layout.
"""
if (
'card' not in touch.ud or
'layout' not in touch.ud or
touch.ud['layout'] != self
):
return
if hasattr(touch.ud['card'], '_topdecked'):
self.canvas.after.remove(touch.ud['card']._topdecked)
del touch.ud['card']._topdecked
if None not in (self.insertion_deck, self.insertion_card):
# need to sync to adapter.data??
card = touch.ud['card']
del card.parent.decks[card.deck][card.idx]
for i in range(0, len(card.parent.decks[card.deck])):
card.parent.decks[card.deck][i].idx = i
deck = self.decks[self.insertion_deck]
if self.insertion_card >= len(deck):
deck.append(card)
else:
deck.insert(self.insertion_card, card)
card.deck = self.insertion_deck
card.idx = self.insertion_card
self.decks[self.insertion_deck] = deck
self.insertion_deck = self.insertion_card = None
self._trigger_layout() | [
"def",
"on_touch_up",
"(",
"self",
",",
"touch",
")",
":",
"if",
"(",
"'card'",
"not",
"in",
"touch",
".",
"ud",
"or",
"'layout'",
"not",
"in",
"touch",
".",
"ud",
"or",
"touch",
".",
"ud",
"[",
"'layout'",
"]",
"!=",
"self",
")",
":",
"return",
... | If a card is being dragged, put it in the place it was just dropped
and trigger a layout. | [
"If",
"a",
"card",
"is",
"being",
"dragged",
"put",
"it",
"in",
"the",
"place",
"it",
"was",
"just",
"dropped",
"and",
"trigger",
"a",
"layout",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L697-L726 | train | 32,981 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderLayout.do_layout | def do_layout(self, *args):
"""Layout each of my decks"""
if self.size == [1, 1]:
return
for i in range(0, len(self.decks)):
self.layout_deck(i) | python | def do_layout(self, *args):
"""Layout each of my decks"""
if self.size == [1, 1]:
return
for i in range(0, len(self.decks)):
self.layout_deck(i) | [
"def",
"do_layout",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"size",
"==",
"[",
"1",
",",
"1",
"]",
":",
"return",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"self",
".",
"decks",
")",
")",
":",
"self",
".",
"l... | Layout each of my decks | [
"Layout",
"each",
"of",
"my",
"decks"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L733-L738 | train | 32,982 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderLayout.layout_deck | def layout_deck(self, i):
"""Stack the cards, starting at my deck's foundation, and proceeding
by ``card_pos_hint``
"""
def get_dragidx(cards):
j = 0
for card in cards:
if card.dragging:
return j
j += 1
# Put a None in the card list in place of the card you're
# hovering over, if you're dragging another card. This will
# result in an empty space where the card will go if you drop
# it now.
cards = list(self.decks[i])
dragidx = get_dragidx(cards)
if dragidx is not None:
del cards[dragidx]
if self.insertion_deck == i and self.insertion_card is not None:
insdx = self.insertion_card
if dragidx is not None and insdx > dragidx:
insdx -= 1
cards.insert(insdx, None)
if self.direction == 'descending':
cards.reverse()
# Work out the initial pos_hint for this deck
(phx, phy) = get_pos_hint(self.starting_pos_hint, *self.card_size_hint)
phx += self.deck_x_hint_step * i + self.deck_x_hint_offsets[i]
phy += self.deck_y_hint_step * i + self.deck_y_hint_offsets[i]
(w, h) = self.size
(x, y) = self.pos
# start assigning pos and size to cards
found = self._get_foundation(i)
if found in self.children:
self.remove_widget(found)
self.add_widget(found)
for card in cards:
if card is not None:
if card in self.children:
self.remove_widget(card)
(shw, shh) = self.card_size_hint
card.pos = (
x + phx * w,
y + phy * h
)
card.size = (w * shw, h * shh)
self.add_widget(card)
phx += self.card_x_hint_step
phy += self.card_y_hint_step | python | def layout_deck(self, i):
"""Stack the cards, starting at my deck's foundation, and proceeding
by ``card_pos_hint``
"""
def get_dragidx(cards):
j = 0
for card in cards:
if card.dragging:
return j
j += 1
# Put a None in the card list in place of the card you're
# hovering over, if you're dragging another card. This will
# result in an empty space where the card will go if you drop
# it now.
cards = list(self.decks[i])
dragidx = get_dragidx(cards)
if dragidx is not None:
del cards[dragidx]
if self.insertion_deck == i and self.insertion_card is not None:
insdx = self.insertion_card
if dragidx is not None and insdx > dragidx:
insdx -= 1
cards.insert(insdx, None)
if self.direction == 'descending':
cards.reverse()
# Work out the initial pos_hint for this deck
(phx, phy) = get_pos_hint(self.starting_pos_hint, *self.card_size_hint)
phx += self.deck_x_hint_step * i + self.deck_x_hint_offsets[i]
phy += self.deck_y_hint_step * i + self.deck_y_hint_offsets[i]
(w, h) = self.size
(x, y) = self.pos
# start assigning pos and size to cards
found = self._get_foundation(i)
if found in self.children:
self.remove_widget(found)
self.add_widget(found)
for card in cards:
if card is not None:
if card in self.children:
self.remove_widget(card)
(shw, shh) = self.card_size_hint
card.pos = (
x + phx * w,
y + phy * h
)
card.size = (w * shw, h * shh)
self.add_widget(card)
phx += self.card_x_hint_step
phy += self.card_y_hint_step | [
"def",
"layout_deck",
"(",
"self",
",",
"i",
")",
":",
"def",
"get_dragidx",
"(",
"cards",
")",
":",
"j",
"=",
"0",
"for",
"card",
"in",
"cards",
":",
"if",
"card",
".",
"dragging",
":",
"return",
"j",
"j",
"+=",
"1",
"# Put a None in the card list in ... | Stack the cards, starting at my deck's foundation, and proceeding
by ``card_pos_hint`` | [
"Stack",
"the",
"cards",
"starting",
"at",
"my",
"deck",
"s",
"foundation",
"and",
"proceeding",
"by",
"card_pos_hint"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L740-L789 | train | 32,983 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | ScrollBarBar.on_touch_down | def on_touch_down(self, touch):
"""Tell my parent if I've been touched"""
if self.parent is None:
return
if self.collide_point(*touch.pos):
self.parent.bar_touched(self, touch) | python | def on_touch_down(self, touch):
"""Tell my parent if I've been touched"""
if self.parent is None:
return
if self.collide_point(*touch.pos):
self.parent.bar_touched(self, touch) | [
"def",
"on_touch_down",
"(",
"self",
",",
"touch",
")",
":",
"if",
"self",
".",
"parent",
"is",
"None",
":",
"return",
"if",
"self",
".",
"collide_point",
"(",
"*",
"touch",
".",
"pos",
")",
":",
"self",
".",
"parent",
".",
"bar_touched",
"(",
"self"... | Tell my parent if I've been touched | [
"Tell",
"my",
"parent",
"if",
"I",
"ve",
"been",
"touched"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L805-L810 | train | 32,984 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderScrollBar.do_layout | def do_layout(self, *args):
"""Put the bar where it's supposed to be, and size it in proportion to
the size of the scrollable area.
"""
if 'bar' not in self.ids:
Clock.schedule_once(self.do_layout)
return
if self.orientation == 'horizontal':
self.ids.bar.size_hint_x = self.hbar[1]
self.ids.bar.pos_hint = {'x': self.hbar[0], 'y': 0}
else:
self.ids.bar.size_hint_y = self.vbar[1]
self.ids.bar.pos_hint = {'x': 0, 'y': self.vbar[0]}
super().do_layout(*args) | python | def do_layout(self, *args):
"""Put the bar where it's supposed to be, and size it in proportion to
the size of the scrollable area.
"""
if 'bar' not in self.ids:
Clock.schedule_once(self.do_layout)
return
if self.orientation == 'horizontal':
self.ids.bar.size_hint_x = self.hbar[1]
self.ids.bar.pos_hint = {'x': self.hbar[0], 'y': 0}
else:
self.ids.bar.size_hint_y = self.vbar[1]
self.ids.bar.pos_hint = {'x': 0, 'y': self.vbar[0]}
super().do_layout(*args) | [
"def",
"do_layout",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"'bar'",
"not",
"in",
"self",
".",
"ids",
":",
"Clock",
".",
"schedule_once",
"(",
"self",
".",
"do_layout",
")",
"return",
"if",
"self",
".",
"orientation",
"==",
"'horizontal'",
":",
... | Put the bar where it's supposed to be, and size it in proportion to
the size of the scrollable area. | [
"Put",
"the",
"bar",
"where",
"it",
"s",
"supposed",
"to",
"be",
"and",
"size",
"it",
"in",
"proportion",
"to",
"the",
"size",
"of",
"the",
"scrollable",
"area",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L935-L949 | train | 32,985 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderScrollBar.upd_scroll | def upd_scroll(self, *args):
"""Update my own ``scroll`` property to where my deck is actually
scrolled.
"""
att = 'deck_{}_hint_offsets'.format(
'x' if self.orientation == 'horizontal' else 'y'
)
self._scroll = getattr(self.deckbuilder, att)[self.deckidx] | python | def upd_scroll(self, *args):
"""Update my own ``scroll`` property to where my deck is actually
scrolled.
"""
att = 'deck_{}_hint_offsets'.format(
'x' if self.orientation == 'horizontal' else 'y'
)
self._scroll = getattr(self.deckbuilder, att)[self.deckidx] | [
"def",
"upd_scroll",
"(",
"self",
",",
"*",
"args",
")",
":",
"att",
"=",
"'deck_{}_hint_offsets'",
".",
"format",
"(",
"'x'",
"if",
"self",
".",
"orientation",
"==",
"'horizontal'",
"else",
"'y'",
")",
"self",
".",
"_scroll",
"=",
"getattr",
"(",
"self"... | Update my own ``scroll`` property to where my deck is actually
scrolled. | [
"Update",
"my",
"own",
"scroll",
"property",
"to",
"where",
"my",
"deck",
"is",
"actually",
"scrolled",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L951-L959 | train | 32,986 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderScrollBar.on_deckbuilder | def on_deckbuilder(self, *args):
"""Bind my deckbuilder to update my ``scroll``, and my ``scroll`` to
update my deckbuilder.
"""
if self.deckbuilder is None:
return
att = 'deck_{}_hint_offsets'.format(
'x' if self.orientation == 'horizontal' else 'y'
)
offs = getattr(self.deckbuilder, att)
if len(offs) <= self.deckidx:
Clock.schedule_once(self.on_deckbuilder, 0)
return
self.bind(scroll=self.handle_scroll)
self.deckbuilder.bind(**{att: self.upd_scroll})
self.upd_scroll()
self.deckbuilder._trigger_layout() | python | def on_deckbuilder(self, *args):
"""Bind my deckbuilder to update my ``scroll``, and my ``scroll`` to
update my deckbuilder.
"""
if self.deckbuilder is None:
return
att = 'deck_{}_hint_offsets'.format(
'x' if self.orientation == 'horizontal' else 'y'
)
offs = getattr(self.deckbuilder, att)
if len(offs) <= self.deckidx:
Clock.schedule_once(self.on_deckbuilder, 0)
return
self.bind(scroll=self.handle_scroll)
self.deckbuilder.bind(**{att: self.upd_scroll})
self.upd_scroll()
self.deckbuilder._trigger_layout() | [
"def",
"on_deckbuilder",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"deckbuilder",
"is",
"None",
":",
"return",
"att",
"=",
"'deck_{}_hint_offsets'",
".",
"format",
"(",
"'x'",
"if",
"self",
".",
"orientation",
"==",
"'horizontal'",
"else"... | Bind my deckbuilder to update my ``scroll``, and my ``scroll`` to
update my deckbuilder. | [
"Bind",
"my",
"deckbuilder",
"to",
"update",
"my",
"scroll",
"and",
"my",
"scroll",
"to",
"update",
"my",
"deckbuilder",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L961-L978 | train | 32,987 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderScrollBar.handle_scroll | def handle_scroll(self, *args):
"""When my ``scroll`` changes, tell my deckbuilder how it's scrolled
now.
"""
if 'bar' not in self.ids:
Clock.schedule_once(self.handle_scroll, 0)
return
att = 'deck_{}_hint_offsets'.format(
'x' if self.orientation == 'horizontal' else 'y'
)
offs = list(getattr(self.deckbuilder, att))
if len(offs) <= self.deckidx:
Clock.schedule_once(self.on_scroll, 0)
return
offs[self.deckidx] = self._scroll
setattr(self.deckbuilder, att, offs)
self.deckbuilder._trigger_layout() | python | def handle_scroll(self, *args):
"""When my ``scroll`` changes, tell my deckbuilder how it's scrolled
now.
"""
if 'bar' not in self.ids:
Clock.schedule_once(self.handle_scroll, 0)
return
att = 'deck_{}_hint_offsets'.format(
'x' if self.orientation == 'horizontal' else 'y'
)
offs = list(getattr(self.deckbuilder, att))
if len(offs) <= self.deckidx:
Clock.schedule_once(self.on_scroll, 0)
return
offs[self.deckidx] = self._scroll
setattr(self.deckbuilder, att, offs)
self.deckbuilder._trigger_layout() | [
"def",
"handle_scroll",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"'bar'",
"not",
"in",
"self",
".",
"ids",
":",
"Clock",
".",
"schedule_once",
"(",
"self",
".",
"handle_scroll",
",",
"0",
")",
"return",
"att",
"=",
"'deck_{}_hint_offsets'",
".",
... | When my ``scroll`` changes, tell my deckbuilder how it's scrolled
now. | [
"When",
"my",
"scroll",
"changes",
"tell",
"my",
"deckbuilder",
"how",
"it",
"s",
"scrolled",
"now",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L980-L997 | train | 32,988 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderScrollBar.bar_touched | def bar_touched(self, bar, touch):
"""Start scrolling, and record where I started scrolling."""
self.scrolling = True
self._start_bar_pos_hint = get_pos_hint(bar.pos_hint, *bar.size_hint)
self._start_touch_pos_hint = (
touch.x / self.width,
touch.y / self.height
)
self._start_bar_touch_hint = (
self._start_touch_pos_hint[0] - self._start_bar_pos_hint[0],
self._start_touch_pos_hint[1] - self._start_bar_pos_hint[1]
)
touch.grab(self) | python | def bar_touched(self, bar, touch):
"""Start scrolling, and record where I started scrolling."""
self.scrolling = True
self._start_bar_pos_hint = get_pos_hint(bar.pos_hint, *bar.size_hint)
self._start_touch_pos_hint = (
touch.x / self.width,
touch.y / self.height
)
self._start_bar_touch_hint = (
self._start_touch_pos_hint[0] - self._start_bar_pos_hint[0],
self._start_touch_pos_hint[1] - self._start_bar_pos_hint[1]
)
touch.grab(self) | [
"def",
"bar_touched",
"(",
"self",
",",
"bar",
",",
"touch",
")",
":",
"self",
".",
"scrolling",
"=",
"True",
"self",
".",
"_start_bar_pos_hint",
"=",
"get_pos_hint",
"(",
"bar",
".",
"pos_hint",
",",
"*",
"bar",
".",
"size_hint",
")",
"self",
".",
"_s... | Start scrolling, and record where I started scrolling. | [
"Start",
"scrolling",
"and",
"record",
"where",
"I",
"started",
"scrolling",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L999-L1011 | train | 32,989 |
LogicalDash/LiSE | ELiDE/ELiDE/card.py | DeckBuilderScrollBar.on_touch_move | def on_touch_move(self, touch):
"""Move the scrollbar to the touch, and update my ``scroll``
accordingly.
"""
if not self.scrolling or 'bar' not in self.ids:
touch.ungrab(self)
return
touch.push()
touch.apply_transform_2d(self.parent.to_local)
touch.apply_transform_2d(self.to_local)
if self.orientation == 'horizontal':
hint_right_of_bar = (touch.x - self.ids.bar.x) / self.width
hint_correction = hint_right_of_bar - self._start_bar_touch_hint[0]
self.scroll += hint_correction
else: # self.orientation == 'vertical'
hint_above_bar = (touch.y - self.ids.bar.y) / self.height
hint_correction = hint_above_bar - self._start_bar_touch_hint[1]
self.scroll += hint_correction
touch.pop() | python | def on_touch_move(self, touch):
"""Move the scrollbar to the touch, and update my ``scroll``
accordingly.
"""
if not self.scrolling or 'bar' not in self.ids:
touch.ungrab(self)
return
touch.push()
touch.apply_transform_2d(self.parent.to_local)
touch.apply_transform_2d(self.to_local)
if self.orientation == 'horizontal':
hint_right_of_bar = (touch.x - self.ids.bar.x) / self.width
hint_correction = hint_right_of_bar - self._start_bar_touch_hint[0]
self.scroll += hint_correction
else: # self.orientation == 'vertical'
hint_above_bar = (touch.y - self.ids.bar.y) / self.height
hint_correction = hint_above_bar - self._start_bar_touch_hint[1]
self.scroll += hint_correction
touch.pop() | [
"def",
"on_touch_move",
"(",
"self",
",",
"touch",
")",
":",
"if",
"not",
"self",
".",
"scrolling",
"or",
"'bar'",
"not",
"in",
"self",
".",
"ids",
":",
"touch",
".",
"ungrab",
"(",
"self",
")",
"return",
"touch",
".",
"push",
"(",
")",
"touch",
".... | Move the scrollbar to the touch, and update my ``scroll``
accordingly. | [
"Move",
"the",
"scrollbar",
"to",
"the",
"touch",
"and",
"update",
"my",
"scroll",
"accordingly",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/card.py#L1013-L1032 | train | 32,990 |
LogicalDash/LiSE | allegedb/allegedb/wrap.py | ListWrapper.unwrap | def unwrap(self):
"""Return a deep copy of myself as a list, and unwrap any wrapper objects in me."""
return [v.unwrap() if hasattr(v, 'unwrap') and not hasattr(v, 'no_unwrap') else v for v in self] | python | def unwrap(self):
"""Return a deep copy of myself as a list, and unwrap any wrapper objects in me."""
return [v.unwrap() if hasattr(v, 'unwrap') and not hasattr(v, 'no_unwrap') else v for v in self] | [
"def",
"unwrap",
"(",
"self",
")",
":",
"return",
"[",
"v",
".",
"unwrap",
"(",
")",
"if",
"hasattr",
"(",
"v",
",",
"'unwrap'",
")",
"and",
"not",
"hasattr",
"(",
"v",
",",
"'no_unwrap'",
")",
"else",
"v",
"for",
"v",
"in",
"self",
"]"
] | Return a deep copy of myself as a list, and unwrap any wrapper objects in me. | [
"Return",
"a",
"deep",
"copy",
"of",
"myself",
"as",
"a",
"list",
"and",
"unwrap",
"any",
"wrapper",
"objects",
"in",
"me",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/wrap.py#L307-L309 | train | 32,991 |
LogicalDash/LiSE | ELiDE/ELiDE/board/arrow.py | ArrowWidget.on_portal | def on_portal(self, *args):
"""Set my ``name`` and instantiate my ``mirrormap`` as soon as I have
the properties I need to do so.
"""
if not (
self.board and
self.origin and
self.destination and
self.origin.name in self.board.character.portal and
self.destination.name in self.board.character.portal
):
Clock.schedule_once(self.on_portal, 0)
return
self.name = '{}->{}'.format(self.portal['origin'], self.portal['destination']) | python | def on_portal(self, *args):
"""Set my ``name`` and instantiate my ``mirrormap`` as soon as I have
the properties I need to do so.
"""
if not (
self.board and
self.origin and
self.destination and
self.origin.name in self.board.character.portal and
self.destination.name in self.board.character.portal
):
Clock.schedule_once(self.on_portal, 0)
return
self.name = '{}->{}'.format(self.portal['origin'], self.portal['destination']) | [
"def",
"on_portal",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"not",
"(",
"self",
".",
"board",
"and",
"self",
".",
"origin",
"and",
"self",
".",
"destination",
"and",
"self",
".",
"origin",
".",
"name",
"in",
"self",
".",
"board",
".",
"chara... | Set my ``name`` and instantiate my ``mirrormap`` as soon as I have
the properties I need to do so. | [
"Set",
"my",
"name",
"and",
"instantiate",
"my",
"mirrormap",
"as",
"soon",
"as",
"I",
"have",
"the",
"properties",
"I",
"need",
"to",
"do",
"so",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/board/arrow.py#L296-L310 | train | 32,992 |
LogicalDash/LiSE | ELiDE/ELiDE/board/arrow.py | ArrowWidget.collide_point | def collide_point(self, x, y):
"""Delegate to my ``collider``, or return ``False`` if I don't have
one.
"""
if not self.collider:
return False
return (x, y) in self.collider | python | def collide_point(self, x, y):
"""Delegate to my ``collider``, or return ``False`` if I don't have
one.
"""
if not self.collider:
return False
return (x, y) in self.collider | [
"def",
"collide_point",
"(",
"self",
",",
"x",
",",
"y",
")",
":",
"if",
"not",
"self",
".",
"collider",
":",
"return",
"False",
"return",
"(",
"x",
",",
"y",
")",
"in",
"self",
".",
"collider"
] | Delegate to my ``collider``, or return ``False`` if I don't have
one. | [
"Delegate",
"to",
"my",
"collider",
"or",
"return",
"False",
"if",
"I",
"don",
"t",
"have",
"one",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/board/arrow.py#L312-L319 | train | 32,993 |
LogicalDash/LiSE | ELiDE/ELiDE/board/arrow.py | ArrowWidget.on_origin | def on_origin(self, *args):
"""Make sure to redraw whenever the origin moves."""
if self.origin is None:
Clock.schedule_once(self.on_origin, 0)
return
self.origin.bind(
pos=self._trigger_repoint,
size=self._trigger_repoint
) | python | def on_origin(self, *args):
"""Make sure to redraw whenever the origin moves."""
if self.origin is None:
Clock.schedule_once(self.on_origin, 0)
return
self.origin.bind(
pos=self._trigger_repoint,
size=self._trigger_repoint
) | [
"def",
"on_origin",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"origin",
"is",
"None",
":",
"Clock",
".",
"schedule_once",
"(",
"self",
".",
"on_origin",
",",
"0",
")",
"return",
"self",
".",
"origin",
".",
"bind",
"(",
"pos",
"=",... | Make sure to redraw whenever the origin moves. | [
"Make",
"sure",
"to",
"redraw",
"whenever",
"the",
"origin",
"moves",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/board/arrow.py#L332-L340 | train | 32,994 |
LogicalDash/LiSE | ELiDE/ELiDE/board/arrow.py | ArrowWidget.on_destination | def on_destination(self, *args):
"""Make sure to redraw whenever the destination moves."""
if self.destination is None:
Clock.schedule_once(self.on_destination, 0)
return
self.destination.bind(
pos=self._trigger_repoint,
size=self._trigger_repoint
) | python | def on_destination(self, *args):
"""Make sure to redraw whenever the destination moves."""
if self.destination is None:
Clock.schedule_once(self.on_destination, 0)
return
self.destination.bind(
pos=self._trigger_repoint,
size=self._trigger_repoint
) | [
"def",
"on_destination",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"destination",
"is",
"None",
":",
"Clock",
".",
"schedule_once",
"(",
"self",
".",
"on_destination",
",",
"0",
")",
"return",
"self",
".",
"destination",
".",
"bind",
... | Make sure to redraw whenever the destination moves. | [
"Make",
"sure",
"to",
"redraw",
"whenever",
"the",
"destination",
"moves",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/board/arrow.py#L342-L350 | train | 32,995 |
LogicalDash/LiSE | ELiDE/ELiDE/board/arrow.py | ArrowWidget.on_board | def on_board(self, *args):
"""Draw myself for the first time as soon as I have the properties I
need to do so.
"""
if None in (
self.board,
self.origin,
self.destination
):
Clock.schedule_once(self.on_board, 0)
return
self._trigger_repoint() | python | def on_board(self, *args):
"""Draw myself for the first time as soon as I have the properties I
need to do so.
"""
if None in (
self.board,
self.origin,
self.destination
):
Clock.schedule_once(self.on_board, 0)
return
self._trigger_repoint() | [
"def",
"on_board",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"None",
"in",
"(",
"self",
".",
"board",
",",
"self",
".",
"origin",
",",
"self",
".",
"destination",
")",
":",
"Clock",
".",
"schedule_once",
"(",
"self",
".",
"on_board",
",",
"0",... | Draw myself for the first time as soon as I have the properties I
need to do so. | [
"Draw",
"myself",
"for",
"the",
"first",
"time",
"as",
"soon",
"as",
"I",
"have",
"the",
"properties",
"I",
"need",
"to",
"do",
"so",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/board/arrow.py#L352-L364 | train | 32,996 |
LogicalDash/LiSE | ELiDE/ELiDE/board/arrow.py | ArrowWidget._get_slope | def _get_slope(self):
"""Return a float of the increase in y divided by the increase in x,
both from left to right."""
orig = self.origin
dest = self.destination
ox = orig.x
oy = orig.y
dx = dest.x
dy = dest.y
if oy == dy:
return 0
elif ox == dx:
return None
else:
rise = dy - oy
run = dx - ox
return rise / run | python | def _get_slope(self):
"""Return a float of the increase in y divided by the increase in x,
both from left to right."""
orig = self.origin
dest = self.destination
ox = orig.x
oy = orig.y
dx = dest.x
dy = dest.y
if oy == dy:
return 0
elif ox == dx:
return None
else:
rise = dy - oy
run = dx - ox
return rise / run | [
"def",
"_get_slope",
"(",
"self",
")",
":",
"orig",
"=",
"self",
".",
"origin",
"dest",
"=",
"self",
".",
"destination",
"ox",
"=",
"orig",
".",
"x",
"oy",
"=",
"orig",
".",
"y",
"dx",
"=",
"dest",
".",
"x",
"dy",
"=",
"dest",
".",
"y",
"if",
... | Return a float of the increase in y divided by the increase in x,
both from left to right. | [
"Return",
"a",
"float",
"of",
"the",
"increase",
"in",
"y",
"divided",
"by",
"the",
"increase",
"in",
"x",
"both",
"from",
"left",
"to",
"right",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/board/arrow.py#L457-L473 | train | 32,997 |
LogicalDash/LiSE | ELiDE/ELiDE/board/arrow.py | ArrowWidget._get_b | def _get_b(self):
"""Return my Y-intercept.
I probably don't really hit the left edge of the window, but
this is where I would, if I were long enough.
"""
orig = self.origin
dest = self.destination
(ox, oy) = orig.pos
(dx, dy) = dest.pos
denominator = dx - ox
x_numerator = (dy - oy) * ox
y_numerator = denominator * oy
return ((y_numerator - x_numerator), denominator) | python | def _get_b(self):
"""Return my Y-intercept.
I probably don't really hit the left edge of the window, but
this is where I would, if I were long enough.
"""
orig = self.origin
dest = self.destination
(ox, oy) = orig.pos
(dx, dy) = dest.pos
denominator = dx - ox
x_numerator = (dy - oy) * ox
y_numerator = denominator * oy
return ((y_numerator - x_numerator), denominator) | [
"def",
"_get_b",
"(",
"self",
")",
":",
"orig",
"=",
"self",
".",
"origin",
"dest",
"=",
"self",
".",
"destination",
"(",
"ox",
",",
"oy",
")",
"=",
"orig",
".",
"pos",
"(",
"dx",
",",
"dy",
")",
"=",
"dest",
".",
"pos",
"denominator",
"=",
"dx... | Return my Y-intercept.
I probably don't really hit the left edge of the window, but
this is where I would, if I were long enough. | [
"Return",
"my",
"Y",
"-",
"intercept",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/board/arrow.py#L475-L489 | train | 32,998 |
LogicalDash/LiSE | ELiDE/ELiDE/board/arrow.py | ArrowWidget._repoint | def _repoint(self, *args):
"""Recalculate points, y-intercept, and slope"""
if None in (self.origin, self.destination):
Clock.schedule_once(self._repoint, 0)
return
try:
(self.trunk_points, self.head_points) = self._get_points()
except ValueError:
self.trunk_points = self.head_points = []
return
(ox, oy, dx, dy) = self.trunk_points
r = self.w / 2
bgr = r * self.bg_scale_selected if self.selected \
else self.bg_scale_unselected
self.trunk_quad_vertices_bg = get_thin_rect_vertices(
ox, oy, dx, dy, bgr
)
self.collider = Collide2DPoly(self.trunk_quad_vertices_bg)
self.trunk_quad_vertices_fg = get_thin_rect_vertices(ox, oy, dx, dy, r)
(x1, y1, endx, endy, x2, y2) = self.head_points
self.left_head_quad_vertices_bg = get_thin_rect_vertices(
x1, y1, endx, endy, bgr
)
self.right_head_quad_vertices_bg = get_thin_rect_vertices(
x2, y2, endx, endy, bgr
)
self.left_head_quad_vertices_fg = get_thin_rect_vertices(
x1, y1, endx, endy, r
)
self.right_head_quad_vertices_fg = get_thin_rect_vertices(
x2, y2, endx, endy, r
)
self.slope = self._get_slope()
self.y_intercept = self._get_b()
self.repointed = True | python | def _repoint(self, *args):
"""Recalculate points, y-intercept, and slope"""
if None in (self.origin, self.destination):
Clock.schedule_once(self._repoint, 0)
return
try:
(self.trunk_points, self.head_points) = self._get_points()
except ValueError:
self.trunk_points = self.head_points = []
return
(ox, oy, dx, dy) = self.trunk_points
r = self.w / 2
bgr = r * self.bg_scale_selected if self.selected \
else self.bg_scale_unselected
self.trunk_quad_vertices_bg = get_thin_rect_vertices(
ox, oy, dx, dy, bgr
)
self.collider = Collide2DPoly(self.trunk_quad_vertices_bg)
self.trunk_quad_vertices_fg = get_thin_rect_vertices(ox, oy, dx, dy, r)
(x1, y1, endx, endy, x2, y2) = self.head_points
self.left_head_quad_vertices_bg = get_thin_rect_vertices(
x1, y1, endx, endy, bgr
)
self.right_head_quad_vertices_bg = get_thin_rect_vertices(
x2, y2, endx, endy, bgr
)
self.left_head_quad_vertices_fg = get_thin_rect_vertices(
x1, y1, endx, endy, r
)
self.right_head_quad_vertices_fg = get_thin_rect_vertices(
x2, y2, endx, endy, r
)
self.slope = self._get_slope()
self.y_intercept = self._get_b()
self.repointed = True | [
"def",
"_repoint",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"None",
"in",
"(",
"self",
".",
"origin",
",",
"self",
".",
"destination",
")",
":",
"Clock",
".",
"schedule_once",
"(",
"self",
".",
"_repoint",
",",
"0",
")",
"return",
"try",
":",... | Recalculate points, y-intercept, and slope | [
"Recalculate",
"points",
"y",
"-",
"intercept",
"and",
"slope"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/board/arrow.py#L491-L525 | train | 32,999 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.