ait/os/bin/opensecurityd/opensecurity-tray.py
author om
Tue, 12 Nov 2013 11:31:34 +0100
branchom
changeset 2 c9bf2537109a
permissions -rwxr-xr-x
added C/C++ and Python sources
     1 #!/bin/env python
     2 # -*- coding: utf-8 -*-
     3 
     4 # ------------------------------------------------------------
     5 # opensecurity-dialog
     6 # 
     7 # an opensecurity dialog
     8 #
     9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    10 #
    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
    15 #
    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.
    19 # 
    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.
    24 # 
    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 # ------------------------------------------------------------
    30 
    31 
    32 # ------------------------------------------------------------
    33 # imports
    34 
    35 import argparse
    36 import os
    37 import subprocess
    38 import sys
    39 
    40 from PyQt4 import QtCore
    41 from PyQt4 import QtGui
    42 
    43 # local
    44 from environment import Environment
    45 
    46 
    47 # ------------------------------------------------------------
    48 # code
    49 
    50 
    51 class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
    52     
    53     """This is the OpenSecuirty Tray Icon"""
    54 
    55     def __init__(self, icon, parent=None):
    56         
    57         super(OpenSecurityTrayIcon, self).__init__(icon, parent)
    58         
    59         # define the tray icon menu
    60         menu = QtGui.QMenu(parent)
    61         self.setContextMenu(menu)
    62         
    63         cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application')
    64         menu.addSeparator()
    65         cAcExit = menu.addAction("Exit")
    66         
    67         cAcLaunch.triggered.connect(self.clicked_launch_application)
    68         cAcExit.triggered.connect(self.clicked_exit)
    69         
    70         
    71     def clicked_exit(self):
    72         """clicked exit"""
    73         sys.exit(0)
    74     
    75 
    76     def clicked_launch_application(self):
    77         """clicked the launch an application"""
    78         dlg_launch_image = os.path.join(sys.path[0], 'launch.py')
    79         process_command = [sys.executable, dlg_launch_image]
    80         process = subprocess.Popen(process_command, shell = False)
    81         process.communicate()
    82             
    83 
    84 def main():
    85     
    86     app = QtGui.QApplication(sys.argv)
    87 
    88     # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
    89     data_path = Environment("opensecurity").image_path
    90     for file in os.listdir(data_path):
    91         if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
    92             QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(data_path, file)))
    93 
    94     w = QtGui.QWidget()
    95     trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w)
    96 
    97     trayIcon.show()
    98     sys.exit(app.exec_())
    99    
   100 
   101 # start
   102 if __name__ == "__main__":
   103     main()
   104