om@2: #!/bin/env python om@2: # -*- coding: utf-8 -*- om@2: om@2: # ------------------------------------------------------------ om@2: # opensecurity-dialog om@2: # om@2: # an opensecurity dialog om@2: # om@2: # Autor: Oliver Maurhart, om@2: # om@2: # Copyright (C) 2013 AIT Austrian Institute of Technology om@2: # AIT Austrian Institute of Technology GmbH om@2: # Donau-City-Strasse 1 | 1220 Vienna | Austria om@2: # http://www.ait.ac.at om@2: # om@2: # This program is free software; you can redistribute it and/or om@2: # modify it under the terms of the GNU General Public License om@2: # as published by the Free Software Foundation version 2. om@2: # om@2: # This program is distributed in the hope that it will be useful, om@2: # but WITHOUT ANY WARRANTY; without even the implied warranty of om@2: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the om@2: # GNU General Public License for more details. om@2: # om@2: # You should have received a copy of the GNU General Public License om@2: # along with this program; if not, write to the Free Software om@2: # Foundation, Inc., 51 Franklin Street, Fifth Floor, om@2: # Boston, MA 02110-1301, USA. om@2: # ------------------------------------------------------------ om@2: om@2: om@2: # ------------------------------------------------------------ om@2: # imports om@2: om@2: import argparse om@2: import os om@2: import subprocess om@2: import sys om@2: om@2: from PyQt4 import QtCore om@2: from PyQt4 import QtGui om@2: om@2: # local om@2: from environment import Environment om@2: om@2: om@2: # ------------------------------------------------------------ om@2: # code om@2: om@2: om@2: class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon): om@2: om@2: """This is the OpenSecuirty Tray Icon""" om@2: om@2: def __init__(self, icon, parent=None): om@2: om@2: super(OpenSecurityTrayIcon, self).__init__(icon, parent) om@2: om@2: # define the tray icon menu om@2: menu = QtGui.QMenu(parent) om@2: self.setContextMenu(menu) om@2: om@2: cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application') om@2: menu.addSeparator() om@2: cAcExit = menu.addAction("Exit") om@2: om@2: cAcLaunch.triggered.connect(self.clicked_launch_application) om@2: cAcExit.triggered.connect(self.clicked_exit) om@2: om@2: om@2: def clicked_exit(self): om@2: """clicked exit""" om@2: sys.exit(0) om@2: om@2: om@2: def clicked_launch_application(self): om@2: """clicked the launch an application""" om@2: dlg_launch_image = os.path.join(sys.path[0], 'launch.py') om@2: process_command = [sys.executable, dlg_launch_image] om@2: process = subprocess.Popen(process_command, shell = False) om@2: process.communicate() om@2: om@2: om@2: def main(): om@2: om@2: app = QtGui.QApplication(sys.argv) om@2: om@2: # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them om@2: data_path = Environment("opensecurity").image_path om@2: for file in os.listdir(data_path): om@2: if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'): om@2: QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(data_path, file))) om@2: om@2: w = QtGui.QWidget() om@2: trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w) om@2: om@2: trayIcon.show() om@2: sys.exit(app.exec_()) om@2: om@2: om@2: # start om@2: if __name__ == "__main__": om@2: main() om@2: