diff options
author | Walter Bender <walter@sugarlabs.org> | 2013-07-27 22:38:22 (GMT) |
---|---|---|
committer | Walter Bender <walter@sugarlabs.org> | 2013-07-27 22:38:22 (GMT) |
commit | a308a5425f6f7bed7fc15ba43d9bf3f1894083fa (patch) | |
tree | bd6a6c37615a6a69a8d391b0dc4e796c82638dd0 /pysamples | |
parent | bf2d9ffa0052fbe2a025d871b9b3c5e91e9c7ff2 (diff) |
remove extra stuffv187
Diffstat (limited to 'pysamples')
-rw-r--r-- | pysamples/brain.py | 111 | ||||
-rw-r--r-- | pysamples/copy_from_heap.py | 16 | ||||
-rw-r--r-- | pysamples/csound.py | 148 | ||||
-rw-r--r-- | pysamples/forward_push.py | 53 | ||||
-rw-r--r-- | pysamples/grecord.py | 228 | ||||
-rw-r--r-- | pysamples/journal-stats.py | 119 | ||||
-rw-r--r-- | pysamples/load_block.py | 90 | ||||
-rw-r--r-- | pysamples/load_file_to_heap.py | 30 | ||||
-rw-r--r-- | pysamples/load_journal_entry_to_heap.py | 18 | ||||
-rw-r--r-- | pysamples/paste_to_heap.py | 21 | ||||
-rw-r--r-- | pysamples/push_mouse_event.py | 26 | ||||
-rw-r--r-- | pysamples/push_time.py | 21 | ||||
-rw-r--r-- | pysamples/save_heap_to_journal_entry.py | 39 | ||||
-rw-r--r-- | pysamples/sensors.py | 33 | ||||
-rw-r--r-- | pysamples/serial.py | 21 | ||||
-rw-r--r-- | pysamples/set_rgb.py | 18 | ||||
-rw-r--r-- | pysamples/sinewave.py | 15 | ||||
-rw-r--r-- | pysamples/speak.py | 57 | ||||
-rw-r--r-- | pysamples/svg_end_group.py | 21 | ||||
-rw-r--r-- | pysamples/svg_start_group.py | 21 | ||||
-rw-r--r-- | pysamples/ta-stats.py | 172 |
21 files changed, 0 insertions, 1278 deletions
diff --git a/pysamples/brain.py b/pysamples/brain.py deleted file mode 100644 index 33ee320..0000000 --- a/pysamples/brain.py +++ /dev/null @@ -1,111 +0,0 @@ -# A Turtle Block based on the Speak Activity interface to AIML -# Copyright 2012 Walter Bender, Sugar Labs -# -# Copyright (C) 2008 Sebastian Silva Fundacion FuenteLibre -# sebastian@fuentelibre.org -# -# Style and structure taken from Speak.activity Copyright (C) Joshua Minor -# -# HablarConSara.activity is free software: you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License as published by the Free Software Foundation, either -# version 3 of the License, or (at your option) any later version. -# -# HablarConSara.activity is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public -# License along with HablarConSara.activity. If not, see -# <http://www.gnu.org/licenses/>. - - -def myblock(tw, text): - ''' Dialog with AIML library: Usage: Load this code into a Python - Block. Pass text as an argument and the robot's response will - be pushed to the stack. Use a Pop Block to pop the response - off the the stack.''' - - # The AIML library is bundled with the Speak activity - SPEAKPATHS = ['/home/olpc/Activities/Speak.activity', - '/home/liveuser/Activities/Speak.activity', - '/usr/share/sugar/activities/Speak.activity'] - import os - from gettext import gettext as _ - speakpath = None - for sp in SPEAKPATHS: - if os.path.exists(sp): - speakpath = sp - break - if speakpath is None: - tw.showlabel( - 'status', _('Please install the Speak Activity and try again.')) - return - import sys - sys.path.append(speakpath) - - import aiml - import voice - - BOTS = { - _('Spanish'): {'name': 'Sara', - 'brain': os.path.join(speakpath, 'bot', 'sara.brn'), - 'predicates': {'nombre_bot': 'Sara', - 'botmaster': 'La comunidad Azucar'}}, - _('English'): {'name': 'Alice', - 'brain': os.path.join(speakpath, 'bot', 'alice.brn'), - 'predicates': {'name': 'Alice', - 'master': 'The Sugar Community'}}} - - def get_mem_info(tag): - meminfo = file('/proc/meminfo').readlines() - return int([i for i in meminfo if i.startswith(tag)][0].split()[1]) - - # load Standard AIML set for restricted systems - if get_mem_info('MemTotal:') < 524288: - mem_free = get_mem_info('MemFree:') + get_mem_info('Cached:') - if mem_free < 102400: - BOTS[_('English')]['brain'] = None - else: - BOTS[_('English')]['brain'] = os.path.join(speakpath, 'bot', - 'alisochka.brn') - - def get_default_voice(): - default_voice = voice.defaultVoice() - if default_voice.friendlyname not in BOTS: - return voice.allVoices()[_('English')] - else: - return default_voice - - def brain_respond(kernel, text): - if kernel is not None: - text = kernel.respond(text) - if kernel is None or not text: - text = '' - tw.showlabel( - 'status', - _("Sorry, I can't understand what you are asking about.")) - return text - - def brain_load(kernel, voice): - brain = BOTS[voice.friendlyname] - kernel = aiml.Kernel() - - if brain['brain'] is None: - tw.showlabel( - 'status', _('Sorry, there is no free memory to load my brain. \ -Close other activities and try once more.')) - return kernel - - kernel.loadBrain(brain['brain']) - for name, value in brain['predicates'].items(): - kernel.setBotPredicate(name, value) - - return kernel - - if not hasattr(tw, 'aiml_kernel'): - tw.aiml_kernel = brain_load(tw, get_default_voice()) - response_text = brain_respond(tw.aiml_kernel, text) - tw.lc.heap.append(response_text) - return diff --git a/pysamples/copy_from_heap.py b/pysamples/copy_from_heap.py deleted file mode 100644 index fbca999..0000000 --- a/pysamples/copy_from_heap.py +++ /dev/null @@ -1,16 +0,0 @@ -#Copyright (c) 2010-11, Walter Bender, Tony Forster - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected. - -# Usage: Import this code into a Python (user-definable) block; when -# this code is run, the FILO heap will be copied to the clipboard. - - -def myblock(tw, x): # second argument is ignored - ''' Copy heap to clipboard ''' - - from gtk import Clipboard - from TurtleArt.tautils import data_to_string - - Clipboard().set_text(data_to_string(tw.lc.heap)) diff --git a/pysamples/csound.py b/pysamples/csound.py deleted file mode 100644 index a935674..0000000 --- a/pysamples/csound.py +++ /dev/null @@ -1,148 +0,0 @@ -#Copyright (c) 2011 Walter Bender - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected. - -# Usage: Import this code into a Python (user-definable) block and -# pass a sound name Python block. The sound will play. -# Alternatively, pass a pitch, amplitude, and duration, e.g., 440, 5000, 1 - -# Note: Assumes TamTam suite is installed in ~/Activities - - -def myblock(tw, sound): - ''' Plays a sound file ''' - - from TurtleArt.tautils import get_path - import os - - dirs = [os.path.join( - os.environ['HOME'], - 'Activities/TamTamMini.activity/common/Resources/Sounds/')] - orchlines = [] - scorelines = [] - instrlist = [] - - def finddir(): - for d in dirs: - if os.path.isdir(d): - return d - - def playSine(pitch=1000, amplitude=5000, duration=1, starttime=0, - pitch_envelope='default', amplitude_envelope='default'): - """ Create a score to play a sine wave. """ - _play(pitch, amplitude, duration, starttime, pitch_envelope, - amplitude_envelope, 1) - - def _play(pitch, amplitude, duration, starttime, pitch_envelope, - amplitude_envelope, instrument): - if pitch_envelope == 'default': - pitenv = 99 - else: - pitenv = pitch_envelope - - if amplitude_envelope == 'default': - ampenv = 100 - else: - ampenv = amplitude_envelope - - if not 1 in instrlist: - orchlines.append("instr 1\n") - orchlines.append("kpitenv oscil 1, 1/p3, p6\n") - orchlines.append("aenv oscil 1, 1/p3, p7\n") - orchlines.append("asig oscil p5*aenv, p4*kpitenv, p8\n") - orchlines.append("out asig\n") - orchlines.append("endin\n\n") - instrlist.append(1) - - scorelines.append("i1 %s %s %s %s %s %s %s\n" % - (str(starttime), str(duration), str(pitch), - str(amplitude), str(pitenv), str(ampenv), - str(instrument))) - - def playWave(sound='horse', pitch=1, amplitude=1, loop=False, duration=1, - starttime=0, pitch_envelope='default', - amplitude_envelope='default'): - """ Create a score to play a wave file. """ - - if '/' in sound: - fullname = sound - else: - fullname = finddir() + str(sound) - - if loop: - lp = 1 - else: - lp = 0 - - if pitch_envelope == 'default': - pitenv = 99 - else: - pitenv = pitch_envelope - - if amplitude_envelope == 'default': - ampenv = 100 - else: - ampenv = amplitude_envelope - - if not 9 in instrlist: - orchlines.append("instr 9\n") - orchlines.append("kpitenv oscil 1, 1/p3, p8\n") - orchlines.append("aenv oscil 1, 1/p3, p9\n") - orchlines.append("asig diskin p4, p5*kpitenv, 0, p7\n") - orchlines.append("out asig*p6*aenv\n") - orchlines.append("endin\n\n") - instrlist.append(9) - - scorelines.append('i9 %f %f "%s" %s %s %s %s %s\n' % - (float(starttime), float(duration), fullname, - str(pitch), str(amplitude), str(lp), str(pitenv), - str(ampenv))) - - def audioWrite(file): - """ Compile a .csd file. """ - - csd = open(file, "w") - csd.write("<CsoundSynthesizer>\n\n") - csd.write("<CsOptions>\n") - csd.write("-+rtaudio=alsa -odevaudio -m0 -d -b256 -B512\n") - csd.write("</CsOptions>\n\n") - csd.write("<CsInstruments>\n\n") - csd.write("sr=16000\n") - csd.write("ksmps=50\n") - csd.write("nchnls=1\n\n") - # csd.write(orchlines.pop()) - for line in orchlines: - csd.write(line) - csd.write("\n</CsInstruments>\n\n") - csd.write("<CsScore>\n\n") - csd.write("f1 0 2048 10 1\n") - csd.write("f2 0 2048 10 1 0 .33 0 .2 0 .143 0 .111\n") - csd.write("f3 0 2048 10 1 .5 .33 .25 .2 .175 .143 .125 .111 .1\n") - csd.write("f10 0 2048 10 1 0 0 .3 0 .2 0 0 .1\n") - csd.write("f99 0 2048 7 1 2048 1\n") - csd.write("f100 0 2048 7 0. 10 1. 1900 1. 132 0.\n") - csd.write(scorelines.pop()) - csd.write("e\n") - csd.write("\n</CsScore>\n") - csd.write("\n</CsoundSynthesizer>") - csd.close() - - if type(sound) == float: - playSine(pitch=float(sound)) - elif type(sound) == list: # Create a score by computing a sinewave. - if len(sound) == 1: - playSine(pitch=float(sound[0])) - elif len(sound) == 2: - playSine(pitch=float(sound[0]), amplitude=float(sound[1])) - else: - playSine(pitch=float(sound[0]), amplitude=float(sound[1]), - duration=float(sound[2])) - else: # Create a score from a prerecorded Wave file. - playWave(sound) - if tw.running_sugar: - path = os.path.join(get_path(tw.activity, 'instance'), 'tmp.csd') - else: - path = os.path.join('/tmp', 'tmp.csd') - audioWrite(path) # Create a csound file from the score. - os.system('csound ' + path) # Play the csound file. diff --git a/pysamples/forward_push.py b/pysamples/forward_push.py deleted file mode 100644 index b98c726..0000000 --- a/pysamples/forward_push.py +++ /dev/null @@ -1,53 +0,0 @@ -#Copyright (c) 2012, Walter Bender - -# Usage: Import this code into a Python (user-definable) block; when -# this code is run, the turtle will draw a line of the length of the -# numeric argument block docked to the Python block. But before -# drawing the line, it pushes the rgb values of the destination to the -# FILO. - - -def myblock(tw, name): - ''' ''' - - def _prim_forward_push(tw, line_length): - try: # make sure line_length is a number - line_length = float(line_length) - except ValueError: - return - penstatus = tw.canvas.pendown - tw.canvas.setpen(False) - tw.canvas.forward(line_length) - r, g, b, a = tw.canvas.get_pixel() - tw.lc.heap.append(b) - tw.lc.heap.append(g) - tw.lc.heap.append(r) - tw.canvas.forward(-line_length) - tw.canvas.setpen(penstatus) - tw.canvas.forward(line_length) - return - - from TurtleArt.tapalette import make_palette, palette_name_to_index - from TurtleArt.talogo import primitive_dictionary - from gettext import gettext as _ - - # Choose a palette for the new block. - palette = make_palette('turtle') - - primitive_dictionary['forwardpush'] = _prim_forward_push - - # Create a new block prototype. - palette.add_block('forwardpush', - style='basic-style-1arg', - label=name, - default=100, - prim_name='forwardpush', - help_string=_('push destination rgb value to heap')) - - # Add its primitive to the LogoCode dictionary. - tw.lc.def_prim('forwardpush', 1, - lambda self, x: primitive_dictionary['forwardpush'](tw, x)) - - # Regenerate the palette, which will now include the new block. - tw.show_toolbar_palette(palette_name_to_index('turtle'), - regenerate=True) diff --git a/pysamples/grecord.py b/pysamples/grecord.py deleted file mode 100644 index a28b82c..0000000 --- a/pysamples/grecord.py +++ /dev/null @@ -1,228 +0,0 @@ -#Copyright (c) 2008, Media Modifications Ltd. -#Copyright (c) 2011, Walter Bender - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected. - -# Usage: Import this code into a Python (user-definable) block; Pass -# it 'start' to start recording; 'stop' to stop recording; 'play' to -# play back your recording; or 'save' to save your recording to the -# Sugar Journal. - - -def myblock(tw, arg): - ''' Record and playback a sound (Sugar only) ''' - import os - import gst - import gobject - gobject.threads_init() - - from TurtleArt.tautils import get_path - from TurtleArt.tagplay import play_audio_from_file - from sugar.datastore import datastore - from sugar import profile - - from gettext import gettext as _ - - class Grecord: - ''' A class for creating a gstreamer session for recording audio. ''' - - def __init__(self, tw): - ''' Set up the stream. We save to a raw .wav file and then - convert the sound to .ogg for saving. ''' - datapath = get_path(tw.parent, 'instance') - self.capture_file = os.path.join(datapath, 'output.wav') - self.save_file = os.path.join(datapath, 'output.ogg') - self._eos_cb = None - - self._can_limit_framerate = False - self._recording = False - - self._audio_transcode_handler = None - self._transcode_id = None - - self._pipeline = gst.Pipeline("Record") - self._create_audiobin() - self._pipeline.add(self._audiobin) - - bus = self._pipeline.get_bus() - bus.add_signal_watch() - bus.connect('message', self._bus_message_handler) - - def _create_audiobin(self): - ''' Assemble all the pieces we need. ''' - src = gst.element_factory_make("alsasrc", "absrc") - - # attempt to use direct access to the 0,0 device, solving - # some A/V sync issues - src.set_property("device", "plughw:0,0") - hwdev_available = src.set_state(gst.STATE_PAUSED) != \ - gst.STATE_CHANGE_FAILURE - src.set_state(gst.STATE_NULL) - if not hwdev_available: - src.set_property("device", "default") - - srccaps = gst.Caps( - "audio/x-raw-int,rate=16000,channels=1,depth=16") - - # guarantee perfect stream, important for A/V sync - rate = gst.element_factory_make("audiorate") - - # without a buffer here, gstreamer struggles at the start - # of the recording and then the A/V sync is bad for the - # whole video (possibly a gstreamer/ALSA bug -- even if it - # gets caught up, it should be able to resync without - # problem) - queue = gst.element_factory_make("queue", "audioqueue") - queue.set_property("leaky", True) # prefer fresh data - queue.set_property("max-size-time", 5000000000) # 5 seconds - queue.set_property("max-size-buffers", 500) - queue.connect("overrun", self._log_queue_overrun) - - enc = gst.element_factory_make("wavenc", "abenc") - - sink = gst.element_factory_make("filesink", "absink") - sink.set_property("location", self.capture_file) - - self._audiobin = gst.Bin("audiobin") - self._audiobin.add(src, rate, queue, enc, sink) - - src.link(rate, srccaps) - gst.element_link_many(rate, queue, enc, sink) - - def _log_queue_overrun(self, queue): - ''' We use a buffer, which may overflow. ''' - cbuffers = queue.get_property("current-level-buffers") - cbytes = queue.get_property("current-level-bytes") - ctime = queue.get_property("current-level-time") - - def is_recording(self): - ''' Are we recording? ''' - return self._recording - - def _get_state(self): - ''' What is the state of our gstreamer pipeline? ''' - return self._pipeline.get_state()[1] - - def start_recording_audio(self): - ''' Start the stream in order to start recording. ''' - if self._get_state() == gst.STATE_PLAYING: - return - self._pipeline.set_state(gst.STATE_PLAYING) - self._recording = True - - def stop_recording_audio(self): - ''' Stop recording and then convert the results into a - .ogg file using a new stream. ''' - self._pipeline.set_state(gst.STATE_NULL) - self._recording = False - - if not os.path.exists(self.capture_file) or \ - os.path.getsize(self.capture_file) <= 0: - return - - # Remove previous transcoding results. - if os.path.exists(self.save_file): - os.remove(self.save_file) - - line = 'filesrc location=' + self.capture_file + \ - ' name=audioFilesrc ! wavparse name=audioWavparse \ -! audioconvert name=audioAudioconvert ! vorbisenc name=audioVorbisenc \ -! oggmux name=audioOggmux ! filesink name=audioFilesink' - audioline = gst.parse_launch(line) - - # vorbis_enc = audioline.get_by_name('audioVorbisenc') - - audioFilesink = audioline.get_by_name('audioFilesink') - audioFilesink.set_property("location", self.save_file) - - audioBus = audioline.get_bus() - audioBus.add_signal_watch() - self._audio_transcode_handler = audioBus.connect( - 'message', self._onMuxedAudioMessageCb, audioline) - self._transcode_id = gobject.timeout_add( - 200, self._transcodeUpdateCb, audioline) - audioline.set_state(gst.STATE_PLAYING) - - def _transcodeUpdateCb(self, pipe): - ''' Where are we in the transcoding process? ''' - position, duration = self._query_position(pipe) - if position != gst.CLOCK_TIME_NONE: - value = position * 100.0 / duration - value = value/100.0 - return True - - def _query_position(self, pipe): - ''' Where are we in the stream? ''' - try: - position, format = pipe.query_position(gst.FORMAT_TIME) - except: - position = gst.CLOCK_TIME_NONE - - try: - duration, format = pipe.query_duration(gst.FORMAT_TIME) - except: - duration = gst.CLOCK_TIME_NONE - - return (position, duration) - - def _onMuxedAudioMessageCb(self, bus, message, pipe): - ''' Clean up at end of stream.''' - if message.type != gst.MESSAGE_EOS: - return True - - gobject.source_remove(self._audio_transcode_handler) - self._audio_transcode_handler = None - gobject.source_remove(self._transcode_id) - self._transcode_id = None - pipe.set_state(gst.STATE_NULL) - pipe.get_bus().remove_signal_watch() - pipe.get_bus().disable_sync_message_emission() - - os.remove(self.capture_file) - return False - - def _bus_message_handler(self, bus, message): - ''' Handle any messages associated with the stream. ''' - t = message.type - if t == gst.MESSAGE_EOS: - if self._eos_cb: - cb = self._eos_cb - self._eos_cb = None - cb() - elif t == gst.MESSAGE_ERROR: - # TODO: if we come out of suspend/resume with errors, then - # get us back up and running... TODO: handle "No space - # left on the resource.gstfilesink.c" err, debug = - # message.parse_error() - pass - - # We store the audio-record stream instance as tw.grecord so that - # we can use it repeatedly. - if not hasattr(tw, 'grecord'): - tw.grecord = Grecord(tw) - - # Sometime we need to parse multiple arguments, e.g., save, savename - save_name = '%s_%s' % (tw.activity.name, _('sound')) - if isinstance(arg, list): - cmd = arg[0].lower() - if len(arg) > 1: - save_name = str(arg[1]) - else: - cmd = arg.lower() - - if cmd == 'start' or cmd == _('start').lower(): - tw.grecord.start_recording_audio() - elif cmd == 'stop' or cmd == _('stop').lower(): - tw.grecord.stop_recording_audio() - elif cmd == 'play' or cmd == _('play').lower(): - play_audio_from_file(tw.lc, tw.grecord.save_file) - elif cmd == 'save' or cmd == _('save').lower(): - if os.path.exists(tw.grecord.save_file) and tw.running_sugar: - dsobject = datastore.create() - dsobject.metadata['title'] = save_name - dsobject.metadata['icon-color'] = profile.get_color().to_string() - dsobject.metadata['mime_type'] = 'audio/ogg' - dsobject.set_file_path(tw.grecord.save_file) - datastore.write(dsobject) - dsobject.destroy() diff --git a/pysamples/journal-stats.py b/pysamples/journal-stats.py deleted file mode 100644 index 1342a69..0000000 --- a/pysamples/journal-stats.py +++ /dev/null @@ -1,119 +0,0 @@ -# Copyright (c) 2012, Walter Bender - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -def myblock(tw, x): # ignore second argument - ''' Load journal stats to heap (Sugar only) ''' - - import os - import glob - from gettext import gettext as _ - - MAX = 19 - DIROFINTEREST = 'datastore' - - class ParseJournal(): - ''' Simple parser of datastore ''' - - def __init__(self): - self._dsdict = {} - self._activity_name = [] - self._activity_count = [] - - homepath = os.environ['HOME'] - for path in glob.glob(os.path.join(homepath, '.sugar', '*')): - if isdsdir(path): - self._dsdict[os.path.basename(path)] = [] - dsobjdirs = glob.glob( - os.path.join(path, DIROFINTEREST, '??')) - for dsobjdir in dsobjdirs: - dsobjs = glob.glob(os.path.join(dsobjdir, '*')) - for dsobj in dsobjs: - self._dsdict[os.path.basename(path)].append({}) - activity = isactivity(dsobj) - if not activity: - self._dsdict[os.path.basename(path)][-1][ - 'activity'] = 'media object' - else: - self._dsdict[os.path.basename(path)][-1][ - 'activity'] = activity - - for k, v in self._dsdict.iteritems(): - for a in v: - if 'activity' in a: - if a['activity'] in self._activity_name: - i = self._activity_name.index(a['activity']) - self._activity_count[i] += 1 - else: - self._activity_name.append(a['activity']) - self._activity_count.append(1) - - def get_sorted(self): - activity_tuples = [] - for i in range(len(self._activity_name)): - activity_tuples.append((self._activity_name[i], - self._activity_count[i])) - sorted_tuples = sorted(activity_tuples, key=lambda x: x[1]) - activity_list = [] - count = 0 - length = len(sorted_tuples) - for i in range(length): - if i < MAX: - activity_list.append([sorted_tuples[length - i - 1][0], - sorted_tuples[length - i - 1][1]]) - else: - count += sorted_tuples[length - i - 1][1] - if count > 0: - activity_list.append([_('other'), count]) - return activity_list - - def hascomponent(path, component): - ''' Return metadata attribute, if any ''' - if not os.path.exists(os.path.join(path, 'metadata')): - return False - if not os.path.exists(os.path.join(path, 'metadata', component)): - return False - fd = open(os.path.join(path, 'metadata', component)) - data = fd.readline() - fd.close() - if len(data) == 0: - return False - return data - - def isactivity(path): - ''' Return activity name ''' - activity = hascomponent(path, 'activity') - if not activity: - return False - else: - return activity.split('.')[-1] - - def isdsdir(path): - ''' Only interested if it is a datastore directory ''' - if not os.path.isdir(path): - return False - if not os.path.exists(os.path.join(path, DIROFINTEREST)): - return False - return True - - data = ParseJournal() - activity_list = data.get_sorted() - for a in activity_list: - tw.lc.heap.append(a[0]) - tw.lc.heap.append(a[1]) - - tw.lc.heap.append(activity_list[0][1]) - return diff --git a/pysamples/load_block.py b/pysamples/load_block.py deleted file mode 100644 index a4f680d..0000000 --- a/pysamples/load_block.py +++ /dev/null @@ -1,90 +0,0 @@ -#Copyright (c) 2011,2012 Walter Bender - -# DEPRECATED by load block on extras palette. - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected. - -# Usage: Import this code into a Python (user-definable) block; when -# this code is run, the turtle will create a block at the current -# location of the turtle. The first argument to the Python block -# should be a string containing the name of the desired -# block. Arguments to the block can be passed by expanding the Python -# block to include up to two additional arguments. Note that the -# turtle is moved to the bottom of the block after it is loaded in -# order position another block to the bottom of the stack. - -# The status of these blocks is set to 'load block' - -# For example, try the following to place forward 100, right 90 on the canvas: -# start -# Python(forward, 100) <-- Python load_block.py expanded to two arguments -# Python(right, 90) <-- Python load_block.py expanded to two arguments - - -def myblock(tw, blkname): - ''' Load a block on to the canvas ''' - - from TurtleArt.tapalette import block_names, block_primitives, \ - special_names, content_blocks - from TurtleArt.tautils import find_group - - def make_block(tw, name, x, y, defaults): - tw._new_block(name, x, y, defaults) - - # Find the block we just created and attach it to a stack. - tw.drag_group = None - spr = tw.sprite_list.find_sprite((x, y)) - if spr is not None: - blk = tw.block_list.spr_to_block(spr) - if blk is not None: - tw.drag_group = find_group(blk) - for b in tw.drag_group: - b.status = 'load block' - tw._snap_to_dock() - - # Disassociate new block from mouse. - tw.drag_group = None - return blk.docks[-1][3] - - def find_block(tw, blkname, x, y, defaults=None): - """ Create a new block. It is a bit more work than just calling - _new_block(). We need to: - (1) translate the label name into the internal block name; - (2) 'dock' the block onto a stack where appropriate; and - (3) disassociate the new block from the mouse. """ - - for name in block_names: - # Translate label name into block/prim name. - if blkname in block_names[name]: - if name in block_primitives and \ - block_primitives[name] == name: - return make_block(tw, name, x, y, defaults) - elif name in content_blocks: - return make_block(tw, name, x, y, defaults) - for name in special_names: - # Translate label name into block/prim name. - if blkname in special_names[name]: - return make_block(tw, name, x, y, defaults) - return -1 - - # Place the block at the active turtle (x, y) and move the turtle - # into position to place the next block in the stack. - x, y = tw.active_turtle.get_xy() - if isinstance(blkname, list): - name = blkname[0] - value = blkname[1:] - dy = int(find_block(tw, name, x, y, value)) - else: - name = blkname - if name == 'delete': - for blk in tw.just_blocks(): - if blk.status == 'load block': - blk.type = 'trash' - blk.spr.hide() - dy = 0 - else: - dy = int(find_block(tw, name, x, y)) - - tw.canvas.ypos -= dy - tw.canvas.move_turtle() diff --git a/pysamples/load_file_to_heap.py b/pysamples/load_file_to_heap.py deleted file mode 100644 index 919d6b5..0000000 --- a/pysamples/load_file_to_heap.py +++ /dev/null @@ -1,30 +0,0 @@ -#Copyright (c) 2010-11, Walter Bender, Tony Forster - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected. - -# Usage: Import this code into a Python (user-definable) block; when -# this code is run, the chooser will be opened for selecting a file -# from the GNU/Linux file system. The contents of that file will be -# loaded onto the FILO heap. Data is assumed to be json encoded. - - -def myblock(tw, path): - ''' Load heap from file (GNOME only) ''' - - import os - from TurtleArt.tautils import get_load_name, data_from_file - - if type(path) == float: - path = '' - - if not os.path.exists(path): - path, tw.load_save_folder = get_load_name('.*', tw.load_save_folder) - if path is None: - return - - data = data_from_file(path) - if data is not None: - for val in data: - tw.lc.heap.append(val) - tw.lc.update_label_value('pop', tw.lc.heap[-1]) diff --git a/pysamples/load_journal_entry_to_heap.py b/pysamples/load_journal_entry_to_heap.py deleted file mode 100644 index 3dd3bb5..0000000 --- a/pysamples/load_journal_entry_to_heap.py +++ /dev/null @@ -1,18 +0,0 @@ -#Copyright (c) 2010-11, Walter Bender, Tony Forster - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected. - -# Usage: Import this code into a Python (user-definable) block; when -# this code is run, the chooser will be opened for selecting a file -# from the Journal. The contents of that file will be loaded onto the -# FILO heap. - - -def myblock(tw, x): # ignore second argument - ''' Load heap from journal (Sugar only) ''' - - from TurtleArt.tautils import chooser - - # Choose a datastore object and push data to heap (Sugar only) - chooser(tw.parent, '', tw.lc.push_file_data_to_heap) diff --git a/pysamples/paste_to_heap.py b/pysamples/paste_to_heap.py deleted file mode 100644 index 0371078..0000000 --- a/pysamples/paste_to_heap.py +++ /dev/null @@ -1,21 +0,0 @@ -#Copyright (c) 2010-11, Walter Bender, Tony Forster - -# This procedure is invoked when the user-definable block on the "extras" -# palette is selected. - -# Usage: Import this code into a Python (user-definable) block; when -# this code is run, the contents of the clipboard will be appended to -# the FILO heap. - - -def myblock(tw, x): # ignore second argument - ''' Paste from clipboard to heap ''' - - from gtk import Clipboard - from tautils import data_from_string - - text = Clipboard().wait_for_text() - if text is not None: - for val in data_from_string(text): - tw.lc.heap.append(val) - tw.lc.update_label_value('pop', val) diff --git a/pysamples/push_mouse_event.py b/pysamples/push_mouse_event.py deleted file mode 100644 index 007c092..0000000 --- a/pysamples/push_mouse_event.py +++ /dev/null @@ -1,26 +0,0 @@ -#Copyright (c) 2009-11, Walter Bender, Tony Forster - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected. - -# Usage: Import this code into a Python (user-definable) block; when -# this code is run, the current mouse status will be pushed to the -# FILO heap. If a mouse button event occurs, a y, x, and 1 are pushed -# to the heap. If no button is pressed, 0 is pushed to the heap. - -# To use these data, pop the heap in a compare block to determine if a -# button has been pushed. If a 1 was popped from the heap, pop the x -# and y coordinates. - - -def myblock(tw, x): # ignore second argument - ''' Push mouse event to stack ''' - - if tw.mouse_flag == 1: - # push y first so x will be popped first - tw.lc.heap.append((tw.canvas.height / 2) - tw.mouse_y) - tw.lc.heap.append(tw.mouse_x - (tw.canvas.width / 2)) - tw.lc.heap.append(1) # mouse event - tw.mouse_flag = 0 - else: - tw.lc.heap.append(0) # no mouse event diff --git a/pysamples/push_time.py b/pysamples/push_time.py deleted file mode 100644 index 5f86be4..0000000 --- a/pysamples/push_time.py +++ /dev/null @@ -1,21 +0,0 @@ -#Copyright (c) 2009-11, Walter Bender - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected. - -# Usage: Import this code into a Python (user-definable) block; when -# this code is run, the current hour, minute, and second are pushed to -# the FILO heap. To use these values, pop second, then minute, then -# hour from the FILO. - - -def myblock(tw, x): # ignore second argument - ''' Push hours, minutes, seconds onto the FILO. ''' - - # Use three 'pop' blocks to retrieve these values. - # Note: because we use a FILO (first in, last out heap), - # the first value you pop off of the FILO will be seconds. - - tw.lc.heap.append(localtime().tm_hour) - tw.lc.heap.append(localtime().tm_min) - tw.lc.heap.append(localtime().tm_sec) diff --git a/pysamples/save_heap_to_journal_entry.py b/pysamples/save_heap_to_journal_entry.py deleted file mode 100644 index a06d4d0..0000000 --- a/pysamples/save_heap_to_journal_entry.py +++ /dev/null @@ -1,39 +0,0 @@ -#Copyright (c) 2010-11, Walter Bender, Tony Forster - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected. - -# Usage: Import this code into a Python (user-definable) block; when -# this code is run, the contents of the FILO heap are saved to a -# Journal entry named by the value of the argument to the Python -# block. - - -def myblock(tw, title): - ''' Save heap to journal (Sugar only) ''' - - import os.path - from gettext import gettext as _ - - from sugar.activity import activity - from sugar.datastore import datastore - from sugar import profile - - from TurtleArt.tautils import get_path, data_to_file - - # Save JSON-encoded heap to temporary file - heap_file = os.path.join(get_path(activity, 'instance'), - str(title) + '.txt') - data_to_file(tw.lc.heap, heap_file) - - # Create a datastore object - dsobject = datastore.create() - - # Write any metadata (specifically set the title of the file - # and specify that this is a plain text file). - dsobject.metadata['title'] = str(title) - dsobject.metadata['icon-color'] = profile.get_color().to_string() - dsobject.metadata['mime_type'] = 'text/plain' - dsobject.set_file_path(heap_file) - datastore.write(dsobject) - dsobject.destroy() diff --git a/pysamples/sensors.py b/pysamples/sensors.py deleted file mode 100644 index d95b311..0000000 --- a/pysamples/sensors.py +++ /dev/null @@ -1,33 +0,0 @@ -#Copyright (c) 2010-11, Walter Bender, Tony Forster -# -# This Python block returns with the brightness sensor value in the heap -# a range of parameters can be measured, for example, substitute any of -# these strings for the string in the program below. -# -# /sys/devices/platform/olpc-battery.0/power_supply/olpc-battery/current_now -# /sys/devices/platform/olpc-battery.0/power_supply/olpc-battery/voltage_now -# /sys/devices/platform/dcon/backlight/dcon-bl/actual_brightness - - -def myblock(tw, x): # ignores second argument - import os - - # The light sensor is only available on the XO 1.75 - device = '/sys/devices/platform/olpc-ols.0/level' - - if os.path.exists(device): - fh = open(device) - string = fh.read() - fh.close() - tw.lc.heap.append(float(string)) # append as a float value to the heap - else: - tw.lc.heap.append(-1) - -# If you can work out how to use them... -# accelerometer: /dev/input/event0 ??? -# power button: /dev/input/event1 -# lid switch: /dev/input/event2 -# ebook: /dev/input/event3 -# headphone jack: /dev/input/event7 -# microphone jack: /dev/input/event8 -# rotate, cursor, and game pad keys: /dev/input/event10 diff --git a/pysamples/serial.py b/pysamples/serial.py deleted file mode 100644 index 84772ab..0000000 --- a/pysamples/serial.py +++ /dev/null @@ -1,21 +0,0 @@ -#Copyright (c) 2010-11, Walter Bender, Tony Forster -# -# This Python block writes serial output to a USB port and pushes -# serial input to the heap. -# -# To use this block: -# (1) import this file into a Python Block; -# (2) pass text strings as an argument -# (3) use a Pop Block to retrieve any strings input from serial device. - - -def myblock(tw, x): # x is the string to transmit - import serial # you may need to install this library - - # serial device on USB, 9600 baud - ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1) - - ser.write(str(x)) # send string x - st = ser.read(1000) # read up to 1000 bytes - tw.lc.heap.append(st) # append to heap - ser.close() diff --git a/pysamples/set_rgb.py b/pysamples/set_rgb.py deleted file mode 100644 index b77d9df..0000000 --- a/pysamples/set_rgb.py +++ /dev/null @@ -1,18 +0,0 @@ -#Copyright (c) 2009-11, Walter Bender - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected and expanded to 3 arguments. - -# Usage: Import this code into a Python (user-definable) block. -# First, expand the Python block to reveal three numerics arguments. -# Set these values to the desired red, green, and blue. When the code -# is run, the red, green, and blue values are used to set the pen -# color. - - -def myblock(tw, rgb_array): - ''' Set rgb color from values ''' - - tw.canvas.fgrgb = [(int(rgb_array[0]) % 256), - (int(rgb_array[1]) % 256), - (int(rgb_array[2]) % 256)] diff --git a/pysamples/sinewave.py b/pysamples/sinewave.py deleted file mode 100644 index 4f14c4c..0000000 --- a/pysamples/sinewave.py +++ /dev/null @@ -1,15 +0,0 @@ -#Copyright (c) 2010-11, Tony Forster - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected. - -# Usage: Import this code into a Python (user-definable) block and -# pass a frequency in Hertz to the Python block. A tone will play over -# the speaker at the specified frequency. - - -def myblock(tw, frequency): - ''' Plays a sound at frequency frequency ''' - - import os - os.system('speaker-test -t sine -l 1 -f %d' % (int(frequency))) diff --git a/pysamples/speak.py b/pysamples/speak.py deleted file mode 100644 index 30762a9..0000000 --- a/pysamples/speak.py +++ /dev/null @@ -1,57 +0,0 @@ -#Copyright (c) 2009-11, Walter Bender, Tony Forster - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected. - -# Usage: Import this code into a Python (user-definable) block and -# pass a string to be read by the voice synthesizer. If a second -# argument is passed, by expanding the Python block, it is used to specify -# the pitch level of the speaker. Valid range is 0 to 99. - - -def myblock(tw, arg): - ''' Text to speech ''' - - TABLE = {'af': 'afrikaans', 'cy': 'welsh-test', 'el': 'greek', - 'es': 'spanish', 'hi': 'hindi-test', 'hy': 'armenian', - 'ku': 'kurdish', 'mk': 'macedonian-test', 'pt': 'brazil', - 'sk': 'slovak', 'sw': 'swahili', 'bs': 'bosnian', 'da': 'danish', - 'en': 'english', 'fi': 'finnish', 'hr': 'croatian', - 'id': 'indonesian-test', 'la': 'latin', 'nl': 'dutch-test', - 'sq': 'albanian', 'ta': 'tamil', 'vi': 'vietnam-test', - 'ca': 'catalan', 'de': 'german', 'eo': 'esperanto', - 'fr': 'french', 'hu': 'hungarian', 'is': 'icelandic-test', - 'lv': 'latvian', 'no': 'norwegian', 'ro': 'romanian', - 'sr': 'serbian', 'zh': 'Mandarin', 'cs': 'czech', 'it': 'italian', - 'pl': 'polish', 'ru': 'russian_test', 'sv': 'swedish', - 'tr': 'turkish'} - import os - - pitch = None - if type(arg) == type([]): - text = arg[0] - if len(arg) > 1: - pitch = int(arg[1]) - if pitch > 99: - pitch = 99 - elif pitch < 0: - pitch = 0 - else: - text = arg - - # Turtle Art numbers are passed as float, - # but they may be integer values. - if type(text) == float and int(text) == text: - text = int(text) - - lang = os.environ['LANG'][0:2] - if lang in TABLE: - language_option = '-v ' + TABLE[lang] - else: - language_option = '' - if pitch is None: - os.system('espeak %s "%s" --stdout | aplay' % (language_option, - text)) - else: - os.system('espeak %s "%s" -p "%s" --stdout | aplay' % ( - language_option, text, pitch)) diff --git a/pysamples/svg_end_group.py b/pysamples/svg_end_group.py deleted file mode 100644 index 3f5f495..0000000 --- a/pysamples/svg_end_group.py +++ /dev/null @@ -1,21 +0,0 @@ -#Copyright (c) 2009-11, Walter Bender - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected and expanded to 3 arguments. - -# Usage: Import this code into a Python (user-definable) block. -# In using SVG, it is sometimes useful to divide your drawing into -# groups of elements. You can do that by inserting <g> </g> around -# sections of your code. -# -# Place the svg_start_group.py block at the point in your program -# where you'd like to start a group in your SVG output. -# -# Be sure to use the corresponding svg_end_group.py block to close -# the SVG group definition. - - -def myblock(tw, x): - ''' Add end group to SVG output ''' - - tw.svg_string += '</g>' diff --git a/pysamples/svg_start_group.py b/pysamples/svg_start_group.py deleted file mode 100644 index e3332bf..0000000 --- a/pysamples/svg_start_group.py +++ /dev/null @@ -1,21 +0,0 @@ -#Copyright (c) 2009-11, Walter Bender - -# This procedure is invoked when the user-definable block on the -# "extras" palette is selected and expanded to 3 arguments. - -# Usage: Import this code into a Python (user-definable) block. -# In using SVG, it is sometimes useful to divide your drawing into -# groups of elements. You can do that by inserting <g> </g> around -# sections of your code. -# -# Place the svg_start_group.py block at the point in your program -# where you'd like to start a group in your SVG output. -# -# Be sure to use the corresponding svg_end_group.py block to close -# the SVG group definition. - - -def myblock(tw, x): - ''' Add start group to SVG output ''' - - tw.svg_string += '<g>' diff --git a/pysamples/ta-stats.py b/pysamples/ta-stats.py deleted file mode 100644 index 9a80c04..0000000 --- a/pysamples/ta-stats.py +++ /dev/null @@ -1,172 +0,0 @@ -# Copyright (c) 2012, Walter Bender - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -def myblock(tw, x): # ignore second argument - ''' Load journal stats to heap (Sugar only) ''' - - import os - import glob - - _DIROFINTEREST = 'datastore' - - class ParseJournal(): - ''' Simple parser of datastore for turtle art entries ''' - - def __init__(self): - self._score = [] - - homepath = os.environ['HOME'] - for path in glob.glob(os.path.join(homepath, '.sugar', '*')): - if isdsdir(path): - dsobjdirs = glob.glob( - os.path.join(path, _DIROFINTEREST, '??')) - for dsobjdir in dsobjdirs: - dsobjs = glob.glob(os.path.join(dsobjdir, '*')) - for dsobj in dsobjs: - if not isactivity(dsobj) == 'TurtleArtActivity': - continue - if hascomponent(dsobj, 'mime_type') != \ - 'application/x-turtle-art': - continue - score = hasturtleblocks(dsobj) - if score: - self._score.append(score) - - def hascomponent(path, component): - ''' Return metadata attribute, if any ''' - if not os.path.exists(os.path.join(path, 'metadata')): - return False - if not os.path.exists(os.path.join(path, 'metadata', component)): - return False - fd = open(os.path.join(path, 'metadata', component)) - data = fd.readline() - fd.close() - if len(data) == 0: - return False - return data - - def isactivity(path): - ''' Return activity name ''' - activity = hascomponent(path, 'activity') - if not activity: - return False - else: - return activity.split('.')[-1] - - def isdsdir(path): - ''' Only interested if it is a datastore directory ''' - if not os.path.isdir(path): - return False - if not os.path.exists(os.path.join(path, _DIROFINTEREST)): - return False - return True - - TACAT = {'clean': 'forward', 'forward': 'forward', 'back': 'forward', - 'left': 'forward', 'right': 'forward', 'arc': 'arc', - 'xcor': 'coord', 'ycor': 'coord', 'heading': 'coord', - 'setxy2': 'setxy', 'seth': 'setxy', 'penup': 'pen', - 'setpensize': 'pen', 'setcolor': 'pen', 'pensize': 'pen', - 'color': 'pen', 'setshade': 'pen', 'setgray': 'pen', - 'gray': 'pen', 'fillscreen': 'pen', 'startfill': 'fill', - 'stopfill': 'fill', 'plus2': 'number', 'minus2': 'number', - 'product2': 'number', 'division2': 'number', - 'pendown': 'pen', 'shade': 'pen', 'remainder2': 'number', - 'sqrt': 'number', 'identity2': 'number', 'and2': 'boolean', - 'or2': 'boolean', 'not': 'boolean', 'greater2': 'boolean', - 'less2': 'boolean', 'equal2': 'boolean', 'random': 'random', - 'repeat': 'repeat', 'forever': 'repeat', 'if': 'ifthen', - 'ifelse': 'ifthen', 'while': 'ifthen', 'until': 'ifthen', - 'hat': 'action', 'stack': 'action', 'storein': 'box', - 'luminance': 'sensor', 'mousex': 'sensor', 'mousey': 'sensor', - 'mousebutton2': 'sensor', 'keyboard': 'sensor', - 'readpixel': 'sensor', 'see': 'sensor', 'time': 'sensor', - 'sound': 'sensor', 'volume': 'sensor', 'pitch': 'sensor', - 'resistance': 'sensor', 'voltage': 'sensor', 'video': 'media', - 'wait': 'media', 'camera': 'media', 'journal': 'media', - 'audio': 'media', 'show': 'media', 'setscale': 'media', - 'savepix': 'media', 'savesvg': 'media', 'mediawait': 'media', - 'mediapause': 'media', 'mediastop': 'media', 'mediaplay': 'media', - 'speak': 'media', 'sinewave': 'media', 'description': 'media', - 'push': 'extras', 'pop': 'extras', 'printheap': 'extras', - 'clearheap': 'extras', 'isheapempty2': 'extras', 'chr': 'extras', - 'int': 'extras', 'myfunction': 'python', 'userdefined': 'python', - 'box': 'box', 'kbinput': 'sensor', - 'loadblock': 'python', 'loadpalette': 'python'} - TAPAL = {'forward': 'turtlep', 'arc': 'turtlep', 'coord': 'turtlep', - 'setxy': 'turtlep', 'pen': 'penp', 'fill': 'penp', - 'random': 'numberp', 'boolean': 'numberp', 'repeat': 'flowp', - 'ifthen': 'flowp', 'action': 'boxp', 'box': 'boxp', - 'sensor': 'sensorp', 'media': 'mediap', 'extras': 'extrasp', - 'number': 'numberp', 'python': 'extrasp'} - TASCORE = {'forward': 3, 'arc': 3, 'setxy': 2.5, 'coord': 4, 'turtlep': 5, - 'pen': 2.5, 'fill': 2.5, 'penp': 5, - 'number': 2.5, 'boolean': 2.5, 'random': 2.5, 'numberp': 0, - 'repeat': 2.5, 'ifthen': 7.5, 'flowp': 10, - 'box': 7.5, 'action': 7.5, 'boxp': 0, - 'media': 5, 'mediap': 0, - 'python': 5, 'extras': 5, 'extrasp': 0, - 'sensor': 5, 'sensorp': 0} - PALS = ['turtlep', 'penp', 'numberp', 'flowp', 'boxp', 'sensorp', 'mediap', - 'extrasp'] - - def hasturtleblocks(path): - ''' Parse turtle block data and generate score based on rubric ''' - - if not os.path.exists(os.path.join(path, 'data')): - return None - fd = open(os.path.join(path, 'data')) - blocks = [] - # block name is second token in each line - for line in fd: - tokens = line.split(',') - if len(tokens) > 1: - token = tokens[1].strip('" [') - blocks.append(token) - - score = [] - for i in range(len(PALS)): - score.append(0) - cats = [] - pals = [] - - for b in blocks: - if b in TACAT: - if not TACAT[b] in cats: - cats.append(TACAT[b]) - for c in cats: - if c in TAPAL: - if not TAPAL[c] in pals: - pals.append(TAPAL[c]) - - for c in cats: - if c in TASCORE: - score[PALS.index(TAPAL[c])] += TASCORE[c] - - for p in pals: - if p in TASCORE: - score[PALS.index(p)] += TASCORE[p] - - return score - - data = ParseJournal() - n = min(40, len(data._score) / len(PALS)) - for i in range(n): - for j in range(len(PALS)): - tw.lc.heap.append(data._score[(n - i - 1)][len(PALS) - j - 1]) - - tw.lc.heap.append(n) - return |