Merge remote-tracking branch 'origin/pr/288'

* origin/pr/288:
  Add check before launch qvm_start()
  Fix main()
  Fix pylint warning
  Added parent to all __init__()
  Retored reject() connect
  Revert "Restored reject() call with ui"
  Restored reject() call with ui
  Close dialog after finish qvm_start()
  Fix pylint warning
  Fix 'Line too long'
  Added bootfromdevice dialog to create_new_vm (instead subprocess.call)
  Removed unneeded reject() definition
  Use vm.name instead vm object
  Removed unneded reject() definition
  Removed qvm_start call from bootfromdevice
  Improved window size and margins
This commit is contained in:
Marek Marczykowski-Górecki 2021-05-30 00:56:15 +02:00
commit 4420e52d0d
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
10 changed files with 85 additions and 55 deletions

View File

@ -30,8 +30,8 @@ from . import ui_about # pylint: disable=no-name-in-module
# pylint: disable=too-few-public-methods
class AboutDialog(ui_about.Ui_AboutDialog, QDialog):
def __init__(self):
super().__init__()
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
@ -40,15 +40,13 @@ class AboutDialog(ui_about.Ui_AboutDialog, QDialog):
self.release.setText(release_file.read())
self.ok.clicked.connect(self.accept)
self.releaseNotes.clicked.connect(on_release_notes_clicked)
self.informationNotes.clicked.connect(on_information_notes_clicked)
self.releaseNotes.clicked.connect(self.on_release_notes_clicked)
self.informationNotes.clicked.connect(self.on_information_notes_clicked)
def on_release_notes_clicked():
release_notes_dialog = ReleaseNotesDialog()
def on_release_notes_clicked(self):
release_notes_dialog = ReleaseNotesDialog(self)
release_notes_dialog.exec_()
def on_information_notes_clicked():
information_notes_dialog = InformationNotesDialog()
def on_information_notes_clicked(self):
information_notes_dialog = InformationNotesDialog(self)
information_notes_dialog.exec_()

View File

@ -23,22 +23,24 @@ from . import utils
from . import ui_bootfromdevice # pylint: disable=no-name-in-module
from PyQt5 import QtWidgets, QtGui # pylint: disable=import-error
from qubesadmin import tools
from qubesadmin.tools import qvm_start
from qubesadmin import exc
from qubesadmin.tools import qvm_start
class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog,
QtWidgets.QDialog):
def __init__(self, vm, qapp, qubesapp=None, parent=None):
def __init__(self, vm, qapp, qubesapp=None, parent=None, new_vm=False):
super().__init__(parent)
self.vm = vm
self.qapp = qapp
self.qubesapp = qubesapp
self.cdrom_location = None
self.new_vm = new_vm
self.setupUi(self)
self.setWindowTitle(
self.tr("Boot {vm} from device").format(vm=self.vm.name))
self.tr("Boot {vm} from device").format(vm=self.vm))
self.buttonBox.accepted.connect(self.save_and_apply)
self.buttonBox.rejected.connect(self.reject)
@ -52,14 +54,11 @@ class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog,
self.qapp.setApplicationName(self.tr("Boot Qube From Device"))
self.qapp.setWindowIcon(QtGui.QIcon.fromTheme("qubes-manager"))
def reject(self):
self.done(0)
def save_and_apply(self):
if self.blockDeviceRadioButton.isChecked():
cdrom_location = self.blockDeviceComboBox.currentText()
self.cdrom_location = self.blockDeviceComboBox.currentText()
elif self.fileRadioButton.isChecked():
cdrom_location = str(self.fileVM.currentData()) + \
self.cdrom_location = str(self.fileVM.currentData()) + \
":" + self.pathText.text()
else:
QtWidgets.QMessageBox.warning(
@ -70,14 +69,14 @@ class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog,
# warn user if the VM is currently running
self.__warn_if_running__()
qvm_start.main(['--cdrom', cdrom_location, self.vm.name])
self.done(0)
self.accept()
def __warn_if_running__(self):
if self.new_vm:
return
try:
if self.vm.is_running():
if self.qubesapp.domains[self.vm].is_running():
QtWidgets.QMessageBox.warning(
self,
self.tr("Warning!"),
@ -107,7 +106,8 @@ class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog,
)
device_choice = []
for domain in self.vm.app.domains:
for domain in self.qubesapp.domains:
try:
for device in domain.devices["block"]:
device_choice.append((str(device), device))
@ -169,8 +169,9 @@ def main(args=None):
args = parser.parse_args(args)
vm = args.domains.pop()
utils.run_synchronous(functools.partial(VMBootFromDeviceWindow, vm))
window = utils.run_synchronous(functools.partial(VMBootFromDeviceWindow, vm))
if window.result() == 1 and window.cdrom_location is not None:
qvm_start.main(['--cdrom', window.cdrom_location, vm.name])
if __name__ == "__main__":
main()

View File

@ -32,6 +32,7 @@ import qubesadmin.tools
import qubesadmin.exc
from . import utils
from . import bootfromdevice
from .ui_newappvmdlg import Ui_NewVMDlg # pylint: disable=import-error
@ -102,6 +103,7 @@ class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg):
self.thread = None
self.progress = None
self.boot_dialog = None
utils.initialize_widget_with_labels(
widget=self.label,
@ -173,14 +175,16 @@ class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg):
self.launch_settings.stateChanged.connect(self.settings_change)
self.install_system.stateChanged.connect(self.install_change)
def reject(self):
self.done(0)
def accept(self):
vmclass = self.vm_type.currentData()
name = str(self.name.text())
if self.install_system.isChecked():
self.boot_dialog = bootfromdevice.VMBootFromDeviceWindow(
name, self.qtapp, self.app, self, True)
if not self.boot_dialog.exec_():
return
if name in self.app.domains:
QtWidgets.QMessageBox.warning(
self,
@ -229,23 +233,23 @@ class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg):
self.progress.show()
def create_finished(self):
self.progress.hide()
if self.thread.msg:
QtWidgets.QMessageBox.warning(
self,
self.tr("Error creating the qube!"),
self.tr("ERROR: {0}").format(self.thread.msg))
self.done(0)
if not self.thread.msg:
else:
if self.launch_settings.isChecked():
subprocess.check_call(['qubes-vm-settings',
str(self.name.text())])
if self.install_system.isChecked():
subprocess.check_call(
['qubes-vm-boot-from-device', str(self.name.text())])
qubesadmin.tools.qvm_start.main(
['--cdrom', self.boot_dialog.cdrom_location,
self.name.text()])
self.progress.hide()
self.done(0)
def type_change(self):
template = self.template_vm.currentData()

