Merge lp:~pitti/autopilot-gtk/gtkbuilder-names into lp:autopilot-gtk

Proposed by Martin Pitt
Status: Merged
Approved by: Martin Pitt
Approved revision: 48
Merged at revision: 48
Proposed branch: lp:~pitti/autopilot-gtk/gtkbuilder-names
Merge into: lp:autopilot-gtk
Diff against target: 126 lines (+36/-27)
3 files modified
lib/GtkNode.cpp (+9/-0)
tests/autopilot/tests/test_actions.py (+4/-18)
tests/autopilot/tests/test_properties.py (+23/-9)
To merge this branch: bzr merge lp:~pitti/autopilot-gtk/gtkbuilder-names
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Thomi Richards (community) Approve
Review via email: mp+171709@code.launchpad.net

Commit message

Expose GtkBuilder widget identifiers as "BuilderName" property. (LP: #1082391)

Description of the change

The objects on the application widget tree should have proper identifiers that
are given to them in the GtkBuilder .ui files. These identifiers are the ones
that the actual program code uses to refer to them, so they are both stable,
and also the most appropriate means to identify a particular widget.

This branch exposes them as "BuilderName" property (capitalized to avoid
potential conflict with real GTK widget properties), and adds/updates the test
cases accordingly.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Looks awesome.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
48. By Martin Pitt

merge with trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/GtkNode.cpp'
--- lib/GtkNode.cpp 2013-06-27 04:47:48 +0000
+++ lib/GtkNode.cpp 2013-06-27 06:09:24 +0000
@@ -105,6 +105,10 @@
105 // add the names of our children105 // add the names of our children
106 builder_wrapper.add("Children", GetChildNodeNames());106 builder_wrapper.add("Children", GetChildNodeNames());
107107
108 // add the GtkBuilder name
109 if (GTK_IS_BUILDABLE (object_))
110 builder_wrapper.add("BuilderName", gtk_buildable_get_name(GTK_BUILDABLE (object_)));
111
108 // add the GlobalRect property: "I am a GtkWidget" edition112 // add the GlobalRect property: "I am a GtkWidget" edition
109 if (GTK_IS_WIDGET(object_)) {113 if (GTK_IS_WIDGET(object_)) {
110 // FIXME: we'd like to remove this duplication (to GetGlobalRect)114 // FIXME: we'd like to remove this duplication (to GetGlobalRect)
@@ -215,6 +219,11 @@
215 if (name == "id")219 if (name == "id")
216 return value == std::to_string(GetObjectId());220 return value == std::to_string(GetObjectId());
217221
222 if (name == "BuilderName" && GTK_IS_BUILDABLE(object_)) {
223 const gchar* name = gtk_buildable_get_name(GTK_BUILDABLE (object_));
224 return name != NULL && std::string(name) == value;
225 }
226
218 GObjectClass* klass = G_OBJECT_GET_CLASS(object_);227 GObjectClass* klass = G_OBJECT_GET_CLASS(object_);
219 GParamSpec* pspec = g_object_class_find_property(klass, name.c_str());228 GParamSpec* pspec = g_object_class_find_property(klass, name.c_str());
220 if (pspec == NULL)229 if (pspec == NULL)
221230
=== modified file 'tests/autopilot/tests/test_actions.py'
--- tests/autopilot/tests/test_actions.py 2013-06-26 07:22:11 +0000
+++ tests/autopilot/tests/test_actions.py 2013-06-27 06:09:24 +0000
@@ -35,15 +35,8 @@
35 def test_greeting_keyboard(self):35 def test_greeting_keyboard(self):
36 """Greeting with keyboard navigation"""36 """Greeting with keyboard navigation"""
3737
38 entries = self.app.select_many('GtkEntry')38 entry_name = self.app.select_single(BuilderName='entry_name')
39 self.assertEqual(len(entries), 2)39 entry_color = self.app.select_single(BuilderName='entry_color')
40 # the upper entry is for the name, the lower for the color
41 # FIXME: once we have proper names (LP# 1082391), replace this with an
42 # assertion
43 if entries[0].globalRect[1] < entries[1].globalRect[1]:
44 (entry_name, entry_color) = entries
45 else:
46 (entry_color, entry_name) = entries
4740
48 # FIXME: This isn't necessary for real X, but under Xvfb there is no41 # FIXME: This isn't necessary for real X, but under Xvfb there is no
49 # default focus sometimes42 # default focus sometimes
@@ -84,15 +77,8 @@
84 def test_greeting_mouse(self):77 def test_greeting_mouse(self):
85 """Greeting with mouse navigation"""78 """Greeting with mouse navigation"""
8679
87 entries = self.app.select_many('GtkEntry')80 entry_name = self.app.select_single(BuilderName='entry_name')
88 self.assertEqual(len(entries), 2)81 entry_color = self.app.select_single(BuilderName='entry_color')
89 # the upper entry is for the name, the lower for the color
90 # FIXME: once we have proper names (LP# 1082391), replace this with an
91 # assertion
92 if entries[0].globalRect[1] < entries[1].globalRect[1]:
93 (entry_name, entry_color) = entries
94 else:
95 (entry_color, entry_name) = entries
9682
97 # FIXME: This isn't necessary for real X, but under Xvfb there is no83 # FIXME: This isn't necessary for real X, but under Xvfb there is no
98 # default focus sometimes84 # default focus sometimes
9985
=== modified file 'tests/autopilot/tests/test_properties.py'
--- tests/autopilot/tests/test_properties.py 2013-06-27 04:47:48 +0000
+++ tests/autopilot/tests/test_properties.py 2013-06-27 06:09:24 +0000
@@ -31,6 +31,20 @@
31 super(PropertyTest, self).setUp()31 super(PropertyTest, self).setUp()
32 self.app = self.launch_test_application(test_app, app_type='gtk')32 self.app = self.launch_test_application(test_app, app_type='gtk')
3333
34 def test_gtk_builder_name(self):
35 """GtkBuilder name lookup"""
36
37 w = self.app.select_single(BuilderName='button_greet')
38 self.assertNotEqual(w, None)
39 self.assertEqual(w.label, 'Greet')
40
41 w = self.app.select_single(BuilderName='button_quit')
42 self.assertNotEqual(w, None)
43 self.assertEqual(w.label, 'gtk-quit')
44
45 w = self.app.select_single(BuilderName='entry_color')
46 self.assertNotEqual(w, None)
47
34 def test_button(self):48 def test_button(self):
35 """GtkButton properties"""49 """GtkButton properties"""
3650
@@ -53,18 +67,15 @@
53 self.assertEqual(len(btn_greet.globalRect), 4)67 self.assertEqual(len(btn_greet.globalRect), 4)
54 self.assertEqual(len(btn_quit.globalRect), 4)68 self.assertEqual(len(btn_quit.globalRect), 4)
5569
70 # all our buttons have a GtkBuilder ID
71 self.assertEqual(btn_greet.BuilderName, 'button_greet')
72 self.assertEqual(btn_quit.BuilderName, 'button_quit')
73
56 def test_entry(self):74 def test_entry(self):
57 """GtkEntry properties"""75 """GtkEntry properties"""
5876
59 entries = self.app.select_many('GtkEntry')77 entry_name = self.app.select_single(BuilderName='entry_name')
60 self.assertEqual(len(entries), 2)78 entry_color = self.app.select_single(BuilderName='entry_color')
61 # the upper entry is for the name, the lower for the color
62 # FIXME: once we have proper names (LP# 1082391), replace this with an
63 # assertion
64 if entries[0].globalRect[1] < entries[1].globalRect[1]:
65 (entry_name, entry_color) = entries
66 else:
67 (entry_color, entry_name) = entries
6879
69 self.assertTrue(entry_name.visible)80 self.assertTrue(entry_name.visible)
70 self.assertTrue(entry_color.visible)81 self.assertTrue(entry_color.visible)
@@ -78,6 +89,9 @@
78 if not entry_name.has_focus:89 if not entry_name.has_focus:
79 self.mouse.click_object(entry_name)90 self.mouse.click_object(entry_name)
8091
92 # the color entry is below the name entry
93 self.assertLess(entry_name.globalRect[1], entry_color.globalRect[1])
94
81 # first entry has default focus95 # first entry has default focus
82 self.assertEqual(entry_name.has_focus, True)96 self.assertEqual(entry_name.has_focus, True)
83 self.assertEqual(entry_color.has_focus, False)97 self.assertEqual(entry_color.has_focus, False)

Subscribers

People subscribed via source and target branches

to all changes: