1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/ait/os/bin/opensecurityd/opensecurity-tray.py Tue Nov 12 11:31:34 2013 +0100
1.3 @@ -0,0 +1,104 @@
1.4 +#!/bin/env python
1.5 +# -*- coding: utf-8 -*-
1.6 +
1.7 +# ------------------------------------------------------------
1.8 +# opensecurity-dialog
1.9 +#
1.10 +# an opensecurity dialog
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 argparse
1.39 +import os
1.40 +import subprocess
1.41 +import sys
1.42 +
1.43 +from PyQt4 import QtCore
1.44 +from PyQt4 import QtGui
1.45 +
1.46 +# local
1.47 +from environment import Environment
1.48 +
1.49 +
1.50 +# ------------------------------------------------------------
1.51 +# code
1.52 +
1.53 +
1.54 +class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
1.55 +
1.56 + """This is the OpenSecuirty Tray Icon"""
1.57 +
1.58 + def __init__(self, icon, parent=None):
1.59 +
1.60 + super(OpenSecurityTrayIcon, self).__init__(icon, parent)
1.61 +
1.62 + # define the tray icon menu
1.63 + menu = QtGui.QMenu(parent)
1.64 + self.setContextMenu(menu)
1.65 +
1.66 + cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application')
1.67 + menu.addSeparator()
1.68 + cAcExit = menu.addAction("Exit")
1.69 +
1.70 + cAcLaunch.triggered.connect(self.clicked_launch_application)
1.71 + cAcExit.triggered.connect(self.clicked_exit)
1.72 +
1.73 +
1.74 + def clicked_exit(self):
1.75 + """clicked exit"""
1.76 + sys.exit(0)
1.77 +
1.78 +
1.79 + def clicked_launch_application(self):
1.80 + """clicked the launch an application"""
1.81 + dlg_launch_image = os.path.join(sys.path[0], 'launch.py')
1.82 + process_command = [sys.executable, dlg_launch_image]
1.83 + process = subprocess.Popen(process_command, shell = False)
1.84 + process.communicate()
1.85 +
1.86 +
1.87 +def main():
1.88 +
1.89 + app = QtGui.QApplication(sys.argv)
1.90 +
1.91 + # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
1.92 + data_path = Environment("opensecurity").image_path
1.93 + for file in os.listdir(data_path):
1.94 + if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
1.95 + QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(data_path, file)))
1.96 +
1.97 + w = QtGui.QWidget()
1.98 + trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w)
1.99 +
1.100 + trayIcon.show()
1.101 + sys.exit(app.exec_())
1.102 +
1.103 +
1.104 +# start
1.105 +if __name__ == "__main__":
1.106 + main()
1.107 +