KDE 4.7 PyKDE API Reference

- KDE's Python API

# KPasswordDialog Class Reference

`from PyKDE4.kdeui import *`

Inherits: KDialog → QDialog → QWidget → QObject

## Detailed Description

A dialog for requesting a password and optionaly a login from the end user.

Usage Exemple

Requesting a simple password, assynchronous

      KPasswordDialog *dlg = new KPasswordDialog( parent );
      dlg->setPrompt(i18n("Enter a password"));
      connect( dlg, SIGNAL( gotPassword( const QString& , bool ) )  , this, SLOT( setPassword( const QString &) ) );
      connect( dlg, SIGNAL( rejected() )  , this, SLOT( slotCancel() ) );
      dlg->show();

Requesting a login and a password, synchronous

      KPasswordDialog dlg(parent, KPasswordDialog.ShowUsernameLine);
      dlg.setPrompt(i18n("Enter a login and a password"));
      if( !dlg.exec() )
          return; //the user canceled
      use( dlg.username() , dlg.password() );

"KDE Password Dialog"

dialog for requesting login and password from the end user

## Enumerations
ErrorType | { UnknownError, UsernameError, PasswordError, FatalError, DomainError }
KPasswordDialogFlag | { NoFlags, ShowKeepPassword, ShowUsernameLine, UsernameReadOnly, ShowAnonymousLoginCheckBox, ShowDomainLine, DomainReadOnly }
## Signals
| gotPassword (QString password, bool keep)
| gotUsernameAndPassword (QString username, QString password, bool keep)
## Methods
| __init__ (self, QWidget parent=0, KPasswordDialog.KPasswordDialogFlags flags=0, KDialog.ButtonCodes otherButtons=0)
| __init__ (self, KPasswordDialog a0)
| accept (self)
| addCommentLine (self, QString label, QString comment)
bool | anonymousMode (self)
bool | checkPassword (self)
QString | domain (self)
bool | keepPassword (self)
QString | password (self)
QPixmap | pixmap (self)
QString | prompt (self)
| setAnonymousMode (self, bool anonymous)
| setDomain (self, QString a0)
| setKeepPassword (self, bool b)
| setKnownLogins (self, {QString:QString} knownLogins)
| setPassword (self, QString password)
| setPixmap (self, QPixmap a0)
| setPrompt (self, QString prompt)
| setUsername (self, QString a0)
| setUsernameReadOnly (self, bool readOnly)
| showErrorMessage (self, QString message, KPasswordDialog.ErrorType type=KPasswordDialog.PasswordError)
QString | username (self)

## Signal Documentation

gotPassword | ( | QString | password,
|  | bool | keep
| ) |  |  |

emitted when the dialog has been accepted

Parameters:

  | password | the entered password
  | keep | true if the "remember password" checkbox was checked, false otherwise. false if ShowKeepPassword was not set in the constructor

Signal syntax:
  `QObject.connect(source, SIGNAL("gotPassword(const QString&, bool)"), target_slot)`

gotUsernameAndPassword | ( | QString | username,
|  | QString | password,
|  | bool | keep
| ) |  |  |

emitted when the dialog has been accepted, and ShowUsernameLine was set on the constructor

Parameters:

  | username | the entered username
  | password | the entered password
  | keep | true if the "remember password" checkbox was checked, false otherwise. false if ShowKeepPassword was not set in the constructor

