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