om@3
|
1 |
#!/bin/env python
|
om@3
|
2 |
# -*- coding: utf-8 -*-
|
om@3
|
3 |
|
om@3
|
4 |
# ------------------------------------------------------------
|
om@3
|
5 |
# credentials-dialog
|
om@3
|
6 |
#
|
om@3
|
7 |
# ask the user credentials
|
om@3
|
8 |
#
|
om@3
|
9 |
# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
|
om@3
|
10 |
#
|
om@3
|
11 |
# Copyright (C) 2013 AIT Austrian Institute of Technology
|
om@3
|
12 |
# AIT Austrian Institute of Technology GmbH
|
om@3
|
13 |
# Donau-City-Strasse 1 | 1220 Vienna | Austria
|
om@3
|
14 |
# http://www.ait.ac.at
|
om@3
|
15 |
#
|
om@3
|
16 |
# This program is free software; you can redistribute it and/or
|
om@3
|
17 |
# modify it under the terms of the GNU General Public License
|
om@3
|
18 |
# as published by the Free Software Foundation version 2.
|
om@3
|
19 |
#
|
om@3
|
20 |
# This program is distributed in the hope that it will be useful,
|
om@3
|
21 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
om@3
|
22 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
om@3
|
23 |
# GNU General Public License for more details.
|
om@3
|
24 |
#
|
om@3
|
25 |
# You should have received a copy of the GNU General Public License
|
om@3
|
26 |
# along with this program; if not, write to the Free Software
|
om@3
|
27 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
om@3
|
28 |
# Boston, MA 02110-1301, USA.
|
om@3
|
29 |
# ------------------------------------------------------------
|
om@3
|
30 |
|
om@3
|
31 |
|
om@3
|
32 |
# ------------------------------------------------------------
|
om@3
|
33 |
# imports
|
om@3
|
34 |
|
om@3
|
35 |
import sys
|
om@3
|
36 |
|
om@3
|
37 |
from PyQt4 import QtCore
|
om@3
|
38 |
from PyQt4 import QtGui
|
om@3
|
39 |
|
om@3
|
40 |
# local
|
om@3
|
41 |
from about import About
|
om@3
|
42 |
|
om@3
|
43 |
# ------------------------------------------------------------
|
om@3
|
44 |
# code
|
om@3
|
45 |
|
om@3
|
46 |
|
om@3
|
47 |
class Credentials(QtGui.QDialog):
|
om@3
|
48 |
|
om@3
|
49 |
"""Ask the user for credentials."""
|
om@3
|
50 |
|
om@3
|
51 |
def __init__(self, text, parent = None, flags = QtCore.Qt.WindowFlags(0)):
|
om@3
|
52 |
|
om@3
|
53 |
super(Credentials, self).__init__(parent, flags)
|
om@3
|
54 |
self.setWindowTitle('OpenSecuirty Credentials Request')
|
om@3
|
55 |
self.setup_ui()
|
om@3
|
56 |
|
om@3
|
57 |
# positionate ourself central
|
om@3
|
58 |
screen = QtGui.QDesktopWidget().screenGeometry()
|
om@3
|
59 |
self.resize(self.geometry().width() * 1.25, self.geometry().height())
|
om@3
|
60 |
size = self.geometry()
|
om@3
|
61 |
self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
|
om@3
|
62 |
|
om@3
|
63 |
# fix up text
|
om@3
|
64 |
self.lbText.setText(text)
|
om@3
|
65 |
|
om@3
|
66 |
|
om@3
|
67 |
def clicked_about(self):
|
om@3
|
68 |
"""clicked the about button"""
|
om@3
|
69 |
dlgAbout = About()
|
om@3
|
70 |
dlgAbout.exec_()
|
om@3
|
71 |
|
om@3
|
72 |
|
om@3
|
73 |
def clicked_cancel(self):
|
om@3
|
74 |
"""clicked the cancel button"""
|
om@3
|
75 |
self.reject()
|
om@3
|
76 |
|
om@3
|
77 |
|
om@3
|
78 |
def clicked_ok(self):
|
om@3
|
79 |
"""clicked the ok button"""
|
om@3
|
80 |
sys.stdout.write('{ ')
|
om@3
|
81 |
sys.stdout.write('\'user\': \'')
|
om@3
|
82 |
sys.stdout.write(self.edUser.text())
|
om@3
|
83 |
sys.stdout.write('\', ')
|
om@3
|
84 |
sys.stdout.write('\'password\': \'')
|
om@3
|
85 |
sys.stdout.write(self.edPassword.text())
|
om@3
|
86 |
sys.stdout.write('\' ')
|
om@3
|
87 |
sys.stdout.write('}\n')
|
om@3
|
88 |
self.accept()
|
om@3
|
89 |
|
om@3
|
90 |
|
om@3
|
91 |
def setup_ui(self):
|
om@3
|
92 |
|
om@3
|
93 |
"""Create the widgets."""
|
om@3
|
94 |
|
om@3
|
95 |
lyMain = QtGui.QVBoxLayout(self)
|
om@3
|
96 |
lyMain.setContentsMargins(8, 8, 8, 8)
|
om@3
|
97 |
|
om@3
|
98 |
# content area: left pixmap, right text
|
om@3
|
99 |
lyContent = QtGui.QHBoxLayout()
|
om@3
|
100 |
lyMain.addLayout(lyContent)
|
om@3
|
101 |
|
om@3
|
102 |
# pixmap
|
om@3
|
103 |
lbPix = QtGui.QLabel()
|
om@3
|
104 |
lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
|
om@3
|
105 |
lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
|
om@3
|
106 |
lyContent.addSpacing(16)
|
om@3
|
107 |
|
om@3
|
108 |
# text ...
|
om@3
|
109 |
lyText = QtGui.QGridLayout()
|
om@3
|
110 |
lyContent.addLayout(lyText)
|
om@3
|
111 |
self.lbText = QtGui.QLabel()
|
om@3
|
112 |
lyText.addWidget(self.lbText, 0, 0, 1, 2)
|
om@3
|
113 |
|
om@3
|
114 |
lbUser = QtGui.QLabel('&User:')
|
om@3
|
115 |
lyText.addWidget(lbUser, 1, 0)
|
om@3
|
116 |
self.edUser = QtGui.QLineEdit()
|
om@3
|
117 |
lyText.addWidget(self.edUser, 1, 1)
|
om@3
|
118 |
lbUser.setBuddy(self.edUser)
|
om@3
|
119 |
|
om@3
|
120 |
lbPassword = QtGui.QLabel('&Password:')
|
om@3
|
121 |
lyText.addWidget(lbPassword, 2, 0)
|
om@3
|
122 |
self.edPassword = QtGui.QLineEdit()
|
om@3
|
123 |
self.edPassword.setEchoMode(QtGui.QLineEdit.Password)
|
om@3
|
124 |
lyText.addWidget(self.edPassword, 2, 1)
|
om@3
|
125 |
lbPassword.setBuddy(self.edPassword)
|
om@3
|
126 |
|
om@3
|
127 |
lyText.addWidget(QtGui.QWidget(), 3, 0, 1, 2)
|
om@3
|
128 |
lyText.setColumnStretch(1, 1)
|
om@3
|
129 |
lyText.setRowStretch(3, 1)
|
om@3
|
130 |
|
om@3
|
131 |
lyMain.addStretch(1)
|
om@3
|
132 |
|
om@3
|
133 |
# buttons
|
om@3
|
134 |
lyButton = QtGui.QHBoxLayout()
|
om@3
|
135 |
lyMain.addLayout(lyButton)
|
om@3
|
136 |
|
om@3
|
137 |
lyButton.addStretch(1)
|
om@3
|
138 |
btnOk = QtGui.QPushButton('&Ok', self)
|
om@3
|
139 |
btnOk.setDefault(True)
|
om@3
|
140 |
btnOk.setMinimumWidth(100)
|
om@3
|
141 |
lyButton.addWidget(btnOk)
|
om@3
|
142 |
btnCancel = QtGui.QPushButton('&Cancel', self)
|
om@3
|
143 |
btnCancel.setMinimumWidth(100)
|
om@3
|
144 |
lyButton.addWidget(btnCancel)
|
om@3
|
145 |
btnAbout = QtGui.QPushButton('&About', self)
|
om@3
|
146 |
btnAbout.setMinimumWidth(100)
|
om@3
|
147 |
lyButton.addWidget(btnAbout)
|
om@3
|
148 |
|
om@3
|
149 |
button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width())
|
om@3
|
150 |
btnOk.setMinimumWidth(button_width)
|
om@3
|
151 |
btnCancel.setMinimumWidth(button_width)
|
om@3
|
152 |
btnAbout.setMinimumWidth(button_width)
|
om@3
|
153 |
|
om@3
|
154 |
# reduce to the max
|
om@3
|
155 |
self.resize(lyMain.minimumSize())
|
om@3
|
156 |
|
om@3
|
157 |
# connectors
|
om@3
|
158 |
btnOk.clicked.connect(self.clicked_ok)
|
om@3
|
159 |
btnCancel.clicked.connect(self.clicked_cancel)
|
om@3
|
160 |
btnAbout.clicked.connect(self.clicked_about)
|