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