[PyKDE] KPasswordDialog and KWallet
david at boddie.org.uk
Sat Nov 25 19:12:51 GMT 2006
On Fri, 24 Nov 2006 17:43:38 +0100, Hans van Leeuwen wrote:
>Let me start by saying I just started using PyKDE and it's been a lot of fun.
>I have never used Python, nor done any GUI-progamming until last week, and
>I've already managed to create a few useable programs.
You're a quick learner! It's good to hear that you're enjoying yourself. :-)
>The question I have is regarding KPasswordDialog and KWallet. I'm writing a
>program which asks the user for a password, and passes it on to an external
>application, which returns an error if the password is incorrect.
>I would really like to be able to store the password using KWallet, but I
>can't figure out how to do that.
Looking at the API, I can see your problem.
>I use the following function:
> password = QCString();
> prompt = "Enter your password"
> KPasswordDialog.getPassword(password, prompt)
> return password
>It asks for the password and returns the entered value, but there is no "Keep
>If I use "password = 'foobar'", the checkbox appears, but this is not what I
>want, because I don't know the correct password beforehand.
Yes, I also found I could pass a null QCString and get a checkbox as well,
but that's useless because you then have no way of accessing the string
afterwards. (I believe the implementation modifies the string itself.)
>In the KpasswordDialog API-docs I see an option "enableKeep", but I have no
>idea how to use it.
QDialog-based classes use a convention where a pointer or reference to
a value is passed to some static function in C++ so that the function can
fill it in, and you can then look at the result afterwards. In Python, these
functions typically return a tuple instead, containing a value indicating
success or failure. In this case, you also get the value corresponding to
the "Keep password" checkbox, though you don't seem to be able to specify
Maybe that's a problem with the PyKDE API, but there is a simple
1. Create a dialog using one of the standard constructors. The first
one looks OK. Pass True for the enableKeep argument.
2. Set any text using setPrompt().
3. Call the dialog's exec_loop() method, obtaining a value that
indicates whether the user accepted or cancelled the dialog.
4. Call the dialog's password() method to get the password.
It's not quite as straightforward as using the static function, but you
get more control over the process as a result.
More information about the PyQt