summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/ui/crumbs/imagedetailspage.py
blob: b7663d8443602a7ac745c1e66ca40aaebf364d81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/usr/bin/env python
#
# BitBake Graphical GTK User Interface
#
# Copyright (C) 2012        Intel Corporation
#
# Authored by Dongxiao Xu <dongxiao.xu@intel.com>
# Authored by Shane Wang <shane.wang@intel.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import gobject
import gtk
from bb.ui.crumbs.hobcolor import HobColors
from bb.ui.crumbs.hobwidget import hic, HobViewTable
from bb.ui.crumbs.hobpages import HobPage

#
# ImageDetailsPage
#
class ImageDetailsPage (HobPage):

    __columns__ = [{
            'col_name' : 'Image name',
            'col_id'   : 0,
            'col_style': 'text',
            'col_min'  : 500,
            'col_max'  : 500
        }, {
            'col_name' : 'Image size',
            'col_id'   : 1,
            'col_style': 'text',
            'col_min'  : 100,
            'col_max'  : 100
        }, {
            'col_name' : 'Select',
            'col_id'   : 2,
            'col_style': 'radio toggle',
            'col_min'  : 100,
            'col_max'  : 100
    }]

    class DetailBox (gtk.EventBox):
        def __init__(self, widget = None, varlist = None, vallist = None, icon = None, button = None, color = HobColors.LIGHT_GRAY):
            gtk.EventBox.__init__(self)

            # set color
            style = self.get_style().copy()
            style.bg[gtk.STATE_NORMAL] = self.get_colormap().alloc_color(color, False, False)
            self.set_style(style)

            self.hbox = gtk.HBox()
            self.hbox.set_border_width(15)
            self.add(self.hbox)

            if widget:
                row = 1
            elif varlist and vallist:
                # pack the icon and the text on the left
                row = len(varlist)
            self.table = gtk.Table(row, 20, True)
            self.table.set_size_request(100, -1)
            self.hbox.pack_start(self.table, expand=True, fill=True, padding=15)

            colid = 0
            self.line_widgets = {}
            if icon:
                self.table.attach(icon, colid, colid + 2, 0, 1)
                colid = colid + 2
            if widget:
                self.table.attach(widget, colid, 20, 0, 1)
            elif varlist and vallist:
                for line in range(0, row):
                    self.line_widgets[varlist[line]] = self.text2label(varlist[line], vallist[line])
                    self.table.attach(self.line_widgets[varlist[line]], colid, 20, line, line + 1)

            # pack the button on the right
            if button:
                self.hbox.pack_end(button, expand=False, fill=False)

        def update_line_widgets(self, variable, value):
            if len(self.line_widgets) == 0:
                return
            if not isinstance(self.line_widgets[variable], gtk.Label):
                return
            self.line_widgets[variable].set_markup(self.format_line(variable, value))

        def format_line(self, variable, value):
            markup = "<span weight=\'bold\'>%s</span>" % variable
            markup += "<span weight=\'normal\' foreground=\'#1c1c1c\' font_desc=\'14px\'>%s</span>" % value
            return markup

        def text2label(self, variable, value):
            # append the name:value to the left box
            # such as "Name: hob-core-minimal-variant-2011-12-15-beagleboard"
            label = gtk.Label()
            label.set_alignment(0.0, 0.5)
            label.set_markup(self.format_line(variable, value))
            return label

    def __init__(self, builder):
        super(ImageDetailsPage, self).__init__(builder, "Image details")

        self.image_store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_BOOLEAN)
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        # create the toolbar
        self.toolbar = gtk.Toolbar()
        self.toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL)
        self.toolbar.set_style(gtk.TOOLBAR_BOTH)

        my_images_button = self.append_toolbar_button(self.toolbar,
            "My images",
            hic.ICON_IMAGES_DISPLAY_FILE,
            hic.ICON_IMAGES_HOVER_FILE,
            "Open images built out previously for running or deployment",
            self.my_images_button_clicked_cb)

        self.details_top_buttons = self.add_onto_top_bar(self.toolbar)

    def _remove_all_widget(self):
        children = self.get_children() or []
        for child in children:
            self.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)

    def _size_to_string(self, size):
        if len(str(int(size))) > 6:
            size_str = '%.1f' % (size*1.0/(1024*1024)) + ' MB'
        elif len(str(int(size))) > 3:
            size_str = '%.1f' % (size*1.0/1024) + ' KB'
        else:
            size_str = str(size) + ' B'
        return size_str

    def show_page(self, step):
        build_succeeded = (step == self.builder.IMAGE_GENERATED)
        image_addr = self.builder.parameters.image_addr
        image_names = self.builder.parameters.image_names
        if build_succeeded:
            machine = self.builder.configuration.curr_mach
            base_image = self.builder.recipe_model.get_selected_image()
            layers = self.builder.configuration.layers
            pkg_num = "%s" % len(self.builder.package_model.get_selected_packages())
        else:
            pkg_num = "N/A"

        self._remove_all_widget()
        self.pack_start(self.details_top_buttons, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        if build_succeeded:
            # building is the previous step
            icon = gtk.Image()
            pixmap_path = hic.ICON_INDI_CONFIRM_FILE
            color = HobColors.RUNNING
            pix_buffer = gtk.gdk.pixbuf_new_from_file(pixmap_path)
            icon.set_from_pixbuf(pix_buffer)
            varlist = [""]
            vallist = ["Your image is ready"]
            build_result = self.DetailBox(varlist=varlist, vallist=vallist, icon=icon, color=color)
            self.box_group_area.pack_start(build_result, expand=False, fill=False)

        # Name
        self.image_store.clear()
        for image_name in image_names:
            image_size = self._size_to_string(os.stat(os.path.join(image_addr, image_name)).st_size)
            self.image_store.set(self.image_store.append(), 0, image_name, 1, image_size, 2, False)
        image_table = HobViewTable(self.__columns__)
        image_table.set_model(self.image_store)
        image_table.toggle_default()
        image_size = self._size_to_string(os.stat(os.path.join(image_addr, image_names[0])).st_size)
        image_table.connect("toggled", self.toggled_cb)
        view_files_button = gtk.LinkButton("file://%s" % image_addr, "View files")
        self.box_group_area.pack_start(self.DetailBox(widget=image_table, button=view_files_button), expand=True, fill=True)

        # Machine, Base image and Layers
        layer_num_limit = 15
        varlist = ["Machine: ", "Base image: ", "Layers: "]
        vallist = []
        if build_succeeded:
            vallist.append(machine)
            vallist.append(base_image)
            i = 0
            for layer in layers:
                varlist.append(" - ")
                if i > layer_num_limit:
                    break
                i += 1
            vallist.append("")
            i = 0
            for layer in layers:
                if i > layer_num_limit:
                    break
                elif i == layer_num_limit:
                    vallist.append("and more...")
                else:
                    vallist.append(layer)
                i += 1

            edit_config_button = gtk.LinkButton("Changes settings for build", "Edit configuration")
            edit_config_button.connect("clicked", self.edit_config_button_clicked_cb)
            setting_detail = self.DetailBox(varlist=varlist, vallist=vallist, button=edit_config_button)
            self.box_group_area.pack_start(setting_detail, expand=False, fill=False)

        # Packages included, and Total image size
        varlist = ["Packages included: ", "Total image size: "]
        vallist = []
        vallist.append(pkg_num)
        vallist.append(image_size)
        if build_succeeded:
            edit_packages_button = gtk.LinkButton("Change package selection for customization", "Edit packages")
            edit_packages_button.connect("clicked", self.edit_packages_button_clicked_cb)
        else: # get to this page from "My images"
            edit_packages_button = None
        self.package_detail = self.DetailBox(varlist=varlist, vallist=vallist, button=edit_packages_button)
        self.box_group_area.pack_start(self.package_detail, expand=False, fill=False)

        if build_succeeded:
            buttonlist = ["Build new image", "Save as template", "Run image", "Deploy image"]
        else: # get to this page from "My images"
            buttonlist = ["Build new image", "Run image", "Deploy image"]
        details_bottom_buttons = self.create_bottom_buttons(buttonlist)
        self.box_group_area.pack_end(details_bottom_buttons, expand=False, fill=False)

        self.show_all()

    def refresh_package_detail_box(self, image_size):
        self.package_detail.update_line_widgets("Total image size: ", image_size)

    def toggled_cb(self, table, cell, path, columnid, tree):
        model = tree.get_model()
        if not model:
            return
        iter = model.get_iter_first()
        while iter:
            rowpath = model.get_path(iter)
            model[rowpath][columnid] = False
            iter = model.iter_next(iter)

        model[path][columnid] = True
        self.refresh_package_detail_box(model[path][1])

    def create_bottom_buttons(self, buttonlist):
        # Create the buttons at the bottom
        bottom_buttons = gtk.HBox(False, 6)
        created = False

        # create button "Deploy image"
        name = "Deploy image"
        if name in buttonlist:
            deploy_button = gtk.Button()
            label = gtk.Label()
            mark = "<span %s>Deploy image</span>" % self.span_tag('24px', 'bold')
            label.set_markup(mark)
            deploy_button.set_image(label)
            deploy_button.set_size_request(205, 49)
            deploy_button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(HobColors.ORANGE))
            deploy_button.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(HobColors.ORANGE))
            deploy_button.modify_bg(gtk.STATE_SELECTED, gtk.gdk.Color(HobColors.ORANGE))
            deploy_button.set_tooltip_text("Deploy image to get your target board")
            deploy_button.set_flags(gtk.CAN_DEFAULT)
            deploy_button.grab_default()
            deploy_button.connect("clicked", self.deploy_button_clicked_cb)
            bottom_buttons.pack_end(deploy_button, expand=False, fill=False)
            created = True

        name = "Run image"
        if name in buttonlist:
            if created == True:
                # separator
                label = gtk.Label(" or ")
                bottom_buttons.pack_end(label, expand=False, fill=False)

            # create button "Run image"
            run_button = gtk.LinkButton("Launch and boot the image in the QEMU emulator", "Run image")
            run_button.connect("clicked", self.run_button_clicked_cb)
            bottom_buttons.pack_end(run_button, expand=False, fill=False)
            created = True

        name = "Save as template"
        if name in buttonlist:
            if created == True:
                # separator
                label = gtk.Label(" or ")
                bottom_buttons.pack_end(label, expand=False, fill=False)

            # create button "Save as template"
            save_button = gtk.LinkButton("Save the hob build template for future use", "Save as template")
            save_button.connect("clicked", self.save_button_clicked_cb)
            bottom_buttons.pack_end(save_button, expand=False, fill=False)
            create = True

        name = "Build new image"
        if name in buttonlist:
            # create button "Build new image"
            build_new_button = gtk.LinkButton("Initiate another new build from the beginning", "Build new image")
            build_new_button.connect("clicked", self.build_new_button_clicked_cb)
            bottom_buttons.pack_start(build_new_button, expand=False, fill=False)

        return bottom_buttons

    def _get_selected_image(self):
        image_name = ""
        iter = self.image_store.get_iter_first()
        while iter:
            path = self.image_store.get_path(iter)
            if self.image_store[path][2]:
                image_name = self.image_store[path][0]
                break
            iter = self.image_store.iter_next(iter)

        return image_name

    def save_button_clicked_cb(self, button):
        self.builder.show_save_template_dialog()

    def deploy_button_clicked_cb(self, button):
        image_name = self._get_selected_image()
        self.builder.deploy_image(image_name)

    def run_button_clicked_cb(self, button):
        image_name = self._get_selected_image()
        self.builder.runqemu_image(image_name)

    def build_new_button_clicked_cb(self, button):
        self.builder.initiate_new_build()

    def edit_config_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def edit_packages_button_clicked_cb(self, button):
        self.builder.show_packages(ask=False)

    def my_images_button_clicked_cb(self, button):
        self.builder.show_load_my_images_dialog()