summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/ui/crumbs/hig/settingsuihelper.py
diff options
context:
space:
mode:
authorBogdan Marinescu <bogdan.a.marinescu@intel.com>2013-01-10 13:08:02 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-01-16 12:51:33 +0000
commit7bfb98568a1d7ba8dbd95332d65cd19faec6c725 (patch)
tree6a6d18d67a80e8ca862435d09c3ae63215659c7a /bitbake/lib/bb/ui/crumbs/hig/settingsuihelper.py
parenta746719a46e9277a118fd7d4a6342bb667034132 (diff)
downloadpoky-7bfb98568a1d7ba8dbd95332d65cd19faec6c725.tar.gz
bitbake: hig.py: refactor into individual components
Since hig.py was becoming too large (which impacted maintenance and operations like git merges) it was split into individual files for the classes that were implemented in hig.py. hig is now a Python package (lib/bb/ui/crumbs/hig/). The patch was tested by building core-image-basic/qemux86 in Hob and accessing the various UI elements implemented in hig. Note that the patch does not change the functionality of Hob in any way, it's just a code refactoring that should make life a bit easier for Hob developers. [YOCTO #3200] (Bitbake rev: a7a2b730f915cafe7aa30539622dd1ca64ae41f5) Signed-off-by: Bogdan Marinescu <bogdan.a.marinescu@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/ui/crumbs/hig/settingsuihelper.py')
-rw-r--r--bitbake/lib/bb/ui/crumbs/hig/settingsuihelper.py216
1 files changed, 216 insertions, 0 deletions
diff --git a/bitbake/lib/bb/ui/crumbs/hig/settingsuihelper.py b/bitbake/lib/bb/ui/crumbs/hig/settingsuihelper.py
new file mode 100644
index 0000000000..e10dd064ab
--- /dev/null
+++ b/bitbake/lib/bb/ui/crumbs/hig/settingsuihelper.py
@@ -0,0 +1,216 @@
1#
2# BitBake Graphical GTK User Interface
3#
4# Copyright (C) 2011-2012 Intel Corporation
5#
6# Authored by Joshua Lock <josh@linux.intel.com>
7# Authored by Dongxiao Xu <dongxiao.xu@intel.com>
8# Authored by Shane Wang <shane.wang@intel.com>
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License version 2 as
12# published by the Free Software Foundation.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License along
20# with this program; if not, write to the Free Software Foundation, Inc.,
21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23import gtk
24import os
25from bb.ui.crumbs.hobwidget import HobInfoButton, HobButton, HobAltButton
26
27"""
28The following are convenience classes for implementing GNOME HIG compliant
29BitBake GUI's
30In summary: spacing = 12px, border-width = 6px
31"""
32
33class SettingsUIHelper():
34
35 def gen_label_widget(self, content):
36 label = gtk.Label()
37 label.set_alignment(0, 0)
38 label.set_markup(content)
39 label.show()
40 return label
41
42 def gen_label_info_widget(self, content, tooltip):
43 table = gtk.Table(1, 10, False)
44 label = self.gen_label_widget(content)
45 info = HobInfoButton(tooltip, self)
46 table.attach(label, 0, 1, 0, 1, xoptions=gtk.FILL)
47 table.attach(info, 1, 2, 0, 1, xoptions=gtk.FILL, xpadding=10)
48 return table
49
50 def gen_spinner_widget(self, content, lower, upper, tooltip=""):
51 hbox = gtk.HBox(False, 12)
52 adjust = gtk.Adjustment(value=content, lower=lower, upper=upper, step_incr=1)
53 spinner = gtk.SpinButton(adjustment=adjust, climb_rate=1, digits=0)
54
55 spinner.set_value(content)
56 hbox.pack_start(spinner, expand=False, fill=False)
57
58 info = HobInfoButton(tooltip, self)
59 hbox.pack_start(info, expand=False, fill=False)
60
61 hbox.show_all()
62 return hbox, spinner
63
64 def gen_combo_widget(self, curr_item, all_item, tooltip=""):
65 hbox = gtk.HBox(False, 12)
66 combo = gtk.combo_box_new_text()
67 hbox.pack_start(combo, expand=False, fill=False)
68
69 index = 0
70 for item in all_item or []:
71 combo.append_text(item)
72 if item == curr_item:
73 combo.set_active(index)
74 index += 1
75
76 info = HobInfoButton(tooltip, self)
77 hbox.pack_start(info, expand=False, fill=False)
78
79 hbox.show_all()
80 return hbox, combo
81
82 def entry_widget_select_path_cb(self, action, parent, entry):
83 dialog = gtk.FileChooserDialog("", parent,
84 gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
85 text = entry.get_text()
86 dialog.set_current_folder(text if len(text) > 0 else os.getcwd())
87 button = dialog.add_button("Cancel", gtk.RESPONSE_NO)
88 HobAltButton.style_button(button)
89 button = dialog.add_button("Open", gtk.RESPONSE_YES)
90 HobButton.style_button(button)
91 response = dialog.run()
92 if response == gtk.RESPONSE_YES:
93 path = dialog.get_filename()
94 entry.set_text(path)
95
96 dialog.destroy()
97
98 def gen_entry_widget(self, content, parent, tooltip="", need_button=True):
99 hbox = gtk.HBox(False, 12)
100 entry = gtk.Entry()
101 entry.set_text(content)
102 entry.set_size_request(350,30)
103
104 if need_button:
105 table = gtk.Table(1, 10, False)
106 hbox.pack_start(table, expand=True, fill=True)
107 table.attach(entry, 0, 9, 0, 1, xoptions=gtk.SHRINK)
108 image = gtk.Image()
109 image.set_from_stock(gtk.STOCK_OPEN,gtk.ICON_SIZE_BUTTON)
110 open_button = gtk.Button()
111 open_button.set_image(image)
112 open_button.connect("clicked", self.entry_widget_select_path_cb, parent, entry)
113 table.attach(open_button, 9, 10, 0, 1, xoptions=gtk.SHRINK)
114 else:
115 hbox.pack_start(entry, expand=True, fill=True)
116
117 if tooltip != "":
118 info = HobInfoButton(tooltip, self)
119 hbox.pack_start(info, expand=False, fill=False)
120
121 hbox.show_all()
122 return hbox, entry
123
124 def gen_mirror_entry_widget(self, content, index, match_content=""):
125 hbox = gtk.HBox(False)
126 entry = gtk.Entry()
127 content = content[:-2]
128 entry.set_text(content)
129 entry.set_size_request(350,30)
130
131 entry_match = gtk.Entry()
132 entry_match.set_text(match_content)
133 entry_match.set_size_request(100,30)
134
135 table = gtk.Table(2, 5, False)
136 table.set_row_spacings(12)
137 table.set_col_spacings(6)
138 hbox.pack_start(table, expand=True, fill=True)
139
140 label_configuration = gtk.Label("Configuration")
141 label_configuration.set_alignment(0.0,0.5)
142 label_mirror_url = gtk.Label("Mirror URL")
143 label_mirror_url.set_alignment(0.0,0.5)
144 label_match = gtk.Label("Match")
145 label_match.set_alignment(0.0,0.5)
146 label_replace_with = gtk.Label("Replace with")
147 label_replace_with.set_alignment(0.0,0.5)
148
149 combo = gtk.combo_box_new_text()
150 combo.append_text("Standard")
151 combo.append_text("Custom")
152 if match_content == "":
153 combo.set_active(0)
154 else:
155 combo.set_active(1)
156 combo.connect("changed", self.on_combo_changed, index)
157 combo.set_size_request(100,30)
158
159 delete_button = HobAltButton("Delete")
160 delete_button.connect("clicked", self.delete_cb, index, entry)
161 if content == "" and index == 0 and len(self.sstatemirrors_list) == 1:
162 delete_button.set_sensitive(False)
163 delete_button.set_size_request(100, 30)
164
165 entry_match.connect("changed", self.insert_entry_match_cb, index)
166 entry.connect("changed", self.insert_entry_cb, index, delete_button)
167
168 if match_content == "":
169 table.attach(label_configuration, 1, 2, 0, 1, xoptions=gtk.SHRINK|gtk.FILL)
170 table.attach(label_mirror_url, 2, 3, 0, 1, xoptions=gtk.SHRINK|gtk.FILL)
171 table.attach(combo, 1, 2, 1, 2, xoptions=gtk.SHRINK)
172 table.attach(entry, 2, 3, 1, 2, xoptions=gtk.SHRINK)
173 table.attach(delete_button, 3, 4, 1, 2, xoptions=gtk.SHRINK)
174 else:
175 table.attach(label_configuration, 1, 2, 0, 1, xoptions=gtk.SHRINK|gtk.FILL)
176 table.attach(label_match, 2, 3, 0, 1, xoptions=gtk.SHRINK|gtk.FILL)
177 table.attach(label_replace_with, 3, 4, 0, 1, xoptions=gtk.SHRINK|gtk.FILL)
178 table.attach(combo, 1, 2, 1, 2, xoptions=gtk.SHRINK)
179 table.attach(entry_match, 2, 3, 1, 2, xoptions=gtk.SHRINK)
180 table.attach(entry, 3, 4, 1, 2, xoptions=gtk.SHRINK)
181 table.attach(delete_button, 4, 5, 1, 2, xoptions=gtk.SHRINK)
182
183 hbox.show_all()
184 return hbox
185
186 def insert_entry_match_cb(self, entry_match, index):
187 self.sstatemirrors_list[index][2] = entry_match.get_text()
188
189 def insert_entry_cb(self, entry, index, button):
190 self.sstatemirrors_list[index][1] = entry.get_text()
191 if entry.get_text() == "" and index == 0:
192 button.set_sensitive(False)
193 else:
194 button.set_sensitive(True)
195
196 def on_combo_changed(self, combo, index):
197 if combo.get_active_text() == "Standard":
198 self.sstatemirrors_list[index][0] = 0
199 self.sstatemirrors_list[index][2] = "file://(.*)"
200 else:
201 self.sstatemirrors_list[index][0] = 1
202 self.refresh_shared_state_page()
203
204 def delete_cb(self, button, index, entry):
205 if index == 0 and len(self.sstatemirrors_list)==1:
206 entry.set_text("")
207 else:
208 self.sstatemirrors_list.pop(index)
209 self.refresh_shared_state_page()
210
211 def add_mirror(self, button):
212 tooltip = "Select the pre-built mirror that will speed your build"
213 index = len(self.sstatemirrors_list)
214 sm_list = [0, "", "file://(.*)"]
215 self.sstatemirrors_list.append(sm_list)
216 self.refresh_shared_state_page()