diff options
| author | Cristiana Voicu <cristiana.voicu@intel.com> | 2013-07-25 07:25:38 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-08-06 13:02:23 +0100 |
| commit | ee4fe5a229125d01cf8b697c759d0852f9a715a8 (patch) | |
| tree | 0c00f7f0fcf78db9e3ccb0b44a8cd51ce5685011 /bitbake/lib/bb/ui/crumbs/hig | |
| parent | 843ef1083243e1569d6cc429ae26e22dda699149 (diff) | |
| download | poky-ee4fe5a229125d01cf8b697c759d0852f9a715a8.tar.gz | |
bitbake: hob: create save image dialog used to save a template
Implemented a new dialog used by Hob. This dialog was desinged
in order to permit to save only in a particular directory.
Also, it has a field where the user can type a description
for the image.
Implemented in the handler a method to retrieve the topdir variable,
because the changes will be saved in {topdir}/recipes/images directory.
[YOCTO #4193]
(Bitbake rev: 117d4809a62e28ffe7e9dcda5433993d76f7d934)
Signed-off-by: Cristiana Voicu <cristiana.voicu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/ui/crumbs/hig')
| -rw-r--r-- | bitbake/lib/bb/ui/crumbs/hig/saveimagedialog.py | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/bitbake/lib/bb/ui/crumbs/hig/saveimagedialog.py b/bitbake/lib/bb/ui/crumbs/hig/saveimagedialog.py new file mode 100644 index 0000000000..3fc389aaa1 --- /dev/null +++ b/bitbake/lib/bb/ui/crumbs/hig/saveimagedialog.py | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | # | ||
| 2 | # BitBake Graphical GTK User Interface | ||
| 3 | # | ||
| 4 | # Copyright (C) 2013 Intel Corporation | ||
| 5 | # | ||
| 6 | # Authored by Cristiana Voicu <cristiana.voicu@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 gtk | ||
| 22 | import glib | ||
| 23 | from bb.ui.crumbs.hig.crumbsdialog import CrumbsDialog | ||
| 24 | from bb.ui.crumbs.hig.crumbsmessagedialog import CrumbsMessageDialog | ||
| 25 | from bb.ui.crumbs.hobwidget import HobButton | ||
| 26 | |||
| 27 | class SaveImageDialog (CrumbsDialog): | ||
| 28 | """ | ||
| 29 | This class is used to create a dialog that permits to save | ||
| 30 | a custom image in a predefined directory. | ||
| 31 | """ | ||
| 32 | def __init__(self, directory, title, parent, flags, buttons=None): | ||
| 33 | super(SaveImageDialog, self).__init__(title, parent, flags, buttons) | ||
| 34 | self.directory = directory | ||
| 35 | self.builder = parent | ||
| 36 | |||
| 37 | # create visual elements on the dialog | ||
| 38 | self.create_visual_elements() | ||
| 39 | |||
| 40 | def create_visual_elements(self): | ||
| 41 | self.set_default_response(gtk.RESPONSE_OK) | ||
| 42 | self.vbox.set_border_width(6) | ||
| 43 | |||
| 44 | sub_vbox = gtk.VBox(False, 12) | ||
| 45 | self.vbox.pack_start(sub_vbox, expand=False, fill=False) | ||
| 46 | label = gtk.Label() | ||
| 47 | label.set_alignment(0, 0) | ||
| 48 | label.set_markup("<b>Name</b>") | ||
| 49 | sub_label = gtk.Label() | ||
| 50 | sub_label.set_alignment(0, 0) | ||
| 51 | content = "Image recipe names should be all lowercase and include only alphanumeric\n" | ||
| 52 | content += "characters. The only special character you can use is the ASCII hyphen (-)." | ||
| 53 | sub_label.set_markup(content) | ||
| 54 | self.name_entry = gtk.Entry() | ||
| 55 | self.name_entry.set_size_request(350,30) | ||
| 56 | self.name_entry.connect("changed", self.name_entry_changed) | ||
| 57 | sub_vbox.pack_start(label, expand=False, fill=False) | ||
| 58 | sub_vbox.pack_start(sub_label, expand=False, fill=False) | ||
| 59 | sub_vbox.pack_start(self.name_entry, expand=False, fill=False) | ||
| 60 | |||
| 61 | sub_vbox = gtk.VBox(False, 12) | ||
| 62 | self.vbox.pack_start(sub_vbox, expand=False, fill=False) | ||
| 63 | label = gtk.Label() | ||
| 64 | label.set_alignment(0, 0) | ||
| 65 | label.set_markup("<b>Description</b> (optional)") | ||
| 66 | sub_label = gtk.Label() | ||
| 67 | sub_label.set_alignment(0, 0) | ||
| 68 | sub_label.set_markup("The description should be less than 150 characters long.") | ||
| 69 | self.description_entry = gtk.TextView() | ||
| 70 | self.description_entry.set_wrap_mode(gtk.WRAP_WORD) | ||
| 71 | self.description_entry.set_size_request(350,150) | ||
| 72 | sub_vbox.pack_start(label, expand=False, fill=False) | ||
| 73 | sub_vbox.pack_start(sub_label, expand=False, fill=False) | ||
| 74 | sub_vbox.pack_start(self.description_entry, expand=False, fill=False) | ||
| 75 | |||
| 76 | sub_vbox = gtk.VBox(False, 12) | ||
| 77 | self.vbox.pack_start(sub_vbox, expand=False, fill=False) | ||
| 78 | label = gtk.Label() | ||
| 79 | label.set_alignment(0, 0) | ||
| 80 | label.set_markup("Your image recipe will be saved to:") | ||
| 81 | sub_label = gtk.Label() | ||
| 82 | sub_label.set_alignment(0, 0) | ||
| 83 | sub_label.set_markup(self.directory) | ||
| 84 | sub_vbox.pack_start(label, expand=False, fill=False) | ||
| 85 | sub_vbox.pack_start(sub_label, expand=False, fill=False) | ||
| 86 | |||
| 87 | table = gtk.Table(1, 4, True) | ||
| 88 | |||
| 89 | cancel_button = gtk.Button() | ||
| 90 | cancel_button.set_label("Cancel") | ||
| 91 | cancel_button.connect("clicked", self.cancel_button_cb) | ||
| 92 | cancel_button.set_size_request(110, 30) | ||
| 93 | |||
| 94 | self.save_button = gtk.Button() | ||
| 95 | self.save_button.set_label("Save") | ||
| 96 | self.save_button.connect("clicked", self.save_button_cb) | ||
| 97 | self.save_button.set_size_request(110, 30) | ||
| 98 | self.save_button.set_sensitive(False) | ||
| 99 | |||
| 100 | table.attach(cancel_button, 2, 3, 0, 1) | ||
| 101 | table.attach(self.save_button, 3, 4, 0, 1) | ||
| 102 | self.vbox.pack_end(table, expand=False, fill=False) | ||
| 103 | |||
| 104 | self.show_all() | ||
| 105 | |||
| 106 | def name_entry_changed(self, entry): | ||
| 107 | text = entry.get_text() | ||
| 108 | if text == '': | ||
| 109 | self.save_button.set_sensitive(False) | ||
| 110 | else: | ||
| 111 | self.save_button.set_sensitive(True) | ||
| 112 | |||
| 113 | def cancel_button_cb(self, button): | ||
| 114 | self.destroy() | ||
| 115 | |||
| 116 | def save_button_cb(self, button): | ||
| 117 | text = self.name_entry.get_text() | ||
| 118 | new_text = text.replace("-","") | ||
| 119 | if new_text.islower() and new_text.isalnum(): | ||
| 120 | print(text) | ||
| 121 | self.destroy() | ||
| 122 | else: | ||
| 123 | self.show_invalid_input_error_dialog() | ||
| 124 | |||
| 125 | def show_invalid_input_error_dialog(self): | ||
| 126 | lbl = "<b>Invalid characters in image recipe name</b>\n" | ||
| 127 | msg = "Image recipe names should be all lowercase and\n" | ||
| 128 | msg += "include only alphanumeric characters. The only\n" | ||
| 129 | msg += "special character you can use is the ASCII hyphen (-)." | ||
| 130 | lbl = lbl + "\n%s\n" % glib.markup_escape_text(msg) | ||
| 131 | dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_ERROR) | ||
| 132 | button = dialog.add_button("Close", gtk.RESPONSE_OK) | ||
| 133 | HobButton.style_button(button) | ||
| 134 | |||
| 135 | res = dialog.run() | ||
| 136 | dialog.destroy() | ||
