Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame^] | 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 | |
| 23 | import gtk |
| 24 | from bb.ui.crumbs.hig.crumbsdialog import CrumbsDialog |
| 25 | |
| 26 | """ |
| 27 | The following are convenience classes for implementing GNOME HIG compliant |
| 28 | BitBake GUI's |
| 29 | In summary: spacing = 12px, border-width = 6px |
| 30 | """ |
| 31 | |
| 32 | class ProxyDetailsDialog (CrumbsDialog): |
| 33 | |
| 34 | def __init__(self, title, user, passwd, parent, flags, buttons=None): |
| 35 | super(ProxyDetailsDialog, self).__init__(title, parent, flags, buttons) |
| 36 | self.connect("response", self.response_cb) |
| 37 | |
| 38 | self.auth = not (user == None or passwd == None or user == "") |
| 39 | self.user = user or "" |
| 40 | self.passwd = passwd or "" |
| 41 | |
| 42 | # create visual elements on the dialog |
| 43 | self.create_visual_elements() |
| 44 | |
| 45 | def create_visual_elements(self): |
| 46 | self.auth_checkbox = gtk.CheckButton("Use authentication") |
| 47 | self.auth_checkbox.set_tooltip_text("Check this box to set the username and the password") |
| 48 | self.auth_checkbox.set_active(self.auth) |
| 49 | self.auth_checkbox.connect("toggled", self.auth_checkbox_toggled_cb) |
| 50 | self.vbox.pack_start(self.auth_checkbox, expand=False, fill=False) |
| 51 | |
| 52 | hbox = gtk.HBox(False, 6) |
| 53 | self.user_label = gtk.Label("Username:") |
| 54 | self.user_text = gtk.Entry() |
| 55 | self.user_text.set_text(self.user) |
| 56 | hbox.pack_start(self.user_label, expand=False, fill=False) |
| 57 | hbox.pack_end(self.user_text, expand=False, fill=False) |
| 58 | self.vbox.pack_start(hbox, expand=False, fill=False) |
| 59 | |
| 60 | hbox = gtk.HBox(False, 6) |
| 61 | self.passwd_label = gtk.Label("Password:") |
| 62 | self.passwd_text = gtk.Entry() |
| 63 | self.passwd_text.set_text(self.passwd) |
| 64 | hbox.pack_start(self.passwd_label, expand=False, fill=False) |
| 65 | hbox.pack_end(self.passwd_text, expand=False, fill=False) |
| 66 | self.vbox.pack_start(hbox, expand=False, fill=False) |
| 67 | |
| 68 | self.refresh_auth_components() |
| 69 | self.show_all() |
| 70 | |
| 71 | def refresh_auth_components(self): |
| 72 | self.user_label.set_sensitive(self.auth) |
| 73 | self.user_text.set_editable(self.auth) |
| 74 | self.user_text.set_sensitive(self.auth) |
| 75 | self.passwd_label.set_sensitive(self.auth) |
| 76 | self.passwd_text.set_editable(self.auth) |
| 77 | self.passwd_text.set_sensitive(self.auth) |
| 78 | |
| 79 | def auth_checkbox_toggled_cb(self, button): |
| 80 | self.auth = self.auth_checkbox.get_active() |
| 81 | self.refresh_auth_components() |
| 82 | |
| 83 | def response_cb(self, dialog, response_id): |
| 84 | if response_id == gtk.RESPONSE_OK: |
| 85 | if self.auth: |
| 86 | self.user = self.user_text.get_text() |
| 87 | self.passwd = self.passwd_text.get_text() |
| 88 | else: |
| 89 | self.user = None |
| 90 | self.passwd = None |