Fixed according to @marmarek request

This commit is contained in:
Marta Marczykowska-Górecka 2018-01-19 01:14:05 +01:00
parent f1964f0c5b
commit 1b9737c1a7
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
3 changed files with 19 additions and 15 deletions

View File

@ -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:

View File

@ -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

View File

@ -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