Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # BitBake Graphical GTK User Interface |
| 4 | # |
| 5 | # Copyright (C) 2012 Intel Corporation |
| 6 | # |
| 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 | |
| 23 | import gtk |
| 24 | import glib |
| 25 | from bb.ui.crumbs.hobcolor import HobColors |
| 26 | from bb.ui.crumbs.hobwidget import HobViewTable, HobNotebook, HobAltButton, HobButton |
| 27 | from bb.ui.crumbs.hoblistmodel import RecipeListModel |
| 28 | from bb.ui.crumbs.hobpages import HobPage |
| 29 | |
| 30 | # |
| 31 | # RecipeSelectionPage |
| 32 | # |
| 33 | class RecipeSelectionPage (HobPage): |
| 34 | pages = [ |
| 35 | { |
| 36 | 'name' : 'Included recipes', |
| 37 | 'tooltip' : 'The recipes currently included for your image', |
| 38 | 'filter' : { RecipeListModel.COL_INC : [True], |
| 39 | RecipeListModel.COL_TYPE : ['recipe', 'packagegroup'] }, |
| 40 | 'search' : 'Search recipes by name', |
| 41 | 'searchtip' : 'Enter a recipe name to find it', |
| 42 | 'columns' : [{ |
| 43 | 'col_name' : 'Recipe name', |
| 44 | 'col_id' : RecipeListModel.COL_NAME, |
| 45 | 'col_style': 'text', |
| 46 | 'col_min' : 100, |
| 47 | 'col_max' : 400, |
| 48 | 'expand' : 'True' |
| 49 | }, { |
| 50 | 'col_name' : 'Group', |
| 51 | 'col_id' : RecipeListModel.COL_GROUP, |
| 52 | 'col_style': 'text', |
| 53 | 'col_min' : 100, |
| 54 | 'col_max' : 300, |
| 55 | 'expand' : 'True' |
| 56 | }, { |
| 57 | 'col_name' : 'Brought in by (+others)', |
| 58 | 'col_id' : RecipeListModel.COL_BINB, |
| 59 | 'col_style': 'binb', |
| 60 | 'col_min' : 100, |
| 61 | 'col_max' : 500, |
| 62 | 'expand' : 'True' |
| 63 | }, { |
| 64 | 'col_name' : 'Included', |
| 65 | 'col_id' : RecipeListModel.COL_INC, |
| 66 | 'col_style': 'check toggle', |
| 67 | 'col_min' : 100, |
| 68 | 'col_max' : 100 |
| 69 | }] |
| 70 | }, { |
| 71 | 'name' : 'All recipes', |
| 72 | 'tooltip' : 'All recipes in your configured layers', |
| 73 | 'filter' : { RecipeListModel.COL_TYPE : ['recipe'] }, |
| 74 | 'search' : 'Search recipes by name', |
| 75 | 'searchtip' : 'Enter a recipe name to find it', |
| 76 | 'columns' : [{ |
| 77 | 'col_name' : 'Recipe name', |
| 78 | 'col_id' : RecipeListModel.COL_NAME, |
| 79 | 'col_style': 'text', |
| 80 | 'col_min' : 100, |
| 81 | 'col_max' : 400, |
| 82 | 'expand' : 'True' |
| 83 | }, { |
| 84 | 'col_name' : 'Group', |
| 85 | 'col_id' : RecipeListModel.COL_GROUP, |
| 86 | 'col_style': 'text', |
| 87 | 'col_min' : 100, |
| 88 | 'col_max' : 400, |
| 89 | 'expand' : 'True' |
| 90 | }, { |
| 91 | 'col_name' : 'License', |
| 92 | 'col_id' : RecipeListModel.COL_LIC, |
| 93 | 'col_style': 'text', |
| 94 | 'col_min' : 100, |
| 95 | 'col_max' : 400, |
| 96 | 'expand' : 'True' |
| 97 | }, { |
| 98 | 'col_name' : 'Included', |
| 99 | 'col_id' : RecipeListModel.COL_INC, |
| 100 | 'col_style': 'check toggle', |
| 101 | 'col_min' : 100, |
| 102 | 'col_max' : 100 |
| 103 | }] |
| 104 | }, { |
| 105 | 'name' : 'Package Groups', |
| 106 | 'tooltip' : 'All package groups in your configured layers', |
| 107 | 'filter' : { RecipeListModel.COL_TYPE : ['packagegroup'] }, |
| 108 | 'search' : 'Search package groups by name', |
| 109 | 'searchtip' : 'Enter a package group name to find it', |
| 110 | 'columns' : [{ |
| 111 | 'col_name' : 'Package group name', |
| 112 | 'col_id' : RecipeListModel.COL_NAME, |
| 113 | 'col_style': 'text', |
| 114 | 'col_min' : 100, |
| 115 | 'col_max' : 400, |
| 116 | 'expand' : 'True' |
| 117 | }, { |
| 118 | 'col_name' : 'Included', |
| 119 | 'col_id' : RecipeListModel.COL_INC, |
| 120 | 'col_style': 'check toggle', |
| 121 | 'col_min' : 100, |
| 122 | 'col_max' : 100 |
| 123 | }] |
| 124 | } |
| 125 | ] |
| 126 | |
| 127 | (INCLUDED, |
| 128 | ALL, |
| 129 | TASKS) = range(3) |
| 130 | |
| 131 | def __init__(self, builder = None): |
| 132 | super(RecipeSelectionPage, self).__init__(builder, "Step 1 of 2: Edit recipes") |
| 133 | |
| 134 | # set invisible members |
| 135 | self.recipe_model = self.builder.recipe_model |
| 136 | |
| 137 | # create visual elements |
| 138 | self.create_visual_elements() |
| 139 | |
| 140 | def included_clicked_cb(self, button): |
| 141 | self.ins.set_current_page(self.INCLUDED) |
| 142 | |
| 143 | def create_visual_elements(self): |
| 144 | self.eventbox = self.add_onto_top_bar(None, 73) |
| 145 | self.pack_start(self.eventbox, expand=False, fill=False) |
| 146 | self.pack_start(self.group_align, expand=True, fill=True) |
| 147 | |
| 148 | # set visible members |
| 149 | self.ins = HobNotebook() |
| 150 | self.tables = [] # we need modify table when the dialog is shown |
| 151 | |
| 152 | search_names = [] |
| 153 | search_tips = [] |
| 154 | # append the tabs in order |
| 155 | for page in self.pages: |
| 156 | columns = page['columns'] |
| 157 | name = page['name'] |
| 158 | tab = HobViewTable(columns, name) |
| 159 | search_names.append(page['search']) |
| 160 | search_tips.append(page['searchtip']) |
| 161 | filter = page['filter'] |
| 162 | sort_model = self.recipe_model.tree_model(filter, initial=True) |
| 163 | tab.set_model(sort_model) |
| 164 | tab.connect("toggled", self.table_toggled_cb, name) |
| 165 | tab.connect("button-release-event", self.button_click_cb) |
| 166 | tab.connect("cell-fadeinout-stopped", self.after_fadeout_checkin_include, filter) |
| 167 | self.ins.append_page(tab, page['name'], page['tooltip']) |
| 168 | self.tables.append(tab) |
| 169 | |
| 170 | self.ins.set_entry(search_names, search_tips) |
| 171 | self.ins.search.connect("changed", self.search_entry_changed) |
| 172 | |
| 173 | # add all into the window |
| 174 | self.box_group_area.pack_start(self.ins, expand=True, fill=True) |
| 175 | |
| 176 | button_box = gtk.HBox(False, 6) |
| 177 | self.box_group_area.pack_end(button_box, expand=False, fill=False) |
| 178 | |
| 179 | self.build_packages_button = HobButton('Build packages') |
| 180 | #self.build_packages_button.set_size_request(205, 49) |
| 181 | self.build_packages_button.set_tooltip_text("Build selected recipes into packages") |
| 182 | self.build_packages_button.set_flags(gtk.CAN_DEFAULT) |
| 183 | self.build_packages_button.grab_default() |
| 184 | self.build_packages_button.connect("clicked", self.build_packages_clicked_cb) |
| 185 | button_box.pack_end(self.build_packages_button, expand=False, fill=False) |
| 186 | |
| 187 | self.back_button = HobAltButton('Cancel') |
| 188 | self.back_button.connect("clicked", self.back_button_clicked_cb) |
| 189 | button_box.pack_end(self.back_button, expand=False, fill=False) |
| 190 | |
| 191 | def search_entry_changed(self, entry): |
| 192 | text = entry.get_text() |
| 193 | if self.ins.search_focus: |
| 194 | self.ins.search_focus = False |
| 195 | elif self.ins.page_changed: |
| 196 | self.ins.page_change = False |
| 197 | self.filter_search(entry) |
| 198 | elif text not in self.ins.search_names: |
| 199 | self.filter_search(entry) |
| 200 | |
| 201 | def filter_search(self, entry): |
| 202 | text = entry.get_text() |
| 203 | current_tab = self.ins.get_current_page() |
| 204 | filter = self.pages[current_tab]['filter'] |
| 205 | filter[RecipeListModel.COL_NAME] = text |
| 206 | self.tables[current_tab].set_model(self.recipe_model.tree_model(filter, search_data=text)) |
| 207 | if self.recipe_model.filtered_nb == 0: |
| 208 | if not self.ins.get_nth_page(current_tab).top_bar: |
| 209 | self.ins.get_nth_page(current_tab).add_no_result_bar(entry) |
| 210 | self.ins.get_nth_page(current_tab).top_bar.set_no_show_all(True) |
| 211 | self.ins.get_nth_page(current_tab).top_bar.show() |
| 212 | self.ins.get_nth_page(current_tab).scroll.hide() |
| 213 | else: |
| 214 | if self.ins.get_nth_page(current_tab).top_bar: |
| 215 | self.ins.get_nth_page(current_tab).top_bar.hide() |
| 216 | self.ins.get_nth_page(current_tab).scroll.show() |
| 217 | if entry.get_text() == '': |
| 218 | entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, False) |
| 219 | else: |
| 220 | entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, True) |
| 221 | |
| 222 | def button_click_cb(self, widget, event): |
| 223 | path, col = widget.table_tree.get_cursor() |
| 224 | tree_model = widget.table_tree.get_model() |
| 225 | if path and col.get_title() != 'Included': # else activation is likely a removal |
| 226 | properties = {'summary': '', 'name': '', 'version': '', 'revision': '', 'binb': '', 'group': '', 'license': '', 'homepage': '', 'bugtracker': '', 'description': ''} |
| 227 | properties['summary'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_SUMMARY) |
| 228 | properties['name'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_NAME) |
| 229 | properties['version'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_VERSION) |
| 230 | properties['revision'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_REVISION) |
| 231 | properties['binb'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_BINB) |
| 232 | properties['group'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_GROUP) |
| 233 | properties['license'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_LIC) |
| 234 | properties['homepage'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_HOMEPAGE) |
| 235 | properties['bugtracker'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_BUGTRACKER) |
| 236 | properties['description'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_DESC) |
| 237 | self.builder.show_recipe_property_dialog(properties) |
| 238 | |
| 239 | def build_packages_clicked_cb(self, button): |
| 240 | self.refresh_tables() |
| 241 | self.builder.build_packages() |
| 242 | |
| 243 | def refresh_tables(self): |
| 244 | self.ins.reset_entry(self.ins.search, 0) |
| 245 | for tab in self.tables: |
| 246 | index = self.tables.index(tab) |
| 247 | filter = self.pages[index]['filter'] |
| 248 | tab.set_model(self.recipe_model.tree_model(filter, search_data="", initial=True)) |
| 249 | |
| 250 | def back_button_clicked_cb(self, button): |
| 251 | self.builder.recipe_model.set_selected_image(self.builder.configuration.initial_selected_image) |
| 252 | self.builder.image_configuration_page.update_image_combo(self.builder.recipe_model, self.builder.configuration.initial_selected_image) |
| 253 | self.builder.image_configuration_page.update_image_desc() |
| 254 | self.builder.show_configuration() |
| 255 | self.refresh_tables() |
| 256 | |
| 257 | def refresh_selection(self): |
| 258 | self.builder.configuration.selected_image = self.recipe_model.get_selected_image() |
| 259 | _, self.builder.configuration.selected_recipes = self.recipe_model.get_selected_recipes() |
| 260 | self.ins.show_indicator_icon("Included recipes", len(self.builder.configuration.selected_recipes)) |
| 261 | |
| 262 | def toggle_item_idle_cb(self, path, view_tree, cell, pagename): |
| 263 | if not self.recipe_model.path_included(path): |
| 264 | self.recipe_model.include_item(item_path=path, binb="User Selected", image_contents=False) |
| 265 | else: |
| 266 | self.pre_fadeout_checkout_include(view_tree, pagename) |
| 267 | self.recipe_model.exclude_item(item_path=path) |
| 268 | self.render_fadeout(view_tree, cell) |
| 269 | |
| 270 | self.refresh_selection() |
| 271 | if not self.builder.customized: |
| 272 | self.builder.customized = True |
| 273 | self.builder.configuration.selected_image = self.recipe_model.__custom_image__ |
| 274 | self.builder.rcppkglist_populated() |
| 275 | |
| 276 | self.builder.window_sensitive(True) |
| 277 | |
| 278 | view_model = view_tree.get_model() |
| 279 | vpath = self.recipe_model.convert_path_to_vpath(view_model, path) |
| 280 | view_tree.set_cursor(vpath) |
| 281 | |
| 282 | def table_toggled_cb(self, table, cell, view_path, toggled_columnid, view_tree, pagename): |
| 283 | # Click to include a recipe |
| 284 | self.builder.window_sensitive(False) |
| 285 | view_model = view_tree.get_model() |
| 286 | path = self.recipe_model.convert_vpath_to_path(view_model, view_path) |
| 287 | glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell, pagename) |
| 288 | |
| 289 | def pre_fadeout_checkout_include(self, tree, pagename): |
| 290 | #after the fadeout the table will be sorted as before |
| 291 | self.sort_column_id = self.recipe_model.sort_column_id |
| 292 | self.sort_order = self.recipe_model.sort_order |
| 293 | |
| 294 | #resync the included items to a backup fade include column |
| 295 | it = self.recipe_model.get_iter_first() |
| 296 | while it: |
| 297 | active = self.recipe_model.get_value(it, self.recipe_model.COL_INC) |
| 298 | self.recipe_model.set(it, self.recipe_model.COL_FADE_INC, active) |
| 299 | it = self.recipe_model.iter_next(it) |
| 300 | # Check out a model which base on the column COL_FADE_INC, |
| 301 | # it's save the prev state of column COL_INC before do exclude_item |
| 302 | filter = { RecipeListModel.COL_FADE_INC:[True] } |
| 303 | if pagename == "Included recipes": |
| 304 | filter[RecipeListModel.COL_TYPE] = ['recipe', 'packagegroup'] |
| 305 | elif pagename == "All recipes": |
| 306 | filter[RecipeListModel.COL_TYPE] = ['recipe'] |
| 307 | else: |
| 308 | filter[RecipeListModel.COL_TYPE] = ['packagegroup'] |
| 309 | |
| 310 | new_model = self.recipe_model.tree_model(filter, excluded_items_ahead=True) |
| 311 | tree.set_model(new_model) |
| 312 | |
| 313 | def render_fadeout(self, tree, cell): |
| 314 | if (not cell) or (not tree): |
| 315 | return |
| 316 | to_render_cells = [] |
| 317 | model = tree.get_model() |
| 318 | it = model.get_iter_first() |
| 319 | while it: |
| 320 | path = model.get_path(it) |
| 321 | prev_cell_is_active = model.get_value(it, RecipeListModel.COL_FADE_INC) |
| 322 | curr_cell_is_active = model.get_value(it, RecipeListModel.COL_INC) |
| 323 | if (prev_cell_is_active == True) and (curr_cell_is_active == False): |
| 324 | to_render_cells.append(path) |
| 325 | it = model.iter_next(it) |
| 326 | |
| 327 | cell.fadeout(tree, 1000, to_render_cells) |
| 328 | |
| 329 | def after_fadeout_checkin_include(self, table, ctrl, cell, tree, filter): |
| 330 | self.recipe_model.sort_column_id = self.sort_column_id |
| 331 | self.recipe_model.sort_order = self.sort_order |
| 332 | tree.set_model(self.recipe_model.tree_model(filter)) |
| 333 | |
| 334 | def set_recipe_curr_tab(self, curr_page): |
| 335 | self.ins.set_current_page(curr_page) |