om@2: #!/bin/env python om@2: # -*- coding: utf-8 -*- om@2: om@2: # ------------------------------------------------------------ om@2: # credentials-dialog om@2: # om@2: # ask the user credentials om@2: # om@2: # Autor: Oliver Maurhart, om@2: # om@2: # Copyright (C) 2013 AIT Austrian Institute of Technology om@2: # AIT Austrian Institute of Technology GmbH om@2: # Donau-City-Strasse 1 | 1220 Vienna | Austria om@2: # http://www.ait.ac.at om@2: # om@2: # This program is free software; you can redistribute it and/or om@2: # modify it under the terms of the GNU General Public License om@2: # as published by the Free Software Foundation version 2. om@2: # om@2: # This program is distributed in the hope that it will be useful, om@2: # but WITHOUT ANY WARRANTY; without even the implied warranty of om@2: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the om@2: # GNU General Public License for more details. om@2: # om@2: # You should have received a copy of the GNU General Public License om@2: # along with this program; if not, write to the Free Software om@2: # Foundation, Inc., 51 Franklin Street, Fifth Floor, om@2: # Boston, MA 02110-1301, USA. om@2: # ------------------------------------------------------------ om@2: om@2: om@2: # ------------------------------------------------------------ om@2: # imports om@2: om@2: import sys om@2: om@2: from PyQt4 import QtCore om@2: from PyQt4 import QtGui om@2: om@2: # local om@2: from about import About om@2: om@2: # ------------------------------------------------------------ om@2: # code om@2: om@2: om@2: class Credentials(QtGui.QDialog): om@2: om@2: """Ask the user for credentials.""" om@2: om@2: def __init__(self, text, parent = None, flags = QtCore.Qt.WindowFlags(0)): om@2: om@2: super(Credentials, self).__init__(parent, flags) om@2: self.setWindowTitle('OpenSecuirty Credentials Request') om@2: self.setup_ui() om@2: om@2: # positionate ourself central om@2: screen = QtGui.QDesktopWidget().screenGeometry() om@2: self.resize(self.geometry().width() * 1.25, self.geometry().height()) om@2: size = self.geometry() om@2: self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) om@2: om@2: # fix up text om@2: self.lbText.setText(text) om@2: om@2: om@2: def clicked_about(self): om@2: """clicked the about button""" om@2: dlgAbout = About() om@2: dlgAbout.exec_() om@2: om@2: om@2: def clicked_cancel(self): om@2: """clicked the cancel button""" om@2: self.reject() om@2: om@2: om@2: def clicked_ok(self): om@2: """clicked the ok button""" om@2: sys.stdout.write('{ ') om@2: sys.stdout.write('\'user\': \'') om@2: sys.stdout.write(self.edUser.text()) om@2: sys.stdout.write('\', ') om@2: sys.stdout.write('\'password\': \'') om@2: sys.stdout.write(self.edPassword.text()) om@2: sys.stdout.write('\' ') om@2: sys.stdout.write('}\n') om@2: self.accept() om@2: om@2: om@2: def setup_ui(self): om@2: om@2: """Create the widgets.""" om@2: om@2: lyMain = QtGui.QVBoxLayout(self) om@2: lyMain.setContentsMargins(8, 8, 8, 8) om@2: om@2: # content area: left pixmap, right text om@2: lyContent = QtGui.QHBoxLayout() om@2: lyMain.addLayout(lyContent) om@2: om@2: # pixmap om@2: lbPix = QtGui.QLabel() om@2: lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64')) om@2: lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter)) om@2: lyContent.addSpacing(16) om@2: om@2: # text ... om@2: lyText = QtGui.QGridLayout() om@2: lyContent.addLayout(lyText) om@2: self.lbText = QtGui.QLabel() om@2: lyText.addWidget(self.lbText, 0, 0, 1, 2) om@2: om@2: lbUser = QtGui.QLabel('&User:') om@2: lyText.addWidget(lbUser, 1, 0) om@2: self.edUser = QtGui.QLineEdit() om@2: lyText.addWidget(self.edUser, 1, 1) om@2: lbUser.setBuddy(self.edUser) om@2: om@2: lbPassword = QtGui.QLabel('&Password:') om@2: lyText.addWidget(lbPassword, 2, 0) om@2: self.edPassword = QtGui.QLineEdit() om@2: self.edPassword.setEchoMode(QtGui.QLineEdit.Password) om@2: lyText.addWidget(self.edPassword, 2, 1) om@2: lbPassword.setBuddy(self.edPassword) om@2: om@2: lyText.addWidget(QtGui.QWidget(), 3, 0, 1, 2) om@2: lyText.setColumnStretch(1, 1) om@2: lyText.setRowStretch(3, 1) om@2: om@2: lyMain.addStretch(1) om@2: om@2: # buttons om@2: lyButton = QtGui.QHBoxLayout() om@2: lyMain.addLayout(lyButton) om@2: om@2: lyButton.addStretch(1) om@2: btnOk = QtGui.QPushButton('&Ok', self) om@2: btnOk.setDefault(True) om@2: btnOk.setMinimumWidth(100) om@2: lyButton.addWidget(btnOk) om@2: btnCancel = QtGui.QPushButton('&Cancel', self) om@2: btnCancel.setMinimumWidth(100) om@2: lyButton.addWidget(btnCancel) om@2: btnAbout = QtGui.QPushButton('&About', self) om@2: btnAbout.setMinimumWidth(100) om@2: lyButton.addWidget(btnAbout) om@2: om@2: button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width()) om@2: btnOk.setMinimumWidth(button_width) om@2: btnCancel.setMinimumWidth(button_width) om@2: btnAbout.setMinimumWidth(button_width) om@2: om@2: # reduce to the max om@2: self.resize(lyMain.minimumSize()) om@2: om@2: # connectors om@2: btnOk.clicked.connect(self.clicked_ok) om@2: btnCancel.clicked.connect(self.clicked_cancel) om@2: btnAbout.clicked.connect(self.clicked_about)