Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPootle daemon <pootle@pootle.sugarlabs.org>2012-11-09 05:30:54 (GMT)
committer Pootle daemon <pootle@pootle.sugarlabs.org>2012-11-09 05:30:54 (GMT)
commit49a33a2d51980142613c03ca22b1bf7c5666b6ff (patch)
tree32d9ebad28cc39ad628ad6176373bdfcf0c43bda
parent41e93a0c5fc7db14553797e40acfd475f890f0c3 (diff)
parent4feae65e6fdd83f5ef3a395e6cd2f535ca6c1653 (diff)
Merge branch 'master' of git.sugarlabs.org:turtleart/mainline
-rw-r--r--TurtleArt/talogo.py3
-rw-r--r--TurtleArt/tawindow.py24
-rw-r--r--TurtleArtActivity.py8
-rw-r--r--plugins/audio_sensors/audio_sensors.py97
-rwxr-xr-xturtleblocks.py20
5 files changed, 99 insertions, 53 deletions
diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py
index 71561de..7b84e9e 100644
--- a/TurtleArt/talogo.py
+++ b/TurtleArt/talogo.py
@@ -155,8 +155,7 @@ class LogoCode:
def stop_logo(self):
""" Stop logo is called from the Stop button on the toolbar """
self.step = _just_stop()
- for plugin in self.tw._plugins:
- plugin.stop()
+ self.tw.stop_plugins()
if self.tw.gst_available:
from tagplay import stop_media
stop_media(self)
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index e0a9106..019b345 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -95,7 +95,6 @@ class TurtleArtWindow():
self._loaded_project = ''
self._sharing = False
self.parent = parent
- self.window_init_complete = False
self.turtle_canvas = turtle_canvas
self.send_event = None # method to send events over the network
self.gst_available = GST_AVAILABLE
@@ -263,7 +262,7 @@ class TurtleArtWindow():
CONSTANTS['height'] = int(self.canvas.height / self.coord_scale)
self._icon_paths = [os.path.join(self.path, 'icons')]
- self._plugins = []
+ self.turtleart_plugins = []
self._init_plugins()
self.lc = LogoCode(self)
@@ -283,7 +282,6 @@ class TurtleArtWindow():
show=True)
self.saved_pictures = []
self.block_operation = ''
- self.window_init_complete = True
def _set_screen_dpi(self):
dpi = get_screen_dpi()
@@ -329,7 +327,7 @@ class TurtleArtWindow():
# NOTE: When debugging plugins, it may be useful to not trap errors
try:
exec f in globals(), plugins
- self._plugins.append(plugins.values()[0](self))
+ self.turtleart_plugins.append(plugins.values()[0](self))
debug_output('Successfully importing %s' % (plugin_class),
self.running_sugar)
# Add the icon dir to the icon_theme search path
@@ -356,44 +354,44 @@ class TurtleArtWindow():
self._get_plugin_home())
if plugin_name in list_plugins:
number_plugin = list_plugins.index(plugin_name)
- return self._plugins[number_plugin]
+ return self.turtleart_plugins[number_plugin]
else:
return None
def _setup_plugins(self):
''' Initial setup -- called just once. '''
- for plugin in self._plugins:
+ for plugin in self.turtleart_plugins:
plugin.setup()
def _start_plugins(self):
''' Start is called everytime we execute blocks. '''
- for plugin in self._plugins:
+ for plugin in self.turtleart_plugins:
plugin.start()
- def _stop_plugins(self):
+ def stop_plugins(self):
''' Stop is called whenever we stop execution. '''
- for plugin in self._plugins:
+ for plugin in self.turtleart_plugins:
plugin.stop()
def clear_plugins(self):
''' Clear is called from the clean block and erase button. '''
- for plugin in self._plugins:
+ for plugin in self.turtleart_plugins:
if hasattr(plugin, 'clear'):
plugin.clear()
def background_plugins(self):
''' Background is called when we are pushed to the background. '''
- for plugin in self._plugins:
+ for plugin in self.turtleart_plugins:
plugin.goto_background()
def foreground_plugins(self):
''' Foreground is called when we are return from the background. '''
- for plugin in self._plugins:
+ for plugin in self.turtleart_plugins:
plugin.return_to_foreground()
def quit_plugins(self):
''' Quit is called upon program exit. '''
- for plugin in self._plugins:
+ for plugin in self.turtleart_plugins:
plugin.quit()
def _setup_events(self):
diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py
index 5ea2213..0e6880a 100644
--- a/TurtleArtActivity.py
+++ b/TurtleArtActivity.py
@@ -78,6 +78,9 @@ class TurtleArtActivity(activity.Activity):
except dbus.exceptions.DBusException, e:
_logger.error(str(e))
+ self.tw = None
+ self.init_complete = False
+
self._check_ver_change(get_path(activity, 'data'))
self.connect("notify::active", self._notify_active_cb)
@@ -110,6 +113,7 @@ class TurtleArtActivity(activity.Activity):
self.metadata['activity count'] = str(count)
self._defer_palette_move = False
+ self.init_complete = True
# Activity toolbar callbacks
def do_save_as_logo_cb(self, button):
@@ -1004,7 +1008,7 @@ Plugin section of plugin.info file.')
create_palette.append(False)
_logger.debug('Initializing plugin...')
self.tw.init_plugin(plugin_name)
- self.tw._plugins[-1].setup()
+ self.tw.turtleart_plugins[-1].setup()
self.tw.load_media_shapes()
for i, palette_name in enumerate(palette_name_list):
if create_palette[i]:
@@ -1073,7 +1077,7 @@ in order to use the plugin.'))
def read_file(self, file_path, run_it=False, plugin=False):
''' Open a project or plugin and then run it. '''
- if hasattr(self, 'tw'):
+ if hasattr(self, 'tw') and self.tw is not None:
_logger.debug('Read file: %s' % (file_path))
# Could be a plugin or deprecated gtar or tar file...
if plugin or file_path.endswith(('.gtar', '.tar', '.tar.gz')):
diff --git a/plugins/audio_sensors/audio_sensors.py b/plugins/audio_sensors/audio_sensors.py
index 5a2a001..f904f17 100644
--- a/plugins/audio_sensors/audio_sensors.py
+++ b/plugins/audio_sensors/audio_sensors.py
@@ -135,17 +135,17 @@ class Audio_sensors(Plugin):
primitive_dictionary['voltage'] = self.prim_voltage
if self.hw in [XO1, XO15, XO175, XO30] and self._status:
if self.hw == XO1:
- self.voltage_gain = 0.00002225
- self.voltage_bias = 1.140
+ self.voltage_gain = 0.000022
+ self.voltage_bias = 1.14
elif self.hw == XO15:
- self.voltage_gain = -0.0001471
- self.voltage_bias = 1.695
- elif self.hw == XO175:
- self.voltage_gain = 0.000051
- self.voltage_bias = 1.372
+ self.voltage_gain = -0.00015
+ self.voltage_bias = 1.70
+ elif self.hw == XO175: # recalibrate in light of #3675?
+ self.voltage_gain = 0.000071
+ self.voltage_bias = 0.55
else: # XO 3.0
- self.voltage_gain = 0.00007692
- self.voltage_bias = 0.719
+ self.voltage_gain = 0.000077
+ self.voltage_bias = 0.72
palette.add_block('resistance',
style='box-style',
label=_('resistance'),
@@ -295,9 +295,18 @@ class Audio_sensors(Plugin):
# Block primitives used in talogo
def prim_volume(self, channel):
- ''' return mic in value '''
if not self._status:
return 0
+ # Return average of both channels if sampling in stereo
+ if self._channels == 2:
+ chan0 = self._prim_volume(0)
+ chan1 = self._prim_volume(1)
+ return (chan0 + chan1) / 2
+ else:
+ return self._prim_volume(0)
+
+ def _prim_volume(self, channel):
+ ''' return mic in value '''
buf = self.ringbuffer[channel].read(None, self.input_step)
if len(buf) > 0:
volume = float(_avg(buf, abs_value=True))
@@ -307,9 +316,18 @@ class Audio_sensors(Plugin):
return 0
def prim_sound(self, channel):
- ''' return raw mic in value '''
if not self._status:
return 0
+ # Return average of both channels if sampling in stereo
+ if self._channels == 2:
+ chan0 = self._prim_sound(0)
+ chan1 = self._prim_sound(1)
+ return (chan0 + chan1) / 2
+ else:
+ return self._prim_sound(0)
+
+ def _prim_sound(self, channel):
+ ''' return raw mic in value '''
buf = self.ringbuffer[channel].read(None, self.input_step)
if len(buf) > 0:
sound = float(buf[0])
@@ -319,9 +337,18 @@ class Audio_sensors(Plugin):
return 0
def prim_pitch(self, channel):
- ''' return index of max value in fft of mic in values '''
if not PITCH_AVAILABLE or not self._status:
return 0
+ # Return average of both channels if sampling in stereo
+ if self._channels == 2:
+ chan0 = self._prim_pitch(0)
+ chan1 = self._prim_pitch(1)
+ return (chan0 + chan1) / 2
+ else:
+ return self._prim_pitch(0)
+
+ def _prim_pitch(self, channel):
+ ''' return index of max value in fft of mic in values '''
buf = self.ringbuffer[channel].read(None, self.input_step)
if len(buf) > 0:
buf = rfft(buf)
@@ -344,15 +371,21 @@ class Audio_sensors(Plugin):
if not self.hw in [XO1, XO15, XO175, XO30] or not self._status:
return 0
if self.hw == XO1:
- return self._prim_resistance(0)
+ resistance = self._prim_resistance(0)
+ self._update_resistance_labels(0, resistance)
+ return resistance
elif self.hw == XO15:
- return self._prim_resistance(channel)
+ resistance = self._prim_resistance(channel)
+ self._update_resistance_labels(channel, resistance)
+ return resistance
# FIXME: For ARM (XO175, XO4) channel assignment is seemingly
# random (#3675), so sum both channels
else:
chan0 = self._prim_resistance(0)
chan1 = self._prim_resistance(1)
- return chan0 + chan1
+ resistance = (chan0 + chan1) / 2.
+ self._update_resistance_labels(0, resistance)
+ return resistance
def _prim_resistance(self, channel):
''' return resistance sensor value '''
@@ -370,7 +403,7 @@ class Audio_sensors(Plugin):
resistance = 420000000
elif self.hw == XO175:
if avg_buf < 30700:
- resistance = (180000000 / (30700 - avg_buf)) - 3150
+ resistance = .12 * ((180000000 / (30700 - avg_buf)) - 3150)
else:
resistance = 999999999
else: # XO 3.0
@@ -378,29 +411,37 @@ class Audio_sensors(Plugin):
resistance = (46000000 / (30514 - avg_buf)) - 1150
else:
resistance = 999999999
- if channel == 0:
- self._parent.lc.update_label_value('resistance', resistance)
- else:
- self._parent.lc.update_label_value('resistance2', resistance)
if resistance < 0:
resistance = 0
return resistance
else:
return 0
+ def _update_resistance_labels(self, channel, resistance):
+ if channel == 0:
+ self._parent.lc.update_label_value('resistance', resistance)
+ else:
+ self._parent.lc.update_label_value('resistance2', resistance)
+
def prim_voltage(self, channel):
if not self.hw in [XO1, XO15, XO175, XO30] or not self._status:
return 0
if self.hw == XO1:
- return self._prim_voltage(0)
+ voltage = self._prim_voltage(0)
+ self._update_voltage_labels(0, voltage)
+ return voltage
elif self.hw == XO15:
- return self._prim_voltage(channel)
+ voltage = self._prim_voltage(channel)
+ self._update_voltage_labels(channel, voltage)
+ return voltage
# FIXME: For ARM (XO175, XO4) channel assignment is seemingly
# random (#3675), so sum both channels
else:
chan0 = self._prim_voltage(0)
chan1 = self._prim_voltage(1)
- return chan0 + chan1
+ voltage = (chan0 + chan1) / 2.
+ self._update_voltage_labels(0, voltage)
+ return voltage
def _prim_voltage(self, channel):
''' return voltage sensor value '''
@@ -408,10 +449,12 @@ class Audio_sensors(Plugin):
if len(buf) > 0:
# See <http://bugs.sugarlabs.org/ticket/552#comment:7>
voltage = float(_avg(buf)) * self.voltage_gain + self.voltage_bias
- if channel == 0:
- self._parent.lc.update_label_value('voltage', voltage)
- else:
- self._parent.lc.update_label_value('voltage2', voltage)
return voltage
else:
return 0
+
+ def _update_voltage_labels(self, channel, voltage):
+ if channel == 0:
+ self._parent.lc.update_label_value('voltage', voltage)
+ else:
+ self._parent.lc.update_label_value('voltage2', voltage)
diff --git a/turtleblocks.py b/turtleblocks.py
index 5c536a2..663db59 100755
--- a/turtleblocks.py
+++ b/turtleblocks.py
@@ -89,7 +89,7 @@ class TurtleMain():
self._init_vars()
self._parse_command_line()
self._ensure_sugar_paths()
- self._plugins = []
+ self._gnome_plugins = []
if self._output_png:
# Outputing to file, so no need for a canvas
@@ -98,10 +98,10 @@ class TurtleMain():
self._draw_and_quit()
else:
self._read_initial_pos()
- self._init_plugins()
+ self._init_gnome_plugins()
self._setup_gtk()
self._build_window()
- self._run_plugins()
+ self._run_gnome_plugins()
self._start_gtk()
def get_config_home(self):
@@ -125,7 +125,7 @@ class TurtleMain():
plugin_files.append(c.split('.')[0])
return plugin_files
- def _init_plugins(self):
+ def _init_gnome_plugins(self):
''' Try launching any plugins we may have found. '''
for p in self._get_plugin_candidates(self._get_gnome_plugin_home()):
P = p.capitalize()
@@ -134,13 +134,13 @@ class TurtleMain():
plugin = {}
try:
exec f in globals(), plugin
- self._plugins.append(plugin.values()[0](self))
+ self._gnome_plugins.append(plugin.values()[0](self))
except ImportError, e:
print 'failed to import %s: %s' % (P, str(e))
- def _run_plugins(self):
+ def _run_gnome_plugins(self):
''' Tell the plugin about the TurtleWindow instance. '''
- for p in self._plugins:
+ for p in self._gnome_plugins:
p.set_tw(self.tw)
def _mkdir_p(self, path):
@@ -166,6 +166,7 @@ class TurtleMain():
''' Get a main window set up. '''
self.win.connect('configure_event', self.tw.update_overlay_position)
self.tw.parent = self.win
+ self.init_complete = True
if self._ta_file is None:
self.tw.load_start()
else:
@@ -212,6 +213,7 @@ class TurtleMain():
self.current_palette = 0
self.scale = 2.0
self.tw = None
+ self.init_complete = False
def _parse_command_line(self):
''' Try to make sense of the command-line arguments. '''
@@ -408,7 +410,7 @@ class TurtleMain():
menu_bar.append(turtle_menu)
# Add menus for plugins
- for p in self._plugins:
+ for p in self._gnome_plugins:
menu_bar.append(p.get_menu())
return menu_bar
@@ -421,7 +423,7 @@ class TurtleMain():
else:
if self.tw.project_has_changed():
self._show_save_dialog(False)
- for plugin in self.tw._plugins:
+ for plugin in self.tw.turtleart_plugins:
if hasattr(plugin, 'quit'):
plugin.quit()
gtk.main_quit()