2 # -*- coding: utf-8 -*-
4 # ------------------------------------------------------------
5 # credentials_dialog.pyw
7 # the user should give us some user/pass info
9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
11 # Copyright (C) 2014 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 if sys.platform == 'win32' or sys.platform == 'cygwin':
42 from PyQt4 import QtCore
43 from PyQt4 import QtGui
45 from ui_CredentialsDialog import Ui_CredentialsDialog
46 from about_dialog import AboutDialog
49 # ------------------------------------------------------------
53 class CredentialsDialog(QtGui.QDialog):
55 """A dialog for letting the user pass on a user/password combo"""
57 def __init__(self, user_text = 'Please provide approbitate login information:'):
59 QtGui.QDialog.__init__(self)
61 # setup the user interface
62 self.ui = Ui_CredentialsDialog()
66 self._about_dialog = AboutDialog()
69 self.ui.lblText.setText(user_text)
70 self.ui.btnAbout.clicked.connect(self.clicked_about)
71 self.ui.btnCancel.clicked.connect(self.reject)
72 self.ui.btnOk.clicked.connect(self.clicked_ok)
74 # positionate ourself central
75 screen = QtGui.QDesktopWidget().screenGeometry()
76 size = self.geometry()
77 self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
79 t = QtCore.QTimer(self)
80 t.timeout.connect(self.force_foreground)
86 def clicked_about(self):
88 """About button has been clicked."""
89 self._about_dialog.show()
94 """Ok button has been clicked."""
95 sys.stdout.write('{ ')
96 sys.stdout.write('"user": "')
97 sys.stdout.write(self.ui.edtUser.text())
98 sys.stdout.write('", ')
99 sys.stdout.write('"password": "')
100 sys.stdout.write(self.ui.edtPassword.text())
101 sys.stdout.write('" ')
102 sys.stdout.write('}\n')
106 def force_foreground(self):
108 """Force ourselves into foreground"""
109 if sys.platform == 'win32' or sys.platform == 'cygwin':
111 while not w.nativeParentWidget() is None:
112 w = w.nativeParentWidget()
113 win32gui.BringWindowToTop(int(w.effectiveWinId()))
114 win32gui.SetForegroundWindow(int(w.effectiveWinId()))
117 def set_user_text(user_text):
119 """Set a text to explain which credentials we need."""
120 self.ui.lblText.setText(user_text)
123 if __name__ == "__main__":
124 if sys.platform == 'win32' or sys.platform == 'cygwin':
125 win32gui.SystemParametersInfo(win32con.SPI_SETFOREGROUNDLOCKTIMEOUT, 0, win32con.SPIF_SENDWININICHANGE | win32con.SPIF_UPDATEINIFILE)
126 a = QtGui.QApplication(sys.argv)
127 d = CredentialsDialog()