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
1=== modified file 'lib/GtkNode.cpp'
2--- lib/GtkNode.cpp 2013-06-27 04:47:48 +0000
3+++ lib/GtkNode.cpp 2013-06-27 06:09:24 +0000
4@@ -105,6 +105,10 @@
5 // add the names of our children
6 builder_wrapper.add("Children", GetChildNodeNames());
7
8+ // add the GtkBuilder name
9+ if (GTK_IS_BUILDABLE (object_))
10+ builder_wrapper.add("BuilderName", gtk_buildable_get_name(GTK_BUILDABLE (object_)));
11+
12 // add the GlobalRect property: "I am a GtkWidget" edition
13 if (GTK_IS_WIDGET(object_)) {
14 // FIXME: we'd like to remove this duplication (to GetGlobalRect)
15@@ -215,6 +219,11 @@
16 if (name == "id")
17 return value == std::to_string(GetObjectId());
18
19+ if (name == "BuilderName" && GTK_IS_BUILDABLE(object_)) {
20+ const gchar* name = gtk_buildable_get_name(GTK_BUILDABLE (object_));
21+ return name != NULL && std::string(name) == value;
22+ }
23+
24 GObjectClass* klass = G_OBJECT_GET_CLASS(object_);
25 GParamSpec* pspec = g_object_class_find_property(klass, name.c_str());
26 if (pspec == NULL)
27
28=== modified file 'tests/autopilot/tests/test_actions.py'
29--- tests/autopilot/tests/test_actions.py 2013-06-26 07:22:11 +0000
30+++ tests/autopilot/tests/test_actions.py 2013-06-27 06:09:24 +0000
31@@ -35,15 +35,8 @@
32 def test_greeting_keyboard(self):
33 """Greeting with keyboard navigation"""
34
35- entries = self.app.select_many('GtkEntry')
36- self.assertEqual(len(entries), 2)
37- # the upper entry is for the name, the lower for the color
38- # FIXME: once we have proper names (LP# 1082391), replace this with an
39- # assertion
40- if entries[0].globalRect[1] < entries[1].globalRect[1]:
41- (entry_name, entry_color) = entries
42- else:
43- (entry_color, entry_name) = entries
44+ entry_name = self.app.select_single(BuilderName='entry_name')
45+ entry_color = self.app.select_single(BuilderName='entry_color')
46
47 # FIXME: This isn't necessary for real X, but under Xvfb there is no
48 # default focus sometimes
49@@ -84,15 +77,8 @@
50 def test_greeting_mouse(self):
51 """Greeting with mouse navigation"""
52
53- entries = self.app.select_many('GtkEntry')
54- self.assertEqual(len(entries), 2)
55- # the upper entry is for the name, the lower for the color
56- # FIXME: once we have proper names (LP# 1082391), replace this with an
57- # assertion
58- if entries[0].globalRect[1] < entries[1].globalRect[1]:
59- (entry_name, entry_color) = entries
60- else:
61- (entry_color, entry_name) = entries
62+ entry_name = self.app.select_single(BuilderName='entry_name')
63+ entry_color = self.app.select_single(BuilderName='entry_color')
64
65 # FIXME: This isn't necessary for real X, but under Xvfb there is no
66 # default focus sometimes
67
68=== modified file 'tests/autopilot/tests/test_properties.py'
69--- tests/autopilot/tests/test_properties.py 2013-06-27 04:47:48 +0000
70+++ tests/autopilot/tests/test_properties.py 2013-06-27 06:09:24 +0000
71@@ -31,6 +31,20 @@
72 super(PropertyTest, self).setUp()
73 self.app = self.launch_test_application(test_app, app_type='gtk')
74
75+ def test_gtk_builder_name(self):
76+ """GtkBuilder name lookup"""
77+
78+ w = self.app.select_single(BuilderName='button_greet')
79+ self.assertNotEqual(w, None)
80+ self.assertEqual(w.label, 'Greet')
81+
82+ w = self.app.select_single(BuilderName='button_quit')
83+ self.assertNotEqual(w, None)
84+ self.assertEqual(w.label, 'gtk-quit')
85+
86+ w = self.app.select_single(BuilderName='entry_color')
87+ self.assertNotEqual(w, None)
88+
89 def test_button(self):
90 """GtkButton properties"""
91
92@@ -53,18 +67,15 @@
93 self.assertEqual(len(btn_greet.globalRect), 4)
94 self.assertEqual(len(btn_quit.globalRect), 4)
95
96+ # all our buttons have a GtkBuilder ID
97+ self.assertEqual(btn_greet.BuilderName, 'button_greet')
98+ self.assertEqual(btn_quit.BuilderName, 'button_quit')
99+
100 def test_entry(self):
101 """GtkEntry properties"""
102
103- entries = self.app.select_many('GtkEntry')
104- self.assertEqual(len(entries), 2)
105- # the upper entry is for the name, the lower for the color
106- # FIXME: once we have proper names (LP# 1082391), replace this with an
107- # assertion
108- if entries[0].globalRect[1] < entries[1].globalRect[1]:
109- (entry_name, entry_color) = entries
110- else:
111- (entry_color, entry_name) = entries
112+ entry_name = self.app.select_single(BuilderName='entry_name')
113+ entry_color = self.app.select_single(BuilderName='entry_color')
114
115 self.assertTrue(entry_name.visible)
116 self.assertTrue(entry_color.visible)
117@@ -78,6 +89,9 @@
118 if not entry_name.has_focus:
119 self.mouse.click_object(entry_name)
120
121+ # the color entry is below the name entry
122+ self.assertLess(entry_name.globalRect[1], entry_color.globalRect[1])
123+
124 # first entry has default focus
125 self.assertEqual(entry_name.has_focus, True)
126 self.assertEqual(entry_color.has_focus, False)

Subscribers

People subscribed via source and target branches

to all changes: