OpenSecurity/bin/opensecurity_tray.pyw
changeset 37 6d7b4672414c
parent 16 e16d64b5e008
child 38 560882d3d3c0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/OpenSecurity/bin/opensecurity_tray.pyw	Tue Dec 10 17:24:12 2013 +0100
     1.3 @@ -0,0 +1,143 @@
     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 about import About
    1.48 +from environment import Environment
    1.49 +
    1.50 +
    1.51 +# ------------------------------------------------------------
    1.52 +# code
    1.53 +
    1.54 +
    1.55 +class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
    1.56 +    
    1.57 +    """This is the OpenSecuirty Tray Icon"""
    1.58 +
    1.59 +    def __init__(self, icon, parent=None):
    1.60 +        
    1.61 +        super(OpenSecurityTrayIcon, self).__init__(icon, parent)
    1.62 +        self.setup_ui()
    1.63 +        
    1.64 +        
    1.65 +    def clicked_about(self):
    1.66 +        """clicked about"""
    1.67 +        dlgAbout = About()
    1.68 +        dlgAbout.exec_()
    1.69 +    
    1.70 +
    1.71 +    def clicked_browser(self):
    1.72 +        """wish for safe internet browsing"""
    1.73 +        dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
    1.74 +        process_command = [sys.executable, dlg_launch_image, '192.168.56.101', '/usr/bin/iceweasel']
    1.75 +        print(process_command)
    1.76 +        process = subprocess.Popen(process_command, shell = False)
    1.77 +        process.communicate()
    1.78 +            
    1.79 +            
    1.80 +    def clicked_exit(self):
    1.81 +        """clicked exit"""
    1.82 +        sys.exit(0)
    1.83 +    
    1.84 +
    1.85 +    def clicked_launch_application(self):
    1.86 +        """clicked the launch an application"""
    1.87 +        dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
    1.88 +        process_command = [sys.executable, dlg_launch_image]
    1.89 +        print(process_command)
    1.90 +        process = subprocess.Popen(process_command, shell = False)
    1.91 +        process.communicate()
    1.92 +            
    1.93 +            
    1.94 +    def clicked_refresh(self):
    1.95 +        """clicked refresh"""
    1.96 +        self.setup_ui()
    1.97 +
    1.98 +    
    1.99 +    def setup_ui(self):
   1.100 +        """create the user interface
   1.101 +        As for the system tray this is 'just' the context menu.
   1.102 +        """
   1.103 +    
   1.104 +        # define the tray icon menu
   1.105 +        menu = QtGui.QMenu(self.parent())
   1.106 +        self.setContextMenu(menu)
   1.107 +        
   1.108 +        # add known apps
   1.109 +        cAcBrowser = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Safe Internet Browsing')
   1.110 +        menu.addSeparator()
   1.111 +        
   1.112 +        # add standard menu items
   1.113 +        cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application')
   1.114 +        menu.addSeparator()
   1.115 +        cAcRefresh = menu.addAction('Refresh')
   1.116 +        cAcAbout = menu.addAction("About")
   1.117 +        cAcExit = menu.addAction("Exit")
   1.118 +        
   1.119 +        cAcBrowser.triggered.connect(self.clicked_browser)
   1.120 +        cAcLaunch.triggered.connect(self.clicked_launch_application)
   1.121 +        cAcRefresh.triggered.connect(self.clicked_refresh)
   1.122 +        cAcAbout.triggered.connect(self.clicked_about)
   1.123 +        cAcExit.triggered.connect(self.clicked_exit)
   1.124 +        
   1.125 +        
   1.126 +def main():
   1.127 +    
   1.128 +    app = QtGui.QApplication(sys.argv)
   1.129 +
   1.130 +    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
   1.131 +    image_path = os.path.join(Environment("OpenSecurity").data_path, '..', 'gfx')
   1.132 +    for file in os.listdir(image_path):
   1.133 +        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
   1.134 +            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
   1.135 +
   1.136 +    w = QtGui.QWidget()
   1.137 +    trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w)
   1.138 +
   1.139 +    trayIcon.show()
   1.140 +    sys.exit(app.exec_())
   1.141 +   
   1.142 +
   1.143 +# start
   1.144 +if __name__ == "__main__":
   1.145 +    main()
   1.146 +