Signal syntax:
  `QObject.connect(source, SIGNAL("gotUsernameAndPassword(const QString&, const QString&, bool)"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | QWidget | parent=0,
|  | KPasswordDialog.KPasswordDialogFlags | flags=0,
|  | KDialog.ButtonCodes | otherButtons=0
| ) |  |  |

create a password dialog

Parameters:

  | parent | the parent widget (default:NULL).
  | flags | a set of KPasswordDialogFlag flags
  | otherButtons | buttons to show in the dialog besides Ok and Cancel. Useful for adding application-specific buttons like "ignore" or "skip".

__init__ | ( | self, |
|  | KPasswordDialog | a0
| ) |  |  |

accept | ( |  | self ) |

Internal:

addCommentLine | ( | self, |
|  | QString | label,
|  | QString | comment
| ) |  |  |

Adds a comment line to the dialog.

This function allows you to add one additional comment line to this widget. Calling this function after a comment has already been added will not have any effect.

Parameters:

  | label | label for comment (ex:"Command:")
  | comment | the actual comment text.

bool anonymousMode | ( |  | self ) |

Returns:
  anonymous mode has been selected.

Since:
  4.1

bool checkPassword | ( |  | self ) |

Virtual function that can be overridden to provide password checking in derived classes. It should return true if the password is valid, false otherwise.

QString domain | ( |  | self ) |

Returns the domain entered by the user.

Returns:
  the domain name

Since:
  4.1

bool keepPassword | ( |  | self ) |

Determines whether supplied authorization should persist even after the application has been closed.

this is set with the check password checkbox is the ShowKeepCheckBox flag is set in the constructor, if it is not set, this function return false

Returns:
  true to keep the password

QString password | ( |  | self ) |

Returns the password entered by the user.

Returns:
  the password

QPixmap pixmap | ( |  | self ) |

QString prompt | ( |  | self ) |

Returns the prompt

setAnonymousMode | ( | self, |
|  | bool | anonymous
| ) |  |  |

set anonymous mode (all other fields will be grayed out)

Since:
  4.1

setDomain | ( | self, |
|  | QString | a0
| ) |  |  |

set the default domain.

Since:
  4.1

setKeepPassword | ( | self, |
|  | bool | b
| ) |  |  |

Check or uncheck the "keep password" checkbox. This can be used to check it before showing the dialog, to tell the user that the password is stored already (e.g. in the wallet). enableKeep must have been set to true in the constructor.

has only effect if ShowKeepCheckBox is set in the constructor

setKnownLogins | ( | self, |
|  | {QString:QString} | knownLogins
| ) |  |  |

Presets a number of login+password pairs that the user can choose from. The passwords can be empty if you simply want to offer usernames to choose from.

This require the flag ShowUnernameLine to be set in the constructoe, and not the flag UsernameReadOnly

Parameters:

  | knownLogins | map of known logins: the keys are usernames, the values are passwords.

setPassword | ( | self, |
|  | QString | password
| ) |  |  |

Presets the password.

Parameters:

  | password | the password to set

setPixmap | ( | self, |
|  | QPixmap | a0
| ) |  |  |

set an image that appears next to the prompt.

setPrompt | ( | self, |
|  | QString | prompt
| ) |  |  |

Sets the prompt to show to the user.

Parameters:

  | prompt | instructional text to be shown.

setUsername | ( | self, |
|  | QString | a0
| ) |  |  |

set the default username.

setUsernameReadOnly | ( | self, |
|  | bool | readOnly
| ) |  |  |

Sets the username field read-only and sets the focus to the password field.

this can also be set by passing UsernameReadOnly as flag in the constructor

Parameters:

  | readOnly | true to set the user field to read-only

showErrorMessage | ( | self, |
|  | QString | message,
|  | KPasswordDialog.ErrorType | type=KPasswordDialog.PasswordError
| ) |  |  |

Shows an error message in the dialog box. Prevents having to show a dialog-on-a-dialog.

Parameters:

  | message | the error message to show

QString username | ( |  | self ) |

Returns the username entered by the user.

Returns:
  the user name

## Enumeration Documentation

ErrorType

Enumerator:

  UnknownError = 0 |
  UsernameError |
  PasswordError |
  FatalError |
  DomainError |

KPasswordDialogFlag

Enumerator:

  NoFlags = 0x00 |
  ShowKeepPassword = 0x01 |
  ShowUsernameLine = 0x02 |
  UsernameReadOnly = 0x04 |
  ShowAnonymousLoginCheckBox = 0x08 |
  ShowDomainLine = 0x10 |
  DomainReadOnly = 0x20 |