Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflavio <fdanesse@gmail.com>2012-06-04 21:07:09 (GMT)
committer flavio <fdanesse@gmail.com>2012-06-04 21:07:09 (GMT)
commitc5392176247353bccdd5315ec43e8a1a74f16849 (patch)
treef4286e8ec298f3b8df6d821ecdcb10561bbafd49
parent16c07ef2dc6ba0bcc0b0035f6256178e7a5b85a5 (diff)
Port Gtk3
-rw-r--r--.gitignore4
-rw-r--r--activity.py77
-rw-r--r--arange.py16
-rw-r--r--atm_toolbars.py20
-rw-r--r--calibration_toolbar.py14
-rwxr-xr-xsetup.py2
-rw-r--r--smoot_toolbar.py14
7 files changed, 75 insertions, 72 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6089118
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.pyc
+*.pyo
+*.??~
+*.bak
diff --git a/activity.py b/activity.py
index 3178d51..a524575 100644
--- a/activity.py
+++ b/activity.py
@@ -16,21 +16,20 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import gobject
-import gtk
+import gi
+from gi.repository import Gtk, Gdk, GObject, Pango, GdkPixbuf
import logging
import telepathy
import telepathy.client
-import pango
import locale
# directory exists if powerd is running. create a file here,
# named after our pid, to inhibit suspend.
POWERD_INHIBIT_DIR = '/var/run/powerd-inhibit-suspend'
-import sugar
-from sugar.activity import activity
-from sugar.presence import presenceservice
+import sugar3
+from sugar3.activity import activity
+from sugar3.presence import presenceservice
from gettext import gettext as _
@@ -61,7 +60,7 @@ def gobject_idle_do(func, *args):
e.set()
return False
- gobject.idle_add(helper, retval, func, args, ev)
+ GObject.idle_add(helper, retval, func, args, ev)
ev.wait()
return retval[0]
@@ -80,7 +79,7 @@ class AcousticMeasureActivity(activity.Activity):
#self.set_title(_('Acoustic Tape Measure Activity'))
self._logger = logging.getLogger('acousticmeasure-activity')
- gobject.threads_init()
+ GObject.threads_init()
try:
self._logger.debug("locale: " + locale.setlocale(locale.LC_ALL,
@@ -91,13 +90,13 @@ class AcousticMeasureActivity(activity.Activity):
# top toolbar with share and close buttons:
try:
- from sugar.graphics.toolbarbox import ToolbarBox
- from sugar.graphics.toolbarbox import ToolbarButton
- from sugar.activity.widgets import ShareButton
- from sugar.activity.widgets import StopButton
- from sugar.activity.widgets import ActivityButton
- from sugar.activity.widgets import TitleEntry
- from sugar.graphics.toolbutton import ToolButton
+ from sugar3.graphics.toolbarbox import ToolbarBox
+ from sugar3.graphics.toolbarbox import ToolbarButton
+ from sugar3.activity.widgets import ShareButton
+ from sugar3.activity.widgets import StopButton
+ from sugar3.activity.widgets import ActivityButton
+ from sugar3.activity.widgets import TitleEntry
+ from sugar3.graphics.toolbutton import ToolButton
toolbar_box = ToolbarBox()
activity_button = ActivityButton(self)
@@ -109,7 +108,7 @@ class AcousticMeasureActivity(activity.Activity):
title_entry.show()
try:
- from sugar.activity.widgets import DescriptionItem
+ from sugar3.activity.widgets import DescriptionItem
description_item = DescriptionItem(self)
toolbar_box.toolbar.insert(description_item, -1)
description_item.show()
@@ -120,12 +119,12 @@ class AcousticMeasureActivity(activity.Activity):
toolbar_box.toolbar.insert(share_button, -1)
share_button.show()
- separator = gtk.SeparatorToolItem()
+ separator = Gtk.SeparatorToolItem()
toolbar_box.toolbar.insert(separator, -1)
separator.show()
self._t_h_bar = atm_toolbars.TempToolbar()
- tb = gtk.HBox()
+ tb = Gtk.HBox()
self._t_h_bar.show_all()
adj_button = ToolbarButton(page=self._t_h_bar,
icon_name='preferences-system')
@@ -139,7 +138,7 @@ class AcousticMeasureActivity(activity.Activity):
toolbar_box.toolbar.insert(custom_button, -1)
custom_button.show()
- separator = gtk.SeparatorToolItem()
+ separator = Gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
toolbar_box.toolbar.insert(separator, -1)
@@ -183,7 +182,7 @@ class AcousticMeasureActivity(activity.Activity):
thread.start_new_thread(self._helper_thread, ())
# Main Panel GUI
- self.main_panel = gtk.VBox()
+ self.main_panel = Gtk.VBox()
self._message_dict['unshared'] = _("To measure the distance between \
two laptops, you must first share this Activity.")
self._message_dict['ready'] = _("Press the button to measure the \
@@ -200,47 +199,47 @@ participants, so you cannot join.")
self._button_dict['waiting'] = _("Begin Measuring Distance")
self._button_dict['going'] = _("Stop Measuring Distance")
- self.button = gtk.ToggleButton(label=self._button_dict['waiting'])
+ self.button = Gtk.ToggleButton(label=self._button_dict['waiting'])
self.button.connect('clicked', self._button_clicked)
self.button.set_sensitive(False)
- check = gtk.Image()
+ check = Gtk.Image()
check.set_from_file('check.svg')
self.button.set_image(check)
- self.message = gtk.Label(self._message_dict['unshared'])
+ self.message = Gtk.Label(label=self._message_dict['unshared'])
self.message.set_selectable(True)
self.message.set_single_line_mode(True)
- img = gtk.Image()
- pb = gtk.gdk.pixbuf_new_from_file(
- sugar.activity.activity.get_bundle_path() + '/dist.svg')
+ img = Gtk.Image()
+ pb = GdkPixbuf.Pixbuf.new_from_file(
+ sugar3.activity.activity.get_bundle_path() + '/dist.svg')
img.set_from_pixbuf(pb)
- self.value = gtk.Label()
+ self.value = Gtk.Label()
self.value.set_selectable(True)
thread.start_new_thread(self._update_distance, (0, ))
- valuefont = pango.FontDescription()
+ valuefont = Pango.FontDescription()
valuefont.set_family("monospace")
- valuefont.set_absolute_size(300 * pango.SCALE)
+ valuefont.set_absolute_size(300 * Pango.SCALE)
self.value.modify_font(valuefont)
self.value.set_single_line_mode(True)
self.value.set_width_chars(6)
- eb = gtk.EventBox()
+ eb = Gtk.EventBox()
eb.add(self.value)
- eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))
+ eb.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("white"))
- self.fr = gtk.Frame(_('Measured distance in %s') % (_('meters')))
+ #self.fr = Gtk.Frame(_('Measured distance in %s') % (_('meters')))
+ self.fr = Gtk.Frame()
self.fr.set_label_align(0.5, 0.5)
self.fr.add(eb)
- self.main_panel.pack_start(self.button, expand=False, padding=6)
- self.main_panel.pack_start(self.message, expand=False)
- self.main_panel.pack_start(img, expand=True, fill=False)
- self.main_panel.pack_start(self.fr, expand=True, fill=False,
- padding=10)
+ self.main_panel.pack_start(self.button, False, False, 6)
+ self.main_panel.pack_start(self.message, False, True, 0)
+ self.main_panel.pack_start(img, True, False, 0)
+ self.main_panel.pack_start(self.fr, True, False, 10)
self.set_canvas(self.main_panel)
self.show_all()
@@ -369,7 +368,7 @@ participants, so you cannot join.")
#f = os.tempnam()
# The filename cannot be in $TMP, because this directory is not
# visible to Telepathy.
- f = sugar.activity.activity.get_activity_root() \
+ f = sugar3.activity.activity.get_activity_root() \
+ '/instance/my_socket'
if os.path.exists(f):
os.unlink(f)
@@ -510,7 +509,7 @@ participants, so you cannot join.")
# KP_Home == box gamekey = 65429
# KP_Page_Up == O gamekey = 65434
def _keypress_cb(self, widget, event):
- self._logger.debug("key press: " + gtk.gdk.keyval_name(event.keyval) \
+ self._logger.debug("key press: " + Gdk.keyval_name(event.keyval) \
+ " " + str(event.keyval))
if event.keyval == 65436:
self.button.clicked()
diff --git a/arange.py b/arange.py
index 4704c83..7ef8fa4 100644
--- a/arange.py
+++ b/arange.py
@@ -43,8 +43,8 @@ cache_dict = {}
def compute_mls(R):
"""
Computes a Maximum-Length-Sequence using a naive LFSR approach
- for n=3...32. R is the register initializer (cannot be all-zero) which
- determines the phase of the MLS.
+ for n=3...32. R is the register initializer (cannot be all-zero) which
+ determines the phase of the MLS.
"""
# 1-indexed collection of MLS taps from http://homepage.mac.com/afj/taplist.html
@@ -96,9 +96,9 @@ def LFSR(R, taps, m):
o = num.resize(num.array([], num.bool), (m))
if len(taps) == 2:
a = taps[0]
- b = taps[1]
+ b = taps[1]
for i in xrange(m):
- next = R[a] ^ R[b]
+ next = R[a] ^ R[b]
o[i] = R[-1]
R[1:] = R[:-1]
R[0] = next
@@ -218,7 +218,7 @@ def cross_cov(a, b, a_id=None):
else:
fa = num.fft.rfft(a,n2)
cache_dict[('fft', a_id, n2)] = fa
- else:
+ else:
fa = num.fft.rfft(a,n2)
fb = num.fft.rfft(b,n2)
fprod = num.conjugate(fa)*fb
@@ -267,7 +267,7 @@ def do_server_simul(server_address, port):
def do_client_simul(server_address, port):
"""
- Make this computer the client for a distance measurement
+ Make this computer the client for a distance measurement
using measure_dt_simul
"""
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -463,7 +463,7 @@ def measure_dt_seq(s, am_server, send_signal=False):
amp_ringdown = 0.2
time.sleep(amp_ringdown)
-
+
handoff_command = 'your turn'
ringdown = 0.3 # seconds
if am_server:
@@ -547,7 +547,7 @@ def measure_dt_seq(s, am_server, send_signal=False):
def getpeak(a):
return num.argmax(abs(a))
-def speed_of_sound(t=25.0, h=0.6, p=101325.0, x_c=0.0004):
+def speed_of_sound(t=25.0, h=0.6, p=101325.0, x_c=0.0004):
"""
t= temperature in Celsius
h = relative humidity as a fraction
diff --git a/atm_toolbars.py b/atm_toolbars.py
index d7d4c00..edd8d75 100644
--- a/atm_toolbars.py
+++ b/atm_toolbars.py
@@ -14,8 +14,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import gtk
-import gobject
+import gi
+from gi.repository import Gtk, Gdk, GObject
import arange
import locale
from gettext import gettext as _
@@ -23,10 +23,10 @@ from gettext import gettext as _
def _label_factory(label, toolbar):
''' Factory for adding a label to a toolbar '''
- my_label = gtk.Label(label)
+ my_label = Gtk.Label(label=label)
my_label.set_line_wrap(True)
my_label.show()
- _toolitem = gtk.ToolItem()
+ _toolitem = Gtk.ToolItem()
_toolitem.add(my_label)
toolbar.insert(_toolitem, -1)
_toolitem.show()
@@ -35,12 +35,12 @@ def _label_factory(label, toolbar):
def _entry_factory(length, toolbar, callback):
''' Factory for adding a text enrty to a toolbar '''
- my_entry = gtk.Entry()
+ my_entry = Gtk.Entry()
my_entry.set_max_length(length)
my_entry.set_width_chars(length)
my_entry.connect('changed', callback)
my_entry.show()
- _toolitem = gtk.ToolItem()
+ _toolitem = Gtk.ToolItem()
_toolitem.add(my_entry)
toolbar.insert(_toolitem, -1)
_toolitem.show()
@@ -49,18 +49,18 @@ def _entry_factory(length, toolbar, callback):
def _separator_factory(toolbar, expand=False, visible=False):
""" add a separator to a toolbar """
- _separator = gtk.SeparatorToolItem()
+ _separator = Gtk.SeparatorToolItem()
_separator.props.draw = visible
_separator.set_expand(expand)
toolbar.insert(_separator, -1)
_separator.show()
-class TempToolbar(gtk.Toolbar):
+class TempToolbar(Gtk.Toolbar):
_speed = 0
def __init__(self):
- gtk.Toolbar.__init__(self)
+ GObject.GObject.__init__(self)
temp_label = _label_factory(_("Temperature (C): "), self)
self._temp_field = _entry_factory(6, self, self._update_cb)
@@ -127,7 +127,7 @@ class TempToolbar(gtk.Toolbar):
return False
def _update_cb(self, widget=None):
- gobject.idle_add(self.update_speed)
+ GObject.idle_add(self.update_speed)
def update_speed(self):
t = self.get_temp()
diff --git a/calibration_toolbar.py b/calibration_toolbar.py
index 1f47258..3cfdf89 100644
--- a/calibration_toolbar.py
+++ b/calibration_toolbar.py
@@ -14,30 +14,30 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import gtk
+from gi.repository import Gtk, Gdk, GObject
import arange
import locale
from gettext import gettext
-class CalibrationToolbar(gtk.Toolbar):
+class CalibrationToolbar(Gtk.Toolbar):
def __init__(self):
- gtk.Toolbar.__init__(self)
+ GObject.GObject.__init__(self)
- offset_label = gtk.Label(gettext("Calibration Offset (meters): "))
- self._offset_field = gtk.Entry()
+ offset_label = Gtk.Label(label=gettext("Calibration Offset (meters): "))
+ self._offset_field = Gtk.Entry()
self._offset_field.set_max_length(10)
self._offset_field.set_width_chars(10)
- bigbox = gtk.HBox()
+ bigbox = Gtk.HBox()
bigbox.pack_start(offset_label, expand=False, fill=False)
bigbox.pack_end(self._offset_field, expand=False, fill=False)
self.set_offset(arange.OLPC_OFFSET)
- tool_item = gtk.ToolItem()
+ tool_item = Gtk.ToolItem()
tool_item.add(bigbox)
tool_item.set_expand(False)
self.insert(tool_item, 0)
diff --git a/setup.py b/setup.py
index 530f97c..c60f4d0 100755
--- a/setup.py
+++ b/setup.py
@@ -16,6 +16,6 @@
# 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/smoot_toolbar.py b/smoot_toolbar.py
index 334fd76..b57adc2 100644
--- a/smoot_toolbar.py
+++ b/smoot_toolbar.py
@@ -15,11 +15,11 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import gtk
+from gi.repository import Gtk, Gdk, GObject
from gettext import gettext as _
-from sugar.graphics.combobox import ComboBox
-from sugar.graphics.toolcombobox import ToolComboBox
+from sugar3.graphics.combobox import ComboBox
+from sugar3.graphics.toolcombobox import ToolComboBox
METERS = 0
CENTIMETERS = 1
@@ -41,10 +41,10 @@ UNIT_DICTIONARY = {METERS: (_('meters'), 1.0),
def _label_factory(label, toolbar):
''' Factory for adding a label to a toolbar '''
- my_label = gtk.Label(label)
+ my_label = Gtk.Label(label=label)
my_label.set_line_wrap(True)
my_label.show()
- _toolitem = gtk.ToolItem()
+ _toolitem = Gtk.ToolItem()
_toolitem.add(my_label)
toolbar.insert(_toolitem, -1)
_toolitem.show()
@@ -67,11 +67,11 @@ def _combo_factory(combo_array, default, tooltip, toolbar):
return my_combo
-class SmootToolbar(gtk.Toolbar):
+class SmootToolbar(Gtk.Toolbar):
''' Defines a toolbar for specifying units of measure '''
def __init__(self, parent):
- gtk.Toolbar.__init__(self)
+ GObject.GObject.__init__(self)
self._parent = parent
self._unit_name = _('meters')