Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgnacio Rodriguez <ignacio@sugarlabs.org>2013-12-18 21:47:28 (GMT)
committer Ignacio Rodriguez <ignacio@sugarlabs.org>2013-12-18 21:47:28 (GMT)
commit776cb43401b93cbbcac951271a9f95d5ea2f5bd0 (patch)
treef4c86a93395f08a5974e78f8ac742c6c1881eedc
parent025fefbf922767ecf2c2a73ce825aa19d3f50faa (diff)
gtk3 port initial version - 'draw audio' don't workHEADmaster
-rw-r--r--audiograb.py58
-rw-r--r--config.py3
-rw-r--r--drawwaveform.py190
-rw-r--r--journal.py9
-rw-r--r--measure.py81
-rw-r--r--sensor_toolbar.py77
-rwxr-xr-xsetup.py2
-rw-r--r--toolbar_side.py45
-rw-r--r--tuning_toolbar.py53
9 files changed, 281 insertions, 237 deletions
diff --git a/audiograb.py b/audiograb.py
index 1253d6c..a7ec6ca 100644
--- a/audiograb.py
+++ b/audiograb.py
@@ -6,6 +6,7 @@
# Copyright (C) 2009, Benjamin Berg, Sebastian Berg
# Copyright (C) 2009, Sayamindu Dasgupta
# Copyright (C) 2010, Sascha Silbe
+# Copyright (C) 2013, Ignacio Rodriguez
#
# 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
@@ -17,10 +18,10 @@
# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
-import pygst
-pygst.require("0.10")
-import gst
-import gst.interfaces
+import gi
+gi.require_version('Gst', '1.0')
+
+from gi.repository import Gst
from numpy import fromstring
import subprocess
import traceback
@@ -46,6 +47,7 @@ SENSOR_AC_BIAS = 'sound'
SENSOR_DC_NO_BIAS = 'voltage'
SENSOR_DC_BIAS = 'resistance'
+Gst.init([])
def _avg(array, abs_value=False):
''' Calc. the average value of an array '''
@@ -111,7 +113,8 @@ class AudioGrab():
self._labels_available = True # Query controls for device names
self._display_counter = DISPLAY_DUTY_CYCLE
- self._query_mixer()
+ # Fixme, ¿no hay alsamixer?
+ #self._query_mixer()
# If Channels was not found in the Capture controller, guess.
if self.channels is None:
log.warning('Guessing there are 2 channels')
@@ -137,39 +140,41 @@ class AudioGrab():
self.pads = []
self.queue = []
self.fakesink = []
- self.pipeline = gst.Pipeline('pipeline')
- self.alsasrc = gst.element_factory_make('alsasrc', 'alsa-source')
+ self.pipeline = Gst.Pipeline.new('pipeline')
+ self.alsasrc = Gst.ElementFactory.make('alsasrc', 'alsa-source')
self.pipeline.add(self.alsasrc)
- self.caps1 = gst.element_factory_make('capsfilter', 'caps1')
+ self.caps1 = Gst.ElementFactory.make('capsfilter', 'caps1')
self.pipeline.add(self.caps1)
caps_str = 'audio/x-raw-int,rate=%d,channels=%d,depth=16' % (
RATE, self.channels)
- self.caps1.set_property('caps', gst.caps_from_string(caps_str))
+ self.caps1.set_property('caps', Gst.Caps.from_string(caps_str))
if self.channels == 1:
- self.fakesink.append(gst.element_factory_make('fakesink', 'fsink'))
+ self.fakesink.append(Gst.ElementFactory.make('fakesink', 'fsink'))
self.pipeline.add(self.fakesink[0])
self.fakesink[0].connect('handoff', self.on_buffer, 0)
self.fakesink[0].set_property('signal-handoffs', True)
- gst.element_link_many(self.alsasrc, self.caps1, self.fakesink[0])
+ # Fixme: ¿Como linkeo todos?
+ #gst.element_link_many(self.alsasrc, self.caps1, self.fakesink[0])
else:
if not hasattr(self, 'splitter'):
- self.splitter = gst.element_factory_make('deinterleave')
+ self.splitter = Gst.ElementFactory.make('deinterlace', 'deinterlace')
self.pipeline.add(self.splitter)
self.splitter.set_properties('keep-positions=true', 'name=d')
self.splitter.connect('pad-added', self._splitter_pad_added)
- gst.element_link_many(self.alsasrc, self.caps1, self.splitter)
+ # Fixme: ¿Como linkeo todo?
+ #gst.element_link_many(self.alsasrc, self.caps1, self.splitter)
for i in range(self.channels):
- self.queue.append(gst.element_factory_make('queue'))
+ self.queue.append(Gst.ElementFactory.make('queue', 'queue%d' % i))
self.pipeline.add(self.queue[i])
- self.fakesink.append(gst.element_factory_make('fakesink'))
+ self.fakesink.append(Gst.ElementFactory.make('fakesink', 'fsink%d' % i))
self.pipeline.add(self.fakesink[i])
self.fakesink[i].connect('handoff', self.on_buffer, i)
self.fakesink[i].set_property('signal-handoffs', True)
def _query_mixer(self):
- self._mixer = gst.element_factory_make('alsamixer')
- rc = self._mixer.set_state(gst.STATE_PAUSED)
- assert rc == gst.STATE_CHANGE_SUCCESS
+ self._mixer = Gst.ElementFactory.make('alsamixer', 'alsamixer')
+ rc = self._mixer.set_state(Gst.State.PAUSED)
+ assert rc == Gst.State.CHANGE_SUCCESS
# Query the available controls
tracks_list = self._mixer.list_tracks()
@@ -384,13 +389,13 @@ class AudioGrab():
def start_sound_device(self):
'''Start or Restart grabbing data from the audio capture'''
- gst.event_new_flush_start()
- self.pipeline.set_state(gst.STATE_PLAYING)
+ Gst.Event.new_flush_start()
+ self.pipeline.set_state(Gst.State.PLAYING)
def stop_sound_device(self):
'''Stop grabbing data from capture device'''
- gst.event_new_flush_stop()
- self.pipeline.set_state(gst.STATE_NULL)
+ Gst.Event.new_flush_stop(True)
+ self.pipeline.set_state(Gst.State.NULL)
def set_logging_params(self, start_stop=False, interval=0,
screenshot=True):
@@ -428,12 +433,14 @@ class AudioGrab():
self.pause_grabbing()
caps_str = 'audio/x-raw-int,rate=%d,channels=%d,depth=16' % (
sr, self.channels)
- self.caps1.set_property('caps', gst.caps_from_string(caps_str))
+ self.caps1.set_property('caps', Gst.Caps.from_string(caps_str))
self.resume_grabbing()
def get_sampling_rate(self):
''' Gets the sampling rate of the capture device '''
- return int(self.caps1.get_property('caps')[0]['rate'])
+ rate = self.caps1.get_property('caps').to_string().split(',')
+ rate = rate[1].replace('rate=(int)', '')
+ return int(rate)
def start_grabbing(self):
'''Called right at the start of the Activity'''
@@ -624,7 +631,8 @@ class AudioGrab():
integer between 0 and 100 and is an indicative of the
percentage 0 to 100%'''
if self._labels_available:
- return self._get_volume(self._master_control, 'master')
+ return 100
+ #return self._get_volume(self._master_control, 'master')
else:
output = check_output(['amixer', 'get', 'Master'],
'amixer: Could not get Master volume')
diff --git a/config.py b/config.py
index f952b7a..8c834d1 100644
--- a/config.py
+++ b/config.py
@@ -2,6 +2,7 @@
# Copyright (C) 2007, Arjun Sarwal
# Copyright (C) 2009-11 Walter Bender
# Copyright (C) 2009, Benjamin Berg, Sebastian Berg
+# Copyright (C) 2013, Ignacio Rodriguez
#
# 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
@@ -19,7 +20,7 @@ Global configuration for Measure.
import os
try:
- from sugar.activity import activity
+ from sugar3.activity import activity
MEASURE_ROOT = activity.get_bundle_path()
SUGAR = True
except ImportError:
diff --git a/drawwaveform.py b/drawwaveform.py
index c42a142..494830c 100644
--- a/drawwaveform.py
+++ b/drawwaveform.py
@@ -15,7 +15,8 @@
# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
-import gtk
+from gi.repository import Gtk
+from gi.repository import Gdk
from math import floor, ceil
from numpy import array, where, float64, multiply, fft, arange, blackman
from ringbuffer import RingBuffer1d
@@ -33,7 +34,7 @@ logging.basicConfig()
from gettext import gettext as _
-class DrawWaveform(gtk.DrawingArea):
+class DrawWaveform(Gtk.DrawingArea):
""" Handles all the drawing of waveforms """
__gtype_name__ = "MeasureDrawWaveform"
@@ -46,10 +47,10 @@ class DrawWaveform(gtk.DrawingArea):
def __init__(self, activity, input_frequency=RATE, channels=1):
""" Initialize drawing area and scope parameter """
- gtk.DrawingArea.__init__(self)
+ Gtk.DrawingArea.__init__(self)
- self.add_events(gtk.gdk.BUTTON_PRESS_MASK | \
- gtk.gdk.PROPERTY_CHANGE_MASK)
+ self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | \
+ Gdk.EventMask.PROPERTY_CHANGE_MASK)
self.activity = activity
self._input_freq = input_frequency
@@ -63,7 +64,7 @@ class DrawWaveform(gtk.DrawingArea):
self.bias = [] # vertical position fine-tuning from slider
self.active = False
- self._redraw_atom = gtk.gdk.atom_intern('MeasureRedraw')
+ self._redraw_atom = Gdk.atom_intern('MeasureRedraw', False)
self.buffers = array([])
self.main_buffers = array([])
@@ -105,7 +106,6 @@ class DrawWaveform(gtk.DrawingArea):
self.scaleY = ""
self._back_surf = None
- self.expose_event_id = self.connect('expose_event', self._expose)
self.pr_time = 0
self.MAX_GRAPHS = MAX_GRAPHS # Maximum simultaneous graphs
@@ -142,7 +142,7 @@ class DrawWaveform(gtk.DrawingArea):
self.Ystart.append(50)
self.Xend.append(1000)
self.Yend.append(500)
- self.type .append(0)
+ self.type.append(0)
self.color.append('#FF0000')
self.source.append(0)
self.visibility.append(True)
@@ -194,16 +194,12 @@ class DrawWaveform(gtk.DrawingArea):
def set_context_on(self):
""" Return to an active state (context on) """
- if not self.context:
- self.handler_unblock(self.expose_event_id)
self.context = True
self._indirect_queue_draw()
return
def set_context_off(self):
""" Return to an inactive state (context off) """
- if self.context:
- self.handler_block(self.expose_event_id)
self.context = False
self._indirect_queue_draw()
return
@@ -224,17 +220,18 @@ class DrawWaveform(gtk.DrawingArea):
def do_size_allocate(self, allocation):
""" Allocate a drawing area for the plot """
- gtk.DrawingArea.do_size_allocate(self, allocation)
+ Gtk.DrawingArea.do_size_allocate(self, allocation)
self._update_mode()
- if self.window is not None:
+ if self.get_window() is not None:
self._create_background_pixmap()
return
def _indirect_queue_draw(self):
- if self.window is None:
+ if self.get_window() is None:
return
- self.window.property_change(self._redraw_atom, self._redraw_atom,
- 32, gtk.gdk.PROP_MODE_REPLACE, [])
+ # FIXME: ¿Como se hace?
+ #self.get_window().property_change(self._redraw_atom, self._redraw_atom,
+ # 32, Gdk.PropMode.REPLACE, [])
return
def do_property_notify_event(self, event):
@@ -245,7 +242,8 @@ class DrawWaveform(gtk.DrawingArea):
def do_realize(self):
""" Called when we are creating all of our window resources """
-
+ # FIXME: No tengo idea de que hacer aca!
+ """
gtk.DrawingArea.do_realize(self)
# Force a native X window to exist
@@ -302,49 +300,47 @@ class DrawWaveform(gtk.DrawingArea):
self._HARMONIC_LINE_THICKNESS, gtk.gdk.LINE_SOLID,
gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_BEVEL)
self._harmonic_gc.set_foreground(clr)
-
+ """
self._create_background_pixmap()
return
def _create_background_pixmap(self):
""" Draw the gridlines for the plot """
- back_surf = gtk.gdk.Pixmap(self.window, self._tick_size,
- self._tick_size)
- cr = back_surf.cairo_create()
- cr.set_source_rgb(0, 0, 0)
- cr.paint()
-
- cr.set_line_width(self._BACKGROUND_LINE_THICKNESS)
- cr.set_source_rgb(0.2, 0.2, 0.2)
-
- x = 0
- y = 0
-
- for j in range(0, 2):
- cr.move_to(x, y)
- cr.rel_line_to(0, self._tick_size)
- x = x + self._tick_size
-
+ cr = self.get_window().cairo_create()
+ Gdk.cairo_set_source_color(cr, Gdk.color_parse('gray'))
+ allocation = self.get_allocation()
x = 0
- y = (self.allocation.height % self._tick_size) / 2 - self._tick_size
-
- for j in range(0, 3):
- cr.move_to(x, y)
- cr.rel_line_to(self._tick_size, 0)
- y = y + self._tick_size
- cr.set_line_width(self._BACKGROUND_LINE_THICKNESS)
- cr.stroke()
+ for j in range(0, allocation.height / (self._FOREGROUND_LINE_THICKNESS * 2)):
+ line = Gdk.Rectangle()
+ line.x = x
+ line.y = 0
+ line.width = 1
+ line.height = allocation.height
+ x = x + (self._FOREGROUND_LINE_THICKNESS * 5)
+ Gdk.cairo_rectangle(cr, line)
+ cr.fill()
+
+
+ y = (allocation.height % self._tick_size) / 2 - self._tick_size
+
+ for j in range(0, allocation.width / (self._FOREGROUND_LINE_THICKNESS * 2)):
+ line = Gdk.Rectangle()
+ line.x = 0
+ line.y = y
+ line.width = allocation.width
+ line.height = 1
+ Gdk.cairo_rectangle(cr, line)
+ cr.fill()
+ y = y + (self._FOREGROUND_LINE_THICKNESS * 5)
- del cr
- self.window.set_back_pixmap(back_surf, False)
return
def do_button_press_event(self, event):
""" Set the trigger postion on a button-press event """
- self.trigger_xpos = event.x / float(self.allocation.width)
- self.trigger_ypos = event.y / float(self.allocation.height)
+ self.trigger_xpos = event.x / float(self.get_allocation().width)
+ self.trigger_ypos = event.y / float(self.get_allocation().height)
return True
def _calculate_trigger_position(self, samples, y_mag, buf):
@@ -359,7 +355,7 @@ class DrawWaveform(gtk.DrawingArea):
else:
ypos *= -32767.0 / y_mag
- x_offset = self.allocation.width * xpos - \
+ x_offset = self.get_allocation().width * xpos - \
(samples - samples_to_end) * self.draw_interval
position = -1
@@ -388,37 +384,61 @@ class DrawWaveform(gtk.DrawingArea):
self.draw_interval + 0.5)
return position, samples_to_end
- def _expose(self, widget, event):
+ def do_draw(self, context):
"""The 'expose' event handler does all the drawing"""
- width, height = self.window.get_size()
+ self._create_background_pixmap()
+ allocation = self.get_allocation()
+ width, height = allocation.width, allocation.height
+ window = self.get_window()
+ Gdk.cairo_set_source_color(context, Gdk.color_parse('red'))
# Real time drawing
if self.context and self.active:
-
# Draw tuning lines
# If we are tuning, we want to scale by 10
scale = 10. * self.freq_div / 500.
if self.fft_show and self.instrument in INSTRUMENT_DICT:
for n, note in enumerate(INSTRUMENT_DICT[self.instrument]):
x = int(note / scale)
- self.window.draw_line(
- self._instrument_gc[n], x, 0, x, height)
+ line = Gdk.Rectangle()
+ line.x = x
+ line.y = 0
+ line.width = x
+ line.height = height
+ Gdk.cairo_rectangle(context, line)
+ context.fill()
for n, note in enumerate(INSTRUMENT_DICT[self.instrument]):
if self.harmonics:
x = int(note / scale)
for i in range(3):
j = i + 2
- self.window.draw_line(self._instrument_h_gc[n],
- x * j, 20 * j, x * j, height)
+ line = Gdk.Rectangle()
+ line.x = x * j
+ line.y = 20 * j
+ line.width = x * j
+ line.height = height
+ Gdk.cairo_rectangle(context, line)
+ context.fill()
if self.fft_show and self.tuning_line > 0.0:
x = int(self.tuning_line / scale)
- self.window.draw_line(self._tuning_line_gc, x, 0, x, height)
+ line = Gdk.Rectangle()
+ line.x = x
+ line.y = 0
+ line.width = x
+ line.height = height
+ Gdk.cairo_rectangle(context, line)
+ context.fill()
if self.harmonics:
for i in range(3):
j = i + 2
- self.window.draw_line(self._harmonic_gc, x * j,
- 20 * j, x * j, height)
+ line = Gdk.Rectangle()
+ line.x = x * j
+ line.y = 20 * j
+ line.width = x * j
+ line.height = height
+ Gdk.cairo_rectangle(context, line)
+ context.fill()
#Iterate for each graph
for graph_id in self.graph_id:
@@ -426,7 +446,7 @@ class DrawWaveform(gtk.DrawingArea):
continue
if self.graph_show_state[graph_id]:
buf = self.ringbuffer[graph_id].read(None, self.input_step)
- samples = ceil(self.allocation.width / self.draw_interval)
+ samples = ceil(width / self.draw_interval)
if len(buf) == 0:
# We don't have enough data to plot.
self._indirect_queue_draw()
@@ -468,15 +488,15 @@ class DrawWaveform(gtk.DrawingArea):
if factor == 0:
factor = 0.01
if self.invert[graph_id]:
- data *= self.allocation.height / factor
+ data *= height / factor
else:
- data *= -self.allocation.height / factor
+ data *= -height / factor
data -= self.bias[graph_id]
if self.fft_show:
- data += self.allocation.height - 3
+ data += height - 3
else:
- data += (self.allocation.height / 2.0)
+ data += (height / 2.0)
# The actual drawing of the graph
lines = (arange(len(data), dtype='float32')\
@@ -500,20 +520,30 @@ class DrawWaveform(gtk.DrawingArea):
freq_note(x, flatsharp=True))
else:
if self.triggering != self.TRIGGER_NONE:
- x = int(self.trigger_xpos * self.allocation.width)
- y = int(self.trigger_ypos * self.allocation.height)
+ x = int(self.trigger_xpos * width)
+ y = int(self.trigger_ypos * height)
length = int(self._TRIGGER_LINE_THICKNESS * 3.5)
- self.window.draw_line(self._trigger_line_gc,
- x - length, y,
- x + length, y)
- self.window.draw_line(self._trigger_line_gc,
- x, y - length,
- x, y - length)
+ line = Gdk.Rectangle()
+ line.x = x - length
+ line.y = y
+ line.width = x + length
+ line.height = y
+ Gdk.cairo_rectangle(context, line)
+ context.fill()
+ line = Gdk.Rectangle()
+ line.x = x
+ line.y = y - length
+ line.width = x
+ line.height = y - length
+ Gdk.cairo_rectangle(context, line)
+ context.fill()
if self.type[graph_id] == 0:
- self.window.draw_lines(self._line_gc[graph_id], lines)
+ print graph_id
+ window.draw_lines(self._line_gc[graph_id], lines)
else:
- self.window.draw_points(self._line_gc[graph_id], lines)
+ window.draw_points(self._line_gc[graph_id], lines)
+ print graph_id
self._indirect_queue_draw()
return True
@@ -538,7 +568,7 @@ class DrawWaveform(gtk.DrawingArea):
self.triggering = trigger
def get_ticks(self):
- return self.allocation.width / float(self._tick_size)
+ return self.get_allocation().width / float(self._tick_size)
def get_fft_mode(self):
"""Returns if FFT is ON (True) or OFF (False)"""
@@ -554,7 +584,7 @@ class DrawWaveform(gtk.DrawingArea):
self._freq_range = freq_range
def _update_mode(self):
- if self.allocation.width <= 0:
+ if self.get_allocation().width <= 0:
return
if self.fft_show:
@@ -565,12 +595,12 @@ class DrawWaveform(gtk.DrawingArea):
self.draw_interval = 5.0
self.set_max_samples(
- ceil(self.allocation.width / \
+ ceil(self.get_allocation().width / \
float(self.draw_interval) * 2) * self.input_step)
# Create the (blackman) window
self.fft_window = blackman(
- ceil(self.allocation.width / float(self.draw_interval) * 2))
+ ceil(self.get_allocation().width / float(self.draw_interval) * 2))
self.draw_interval *= wanted_step / self.input_step
else:
@@ -582,8 +612,8 @@ class DrawWaveform(gtk.DrawingArea):
self.set_max_samples(samples * self.max_samples_fact)
self.input_step = max(ceil(samples\
- / (self.allocation.width / 3.0)), 1)
- self.draw_interval = self.allocation.width\
+ / (self.get_allocation().width / 3.0)), 1)
+ self.draw_interval = self.get_allocation().width\
/ (float(samples) / self.input_step)
self.fft_window = None
diff --git a/journal.py b/journal.py
index 15ee87f..af6e9f4 100644
--- a/journal.py
+++ b/journal.py
@@ -3,6 +3,7 @@
# Author: Arjun Sarwal arjun@laptop.org
# Copyright (C) 2007, Arjun Sarwal
# Copyright (C) 2009-12 Walter Bender
+# Copyright (C) 2013, Ignacio Rodriguez
#
#
# This program is free software; you can redistribute it and/or modify
@@ -19,14 +20,14 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-import gtk
+from gi.repository import Gtk
import cairo
import time
import os
from numpy import array
from gettext import gettext as _
-from sugar.datastore import datastore
+from sugar3.datastore import datastore
# Initialize logging.
import logging
@@ -90,7 +91,7 @@ class DataLogger():
log.debug('saving screen capture to temp file %s' % (tmp_file_path))
- gtk.threads_enter()
+ Gtk.threads_enter()
win = self.activity.wave.get_window()
width, height = win.get_size()
@@ -102,7 +103,7 @@ class DataLogger():
cr.paint()
img_surface.write_to_png(tmp_file_path)
- gtk.threads_leave()
+ Gtk.threads_leave()
if os.path.exists(tmp_file_path):
dsobject = datastore.create()
try:
diff --git a/measure.py b/measure.py
index 4b5b12f..0955a01 100644
--- a/measure.py
+++ b/measure.py
@@ -5,6 +5,7 @@
# Copyright (C) 2007, Arjun Sarwal
# Copyright (C) 2009-13 Walter Bender
# Copyright (C) 2009, Benjamin Berg, Sebastian Berg
+# Copyright (C) 2013, Ignacio Rodriguez
#
# 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
@@ -16,24 +17,25 @@
# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
-import pygst
-pygst.require("0.10")
-import gtk
-import pango
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import GdkPixbuf
+from gi.repository import Pango
+
import os
import subprocess
import csv
from gettext import gettext as _
-from sugar.activity import activity
-from sugar.activity.widgets import ActivityToolbarButton
-from sugar.activity.widgets import StopButton
-from sugar.graphics.toolbarbox import ToolbarBox
-from sugar.graphics.toolbarbox import ToolbarButton
-from sugar.graphics.toolbutton import ToolButton
-from sugar.graphics import style
-from sugar.datastore import datastore
+from sugar3.activity import activity
+from sugar3.activity.widgets import ActivityToolbarButton
+from sugar3.activity.widgets import StopButton
+from sugar3.graphics.toolbarbox import ToolbarBox
+from sugar3.graphics.toolbarbox import ToolbarButton
+from sugar3.graphics.toolbutton import ToolButton
+from sugar3.graphics import style
+from sugar3.datastore import datastore
from sugar import profile
@@ -100,11 +102,11 @@ class MeasureActivity(activity.Activity):
activity.Activity.__init__(self, handle)
self.mode_images = {}
- self.mode_images['sound'] = gtk.gdk.pixbuf_new_from_file_at_size(
+ self.mode_images['sound'] = GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(ICONS_DIR, 'media-audio.svg'), 45, 45)
- self.mode_images['resistance'] = gtk.gdk.pixbuf_new_from_file_at_size(
+ self.mode_images['resistance'] = GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(ICONS_DIR, 'resistance.svg'), 45, 45)
- self.mode_images['voltage'] = gtk.gdk.pixbuf_new_from_file_at_size(
+ self.mode_images['voltage'] = GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(ICONS_DIR, 'voltage.svg'), 45, 45)
self.icon_colors = self.get_icon_colors_from_sugar()
@@ -144,31 +146,29 @@ class MeasureActivity(activity.Activity):
# no sharing
self.max_participants = 1
- box3 = gtk.HBox(False, 0)
+ box3 = Gtk.HBox(False, 0)
box3.pack_start(self.wave, True, True, 0)
# We need event boxes in order to set the background color.
side_eventboxes = []
self.side_toolbars = []
for i in range(self.audiograb.channels):
- side_eventboxes.append(gtk.EventBox())
+ side_eventboxes.append(Gtk.EventBox())
side_eventboxes[i].modify_bg(
- gtk.STATE_NORMAL, style.COLOR_TOOLBAR_GREY.get_gdk_color())
+ Gtk.StateType.NORMAL, style.COLOR_TOOLBAR_GREY.get_gdk_color())
self.side_toolbars.append(SideToolbar(self, channel=i))
side_eventboxes[i].add(self.side_toolbars[i].box1)
box3.pack_start(side_eventboxes[i], False, True, 0)
- event_box = gtk.EventBox()
- self.text_box = gtk.Label()
- self.text_box.set_justify(gtk.JUSTIFY_LEFT)
- alist = pango.AttrList()
- alist.insert(pango.AttrForeground(65535, 65535, 65535, 0, -1))
- self.text_box.set_attributes(alist)
+ event_box = Gtk.EventBox()
+ self.text_box = Gtk.Label()
+ self.text_box.set_justify(Gtk.Justification.LEFT)
+ self.text_box.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse('white'))
event_box.add(self.text_box)
event_box.modify_bg(
- gtk.STATE_NORMAL, style.COLOR_TOOLBAR_GREY.get_gdk_color())
+ Gtk.StateType.NORMAL, style.COLOR_TOOLBAR_GREY.get_gdk_color())
- box1 = gtk.VBox(False, 0)
+ box1 = Gtk.VBox(False, 0)
box1.pack_start(box3, True, True, 0)
box1.pack_start(event_box, False, True, 0)
@@ -183,8 +183,8 @@ class MeasureActivity(activity.Activity):
self.sensor_toolbar = SensorToolbar(self, self.audiograb.channels)
self.tuning_toolbar = TuningToolbar(self)
self.new_instrument_toolbar = InstrumentToolbar(self)
- self._extras_toolbar = gtk.Toolbar()
- self.control_toolbar = gtk.Toolbar()
+ self._extras_toolbar = Gtk.Toolbar()
+ self.control_toolbar = Gtk.Toolbar()
sensor_button = ToolbarButton(
label=_('Sensors'),
@@ -209,12 +209,12 @@ class MeasureActivity(activity.Activity):
page=self._extras_toolbar,
icon_name='domain-time')
toolbox.toolbar.insert(self._extras_button, -1)
- self._extras_toolbar_item = gtk.ToolItem()
+ self._extras_toolbar_item = Gtk.ToolItem()
self._extras_toolbar.insert(self._extras_toolbar_item, -1)
self._extras_button.hide()
self.sensor_toolbar.show()
- self._extra_tools = gtk.HBox()
+ self._extra_tools = Gtk.HBox()
# Set up Frequency-domain Button
self.freq = ToolButton('domain-time')
@@ -225,7 +225,7 @@ class MeasureActivity(activity.Activity):
self.sensor_toolbar.add_frequency_slider(self._extra_tools)
- self._extra_item = gtk.ToolItem()
+ self._extra_item = Gtk.ToolItem()
self._extra_item.add(self._extra_tools)
self._extra_tools.show()
toolbox.toolbar.insert(self._extra_item, -1)
@@ -243,18 +243,17 @@ class MeasureActivity(activity.Activity):
self._capture.show()
toolbox.toolbar.insert(self._capture, -1)
- separator = gtk.SeparatorToolItem()
+ separator = Gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
toolbox.toolbar.insert(separator, -1)
separator.show()
stop_button = StopButton(self)
- stop_button.props.accelerator = _('<Ctrl>Q')
toolbox.toolbar.insert(stop_button, -1)
stop_button.show()
- self.set_toolbox(toolbox)
+ self.set_toolbar_box(toolbox)
sensor_button.set_expanded(True)
toolbox.show()
@@ -271,14 +270,14 @@ class MeasureActivity(activity.Activity):
self.wave.set_active(True)
self.wave.set_context_on()
- gtk.gdk.screen_get_default().connect('size-changed',
+ Gdk.Screen.get_default().connect('size-changed',
self._configure_cb)
self._configure_cb(None)
def _configure_cb(self, event):
''' Screen size has changed, so check to see if the toolbar
elements still fit.'''
- self.width = gtk.gdk.screen_width()
+ self.width = Gdk.Screen.width()
if self.width < style.GRID_CELL_SIZE * 14:
self._extras_button.show()
if self._extra_tools in self._extra_item:
@@ -408,12 +407,12 @@ class MeasureActivity(activity.Activity):
''' Callback for Pause Button '''
if self.audiograb.get_freeze_the_display():
self.audiograb.set_freeze_the_display(False)
- self._pause.set_icon('media-playback-start')
+ self._pause.set_icon_name('media-playback-start')
self._pause.set_tooltip(_('Unfreeze the display'))
self._pause.show()
else:
self.audiograb.set_freeze_the_display(True)
- self._pause.set_icon('media-playback-pause')
+ self._pause.set_icon_name('media-playback-pause')
self._pause.set_tooltip(_('Freeze the display'))
self._pause.show()
return False
@@ -429,11 +428,11 @@ class MeasureActivity(activity.Activity):
self.sensor_toolbar.record_control_cb()
if self.wave.get_fft_mode():
self.wave.set_fft_mode(False)
- self.freq.set_icon('domain-time')
+ self.freq.set_icon_name('domain-time')
self.freq.set_tooltip(_('Time Base'))
else:
self.wave.set_fft_mode(True)
- self.freq.set_icon('domain-freq')
+ self.freq.set_icon_name('domain-freq')
self.freq.set_tooltip(_('Frequency Base'))
# Turn off triggering in Frequencey Base
self.sensor_toolbar.trigger_none.set_active(True)
@@ -453,4 +452,4 @@ class MeasureActivity(activity.Activity):
''' Returns nick from Sugar '''
return profile.get_nick_name()
-gtk.gdk.threads_init()
+Gdk.threads_init()
diff --git a/sensor_toolbar.py b/sensor_toolbar.py
index 711146e..c4d8eca 100644
--- a/sensor_toolbar.py
+++ b/sensor_toolbar.py
@@ -5,6 +5,7 @@
# Copyright (C) 2007, Arjun Sarwal
# Copyright (C) 2009-13 Walter Bender
# Copyright (C) 2009, Benjamin Berg, Sebastian Berg
+# Copyright (C) 2013, Ignacio Rodriguez
#
# 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
@@ -16,17 +17,18 @@
# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
-import gtk
-import gobject
+from gi.repository import Gtk
+from gi.repository import GObject
+from gi.repository import Gdk
import os
from gettext import gettext as _
from gettext import ngettext
from config import ICONS_DIR, CAPTURE_GAIN, MIC_BOOST, XO1, XO15, XO175, XO4
-from sugar.graphics.toolbutton import ToolButton
-from sugar.graphics.menuitem import MenuItem
-from sugar.graphics.radiotoolbutton import RadioToolButton
+from sugar3.graphics.toolbutton import ToolButton
+from sugar3.graphics.menuitem import MenuItem
+from sugar3.graphics.radiotoolbutton import RadioToolButton
import logging
log = logging.getLogger('measure-activity')
log.setLevel(logging.DEBUG)
@@ -42,7 +44,7 @@ def _is_xo(hw):
return hw in [XO1, XO15, XO175, XO4]
-class SensorToolbar(gtk.Toolbar):
+class SensorToolbar(Gtk.Toolbar):
''' The toolbar for specifiying the sensor: sound, resitance, or
voltage '''
@@ -69,7 +71,7 @@ of XO)") + ' '
def __init__(self, activity, channels):
''' By default, start with resistance mode '''
- gtk.Toolbar.__init__(self)
+ Gtk.Toolbar.__init__(self)
self.activity = activity
self._channels = channels
@@ -90,7 +92,7 @@ of XO)") + ' '
# Set up Time-domain Button
self.time = RadioToolButton(group=None)
- self.time.set_named_icon('media-audio')
+ self.time.set_icon_name('media-audio')
self.insert(self.time, -1)
self.time.set_tooltip(_('Sound'))
self.time.connect(
@@ -98,7 +100,7 @@ of XO)") + ' '
# Set up Resistance Button
self.resistance = RadioToolButton(group=self.time)
- self.resistance.set_named_icon('resistance')
+ self.resistance.set_icon_name('resistance')
if _is_xo(self.activity.hw):
self.insert(self.resistance, -1)
self.resistance.show()
@@ -109,7 +111,7 @@ of XO)") + ' '
# Set up Voltage Button
self.voltage = RadioToolButton(group=self.time)
- self.voltage.set_named_icon('voltage')
+ self.voltage.set_icon_name('voltage')
if _is_xo(self.activity.hw):
self.insert(self.voltage, -1)
self.voltage.set_tooltip(_('Voltage Sensor'))
@@ -117,13 +119,14 @@ of XO)") + ' '
self.analog_resistance_voltage_mode_cb,
'voltage')
- separator = gtk.SeparatorToolItem()
+ separator = Gtk.SeparatorToolItem()
separator.props.draw = True
self.insert(separator, -1)
self._log_value = LOG_TIMER_VALUES[1]
- self.log_label = gtk.Label(self._log_to_string(self._log_value))
- toolitem = gtk.ToolItem()
+ self.log_label = Gtk.Label(self._log_to_string(self._log_value))
+ self.log_label.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse('white'))
+ toolitem = Gtk.ToolItem()
toolitem.add(self.log_label)
self.insert(toolitem, -1)
@@ -139,18 +142,19 @@ of XO)") + ' '
self._record.set_tooltip(_('Start logging'))
self._record.connect('clicked', self.record_control_cb)
- separator = gtk.SeparatorToolItem()
+ separator = Gtk.SeparatorToolItem()
separator.props.draw = True
self.insert(separator, -1)
- toolitem = gtk.ToolItem()
- self.trigger_label = gtk.Label(_('Trigger'))
+ toolitem = Gtk.ToolItem()
+ self.trigger_label = Gtk.Label(_('Trigger'))
+ self.trigger_label.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse('white'))
toolitem.add(self.trigger_label)
self.insert(toolitem, -1)
# Set up Trigger Combo box
self.trigger_none = RadioToolButton()
- self.trigger_none.set_named_icon('trigger-none')
+ self.trigger_none.set_icon_name('trigger-none')
self.insert(self.trigger_none, -1)
self.trigger_none.set_tooltip(_('None'))
self.trigger_none.connect('clicked',
@@ -158,7 +162,7 @@ of XO)") + ' '
self.activity.wave.TRIGGER_NONE)
self.trigger_rise = RadioToolButton(group=self.trigger_none)
- self.trigger_rise.set_named_icon('trigger-rise')
+ self.trigger_rise.set_icon_name('trigger-rise')
self.insert(self.trigger_rise, -1)
self.trigger_rise.set_tooltip(_('Rising Edge'))
self.trigger_rise.connect('clicked',
@@ -166,7 +170,7 @@ of XO)") + ' '
self.activity.wave.TRIGGER_POS)
self.trigger_fall = RadioToolButton(group=self.trigger_none)
- self.trigger_fall.set_named_icon('trigger-fall')
+ self.trigger_fall.set_icon_name('trigger-fall')
self.insert(self.trigger_fall, -1)
self.trigger_fall.set_tooltip(_('Falling Edge'))
self.trigger_fall.connect('clicked',
@@ -188,7 +192,7 @@ of XO)") + ' '
self._log_value = LOG_TIMER_VALUES[idx]
self.log_label.set_text(self._log_to_string(self._log_value))
if hasattr(self, '_log_button'):
- self._log_button.set_icon('timer-%d' % (self._log_value))
+ self._log_button.set_icon_name('timer-%d' % (self._log_value))
def _log_selection_cb(self, widget):
if self._log_palette:
@@ -229,14 +233,13 @@ of XO)") + ' '
self._freq_stepper_up.connect('clicked', self._freq_stepper_up_cb)
self._freq_stepper_up.show()
- self.activity.adjustmentf = gtk.Adjustment(
+ self.activity.adjustmentf = Gtk.Adjustment.new(
0.5, self.LOWER, self.UPPER, 0.01, 0.1, 0)
self.activity.adjustmentf.connect('value_changed', self.cb_page_sizef)
- self._freq_range = gtk.HScale(self.activity.adjustmentf)
+ self._freq_range = Gtk.HScale.new(self.activity.adjustmentf)
self._freq_range.set_inverted(True)
self._freq_range.set_draw_value(False)
- self._freq_range.set_update_policy(gtk.UPDATE_CONTINUOUS)
self._freq_range.set_size_request(120, 15)
self._freq_range.show()
@@ -245,7 +248,7 @@ of XO)") + ' '
self._freq_stepper_down.connect('clicked', self._freq_stepper_down_cb)
self._freq_stepper_down.show()
- self._freq_range_tool = gtk.ToolItem()
+ self._freq_range_tool = Gtk.ToolItem()
self._freq_range_tool.add(self._freq_range)
self._freq_range_tool.show()
@@ -346,20 +349,20 @@ of XO)") + ' '
def cb_page_sizef(self, button=None):
''' Callback to scale the frequency range (zoom in and out) '''
if self._update_page_size_id:
- gobject.source_remove(self._update_page_size_id)
+ GObject.source_remove(self._update_page_size_id)
self._update_page_size_id =\
- gobject.timeout_add(250, self.update_page_size)
+ GObject.timeout_add(250, self.update_page_size)
return True
def update_page_size(self):
''' Set up the scaling of the display. '''
self._update_page_size_id = None
- new_value = round(self.activity.adjustmentf.value * 100.0) / 100.0
- if self.activity.adjustmentf.value != new_value:
- self.activity.adjustmentf.value = new_value
+ new_value = round(self.activity.adjustmentf.get_value() * 100.0) / 100.0
+ if self.activity.adjustmentf.get_value() != new_value:
+ self.activity.adjustmentf.set_value(new_value)
return False
- time_div = 0.001 * max(self.activity.adjustmentf.value, 0.05)
- freq_div = 1000 * max(self.activity.adjustmentf.value, 0.01)
+ time_div = 0.001 * max(self.activity.adjustmentf.get_value(), 0.05)
+ freq_div = 1000 * max(self.activity.adjustmentf.get_value(), 0.01)
self.activity.wave.set_div(time_div, freq_div)
self.update_string_for_textbox()
return False
@@ -367,13 +370,13 @@ of XO)") + ' '
def set_sound_context(self):
''' Called when analog sensing is selected '''
self.set_show_hide_windows(mode='sound')
- gobject.timeout_add(500, self.sound_context_on)
+ GObject.timeout_add(500, self.sound_context_on)
self.activity.CONTEXT = 'sound'
def set_sensor_context(self):
''' Called when digital sensing is selected '''
self.set_show_hide_windows(mode='sensor')
- gobject.timeout_add(500, self.sensor_context_on)
+ GObject.timeout_add(500, self.sensor_context_on)
self.activity.CONTEXT = 'sensor'
def set_show_hide_windows(self, mode='sound'):
@@ -412,10 +415,10 @@ of XO)") + ' '
def set_sample_value(self, value='', channel=0):
''' Write a sample value to the textbox. '''
- gtk.threads_enter()
+ Gtk.threads_enter()
self.values[channel] = value
self.update_string_for_textbox()
- gtk.threads_leave()
+ Gtk.threads_leave()
return
def record_control_cb(self, button=None):
@@ -423,7 +426,7 @@ of XO)") + ' '
session, or just logs the current buffer. '''
if self.activity.audiograb.we_are_logging:
self.activity.audiograb.set_logging_params(start_stop=False)
- self._record.set_icon('media-record')
+ self._record.set_icon_name('media-record')
self._record.show()
self._record.set_tooltip(_('Start Recording'))
else:
@@ -443,7 +446,7 @@ of XO)") + ' '
channels=self._channels, mode=self.mode)
self.activity.audiograb.set_logging_params(
start_stop=True, interval=interval, screenshot=False)
- self._record.set_icon('record-stop')
+ self._record.set_icon_name('record-stop')
self._record.show()
self._record.set_tooltip(_('Stop Recording'))
self.activity.new_recording = True
diff --git a/setup.py b/setup.py
index 876cd3f..95390a3 100755
--- a/setup.py
+++ b/setup.py
@@ -16,7 +16,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-from sugar.activity import bundlebuilder
+from sugar3.activity import bundlebuilder
bundlebuilder.start()
diff --git a/toolbar_side.py b/toolbar_side.py
index 387cc8b..1990a6e 100644
--- a/toolbar_side.py
+++ b/toolbar_side.py
@@ -4,6 +4,7 @@
# Author: Arjun Sarwal arjun@laptop.org
# Copyright (C) 2007, Arjun Sarwal
# Copyright (C) 2009-11 Walter Bender
+# Copyright (C) 2013, Ignacio Rodriguez
#
#
# This program is free software; you can redistribute it and/or modify
@@ -16,20 +17,21 @@
# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
-import gtk
+from gi.repository import Gtk
+from gi.repository import GdkPixbuf
from gettext import gettext as _
-from sugar.graphics.toolbutton import ToolButton
+from sugar3.graphics.toolbutton import ToolButton
from config import LOWER, UPPER
-class SideToolbar(gtk.Toolbar):
+class SideToolbar(Gtk.Toolbar):
''' A toolbar on the side of the canvas for adjusting gain/bias '''
def __init__(self, activity, channel=0):
''' Set up initial toolbars '''
- gtk.Toolbar.__init__(self)
+ Gtk.Toolbar.__init__(self)
self.activity = activity
self._channel = channel
@@ -40,11 +42,11 @@ class SideToolbar(gtk.Toolbar):
self.mode = 'sound'
self.mode_values = {'sound': 3, 'sensor': 2}
- self._toggle = gtk.CheckButton()
+ self._toggle = Gtk.CheckButton()
self._toggle.set_active(True)
self._toggle.connect('clicked', self.toggle_cb)
self._toggle.show()
- self._toggle_box = gtk.HBox()
+ self._toggle_box = Gtk.HBox()
self._toggle_box.pack_start(self._toggle, False, True, 18)
self._invert = ToolButton('invert')
@@ -58,22 +60,21 @@ class SideToolbar(gtk.Toolbar):
self.button_up.connect('clicked', self._button_up_cb)
self.button_up.show()
- self.adjustmenty = gtk.Adjustment(self.mode_values[self.mode],
+ self.adjustmenty = Gtk.Adjustment.new(self.mode_values[self.mode],
LOWER, UPPER,
0.1, 0.1, 0.0)
self.adjustmenty.connect('value_changed', self._yscrollbar_cb,
self.adjustmenty)
- self.yscrollbar = gtk.VScale(self.adjustmenty)
+ self.yscrollbar = Gtk.VScale.new(self.adjustmenty)
self.yscrollbar.set_draw_value(False)
self.yscrollbar.set_inverted(True)
- self.yscrollbar.set_update_policy(gtk.UPDATE_CONTINUOUS)
self.button_down = ToolButton('amp-low')
self.button_down.set_tooltip(_('Decrease amplitude'))
self.button_down.connect('clicked', self._button_down_cb)
self.button_down.show()
- self.box1 = gtk.VBox(False, 0)
+ self.box1 = Gtk.VBox(False, 0)
if self._channel == 0:
self.box1.pack_start(self._color_wave(self.activity.stroke_color),
@@ -94,15 +95,15 @@ class SideToolbar(gtk.Toolbar):
def _yscrollbar_cb(self, adjy, data=None):
''' Callback for scrollbar '''
if self.mode == 'sound':
- self.activity.wave.set_mag_params(1.0, adjy.value,
+ self.activity.wave.set_mag_params(1.0, adjy.get_value(),
channel=self._channel)
self.activity.wave.set_bias_param(0,
channel=self._channel)
elif self.mode == 'sensor':
self.activity.wave.set_bias_param(int(
- 300 * (adjy.value - (UPPER - LOWER) / 2.)),
+ 300 * (adjy.get_value() - (UPPER - LOWER) / 2.)),
channel=self._channel)
- self.mode_values[self.mode] = adjy.value
+ self.mode_values[self.mode] = adjy.get_value()
return True
def _button_up_cb(self, data=None):
@@ -134,14 +135,14 @@ class SideToolbar(gtk.Toolbar):
''' Set the toolbar to either 'sound' or 'sensor' '''
self.mode = mode
if self.mode == 'sound':
- self.button_up.set_icon('amp-high')
+ self.button_up.set_icon_name('amp-high')
self.button_up.set_tooltip(_('Increase amplitude'))
- self.button_down.set_icon('amp-low')
+ self.button_down.set_icon_name('amp-low')
self.button_down.set_tooltip(_('Decrease amplitude'))
elif self.mode == 'sensor':
- self.button_up.set_icon('bias-high')
+ self.button_up.set_icon_name('bias-high')
self.button_up.set_tooltip(_('Increase bias'))
- self.button_down.set_icon('bias-low')
+ self.button_down.set_icon_name('bias-low')
self.button_down.set_tooltip(_('Decrease bias'))
self._invert.show()
self.yscrollbar.set_value(self.mode_values[self.mode])
@@ -156,11 +157,11 @@ class SideToolbar(gtk.Toolbar):
''' Callback for Invert Button '''
if self.activity.wave.get_invert_state(channel=self._channel):
self.activity.wave.set_invert_state(False, self._channel)
- self._invert.set_icon('invert')
+ self._invert.set_icon_name('invert')
self._invert.show()
elif not self.activity.wave.get_fft_mode():
self.activity.wave.set_invert_state(True, self._channel)
- self._invert.set_icon('invert2')
+ self._invert.set_icon_name('invert2')
self._invert.show()
self.activity.sensor_toolbar.update_string_for_textbox()
return False
@@ -179,16 +180,16 @@ c9.179,0,9.179,27.668,18.358,27.668c4.59,0,6.986-6.917,9.332-13.834"\n\
fill="none" stroke="%s" stroke-linecap="round" stroke-width="3.5"/>\n\
</svg>' % (color)
pixbuf = svg_str_to_pixbuf(svg)
- img = gtk.Image()
+ img = Gtk.Image()
img.set_from_pixbuf(pixbuf)
- img_tool = gtk.ToolItem()
+ img_tool = Gtk.ToolItem()
img_tool.add(img)
return img_tool
def svg_str_to_pixbuf(svg_string):
''' Load pixbuf from SVG string '''
- pl = gtk.gdk.PixbufLoader('svg')
+ pl = GdkPixbuf.PixbufLoader()
pl.write(svg_string)
pl.close()
pixbuf = pl.get_pixbuf()
diff --git a/tuning_toolbar.py b/tuning_toolbar.py
index aa2b845..f71d041 100644
--- a/tuning_toolbar.py
+++ b/tuning_toolbar.py
@@ -2,6 +2,7 @@
#! /usr/bin/python
#
# Copyright (C) 2009-12 Walter Bender
+# Copyright (C) 2013, Ignacio Rodriguez
#
# 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
@@ -14,17 +15,17 @@
import os
-import gtk
-import gobject
+from gi.repository import Gtk
+from gi.repository import GObject
from gettext import gettext as _
from config import XO4, XO175, INSTRUMENT_DICT
from audiograb import check_output
-from sugar.graphics.toolbutton import ToolButton
-from sugar.graphics.menuitem import MenuItem
-from sugar.graphics import style
+from sugar3.graphics.toolbutton import ToolButton
+from sugar3.graphics.menuitem import MenuItem
+from sugar3.graphics import style
import logging
log = logging.getLogger('measure-activity')
@@ -44,11 +45,11 @@ COLOR_GREEN = style.Color('#00FF00')
SPAN = '<span foreground="%s"><big><b>%s</b></big></span>'
-class TuningToolbar(gtk.Toolbar):
+class TuningToolbar(Gtk.Toolbar):
''' The toolbar for tuning instruments '''
def __init__(self, activity):
- gtk.Toolbar.__init__(self)
+ Gtk.Toolbar.__init__(self)
self.activity = activity
self._show_tuning_line = False
@@ -62,7 +63,7 @@ class TuningToolbar(gtk.Toolbar):
self.insert(self._instrument_button, -1)
self._setup_instrument_palette()
- separator = gtk.SeparatorToolItem()
+ separator = Gtk.SeparatorToolItem()
separator.props.draw = True
self.insert(separator, -1)
@@ -83,7 +84,7 @@ class TuningToolbar(gtk.Toolbar):
self._setup_octaves_palette()
# The entry is used to display a note or for direct user input
- self._freq_entry = gtk.Entry()
+ self._freq_entry = Gtk.Entry()
self._freq_entry.set_text('440') # A
self._freq_entry_changed_id = self._freq_entry.connect(
'changed', self._update_freq_entry)
@@ -92,7 +93,7 @@ class TuningToolbar(gtk.Toolbar):
_('Enter a frequency to display.'))
self._freq_entry.set_width_chars(8)
self._freq_entry.show()
- toolitem = gtk.ToolItem()
+ toolitem = Gtk.ToolItem()
toolitem.add(self._freq_entry)
self.insert(toolitem, -1)
toolitem.show()
@@ -103,7 +104,7 @@ class TuningToolbar(gtk.Toolbar):
self._new_tuning_line.set_tooltip(_('Show tuning line.'))
self._new_tuning_line.connect('clicked', self.tuning_line_cb)
- separator = gtk.SeparatorToolItem()
+ separator = Gtk.SeparatorToolItem()
separator.props.draw = True
self.insert(separator, -1)
@@ -113,7 +114,7 @@ class TuningToolbar(gtk.Toolbar):
self._harmonic.set_tooltip(_('Show harmonics.'))
self._harmonic.connect('clicked', self.harmonic_cb)
- separator = gtk.SeparatorToolItem()
+ separator = Gtk.SeparatorToolItem()
separator.props.draw = True
self.insert(separator, -1)
@@ -123,15 +124,15 @@ class TuningToolbar(gtk.Toolbar):
self._play_tone.set_tooltip(_('Play a note.'))
self._play_tone.connect('clicked', self.play_cb)
- separator = gtk.SeparatorToolItem()
+ separator = Gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
self.insert(separator, -1)
- self.label = gtk.Label('')
+ self.label = Gtk.Label('')
self.label.set_use_markup(True)
self.label.show()
- toolitem = gtk.ToolItem()
+ toolitem = Gtk.ToolItem()
toolitem.add(self.label)
self.insert(toolitem, -1)
toolitem.show()
@@ -287,14 +288,14 @@ class TuningToolbar(gtk.Toolbar):
if fidx == -1: # All notes
self.activity.wave.instrument = instrument
self.activity.wave.tuning_line = 0.0
- self._new_tuning_line.set_icon('tuning-tools')
+ self._new_tuning_line.set_icon_name('tuning-tools')
self._new_tuning_line.set_tooltip(_('Show tuning line.'))
self._show_tuning_line = False
else:
freq = INSTRUMENT_DICT[instrument][fidx]
self.activity.wave.instrument = None
self.activity.wave.tuning_line = freq
- self._new_tuning_line.set_icon('tuning-tools-off')
+ self._new_tuning_line.set_icon_name('tuning-tools-off')
self._new_tuning_line.set_tooltip(_('Hide tuning line.'))
self._show_tuning_line = True
@@ -304,20 +305,20 @@ class TuningToolbar(gtk.Toolbar):
''' Callback for harmonics control '''
self.activity.wave.harmonics = not self.activity.wave.harmonics
if self.activity.wave.harmonics:
- self._harmonic.set_icon('harmonics-off')
+ self._harmonic.set_icon_name('harmonics-off')
self._harmonic.set_tooltip(_('Hide harmonics.'))
if self.activity.wave.instrument is None and \
self.activity.wave.tuning_line == 0.0:
self._load_tuning_line()
else:
- self._harmonic.set_icon('harmonics')
+ self._harmonic.set_icon_name('harmonics')
self._harmonic.set_tooltip(_('Show harmonics.'))
def tuning_line_cb(self, *args):
''' Callback for tuning insert '''
if self._show_tuning_line:
self.activity.wave.tuning_line = 0.0
- self._new_tuning_line.set_icon('tuning-tools')
+ self._new_tuning_line.set_icon_name('tuning-tools')
self._new_tuning_line.set_tooltip(_('Show tuning line.'))
self._show_tuning_line = False
else:
@@ -330,7 +331,7 @@ class TuningToolbar(gtk.Toolbar):
self.activity.wave.tuning_line = float(freq)
if freq < 0:
freq = -freq
- self._new_tuning_line.set_icon('tuning-tools-off')
+ self._new_tuning_line.set_icon_name('tuning-tools-off')
self._new_tuning_line.set_tooltip(_('Hide tuning line.'))
self._show_tuning_line = True
except ValueError:
@@ -354,7 +355,7 @@ class TuningToolbar(gtk.Toolbar):
self.activity.audiograb.stop_grabbing()
freq = float(self._freq_entry.get_text())
- gobject.timeout_add(200, self.play_sound, freq, channels, wave_status)
+ GObject.timeout_add(200, self.play_sound, freq, channels, wave_status)
def play_sound(self, freq, channels, wave_status):
''' Play the sound and then restore wave settings '''
@@ -443,15 +444,15 @@ class TuningToolbar(gtk.Toolbar):
csd.close()
-class InstrumentToolbar(gtk.Toolbar):
+class InstrumentToolbar(Gtk.Toolbar):
''' The toolbar for adding new instruments '''
def __init__(self, activity):
- gtk.Toolbar.__init__(self)
+ Gtk.Toolbar.__init__(self)
self.activity = activity
self.new_instruments = []
- self._name_entry = gtk.Entry()
+ self._name_entry = Gtk.Entry()
self._name_entry.set_text(_('my instrument'))
self._name_entry_changed_id = self._name_entry.connect(
'changed', self.update_name_entry)
@@ -460,7 +461,7 @@ class InstrumentToolbar(gtk.Toolbar):
_('Enter instrument name.'))
self._name_entry.set_width_chars(24)
self._name_entry.show()
- toolitem = gtk.ToolItem()
+ toolitem = Gtk.ToolItem()
toolitem.add(self._name_entry)
self.insert(toolitem, -1)
toolitem.show()