label: add index and icon
This commit is contained in:
parent
785706af2f
commit
d0e8c0515e
@ -22,6 +22,7 @@
|
||||
|
||||
import qubesmgmt.exc
|
||||
|
||||
|
||||
class Label(object):
|
||||
'''Label definition for virtual machines
|
||||
|
||||
@ -35,6 +36,7 @@ class Label(object):
|
||||
self.app = app
|
||||
self._name = name
|
||||
self._color = None
|
||||
self._index = None
|
||||
|
||||
@property
|
||||
def color(self):
|
||||
@ -53,5 +55,23 @@ class Label(object):
|
||||
'''label's name like "red" or "green"'''
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
'''freedesktop icon name, suitable for use in
|
||||
:py:meth:`PyQt4.QtGui.QIcon.fromTheme`'''
|
||||
return 'appvm-' + self.name
|
||||
|
||||
@property
|
||||
def index(self):
|
||||
'''color specification as in HTML (``#abcdef``)'''
|
||||
if self._index is None:
|
||||
try:
|
||||
qubesd_response = self.app.qubesd_call(
|
||||
'dom0', 'mgmt.label.Index', self._name, None)
|
||||
except qubesmgmt.exc.QubesDaemonNoResponseError:
|
||||
raise AttributeError
|
||||
self._index = int(qubesd_response.decode())
|
||||
return self._index
|
||||
|
||||
def __str__(self):
|
||||
return self._name
|
||||
|
@ -51,3 +51,18 @@ class TC_00_Label(qubesmgmt.tests.QubesTestCase):
|
||||
label = self.app.labels['green']
|
||||
self.assertEqual(label.color, '0x00FF00')
|
||||
|
||||
def test_012_get_index(self):
|
||||
self.app.expected_calls[
|
||||
('dom0', 'mgmt.label.List', None, None)] = \
|
||||
b'0\x00green\nred\nblack\n'
|
||||
self.app.expected_calls[
|
||||
('dom0', 'mgmt.label.Index', 'green', None)] = b'0\x003'
|
||||
label = self.app.labels['green']
|
||||
self.assertEqual(label.index, 3)
|
||||
|
||||
def test_024_get_icon(self):
|
||||
self.app.expected_calls[
|
||||
('dom0', 'mgmt.label.List', None, None)] = \
|
||||
b'0\x00green\nred\nblack\n'
|
||||
label = self.app.labels['green']
|
||||
self.assertEqual(label.icon, 'appvm-green')
|
||||
|
Loading…
Reference in New Issue
Block a user