function stringlengths 11 56k | repo_name stringlengths 5 60 | features list |
|---|---|---|
def start(self, rev):
return int(self.index[rev][0] >> 16) | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def length(self, rev):
return self.index[rev][1] | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def flags(self, rev):
return self.index[rev][0] & 0xFFFF | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def reachable(self, node, stop=None):
"""return the set of all nodes ancestral to a given node, including
the node itself, stopping when stop is matched"""
reachable = set((node,))
visit = [node]
if stop:
stopn = self.rev(stop)
else:
stopn = 0
... | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def descendants(self, *revs):
"""Generate the descendants of 'revs' in revision order.
Yield a sequence of revision numbers starting with a child of
some rev in revs, i.e., each revision is *not* considered a
descendant of itself. Results are ordered by revision number (a
topol... | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def findmissing(self, common=None, heads=None):
"""Return the ancestors of heads that are not ancestors of common.
More specifically, return a list of nodes N such that every N
satisfies the following constraints:
1. N is an ancestor of some node in 'heads'
2. N is not an a... | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def headrevs(self):
count = len(self)
if not count:
return [nullrev]
ishead = [1] * (count + 1)
index = self.index
for r in xrange(count):
e = index[r]
ishead[e[5]] = ishead[e[6]] = 0
return [r for r in xrange(count) if ishead[r]] | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def children(self, node):
"""find the children of a given node"""
c = []
p = self.rev(node)
for r in range(p + 1, len(self)):
prevs = [pr for pr in self.parentrevs(r) if pr != nullrev]
if prevs:
for pr in prevs:
if pr == p:
... | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def ancestor(self, a, b):
"""calculate the least common ancestor of nodes a and b"""
# fast path, check if it is a descendant
a, b = self.rev(a), self.rev(b)
start, end = sorted((a, b))
if self.descendant(start, end):
return self.node(start)
def parents(rev)... | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def _partialmatch(self, id):
if id in self._pcache:
return self._pcache[id]
if len(id) < 40:
try:
# hex(node)[:...]
l = len(id) // 2 # grab an even number of digits
prefix = bin(id[:l * 2])
nl = [e[7] for e in self... | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def cmp(self, node, text):
"""compare text with a given file revision
returns True if text is different than what is stored.
"""
p1, p2 = self.parents(node)
return hash(text, p1, p2) != node | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def _loadchunk(self, offset, length):
if self._inline:
df = self.opener(self.indexfile)
else:
df = self.opener(self.datafile)
readahead = max(65536, length)
df.seek(offset)
d = df.read(readahead)
df.close()
self._addchunk(offset, d)
... | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def _chunkraw(self, startrev, endrev):
start = self.start(startrev)
length = self.end(endrev) - start
if self._inline:
start += (startrev + 1) * self._io.size
return self._getchunk(start, length) | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def _chunkbase(self, rev):
return self._chunk(rev) | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def deltaparent(self, rev):
"""return deltaparent of the given revision"""
base = self.index[rev][3]
if base == rev:
return nullrev
elif self._generaldelta:
return base
else:
return rev - 1 | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def revision(self, nodeorrev):
"""return an uncompressed revision of a given node or revision
number.
"""
if isinstance(nodeorrev, int):
rev = nodeorrev
node = self.node(rev)
else:
node = nodeorrev
rev = None
cachedrev = No... | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def checkinlinesize(self, tr, fp=None):
if not self._inline or (self.start(-2) + self.length(-2)) < _maxinline:
return
trinfo = tr.find(self.indexfile)
if trinfo is None:
raise RevlogError(_("%s not found in the transaction")
% self.indexfil... | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def _addrevision(self, node, text, transaction, link, p1, p2,
cachedelta, ifh, dfh):
"""internal function to add revisions to the log
see addrevision for argument descriptions.
invariants:
- text is optional (can be None); if not set, cachedelta must be set.
... | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def addgroup(self, bundle, linkmapper, transaction):
"""
add a delta group
given a set of deltas, add them to the revision log. the
first delta is against its parent, which should be in our
log, the rest are against the previous delta.
"""
# track the base of th... | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def checksize(self):
expected = 0
if len(self):
expected = max(0, self.end(len(self) - 1))
try:
f = self.opener(self.datafile)
f.seek(0, 2)
actual = f.tell()
f.close()
dd = actual - expected
except IOError, inst:
... | mikel-egana-aranguren/SADI-Galaxy-Docker | [
1,
3,
1,
1,
1417087373
] |
def __init__(self, ini_path='', section='', debug=False):
"""
To init CCParser you can enter a path
and a section. If you doesn't know them yet
you can leave them empty.
If debug is set to True, all the exceptions
will print its traceback.
"""... | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def __str__(self):
return ''' | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def check_value(self, value):
"""
return False if the value don't exists,
return True if the value exists
"""
if not os.path.exists(self.ini_path):
return False
else:
try:
self._config.read(self.ini_path)
except ... | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def get_float(self, value):
"""
If the value exists, return the float
corresponding to the string. If it does
not exists, or the value can not be converted
to a float, return the default float.
"""
if self.check_value(value):
val = self... | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def get_list(self, value):
"""
If the value exists, return the integer
corresponding to the string. If it does
not exists, or the value can not be converted
to a integer, return the default integer.
"""
if self.check_value(value):
val =... | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def get_bool_defval(self, value, default):
"""
If the value exists, return the boolean
corresponding to the string. If it does
not exists, or the value can not be converted
to a boolean, return the the second argument.
"""
if self.check_value(value... | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def get_int_defval(self, value, default):
"""
If the value exists, return the integer
corresponding to the string. If it does
not exists, or the value can not be converted
to a integer, return the the second argument.
"""
if self.check_value(value)... | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def set_configuration_path(self, ini_path):
"""
Set the path to the configuration file.
"""
if isinstance(ini_path, str):
self.ini_path = ini_path
if not os.path.exists(ini_path) and self._debug:
print("CCParser Warning: the path to the configu... | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def set_default_float(self, value):
"""
Set the default float to return when
a value does not exists. By default
it returns 0.0
"""
self.__default_float = value | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def set_default_bool(self, value):
"""
Set the default boolean to return when
a value does not exists. By default
it returns false
"""
self.__default_bool = value | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def set_default_list(self, value):
"""
Set the default integer to return when
a value does not exists. By default
it returns 0
"""
self.__default_list = value | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def get_default_bool(self):
return self.__default_bool | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def get_default_str(self):
return self.__default_string | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def get_default_list(self):
return self.__default_list | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def get_configuration_path(self):
return self.ini_path | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def test(path): | rsm-gh/alienware-kbl | [
111,
23,
111,
50,
1478047481
] |
def upgrade():
''' Drop the columns calendar_multiple_meetings and
calendar_regional_meetings and rename meeting_region into
meeting_location.
'''
op.drop_column('calendars', 'calendar_multiple_meetings')
op.drop_column('calendars', 'calendar_regional_meetings')
op.alter_column(
'mee... | fedora-infra/fedocal | [
24,
19,
24,
1,
1363980910
] |
def extractbody(m) :
begin = re.compile("\\\\begin\s*")
m= begin.sub("\\\\begin",m)
end = re.compile("\\\\end\s*")
m = end.sub("\\\\end",m) | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def convertsqb(m) :
r = re.compile("\\\\item\\s*\\[.*?\\]")
Litems = r.findall(m)
Lrest = r.split(m)
m = Lrest[0]
for i in range(0,len(Litems)) :
s= Litems[i]
s=s.replace("\\item","\\nitem")
s=s.replace("[","{")
s=s.replace("]","}")
m=m+s+Lrest[i+1]
r = re.compi... | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def convertmacros(m) :
comm = re.compile("\\\\[a-zA-Z]*")
commands = comm.findall(m)
rest = comm.split(m)
r= rest[0]
for i in range( len (commands) ) :
for s1,s2 in M :
if s1==commands[i] :
commands[i] = s2
r=r+commands[i]+rest[i+1]
return(r) | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def separatemath(m) :
mathre = re.compile("\\$.*?\\$"
"|\\\\begin\\{equation}.*?\\\\end\\{equation}"
"|\\\\\\[.*?\\\\\\]")
math = mathre.findall(m)
text = mathre.split(m)
return(math,text) | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def convertcolors(m,c) :
if m.find("begin") != -1 :
return("<span style=\"color:#"+colors[c]+";\">")
else :
return("</span>") | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def convertenum(m) :
if m.find("begin") != -1 :
return ("\n\n<ol>")
else :
return ("\n</ol>\n\n") | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def convertbeginthm(thm) :
global inthm
count[T[thm]] +=1
inthm = thm
t = beginthm.replace("_ThmType_",thm.capitalize())
t = t.replace("_ThmNumb_",str(count[T[thm]]))
return(t) | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def convertendthm(thm) :
global inthm
inthm = ""
return(endthm) | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def convertproof(m) :
if m.find("begin") != -1 :
return(beginproof)
else :
return(endproof) | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def convertsection (m) : | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def convertsubsection (m) : | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def converturl (m) :
L = cb.split(m)
return ("<a href=\""+L[1]+"\">"+L[3]+"</a>") | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def convertimage (m) :
L = cb.split (m)
return ("<p align=center><img "+L[1] + " src=\""+L[3]
+"\"></p>") | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def processtext ( t ) :
p = re.compile("\\\\begin\\{\\w+}"
"|\\\\nbegin\\{\\w+}\\s*\\{.*?}"
"|\\\\end\\{\\w+}"
"|\\\\item"
"|\\\\nitem\\s*\\{.*?}"
"|\\\\label\\s*\\{.*?}"
"|\\\\section\\s*\\{.*?}"
... | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def processfontstyle(w) :
close = dict()
ww = ""
level = i = 0
while i < len(w):
special = False
for k, v in fontstyle.items():
l = len(k)
if w[i:i+l] == k:
level += 1
ww += '<' + v + '>'
close[level] ... | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def convertref(m) :
global ref | theoj2/Nibbletex | [
1,
1,
1,
6,
1395387630
] |
def __init__(self, line_string):
"""
To initialize a Cluster object, only a string compliant with the
format of a cluster in an OrthoMCL groups file has to be provided.
This line should contain the name of the group, a colon, and the
sequences belonging to that group separated by... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def remove_taxa(self, taxa_list):
"""
Removes the taxa contained in taxa_list from self.sequences and
self.species_frequency
:param taxa_list: list, each element should be a taxon name
"""
self.sequences = [x for x in self.sequences if x.split("|")[0]
... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def __init__(self, groups_file, gene_threshold=None,
species_threshold=None, ns=None):
self.gene_threshold = gene_threshold if gene_threshold else None
self.species_threshold = species_threshold if species_threshold \
else None
# Attribute containing the list of in... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def iter_species_frequency(self):
"""
In order to prevent permanent changes to the species_frequency
attribute due to the filtering of taxa, this iterable should be used
instead of the said variable. This creates a temporary deepcopy of
species_frequency which will be iterated ov... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def _apply_filter(self, cl):
"""
Sets or updates the basic group statistics, such as the number of
orthologs compliant with the gene copy and minimum taxa filters.
:param cl: dictionary. Contains the number of occurrences for each
taxon present in the ortholog cluster
... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def _reset_counter(self):
self.all_clusters = 0
self.num_gene_compliant = 0
self.num_species_compliant = 0
self.all_compliant = 0 | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def exclude_taxa(self, taxa_list, update_stats=False):
"""
Updates the excluded_taxa attribute and updates group statistics if
update_stats is True. This does not change the Group object data
permanently, only sets an attribute that will be taken into account
when plotting and ex... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def _get_sp_proportion(self):
"""
When the species filter is a float value between 0 and 1, convert
this proportion into absolute values (rounded up), since filters were
already designed for absolutes.
"""
self.species_threshold = int(self.species_threshold *
... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def retrieve_sequences(self, sqldb, protein_db, dest="./",
shared_namespace=None, outfile=None):
"""
:param sqldb: srting. Path to sqlite database file
:param protein_db: string. Path to protein database file
:param dest: string. Directory where sequences wil... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def bar_species_distribution(self, filt=False):
if filt:
data = Counter((len(cl) for cl in self.iter_species_frequency() if
self._get_compliance(cl) == (1, 1)))
else:
data = Counter((len(cl) for cl in self.species_frequency))
x_labels = [x for... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def bar_species_coverage(self, filt=False):
"""
Creates a stacked bar plot with the proportion of
:return:
"""
data = Counter(dict((x, 0) for x in self.species_list))
self._reset_counter()
for cl in self.iter_species_frequency():
self._apply_filter... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def __init__(self, groups_file, gene_threshold=None,
species_threshold=None, project_prefix="MyGroups"):
# Initializing thresholds. These may be set from the start, or using
# some method that uses them as arguments
self.gene_threshold = gene_threshold
self.species_thr... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def exclude_taxa(self, taxa_list):
"""
Adds a taxon_name to the excluded_taxa list and updates the
filtered_groups list
"""
self.excluded_taxa.extend(taxa_list)
# Storage variable for new filtered groups
filtered_groups = []
# Reset max_extra_copy attri... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def basic_group_statistics(self):
"""
This method creates a basic table in list format containing basic
information of the groups file (total number of clusters, total number
of sequences, number of clusters below the gene threshold, number of
clusters below the species threshold... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def export_filtered_group(self, output_file_name="filtered_groups",
dest="./", get_stats=False,
shared_namespace=None):
"""
Export the filtered groups into a new file.
:param output_file_name: string, name of the filtered groups file
... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def update_filtered_group(self):
"""
This method creates a new filtered group variable, like
export_filtered_group, but instead of writing into a new file, it
replaces the self.filtered_groups variable
"""
self.filtered_groups = []
# Reset gene and species compl... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def bar_species_distribution(self, dest="./", filt=False, ns=None,
output_file_name="Species_distribution"):
"""
Creates a bar plot with the distribution of species numbers across
clusters
:param dest: string, destination directory
:param filt: Bo... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def bar_species_coverage(self, dest="./", filt=False, ns=None,
output_file_name="Species_coverage"):
"""
Creates a stacked bar plot with the proportion of
:return:
"""
# Determine which groups to use
if filt:
groups = self.filtere... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def __init__(self, groups_files=None, gene_threshold=None,
species_threshold=None, project_prefix="MyGroups"):
"""
:param groups_files: A list containing the file names of the multiple
group files
:return: Populates the self.multiple_groups attribute
"""
... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def iter_gnames(self):
return (x.name for x in self.multiple_groups) | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def add_group(self, group_obj):
"""
Adds a group object
:param group_obj: Group object
"""
# Check for duplicate groups
if group_obj.name in self.multiple_groups:
self.duplicate_groups.append(group_obj.name)
else:
self.multiple_groups[grou... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def get_group(self, group_id):
"""
Returns a group object based on its name. If the name does not match
any group object, returns None
:param group_id: string. Name of group object
"""
try:
return self.multiple_groups[group_id]
except KeyError:
... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def update_filters(self, gn_filter, sp_filter, group_names=None,
default=False):
"""
This will not change the Group object themselves, only the filter
mapping. The filter is only applied when the Group object is retrieved
to reduce computations
:param gn_fi... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def bar_orthologs(self, output_file_name="Final_orthologs",
dest="./", stats="total"):
"""
Creates a bar plot with the final ortholog values for each group file
:param output_file_name: string. Name of output file
:param dest: string. output directory
... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def parse_groups(group_obj):
"""
Returns a list with the sorted ortholog clusters
"""
storage = []
for cluster in group_obj.groups:
storage.append(set(cluster.iter_sequences))
return storage | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def __init__(self, db_path, groups=None, gene_threshold=None,
species_threshold=None, project_prefix="MyGroups",
ns=None):
"""
:param groups: A list containing the file names of the multiple
group files
:return: Populates the self.multiple_groups attribu... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def clear_groups(self):
"""
Clears the current MultiGroupsLight object
"""
for f in self.groups.values():
os.remove(f)
self.duplicate_groups = []
self.groups = {}
self.groups_stats = {}
self.filters = {}
self.max_extra_copy = {}
... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def remove_group(self, group_id):
"""
Removes a group object according to its name
:param group_id: string, name matching a Group object name attribute
"""
if group_id in self.groups:
os.remove(self.groups[group_id])
del self.groups[group_id] | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def add_multigroups(self, multigroup_obj):
"""
Merges a MultiGroup object
:param multigroup_obj: MultiGroup object
"""
for _, group_obj in multigroup_obj:
self.add_group(group_obj) | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def get_multigroup_statistics(self, group_obj):
"""
:return:
"""
stats = group_obj.basic_group_statistics()
self.groups_stats[group_obj.name] = {"stats": stats,
"species": group_obj.species_list,
"m... | ODiogoSilva/TriFusion | [
83,
23,
83,
21,
1392138811
] |
def __init__(self, sheet_width, sheet_height, columns, rows, label_width, label_height, **kwargs):
"""
Required parameters
-------------------
sheet_width, sheet_height: positive dimension
The size of the sheet.
columns, rows: positive integer
The number ... | bcbnz/pylabels | [
87,
40,
87,
11,
1352002192
] |
def bounding_boxes(self, mode='fraction', output='dict'):
"""Get the bounding boxes of the labels on a page.
Parameters
----------
mode: 'fraction', 'actual'
If 'fraction', the bounding boxes are expressed as a fraction of the
height and width of the sheet. If 'a... | bcbnz/pylabels | [
87,
40,
87,
11,
1352002192
] |
def create_accessor(attr, deletable=False):
# Getter is simple; no processing needed.
@property
def accessor(self):
return getattr(self, attr)
# Setter is more complicated.
@accessor.setter
def accessor(self, value):
# Store the original value in ... | bcbnz/pylabels | [
87,
40,
87,
11,
1352002192
] |
def __init__(self, x, y, vx, vy, word):
self.x = x
self.y = y
self.vx = vx
self.vy = vy
self.word = word
self.size = max(100, 50 + len(word) * 20)
self.color = random.choice(BALLOON_COLORS) | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def __init__(self, lesson, activity):
GObject.GObject.__init__(self) | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def realize_cb(self, widget):
self.activity.add_events(Gdk.EventMask.KEY_PRESS_MASK)
self.key_press_cb_id = self.activity.connect('key-press-event', self.key_cb)
# Clear the mouse cursor.
#pixmap = Gdk.Pixmap(widget.window, 10, 10)
#color = Gdk.Color()
#cursor = Gdk.Cur... | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def unrealize_cb(self, widget):
self.activity.disconnect(self.key_press_cb_id) | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def stop_cb(self, widget):
# Stop the animation loop.
if self.update_timer:
try:
GObject.source_remove(self.update_timer)
except:
pass # Try remove instance, if not found, just pass | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def key_cb(self, widget, event):
# Ignore hotkeys.
if event.get_state() & (Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD1_MASK):
return False
# Extract information about the key pressed.
key = Gdk.keyval_to_unicode(event.keyval)
if key != 0: key = chr(key)
... | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def update_balloon(self, b):
b.x += b.vx
b.y += b.vy
if b.x < 100 or b.x >= self.bounds.width - 100:
b.vx = -b.vx
if b.y < -100:
self.balloons.remove(b)
self.queue_draw_balloon(b) | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def tick(self):
if self.finished:
return False
self.bounds = self.area.get_allocation() | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def draw_results(self, cr):
# Draw background.
w = self.bounds.width - 400
h = self.bounds.height - 200
x = self.bounds.width/2 - w/2
y = self.bounds.height/2 - h/2
cr.set_source_rgb(0.762, 0.762, 0.762)
cr.rectangle(x, y, w, h)
cr.fill()
cr.set_... | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def finish_game(self):
self.finished = True
# Add to the lesson history.
report = {
'lesson': self.lesson['name'],
'score': self.score,
}
self.activity.add_history(report)
# Show the medal screen, if one should be given.
got_medal = None | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def queue_draw_balloon(self, b):
x = int(b.x - b.size/2) - 5
y = int(b.y - b.size/2) - 5
w = int(b.size + 100)
h = int(b.size*1.5 + 10)
self.area.queue_draw_area(x, y, w, h) | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def add_score(self, num):
self.score += num
self.queue_draw_score() | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def draw_score(self, cr):
cr.set_source_rgb(0, 0, 0)
pango_layout = PangoCairo.create_layout(cr)
fd = Pango.FontDescription('Times')
fd.set_size(14 * Pango.SCALE)
pango_layout.set_font_description(fd)
text = _('SCORE: %d') % self.score
pango_layout.set_text(text, ... | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
def draw(self, cr):
self.bounds = self.area.get_allocation()
# Draw background.
cr.set_source_rgb(0.915, 0.915, 1)
cr.rectangle(0, 0, self.bounds.width, self.bounds.height)
cr.fill()
# Draw the balloons.
for b in self.balloons:
self.draw_balloon(cr, ... | godiard/typing-turtle-activity | [
4,
8,
4,
4,
1419121319
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.