Exemple #1
0
    def run(self):
        '''
        Setup the dialog and return the results to the invoker.
        '''

        msg = _('\nChoose how to report the bug(s)')

        if self._invalid_login:
            msg += _(
                '<b><i>Invalid credentials, please try again.</i></b>\n\n')

        self.set_markup(msg)

        #
        #    Anon
        #
        anon_button = gtk.RadioButton(None, "Anonymously")
        anon_button.set_active(True)
        self.vbox.pack_start(anon_button, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        #
        #    Email
        #
        email_button = gtk.RadioButton(anon_button, "Use email address")
        self.vbox.pack_start(email_button, True, True, 0)

        # Create the text input field
        self.email_entry = EmailEntry(self._email_entry_changed)
        self.email_entry.connect("activate",
                                 lambda x: self.response(gtk.RESPONSE_OK))

        # Create a horizontal box to pack the entry and a label
        email_hbox = gtk.HBox()
        email_hbox.pack_start(gtk.Label("Email address:"), False, 5, 5)
        email_hbox.pack_end(self.email_entry)
        email_hbox.set_sensitive(False)
        self.vbox.pack_start(email_hbox, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        #
        #    Github credentials
        #
        gh_button = gtk.RadioButton(email_button, "GitHub credentials:")
        self.vbox.pack_start(gh_button, True, True, 0)

        gh_vbox = gtk.VBox()

        # Create the text input field
        user_entry = gtk.Entry()
        user_entry.connect("activate",
                           lambda x: self.response(gtk.RESPONSE_OK))

        user_hbox = gtk.HBox()
        user_hbox.pack_start(gtk.Label("Username:  "******"activate",
                             lambda x: self.response(gtk.RESPONSE_OK))

        passwd_hbox = gtk.HBox()
        passwd_hbox.pack_start(gtk.Label("Password:  "******"\nYour credentials won't be stored in your computer,\n"
                    "  and will only be sent over HTTPS connections.")
        warning_label.set_text(warning)
        gh_vbox.pack_start(warning_label, True, True, 0)
        gh_vbox.set_sensitive(False)
        self.vbox.pack_start(gh_vbox, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        # Handling of sensitiviness between the radio contents
        anon_button.connect("toggled", self._radio_callback_anon, [],
                            [email_hbox, gh_vbox])
        email_button.connect("toggled", self._radio_callback_email, [
            email_hbox,
        ], [
            gh_vbox,
        ])
        gh_button.connect("toggled", self._radio_callback_gh, [
            gh_vbox,
        ], [
            email_hbox,
        ])

        # Go go go!
        self.show_all()
        gtk_response = super(dlg_ask_credentials, self).run()

        # The user closed the dialog with the X
        if gtk_response == gtk.RESPONSE_DELETE_EVENT:
            return True, None, None

        #
        # Get the results, generate the result tuple and return
        #
        active_label = [
            r.get_label() for r in anon_button.get_group() if r.get_active()
        ]
        active_label = active_label[0].lower()

        if 'email' in active_label:
            method = self.METHOD_EMAIL
            email = self.email_entry.get_text()
            params = (email, )
        elif 'sourceforge' in active_label:
            method = self.METHOD_GH
            user = user_entry.get_text()
            passwd = passwd_entry.get_text()
            params = (user, passwd)
        else:
            method = self.METHOD_ANON
            params = ()

        # I'm done!
        self.destroy()

        return (False, method, params)