diff options
author | Manuel Kaufmann <humitos@gmail.com> | 2012-11-22 21:28:30 (GMT) |
---|---|---|
committer | Manuel Kaufmann <humitos@gmail.com> | 2012-11-22 21:28:30 (GMT) |
commit | 1d6008630248c4e234af1aed53ccf0732f9c0fc6 (patch) | |
tree | f811e086c7f63ab58a7c46681e57ecbf43b32c0f | |
parent | 73fc0f0736b1a1ebcb4f8281cbbf9926a09745f2 (diff) |
Many tests and one example
-rw-r--r-- | examples/gtk_treeview.py | 17 | ||||
-rw-r--r-- | tests/espeak_gst_1.py | 63 | ||||
-rw-r--r-- | tests/focus-button-osk-javascript.html | 19 | ||||
-rw-r--r-- | tests/focus-initial-osk-javascript.html | 20 | ||||
-rw-r--r-- | tests/gobject_handlers_block.py | 12 | ||||
-rw-r--r-- | tests/scrollable_inside_scrollable.py | 36 | ||||
-rw-r--r-- | tests/target_blank.html | 18 | ||||
-rw-r--r-- | tests/webkit_load_status.py | 38 | ||||
-rw-r--r-- | tests/webkit_window_features.py | 39 | ||||
-rw-r--r-- | tests/wikipedia_search.html | 25 | ||||
-rw-r--r-- | tests/zoom_center.py | 57 |
11 files changed, 344 insertions, 0 deletions
diff --git a/examples/gtk_treeview.py b/examples/gtk_treeview.py new file mode 100644 index 0000000..7884461 --- /dev/null +++ b/examples/gtk_treeview.py @@ -0,0 +1,17 @@ +from gi.repository import Gtk + + +def _destroy_cb(widget, data=None): + Gtk.main_quit() + +window = Gtk.Window() +window.connect("destroy", _destroy_cb) + +tree = Gtk.TreeView() +cell = Gtk.CellRendererToggle() + +tree.insert_column_with_attributes(0, 'Test', cell) + + +window.show_all() +Gtk.main() diff --git a/tests/espeak_gst_1.py b/tests/espeak_gst_1.py new file mode 100644 index 0000000..ef9402f --- /dev/null +++ b/tests/espeak_gst_1.py @@ -0,0 +1,63 @@ +from gi.repository import Gtk +from gi.repository import Gst +from gi.repository import GObject + +GObject.threads_init() + +import gi +gi.require_version('Gtk', '3.0') +gi.require_version('Gst', '1.0') + +Gst.init(None) + +# pipeline = None +# bus = None + + +def _destroy_cb(widget, data=None): + Gtk.main_quit() + +window = Gtk.Window() +window.set_default_size(100, 40) +window.connect("destroy", _destroy_cb) + + +def pipe_message_cb(bus, message, pipeline): + if message.type == Gst.MessageType.EOS: + print 'EOS' + pipeline.set_state(Gst.State.NULL) + elif message.type == Gst.MessageType.ERROR: + print 'ERROR' + pipeline.set_state(Gst.State.NULL) + print Gst.Message.parse_error(message) + # else: + # print 'Error' + # print message.type + + +def play(*args, **kargs): + # global pipeline, bus + + pipeline = Gst.parse_launch('espeak name=espeak ! autovideosink') + + bus = pipeline.get_bus() + bus.add_signal_watch() + bus.connect('message', pipe_message_cb, pipeline) + + src = pipeline.get_by_name('espeak') + + src.props.text = 'Hello Manuel Kaufmann. Please, type something' + src.props.rate = 0 + src.props.pitch = 0 + src.props.voice = 'default' + # src.props.voice = 'en_GB.utf8' + src.props.track = 2 + + # pipeline.set_state(Gst.State.NULL) + pipeline.set_state(Gst.State.PLAYING) + +button = Gtk.Button('Click me!') +button.connect('clicked', play) +window.add(button) +window.show_all() +Gtk.main() diff --git a/tests/focus-button-osk-javascript.html b/tests/focus-button-osk-javascript.html new file mode 100644 index 0000000..3b3519b --- /dev/null +++ b/tests/focus-button-osk-javascript.html @@ -0,0 +1,19 @@ +<!DOCTYPE HTML> +<html> + <head> + <meta http-equiv="Content-type" content="text/html; charset=utf-8"> + <title>Focus OSK test case</title> + </head> + <body> + + <p>This page will be loaded without focusing anything and after clicking + the "Click me!" button the focus will be taken to the input field and + OSK should appear</p> + + <form action="." name="f" target="_top"> + <input maxlength=2048 name="q" value="" style="height: 200px; width: 500px;"/> + <input type="button" value="Click me!" style="height: 200px; width: 200px;" onclick="javascript: document.f.q.focus()" /> + </form> +</body> +</html> + diff --git a/tests/focus-initial-osk-javascript.html b/tests/focus-initial-osk-javascript.html new file mode 100644 index 0000000..51ab5c0 --- /dev/null +++ b/tests/focus-initial-osk-javascript.html @@ -0,0 +1,20 @@ +<!DOCTYPE HTML> +<html> + <head> + <meta http-equiv="Content-type" content="text/html; charset=utf-8"> + <title>Focus OSK test case</title> + </head> + <body onload="javascript: document.f.q.focus()"> + + <p>This page will be loaded focusing on the input field. You + can click the "Click me!" button to focus it again after + loosing the focus by clicking outside. OSK should appear + everytime the input field has the focus.</p> + + <form action="." name="f" target="_top"> + <input maxlength=2048 name="q" value="" style="height: 200px; width: 500px;"/> + <input type="button" value="Click me!" style="height: 200px; width: 200px;" onclick="javascript: document.f.q.focus()" /> + </form> +</body> +</html> + diff --git a/tests/gobject_handlers_block.py b/tests/gobject_handlers_block.py new file mode 100644 index 0000000..fe1bd52 --- /dev/null +++ b/tests/gobject_handlers_block.py @@ -0,0 +1,12 @@ +from gi.repository import Gtk +from gi.repository import GObject + + +def my_func(*args, **kargs): + print 'my_func was called.' + + +adj = Gtk.Adjustment() +sw = Gtk.ScrolledWindow() +GObject.signal_handlers_block_matched(adj, GObject.SignalMatchType.ID, 0, 0, None, my_func, sw) + diff --git a/tests/scrollable_inside_scrollable.py b/tests/scrollable_inside_scrollable.py new file mode 100644 index 0000000..47cf776 --- /dev/null +++ b/tests/scrollable_inside_scrollable.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +from gi.repository import Gtk + + +def main(): + window = Gtk.Window() + window.set_default_size(400, 400) + + tv1 = Gtk.TextView() + tv2 = Gtk.TextView() + + label = Gtk.Label() + label.set_text('Separator') + + sw1 = Gtk.ScrolledWindow() + sw1.add(tv1) + + sw2 = Gtk.ScrolledWindow() + sw2.add(tv2) + + container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + container.pack_start(sw1, True, True, 0) + container.add(label) + container.pack_start(sw2, True, True, 0) + + sw3 = Gtk.ScrolledWindow() + sw3.add(container) + + window.add(sw3) + window.connect("destroy", Gtk.main_quit) + window.show_all() + Gtk.main() + +if __name__ == "__main__": + main() diff --git a/tests/target_blank.html b/tests/target_blank.html new file mode 100644 index 0000000..6dd5dab --- /dev/null +++ b/tests/target_blank.html @@ -0,0 +1,18 @@ +<html> + +<head> +</head> + +<body> +<a target="_blank" href="http://google.com">Go to Google.com</a> + +<form id="tntdispatcher" class="form" target="_blank" method="get" action="http://nolp.dhl.de/nextt-online-public/set_identcodes.do"> +<input type="hidden" value="en" name="lang" /> +<input type="hidden" value="350043001668" name="idc" /> +<input type="submit" value="Buscar" /> +</form> + + +</body> + +</html> diff --git a/tests/webkit_load_status.py b/tests/webkit_load_status.py new file mode 100644 index 0000000..1d6649f --- /dev/null +++ b/tests/webkit_load_status.py @@ -0,0 +1,38 @@ +from gi.repository import Gtk +from gi.repository import WebKit +from gi.repository import GObject + + +class MyWindow(Gtk.Window): + + def __init__(self): + Gtk.Window.__init__(self, title="WebKit load-status FAILED") + self.set_default_size(1000, 500) + self.connect("delete-event", Gtk.main_quit) + + webview = WebKit.WebView() + webview.connect('notify::load-status', self.__load_status_changed_cb) + webview.connect('load-error', self.__load_error_cb) + webview.load_uri('http://www.google.com') + + self.add(webview) + self.show_all() + + def __load_error_cb(self, web_view, web_frame, uri, web_error): + print '### WEB_ERROR_CODE:', web_error.code + + def __load_status_changed_cb(self, widget, param): + status = widget.get_load_status() + if status is WebKit.LoadStatus.COMMITTED: + GObject.timeout_add(40, self.__stop_loading, widget) + print '### STATUS:', status + print '### URI:', widget.props.uri + + def __stop_loading(self, webview): + print 'WebKit.WebView.stop_loading' + webview.stop_loading() + + +if __name__ == '__main__': + win = MyWindow() + Gtk.main() diff --git a/tests/webkit_window_features.py b/tests/webkit_window_features.py new file mode 100644 index 0000000..1a29180 --- /dev/null +++ b/tests/webkit_window_features.py @@ -0,0 +1,39 @@ +from gi.repository import Gtk +from gi.repository import WebKit + + +class MyWindow(Gtk.Window): + + def __init__(self): + Gtk.Window.__init__(self, title='WebKit Scroll Bars') + self.set_default_size(250, 200) + self.connect("delete-event", Gtk.main_quit) + + self.webview = WebKit.WebView(self_scrolling=True) + # self.webview.props.self_scrolling = True + self.window_features = self.webview.get_window_features() + self.window_features.connect( + 'notify::height', self.__height_cb) + self.webview.connect( + 'notify::load-status', self.__load_status_changed_cb) + self.webview.connect( + 'notify::window-features', self.__window_features_cb) + + self.webview.load_uri('http://css-tricks.com/examples/WebKitScrollbars/') + + self.add(self.webview) + self.show_all() + + def __window_features_cb(self, *args, **kwargs): + print '__window_features_cb' + + def __height_cb(self, *args, **kwargs): + print '__height_cb' + + def __load_status_changed_cb(self, *args, **kwargs): + print 'scrollbar-visible:', self.webview.props.window_features.props.scrollbar_visible + + +if __name__ == '__main__': + win = MyWindow() + Gtk.main() diff --git a/tests/wikipedia_search.html b/tests/wikipedia_search.html new file mode 100644 index 0000000..06812b4 --- /dev/null +++ b/tests/wikipedia_search.html @@ -0,0 +1,25 @@ +<html> + + <head> + <title>wikipedia search</title> + + <!-- <script src="http://bits.wikimedia.org/en.wikipedia.org/load.php?debug=false&lang=en&modules=ext.EventLogging%2CUserBuckets%2CmarkAsHelpful%2CpostEdit|ext.Experiments.experiments%2Clib|ext.articleFeedback.startup|ext.articleFeedbackv5.startup|ext.gadget.DRN-wizard%2CReferenceTooltips%2Ccharinsert%2Cteahouse|jquery.articleFeedbackv5.verify|jquery.autoEllipsis%2CcheckboxShiftClick%2CclickTracking%2CcollapsibleTabs%2CdelayedBind%2Chidpi%2ChighlightText%2Cjson%2CmakeCollapsible%2Cmw-jump%2Cplaceholder%2Csuggestions%2CtabIndex|mediawiki.api%2Chidpi%2CsearchSuggest%2Cuser|mediawiki.page.ready|mw.MwEmbedSupport.style|mw.PopUpMediaTransform&skin=vector&version=20121120T025205Z&*"> </script> --> + </head> + + <body> + <div id="p-search" role="search"> + <h5> + <label for="searchInput">Search</label> + </h5> + <form id="searchform" action="https://en.wikipedia.org/w/index.php"> + <div id="simpleSearch"> + <input id="searchInput" accesskey="f" title="Search Wikipedia [alt-shift-f]" name="search" autocomplete="off" placeholder="Search" tabindex="1"> + <button id="searchButton" title="Search Wikipedia for this text" name="button"> + <img width="12" height="13" alt="Search" src="//bits.wikimedia.org/static-1.21wmf4/skins/vector/images/search-ltr.png?303-4"> + </button> + <input type="hidden" value="Special:Search" name="title"> + </div> + </form> + </div> + </body> +</html> diff --git a/tests/zoom_center.py b/tests/zoom_center.py new file mode 100644 index 0000000..db96b04 --- /dev/null +++ b/tests/zoom_center.py @@ -0,0 +1,57 @@ +#!/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 +import random + +COLORS = (0.1, 0.2, 0.3, 0.4) + + +class TestTouch(Gtk.DrawingArea): + + def __init__(self): + super(TestTouch, self).__init__() + + self.touch = None + + self.set_events(Gdk.EventMask.TOUCH_MASK) + self.connect('draw', self.__draw_cb) + self.connect('event', self.__event_cb) + + def __event_cb(self, widget, event): + if event.type == Gdk.EventType.TOUCH_BEGIN: + self.touch = 200, 200 + self.queue_draw() + else: + self.touch = None + + def __draw_cb(self, widget, ctx): + if self.touch is None: + return + + for x in range(1, 10): + color = random.choice(COLORS) + ctx.set_source_rgba(color, color, color, 0.7) + ctx.save() + ctx.arc(x, y, 60 * x, 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.set_requested_size(400, 400) + Gtk.main() + +if __name__ == "__main__": + main() |