2 # -*- coding: utf-8 -*-
4 # ------------------------------------------------------------
7 # ask the user credentials
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 Credentials(QtGui.QDialog):
49 """Ask the user for credentials."""
51 def __init__(self, text, parent = None, flags = QtCore.Qt.WindowFlags(0)):
53 super(Credentials, self).__init__(parent, flags)
54 self.setWindowTitle('OpenSecuirty Credentials Request')
57 # positionate ourself central
58 screen = QtGui.QDesktopWidget().screenGeometry()
59 self.resize(self.geometry().width() * 1.25, self.geometry().height())
60 size = self.geometry()
61 self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
64 self.lbText.setText(text)
67 def clicked_about(self):
68 """clicked the about button"""
73 def clicked_cancel(self):
74 """clicked the cancel button"""
79 """clicked the ok button"""
80 sys.stdout.write('{ ')
81 sys.stdout.write('\'user\': \'')
82 sys.stdout.write(self.edUser.text())
83 sys.stdout.write('\', ')
84 sys.stdout.write('\'password\': \'')
85 sys.stdout.write(self.edPassword.text())
86 sys.stdout.write('\' ')
87 sys.stdout.write('}\n')
93 """Create the widgets."""
95 lyMain = QtGui.QVBoxLayout(self)
96 lyMain.setContentsMargins(8, 8, 8, 8)
98 # content area: left pixmap, right text
99 lyContent = QtGui.QHBoxLayout()
100 lyMain.addLayout(lyContent)
103 lbPix = QtGui.QLabel()
104 lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
105 lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
106 lyContent.addSpacing(16)
109 lyText = QtGui.QGridLayout()
110 lyContent.addLayout(lyText)
111 self.lbText = QtGui.QLabel()
112 lyText.addWidget(self.lbText, 0, 0, 1, 2)
114 lbUser = QtGui.QLabel('&User:')
115 lyText.addWidget(lbUser, 1, 0)
116 self.edUser = QtGui.QLineEdit()
117 lyText.addWidget(self.edUser, 1, 1)
118 lbUser.setBuddy(self.edUser)
120 lbPassword = QtGui.QLabel('&Password:')
121 lyText.addWidget(lbPassword, 2, 0)
122 self.edPassword = QtGui.QLineEdit()
123 self.edPassword.setEchoMode(QtGui.QLineEdit.Password)
124 lyText.addWidget(self.edPassword, 2, 1)
125 lbPassword.setBuddy(self.edPassword)
127 lyText.addWidget(QtGui.QWidget(), 3, 0, 1, 2)
128 lyText.setColumnStretch(1, 1)
129 lyText.setRowStretch(3, 1)
134 lyButton = QtGui.QHBoxLayout()
135 lyMain.addLayout(lyButton)
137 lyButton.addStretch(1)
138 btnOk = QtGui.QPushButton('&Ok', self)
139 btnOk.setDefault(True)
140 btnOk.setMinimumWidth(100)
141 lyButton.addWidget(btnOk)
142 btnCancel = QtGui.QPushButton('&Cancel', self)
143 btnCancel.setMinimumWidth(100)
144 lyButton.addWidget(btnCancel)
145 btnAbout = QtGui.QPushButton('&About', self)
146 btnAbout.setMinimumWidth(100)
147 lyButton.addWidget(btnAbout)
149 button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width())
150 btnOk.setMinimumWidth(button_width)
151 btnCancel.setMinimumWidth(button_width)
152 btnAbout.setMinimumWidth(button_width)
155 self.resize(lyMain.minimumSize())
158 btnOk.clicked.connect(self.clicked_ok)
159 btnCancel.clicked.connect(self.clicked_cancel)
160 btnAbout.clicked.connect(self.clicked_about)