Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # BitBake Graphical GTK User Interface |
| 3 | # |
| 4 | # Copyright (C) 2011-2013 Intel Corporation |
| 5 | # |
| 6 | # Authored by Andrei Dinu <andrei.adrianx.dinu@intel.com> |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License version 2 as |
| 10 | # published by the Free Software Foundation. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License along |
| 18 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | |
| 21 | import string |
| 22 | import gtk |
| 23 | import gobject |
| 24 | import os |
| 25 | import tempfile |
| 26 | import glib |
| 27 | from bb.ui.crumbs.hig.crumbsdialog import CrumbsDialog |
| 28 | from bb.ui.crumbs.hig.settingsuihelper import SettingsUIHelper |
| 29 | from bb.ui.crumbs.hig.crumbsmessagedialog import CrumbsMessageDialog |
| 30 | from bb.ui.crumbs.hig.layerselectiondialog import LayerSelectionDialog |
| 31 | |
| 32 | """ |
| 33 | The following are convenience classes for implementing GNOME HIG compliant |
| 34 | BitBake GUI's |
| 35 | In summary: spacing = 12px, border-width = 6px |
| 36 | """ |
| 37 | |
| 38 | class PropertyDialog(CrumbsDialog): |
| 39 | |
| 40 | def __init__(self, title, parent, information, flags, buttons=None): |
| 41 | |
| 42 | super(PropertyDialog, self).__init__(title, parent, flags, buttons) |
| 43 | |
| 44 | self.properties = information |
| 45 | |
| 46 | if len(self.properties) == 10: |
| 47 | self.create_recipe_visual_elements() |
| 48 | elif len(self.properties) == 5: |
| 49 | self.create_package_visual_elements() |
| 50 | else: |
| 51 | self.create_information_visual_elements() |
| 52 | |
| 53 | |
| 54 | def create_information_visual_elements(self): |
| 55 | |
| 56 | HOB_ICON_BASE_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), ("icons/")) |
| 57 | ICON_PACKAGES_DISPLAY_FILE = os.path.join(HOB_ICON_BASE_DIR, ('info/info_display.png')) |
| 58 | |
| 59 | self.set_resizable(False) |
| 60 | |
| 61 | self.table = gtk.Table(1,1,False) |
| 62 | self.table.set_row_spacings(0) |
| 63 | self.table.set_col_spacings(0) |
| 64 | |
| 65 | self.image = gtk.Image() |
| 66 | self.image.set_from_file(ICON_PACKAGES_DISPLAY_FILE) |
| 67 | self.image.set_property("xalign",0) |
| 68 | #self.vbox.add(self.image) |
| 69 | |
| 70 | image_info = self.properties.split("*")[0] |
| 71 | info = self.properties.split("*")[1] |
| 72 | |
| 73 | vbox = gtk.VBox(True, spacing=30) |
| 74 | |
| 75 | self.label_short = gtk.Label() |
| 76 | self.label_short.set_line_wrap(False) |
| 77 | self.label_short.set_markup(image_info) |
| 78 | self.label_short.set_property("xalign", 0) |
| 79 | |
| 80 | self.info_label = gtk.Label() |
| 81 | self.info_label.set_line_wrap(True) |
| 82 | self.info_label.set_markup(info) |
| 83 | self.info_label.set_property("yalign", 0.5) |
| 84 | |
| 85 | self.table.attach(self.image, 0,1,0,1, xoptions=gtk.FILL|gtk.EXPAND, yoptions=gtk.FILL,xpadding=5,ypadding=5) |
| 86 | self.table.attach(self.label_short, 0,1,0,1, xoptions=gtk.FILL|gtk.EXPAND, yoptions=gtk.FILL,xpadding=40,ypadding=5) |
| 87 | self.table.attach(self.info_label, 0,1,1,2, xoptions=gtk.FILL|gtk.EXPAND, yoptions=gtk.FILL,xpadding=40,ypadding=10) |
| 88 | |
| 89 | self.vbox.add(self.table) |
| 90 | self.connect('delete-event', lambda w, e: self.destroy() or True) |
| 91 | |
| 92 | def treeViewTooltip( self, widget, e, tooltips, cell, emptyText="" ): |
| 93 | try: |
| 94 | (path,col,x,y) = widget.get_path_at_pos( int(e.x), int(e.y) ) |
| 95 | it = widget.get_model().get_iter(path) |
| 96 | value = widget.get_model().get_value(it,cell) |
| 97 | if value in self.tooltip_items: |
| 98 | tooltips.set_tip(widget, self.tooltip_items[value]) |
| 99 | tooltips.enable() |
| 100 | else: |
| 101 | tooltips.set_tip(widget, emptyText) |
| 102 | except: |
| 103 | tooltips.set_tip(widget, emptyText) |
| 104 | |
| 105 | |
| 106 | def create_package_visual_elements(self): |
| 107 | |
| 108 | import json |
| 109 | |
| 110 | name = self.properties['name'] |
| 111 | binb = self.properties['binb'] |
| 112 | size = self.properties['size'] |
| 113 | recipe = self.properties['recipe'] |
| 114 | file_list = json.loads(self.properties['files_list']) |
| 115 | |
| 116 | files_temp = '' |
| 117 | paths_temp = '' |
| 118 | files_binb = [] |
| 119 | paths_binb = [] |
| 120 | |
| 121 | self.tooltip_items = {} |
| 122 | |
| 123 | self.set_resizable(False) |
| 124 | |
| 125 | #cleaning out the recipe variable |
| 126 | recipe = recipe.split("+")[0] |
| 127 | |
| 128 | vbox = gtk.VBox(True,spacing = 0) |
| 129 | |
| 130 | ###################################### NAME ROW + COL ################################# |
| 131 | |
| 132 | self.label_short = gtk.Label() |
| 133 | self.label_short.set_size_request(300,-1) |
| 134 | self.label_short.set_selectable(True) |
| 135 | self.label_short.set_line_wrap(True) |
| 136 | self.label_short.set_markup("<span weight=\"bold\">Name: </span>" + name) |
| 137 | self.label_short.set_property("xalign", 0) |
| 138 | |
| 139 | self.vbox.add(self.label_short) |
| 140 | |
| 141 | ###################################### SIZE ROW + COL ###################################### |
| 142 | |
| 143 | self.label_short = gtk.Label() |
| 144 | self.label_short.set_size_request(300,-1) |
| 145 | self.label_short.set_selectable(True) |
| 146 | self.label_short.set_line_wrap(True) |
| 147 | self.label_short.set_markup("<span weight=\"bold\">Size: </span>" + size) |
| 148 | self.label_short.set_property("xalign", 0) |
| 149 | |
| 150 | self.vbox.add(self.label_short) |
| 151 | |
| 152 | ##################################### RECIPE ROW + COL ######################################### |
| 153 | |
| 154 | self.label_short = gtk.Label() |
| 155 | self.label_short.set_size_request(300,-1) |
| 156 | self.label_short.set_selectable(True) |
| 157 | self.label_short.set_line_wrap(True) |
| 158 | self.label_short.set_markup("<span weight=\"bold\">Recipe: </span>" + recipe) |
| 159 | self.label_short.set_property("xalign", 0) |
| 160 | |
| 161 | self.vbox.add(self.label_short) |
| 162 | |
| 163 | ##################################### BINB ROW + COL ####################################### |
| 164 | |
| 165 | if binb != '': |
| 166 | self.label_short = gtk.Label() |
| 167 | self.label_short.set_selectable(True) |
| 168 | self.label_short.set_line_wrap(True) |
| 169 | self.label_short.set_markup("<span weight=\"bold\">Brought in by: </span>") |
| 170 | self.label_short.set_property("xalign", 0) |
| 171 | |
| 172 | self.label_info = gtk.Label() |
| 173 | self.label_info.set_size_request(300,-1) |
| 174 | self.label_info.set_selectable(True) |
| 175 | self.label_info.set_line_wrap(True) |
| 176 | self.label_info.set_markup(binb) |
| 177 | self.label_info.set_property("xalign", 0) |
| 178 | |
| 179 | self.vbox.add(self.label_short) |
| 180 | self.vbox.add(self.label_info) |
| 181 | |
| 182 | #################################### FILES BROUGHT BY PACKAGES ################################### |
| 183 | |
| 184 | if file_list: |
| 185 | |
| 186 | self.textWindow = gtk.ScrolledWindow() |
| 187 | self.textWindow.set_shadow_type(gtk.SHADOW_IN) |
| 188 | self.textWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
| 189 | self.textWindow.set_size_request(100, 170) |
| 190 | |
| 191 | packagefiles_store = gtk.ListStore(str) |
| 192 | |
| 193 | self.packagefiles_tv = gtk.TreeView() |
| 194 | self.packagefiles_tv.set_rules_hint(True) |
| 195 | self.packagefiles_tv.set_headers_visible(True) |
| 196 | self.textWindow.add(self.packagefiles_tv) |
| 197 | |
| 198 | self.cell1 = gtk.CellRendererText() |
| 199 | col1 = gtk.TreeViewColumn('Package files', self.cell1) |
| 200 | col1.set_cell_data_func(self.cell1, self.regex_field) |
| 201 | self.packagefiles_tv.append_column(col1) |
| 202 | |
| 203 | items = file_list.keys() |
| 204 | items.sort() |
| 205 | for item in items: |
| 206 | fullpath = item |
| 207 | while len(item) > 35: |
| 208 | item = item[:len(item)/2] + "" + item[len(item)/2+1:] |
| 209 | if len(item) == 35: |
| 210 | item = item[:len(item)/2] + "..." + item[len(item)/2+3:] |
| 211 | self.tooltip_items[item] = fullpath |
| 212 | |
| 213 | packagefiles_store.append([str(item)]) |
| 214 | |
| 215 | self.packagefiles_tv.set_model(packagefiles_store) |
| 216 | |
| 217 | tips = gtk.Tooltips() |
| 218 | tips.set_tip(self.packagefiles_tv, "") |
| 219 | self.packagefiles_tv.connect("motion-notify-event", self.treeViewTooltip, tips, 0) |
| 220 | self.packagefiles_tv.set_events(gtk.gdk.POINTER_MOTION_MASK) |
| 221 | |
| 222 | self.vbox.add(self.textWindow) |
| 223 | |
| 224 | self.vbox.show_all() |
| 225 | |
| 226 | |
| 227 | def regex_field(self, column, cell, model, iter): |
| 228 | cell.set_property('text', model.get_value(iter, 0)) |
| 229 | return |
| 230 | |
| 231 | |
| 232 | def create_recipe_visual_elements(self): |
| 233 | |
| 234 | summary = self.properties['summary'] |
| 235 | name = self.properties['name'] |
| 236 | version = self.properties['version'] |
| 237 | revision = self.properties['revision'] |
| 238 | binb = self.properties['binb'] |
| 239 | group = self.properties['group'] |
| 240 | license = self.properties['license'] |
| 241 | homepage = self.properties['homepage'] |
| 242 | bugtracker = self.properties['bugtracker'] |
| 243 | description = self.properties['description'] |
| 244 | |
| 245 | self.set_resizable(False) |
| 246 | |
| 247 | #cleaning out the version variable and also the summary |
| 248 | version = version.split(":")[1] |
| 249 | if len(version) > 30: |
| 250 | version = version.split("+")[0] |
| 251 | else: |
| 252 | version = version.split("-")[0] |
| 253 | license = license.replace("&" , "and") |
| 254 | if (homepage == ''): |
| 255 | homepage = 'unknown' |
| 256 | if (bugtracker == ''): |
| 257 | bugtracker = 'unknown' |
| 258 | summary = summary.split("+")[0] |
| 259 | |
| 260 | #calculating the rows needed for the table |
| 261 | binb_items_count = len(binb.split(',')) |
| 262 | binb_items = binb.split(',') |
| 263 | |
| 264 | vbox = gtk.VBox(False,spacing = 0) |
| 265 | |
| 266 | ######################################## SUMMARY LABEL ######################################### |
| 267 | |
| 268 | if summary != '': |
| 269 | self.label_short = gtk.Label() |
| 270 | self.label_short.set_width_chars(37) |
| 271 | self.label_short.set_selectable(True) |
| 272 | self.label_short.set_line_wrap(True) |
| 273 | self.label_short.set_markup("<b>" + summary + "</b>") |
| 274 | self.label_short.set_property("xalign", 0) |
| 275 | |
| 276 | self.vbox.add(self.label_short) |
| 277 | |
| 278 | ########################################## NAME ROW + COL ####################################### |
| 279 | |
| 280 | self.label_short = gtk.Label() |
| 281 | self.label_short.set_selectable(True) |
| 282 | self.label_short.set_line_wrap(True) |
| 283 | self.label_short.set_markup("<span weight=\"bold\">Name: </span>" + name) |
| 284 | self.label_short.set_property("xalign", 0) |
| 285 | |
| 286 | self.vbox.add(self.label_short) |
| 287 | |
| 288 | ####################################### VERSION ROW + COL #################################### |
| 289 | |
| 290 | self.label_short = gtk.Label() |
| 291 | self.label_short.set_selectable(True) |
| 292 | self.label_short.set_line_wrap(True) |
| 293 | self.label_short.set_markup("<span weight=\"bold\">Version: </span>" + version) |
| 294 | self.label_short.set_property("xalign", 0) |
| 295 | |
| 296 | self.vbox.add(self.label_short) |
| 297 | |
| 298 | ##################################### REVISION ROW + COL ##################################### |
| 299 | |
| 300 | self.label_short = gtk.Label() |
| 301 | self.label_short.set_line_wrap(True) |
| 302 | self.label_short.set_selectable(True) |
| 303 | self.label_short.set_markup("<span weight=\"bold\">Revision: </span>" + revision) |
| 304 | self.label_short.set_property("xalign", 0) |
| 305 | |
| 306 | self.vbox.add(self.label_short) |
| 307 | |
| 308 | ################################## GROUP ROW + COL ############################################ |
| 309 | |
| 310 | self.label_short = gtk.Label() |
| 311 | self.label_short.set_selectable(True) |
| 312 | self.label_short.set_line_wrap(True) |
| 313 | self.label_short.set_markup("<span weight=\"bold\">Group: </span>" + group) |
| 314 | self.label_short.set_property("xalign", 0) |
| 315 | |
| 316 | self.vbox.add(self.label_short) |
| 317 | |
| 318 | ################################# HOMEPAGE ROW + COL ############################################ |
| 319 | |
| 320 | if homepage != 'unknown': |
| 321 | self.label_info = gtk.Label() |
| 322 | self.label_info.set_selectable(True) |
| 323 | self.label_info.set_line_wrap(True) |
| 324 | if len(homepage) > 35: |
| 325 | self.label_info.set_markup("<a href=\"" + homepage + "\">" + homepage[0:35] + "..." + "</a>") |
| 326 | else: |
| 327 | self.label_info.set_markup("<a href=\"" + homepage + "\">" + homepage[0:60] + "</a>") |
| 328 | |
| 329 | self.label_info.set_property("xalign", 0) |
| 330 | |
| 331 | self.label_short = gtk.Label() |
| 332 | self.label_short.set_selectable(True) |
| 333 | self.label_short.set_line_wrap(True) |
| 334 | self.label_short.set_markup("<b>Homepage: </b>") |
| 335 | self.label_short.set_property("xalign", 0) |
| 336 | |
| 337 | self.vbox.add(self.label_short) |
| 338 | self.vbox.add(self.label_info) |
| 339 | |
| 340 | ################################# BUGTRACKER ROW + COL ########################################### |
| 341 | |
| 342 | if bugtracker != 'unknown': |
| 343 | self.label_info = gtk.Label() |
| 344 | self.label_info.set_selectable(True) |
| 345 | self.label_info.set_line_wrap(True) |
| 346 | if len(bugtracker) > 35: |
| 347 | self.label_info.set_markup("<a href=\"" + bugtracker + "\">" + bugtracker[0:35] + "..." + "</a>") |
| 348 | else: |
| 349 | self.label_info.set_markup("<a href=\"" + bugtracker + "\">" + bugtracker[0:60] + "</a>") |
| 350 | self.label_info.set_property("xalign", 0) |
| 351 | |
| 352 | self.label_short = gtk.Label() |
| 353 | self.label_short.set_selectable(True) |
| 354 | self.label_short.set_line_wrap(True) |
| 355 | self.label_short.set_markup("<b>Bugtracker: </b>") |
| 356 | self.label_short.set_property("xalign", 0) |
| 357 | |
| 358 | self.vbox.add(self.label_short) |
| 359 | self.vbox.add(self.label_info) |
| 360 | |
| 361 | ################################# LICENSE ROW + COL ############################################ |
| 362 | |
| 363 | self.label_info = gtk.Label() |
| 364 | self.label_info.set_selectable(True) |
| 365 | self.label_info.set_line_wrap(True) |
| 366 | self.label_info.set_markup(license) |
| 367 | self.label_info.set_property("xalign", 0) |
| 368 | |
| 369 | self.label_short = gtk.Label() |
| 370 | self.label_short.set_selectable(True) |
| 371 | self.label_short.set_line_wrap(True) |
| 372 | self.label_short.set_markup("<span weight=\"bold\">License: </span>") |
| 373 | self.label_short.set_property("xalign", 0) |
| 374 | |
| 375 | self.vbox.add(self.label_short) |
| 376 | self.vbox.add(self.label_info) |
| 377 | |
| 378 | ################################### BINB ROW+COL ############################################# |
| 379 | |
| 380 | if binb != '': |
| 381 | self.label_short = gtk.Label() |
| 382 | self.label_short.set_selectable(True) |
| 383 | self.label_short.set_line_wrap(True) |
| 384 | self.label_short.set_markup("<span weight=\"bold\">Brought in by: </span>") |
| 385 | self.label_short.set_property("xalign", 0) |
| 386 | self.vbox.add(self.label_short) |
| 387 | self.label_info = gtk.Label() |
| 388 | self.label_info.set_selectable(True) |
| 389 | self.label_info.set_width_chars(36) |
| 390 | if len(binb) > 200: |
| 391 | scrolled_window = gtk.ScrolledWindow() |
| 392 | scrolled_window.set_policy(gtk.POLICY_NEVER,gtk.POLICY_ALWAYS) |
| 393 | scrolled_window.set_size_request(100,100) |
| 394 | self.label_info.set_markup(binb) |
| 395 | self.label_info.set_padding(6,6) |
| 396 | self.label_info.set_alignment(0,0) |
| 397 | self.label_info.set_line_wrap(True) |
| 398 | scrolled_window.add_with_viewport(self.label_info) |
| 399 | self.vbox.add(scrolled_window) |
| 400 | else: |
| 401 | self.label_info.set_markup(binb) |
| 402 | self.label_info.set_property("xalign", 0) |
| 403 | self.label_info.set_line_wrap(True) |
| 404 | self.vbox.add(self.label_info) |
| 405 | |
| 406 | ################################ DESCRIPTION TAG ROW ################################################# |
| 407 | |
| 408 | self.label_short = gtk.Label() |
| 409 | self.label_short.set_line_wrap(True) |
| 410 | self.label_short.set_markup("<span weight=\"bold\">Description </span>") |
| 411 | self.label_short.set_property("xalign", 0) |
| 412 | self.vbox.add(self.label_short) |
| 413 | |
| 414 | ################################ DESCRIPTION INFORMATION ROW ########################################## |
| 415 | |
| 416 | hbox = gtk.HBox(True,spacing = 0) |
| 417 | |
| 418 | self.label_short = gtk.Label() |
| 419 | self.label_short.set_selectable(True) |
| 420 | self.label_short.set_width_chars(36) |
| 421 | if len(description) > 200: |
| 422 | scrolled_window = gtk.ScrolledWindow() |
| 423 | scrolled_window.set_policy(gtk.POLICY_NEVER,gtk.POLICY_ALWAYS) |
| 424 | scrolled_window.set_size_request(100,100) |
| 425 | self.label_short.set_markup(description) |
| 426 | self.label_short.set_padding(6,6) |
| 427 | self.label_short.set_alignment(0,0) |
| 428 | self.label_short.set_line_wrap(True) |
| 429 | scrolled_window.add_with_viewport(self.label_short) |
| 430 | self.vbox.add(scrolled_window) |
| 431 | else: |
| 432 | self.label_short.set_markup(description) |
| 433 | self.label_short.set_property("xalign", 0) |
| 434 | self.label_short.set_line_wrap(True) |
| 435 | self.vbox.add(self.label_short) |
| 436 | |
| 437 | self.vbox.show_all() |