2 # -*- coding: utf-8 -*-
4 # ------------------------------------------------------------
7 # an opensecurity dialog
9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
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
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.
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.
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 # ------------------------------------------------------------
32 # ------------------------------------------------------------
40 from PyQt4 import QtCore
41 from PyQt4 import QtGui
44 from about import About
45 from environment import Environment
48 # ------------------------------------------------------------
52 class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
54 """This is the OpenSecuirty Tray Icon"""
56 def __init__(self, icon, parent=None):
58 super(OpenSecurityTrayIcon, self).__init__(icon, parent)
62 def clicked_about(self):
68 def clicked_exit(self):
73 def clicked_launch_application(self):
74 """clicked the launch an application"""
75 dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
76 process_command = [sys.executable, dlg_launch_image]
77 print(process_command)
78 process = subprocess.Popen(process_command, shell = False)
82 def clicked_refresh(self):
88 """create the user interface
89 As for the system tray this is 'just' the context menu.
92 # define the tray icon menu
93 menu = QtGui.QMenu(self.parent())
94 self.setContextMenu(menu)
98 # add standard menu items
99 cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application')
101 cAcRefresh = menu.addAction('Refresh')
102 cAcAbout = menu.addAction("About")
103 cAcExit = menu.addAction("Exit")
105 cAcLaunch.triggered.connect(self.clicked_launch_application)
106 cAcRefresh.triggered.connect(self.clicked_refresh)
107 cAcAbout.triggered.connect(self.clicked_about)
108 cAcExit.triggered.connect(self.clicked_exit)
113 app = QtGui.QApplication(sys.argv)
115 # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
116 image_path = os.path.join(Environment("OpenSecurity").data_path, '..', 'gfx')
117 for file in os.listdir(image_path):
118 if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
119 QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
122 trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w)
125 sys.exit(app.exec_())
129 if __name__ == "__main__":