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