1.1 --- a/OpenSecurity/bin/opensecurity_tray.py Tue Dec 10 16:02:24 2013 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,131 +0,0 @@
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_exit(self):
1.72 - """clicked exit"""
1.73 - sys.exit(0)
1.74 -
1.75 -
1.76 - def clicked_launch_application(self):
1.77 - """clicked the launch an application"""
1.78 - dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
1.79 - process_command = [sys.executable, dlg_launch_image]
1.80 - print(process_command)
1.81 - process = subprocess.Popen(process_command, shell = False)
1.82 - process.communicate()
1.83 -
1.84 -
1.85 - def clicked_refresh(self):
1.86 - """clicked refresh"""
1.87 - self.setup_ui()
1.88 -
1.89 -
1.90 - def setup_ui(self):
1.91 - """create the user interface
1.92 - As for the system tray this is 'just' the context menu.
1.93 - """
1.94 -
1.95 - # define the tray icon menu
1.96 - menu = QtGui.QMenu(self.parent())
1.97 - self.setContextMenu(menu)
1.98 -
1.99 - # add known apps
1.100 -
1.101 - # add standard menu items
1.102 - cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application')
1.103 - menu.addSeparator()
1.104 - cAcRefresh = menu.addAction('Refresh')
1.105 - cAcAbout = menu.addAction("About")
1.106 - cAcExit = menu.addAction("Exit")
1.107 -
1.108 - cAcLaunch.triggered.connect(self.clicked_launch_application)
1.109 - cAcRefresh.triggered.connect(self.clicked_refresh)
1.110 - cAcAbout.triggered.connect(self.clicked_about)
1.111 - cAcExit.triggered.connect(self.clicked_exit)
1.112 -
1.113 -
1.114 -def main():
1.115 -
1.116 - app = QtGui.QApplication(sys.argv)
1.117 -
1.118 - # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
1.119 - image_path = os.path.join(Environment("OpenSecurity").data_path, '..', 'gfx')
1.120 - for file in os.listdir(image_path):
1.121 - if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
1.122 - QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
1.123 -
1.124 - w = QtGui.QWidget()
1.125 - trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w)
1.126 -
1.127 - trayIcon.show()
1.128 - sys.exit(app.exec_())
1.129 -
1.130 -
1.131 -# start
1.132 -if __name__ == "__main__":
1.133 - main()
1.134 -