2 # -*- coding: utf-8 -*-
4 # ------------------------------------------------------------
7 # let the user launch an app in a vm
9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
11 # Copyright 2013-2014 X-Net and AIT Austrian Institute of Technology
18 # https://www.x-net.at
20 # AIT Austrian Institute of Technology
21 # Donau City Strasse 1
24 # http://www.ait.ac.at
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
31 # http://www.apache.org/licenses/LICENSE-2.0
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 # ------------------------------------------------------------
41 # ------------------------------------------------------------
46 from PyQt4 import QtCore
47 from PyQt4 import QtGui
49 from ui_LaunchDialog import Ui_LaunchDialog
50 from about_dialog import AboutDialog
53 # ------------------------------------------------------------
57 class LaunchDialog(QtGui.QDialog):
59 """A dialog for letting the user launch an arbitrary app in a vm"""
61 def __init__(self, vms, apps):
63 QtGui.QDialog.__init__(self)
65 # setup the user interface
66 self.ui = Ui_LaunchDialog()
69 self.ui.cmbVM.addItem(v)
71 self.ui.cmbApplication.addItem(a)
74 self._about_dialog = AboutDialog()
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)
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)
87 def clicked_about(self):
89 """About button has been clicked."""
90 self._about_dialog.show()
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')
110 """The application of the user."""
111 return str(self.ui.cmbApplication.currentText())
117 """The application of the user."""
118 return str(self.ui.cmbVM.currentText())
121 if __name__ == "__main__":
122 a = QtGui.QApplication(sys.argv)
123 d = LaunchDialog(['SecurityDVM0', 'SecurityDVM1'], ['/usr/bin/xterm', '/usr/bin/xclock', '/usr/bin/xeyes'])