om@2
|
1 |
#!/bin/env python
|
om@2
|
2 |
# -*- coding: utf-8 -*-
|
om@2
|
3 |
|
om@2
|
4 |
# ------------------------------------------------------------
|
om@2
|
5 |
# opensecurity-dialog
|
om@2
|
6 |
#
|
om@2
|
7 |
# an opensecurity dialog
|
om@2
|
8 |
#
|
om@2
|
9 |
# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
|
om@2
|
10 |
#
|
om@2
|
11 |
# Copyright (C) 2013 AIT Austrian Institute of Technology
|
om@2
|
12 |
# AIT Austrian Institute of Technology GmbH
|
om@2
|
13 |
# Donau-City-Strasse 1 | 1220 Vienna | Austria
|
om@2
|
14 |
# http://www.ait.ac.at
|
om@2
|
15 |
#
|
om@2
|
16 |
# This program is free software; you can redistribute it and/or
|
om@2
|
17 |
# modify it under the terms of the GNU General Public License
|
om@2
|
18 |
# as published by the Free Software Foundation version 2.
|
om@2
|
19 |
#
|
om@2
|
20 |
# This program is distributed in the hope that it will be useful,
|
om@2
|
21 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
om@2
|
22 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
om@2
|
23 |
# GNU General Public License for more details.
|
om@2
|
24 |
#
|
om@2
|
25 |
# You should have received a copy of the GNU General Public License
|
om@2
|
26 |
# along with this program; if not, write to the Free Software
|
om@2
|
27 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
om@2
|
28 |
# Boston, MA 02110-1301, USA.
|
om@2
|
29 |
# ------------------------------------------------------------
|
om@2
|
30 |
|
om@2
|
31 |
|
om@2
|
32 |
# ------------------------------------------------------------
|
om@2
|
33 |
# imports
|
om@2
|
34 |
|
om@2
|
35 |
import argparse
|
om@2
|
36 |
import os
|
om@2
|
37 |
import subprocess
|
om@2
|
38 |
import sys
|
om@2
|
39 |
|
om@2
|
40 |
from PyQt4 import QtCore
|
om@2
|
41 |
from PyQt4 import QtGui
|
om@2
|
42 |
|
om@2
|
43 |
# local
|
om@2
|
44 |
from environment import Environment
|
om@2
|
45 |
|
om@2
|
46 |
|
om@2
|
47 |
# ------------------------------------------------------------
|
om@2
|
48 |
# code
|
om@2
|
49 |
|
om@2
|
50 |
|
om@2
|
51 |
class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
|
om@2
|
52 |
|
om@2
|
53 |
"""This is the OpenSecuirty Tray Icon"""
|
om@2
|
54 |
|
om@2
|
55 |
def __init__(self, icon, parent=None):
|
om@2
|
56 |
|
om@2
|
57 |
super(OpenSecurityTrayIcon, self).__init__(icon, parent)
|
om@2
|
58 |
|
om@2
|
59 |
# define the tray icon menu
|
om@2
|
60 |
menu = QtGui.QMenu(parent)
|
om@2
|
61 |
self.setContextMenu(menu)
|
om@2
|
62 |
|
om@2
|
63 |
cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application')
|
om@2
|
64 |
menu.addSeparator()
|
om@2
|
65 |
cAcExit = menu.addAction("Exit")
|
om@2
|
66 |
|
om@2
|
67 |
cAcLaunch.triggered.connect(self.clicked_launch_application)
|
om@2
|
68 |
cAcExit.triggered.connect(self.clicked_exit)
|
om@2
|
69 |
|
om@2
|
70 |
|
om@2
|
71 |
def clicked_exit(self):
|
om@2
|
72 |
"""clicked exit"""
|
om@2
|
73 |
sys.exit(0)
|
om@2
|
74 |
|
om@2
|
75 |
|
om@2
|
76 |
def clicked_launch_application(self):
|
om@2
|
77 |
"""clicked the launch an application"""
|
om@2
|
78 |
dlg_launch_image = os.path.join(sys.path[0], 'launch.py')
|
om@2
|
79 |
process_command = [sys.executable, dlg_launch_image]
|
om@2
|
80 |
process = subprocess.Popen(process_command, shell = False)
|
om@2
|
81 |
process.communicate()
|
om@2
|
82 |
|
om@2
|
83 |
|
om@2
|
84 |
def main():
|
om@2
|
85 |
|
om@2
|
86 |
app = QtGui.QApplication(sys.argv)
|
om@2
|
87 |
|
om@2
|
88 |
# prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
|
om@2
|
89 |
data_path = Environment("opensecurity").image_path
|
om@2
|
90 |
for file in os.listdir(data_path):
|
om@2
|
91 |
if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
|
om@2
|
92 |
QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(data_path, file)))
|
om@2
|
93 |
|
om@2
|
94 |
w = QtGui.QWidget()
|
om@2
|
95 |
trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w)
|
om@2
|
96 |
|
om@2
|
97 |
trayIcon.show()
|
om@2
|
98 |
sys.exit(app.exec_())
|
om@2
|
99 |
|
om@2
|
100 |
|
om@2
|
101 |
# start
|
om@2
|
102 |
if __name__ == "__main__":
|
om@2
|
103 |
main()
|
om@2
|
104 |
|