OpenSecurity/client/credentials.py
changeset 14 c187aaceca32
parent 12 11dc05750aea
child 15 2e4cb1ebcbed
     1.1 --- a/OpenSecurity/client/credentials.py	Fri Dec 06 10:47:26 2013 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,160 +0,0 @@
     1.4 -#!/bin/env python
     1.5 -# -*- coding: utf-8 -*-
     1.6 -
     1.7 -# ------------------------------------------------------------
     1.8 -# credentials-dialog
     1.9 -# 
    1.10 -# ask the user credentials
    1.11 -#
    1.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    1.13 -#
    1.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
    1.15 -# AIT Austrian Institute of Technology GmbH
    1.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
    1.17 -# http://www.ait.ac.at
    1.18 -#
    1.19 -# This program is free software; you can redistribute it and/or
    1.20 -# modify it under the terms of the GNU General Public License
    1.21 -# as published by the Free Software Foundation version 2.
    1.22 -# 
    1.23 -# This program is distributed in the hope that it will be useful,
    1.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.26 -# GNU General Public License for more details.
    1.27 -# 
    1.28 -# You should have received a copy of the GNU General Public License
    1.29 -# along with this program; if not, write to the Free Software
    1.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    1.31 -# Boston, MA  02110-1301, USA.
    1.32 -# ------------------------------------------------------------
    1.33 -
    1.34 -
    1.35 -# ------------------------------------------------------------
    1.36 -# imports
    1.37 -
    1.38 -import sys
    1.39 -
    1.40 -from PyQt4 import QtCore
    1.41 -from PyQt4 import QtGui
    1.42 -
    1.43 -# local
    1.44 -from about import About
    1.45 -
    1.46 -# ------------------------------------------------------------
    1.47 -# code
    1.48 -
    1.49 -
    1.50 -class Credentials(QtGui.QDialog):
    1.51 -    
    1.52 -    """Ask the user for credentials."""
    1.53 -    
    1.54 -    def __init__(self, text, parent = None, flags = QtCore.Qt.WindowFlags(0)):
    1.55 -        
    1.56 -        super(Credentials, self).__init__(parent, flags)
    1.57 -        self.setWindowTitle('OpenSecuirty Credentials Request')
    1.58 -        self.setup_ui()
    1.59 -        
    1.60 -        # positionate ourself central
    1.61 -        screen = QtGui.QDesktopWidget().screenGeometry()
    1.62 -        self.resize(self.geometry().width() * 1.25, self.geometry().height())
    1.63 -        size = self.geometry()
    1.64 -        self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
    1.65 -        
    1.66 -        # fix up text
    1.67 -        self.lbText.setText(text)
    1.68 -        
    1.69 -
    1.70 -    def clicked_about(self):
    1.71 -        """clicked the about button"""
    1.72 -        dlgAbout = About()
    1.73 -        dlgAbout.exec_()
    1.74 -    
    1.75 -
    1.76 -    def clicked_cancel(self):
    1.77 -        """clicked the cancel button"""
    1.78 -        self.reject()
    1.79 -    
    1.80 -
    1.81 -    def clicked_ok(self):
    1.82 -        """clicked the ok button"""
    1.83 -        sys.stdout.write('{ ')
    1.84 -        sys.stdout.write('\'user\': \'')
    1.85 -        sys.stdout.write(self.edUser.text())
    1.86 -        sys.stdout.write('\', ')
    1.87 -        sys.stdout.write('\'password\': \'')
    1.88 -        sys.stdout.write(self.edPassword.text())
    1.89 -        sys.stdout.write('\' ')
    1.90 -        sys.stdout.write('}\n')
    1.91 -        self.accept()
    1.92 -    
    1.93 -
    1.94 -    def setup_ui(self):
    1.95 -        
    1.96 -        """Create the widgets."""
    1.97 -        
    1.98 -        lyMain = QtGui.QVBoxLayout(self)
    1.99 -        lyMain.setContentsMargins(8, 8, 8, 8)
   1.100 -        
   1.101 -        # content area: left pixmap, right text
   1.102 -        lyContent = QtGui.QHBoxLayout()
   1.103 -        lyMain.addLayout(lyContent)
   1.104 -        
   1.105 -        # pixmap
   1.106 -        lbPix = QtGui.QLabel()
   1.107 -        lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
   1.108 -        lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
   1.109 -        lyContent.addSpacing(16)
   1.110 -        
   1.111 -        # text ...
   1.112 -        lyText = QtGui.QGridLayout()
   1.113 -        lyContent.addLayout(lyText)
   1.114 -        self.lbText = QtGui.QLabel()
   1.115 -        lyText.addWidget(self.lbText, 0, 0, 1, 2)
   1.116 -        
   1.117 -        lbUser = QtGui.QLabel('&User:')
   1.118 -        lyText.addWidget(lbUser, 1, 0)
   1.119 -        self.edUser = QtGui.QLineEdit()
   1.120 -        lyText.addWidget(self.edUser, 1, 1)
   1.121 -        lbUser.setBuddy(self.edUser)
   1.122 -        
   1.123 -        lbPassword = QtGui.QLabel('&Password:')
   1.124 -        lyText.addWidget(lbPassword, 2, 0)
   1.125 -        self.edPassword = QtGui.QLineEdit()
   1.126 -        self.edPassword.setEchoMode(QtGui.QLineEdit.Password)
   1.127 -        lyText.addWidget(self.edPassword, 2, 1)
   1.128 -        lbPassword.setBuddy(self.edPassword)
   1.129 -        
   1.130 -        lyText.addWidget(QtGui.QWidget(), 3, 0, 1, 2)
   1.131 -        lyText.setColumnStretch(1, 1)
   1.132 -        lyText.setRowStretch(3, 1)
   1.133 -        
   1.134 -        lyMain.addStretch(1)
   1.135 -        
   1.136 -        # buttons
   1.137 -        lyButton = QtGui.QHBoxLayout()
   1.138 -        lyMain.addLayout(lyButton)
   1.139 -        
   1.140 -        lyButton.addStretch(1)
   1.141 -        btnOk = QtGui.QPushButton('&Ok', self)
   1.142 -        btnOk.setDefault(True)
   1.143 -        btnOk.setMinimumWidth(100)
   1.144 -        lyButton.addWidget(btnOk)
   1.145 -        btnCancel = QtGui.QPushButton('&Cancel', self)
   1.146 -        btnCancel.setMinimumWidth(100)
   1.147 -        lyButton.addWidget(btnCancel)
   1.148 -        btnAbout = QtGui.QPushButton('&About', self)
   1.149 -        btnAbout.setMinimumWidth(100)
   1.150 -        lyButton.addWidget(btnAbout)
   1.151 -        
   1.152 -        button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width())
   1.153 -        btnOk.setMinimumWidth(button_width)
   1.154 -        btnCancel.setMinimumWidth(button_width)
   1.155 -        btnAbout.setMinimumWidth(button_width)
   1.156 -        
   1.157 -        # reduce to the max
   1.158 -        self.resize(lyMain.minimumSize())
   1.159 -        
   1.160 -        # connectors
   1.161 -        btnOk.clicked.connect(self.clicked_ok)
   1.162 -        btnCancel.clicked.connect(self.clicked_cancel)
   1.163 -        btnAbout.clicked.connect(self.clicked_about)