View File

@ -29,8 +29,8 @@ import subprocess
class InformationNotesDialog(ui_informationnotes.Ui_InformationNotesDialog,
QDialog):
# pylint: disable=too-few-public-methods
def __init__(self):
super().__init__()
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
details = subprocess.check_output(

View File

@ -1273,7 +1273,8 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
@pyqtSlot(name='on_action_createvm_triggered')
def action_createvm_triggered(self):
with common_threads.busy_cursor():
create_window = create_new_vm.NewVmDlg(self.qt_app, self.qubes_app)
create_window = create_new_vm.NewVmDlg(
self.qt_app, self.qubes_app, self)
create_window.exec_()
# noinspection PyArgumentList
@ -1519,8 +1520,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
try:
with common_threads.busy_cursor():
settings_window = settings.VMSettingsWindow(
vm, init_page=tab, qapp=self.qt_app,
qubesapp=self.qubes_app)
vm, tab, self.qt_app, self.qubes_app, self)
settings_window.show()
self.settings_windows[vm.name] = settings_window
except exc.QubesException as ex:
@ -1623,7 +1623,8 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
with common_threads.busy_cursor():
global_settings_window = global_settings.GlobalSettingsWindow(
self.qt_app,
self.qubes_app)
self.qubes_app,
self)
global_settings_window.show()
self.settings_windows['global_settings_window'] = global_settings_window
@ -1646,7 +1647,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
def action_restore_triggered(self):
with common_threads.busy_cursor():
restore_window = restore.RestoreVMsWindow(self.qt_app,
self.qubes_app)
self.qubes_app, self)
restore_window.exec_()
# noinspection PyArgumentList
@ -1696,7 +1697,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
# noinspection PyArgumentList
@pyqtSlot(name='on_action_about_qubes_triggered')
def action_about_qubes_triggered(self): # pylint: disable=no-self-use
about = AboutDialog()
about = AboutDialog(self)
about.exec_()
def createPopupMenu(self): # pylint: disable=invalid-name

View File

@ -27,8 +27,8 @@ from . import ui_releasenotes # pylint: disable=no-name-in-module
class ReleaseNotesDialog(ui_releasenotes.Ui_ReleaseNotesDialog, QDialog):
# pylint: disable=too-few-public-methods
def __init__(self):
super().__init__()
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)

View File

@ -30,8 +30,10 @@ import traceback
from qubesadmin.tools import QubesArgumentParser
from qubesadmin import devices
from qubesadmin import utils as admin_utils
from qubesadmin.tools import qvm_start
import qubesadmin.exc
from . import bootfromdevice
from . import utils
from . import multiselectwidget
from . import common_threads
@ -1023,8 +1025,12 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog):
self.check_mem_changes()
def boot_from_cdrom_button_pressed(self):
boot_dialog = bootfromdevice.VMBootFromDeviceWindow(
self.vm.name, self.qapp, self.qubesapp, self)
if boot_dialog.exec_():
self.save_and_apply()
subprocess.check_call(['qubes-vm-boot-from-device', self.vm.name])
qvm_start.main(
['--cdrom', boot_dialog.cdrom_location, self.vm.name])
def virt_mode_changed(self, new_idx): # pylint: disable=unused-argument
self.update_pv_warning()

View File

@ -35,7 +35,7 @@ class TemplateManagerWindow(
def __init__(self, qt_app, qubes_app, dispatcher, parent=None):
# pylint: disable=unused-argument
super().__init__()
super().__init__(parent)
self.setupUi(self)
self.qubes_app = qubes_app

View File

@ -564,3 +564,5 @@ def run_synchronous(window_class):
qt_app.exec_()
qt_app.exit()
return window

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<width>610</width>
<height>170</height>
</rect>
</property>
@ -27,16 +27,34 @@
<property name="title">
<string>Boot qube from device</string>
</property>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>30</y>
<width>581</width>
<height>72</height>
<height>74</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<property name="horizontalSpacing">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="blockDeviceRadioButton">
<property name="text">