Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/227'
Browse files Browse the repository at this point in the history
* origin/pr/227:
  Changed display of image sizes in VM settings to GB when sensible
  • Loading branch information
marmarek committed Feb 17, 2020
2 parents 0534ec6 + bd8fc05 commit 2520952
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
35 changes: 32 additions & 3 deletions qubesmanager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,44 @@
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):
return (not vm.klass == 'AdminVM'
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,
Expand Down Expand Up @@ -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)


Expand Down
23 changes: 15 additions & 8 deletions ui/settingsdlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Values displayed using the binary definition of gigabyte and megabyte, i.e. 1024&lt;span style=&quot; vertical-align:super;&quot;&gt;3&lt;/span&gt; and 1024&lt;span style=&quot; vertical-align:super;&quot;&gt;2 &lt;/span&gt;bytes respectively.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</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>
Expand All @@ -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>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Values displayed using the binary definition of gigabyte and megabyte, i.e. 1024&lt;span style=&quot; vertical-align:super;&quot;&gt;3&lt;/span&gt; and 1024&lt;span style=&quot; vertical-align:super;&quot;&gt;2 &lt;/span&gt;bytes respectively.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 2520952

Please sign in to comment.