Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2014-09-12 21:04:47 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2014-09-12 21:04:47 (GMT)
commite40924288954679b718fe000c51a29c2e398a148 (patch)
treee3604c929c464387fc5fca44b68a91ceb9cb28bc
parent566ee052c69ca02427f2874b5bc19e8577dd6b0f (diff)
Many more tests
-rw-r--r--add_notification.py10
-rw-r--r--atom_test.py18
-rw-r--r--avahi_browse.py46
-rw-r--r--avahi_publish.py54
-rw-r--r--cairo_colors.py18
-rw-r--r--check_pendings_commits.py106
-rw-r--r--clipi_gtk2.py49
-rw-r--r--clipi_gtk3.py49
-rw-r--r--clipi_gtk3_garnacho.py52
-rw-r--r--clipi_gtk3_simon.py49
-rw-r--r--clock_ex3.py74
-rw-r--r--draw_points.py109
-rw-r--r--ebook_mode.py20
-rw-r--r--fake_menu_test.py61
-rw-r--r--filechooser.py327
-rw-r--r--gconf_monitor_test.py31
-rw-r--r--gestures_new.py55
-rw-r--r--get_title.py54
-rw-r--r--get_title2.py54
-rw-r--r--gst_volume_view.py36
-rw-r--r--gtk3-drag-and-drop-example.py73
-rw-r--r--gtk3_test_draganddrop.py59
-rwxr-xr-xicon_viewer.py14
-rw-r--r--key_values.py25
-rw-r--r--label_pango_layout.py46
-rw-r--r--mini_abi_gtk3.py9
-rw-r--r--mini_abi_gtk3_b.py16
-rw-r--r--minimal_webkit.py14
-rw-r--r--nm_list_devices.py79
-rw-r--r--notifications.py8
-rw-r--r--open_html.py27
-rw-r--r--radio_btn_test.py26
-rw-r--r--read_pdf_index.py42
-rw-r--r--roundbox.py100
-rw-r--r--scribble.py123
-rw-r--r--selection_entry_test.py23
-rw-r--r--show_pulsing_icon_zoom_in.py24
-rw-r--r--show_pulsing_icon_zoom_out.py22
-rw-r--r--show_svg.py54
-rw-r--r--simple_label.py25
-rw-r--r--simple_tts.py75
-rw-r--r--simple_tts2.py80
-rw-r--r--simple_tts3.py87
-rw-r--r--simplecairodraw.py54
-rw-r--r--test_abi_content.py31
-rw-r--r--test_combo_font.py10
-rw-r--r--test_fixed.py20
-rw-r--r--test_menu_item.py32
-rw-r--r--test_pack.py40
-rw-r--r--test_scroll_webkit.py68
-rw-r--r--test_scroll_webkit_overlay.py81
-rw-r--r--test_speaker_dbus_msg.py23
-rw-r--r--test_vte_get_text.py41
-rw-r--r--test_vte_get_text_2.py46
-rw-r--r--touch_test_error_scrolled.py80
-rw-r--r--touch_test_walter.py62
-rw-r--r--treeview_dnd_test.py121
-rw-r--r--webkit_touch_test.py27
58 files changed, 3052 insertions, 7 deletions
diff --git a/add_notification.py b/add_notification.py
new file mode 100644
index 0000000..668b34d
--- /dev/null
+++ b/add_notification.py
@@ -0,0 +1,10 @@
+import dbus
+BUS_NAME = 'org.freedesktop.Notifications'
+OBJ_PATH = '/org/freedesktop/Notifications'
+IFACE_NAME = 'org.freedesktop.Notifications'
+bus = dbus.SessionBus()
+notify_obj = bus.get_object(BUS_NAME,OBJ_PATH)
+notifications = dbus.Interface(notify_obj,IFACE_NAME)
+notifications.Notify("Software Update", 0, '', "New activities are available!",
+ "Please check your activities list, there are beutiful surprises just where you think nothing can be expected. Happy Christmas, Hanuka, and other festivities. This is in your hands thanks to the hard work of the happy comunity of the Sherwood forests", [],
+ {'x-sugar-icon-name': 'module-updater'}, -1)
diff --git a/atom_test.py b/atom_test.py
new file mode 100644
index 0000000..55aaff7
--- /dev/null
+++ b/atom_test.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+# Test Clipboard.wait_for_targets() return values.
+
+from gi.repository import Gtk, Gdk, GdkX11
+
+
+def main():
+ #atom = Gdk.Atom.intern("CLIPBOARD", False)
+ #clippy = Gtk.Clipboard.get(selection=atom)
+ clippy = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
+ result, targets = clippy.wait_for_targets()
+ for target in targets:
+ print target, GdkX11.x11_xatom_to_atom(target).name()
+ print(targets)
+
+if __name__ == '__main__':
+ main()
+
diff --git a/avahi_browse.py b/avahi_browse.py
new file mode 100644
index 0000000..ecc4f8a
--- /dev/null
+++ b/avahi_browse.py
@@ -0,0 +1,46 @@
+# http://avahi.org/wiki/PythonBrowseExample
+import dbus, gobject, avahi
+from dbus import DBusException
+from dbus.mainloop.glib import DBusGMainLoop
+
+# Looks for iTunes shares
+
+TYPE = "_http._tcp"
+
+def service_resolved(*args):
+ print 'service resolved'
+ print 'name:', args[2]
+ print 'address:', args[7]
+ print 'port:', args[8]
+ print args
+
+def print_error(*args):
+ print 'error_handler'
+ print args[0]
+
+def myhandler(interface, protocol, name, stype, domain, flags):
+ print "Found service '%s' type '%s' domain '%s' " % (name, stype, domain)
+
+ if flags & avahi.LOOKUP_RESULT_LOCAL:
+ # local service, skip
+ pass
+
+ server.ResolveService(interface, protocol, name, stype,
+ domain, avahi.PROTO_UNSPEC, dbus.UInt32(0),
+ reply_handler=service_resolved, error_handler=print_error)
+
+loop = DBusGMainLoop()
+
+bus = dbus.SystemBus(mainloop=loop)
+
+server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, '/'),
+ 'org.freedesktop.Avahi.Server')
+
+sbrowser = dbus.Interface(bus.get_object(avahi.DBUS_NAME,
+ server.ServiceBrowserNew(avahi.IF_UNSPEC,
+ avahi.PROTO_UNSPEC, TYPE, 'local', dbus.UInt32(0))),
+ avahi.DBUS_INTERFACE_SERVICE_BROWSER)
+
+sbrowser.connect_to_signal("ItemNew", myhandler)
+
+gobject.MainLoop().run()
diff --git a/avahi_publish.py b/avahi_publish.py
new file mode 100644
index 0000000..ff9e394
--- /dev/null
+++ b/avahi_publish.py
@@ -0,0 +1,54 @@
+# from http://stackoverflow.com/questions/3430245/how-to-develop-an-avahi-client-server
+import avahi
+import dbus
+
+__all__ = ["ZeroconfService"]
+
+class ZeroconfService:
+ """A simple class to publish a network service with zeroconf using
+ avahi.
+
+ """
+
+ def __init__(self, name, port, stype="_http._tcp",
+ domain="", host="", text=""):
+ self.name = name
+ self.stype = stype
+ self.domain = domain
+ self.host = host
+ self.port = port
+ self.text = text
+
+ def publish(self):
+ bus = dbus.SystemBus()
+ server = dbus.Interface(
+ bus.get_object(
+ avahi.DBUS_NAME,
+ avahi.DBUS_PATH_SERVER),
+ avahi.DBUS_INTERFACE_SERVER)
+
+ g = dbus.Interface(
+ bus.get_object(avahi.DBUS_NAME,
+ server.EntryGroupNew()),
+ avahi.DBUS_INTERFACE_ENTRY_GROUP)
+
+ g.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC,dbus.UInt32(0),
+ self.name, self.stype, self.domain, self.host,
+ dbus.UInt16(self.port), self.text)
+
+ g.Commit()
+ self.group = g
+
+ def unpublish(self):
+ self.group.Reset()
+
+
+def test():
+ service = ZeroconfService(name="Teacher", port=3000, text="this is a text")
+ service.publish()
+ raw_input("Press any key to unpublish the service ")
+ service.unpublish()
+
+
+if __name__ == "__main__":
+ test()
diff --git a/cairo_colors.py b/cairo_colors.py
new file mode 100644
index 0000000..f26acdd
--- /dev/null
+++ b/cairo_colors.py
@@ -0,0 +1,18 @@
+import cairo
+import array
+
+width = 50
+# green
+color = 255 * 256 + 0xff000000
+
+# blue
+color = 255 + 0xff000000
+
+# red
+color = 255 * 65536 + 0xff000000
+
+pixels = array.array('I', [color] * (width * width))
+
+surface = cairo.ImageSurface.create_for_data(pixels, cairo.FORMAT_ARGB32, width, width)
+surface.write_to_png('/tmp/test1.png')
+
diff --git a/check_pendings_commits.py b/check_pendings_commits.py
new file mode 100644
index 0000000..3382e3a
--- /dev/null
+++ b/check_pendings_commits.py
@@ -0,0 +1,106 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os
+import subprocess
+
+POOTLE_DIR = '/var/lib/pootle/checkouts'
+OUTPUT = '/home/godiard/pending_commits.html'
+
+out = open(OUTPUT, 'w')
+
+langs = ['af', 'am', 'ar', 'ar_SY', 'ay', 'bg', 'bi', 'bn', 'bn_IN', 'bs',
+ 'ca', 'cpp', 'cs', 'de','dz', 'el', 'es', 'fa', 'fa_AF', 'ff', 'fi', 'fil',
+ 'gu', 'ha', 'he', 'hi', 'ht', 'hu', 'hus', 'ig', 'is', 'it', 'ja',
+ 'km', 'kn', 'ko', 'kos', 'lv', 'mg', 'mk', 'ml', 'mn', 'mr', 'ms',
+ 'mvo', 'na', 'nb', 'ne', 'nl', 'nn', 'pa', 'pap', 'pis', 'pl', 'ps',
+ 'pt', 'pt_BR', 'quy', 'quz', 'ro', 'ru', 'rw', 'sd', 'si', 'sk', 'sl', 'sm',
+ 'st', 'sv', 'sw', 'ta', 'te', 'th', 'ton', 'tpi', 'tr', 'tvl', 'tzo',
+ 'ug', 'uk', 'ur', 'vi', 'wa', 'yo', 'zh_CN', 'zh_TW']
+
+
+projects = ['fructose', 'glucose', 'honey', 'glucose92',
+ 'fructose84', 'glucose84', 'dextrose3', 'olpc_software']
+cant_langs = len(langs)
+
+out.write('<html><body>')
+out.write('<table>')
+out.write('<tr><th>Module</th><th>Git</th>')
+
+out.write('<head>' +
+ '<style type=text/css>' +
+ 'body {' +
+ ' background-color:#d0e4fe;' +
+ ' font-family:Arial;' +
+ ' font-size:10px;}' +
+ 'p {' +
+ ' font-size:14px;' +
+ ' color:orange;}' +
+ 'th {' +
+ ' background-color:grey;' +
+ ' color:orange;' +
+ ' text-align:center;}' +
+ 'td {' +
+ ' background-color:white;}' +
+ '</style></head>')
+
+for lang in langs:
+ out.write('<th>%s</th>' % lang)
+out.write('</tr>\n')
+
+for project in projects:
+ out.write('<tr><th> %s </th><th></th><th colspan="%d"></th></tr>' %
+ (project, cant_langs))
+ for module in os.listdir(os.path.join(POOTLE_DIR, project)):
+ if not module.endswith('.old') and \
+ not module.endswith('.bak'):
+ module_dir = os.path.join(POOTLE_DIR, project, module)
+ if os.path.isdir(module_dir) and \
+ os.path.isdir(os.path.join(module_dir, 'po')):
+ out.write('<tr><th> %s </th>' % module)
+ # check push status
+ push_status = subprocess.Popen(['sudo', '-u', 'pootle',
+ 'git', 'push', '-n'], stderr=subprocess.PIPE,
+ stdout=subprocess.PIPE).communicate()[1]
+ in_signature = True
+ push_msj = ''
+ #print push_status
+ for line in push_status.split('\n'):
+ if not in_signature:
+ push_msj += line
+ if line == '+-----------------+':
+ in_signature = False
+ if push_msj.endswith('Everything up-to-date') or push_msj == '':
+ out.write('<th>OK</th>')
+ else:
+ out.write('<th><a href="javascript:alert(\'%s\')" ' %
+ push_msj.replace("'","*") + 'style="color:red">ERROR</a></th>')
+
+ # check git status
+ module_state = {}
+ os.chdir(os.path.join(module_dir, 'po'))
+ status = subprocess.Popen(['sudo', '-u', 'pootle',
+ 'git', 'status', '-s'],
+ stdout=subprocess.PIPE).communicate()[0]
+
+
+ for line in status.split('\n'):
+ words = line.split()
+ if words == []:
+ break
+ state = words[0]
+ if words[1].endswith('.po'):
+ lang = words[1][:-3]
+ if lang in langs:
+ module_state[lang] = state
+ for lang in langs:
+ if lang in module_state:
+ out.write('<td>%s</td>' % module_state[lang])
+ else:
+ out.write('<td></td>')
+ out.write('</tr>\n')
+
+
+out.write('</table>')
+out.write('</body></html>')
+
diff --git a/clipi_gtk2.py b/clipi_gtk2.py
new file mode 100644
index 0000000..e986ed8
--- /dev/null
+++ b/clipi_gtk2.py
@@ -0,0 +1,49 @@
+import gtk
+
+def _destroy_cb(widget, data=None):
+ gtk.main_quit()
+
+
+def __copy_clicked_cb(widget):
+ clipboard = gtk.Clipboard()
+ clipboard.set_with_data([('foobar', 0, 0)],
+ __clipboard_get_func_cb,
+ __clipboard_clear_func_cb,
+ '~/file-test/sample-text')
+
+def __clipboard_get_func_cb(clipboard, selectiondata, info, data):
+ print '* __clipboard_get_func_cb data=', data
+ selectiondata.set('STRING', 8, data)
+
+def __clipboard_clear_func_cb(clipboard, data):
+ print '* __clipboard_clear_func_cb'
+
+
+def __paste_clicked_cb(widget):
+ clipboard = gtk.Clipboard()
+ clipboard.request_contents('foobar', __paste_contents_received, None)
+
+def __paste_contents_received(clipboard, selectiondata, data):
+ print '* __paste_contents_received: '
+ print ' - data=', (str(selectiondata.data))
+ print ' - type=', (str(selectiondata.type))
+ print ' - format=', (str(selectiondata.format))
+ print ' - target=', (str(selectiondata.target))
+
+
+window = gtk.Window()
+window.connect("destroy", _destroy_cb)
+
+box = gtk.VBox()
+window.add(box)
+
+button = gtk.Button(label='copy')
+box.add(button)
+button.connect('clicked', __copy_clicked_cb)
+
+button = gtk.Button(label='paste')
+box.add(button)
+button.connect('clicked', __paste_clicked_cb)
+
+window.show_all()
+gtk.main()
diff --git a/clipi_gtk3.py b/clipi_gtk3.py
new file mode 100644
index 0000000..1f395e6
--- /dev/null
+++ b/clipi_gtk3.py
@@ -0,0 +1,49 @@
+from gi.repository import Gtk
+from gi.repository import Gdk
+
+def _destroy_cb(widget, data=None):
+ Gtk.main_quit()
+
+
+def __copy_clicked_cb(widget):
+ clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
+ clipboard.set_with_closures([Gtk.TargetEntry.new('STRING', 0, 0)],
+ __clipboard_get_func_cb,
+ __clipboard_clear_func_cb,
+ None)
+
+def __clipboard_get_func_cb(clipboard, selectiondata, info):
+ print '* __clipboard_get_func_cb data=', data
+ selectiondata.set('STRING', 8, data)
+
+def __clipboard_clear_func_cb(clipboard):
+ print '* __clipboard_clear_func_cb'
+
+
+def __paste_clicked_cb(widget):
+ clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
+ clipboard.request_contents(Gdk.Atom.intern_static_string('STRING'), __paste_contents_received, None)
+
+def __paste_contents_received(clipboard, selectiondata, data):
+ print '* __paste_contents_received: '
+ print ' - data=', (str(selectiondata.get_data()))
+ print ' - format=', (str(selectiondata.get_format()))
+ print ' - target=', (str(selectiondata.get_target()))
+
+
+window = Gtk.Window()
+window.connect("destroy", _destroy_cb)
+
+box = Gtk.VBox()
+window.add(box)
+
+button = Gtk.Button(label='copy')
+box.add(button)
+button.connect('clicked', __copy_clicked_cb)
+
+button = Gtk.Button(label='paste')
+box.add(button)
+button.connect('clicked', __paste_clicked_cb)
+
+window.show_all()
+Gtk.main()
diff --git a/clipi_gtk3_garnacho.py b/clipi_gtk3_garnacho.py
new file mode 100644
index 0000000..8a56bea
--- /dev/null
+++ b/clipi_gtk3_garnacho.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python3
+from gi.repository import Gtk
+from gi.repository import Gdk
+
+def _destroy_cb(widget, data=None):
+ Gtk.main_quit()
+
+
+def __copy_clicked_cb(widget):
+ clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
+ clipboard.set_with_data([Gtk.TargetEntry.new('foobar', 0, 0),
+ Gtk.TargetEntry.new('foobarbaz', 0, 0)],
+ __clipboard_get_func_cb,
+ __clipboard_clear_func_cb,
+ 'hello clipboard')
+
+def __clipboard_get_func_cb(clipboard, selectiondata, info, data):
+ print('* __clipboard_get_func_cb data=', data)
+ selectiondata.set(Gdk.Atom.intern('STRING', False), 8, data)
+
+def __clipboard_clear_func_cb(clipboard, data):
+ print('* __clipboard_clear_func_cb')
+
+
+def __paste_clicked_cb(widget):
+ clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
+ atom = Gdk.Atom.intern('foobar', False)
+ clipboard.request_contents(atom, __paste_contents_received, None)
+
+def __paste_contents_received(clipboard, selectiondata, data):
+ print('* __paste_contents_received: ', selectiondata, data)
+ print(' - data=', (str(selectiondata.get_format())))
+ print(' - type=', (str(selectiondata.get_data())))
+ print(' - format=', (str(selectiondata.get_data_type())))
+ print(' - target=', (str(selectiondata.get_target())))
+
+window = Gtk.Window()
+window.connect("destroy", _destroy_cb)
+
+box = Gtk.VBox()
+window.add(box)
+
+button = Gtk.Button(label='copy')
+box.add(button)
+button.connect('clicked', __copy_clicked_cb)
+
+button = Gtk.Button(label='paste')
+box.add(button)
+button.connect('clicked', __paste_clicked_cb)
+
+window.show_all()
+Gtk.main()
diff --git a/clipi_gtk3_simon.py b/clipi_gtk3_simon.py
new file mode 100644
index 0000000..1f395e6
--- /dev/null
+++ b/clipi_gtk3_simon.py
@@ -0,0 +1,49 @@
+from gi.repository import Gtk
+from gi.repository import Gdk
+
+def _destroy_cb(widget, data=None):
+ Gtk.main_quit()
+
+
+def __copy_clicked_cb(widget):
+ clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
+ clipboard.set_with_closures([Gtk.TargetEntry.new('STRING', 0, 0)],
+ __clipboard_get_func_cb,
+ __clipboard_clear_func_cb,
+ None)
+
+def __clipboard_get_func_cb(clipboard, selectiondata, info):
+ print '* __clipboard_get_func_cb data=', data
+ selectiondata.set('STRING', 8, data)
+
+def __clipboard_clear_func_cb(clipboard):
+ print '* __clipboard_clear_func_cb'
+
+
+def __paste_clicked_cb(widget):
+ clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
+ clipboard.request_contents(Gdk.Atom.intern_static_string('STRING'), __paste_contents_received, None)
+
+def __paste_contents_received(clipboard, selectiondata, data):
+ print '* __paste_contents_received: '
+ print ' - data=', (str(selectiondata.get_data()))
+ print ' - format=', (str(selectiondata.get_format()))
+ print ' - target=', (str(selectiondata.get_target()))
+
+
+window = Gtk.Window()
+window.connect("destroy", _destroy_cb)
+
+box = Gtk.VBox()
+window.add(box)
+
+button = Gtk.Button(label='copy')
+box.add(button)
+button.connect('clicked', __copy_clicked_cb)
+
+button = Gtk.Button(label='paste')
+box.add(button)
+button.connect('clicked', __paste_clicked_cb)
+
+window.show_all()
+Gtk.main()
diff --git a/clock_ex3.py b/clock_ex3.py
new file mode 100644
index 0000000..e51b2a3
--- /dev/null
+++ b/clock_ex3.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+# clock_ex3.py
+
+# a pygtk widget that implements a clock face
+# porting of Davyd Madeley's
+# http://www.gnome.org/~davyd/gnome-journal-cairo-article/clock-ex3.c
+
+# author: Lawrence Oluyede <l.oluyede@gmail.com>
+# date: 03 December 2005
+
+import gtk
+import math
+
+class EggClockFace(gtk.DrawingArea):
+ def __init__(self):
+ super(EggClockFace, self).__init__()
+ self.connect("expose_event", self.expose)
+
+ def expose(self, widget, event):
+ context = widget.window.cairo_create()
+
+ # set a clip region for the expose event
+ context.rectangle(event.area.x, event.area.y,
+ event.area.width, event.area.height)
+ context.clip()
+
+ self.draw(context)
+
+ return False
+
+ def draw(self, context):
+ rect = self.get_allocation()
+ x = rect.x + rect.width / 2.0
+ y = rect.y + rect.height / 2.0
+
+ radius = min(rect.width / 2.0, rect.height / 2.0) - 5
+
+ # clock back
+ context.arc(x, y, radius, 0, 2.0 * math.pi)
+ context.set_source_rgb(1, 1, 1)
+ context.fill_preserve()
+ context.set_source_rgb(0, 0, 0)
+ context.stroke()
+
+ # clock ticks
+ for i in xrange(12):
+ context.save()
+
+ if i % 3 == 0:
+ inset = 0.2 * radius
+ else:
+ inset = 0.1 * radius
+ context.set_line_width(0.5 * context.get_line_width())
+
+ context.move_to(x + (radius - inset) * math.cos(i * math.pi / 6.0),
+ y + (radius - inset) * math.sin(i * math.pi / 6.0))
+ context.line_to(x + radius * math.cos(i * math.pi / 6.0),
+ y + radius * math.sin(i * math.pi / 6.0))
+ context.stroke()
+ context.restore()
+
+
+def main():
+ window = gtk.Window()
+ clock = EggClockFace()
+
+ window.add(clock)
+ window.connect("destroy", gtk.main_quit)
+ window.show_all()
+
+ gtk.main()
+
+if __name__ == "__main__":
+ main()
diff --git a/draw_points.py b/draw_points.py
new file mode 100644
index 0000000..1d9921d
--- /dev/null
+++ b/draw_points.py
@@ -0,0 +1,109 @@
+#!/usr/bin/env python
+# Copyright (C) 2011, One Laptop Per Child
+# Author, Gonzalo Odiard <gonzalo@laptop.org>
+
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import Pango, PangoCairo
+import math
+import logging
+
+t1 = "[(130.0, 58.0), (111, 77), (84, 115), (73, 137), (64, 172), (55, 195), (51, 230), (53, 273), (61, 284), (107, 305), (130, 305), (171, 300), (189, 291), (214, 279), (241, 249), (284, 202), (308, 181), (333, 156), (355, 141), (391, 126), (409, 113), (447, 101), (468, 100), (499, 101), (508, 107), (519, 133), (522, 132)]"
+
+
+class ShowPoints(Gtk.DrawingArea):
+
+ def __init__(self):
+ self.points = []
+ self._mark_next = False
+ self._last_crossproduct = 0
+ super(ShowPoints, self).__init__()
+ self.connect('draw', self.__draw_cb)
+
+ def __draw_cb(self, widget, ctx):
+ i = 0
+ EPS = 100
+ for point in self.points:
+ if self._mark_next:
+ ctx.set_source_rgba(1, 0, 0, 0.7)
+ else:
+ ctx.set_source_rgba(0.3, 0.3, 0.3, 0.7)
+ self._mark_next = False
+
+ crossproduct = 0
+ if i < len(self.points) - 3:
+ # X_ab, Y_ab - coordinates of vector B-A.
+ X_ab = float(self.points[i +1][0] - self.points[i][0])
+ Y_ab = float(self.points[i +1][1] - self.points[i][1])
+
+ # X_ac, Y_ac - coordinates of vector C-A.
+ X_ac = float(self.points[i +2][0] - self.points[i][0])
+ Y_ac = float(self.points[i +2][1] - self.points[i][1])
+
+ crossproduct = Y_ab * X_ac - X_ab * Y_ac
+ if abs(crossproduct) < EPS: # if crossprudct == 0
+ # on the same line.
+ innerproduct = X_ab * X_ac + Y_ab * Y_ac;
+ logging.error('innerproduct %f', innerproduct)
+ if innerproduct > 0:
+ self._mark_next = True
+ i = i + 1
+
+ ctx.save()
+ x, y = point[0], point[1]
+ logging.error('point %d %d', point[0], point[1])
+ ctx.arc(x, y, 5, 0., 2 * math.pi)
+ ctx.fill()
+
+ pango_layout = PangoCairo.create_layout(ctx)
+ fd = Pango.FontDescription('Sans 10')
+ pango_layout.set_font_description(fd)
+ label = str(self._last_crossproduct)
+ pango_layout.set_text(unicode(label), len(unicode(label)))
+ ctx.move_to(x + 20, y + 20)
+ PangoCairo.show_layout(ctx, pango_layout)
+ ctx.stroke()
+ ctx.restore()
+ self._last_crossproduct = crossproduct
+
+
+class SPWin(Gtk.Window):
+
+ def __init__(self):
+ super(Gtk.Window, self).__init__( )
+ vbox = Gtk.VBox()
+ self.add(vbox)
+ self.show_points = ShowPoints()
+ vbox.add(self.show_points)
+ self.entry = Gtk.Entry()
+ self.entry.set_text(t1)
+ vbox.add(self.entry)
+ self.entry.connect('activate', self.show_points_from_entry)
+ self.connect("destroy", Gtk.main_quit)
+ self.show_all()
+ self.maximize()
+
+ def show_points_from_entry(self, entry):
+ self.show_points.points = self.parse_points(entry.get_text())
+ self.show_points.queue_draw()
+
+ def parse_points(self, text):
+ points_list = []
+ pairs = text.split('),')
+ for pair in pairs:
+ parts = pair.split(',')
+ xs = parts[0].replace('[','').replace('(','').replace(')','').replace(']','')
+ ys = parts[1].replace('[','').replace('(','').replace(')','').replace(']','')
+ x, y = int(float(xs)), int(float(ys))
+ points_list.append((x, y))
+ return points_list
+
+ #def update_points(entry):
+
+
+def main():
+ window = SPWin()
+ Gtk.main()
+
+if __name__ == "__main__":
+ main()
diff --git a/ebook_mode.py b/ebook_mode.py
new file mode 100644
index 0000000..ce45d6e
--- /dev/null
+++ b/ebook_mode.py
@@ -0,0 +1,20 @@
+import os
+import subprocess
+import logging
+
+def _is_tablet_mode():
+ if not os.path.exists('/dev/input/event4'):
+ return False
+ try:
+ output = subprocess.call(
+ ['/bin/evtest', '--query', '/dev/input/event4', 'EV_SW',
+ 'SW_TABLET_MODE'])
+ except subprocess.CalledProcessError:
+ return False
+ logging.error('output %s',output)
+ if output == '10':
+ return True
+ return False
+
+
+_is_tablet_mode()
diff --git a/fake_menu_test.py b/fake_menu_test.py
new file mode 100644
index 0000000..6a1621d
--- /dev/null
+++ b/fake_menu_test.py
@@ -0,0 +1,61 @@
+import cairo
+import gtk
+import sys
+from sugar.graphics import style
+from sugar.graphics.icon import Icon
+
+
+class FakeMenuItem(gtk.EventBox):
+
+ __gsignals__ = {
+ 'clicked': (gobject.SIGNAL_RUN_FIRST, None, [])
+ }
+
+ def __init__(self, icon_name, label_text):
+ gtk.EventBox.__init__(self)
+ hbox = gtk.HBox()
+ self.icon = Icon()
+ self.icon.props.icon_name = icon_name
+ hbox.pack_start(self.icon, expand=False, fill=False, padding=10)
+ aligment = gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0)
+ text = '<span foreground="%s">' % style.COLOR_WHITE.get_html() + \
+ label_text + '</span>'
+ self.label = gtk.Label()
+ self.label.set_use_markup(True)
+ self.label.set_markup(text)
+ aligment.add(self.label)
+ hbox.pack_start(aligment, expand=True, fill=True, padding=10)
+ self.add(hbox)
+ self.connect('button-release-event', self.__button_release_cb)
+ self.connect('enter-notify-event', self.__enter_notify_cb)
+ self.connect('leave-notify-event', self.__leave_notify_cb)
+ self.modify_bg(gtk.STATE_NORMAL, style.COLOR_BLACK.get_gdk_color())
+ self.show_all()
+ self.set_above_child(True)
+
+ def __button_release_cb(self, widget, event):
+ self.emit('clicked')
+
+ def __enter_notify_cb(self, widget, event):
+ self.modify_bg(gtk.STATE_NORMAL, style.COLOR_PANEL_GREY.get_gdk_color())
+
+ def __leave_notify_cb(self, widget, event):
+ self.modify_bg(gtk.STATE_NORMAL, style.COLOR_BLACK.get_gdk_color())
+
+def main():
+ win = gtk.Window()
+ win.connect('destroy', gtk.main_quit)
+ win.set_default_size(450, 550)
+ fake_memu = FakeMenuItem('player_play', 'Say text')
+ vbox = gtk.VBox()
+ win.add(vbox)
+ vbox.add(gtk.Label('Before 1'))
+ vbox.add(gtk.Label('Before 2'))
+ vbox.add(fake_memu)
+ vbox.add(gtk.Label('After 1'))
+ vbox.add(gtk.Label('After 2'))
+ win.show_all()
+ gtk.main()
+
+if __name__ == '__main__':
+ main()
diff --git a/filechooser.py b/filechooser.py
new file mode 100644
index 0000000..16a52d7
--- /dev/null
+++ b/filechooser.py
@@ -0,0 +1,327 @@
+# Copyright (C) 2007, One Laptop Per Child
+#
+# 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 2 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
+
+from gettext import gettext as _
+import logging
+import os
+import time
+
+from gi.repository import GObject
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import Wnck
+from gi.repository import Pango
+from gi.repository import Gio
+
+
+from sugar3.graphics import style
+from sugar3 import util
+from sugar3.graphics.toolbutton import ToolButton
+from sugar3.graphics.icon import CellRendererIcon
+
+
+class FileChooser(Gtk.Window):
+
+ __gtype_name__ = 'ObjectChooser'
+
+ __gsignals__ = {
+ 'response': (GObject.SignalFlags.RUN_FIRST, None, ([int])),
+ }
+
+ def __init__(self, title, directory, parent=None):
+ Gtk.Window.__init__(self)
+ self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
+ self.set_decorated(False)
+ self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
+ self.set_border_width(style.LINE_WIDTH)
+ self.set_has_resize_grip(False)
+
+ self._selected_object_id = None
+
+ self.add_events(Gdk.EventMask.VISIBILITY_NOTIFY_MASK)
+ self.connect('delete-event', self.__delete_event_cb)
+ self.connect('key-press-event', self.__key_press_event_cb)
+
+ if parent is None:
+ logging.warning('FileChooser: No parent window specified')
+ else:
+ self.connect('realize', self.__realize_cb, parent)
+
+ screen = Wnck.Screen.get_default()
+ screen.connect('window-closed', self.__window_closed_cb, parent)
+
+ vbox = Gtk.VBox()
+ self.add(vbox)
+ vbox.show()
+
+ title_box = TitleBox(title)
+ title_box.close_button.connect('clicked',
+ self.__close_button_clicked_cb)
+ title_box.set_size_request(-1, style.GRID_CELL_SIZE)
+ vbox.pack_start(title_box, False, True, 0)
+ title_box.show()
+
+ separator = Gtk.HSeparator()
+ vbox.pack_start(separator, False, True, 0)
+ separator.show()
+
+ self._list_view = FileListView(directory)
+ self._list_view.connect('entry-activated',
+ self.__entry_activated_cb)
+ vbox.pack_start(self._list_view, True, True, 0)
+ self._list_view.show()
+
+ width = Gdk.Screen.width() - style.GRID_CELL_SIZE * 2
+ height = Gdk.Screen.height() - style.GRID_CELL_SIZE * 2
+ self.set_size_request(width, height)
+
+ def __realize_cb(self, chooser, parent):
+ self.get_window().set_transient_for(parent)
+ # TODO: Should we disconnect the signal here?
+
+ def __window_closed_cb(self, screen, window, parent):
+ self.destroy()
+
+ def __entry_activated_cb(self, list_view, uid):
+ self._selected_object_id = uid
+ self.emit('response', Gtk.ResponseType.ACCEPT)
+
+ def __delete_event_cb(self, chooser, event):
+ self.emit('response', Gtk.ResponseType.DELETE_EVENT)
+
+ def __key_press_event_cb(self, widget, event):
+ keyname = Gdk.keyval_name(event.keyval)
+ if keyname == 'Escape':
+ self.emit('response', Gtk.ResponseType.DELETE_EVENT)
+
+ def __close_button_clicked_cb(self, button):
+ self.emit('response', Gtk.ResponseType.DELETE_EVENT)
+
+ def get_selected_object_id(self):
+ return self._selected_object_id
+
+
+class TitleBox(Gtk.Toolbar):
+ __gtype_name__ = 'TitleBox'
+
+ def __init__(self, title):
+ Gtk.Toolbar.__init__(self)
+
+ label = Gtk.Label()
+ label.set_markup('<b>%s</b>' % title)
+ label.set_alignment(0, 0.5)
+ self._add_widget(label, expand=True)
+
+ self.close_button = ToolButton(icon_name='dialog-cancel')
+ self.close_button.set_tooltip(_('Close'))
+ self.insert(self.close_button, -1)
+ self.close_button.show()
+
+ def _add_widget(self, widget, expand=False):
+ tool_item = Gtk.ToolItem()
+ tool_item.set_expand(expand)
+
+ tool_item.add(widget)
+ widget.show()
+
+ self.insert(tool_item, -1)
+ tool_item.show()
+
+
+class TreeView(Gtk.TreeView):
+ __gtype_name__ = 'JournalTreeView'
+
+ def __init__(self):
+ Gtk.TreeView.__init__(self)
+ self.set_headers_visible(False)
+ self.set_enable_search(False)
+ self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
+ Gdk.EventMask.TOUCH_MASK |
+ Gdk.EventMask.BUTTON_RELEASE_MASK)
+
+ def do_size_request(self, requisition):
+ tree_model = self.get_model()
+ if tree_model is not None:
+ tree_model.view_is_resizing = True
+ try:
+ Gtk.TreeView.do_size_request(self, requisition)
+ finally:
+ if tree_model is not None:
+ tree_model.view_is_resizing = False
+
+COLUMN_PATH = 0
+COLUMN_TITLE = 1
+COLUMN_MIME = 2
+COLUMN_TIMESTAMP = 3
+
+
+class FileListView(Gtk.Bin):
+
+ __gtype_name__ = 'JournalFileListView'
+
+ __gsignals__ = {
+ 'entry-activated': (GObject.SignalFlags.RUN_FIRST,
+ None,
+ ([str])),
+ }
+
+ def __init__(self, directory):
+ self._query = {}
+ self._directory = directory
+ self._model = None
+ self._progress_bar = None
+ self._last_progress_bar_pulse = None
+ self._scroll_position = 0.
+
+ Gtk.Bin.__init__(self)
+
+ self._scrolled_window = Gtk.ScrolledWindow()
+ self._scrolled_window.set_policy(Gtk.PolicyType.NEVER,
+ Gtk.PolicyType.AUTOMATIC)
+ self.add(self._scrolled_window)
+ self._scrolled_window.show()
+
+ self.tree_view = TreeView()
+ selection = self.tree_view.get_selection()
+ selection.set_mode(Gtk.SelectionMode.NONE)
+ self.tree_view.props.fixed_height_mode = True
+ self._scrolled_window.add(self.tree_view)
+ self.tree_view.show()
+
+ self.cell_title = None
+ self.cell_icon = None
+ self._title_column = None
+ self.sort_column = None
+ self._add_columns()
+
+ # Auto-update stuff
+ self._fully_obscured = True
+ self._dirty = False
+
+ #self.cell_icon.props.show_palette = False
+ self.tree_view.props.hover_selection = True
+
+ self.tree_view.connect('button-release-event',
+ self.__button_release_event_cb)
+
+ GObject.idle_add(self._load_model)
+
+ def __entry_activated_cb(self, entry):
+ self.emit('entry-activated', entry)
+
+ def __button_release_event_cb(self, tree_view, event):
+ if event.window != tree_view.get_bin_window():
+ return False
+
+ pos = tree_view.get_path_at_pos(int(event.x), int(event.y))
+ if pos is None:
+ return False
+
+ path, column_, x_, y_ = pos
+ uid = tree_view.get_model()[path][COLUMN_PATH]
+ self.emit('entry-activated', uid)
+
+ return False
+
+ def _load_model(self):
+ self._model = Gtk.ListStore(str, str, str)
+ # append the values in the model
+ for root, dirs, files in os.walk(self._directory):
+ for f in files:
+ full_path = os.path.join(root, f)
+ mime_type, uncertain_result_ = \
+ Gio.content_type_guess(filename=full_path, data=None)
+ logging.error('MIME TYPE %s', mime_type)
+ self._model.append([full_path, f, mime_type])
+ self.tree_view.set_model(self._model)
+
+ def _add_columns(self):
+
+ self.cell_icon = CellRendererActivityIcon(self.tree_view)
+
+ column = Gtk.TreeViewColumn()
+ column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
+ column.props.fixed_width = self.cell_icon.props.width
+ column.pack_start(self.cell_icon, True)
+ column.add_attribute(self.cell_icon, 'file-name',
+ COLUMN_MIME)
+ #column.add_attribute(self.cell_icon, 'xo-color',
+ # COLUMN_MIME)
+ self.tree_view.append_column(column)
+
+ self.cell_title = Gtk.CellRendererText()
+ self.cell_title.props.ellipsize = Pango.EllipsizeMode.MIDDLE
+ self.cell_title.props.ellipsize_set = True
+
+ self._title_column = Gtk.TreeViewColumn()
+ self._title_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
+ self._title_column.props.expand = True
+ self._title_column.props.clickable = True
+ self._title_column.pack_start(self.cell_title, True)
+ self._title_column.add_attribute(self.cell_title, 'markup',
+ COLUMN_TITLE)
+ self.tree_view.append_column(self._title_column)
+
+ cell_text = Gtk.CellRendererText()
+ cell_text.props.xalign = 1
+
+ # Measure the required width for a date in the form of "10 hours, 10
+ # minutes ago"
+ timestamp = time.time() - 10 * 60 - 10 * 60 * 60
+ date = util.timestamp_to_elapsed_string(timestamp)
+ date_width = self._get_width_for_string(date)
+
+ self.sort_column = Gtk.TreeViewColumn()
+ self.sort_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
+ self.sort_column.props.fixed_width = date_width
+ self.sort_column.set_alignment(1)
+ self.sort_column.props.resizable = True
+ self.sort_column.props.clickable = True
+ self.sort_column.pack_start(cell_text, True)
+ self.sort_column.add_attribute(cell_text, 'text',
+ COLUMN_TIMESTAMP)
+ self.tree_view.append_column(self.sort_column)
+
+ def _get_width_for_string(self, text):
+ # Add some extra margin
+ text = text + 'aaaaa'
+
+ widget = Gtk.Label(label='')
+ context = widget.get_pango_context()
+ layout = Pango.Layout(context)
+ layout.set_text(text, len(text))
+ width, height_ = layout.get_pixel_size()
+ return width
+
+ def do_size_allocate(self, allocation):
+ self.set_allocation(allocation)
+ self.get_child().size_allocate(allocation)
+
+ def do_size_request(self, requisition):
+ requisition.width, requisition.height = \
+ self.get_child().size_request()
+
+class CellRendererActivityIcon(CellRendererIcon):
+ __gtype_name__ = 'JournalCellRendererActivityIcon'
+
+ def __init__(self, tree_view):
+ CellRendererIcon.__init__(self, tree_view)
+
+ self.props.width = style.GRID_CELL_SIZE
+ self.props.height = style.GRID_CELL_SIZE
+ self.props.size = style.STANDARD_ICON_SIZE
+ self.props.mode = Gtk.CellRendererMode.ACTIVATABLE
+ self.tree_view = tree_view
diff --git a/gconf_monitor_test.py b/gconf_monitor_test.py
new file mode 100644
index 0000000..6a6b1d7
--- /dev/null
+++ b/gconf_monitor_test.py
@@ -0,0 +1,31 @@
+from gi.repository import Gtk
+from gi.repository import GConf
+
+import logging
+
+def gconf_event_cb(client, timestamp, entry, *extra):
+ logging.error('GCONF CHANGED %s', client.get_string('/test/blabla'))
+
+def change_value_cb(widget, client):
+ text = widget.get_text()
+ logging.error('Before changing gconf value %s', text)
+ client.set_string('/test/blabla', text)
+
+window = Gtk.Window()
+window.connect('destroy',
+ lambda sender: Gtk.main_quit())
+
+box = Gtk.VBox()
+window.add(box)
+
+entry = Gtk.Entry()
+box.add(entry)
+
+client = GConf.Client.get_default()
+client.add_dir('/test/blabla', GConf.ClientPreloadType.PRELOAD_NONE)
+client.notify_add('/test/blabla', gconf_event_cb, None)
+
+entry.connect('activate', change_value_cb, client)
+
+window.show_all()
+Gtk.main()
diff --git a/gestures_new.py b/gestures_new.py
new file mode 100644
index 0000000..0eca5a6
--- /dev/null
+++ b/gestures_new.py
@@ -0,0 +1,55 @@
+from gi.repository import WebKit
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import SugarGestures
+
+def _destroy_cb(widget, data=None):
+ Gtk.main_quit()
+
+def _swipe_ended_cb(controller, direction):
+ print direction
+ if direction == SugarGestures.SwipeDirection.UP:
+ print '==> UP'
+ elif direction == SugarGestures.SwipeDirection.DOWN:
+ print '==> DOWN'
+ elif direction == SugarGestures.SwipeDirection.RIGHT:
+ print '==> RIGHT'
+ elif direction == SugarGestures.SwipeDirection.LEFT:
+ print '==> LEFT'
+
+def _lp_began_cb(controller):
+ print '===> lp began'
+
+def _scale_changed_cb(controller, scale):
+ print '===> zoom changed scale=%s', scale
+
+def _angle_changed_cb(controller, angle, diff):
+ print '===> rotate changed: ', angle, diff
+
+
+window = Gtk.Window()
+window.set_default_size(800, 640)
+window.connect("destroy", _destroy_cb)
+window.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
+ Gdk.EventMask.BUTTON_RELEASE_MASK |
+ Gdk.EventMask.POINTER_MOTION_MASK |
+ Gdk.EventMask.TOUCH_MASK)
+
+zoom = SugarGestures.ZoomController()
+zoom.connect('scale-changed', _scale_changed_cb)
+zoom.attach(window, SugarGestures.EventControllerFlags.NONE)
+
+rotate = SugarGestures.RotateController()
+rotate.connect('angle-changed', _angle_changed_cb)
+rotate.attach(window, SugarGestures.EventControllerFlags.NONE)
+
+swipe = SugarGestures.SwipeController()
+swipe.connect('swipe-ended', _swipe_ended_cb)
+swipe.attach(window, SugarGestures.EventControllerFlags.NONE)
+
+lp = SugarGestures.LongPressController(trigger_delay=1000)
+lp.connect('began', _lp_began_cb)
+lp.attach(window, SugarGestures.EventControllerFlags.NONE)
+
+window.show()
+Gtk.main()
diff --git a/get_title.py b/get_title.py
new file mode 100644
index 0000000..c76c7b1
--- /dev/null
+++ b/get_title.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import gst
+import gobject
+
+class TagGetter:
+ def __init__(self):
+ # dictionary to hold our tag info
+ self.file_tags = {}
+ # a playbin to parse the audio file
+ self.playbin = gst.element_factory_make("playbin")
+ # we need to receive tag signals from the playbin's bus
+ self.bus = self.playbin.get_bus()
+ self.bus.enable_sync_message_emission()
+ self.bus.add_signal_watch()
+ self.bus.connect("message::tag", self.on_message_tag)
+
+ def on_message_tag(self, bus, message):
+ """We received a tag message."""
+ taglist = message.parse_tag()
+ for key in taglist.keys():
+ self.file_tags[key] = taglist[key]
+ print key, '=', taglist[key]
+ """
+ # if we have the title tag, we can return
+ if self.file_tags.get('title', False):
+ title = self.file_tags.get('title', 'Unknown title')
+ artist = self.file_tags.get('artist', 'Unknown artist')
+ print "%s - %s" % (title, artist)
+ self.playbin.set_state(gst.STATE_NULL)
+ """
+
+ def set_uri(self, file_path):
+ # set the uri of the playbin to our audio file
+ print file_path
+ self.playbin.set_property("uri", file_path)
+ # pause the playbin, we don't really need to play
+ self.playbin.set_state(gst.STATE_P)
+
+
+if __name__=="__main__":
+ if len(sys.argv) > 1:
+ file_name = sys.argv[1]
+ getter = TagGetter()
+ getter.set_uri(file_name)
+
+ # create a loop to control our app
+ mainloop = gobject.MainLoop()
+ mainloop.run()
+
+ else:
+ print "select an audio file"
diff --git a/get_title2.py b/get_title2.py
new file mode 100644
index 0000000..f1370ae
--- /dev/null
+++ b/get_title2.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+import os
+import sys
+import gst
+import gobject
+
+class tag_getter:
+ def __init__(self):
+ #make a dictionary to hold our tag info
+ self.file_tags = {}
+ #make a playbin to parse the audio file
+ self.pbin = gst.element_factory_make("playbin")
+ #we need to receive signals from the playbin's bus
+ self.bus = self.pbin.get_bus()
+ #make sure we are watching the signals on the bus
+ self.bus.add_signal_watch()
+ #what do we do when a tag is part of the bus signal?
+ self.bus.connect("message::tag", self.bus_message_tag)
+ #create a loop to control our app
+ self.mainloop = gobject.MainLoop()
+
+ def bus_message_tag (self, bus, message):
+ #we received a tag message
+ taglist = message.parse_tag()
+ #put the keys in the dictionary
+ for key in taglist.keys():
+ self.file_tags[key] = taglist[key]
+ print key, '=', taglist[key]
+ #for this test, if we have the artist tag, we can quit
+ if self.file_tags['artist']:
+ print self.file_tags
+ sys.exit()
+
+ def set_file(self,file):
+ #set the uri of the playbin to our audio file
+ self.pbin.set_property("uri","file://"+file)
+ #pause the playbin, we don't really need to play
+ self.pbin.set_state(gst.STATE_PAUSED)
+
+ def run(self):
+ #start the main loop
+ self.mainloop.run()
+
+if __name__=="__main__":
+ if len(sys.argv)>1:
+ file = sys.argv[1]
+ pwd = os.getcwd()
+ filepath = os.path.join(pwd,file)
+ getter = tag_getter()
+ getter.set_file(file)
+ getter.run()
+
+ else:
+ print "select an audio file"
diff --git a/gst_volume_view.py b/gst_volume_view.py
new file mode 100644
index 0000000..d0fb1f6
--- /dev/null
+++ b/gst_volume_view.py
@@ -0,0 +1,36 @@
+from gi.repository import Gst
+from gi.repository import GLib
+
+import sys
+
+mainloop = GLib.MainLoop()
+
+def _messageCb(bus, message):
+ if str(type(message.src)) == "<class '__main__.__main__.GstLevel'>":
+ s = message.get_structure()
+ p = None
+ if s:
+ p = s.get_value("rms")
+ if p:
+ st = s.get_value("stream-time")
+ print "rms = " + str(p) + "; stream-time = " + str(st)
+
+ if message.type == Gst.MessageType.EOS:
+ mainloop.quit()
+
+ elif message.type == Gst.MessageType.ERROR:
+ bus.disconnect_by_func(_messageCb)
+ mainloop.quit()
+
+
+if __name__=="__main__":
+ #global mainloop
+ Gst.init([])
+ pipeline = Gst.parse_launch("uridecodebin name=decode uri=" + sys.argv[1] + " ! audioconvert ! level name=wavelevel interval=10000000 post-messages=true ! fakesink qos=false name=faked")
+ faked = pipeline.get_by_name("faked")
+ bus = pipeline.get_bus()
+ bus.add_signal_watch()
+ bus.connect("message", _messageCb)
+ pipeline.set_state(Gst.State.PLAYING)
+ mainloop.run()
+ pipeline.set_state(Gst.State.NULL)
diff --git a/gtk3-drag-and-drop-example.py b/gtk3-drag-and-drop-example.py
new file mode 100644
index 0000000..4a899b7
--- /dev/null
+++ b/gtk3-drag-and-drop-example.py
@@ -0,0 +1,73 @@
+from gi.repository import Gtk
+from gi.repository import GdkPixbuf
+from gi.repository import Gdk
+from gi.repository import Pango
+
+# The images used in this example are these ones:
+# http://git.gnome.org/browse/pygobject/tree/demos/gtk-demo/demos/data/apple-red.png
+
+def _destroy_cb(widget, data=None):
+ Gtk.main_quit()
+
+def drag_begin_event(widget, context, data):
+ print 'drag_BEGIN_event'
+ widget.drag_source_set_icon_pixbuf(widget.get_child().get_pixbuf())
+
+def drag_data_get_event(widget, context, selection_data, info,
+ timestamp, data):
+ print 'drag_data_GET_event'
+ selection_data.set_pixbuf(widget.get_child().get_pixbuf())
+
+def drag_data_received_event(widget, drag_context, x, y, data,
+ info, time, user_data):
+ print 'drag_data_RECEIVED_event'
+ if user_data == 'Image':
+ widget.set_from_pixbuf(data.get_pixbuf())
+ elif user_data == 'TextView':
+ buf = widget.get_buffer()
+ buf.insert_pixbuf(buf.get_start_iter(), data.get_pixbuf())
+ Gtk.drag_finish(drag_context, True, False, time)
+
+window = Gtk.Window()
+window.set_title('Gtk3 Drag And Drop Example')
+window.set_default_size(300, 180)
+window.connect("destroy", _destroy_cb)
+
+
+image = Gtk.Image()
+imagebuf = GdkPixbuf.Pixbuf.new_from_file('apple-red.png')
+image.set_from_pixbuf(imagebuf)
+
+imagebox = Gtk.EventBox()
+imagebox.add(image)
+
+imagebox.drag_source_set(
+ Gdk.ModifierType.BUTTON1_MASK,
+ [],
+ Gdk.DragAction.COPY)
+imagebox.drag_source_add_image_targets()
+
+imagebox.connect('drag-begin', drag_begin_event, None)
+imagebox.connect('drag-data-get', drag_data_get_event, None)
+
+hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
+hbox.pack_start(imagebox, True, True, 10)
+
+text = Gtk.TextView()
+text.set_wrap_mode(Gtk.WrapMode.WORD)
+text.set_editable(True)
+text.modify_font(Pango.FontDescription('arial 12'))
+text.connect('drag-data-received', drag_data_received_event, 'TextView')
+text.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
+# text.drag_dest_set_target_list(None)
+text.drag_dest_add_text_targets()
+text.drag_dest_add_image_targets()
+
+vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+vbox.add(hbox)
+vbox.add(text)
+
+window.add(vbox)
+
+window.show_all()
+Gtk.main()
diff --git a/gtk3_test_draganddrop.py b/gtk3_test_draganddrop.py
new file mode 100644
index 0000000..c78d089
--- /dev/null
+++ b/gtk3_test_draganddrop.py
@@ -0,0 +1,59 @@
+from gi.repository import Gtk, Gdk, GdkPixbuf
+
+
+class DragDropWindow(Gtk.Window):
+
+ def __init__(self):
+ Gtk.Window.__init__(self, title="Drag and Drop Demo")
+
+ hbox = Gtk.Box(spacing=12)
+ self.add(hbox)
+
+ self.drag_source = DragSource()
+ self.drop_area = DropArea()
+
+ hbox.pack_start(self.drag_source, True, True, 0)
+ hbox.pack_start(self.drop_area, True, True, 0)
+
+ self.drag_source.drag_source_add_image_targets()
+ self.drop_area.drag_dest_add_image_targets()
+
+
+class DragSource(Gtk.EventBox):
+
+ def __init__(self):
+ Gtk.EventBox.__init__(self)
+ self.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, [],
+ Gdk.DragAction.COPY)
+
+ self.connect('drag-begin', self.drag_begin_event)
+ self.connect("drag-data-get", self.on_drag_data_get)
+
+ image = Gtk.Image()
+ self.pixbuf = GdkPixbuf.Pixbuf.new_from_file('apple-red.png')
+ image.set_from_pixbuf(self.pixbuf)
+ self.add(image)
+
+ def drag_begin_event(self, widget, context):
+ self.drag_source_set_icon_pixbuf(self.pixbuf)
+
+ def on_drag_data_get(self, widget, drag_context, data, info, time):
+ print "DRAG-N-DROP"
+
+
+class DropArea(Gtk.EventBox):
+
+ def __init__(self):
+ Gtk.EventBox.__init__(self)
+ self.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
+
+ destination_image = Gtk.Image()
+ imagebuf = GdkPixbuf.Pixbuf.new_from_file('gnome-foot.png')
+ destination_image.set_from_pixbuf(imagebuf)
+ self.add(destination_image)
+
+
+win = DragDropWindow()
+win.connect("delete-event", Gtk.main_quit)
+win.show_all()
+Gtk.main() \ No newline at end of file
diff --git a/icon_viewer.py b/icon_viewer.py
index ef94ec6..0091c0c 100755
--- a/icon_viewer.py
+++ b/icon_viewer.py
@@ -1,22 +1,22 @@
-import cairo
-import gtk
+
+from gi.repository import Gtk
import sys
-from icon import Icon
-from xocolor import XoColor
+from sugar3.graphics.icon import Icon
+from sugar3.graphics.xocolor import XoColor
def main():
if len(sys.argv) == 1:
print "Use icon_viewer icon_file.svg"
return
icon_file_name = sys.argv[1]
- win = gtk.Window()
- win.connect('destroy', gtk.main_quit)
+ win = Gtk.Window()
+ win.connect('destroy', Gtk.main_quit)
win.set_default_size(450, 550)
test_icon = Icon(file=icon_file_name, pixel_size=100, xo_color=XoColor('#FF8F00,#FF2B34'))
win.add(test_icon)
win.show_all()
- gtk.main()
+ Gtk.main()
if __name__ == '__main__':
main()
diff --git a/key_values.py b/key_values.py
new file mode 100644
index 0000000..8e748fa
--- /dev/null
+++ b/key_values.py
@@ -0,0 +1,25 @@
+from gi.repository import Gtk
+from gi.repository import Gdk
+
+def _destroy_cb(widget, data=None):
+ Gtk.main_quit()
+
+
+def event_cb(widget, event):
+ print Gdk.keyval_name(event.keyval)
+
+window = Gtk.Window()
+window.connect("destroy", _destroy_cb)
+
+box = Gtk.EventBox()
+
+box.set_events(Gdk.EventMask.KEY_PRESS_MASK)
+
+box.connect('key_press_event', event_cb)
+window.add(box)
+box.set_can_focus(True)
+box.grab_focus()
+
+
+window.show_all()
+Gtk.main()
diff --git a/label_pango_layout.py b/label_pango_layout.py
new file mode 100644
index 0000000..94ef5b9
--- /dev/null
+++ b/label_pango_layout.py
@@ -0,0 +1,46 @@
+from gi.repository import Gtk
+from gi.repository import Pango
+
+LONG_TEXT = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam'
+
+class MyLabel(Gtk.Label):
+
+ def __init__(self, text, width, rows):
+ Gtk.Label.__init__(self)
+ self.set_text(text)
+ self._width = width
+ self._height = 100
+ self._rows = rows
+ self.set_single_line_mode(False)
+ self.connect('draw', self._draw)
+ self.connect('size_allocate', self._size_allocate)
+ self.set_size_request(self._width, -1)
+
+ def _size_allocate(self, label, allocation):
+ allocation.width = self._width
+ allocation.height = self._height
+ self.size_allocate(allocation)
+
+ def _draw(self, label, context):
+ layout = label.get_layout()
+ layout.set_wrap(Pango.WrapMode.WORD)
+ layout.set_ellipsize(Pango.EllipsizeMode.END)
+ layout.set_height(- self._rows)
+ layout.set_width(self._width * Pango.SCALE)
+ width, height = layout.get_size()
+ self._width, self._height = width / Pango.SCALE, height / Pango.SCALE
+ print self._width, self._height
+ self.set_size_request(self._width, self._height)
+ #self.queue_resize()
+
+win = Gtk.Window()
+box = Gtk.VBox()
+
+label = MyLabel(LONG_TEXT, 300, 3)
+
+box.add(label)
+win.add(box)
+
+win.connect("delete-event", Gtk.main_quit)
+win.show_all()
+Gtk.main()
diff --git a/mini_abi_gtk3.py b/mini_abi_gtk3.py
new file mode 100644
index 0000000..251cd3d
--- /dev/null
+++ b/mini_abi_gtk3.py
@@ -0,0 +1,9 @@
+from gi.repository import Gtk
+from gi.repository import Abi
+
+win = Gtk.Window()
+abi = Abi.Widget()
+win.add(abi)
+win.show_all()
+win.connect("destroy", Gtk.main_quit)
+Gtk.main()
diff --git a/mini_abi_gtk3_b.py b/mini_abi_gtk3_b.py
new file mode 100644
index 0000000..a151ab7
--- /dev/null
+++ b/mini_abi_gtk3_b.py
@@ -0,0 +1,16 @@
+from gi.repository import Gtk
+from gi.repository import Abi
+
+win = Gtk.Window()
+vbox = Gtk.VBox()
+label = Gtk.Label(label='test')
+vbox.add(label)
+abi = Abi.Widget()
+scrolled = Gtk.ScrolledWindow()
+win.add(vbox)
+vbox.add(scrolled)
+scrolled.add_with_viewport(abi)
+abi.show()
+win.show_all()
+win.connect("destroy", Gtk.main_quit)
+Gtk.main()
diff --git a/minimal_webkit.py b/minimal_webkit.py
new file mode 100644
index 0000000..b168afe
--- /dev/null
+++ b/minimal_webkit.py
@@ -0,0 +1,14 @@
+from gi.repository import WebKit
+from gi.repository import Gtk
+
+def _destroy_cb(widget):
+ Gtk.main_quit()
+
+window = Gtk.Window()
+window.set_default_size(800, 640)
+window.connect("destroy", _destroy_cb)
+b = WebKit.WebView()
+b.load_uri('http://google.com')
+window.add(b)
+window.show_all()
+Gtk.main()
diff --git a/nm_list_devices.py b/nm_list_devices.py
new file mode 100644
index 0000000..5d9b8c4
--- /dev/null
+++ b/nm_list_devices.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+#
+# 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 2 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Copyright (C) 2011 - 2012 Red Hat, Inc.
+#
+
+import dbus, sys
+
+# This example lists basic information about network interfaces known to NM
+
+devtypes = { 1: "Ethernet",
+ 2: "Wi-Fi",
+ 5: "Bluetooth",
+ 6: "OLPC",
+ 7: "WiMAX",
+ 8: "Modem",
+ 9: "InfiniBand",
+ 10: "Bond",
+ 11: "VLAN",
+ 12: "ADSL" }
+
+states = { 0: "Unknown",
+ 10: "Unmanaged",
+ 20: "Unavailable",
+ 30: "Disconnected",
+ 40: "Prepare",
+ 50: "Config",
+ 60: "Need Auth",
+ 70: "IP Config",
+ 80: "IP Check",
+ 90: "Secondaries",
+ 100: "Activated",
+ 110: "Deactivating",
+ 120: "Failed" }
+
+bus = dbus.SystemBus()
+
+# Get a proxy for the base NetworkManager object
+proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager")
+manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager")
+
+# Get all devices known to NM and print their properties
+devices = manager.GetDevices()
+for d in devices:
+ dev_proxy = bus.get_object("org.freedesktop.NetworkManager", d)
+ prop_iface = dbus.Interface(dev_proxy, "org.freedesktop.DBus.Properties")
+ props = prop_iface.GetAll("org.freedesktop.NetworkManager.Device")
+ print "============================"
+ print props
+
+ print "Interface: %s" % props['Interface']
+ try:
+ devtype = devtypes[props['DeviceType']]
+ except KeyError:
+ devtype = "Unknown"
+ print "Type: %s" % devtype
+
+ print "Driver: %s" % props['Driver']
+
+ try:
+ state = states[props['State']]
+ except KeyError:
+ state = "Unknown"
+ print "State: %s" % state
+
diff --git a/notifications.py b/notifications.py
new file mode 100644
index 0000000..7ae3902
--- /dev/null
+++ b/notifications.py
@@ -0,0 +1,8 @@
+import dbus
+BUS_NAME = 'org.freedesktop.Notifications'
+OBJ_PATH = '/org/freedesktop/Notifications'
+IFACE_NAME = 'org.freedesktop.Notifications'
+bus = dbus.SessionBus()
+notify_obj = bus.get_object(BUS_NAME,OBJ_PATH)
+notifications = dbus.Interface(notify_obj,IFACE_NAME)
+notifications.Notify("Software Update", 0, "", "New activities are available!", "Please check your activities list", [], {'x-sugar-icon-name': 'module-updater'}, -1)
diff --git a/open_html.py b/open_html.py
new file mode 100644
index 0000000..690c90f
--- /dev/null
+++ b/open_html.py
@@ -0,0 +1,27 @@
+from gi.repository import Gtk
+from gi.repository import WebKit
+
+webview = WebKit.WebView()
+
+data = {'name': 'Butterfly', 'icon_name': 'butterflies',
+ 'video': 'Butterflies.mp4', 'icon_position': (-0.7, 0.1),
+ 'text': _('The monarch butterfly is famous for its southward '
+ 'migration and northward return in summer from '
+ 'Canada to Mexico and Baja California which spans '
+ 'the life of three to four generations of the '
+ 'butterfly. \n\n'
+ 'The journey is 3000 miles and take 6 months')}
+
+data['title'] = _('Did you know?')
+_info_templ_text = open('./info.tmpl', 'r').read()
+html = _info_templ_text % data
+webview.load_string(html, 'text/html', 'utf-8', '/')
+
+window = Gtk.Window()
+window.set_title('Gtk3 Drag And Drop Example')
+window.set_default_size(300, 180)
+window.connect("destroy", _destroy_cb)
+window.add(webview)
+
+window.show_all()
+Gtk.main()
diff --git a/radio_btn_test.py b/radio_btn_test.py
new file mode 100644
index 0000000..b966054
--- /dev/null
+++ b/radio_btn_test.py
@@ -0,0 +1,26 @@
+from gi.repository import Gtk
+
+class TestRadioButton(Gtk.Window):
+
+ def __init__(self):
+ super(TestRadioButton, self).__init__()
+ self.set_size_request(400, 400)
+ self.connect("destroy", Gtk.main_quit)
+ vbox = Gtk.VBox()
+ r0 = Gtk.RadioButton()
+ r1 = Gtk.RadioButton.new_with_label_from_widget(r0, "Test 1!")
+ r1.set_active(False)
+ vbox.pack_start(r1, True, False, 10)
+ r2 = Gtk.RadioButton.new_with_label_from_widget(r0, "Test 2!")
+ r1.set_active(False)
+ vbox.pack_start(r2, True, False, 10)
+ r3 = Gtk.RadioButton.new_with_label_from_widget(r0, "Test 3!")
+ r3.set_active(False)
+ vbox.pack_start(r3, True, False, 10)
+
+ self.add(vbox)
+ self.show_all()
+
+
+TestRadioButton()
+Gtk.main()
diff --git a/read_pdf_index.py b/read_pdf_index.py
new file mode 100644
index 0000000..b14f057
--- /dev/null
+++ b/read_pdf_index.py
@@ -0,0 +1,42 @@
+from gi.repository import Gtk
+from gi.repository import EvinceDocument
+from gi.repository import EvinceView
+
+EvinceDocument.init()
+
+doc = EvinceDocument.Document.factory_get_document('file:///home/gonzalo/Desktop/Libros/La_gran_manzana.pdf')
+
+def job_finished_cb(job):
+ model = job.get_model()
+ _iter = model.get_iter_first()
+ while True:
+ value = model.get_value(_iter, 0)
+ print value, model.get_value(_iter, 1)
+ _iter = model.iter_next(_iter)
+ if _iter is None:
+ break
+
+view = EvinceView.View()
+
+model = EvinceView.DocumentModel()
+model.set_document(doc)
+view.set_model(model)
+
+if not doc.has_document_links():
+ print 'The pdf file does not have a index'
+else:
+ jl = EvinceView.JobLinks.new(document=doc)
+ jl.connect('finished', job_finished_cb)
+ EvinceView.Job.scheduler_push_job(jl, EvinceView.JobPriority.PRIORITY_NONE)
+
+win = Gtk.Window()
+scrolled = Gtk.ScrolledWindow()
+win.add(scrolled)
+scrolled.add_with_viewport(view)
+
+win.set_default_geometry(200, 300)
+win.connect("destroy", Gtk.main_quit)
+
+win.show_all()
+Gtk.main()
+
diff --git a/roundbox.py b/roundbox.py
new file mode 100644
index 0000000..35d5f7c
--- /dev/null
+++ b/roundbox.py
@@ -0,0 +1,100 @@
+import math
+import gtk
+from sugar.graphics import style
+
+
+class RoundBox(gtk.HBox):
+ __gtype_name__ = 'RoundBox'
+
+ _BORDER_DEFAULT = style.LINE_WIDTH
+
+ def __init__(self, **kwargs):
+ gtk.HBox.__init__(self, **kwargs)
+
+ self._x = None
+ self._y = None
+ self._width = None
+ self._height = None
+ self._radius = style.zoom(10)
+ self.border = self._BORDER_DEFAULT
+ self.border_color = style.COLOR_BLACK
+ self.background_color = None
+ self.set_reallocate_redraws(True)
+ self.set_resize_mode(gtk.RESIZE_PARENT)
+ self.connect("expose_event", self.__expose_cb)
+ self.connect("add", self.__add_cb)
+
+ def __add_cb(self, child, params):
+ child.set_border_width(style.zoom(5))
+
+ def __size_allocate_cb(self, widget, allocation):
+ self._x = allocation.x
+ self._y = allocation.y
+ self._width = allocation.width
+ self._height = allocation.height
+
+ def __expose_cb(self, widget, event):
+ context = widget.window.cairo_create()
+
+ # set a clip region for the expose event
+ context.rectangle(event.area.x, event.area.y,
+ event.area.width, event.area.height)
+ context.clip()
+ self.draw(context)
+ return False
+
+ def draw(self, cr):
+ rect = self.get_allocation()
+ x = rect.x + self._BORDER_DEFAULT / 2
+ y = rect.y + self._BORDER_DEFAULT / 2
+ width = rect.width - self._BORDER_DEFAULT
+ height = rect.height - self._BORDER_DEFAULT
+
+ cr.move_to(x + self._radius, y)
+ cr.arc(x + width - self._radius, y + self._radius,
+ self._radius, math.pi * 1.5, math.pi * 2)
+ cr.arc(x + width - self._radius, y + height - self._radius,
+ self._radius, 0, math.pi * 0.5)
+ cr.arc(x + self._radius, y + height - self._radius,
+ self._radius, math.pi * 0.5, math.pi)
+ cr.arc(x + self._radius, y + self._radius, self._radius,
+ math.pi, math.pi * 1.5)
+ cr.close_path()
+
+ if self.background_color is not None:
+ r, g, b, __ = self.background_color.get_rgba()
+ cr.set_source_rgb(r, g, b)
+ cr.fill_preserve()
+
+ if self.border_color is not None:
+ r, g, b, __ = self.border_color.get_rgba()
+ cr.set_source_rgb(r, g, b)
+ cr.set_line_width(self.border)
+ cr.stroke()
+
+if __name__ == '__main__':
+
+ win = gtk.Window()
+ win.connect('destroy', gtk.main_quit)
+ win.set_default_size(450, 550)
+ vbox = gtk.VBox()
+
+ box1 = RoundBox()
+ vbox.add(box1)
+ label1 = gtk.Label("Test 1")
+ box1.add(label1)
+
+ rbox = RoundBox()
+ rbox.background_color = style.Color('#FF0000')
+ vbox.add(rbox)
+ label2 = gtk.Label("Test 2")
+ rbox.add(label2)
+
+ bbox = RoundBox()
+ bbox.background_color = style.Color('#aaff33')
+ bbox.border_color = style.Color('#ff3300')
+ vbox.add(bbox)
+
+ win.add(vbox)
+ win.show_all()
+ gtk.main()
diff --git a/scribble.py b/scribble.py
new file mode 100644
index 0000000..3b36111
--- /dev/null
+++ b/scribble.py
@@ -0,0 +1,123 @@
+#!/usr/bin/env python
+
+# example scribblesimple.py
+
+ # GTK - The GIMP Toolkit
+ # Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ # Copyright (C) 2001-2004 John Finlay
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Library General Public
+ # License as published by the Free Software Foundation; either
+ # version 2 of the License, or (at your option) any later version.
+ #
+ # This library 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
+ # Library General Public License for more details.
+ #
+ # You should have received a copy of the GNU Library General Public
+ # License along with this library; if not, write to the
+ # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ # Boston, MA 02111-1307, USA.
+#
+# [SNIPPET_NAME: Scribble Simple]
+# [SNIPPET_CATEGORIES: PyGTK]
+# [SNIPPET_DESCRIPTION: A simple scribbling example]
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+
+# Backing pixmap for drawing area
+pixmap = None
+
+# Create a new backing pixmap of the appropriate size
+def configure_event(widget, event):
+ global pixmap
+
+ x, y, width, height = widget.get_allocation()
+ pixmap = gtk.gdk.Pixmap(widget.window, width, height)
+ pixmap.draw_rectangle(widget.get_style().white_gc,
+ True, 0, 0, width, height)
+
+ return True
+
+# Redraw the screen from the backing pixmap
+def expose_event(widget, event):
+ x , y, width, height = event.area
+ widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL],
+ pixmap, x, y, x, y, width, height)
+ return False
+
+# Draw a rectangle on the screen
+def draw_brush(widget, x, y):
+ rect = (int(x-5), int(y-5), 10, 10)
+ pixmap.draw_rectangle(widget.get_style().black_gc, True,
+ rect[0], rect[1], rect[2], rect[3])
+ widget.queue_draw_area(rect[0], rect[1], rect[2], rect[3])
+
+def button_press_event(widget, event):
+ if event.button == 1 and pixmap != None:
+ draw_brush(widget, event.x, event.y)
+ return True
+
+def motion_notify_event(widget, event):
+ if event.is_hint:
+ x, y, state = event.window.get_pointer()
+ else:
+ x = event.x
+ y = event.y
+ state = event.state
+
+ if state & gtk.gdk.BUTTON1_MASK and pixmap != None:
+ draw_brush(widget, x, y)
+
+ return True
+
+def main():
+ window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+ window.set_name ("Test Input")
+
+ vbox = gtk.VBox(False, 0)
+ window.add(vbox)
+ vbox.show()
+
+ window.connect("destroy", lambda w: gtk.main_quit())
+
+ # Create the drawing area
+ drawing_area = gtk.DrawingArea()
+ drawing_area.set_size_request(200, 200)
+ vbox.pack_start(drawing_area, True, True, 0)
+
+ drawing_area.show()
+
+ # Signals used to handle backing pixmap
+ drawing_area.connect("expose_event", expose_event)
+ drawing_area.connect("configure_event", configure_event)
+
+ # Event signals
+ drawing_area.connect("motion_notify_event", motion_notify_event)
+ drawing_area.connect("button_press_event", button_press_event)
+
+ drawing_area.set_events(gtk.gdk.EXPOSURE_MASK
+ | gtk.gdk.LEAVE_NOTIFY_MASK
+ | gtk.gdk.BUTTON_PRESS_MASK
+ | gtk.gdk.POINTER_MOTION_MASK
+ | gtk.gdk.POINTER_MOTION_HINT_MASK)
+
+ # .. And a quit button
+ button = gtk.Button("Quit")
+ vbox.pack_start(button, False, False, 0)
+
+ button.connect_object("clicked", lambda w: w.destroy(), window)
+ button.show()
+
+ window.show()
+
+ gtk.main()
+
+ return 0
+
+if __name__ == "__main__":
+ main()
diff --git a/selection_entry_test.py b/selection_entry_test.py
new file mode 100644
index 0000000..f97e45a
--- /dev/null
+++ b/selection_entry_test.py
@@ -0,0 +1,23 @@
+from gi.repository import Gtk
+
+class Test(Gtk.Window):
+
+ def __init__(self):
+ super(Test, self).__init__()
+ self.connect("destroy", Gtk.main_quit)
+ vbox = Gtk.VBox()
+ self.entry = Gtk.Entry()
+ vbox.add(self.entry)
+
+ button1 = Gtk.Button('Get bounds')
+ button1.connect('clicked', self.__get_text_cb)
+ vbox.add(button1)
+
+ self.add(vbox)
+ self.show_all()
+
+ def __get_text_cb(self, button):
+ print self.entry.get_selection_bounds()
+
+Test()
+Gtk.main()
diff --git a/show_pulsing_icon_zoom_in.py b/show_pulsing_icon_zoom_in.py
new file mode 100644
index 0000000..361343d
--- /dev/null
+++ b/show_pulsing_icon_zoom_in.py
@@ -0,0 +1,24 @@
+import cairo
+import gtk
+
+from pulsingicon import PulsingIcon
+from xocolor import XoColor
+
+
+def main():
+ win = gtk.Window()
+ win.connect('destroy', gtk.main_quit)
+ win.set_default_size(450, 550)
+ vb = gtk.VBox()
+ test_icon = PulsingIcon(file='./icons/activity-web.svg',
+ icon_size=1.0)
+ test_icon.set_base_color(XoColor('#FF8F00,#FF2B34'))
+ test_icon.set_zoom(20, 100, 10)
+ test_icon.set_pulsing(True)
+ vb.pack_start(test_icon)
+ win.add(vb)
+ win.show_all()
+ gtk.main()
+
+if __name__ == '__main__':
+ main()
diff --git a/show_pulsing_icon_zoom_out.py b/show_pulsing_icon_zoom_out.py
new file mode 100644
index 0000000..b63b8be
--- /dev/null
+++ b/show_pulsing_icon_zoom_out.py
@@ -0,0 +1,22 @@
+import cairo
+import gtk
+
+from pulsingicon import PulsingIcon
+from xocolor import XoColor
+
+
+def main():
+ win = gtk.Window()
+ win.connect('destroy', gtk.main_quit)
+ win.set_default_size(450, 550)
+ test_icon = PulsingIcon(file='./icons/activity-web.svg',
+ pixel_size=100)
+ test_icon.set_base_color(XoColor('#FF8F00,#FF2B34'))
+ test_icon.set_zoom(100, 20, 10)
+ test_icon.set_pulsing(True)
+ win.add(test_icon)
+ win.show_all()
+ gtk.main()
+
+if __name__ == '__main__':
+ main()
diff --git a/show_svg.py b/show_svg.py
new file mode 100644
index 0000000..bd76ed1
--- /dev/null
+++ b/show_svg.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+import sys
+import cairo
+import rsvg
+import gtk
+
+
+BORDER_WIDTH = 10
+
+
+def delete_cb(win, event):
+ gtk.main_quit()
+
+
+def expose_cairo(win, event, svg):
+
+ x, y, w, h = win.allocation
+ cr = win.window.cairo_create()
+ cr.set_source_color(win.style.fg[win.state])
+ cr.rectangle(BORDER_WIDTH, BORDER_WIDTH,
+ w - 2*BORDER_WIDTH, h - 2*BORDER_WIDTH)
+ cr.set_line_width(5.0)
+ cr.set_line_join(cairo.LINE_JOIN_ROUND)
+ cr.stroke()
+
+ if svg != None:
+ matrix = cairo.Matrix(3,0,0,3,0, 0)
+ #cairo.Matrix.rotate( matrix, prop.rot )
+ cr.transform (matrix)
+ svg.render_cairo(cr)
+
+ return True
+
+def main():
+ win = gtk.Window ()
+ win.connect("delete-event", delete_cb)
+
+ svg = None
+ if (len (sys.argv) > 1):
+ svg = rsvg.Handle(file=sys.argv[1])
+ else:
+ raise SystemExit("need svg file")
+
+ win.connect("expose-event", expose_cairo, svg)
+
+ print svg.props.width, svg.props.height, svg.props.em, svg.props.ex
+
+ win.show_all()
+ win.connect("destroy", lambda w: gtk.main_quit())
+ gtk.main()
+
+if __name__ == '__main__':
+ main()
diff --git a/simple_label.py b/simple_label.py
new file mode 100644
index 0000000..1196aac
--- /dev/null
+++ b/simple_label.py
@@ -0,0 +1,25 @@
+from gi.repository import Gtk
+
+LONG_TEXT = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, ' \
+ 'sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna ' \
+ 'sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna ' \
+ 'sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna ' \
+ 'sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna ' \
+ ' liquam erat volutpat. Ut wisi enim ad minim veniam'
+
+win = Gtk.Window()
+box = Gtk.VBox()
+
+align = Gtk.Alignment.new(0.5, 0.5, 0, 0)
+label = Gtk.Label(LONG_TEXT)
+label.set_max_width_chars(40)
+label.set_single_line_mode(False)
+label.set_line_wrap(True)
+
+align.add(label)
+box.add(align)
+win.add(box)
+
+win.connect("delete-event", Gtk.main_quit)
+win.show_all()
+Gtk.main()
diff --git a/simple_tts.py b/simple_tts.py
new file mode 100644
index 0000000..7212fc6
--- /dev/null
+++ b/simple_tts.py
@@ -0,0 +1,75 @@
+# From http://wiki.sugarlabs.org/go/Activity_Team/gst-plugins-espeak
+import gtk
+import gst
+import pango
+
+window = gtk.Window()
+window.connect('destroy',
+ lambda sender: gtk.main_quit())
+
+workspace = gtk.VBox()
+window.add(workspace)
+
+# text widget
+
+scrolled = gtk.ScrolledWindow()
+workspace.pack_start(scrolled)
+
+text = gtk.TextView()
+scrolled.add(text)
+
+buffer = text.props.buffer
+buffer.props.text = file(__file__).read()
+
+tag = buffer.create_tag()
+tag.props.weight = pango.WEIGHT_BOLD
+
+# play controls
+
+toolbar = gtk.HBox()
+workspace.pack_end(toolbar, False)
+
+play = gtk.Button('Play/Resume')
+play.connect('clicked',
+ lambda sender: pipe.set_state(gst.STATE_PLAYING))
+toolbar.add(play)
+
+pause = gtk.Button('Pause')
+pause.connect('clicked',
+ lambda sender: pipe.set_state(gst.STATE_PAUSED))
+toolbar.add(pause)
+
+stop = gtk.Button('Stop')
+stop.connect('clicked',
+ lambda sender: pipe.set_state(gst.STATE_NULL))
+toolbar.add(stop)
+
+# gst code
+
+pipe = gst.parse_launch('espeak name=src ! autoaudiosink')
+
+src = pipe.get_by_name('src')
+src.props.voice = 'english_wmids'
+src.props.text = buffer.props.text
+src.props.track = 1 # track for words
+
+def tts_cb(bus, message):
+ if message.structure.get_name() != 'espeak-word':
+ return
+
+ offset = message.structure['offset']
+ len = message.structure['len']
+
+ buffer.remove_tag(tag, buffer.get_start_iter(), buffer.get_end_iter())
+ start = buffer.get_iter_at_offset(offset)
+ end = buffer.get_iter_at_offset(offset + len)
+ buffer.apply_tag(tag, start, end)
+
+bus = pipe.get_bus()
+bus.add_signal_watch()
+bus.connect('message::element', tts_cb)
+
+# gtk start
+
+window.show_all()
+gtk.main()
diff --git a/simple_tts2.py b/simple_tts2.py
new file mode 100644
index 0000000..ab213d8
--- /dev/null
+++ b/simple_tts2.py
@@ -0,0 +1,80 @@
+# From http://wiki.sugarlabs.org/go/Activity_Team/gst-plugins-espeak
+import gtk
+import gst
+import pango
+
+import logging
+
+window = gtk.Window()
+window.connect('destroy',
+ lambda sender: gtk.main_quit())
+
+workspace = gtk.VBox()
+window.add(workspace)
+
+# text widget
+
+scrolled = gtk.ScrolledWindow()
+workspace.pack_start(scrolled)
+
+text = gtk.TextView()
+scrolled.add(text)
+
+buffer = text.props.buffer
+buffer.props.text = 'This is a simple text to speech test'
+
+tag = buffer.create_tag()
+tag.props.weight = pango.WEIGHT_BOLD
+
+# play controls
+
+toolbar = gtk.HBox()
+workspace.pack_end(toolbar, False)
+
+play = gtk.Button('Play/Resume')
+play.connect('clicked',
+ lambda sender: pipe.set_state(gst.STATE_PLAYING))
+toolbar.add(play)
+
+pause = gtk.Button('Pause')
+pause.connect('clicked',
+ lambda sender: pipe.set_state(gst.STATE_PAUSED))
+toolbar.add(pause)
+
+stop = gtk.Button('Stop')
+stop.connect('clicked',
+ lambda sender: pipe.set_state(gst.STATE_NULL))
+toolbar.add(stop)
+
+# gst code
+
+pipe = gst.parse_launch('espeak name=src ! autoaudiosink')
+
+src = pipe.get_by_name('src')
+src.props.voice = 'english_wmids'
+src.props.text = buffer.props.text
+src.props.track = 1 # track for words
+
+def tts_cb(bus, message):
+ logging.error('gstreamer message %s', message)
+ if message is None:
+ return
+ if message.structure.get_name() != 'espeak-word':
+ return
+
+ offset = message.structure['offset']
+ len = message.structure['len']
+
+ buffer.remove_tag(tag, buffer.get_start_iter(), buffer.get_end_iter())
+ start = buffer.get_iter_at_offset(offset)
+ end = buffer.get_iter_at_offset(offset + len)
+ buffer.apply_tag(tag, start, end)
+
+bus = pipe.get_bus()
+bus.add_signal_watch()
+bus.connect('message::element', tts_cb)
+
+# gtk start
+
+window.show_all()
+gtk.main()
diff --git a/simple_tts3.py b/simple_tts3.py
new file mode 100644
index 0000000..9f4f7b7
--- /dev/null
+++ b/simple_tts3.py
@@ -0,0 +1,87 @@
+# From http://wiki.sugarlabs.org/go/Activity_Team/gst-plugins-espeak
+from gi.repository import Gtk
+#import pygst
+#pygst.require("0.10")
+from gi.repository import Gst
+from gi.repository import Pango
+
+import logging
+
+window = Gtk.Window()
+window.connect('destroy',
+ lambda sender: Gtk.main_quit())
+
+workspace = Gtk.VBox()
+window.add(workspace)
+
+# text widget
+
+scrolled = Gtk.ScrolledWindow()
+workspace.pack_start(scrolled, False, False, padding=5)
+
+text = Gtk.TextView()
+scrolled.add(text)
+
+buffer = text.props.buffer
+buffer.props.text = 'This is a simple text to speech test'
+
+tag = buffer.create_tag()
+tag.props.weight = Pango.Weight.BOLD
+
+# play controls
+
+toolbar = Gtk.HBox()
+workspace.pack_end(toolbar, False, False, padding=5)
+
+play = Gtk.Button('Play/Resume')
+play.connect('clicked',
+ lambda sender: pipe.set_state(Gst.State.PLAYING))
+toolbar.add(play)
+
+pause = Gtk.Button('Pause')
+pause.connect('clicked',
+ lambda sender: pipe.set_state(Gst.State.PAUSED))
+toolbar.add(pause)
+
+stop = Gtk.Button('Stop')
+stop.connect('clicked',
+ lambda sender: pipe.set_state(Gst.State.NULL))
+toolbar.add(stop)
+
+# gst code
+
+Gst.init_check(None)
+
+pipe = Gst.parse_launch('espeak name=src ! autoaudiosink')
+
+src = pipe.get_by_name('src')
+src.props.voice = 'english_wmids'
+src.props.text = buffer.props.text
+src.props.track = 2
+#src.props.track = 1 # track for words
+
+
+def tts_cb(bus, message):
+ logging.error('gstreamer message %s', message)
+ if message is None:
+ return
+ if message.structure.get_name() != 'espeak-word':
+ return
+
+ offset = message.structure['offset']
+ len = message.structure['len']
+
+ buffer.remove_tag(tag, buffer.get_start_iter(), buffer.get_end_iter())
+ start = buffer.get_iter_at_offset(offset)
+ end = buffer.get_iter_at_offset(offset + len)
+ buffer.apply_tag(tag, start, end)
+
+bus = pipe.get_bus()
+bus.add_signal_watch()
+#bus.connect('message::element', tts_cb)
+bus.connect('message', tts_cb)
+
+# gtk start
+
+window.show_all()
+Gtk.main()
diff --git a/simplecairodraw.py b/simplecairodraw.py
new file mode 100644
index 0000000..9b87aeb
--- /dev/null
+++ b/simplecairodraw.py
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+
+# ZetCode PyGTK tutorial
+#
+# This code example draws basic shapes
+# with the cairo library
+#
+# author: jan bodnar
+# website: zetcode.com
+# last edited: February 2009
+
+import gtk
+import math
+
+class PyApp(gtk.Window):
+
+ def __init__(self):
+ super(PyApp, self).__init__()
+
+ self.set_title("Basic shapes")
+ self.set_size_request(390, 240)
+ self.set_position(gtk.WIN_POS_CENTER)
+
+ self.connect("destroy", gtk.main_quit)
+
+ darea = gtk.DrawingArea()
+ darea.connect("expose-event", self.expose)
+ self.add(darea)
+
+ self.show_all()
+
+ def expose(self, widget, event):
+
+ cr = widget.window.cairo_create()
+ cr.set_source_rgb(0.6, 0.6, 0.6)
+
+ cr.rectangle(20, 20, 120, 80)
+ cr.rectangle(180, 20, 80, 80)
+ cr.fill()
+
+ cr.arc(330, 60, 40, 0, 2*math.pi)
+ cr.fill()
+
+ cr.arc(90, 160, 40, math.pi/4, math.pi)
+ cr.fill()
+
+ cr.translate(220, 180)
+ cr.scale(1, 0.7)
+ cr.arc(0, 0, 50, 0, 2*math.pi)
+ cr.fill()
+
+
+PyApp()
+gtk.main()
diff --git a/test_abi_content.py b/test_abi_content.py
new file mode 100644
index 0000000..1c2e4b5
--- /dev/null
+++ b/test_abi_content.py
@@ -0,0 +1,31 @@
+from gi.repository import Gtk
+from gi.repository import Abi
+
+
+class TestAbi(Gtk.Window):
+
+ def __init__(self):
+ super(TestAbi, self).__init__()
+ self.set_size_request(400, 400)
+ self.connect("destroy", Gtk.main_quit)
+ vbox = Gtk.VBox()
+ self.abi = Abi.Widget()
+ vbox.add(self.abi)
+ button1 = Gtk.Button('Get selection')
+ button1.connect('clicked', self.__get_selection_cb)
+ vbox.add(button1)
+ button2 = Gtk.Button('Get content')
+ button2.connect('clicked', self.__get_content_cb)
+ vbox.add(button2)
+
+ self.add(vbox)
+ self.show_all()
+
+ def __get_selection_cb(self, button):
+ print self.abi.get_selection('text/plain')
+
+ def __get_content_cb(self, button):
+ print self.abi.get_content('text/plain', None)
+
+TestAbi()
+Gtk.main()
diff --git a/test_combo_font.py b/test_combo_font.py
new file mode 100644
index 0000000..64858d1
--- /dev/null
+++ b/test_combo_font.py
@@ -0,0 +1,10 @@
+from gi.repository import Gtk
+from fontcombobox import FontComboBox
+
+win = Gtk.Window()
+win.connect('destroy', lambda sender: Gtk.main_quit())
+combo = FontComboBox()
+win.add(combo)
+win.show_all()
+
+Gtk.main()
diff --git a/test_fixed.py b/test_fixed.py
new file mode 100644
index 0000000..858d0c3
--- /dev/null
+++ b/test_fixed.py
@@ -0,0 +1,20 @@
+import gtk
+
+def _destroy_cb(widget, data=None):
+ gtk.main_quit()
+
+
+window = gtk.Window()
+window.connect("destroy", _destroy_cb)
+
+fixed = gtk.Fixed()
+window.add(fixed)
+
+button = gtk.Button(label='copy')
+fixed.put(button, 0, 0)
+
+button = gtk.Button(label='paste')
+fixed.put(button, 10, 10)
+
+window.show_all()
+gtk.main()
diff --git a/test_menu_item.py b/test_menu_item.py
new file mode 100644
index 0000000..6011cb8
--- /dev/null
+++ b/test_menu_item.py
@@ -0,0 +1,32 @@
+
+from gi.repository import Gtk
+
+class MenuTest(Gtk.Window):
+
+ def __init__(self):
+ super(MenuTest, self).__init__()
+
+ self.set_title("Click the menu to update the counter!")
+
+ mb = Gtk.MenuBar()
+ menu_item = Gtk.MenuItem("Add 1")
+ menu_item.connect("activate", self.on_menu_item_activate)
+ mb.append(menu_item)
+
+ vbox = Gtk.VBox()
+ vbox.pack_start(mb, False, False, 0)
+ self.add(vbox)
+ self.label = Gtk.Label('Test!')
+ vbox.pack_start(self.label, False, False, 0)
+
+ self.connect("destroy", Gtk.main_quit)
+ self.show_all()
+ self._counter = 0
+
+ def on_menu_item_activate(self, widget):
+ self._counter += 1
+ self.label.set_text(str(self._counter))
+
+
+MenuTest()
+Gtk.main()
diff --git a/test_pack.py b/test_pack.py
new file mode 100644
index 0000000..4cfccf7
--- /dev/null
+++ b/test_pack.py
@@ -0,0 +1,40 @@
+import gtk
+
+def main():
+ win = gtk.Window()
+ win.connect('destroy', gtk.main_quit)
+ win.set_default_size(850, 550)
+
+ scroll = gtk.ScrolledWindow()
+ scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ viewport = gtk.Viewport()
+ vbox = gtk.VBox()
+
+ label_space = 30
+
+ label = gtk.Label(
+ "Sugar is the graphical user interface that you are looking at. "
+ "It is a learning environment designed for children.")
+ label.set_line_wrap(True)
+ label.set_justify(gtk.JUSTIFY_FILL)
+ label.set_width_chars(80)
+
+ eb = gtk.EventBox()
+ eb.add(label)
+ eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("blue"))
+
+ hbox = gtk.HBox(homogeneous=True, spacing=label_space)
+ hbox.pack_start(eb, True, True,padding=50)
+ vbox.pack_start(hbox, False)
+
+ win.add(scroll)
+ scroll.add(viewport)
+ viewport.add(vbox)
+
+ label.show()
+
+ win.show_all()
+ gtk.main()
+
+if __name__ == '__main__':
+ main()
diff --git a/test_scroll_webkit.py b/test_scroll_webkit.py
new file mode 100644
index 0000000..5be526e
--- /dev/null
+++ b/test_scroll_webkit.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+
+import logging
+
+from gi.repository import Gtk
+from gi.repository import WebKit
+
+class TestScrollWeb:
+
+ def __init__(self):
+ window = Gtk.Window()
+ window.set_default_size(400, 350)
+ window.connect('destroy', Gtk.main_quit)
+
+ self._sw = Gtk.ScrolledWindow()
+ self._view = WebKit.WebView()
+
+ # Uncommenting this line
+ # and pressing many times pgup pgdown in the viewer
+ # crash my gnome session
+ #self._view.connect('load-finished', self._view_load_finished_cb)
+
+ self._view.load_uri('http://es.wikipedia.org/wiki/Cristobal_Colon')
+
+ settings = self._view.get_settings()
+ settings.props.default_font_family = 'DejaVu LGC Serif'
+ settings.props.enable_plugins = False
+ settings.props.default_encoding = 'utf-8'
+ self._view.connect('scroll-event', self._view_scroll_event_cb)
+
+ self._sw.add(self._view)
+ self._sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
+ self._v_vscrollbar = self._sw.get_vscrollbar()
+ self._v_scrollbar_value_changed_cb_id = \
+ self._v_vscrollbar.connect('value-changed', \
+ self._v_scrollbar_value_changed_cb)
+ window.add(self._sw)
+ window.show_all()
+
+ def _view_load_finished_cb(self, v, frame):
+ logging.debug('*** _view_load_finished_cb')
+
+ # Normally the line below would not be required - ugly workaround for
+ # possible Webkit bug. See : https://bugs.launchpad.net/bugs/483231
+ self._sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
+
+ def _v_scrollbar_value_changed_cb(self, scrollbar):
+ logging.error('_v_scrollbar_value_changed_cb value = %f upper %f lower %f page_size %f',
+ self._v_vscrollbar.get_value(),
+ self._v_vscrollbar.props.adjustment.props.upper,
+ self._v_vscrollbar.props.adjustment.props.lower,
+ self._v_vscrollbar.props.adjustment.props.page_size)
+
+ def _view_scroll_event_cb(self, view, event):
+ logging.error('_view_scroll_event_cb value = %f upper %f lower %f page_size %f',
+ self._v_vscrollbar.get_value(),
+ self._v_vscrollbar.props.adjustment.props.upper,
+ self._v_vscrollbar.props.adjustment.props.lower,
+ self._v_vscrollbar.props.adjustment.props.page_size)
+
+
+
+def main():
+ test = TestScrollWeb()
+ Gtk.main()
+
+if __name__ == "__main__":
+ main()
diff --git a/test_scroll_webkit_overlay.py b/test_scroll_webkit_overlay.py
new file mode 100644
index 0000000..985df40
--- /dev/null
+++ b/test_scroll_webkit_overlay.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+
+import logging
+
+from gi.repository import Gtk
+from gi.repository import WebKit
+
+class TestScrollWeb:
+
+ def __init__(self):
+ window = Gtk.Window()
+ window.set_default_size(400, 350)
+ window.connect('destroy', Gtk.main_quit)
+
+ hbox = Gtk.HBox()
+
+ self._sw = Gtk.ScrolledWindow()
+ self._view = WebKit.WebView()
+
+ overlay = Gtk.Overlay()
+ overlay.add(hbox)
+ hbox.add(self._sw)
+
+ # Uncommenting this line
+ # and pressing many times pgup pgdown in the viewer
+ # crash my gnome session
+ #self._view.connect('load-finished', self._view_load_finished_cb)
+
+ self._view.load_uri('http://es.wikipedia.org/wiki/Cristobal_Colon')
+
+ settings = self._view.get_settings()
+ settings.props.default_font_family = 'DejaVu LGC Serif'
+ settings.props.enable_plugins = False
+ settings.props.default_encoding = 'utf-8'
+ self._view.connect('scroll-event', self._view_scroll_event_cb)
+
+ self._sw.add(self._view)
+ self._sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
+ self._v_vscrollbar = self._sw.get_vscrollbar()
+ self._v_scrollbar_value_changed_cb_id = \
+ self._v_vscrollbar.connect('value-changed', \
+ self._v_scrollbar_value_changed_cb)
+ window.add(overlay)
+ self._view.show()
+
+ scrollbar = Gtk.VScrollbar()
+ scrollbar.props.halign = Gtk.Align.END
+ scrollbar.props.valign = Gtk.Align.FILL
+ overlay.add_overlay(scrollbar)
+
+ window.show_all()
+
+ def _view_load_finished_cb(self, v, frame):
+ logging.debug('*** _view_load_finished_cb')
+
+ # Normally the line below would not be required - ugly workaround for
+ # possible Webkit bug. See : https://bugs.launchpad.net/bugs/483231
+ self._sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
+
+ def _v_scrollbar_value_changed_cb(self, scrollbar):
+ logging.error('_v_scrollbar_value_changed_cb value = %f upper %f lower %f page_size %f',
+ self._v_vscrollbar.get_value(),
+ self._v_vscrollbar.props.adjustment.props.upper,
+ self._v_vscrollbar.props.adjustment.props.lower,
+ self._v_vscrollbar.props.adjustment.props.page_size)
+
+ def _view_scroll_event_cb(self, view, event):
+ logging.error('_view_scroll_event_cb value = %f upper %f lower %f page_size %f',
+ self._v_vscrollbar.get_value(),
+ self._v_vscrollbar.props.adjustment.props.upper,
+ self._v_vscrollbar.props.adjustment.props.lower,
+ self._v_vscrollbar.props.adjustment.props.page_size)
+
+
+
+def main():
+ test = TestScrollWeb()
+ Gtk.main()
+
+if __name__ == "__main__":
+ main()
diff --git a/test_speaker_dbus_msg.py b/test_speaker_dbus_msg.py
new file mode 100644
index 0000000..695175a
--- /dev/null
+++ b/test_speaker_dbus_msg.py
@@ -0,0 +1,23 @@
+import dbus
+import gobject
+
+def main():
+ loop = gobject.MainLoop()
+ loop.run()
+ try:
+ bus = dbus.SystemBus()
+ bus.add_signal_receiver(__button_pressed_cb,
+ dbus_interface='org.freedesktop.Hal.Device',
+ signal_name='volume-up')
+ except dbus.DBusException, e:
+ print 'Can''t create signal receiver.'
+
+def __button_pressed_cb(sender,message):
+ print 'dbus message', message
+
+
+
+
+if __name__ == '__main__':
+ main()
+
diff --git a/test_vte_get_text.py b/test_vte_get_text.py
new file mode 100644
index 0000000..91037c4
--- /dev/null
+++ b/test_vte_get_text.py
@@ -0,0 +1,41 @@
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import GLib
+from gi.repository import Vte
+import os
+
+class TestVte(Gtk.Window):
+
+ def __init__(self):
+ super(TestVte, self).__init__()
+ self.set_size_request(400, 400)
+ self.connect("destroy", Gtk.main_quit)
+ vbox = Gtk.VBox()
+ self.vte = Vte.Terminal()
+ vbox.add(self.vte)
+ self.vte.set_colors(Gdk.color_parse('#000000'),
+ Gdk.color_parse('#FFFFFF'), [])
+ self.vte.set_emulation('xterm')
+
+ sucess_, pid = self.vte.fork_command_full(Vte.PtyFlags.DEFAULT,
+ os.environ["HOME"],
+ ["/bin/bash"],
+ [],
+ GLib.SpawnFlags.DO_NOT_REAP_CHILD,
+ None,
+ None)
+
+ button1 = Gtk.Button('Get text')
+ button1.connect('clicked', self.__get_text_cb)
+ vbox.add(button1)
+
+ self.add(vbox)
+ self.show_all()
+
+ def __get_text_cb(self, button):
+ args = []
+ print self.vte.get_text(None, None, None)
+ print "ARGS", args
+
+TestVte()
+Gtk.main()
diff --git a/test_vte_get_text_2.py b/test_vte_get_text_2.py
new file mode 100644
index 0000000..8175f04
--- /dev/null
+++ b/test_vte_get_text_2.py
@@ -0,0 +1,46 @@
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import GLib
+from gi.repository import Vte
+import os
+
+
+class TestVte(Gtk.Window):
+
+ def __init__(self):
+ super(TestVte, self).__init__()
+ self.set_size_request(400, 400)
+ self.connect("destroy", Gtk.main_quit)
+ vbox = Gtk.VBox()
+ self.vte = Vte.Terminal()
+ vbox.add(self.vte)
+ self.vte.set_colors(Gdk.color_parse('#000000'),
+ Gdk.color_parse('#FFFFFF'), [])
+ self.vte.set_emulation('xterm')
+
+ sucess_, pid = self.vte.fork_command_full(Vte.PtyFlags.DEFAULT,
+ os.environ["HOME"],
+ ["/bin/bash"],
+ [],
+ GLib.SpawnFlags.DO_NOT_REAP_CHILD,
+ None,
+ None)
+
+ button1 = Gtk.Button('Get text')
+ button1.connect('clicked', self.__get_text_cb)
+ vbox.add(button1)
+
+ self.add(vbox)
+ self.show_all()
+
+ def is_selected(self, vte, *args):
+ return True
+
+ def __get_text_cb(self, button):
+ #self.attrs = GLib.Array()
+ text = self.vte.get_text(self.is_selected, None)
+ print text
+ #print self.attrs
+
+TestVte()
+Gtk.main()
diff --git a/touch_test_error_scrolled.py b/touch_test_error_scrolled.py
new file mode 100644
index 0000000..78dcfff
--- /dev/null
+++ b/touch_test_error_scrolled.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+# Copyright (C) 2011, One Laptop Per Child
+# Author, Gonzalo Odiard <gonzalo@laptop.org>
+# Translated from c demo provided by Carlos Garnacho <carlos@lanedo.com>
+
+from gi.repository import Gtk
+from gi.repository import Gdk
+import math
+import logging
+
+class TestTouch(Gtk.DrawingArea):
+
+ def __init__(self):
+ self.touches = {}
+ super(TestTouch, self).__init__()
+ self.set_events(Gdk.EventMask.TOUCH_MASK)
+ self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
+ self.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
+ self.add_events(Gdk.EventMask.BUTTON_MOTION_MASK)
+ self.connect('draw', self.__draw_cb)
+ self.connect('event', self.__event_cb)
+
+ def __event_cb(self, widget, event):
+ logging.error('touch event type %s', event.type)
+ if event.type in (Gdk.EventType.TOUCH_BEGIN,
+ Gdk.EventType.TOUCH_CANCEL, Gdk.EventType.TOUCH_END,
+ Gdk.EventType.TOUCH_UPDATE, Gdk.EventType.BUTTON_PRESS,
+ Gdk.EventType.BUTTON_RELEASE, Gdk.EventType.MOTION_NOTIFY):
+ x = event.get_coords()[1]
+ y = event.get_coords()[2]
+ seq = str(event.touch.sequence)
+
+ if event.type in (Gdk.EventType.TOUCH_BEGIN,
+ Gdk.EventType.TOUCH_UPDATE, Gdk.EventType.BUTTON_PRESS,
+ Gdk.EventType.MOTION_NOTIFY):
+ self.touches[seq] = (x, y)
+ elif event.type in (Gdk.EventType.TOUCH_END,
+ Gdk.EventType.BUTTON_RELEASE):
+ del self.touches[seq]
+ self.queue_draw()
+
+ def __draw_cb(self, widget, ctx):
+ ctx.set_source_rgba(0.3, 0.3, 0.3, 0.7)
+ for touch in self.touches.values():
+ x, y = touch
+ ctx.save()
+ ctx.arc(x, y, 50, 0., 2 * math.pi)
+ ctx.fill()
+ ctx.restore()
+
+
+def main():
+ window = Gtk.Window()
+ test_touch = TestTouch()
+ hbox = Gtk.HBox()
+ scrolled = Gtk.ScrolledWindow()
+
+ # if kinetic scrolling is disabled the problem disappear
+ # but the scrolledwindow is not touch friendly
+ #scrolled.set_kinetic_scrolling(False)
+
+ store = Gtk.ListStore(str)
+ for i in range(50):
+ store.append(['Test %d' % i])
+ tview = Gtk.TreeView(store)
+ renderer = Gtk.CellRendererText()
+ column = Gtk.TreeViewColumn("Title", renderer, text=0)
+ tview.append_column(column)
+ scrolled.add(tview)
+ window.add(hbox)
+ hbox.add(scrolled)
+ hbox.add(test_touch)
+
+ window.connect("destroy", Gtk.main_quit)
+ window.set_default_size(700, 500)
+ window.show_all()
+ Gtk.main()
+
+if __name__ == "__main__":
+ main()
diff --git a/touch_test_walter.py b/touch_test_walter.py
new file mode 100644
index 0000000..fd82424
--- /dev/null
+++ b/touch_test_walter.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# Copyright (C) 2011, One Laptop Per Child
+# Author, Gonzalo Odiard <gonzalo@laptop.org>
+# Translated from c demo provided by Carlos Garnacho <carlos@lanedo.com>
+
+from gi.repository import Gtk
+from gi.repository import Gdk
+import math
+
+
+class TestTouch(Gtk.DrawingArea):
+
+ def __init__(self):
+ self.touches = {}
+ super(TestTouch, self).__init__()
+ self.set_events(Gdk.EventMask.TOUCH_MASK)
+ self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
+ self.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
+ self.add_events(Gdk.EventMask.BUTTON_MOTION_MASK)
+ self.connect('draw', self.__draw_cb)
+ self.connect('event', self.__event_cb)
+
+ def __event_cb(self, widget, event):
+ if event.type in (Gdk.EventType.TOUCH_BEGIN,
+ Gdk.EventType.TOUCH_CANCEL, Gdk.EventType.TOUCH_END,
+ Gdk.EventType.TOUCH_UPDATE, Gdk.EventType.BUTTON_PRESS,
+ Gdk.EventType.BUTTON_RELEASE, Gdk.EventType.MOTION_NOTIFY):
+ x = event.get_coords()[1]
+ y = event.get_coords()[2]
+ seq = str(event.touch.sequence)
+
+ if event.type in (Gdk.EventType.TOUCH_BEGIN,
+ Gdk.EventType.TOUCH_UPDATE, Gdk.EventType.BUTTON_PRESS,
+ Gdk.EventType.MOTION_NOTIFY):
+ self.touches[seq] = (x, y)
+ elif event.type in (Gdk.EventType.TOUCH_END,
+ Gdk.EventType.BUTTON_RELEASE):
+ del self.touches[seq]
+ self.queue_draw()
+
+ def __draw_cb(self, widget, ctx):
+ ctx.set_source_rgba(0.3, 0.3, 0.3, 0.7)
+ for touch in self.touches.values():
+ x, y = touch
+ ctx.save()
+ ctx.arc(x, y, 60, 0., 2 * math.pi)
+ ctx.fill()
+ ctx.restore()
+
+
+def main():
+ window = Gtk.Window()
+ test_touch = TestTouch()
+
+ window.add(test_touch)
+ window.connect("destroy", Gtk.main_quit)
+ window.show_all()
+ window.maximize()
+ Gtk.main()
+
+if __name__ == "__main__":
+ main()
diff --git a/treeview_dnd_test.py b/treeview_dnd_test.py
new file mode 100644
index 0000000..315e20f
--- /dev/null
+++ b/treeview_dnd_test.py
@@ -0,0 +1,121 @@
+#!/usr/bin/env python
+
+# example treeviewdnd.py
+
+from gi.repository import Gtk, Gdk, Pango, GObject
+
+class TreeViewDnDExample:
+
+ TARGETS = [
+ ('MY_TREE_MODEL_ROW', Gtk.TargetFlags.SAME_WIDGET, 0),
+ ('text/plain', 0, 1),
+ ('TEXT', 0, 2),
+ ('STRING', 0, 3),
+ ]
+ # close the window and quit
+ def delete_event(self, widget, event, data=None):
+ Gtk.main_quit()
+ return False
+
+ def clear_selected(self, button):
+ selection = self.treeview.get_selection()
+ model, iter = selection.get_selected()
+ if iter:
+ model.remove(iter)
+ return
+
+ def __init__(self):
+ # Create a new window
+ self.window = Gtk.Window()
+
+ self.window.set_title("URL Cache")
+
+ self.window.set_size_request(200, 200)
+
+ self.window.connect("delete_event", self.delete_event)
+
+ self.scrolledwindow = Gtk.ScrolledWindow()
+ self.vbox = Gtk.VBox()
+ self.hbox = Gtk.HButtonBox()
+ self.vbox.pack_start(self.scrolledwindow, True, True, 0)
+ self.vbox.pack_start(self.hbox, False, True, 0)
+ self.b0 = Gtk.Button('Clear All')
+ self.b1 = Gtk.Button('Clear Selected')
+ self.hbox.pack_start(self.b0, True, True, 0)
+ self.hbox.pack_start(self.b1, True, True, 0)
+
+ # create a liststore with one string column to use as the model
+ self.liststore = Gtk.ListStore(str)
+
+ # create the TreeView using liststore
+ self.treeview = Gtk.TreeView(self.liststore)
+
+ # create a CellRenderer to render the data
+ self.cell = Gtk.CellRendererText()
+
+ # create the TreeViewColumns to display the data
+ self.tvcolumn = Gtk.TreeViewColumn('URL', self.cell, text=0)
+
+ # add columns to treeview
+ self.treeview.append_column(self.tvcolumn)
+ self.b0.connect_object('clicked', Gtk.ListStore.clear, self.liststore)
+ self.b1.connect('clicked', self.clear_selected)
+ # make treeview searchable
+ self.treeview.set_search_column(0)
+
+ # Allow sorting on the column
+ self.tvcolumn.set_sort_column_id(0)
+
+ # Allow enable drag and drop of rows including row move
+ self.treeview.enable_model_drag_source( Gdk.ModifierType.BUTTON1_MASK,
+ self.TARGETS,
+ Gdk.DragAction.DEFAULT|
+ Gdk.DragAction.MOVE)
+ self.treeview.enable_model_drag_dest(self.TARGETS,
+ Gdk.DragAction.DEFAULT)
+ self.treeview.drag_dest_add_text_targets()
+ self.treeview.drag_source_add_text_targets()
+
+ self.treeview.connect("drag_data_get", self.drag_data_get_data)
+ self.treeview.connect("drag_data_received",
+ self.drag_data_received_data)
+
+ self.scrolledwindow.add(self.treeview)
+ self.window.add(self.vbox)
+ self.window.show_all()
+
+ def drag_data_get_data(self, treeview, context, selection, target_id,
+ etime):
+ treeselection = treeview.get_selection()
+ model, iter = treeselection.get_selected()
+ print "model: %s, iter: %s" % (model, iter)
+ value = model.get_value(iter, 0)
+ print value
+ data = bytes(value)
+ selection.set(selection.get_target(), 8, data)
+
+ def drag_data_received_data(self, treeview, context, x, y, selection,
+ info, etime):
+ model = treeview.get_model()
+ data = selection.get_data().decode("utf-8")
+ drop_info = treeview.get_dest_row_at_pos(x, y)
+ if drop_info:
+ path, position = drop_info
+ iter = model.get_iter(path)
+ if (position == Gtk.TreeViewDropPosition.BEFORE
+ or position == Gtk.TreeViewDropPosition.BEFORE):
+ model.insert_before(iter, [data])
+ else:
+ model.insert_after(iter, [data])
+ else:
+ model.append([data])
+ if context.get_actions() == Gdk.DragAction.MOVE:
+ context.finish(True, True, etime)
+ return
+
+def main():
+ Gtk.main()
+
+if __name__ == "__main__":
+ treeviewdndex = TreeViewDnDExample()
+ main()
diff --git a/webkit_touch_test.py b/webkit_touch_test.py
new file mode 100644
index 0000000..87307a2
--- /dev/null
+++ b/webkit_touch_test.py
@@ -0,0 +1,27 @@
+from gi.repository import WebKit
+from gi.repository import Gtk
+from gi.repository import Gdk
+
+def _destroy_cb(widget, data=None):
+ Gtk.main_quit()
+
+def __event_cb(widget, event):
+ if event.type == Gdk.EventType.TOUCH_BEGIN:
+ print 'touch at', event.touch.x, event.touch.y
+
+window = Gtk.Window()
+window.set_default_size(800, 640)
+window.connect("destroy", _destroy_cb)
+window.add_events(Gdk.EventMask.TOUCH_MASK)
+
+b = WebKit.WebView()
+b.load_uri('http://google.com')
+window.add(b)
+b.realize()
+b.get_window().set_events(b.get_window().get_events()|
+ Gdk.EventMask.TOUCH_MASK)
+b.connect('event', __event_cb)
+b.show()
+
+window.show()
+Gtk.main()