summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRené Stadler <mail@renestadler.de>2007-06-08 21:33:43 +0200
committerRené Stadler <mail@renestadler.de>2007-06-08 21:33:43 +0200
commitdca2f585cf35b9199546f19144b8c5c74b891660 (patch)
tree827ef4aada8a289b4d99eb992973808a89044d75 /tests
Import from private development linev0.1
Diffstat (limited to 'tests')
-rwxr-xr-xtests/demo_namevalueview.py162
-rwxr-xr-xtests/test_main.py80
2 files changed, 242 insertions, 0 deletions
diff --git a/tests/demo_namevalueview.py b/tests/demo_namevalueview.py
new file mode 100755
index 0000000..2c98d4f
--- /dev/null
+++ b/tests/demo_namevalueview.py
@@ -0,0 +1,162 @@
+#!/usr/bin/env python
+# -*- coding: utf-8; mode: python; -*-
+#
+# GStreamer Inspector - Multimedia system plugin introspection
+#
+# Copyright (C) 2007 René Stadler <mail@renestadler.de>
+#
+# 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.
+
+"""GStreamer Inspector NameValuePageBase demo."""
+
+import sys
+import os
+import os.path
+
+sys.path.insert (0, os.path.join (sys.path[0], os.pardir))
+
+from GstInspector import GUI
+
+import gtk
+
+class Widgets (object):
+
+ def __init__ (self):
+
+ self.window = gtk.Window ()
+ self.window.set_default_size (400, 500)
+ self.window.props.border_width = 12
+ self.window.show ()
+
+ self.notebook = gtk.Notebook ()
+
+ self.demo_scrolled = gtk.ScrolledWindow ()
+ self.demo_scrolled.set_policy (gtk.POLICY_AUTOMATIC,
+ gtk.POLICY_AUTOMATIC)
+
+ self.demo_view = gtk.TreeView ()
+ self.demo_view.props.headers_visible = False
+
+ self.demo_scrolled.add_with_viewport (self.demo_view)
+ self.notebook.append_page (self.demo_scrolled,
+ gtk.Label ("spanning"))
+
+ self.normal_scrolled = gtk.ScrolledWindow ()
+ self.normal_scrolled.set_policy (gtk.POLICY_AUTOMATIC,
+ gtk.POLICY_AUTOMATIC)
+
+ self.normal_view = gtk.TreeView ()
+ self.normal_view.props.headers_visible = False
+
+ self.normal_scrolled.add_with_viewport (self.normal_view)
+ self.notebook.append_page (self.normal_scrolled,
+ gtk.Label ("normal"))
+
+ self.window.add (self.notebook)
+ self.window.show_all ()
+
+class DemoModel (GUI.NameValueModel):
+
+ def __init__ (self):
+
+ GUI.NameValueModel.__init__ (self)
+
+ def set (i, name, value):
+ self.set (i,
+ self.COL_NAME, name,
+ self.COL_VALUE, value)
+
+ i = None
+ for x in range (5):
+ i = self.append (i)
+ set (i, "Test %i" % (x,), "Nested further")
+
+ i = None
+ for x in range (5):
+ i = self.append (i)
+ if x % 2:
+ set (i, "Test %i" % (x,), "Name not spanning")
+ else:
+ set (i, "Test %i spanning" % (x,), None)
+ for x in range (3):
+ i2 = self.append (i)
+ set (i2, "Name", "value " * 12)
+
+class DemoPage (GUI.NameValuePageBase):
+
+ name = "demo"
+ view_name = "demo_view"
+ widget_name = "demo_scrolled"
+
+ def __init__ (self, *a, **kw):
+
+ GUI.NameValuePageBase.__init__ (self, *a, **kw)
+
+ view = self.view
+ view.props.model = DemoModel ()
+ view.expand_all ()
+ for column in view.get_columns ():
+ column.queue_resize ()
+
+rc_style = """
+
+style "demo"
+{
+ GtkWidget::focus-line-width = 4
+
+ GtkTreeView::expander-size = 32
+ GtkTreeView::horizontal-separator = 12
+ GtkTreeView::vertical-separator = 1
+}
+
+class "GtkWidget" style "demo"
+"""
+
+def main ():
+
+ ## gtk.rc_parse_string (rc_style)
+
+ widgets = Widgets ()
+
+ page = DemoPage (widgets)
+
+ view = widgets.normal_view
+ model = DemoModel ()
+ view.props.model = model
+
+ column = gtk.TreeViewColumn ("")
+ cell = gtk.CellRendererText ()
+ cell.props.cell_background = "blue"
+ cell.props.background = "yellow"
+ column.pack_start (cell, True)
+ column.add_attribute (cell, "text", model.COL_NAME)
+ view.append_column (column)
+ column = gtk.TreeViewColumn ("")
+ cell = gtk.CellRendererText ()
+ cell.props.cell_background = "red"
+ cell.props.background = "green"
+ column.pack_start (cell, True)
+ column.add_attribute (cell, "text", model.COL_VALUE)
+ view.append_column (column)
+
+ view.expand_all ()
+
+ def window_delete_event (window, event):
+ gtk.main_quit ()
+ widgets.window.connect ("delete-event", window_delete_event)
+ gtk.main ()
+
+if __name__ == "__main__":
+ main ()
diff --git a/tests/test_main.py b/tests/test_main.py
new file mode 100755
index 0000000..be4fff0
--- /dev/null
+++ b/tests/test_main.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+# -*- coding: utf-8; mode: python; -*-
+#
+# GStreamer Inspector - Multimedia system plugin introspection
+#
+# Copyright (C) 2007 René Stadler <mail@renestadler.de>
+#
+# 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.
+
+"""GStreamer Inspector test suite for the main module."""
+
+import sys
+import os
+import os.path
+
+sys.path.insert (0, os.path.join (sys.path[0], os.pardir))
+
+from unittest import TestCase, main as test_main
+
+import pygtk
+pygtk.require ("2.0")
+del pygtk
+
+import gobject
+import gtk
+
+from GstInspector import main
+
+class TestError (Exception):
+
+ pass
+
+class TestMainLoopWrapper (TestCase):
+
+ def setUp (self):
+
+ main.ExceptHookManager.setup ()
+
+ def tearDown (self):
+
+ # Restore any global settings to the defaults:
+ main.ExceptHookManager.shutdown ()
+ # Replace with a fresh instance to ensure all state is cleared:
+ main.ExceptHookManager = type (main.ExceptHookManager) ()
+
+ def test_gtk_main (self):
+
+ def quitting_timeout ():
+ gtk.main_quit ()
+ return False
+
+ gobject.timeout_add (100, quitting_timeout)
+
+ main.MainLoopWrapper (gtk.main, gtk.main_quit).run ()
+
+ def test_gtk_main_exception (self):
+
+ def failing_timeout ():
+ raise TestError ("testing exception handling")
+
+ gobject.timeout_add (100, failing_timeout)
+
+ run = main.MainLoopWrapper (gtk.main, gtk.main_quit).run
+
+ self.assertRaises (TestError, run)
+
+if __name__ == "__main__":
+ test_main ()