2 # -*- coding: utf-8 -*-
4 # ------------------------------------------------------------
7 # show the user an opensecurity specific message box
9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
11 # Copyright (C) 2013 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 from PyQt4 import QtCore
38 from PyQt4 import QtGui
41 from about import About
44 # ------------------------------------------------------------
47 class Notification(QtGui.QDialog):
49 """Show the user an OpenSecurity specific notification."""
51 TYPES = ['information', 'warning', 'critical']
53 def __init__(self, msgtype, text, parent = None, flags = QtCore.Qt.WindowFlags(0)):
55 # super call and widget init
56 super(Notification, self).__init__(parent, flags)
57 self.setWindowTitle('OpenSecuirty Notification')
58 self.setup_ui(msgtype)
60 # positionate ourself central
61 screen = QtGui.QDesktopWidget().screenGeometry()
62 self.resize(self.geometry().width() * 1.25, self.geometry().height())
63 size = self.geometry()
64 self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
67 if msgtype in Notification.TYPES:
70 'information': 'OpenSecurity information',
71 'warning': '<b>OpenSecurity warning</b>',
72 'critical': '<b>OpenSecurity critical error</b>'
74 self.lbMsgType.setText(typetext[msgtype])
77 'information': 'OpenSecurity: Information',
78 'warning': 'OpenSecurity: Warning',
79 'critical': 'OpenSecurity: Critical'
81 self.setWindowTitle(captiontext[msgtype])
84 raise ValueError('unknown msgtype')
86 self.lbText.setText(text)
89 def clicked_about(self):
90 """clicked the about button"""
96 """clicked the ok button"""
100 def setup_ui(self, msgtype):
102 """Create the widgets."""
104 lyMain = QtGui.QVBoxLayout(self)
105 lyMain.setContentsMargins(8, 8, 8, 8)
107 # content area: left pixmap, right text
108 lyContent = QtGui.QHBoxLayout()
109 lyMain.addLayout(lyContent)
112 lbPix = QtGui.QLabel()
113 lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
114 lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
115 lyContent.addSpacing(16)
118 lyText = QtGui.QVBoxLayout()
119 lyContent.addLayout(lyText, 1)
121 self.lbMsgType = QtGui.QLabel()
122 lyText.addWidget(self.lbMsgType)
123 self.lbText = QtGui.QLabel()
124 lyText.addWidget(self.lbText)
130 lyButton = QtGui.QHBoxLayout()
131 lyMain.addLayout(lyButton)
133 lyButton.addStretch(1)
134 btnOk = QtGui.QPushButton('&Ok', self)
135 btnOk.setDefault(True)
136 btnOk.setMinimumWidth(100)
137 lyButton.addWidget(btnOk)
138 btnAbout = QtGui.QPushButton('&About', self)
139 btnAbout.setMinimumWidth(100)
140 lyButton.addWidget(btnAbout)
142 button_width = max(btnOk.width(), btnAbout.width())
143 btnOk.setMinimumWidth(button_width)
144 btnAbout.setMinimumWidth(button_width)
147 self.resize(lyMain.minimumSize())
150 btnOk.clicked.connect(self.clicked_ok)
151 btnAbout.clicked.connect(self.clicked_about)