OpenSecurity/bin/ui/launch_dialog.py
author Oliver Maurhart <oliver.maurhart@ait.ac.at>
Wed, 29 Oct 2014 15:18:22 +0100
changeset 240 d7ef04254e9c
parent 187 63ca020b148d
permissions -rwxr-xr-x
lizenz fixed in all files
oliver@102
     1
#!/bin/env python
oliver@102
     2
# -*- coding: utf-8 -*-
oliver@102
     3
oliver@102
     4
# ------------------------------------------------------------
oliver@102
     5
# launch_dialog.pyw
oliver@102
     6
# 
oliver@102
     7
# let the user launch an app in a vm
oliver@102
     8
#
oliver@102
     9
# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
oliver@102
    10
#
oliver@240
    11
# Copyright 2013-2014 X-Net and AIT Austrian Institute of Technology
oliver@102
    12
# 
oliver@102
    13
# 
oliver@240
    14
#     X-Net Services GmbH
oliver@240
    15
#     Elisabethstrasse 1
oliver@240
    16
#     4020 Linz
oliver@240
    17
#     AUSTRIA
oliver@240
    18
#     https://www.x-net.at
oliver@240
    19
# 
oliver@240
    20
#     AIT Austrian Institute of Technology
oliver@240
    21
#     Donau City Strasse 1
oliver@240
    22
#     1220 Wien
oliver@240
    23
#     AUSTRIA
oliver@240
    24
#     http://www.ait.ac.at
oliver@240
    25
# 
oliver@240
    26
# 
oliver@240
    27
# Licensed under the Apache License, Version 2.0 (the "License");
oliver@240
    28
# you may not use this file except in compliance with the License.
oliver@240
    29
# You may obtain a copy of the License at
oliver@240
    30
# 
oliver@240
    31
#    http://www.apache.org/licenses/LICENSE-2.0
oliver@240
    32
# 
oliver@240
    33
# Unless required by applicable law or agreed to in writing, software
oliver@240
    34
# distributed under the License is distributed on an "AS IS" BASIS,
oliver@240
    35
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
oliver@240
    36
# See the License for the specific language governing permissions and
oliver@240
    37
# limitations under the License.
oliver@102
    38
# ------------------------------------------------------------
oliver@102
    39
oliver@102
    40
oliver@102
    41
# ------------------------------------------------------------
oliver@102
    42
# imports
oliver@102
    43
oliver@102
    44
import sys
oliver@102
    45
oliver@102
    46
from PyQt4 import QtCore
oliver@102
    47
from PyQt4 import QtGui
oliver@102
    48
oliver@102
    49
from ui_LaunchDialog import Ui_LaunchDialog 
oliver@102
    50
from about_dialog import AboutDialog
oliver@102
    51
oliver@102
    52
oliver@102
    53
# ------------------------------------------------------------
oliver@102
    54
# code
oliver@102
    55
oliver@102
    56
oliver@102
    57
class LaunchDialog(QtGui.QDialog):
oliver@102
    58
oliver@102
    59
    """A dialog for letting the user launch an arbitrary app in a vm"""
oliver@102
    60
oliver@102
    61
    def __init__(self, vms, apps):
oliver@102
    62
oliver@102
    63
        QtGui.QDialog.__init__(self)
oliver@102
    64
oliver@102
    65
        # setup the user interface
oliver@102
    66
        self.ui = Ui_LaunchDialog()
oliver@102
    67
        self.ui.setupUi(self)
oliver@102
    68
        for v in vms: 
oliver@102
    69
            self.ui.cmbVM.addItem(v)
oliver@102
    70
        for a in apps: 
oliver@102
    71
            self.ui.cmbApplication.addItem(a)
oliver@102
    72
    
oliver@102
    73
        # local members
oliver@102
    74
        self._about_dialog = AboutDialog()
oliver@102
    75
oliver@102
    76
        # connectors
oliver@102
    77
        self.ui.btnAbout.clicked.connect(self.clicked_about)
oliver@102
    78
        self.ui.btnCancel.clicked.connect(self.reject)
oliver@102
    79
        self.ui.btnOk.clicked.connect(self.clicked_ok)
oliver@102
    80
oliver@102
    81
        # positionate ourself central
oliver@102
    82
        screen = QtGui.QDesktopWidget().screenGeometry()
oliver@102
    83
        size = self.geometry()
oliver@102
    84
        self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
oliver@102
    85
 
oliver@102
    86
oliver@102
    87
    def clicked_about(self):
oliver@102
    88
oliver@102
    89
        """About button has been clicked."""
oliver@102
    90
        self._about_dialog.show()
oliver@102
    91
oliver@102
    92
oliver@102
    93
    def clicked_ok(self):
oliver@102
    94
        
oliver@102
    95
        """Ok button has been clicked."""
oliver@102
    96
        sys.stdout.write('{ ')
oliver@165
    97
        sys.stdout.write('"application": "')
oliver@102
    98
        sys.stdout.write(self.app)
oliver@165
    99
        sys.stdout.write('", ')
oliver@165
   100
        sys.stdout.write('"vm": "')
oliver@102
   101
        sys.stdout.write(self.vm)
oliver@165
   102
        sys.stdout.write('" ')
oliver@102
   103
        sys.stdout.write('}\n')
oliver@102
   104
        self.accept()
oliver@102
   105
oliver@102
   106
oliver@102
   107
    @property
oliver@102
   108
    def app(self):
oliver@102
   109
oliver@102
   110
        """The application of the user."""
oliver@102
   111
        return str(self.ui.cmbApplication.currentText())
oliver@102
   112
 
oliver@102
   113
oliver@102
   114
    @property
oliver@102
   115
    def vm(self):
oliver@102
   116
oliver@102
   117
        """The application of the user."""
oliver@102
   118
        return str(self.ui.cmbVM.currentText())
oliver@102
   119
 
oliver@102
   120
oliver@102
   121
if __name__ == "__main__":
oliver@113
   122
    a = QtGui.QApplication(sys.argv)
oliver@187
   123
    d = LaunchDialog(['SecurityDVM0', 'SecurityDVM1'], ['/usr/bin/xterm', '/usr/bin/xclock', '/usr/bin/xeyes'])
oliver@113
   124
    d.show()
oliver@113
   125
    sys.exit(a.exec_())     
oliver@102
   126