Changed display of image sizes in VM settings to GB when sensible
For sizes above 1 GB, the sizes of private image and root image will be displayed as %.1f GB; smaller sizes will be displayed as %d MB. fixes QubesOS/qubes-issues#5592
This commit is contained in:
parent
8902727e0f
commit
bd8fc05725
@ -30,8 +30,7 @@ import sys
|
||||
import quamash
|
||||
from qubesadmin import events
|
||||
|
||||
from PyQt5 import QtWidgets, QtCore # pylint: disable=import-error
|
||||
from PyQt5.QtGui import QIcon # pylint: disable=import-error
|
||||
from PyQt5 import QtWidgets, QtCore, QtGui # pylint: disable=import-error
|
||||
|
||||
|
||||
def _filter_internal(vm):
|
||||
@ -39,6 +38,36 @@ def _filter_internal(vm):
|
||||
and not vm.features.get('internal', False))
|
||||
|
||||
|
||||
class SizeSpinBox(QtWidgets.QSpinBox):
|
||||
# pylint: disable=invalid-name, no-self-use
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SizeSpinBox, self).__init__(*args, **kwargs)
|
||||
|
||||
self.pattern = r'(\d+\.?\d?) ?(GB|MB)'
|
||||
self.regex = re.compile(self.pattern)
|
||||
self.validator = QtGui.QRegExpValidator(QtCore.QRegExp(
|
||||
self.pattern), self)
|
||||
|
||||
def textFromValue(self, v: int) -> str:
|
||||
if v > 1024:
|
||||
return '{:.1f} GB'.format(v / 1024)
|
||||
|
||||
return '{} MB'.format(v)
|
||||
|
||||
def validate(self, text: str, pos: int):
|
||||
return self.validator.validate(text, pos)
|
||||
|
||||
def valueFromText(self, text: str) -> int:
|
||||
value, unit = self.regex.fullmatch(text.strip()).groups()
|
||||
|
||||
if unit == 'GB':
|
||||
multiplier = 1024
|
||||
else:
|
||||
multiplier = 1
|
||||
|
||||
return int(float(value) * multiplier)
|
||||
|
||||
|
||||
def prepare_choice(widget, holder, propname, choice, default,
|
||||
filter_function=None, *,
|
||||
icon_getter=None, allow_internal=None, allow_default=False,
|
||||
@ -171,7 +200,7 @@ def prepare_label_choice(widget, holder, propname, default, *args, **kwargs):
|
||||
sorted(app.labels.values(), key=lambda l: l.index),
|
||||
default, *args,
|
||||
icon_getter=(lambda label:
|
||||
QIcon.fromTheme(label.icon)),
|
||||
QtGui.QIcon.fromTheme(label.icon)),
|
||||
**kwargs)
|
||||
|
||||
|
||||
|
@ -110,16 +110,16 @@
|
||||
<number>15</number>
|
||||
</property>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="root_resize">
|
||||
<widget class="SizeSpinBox" name="root_resize">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Values displayed using the binary definition of gigabyte and megabyte, i.e. 1024<span style=" vertical-align:super;">3</span> and 1024<span style=" vertical-align:super;">2 </span>bytes respectively.</p></body></html></string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string>MiB</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1048576</number>
|
||||
</property>
|
||||
@ -129,16 +129,16 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="max_priv_storage">
|
||||
<widget class="SizeSpinBox" name="max_priv_storage">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Values displayed using the binary definition of gigabyte and megabyte, i.e. 1024<span style=" vertical-align:super;">3</span> and 1024<span style=" vertical-align:super;">2 </span>bytes respectively.</p></body></html></string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string>MiB</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@ -1556,6 +1556,13 @@ The qube must be running to disable seamless mode; this setting is not persisten
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>SizeSpinBox</class>
|
||||
<extends>QSpinBox</extends>
|
||||
<header>qubesmanager/utils.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>tabWidget</tabstop>
|
||||
<tabstop>vmname</tabstop>
|
||||
|
Loading…
Reference in New Issue
Block a user