2 # -*- coding: utf-8 -*-
4 # ------------------------------------------------------------
7 # ask the user a password
9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
11 # Copyright (C) 2013 AIT Austrian Institute of Technology
12 # AIT Austrian Institute of Technology GmbH
13 # Donau-City-Strasse 1 | 1220 Vienna | Austria
14 # http://www.ait.ac.at
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License
18 # as published by the Free Software Foundation version 2.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 # Boston, MA 02110-1301, USA.
29 # ------------------------------------------------------------
32 # ------------------------------------------------------------
37 from PyQt4 import QtCore
38 from PyQt4 import QtGui
41 from about import About
43 # ------------------------------------------------------------
47 class Password(QtGui.QDialog):
49 """Ask the user for a password."""
51 def __init__(self, text, parent = None, flags = QtCore.Qt.WindowFlags(0)):
53 # super call and widget init
54 super(Password, self).__init__(parent, flags)
55 self.setWindowTitle('OpenSecuirty Password Request')
58 # positionate ourself central
59 screen = QtGui.QDesktopWidget().screenGeometry()
60 self.resize(self.geometry().width() * 1.25, self.geometry().height())
61 size = self.geometry()
62 self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
65 self.lbText.setText(text)
68 def clicked_about(self):
69 """clicked the about button"""
74 def clicked_cancel(self):
75 """clicked the cancel button"""
80 """clicked the ok button"""
81 sys.stdout.write('{ ')
82 sys.stdout.write('\'password\': \'')
83 sys.stdout.write(self.edPassword.text())
84 sys.stdout.write('\' ')
85 sys.stdout.write('}\n')
91 """Create the widgets."""
93 lyMain = QtGui.QVBoxLayout(self)
94 lyMain.setContentsMargins(8, 8, 8, 8)
96 # content area: left pixmap, right text
97 lyContent = QtGui.QHBoxLayout()
98 lyMain.addLayout(lyContent)
101 lbPix = QtGui.QLabel()
102 lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
103 lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
104 lyContent.addSpacing(16)
107 lyText = QtGui.QVBoxLayout()
108 lyContent.addLayout(lyText)
109 self.lbText = QtGui.QLabel()
110 lyText.addWidget(self.lbText)
111 lyPassword = QtGui.QHBoxLayout()
112 lyText.addLayout(lyPassword)
113 lbPassword = QtGui.QLabel('&Password:')
114 lyPassword.addWidget(lbPassword)
115 self.edPassword = QtGui.QLineEdit()
116 self.edPassword.setEchoMode(QtGui.QLineEdit.Password)
117 lyPassword.addWidget(self.edPassword)
118 lbPassword.setBuddy(self.edPassword)
124 lyButton = QtGui.QHBoxLayout()
125 lyMain.addLayout(lyButton)
127 lyButton.addStretch(1)
128 btnOk = QtGui.QPushButton('&Ok', self)
129 btnOk.setDefault(True)
130 btnOk.setMinimumWidth(100)
131 lyButton.addWidget(btnOk)
132 btnCancel = QtGui.QPushButton('&Cancel', self)
133 btnCancel.setMinimumWidth(100)
134 lyButton.addWidget(btnCancel)
135 btnAbout = QtGui.QPushButton('&About', self)
136 btnAbout.setMinimumWidth(100)
137 lyButton.addWidget(btnAbout)
139 button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width())
140 btnOk.setMinimumWidth(button_width)
141 btnCancel.setMinimumWidth(button_width)
142 btnAbout.setMinimumWidth(button_width)
145 self.resize(lyMain.minimumSize())
148 btnOk.clicked.connect(self.clicked_ok)
149 btnCancel.clicked.connect(self.clicked_cancel)
150 btnAbout.clicked.connect(self.clicked_about)