OpenSecurity/bin/ui/notification_dialog.py
author Oliver Maurhart <oliver.maurhart@ait.ac.at>
Wed, 29 Oct 2014 15:18:22 +0100
changeset 240 d7ef04254e9c
parent 113 67158aad9e06
permissions -rwxr-xr-x
lizenz fixed in all files
     1 #!/bin/env python
     2 # -*- coding: utf-8 -*-
     3 
     4 # ------------------------------------------------------------
     5 # notification_dialog.pyw
     6 # 
     7 # the user should give us a notification
     8 #
     9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    10 #
    11 # Copyright 2013-2014 X-Net and AIT Austrian Institute of Technology
    12 # 
    13 # 
    14 #     X-Net Services GmbH
    15 #     Elisabethstrasse 1
    16 #     4020 Linz
    17 #     AUSTRIA
    18 #     https://www.x-net.at
    19 # 
    20 #     AIT Austrian Institute of Technology
    21 #     Donau City Strasse 1
    22 #     1220 Wien
    23 #     AUSTRIA
    24 #     http://www.ait.ac.at
    25 # 
    26 # 
    27 # Licensed under the Apache License, Version 2.0 (the "License");
    28 # you may not use this file except in compliance with the License.
    29 # You may obtain a copy of the License at
    30 # 
    31 #    http://www.apache.org/licenses/LICENSE-2.0
    32 # 
    33 # Unless required by applicable law or agreed to in writing, software
    34 # distributed under the License is distributed on an "AS IS" BASIS,
    35 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    36 # See the License for the specific language governing permissions and
    37 # limitations under the License.
    38 # ------------------------------------------------------------
    39 
    40 
    41 # ------------------------------------------------------------
    42 # imports
    43 
    44 import sys
    45 
    46 from PyQt4 import QtCore
    47 from PyQt4 import QtGui
    48 
    49 from ui_NotificationDialog import Ui_NotificationDialog 
    50 from about_dialog import AboutDialog
    51 
    52 
    53 # ------------------------------------------------------------
    54 # code
    55 
    56 
    57 class NotificationDialog(QtGui.QDialog):
    58 
    59     """A dialog for letting the user pass on a user/notification combo"""
    60 
    61     def __init__(self, caption = 'OpenSecurity Notification', message = 'This is a notification from the OpenSecurity System.'):
    62 
    63         QtGui.QDialog.__init__(self)
    64 
    65         # setup the user interface
    66         self.ui = Ui_NotificationDialog()
    67         self.ui.setupUi(self)
    68         self.setWindowTitle(caption)
    69 
    70         # local members
    71         self._about_dialog = AboutDialog()
    72 
    73         # connectors
    74         self.ui.lblMessage.setText(message)
    75         self.ui.btnAbout.clicked.connect(self.clicked_about)
    76         self.ui.btnOk.clicked.connect(self.accept)
    77 
    78         # positionate ourself central
    79         screen = QtGui.QDesktopWidget().screenGeometry()
    80         size = self.geometry()
    81         self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
    82  
    83 
    84     def clicked_about(self):
    85 
    86         """About button has been clicked."""
    87         self._about_dialog.show()
    88 
    89 
    90     def clicked_ok(self):
    91         
    92         """Ok button has been clicked."""
    93         sys.stdout.write('{ ')
    94         sys.stdout.write('\'notification\': \'')
    95         sys.stdout.write(self.ui.edtNotification.text())
    96         sys.stdout.write('\' ')
    97         sys.stdout.write('}\n')
    98         self.accept()
    99 
   100 
   101     def set_user_text(user_text):
   102 
   103         """Set a text to explain which notification we need."""
   104         self.ui.lblText.setText(user_text)
   105 
   106 
   107 if __name__ == "__main__":
   108     a = QtGui.QApplication(sys.argv)
   109     d = NotificationDialog()
   110     d.show()
   111     sys.exit(a.exec_())     
   112