om@3
|
1 |
#!/bin/env python
|
om@3
|
2 |
# -*- coding: utf-8 -*-
|
om@3
|
3 |
|
om@3
|
4 |
# ------------------------------------------------------------
|
om@3
|
5 |
# password-dialog
|
om@3
|
6 |
#
|
om@3
|
7 |
# ask the user a password
|
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 Password(QtGui.QDialog):
|
om@3
|
48 |
|
om@3
|
49 |
"""Ask the user for a password."""
|
om@3
|
50 |
|
om@3
|
51 |
def __init__(self, text, parent = None, flags = QtCore.Qt.WindowFlags(0)):
|
om@3
|
52 |
|
om@3
|
53 |
# super call and widget init
|
om@3
|
54 |
super(Password, self).__init__(parent, flags)
|
om@3
|
55 |
self.setWindowTitle('OpenSecuirty Password Request')
|
om@3
|
56 |
self.setup_ui()
|
om@3
|
57 |
|
om@3
|
58 |
# positionate ourself central
|
om@3
|
59 |
screen = QtGui.QDesktopWidget().screenGeometry()
|
om@3
|
60 |
self.resize(self.geometry().width() * 1.25, self.geometry().height())
|
om@3
|
61 |
size = self.geometry()
|
om@3
|
62 |
self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
|
om@3
|
63 |
|
om@3
|
64 |
# fix up text
|
om@3
|
65 |
self.lbText.setText(text)
|
om@3
|
66 |
|
om@3
|
67 |
|
om@3
|
68 |
def clicked_about(self):
|
om@3
|
69 |
"""clicked the about button"""
|
om@3
|
70 |
dlgAbout = About()
|
om@3
|
71 |
dlgAbout.exec_()
|
om@3
|
72 |
|
om@3
|
73 |
|
om@3
|
74 |
def clicked_cancel(self):
|
om@3
|
75 |
"""clicked the cancel button"""
|
om@3
|
76 |
self.reject()
|
om@3
|
77 |
|
om@3
|
78 |
|
om@3
|
79 |
def clicked_ok(self):
|
om@3
|
80 |
"""clicked the ok button"""
|
om@3
|
81 |
sys.stdout.write('{ ')
|
om@3
|
82 |
sys.stdout.write('\'password\': \'')
|
om@3
|
83 |
sys.stdout.write(self.edPassword.text())
|
om@3
|
84 |
sys.stdout.write('\' ')
|
om@3
|
85 |
sys.stdout.write('}\n')
|
om@3
|
86 |
self.accept()
|
om@3
|
87 |
|
om@3
|
88 |
|
om@3
|
89 |
def setup_ui(self):
|
om@3
|
90 |
|
om@3
|
91 |
"""Create the widgets."""
|
om@3
|
92 |
|
om@3
|
93 |
lyMain = QtGui.QVBoxLayout(self)
|
om@3
|
94 |
lyMain.setContentsMargins(8, 8, 8, 8)
|
om@3
|
95 |
|
om@3
|
96 |
# content area: left pixmap, right text
|
om@3
|
97 |
lyContent = QtGui.QHBoxLayout()
|
om@3
|
98 |
lyMain.addLayout(lyContent)
|
om@3
|
99 |
|
om@3
|
100 |
# pixmap
|
om@3
|
101 |
lbPix = QtGui.QLabel()
|
om@3
|
102 |
lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
|
om@3
|
103 |
lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
|
om@3
|
104 |
lyContent.addSpacing(16)
|
om@3
|
105 |
|
om@3
|
106 |
# text ...
|
om@3
|
107 |
lyText = QtGui.QVBoxLayout()
|
om@3
|
108 |
lyContent.addLayout(lyText)
|
om@3
|
109 |
self.lbText = QtGui.QLabel()
|
om@3
|
110 |
lyText.addWidget(self.lbText)
|
om@3
|
111 |
lyPassword = QtGui.QHBoxLayout()
|
om@3
|
112 |
lyText.addLayout(lyPassword)
|
om@3
|
113 |
lbPassword = QtGui.QLabel('&Password:')
|
om@3
|
114 |
lyPassword.addWidget(lbPassword)
|
om@3
|
115 |
self.edPassword = QtGui.QLineEdit()
|
om@3
|
116 |
self.edPassword.setEchoMode(QtGui.QLineEdit.Password)
|
om@3
|
117 |
lyPassword.addWidget(self.edPassword)
|
om@3
|
118 |
lbPassword.setBuddy(self.edPassword)
|
om@3
|
119 |
lyText.addStretch(1)
|
om@3
|
120 |
|
om@3
|
121 |
lyMain.addStretch(1)
|
om@3
|
122 |
|
om@3
|
123 |
# buttons
|
om@3
|
124 |
lyButton = QtGui.QHBoxLayout()
|
om@3
|
125 |
lyMain.addLayout(lyButton)
|
om@3
|
126 |
|
om@3
|
127 |
lyButton.addStretch(1)
|
om@3
|
128 |
btnOk = QtGui.QPushButton('&Ok', self)
|
om@3
|
129 |
btnOk.setDefault(True)
|
om@3
|
130 |
btnOk.setMinimumWidth(100)
|
om@3
|
131 |
lyButton.addWidget(btnOk)
|
om@3
|
132 |
btnCancel = QtGui.QPushButton('&Cancel', self)
|
om@3
|
133 |
btnCancel.setMinimumWidth(100)
|
om@3
|
134 |
lyButton.addWidget(btnCancel)
|
om@3
|
135 |
btnAbout = QtGui.QPushButton('&About', self)
|
om@3
|
136 |
btnAbout.setMinimumWidth(100)
|
om@3
|
137 |
lyButton.addWidget(btnAbout)
|
om@3
|
138 |
|
om@3
|
139 |
button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width())
|
om@3
|
140 |
btnOk.setMinimumWidth(button_width)
|
om@3
|
141 |
btnCancel.setMinimumWidth(button_width)
|
om@3
|
142 |
btnAbout.setMinimumWidth(button_width)
|
om@3
|
143 |
|
om@3
|
144 |
# reduce to the max
|
om@3
|
145 |
self.resize(lyMain.minimumSize())
|
om@3
|
146 |
|
om@3
|
147 |
# connectors
|
om@3
|
148 |
btnOk.clicked.connect(self.clicked_ok)
|
om@3
|
149 |
btnCancel.clicked.connect(self.clicked_cancel)
|
om@3
|
150 |
btnAbout.clicked.connect(self.clicked_about)
|