1.1 --- a/OpenSecurity/client/password.py Fri Dec 06 10:47:26 2013 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,150 +0,0 @@
1.4 -#!/bin/env python
1.5 -# -*- coding: utf-8 -*-
1.6 -
1.7 -# ------------------------------------------------------------
1.8 -# password-dialog
1.9 -#
1.10 -# ask the user a password
1.11 -#
1.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
1.13 -#
1.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
1.15 -# AIT Austrian Institute of Technology GmbH
1.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
1.17 -# http://www.ait.ac.at
1.18 -#
1.19 -# This program is free software; you can redistribute it and/or
1.20 -# modify it under the terms of the GNU General Public License
1.21 -# as published by the Free Software Foundation version 2.
1.22 -#
1.23 -# This program is distributed in the hope that it will be useful,
1.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
1.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.26 -# GNU General Public License for more details.
1.27 -#
1.28 -# You should have received a copy of the GNU General Public License
1.29 -# along with this program; if not, write to the Free Software
1.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.31 -# Boston, MA 02110-1301, USA.
1.32 -# ------------------------------------------------------------
1.33 -
1.34 -
1.35 -# ------------------------------------------------------------
1.36 -# imports
1.37 -
1.38 -import sys
1.39 -
1.40 -from PyQt4 import QtCore
1.41 -from PyQt4 import QtGui
1.42 -
1.43 -# local
1.44 -from about import About
1.45 -
1.46 -# ------------------------------------------------------------
1.47 -# code
1.48 -
1.49 -
1.50 -class Password(QtGui.QDialog):
1.51 -
1.52 - """Ask the user for a password."""
1.53 -
1.54 - def __init__(self, text, parent = None, flags = QtCore.Qt.WindowFlags(0)):
1.55 -
1.56 - # super call and widget init
1.57 - super(Password, self).__init__(parent, flags)
1.58 - self.setWindowTitle('OpenSecuirty Password Request')
1.59 - self.setup_ui()
1.60 -
1.61 - # positionate ourself central
1.62 - screen = QtGui.QDesktopWidget().screenGeometry()
1.63 - self.resize(self.geometry().width() * 1.25, self.geometry().height())
1.64 - size = self.geometry()
1.65 - self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
1.66 -
1.67 - # fix up text
1.68 - self.lbText.setText(text)
1.69 -
1.70 -
1.71 - def clicked_about(self):
1.72 - """clicked the about button"""
1.73 - dlgAbout = About()
1.74 - dlgAbout.exec_()
1.75 -
1.76 -
1.77 - def clicked_cancel(self):
1.78 - """clicked the cancel button"""
1.79 - self.reject()
1.80 -
1.81 -
1.82 - def clicked_ok(self):
1.83 - """clicked the ok button"""
1.84 - sys.stdout.write('{ ')
1.85 - sys.stdout.write('\'password\': \'')
1.86 - sys.stdout.write(self.edPassword.text())
1.87 - sys.stdout.write('\' ')
1.88 - sys.stdout.write('}\n')
1.89 - self.accept()
1.90 -
1.91 -
1.92 - def setup_ui(self):
1.93 -
1.94 - """Create the widgets."""
1.95 -
1.96 - lyMain = QtGui.QVBoxLayout(self)
1.97 - lyMain.setContentsMargins(8, 8, 8, 8)
1.98 -
1.99 - # content area: left pixmap, right text
1.100 - lyContent = QtGui.QHBoxLayout()
1.101 - lyMain.addLayout(lyContent)
1.102 -
1.103 - # pixmap
1.104 - lbPix = QtGui.QLabel()
1.105 - lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
1.106 - lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
1.107 - lyContent.addSpacing(16)
1.108 -
1.109 - # text ...
1.110 - lyText = QtGui.QVBoxLayout()
1.111 - lyContent.addLayout(lyText)
1.112 - self.lbText = QtGui.QLabel()
1.113 - lyText.addWidget(self.lbText)
1.114 - lyPassword = QtGui.QHBoxLayout()
1.115 - lyText.addLayout(lyPassword)
1.116 - lbPassword = QtGui.QLabel('&Password:')
1.117 - lyPassword.addWidget(lbPassword)
1.118 - self.edPassword = QtGui.QLineEdit()
1.119 - self.edPassword.setEchoMode(QtGui.QLineEdit.Password)
1.120 - lyPassword.addWidget(self.edPassword)
1.121 - lbPassword.setBuddy(self.edPassword)
1.122 - lyText.addStretch(1)
1.123 -
1.124 - lyMain.addStretch(1)
1.125 -
1.126 - # buttons
1.127 - lyButton = QtGui.QHBoxLayout()
1.128 - lyMain.addLayout(lyButton)
1.129 -
1.130 - lyButton.addStretch(1)
1.131 - btnOk = QtGui.QPushButton('&Ok', self)
1.132 - btnOk.setDefault(True)
1.133 - btnOk.setMinimumWidth(100)
1.134 - lyButton.addWidget(btnOk)
1.135 - btnCancel = QtGui.QPushButton('&Cancel', self)
1.136 - btnCancel.setMinimumWidth(100)
1.137 - lyButton.addWidget(btnCancel)
1.138 - btnAbout = QtGui.QPushButton('&About', self)
1.139 - btnAbout.setMinimumWidth(100)
1.140 - lyButton.addWidget(btnAbout)
1.141 -
1.142 - button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width())
1.143 - btnOk.setMinimumWidth(button_width)
1.144 - btnCancel.setMinimumWidth(button_width)
1.145 - btnAbout.setMinimumWidth(button_width)
1.146 -
1.147 - # reduce to the max
1.148 - self.resize(lyMain.minimumSize())
1.149 -
1.150 - # connectors
1.151 - btnOk.clicked.connect(self.clicked_ok)
1.152 - btnCancel.clicked.connect(self.clicked_cancel)
1.153 - btnAbout.clicked.connect(self.clicked_about)