From 1b9737c1a7815e3d32394a5d5684325ede7f9f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Fri, 19 Jan 2018 01:14:05 +0100 Subject: [PATCH] Fixed according to @marmarek request --- qubesmanager/settings.py | 9 ++++----- qubesmanager/utils.py | 23 ++++++++++++++--------- rpm_spec/qmgr.spec | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/qubesmanager/settings.py b/qubesmanager/settings.py index 5abeec7..0ac5985 100755 --- a/qubesmanager/settings.py +++ b/qubesmanager/settings.py @@ -300,7 +300,9 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog): self.vm, 'template', self.vm.app.default_template, (lambda vm: vm.klass == 'TemplateVM'), - allow_default=True, allow_none=False) + allow_default=False, allow_none=False, + transform=(lambda x: x if x != self.vm.app.default_template + else x + self.tr(' (default)'))) else: self.template_name.setEnabled(False) self.template_idx = -1 @@ -627,8 +629,6 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog): try: if self.virt_mode.currentIndex() != self.virt_mode_idx: self.vm.virt_mode = self.selected_virt_mode().lower() - # pylint: disable=attribute-defined-outside-init - self.anything_changed = True except Exception as ex: # pylint: disable=broad-except msg.append(str(ex)) @@ -674,10 +674,9 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog): self.virt_mode.clear() - # XXX: Hardcoded default value. # pylint: disable=attribute-defined-outside-init self.virt_mode_list, self.virt_mode_idx = utils.prepare_choice( - self.virt_mode, self.vm, 'virt_mode', choices, 'HVM', + self.virt_mode, self.vm, 'virt_mode', choices, None, allow_default=True, transform=(lambda x: str(x).upper())) if old_mode is not None: diff --git a/qubesmanager/utils.py b/qubesmanager/utils.py index 4457844..45de190 100644 --- a/qubesmanager/utils.py +++ b/qubesmanager/utils.py @@ -49,17 +49,19 @@ def prepare_choice(widget, holder, propname, choice, default, 'allow_default={allow_default!r}, ' 'allow_none={allow_none!r})'.format(**locals())) + if propname is not None and allow_default: + default = holder.property_get_default(propname) + if allow_internal is None: allow_internal = propname is None or not propname.endswith('vm') if propname is not None: - oldvalue = getattr(holder, propname) - if transform is not None: - oldvalue = transform(oldvalue) - is_default = holder.property_is_default(propname) + if holder.property_is_default(propname): + oldvalue = qubesadmin.DEFAULT + else: + oldvalue = getattr(holder, propname) else: oldvalue = object() # won't match for identity - is_default = False idx = 0 choice_list = list(choice)[:] @@ -78,17 +80,20 @@ def prepare_choice(widget, holder, propname, choice, default, debug('i={} item={}'.format(i, item)) # 0: default (unset) if item is qubesadmin.DEFAULT: - text = 'default ({})'.format( - str(default) if default is not None else 'none') + default_string = str(default) if default is not None else 'none' + if transform is not None: + default_string = transform(default_string) + text = 'default ({})'.format(default_string) # N+1: explicit None elif item is None: text = '(none)' # 1..N: choices else: text = str(item) + if transform is not None: + text = transform(text) - if item is qubesadmin.DEFAULT and is_default \ - or item is not qubesadmin.DEFAULT and item == oldvalue: + if item == oldvalue: text += ' (current)' idx = i diff --git a/rpm_spec/qmgr.spec b/rpm_spec/qmgr.spec index 877caaa..f41b8cf 100644 --- a/rpm_spec/qmgr.spec +++ b/rpm_spec/qmgr.spec @@ -12,7 +12,7 @@ URL: http://fixme Requires: python3 Requires: python3-PyQt4 Requires: python3-inotify -Requires: python3-qubesadmin >= 4.0.7 +Requires: python3-qubesadmin >= 4.0.13 Requires: qubes-artwork Requires: pmount Requires: cryptsetup