highlighting error status messages with an icon

This commit is contained in:
sezanzeb 2020-12-27 13:27:49 +01:00
parent 56b89451ee
commit 7a740cb58d
3 changed files with 37 additions and 10 deletions

View File

@ -66,7 +66,7 @@
<property name="yalign">0</property>
<property name="xpad">12</property>
<property name="ypad">12</property>
<property name="icon-name">cancel</property>
<property name="icon-name">dialog-error</property>
<property name="icon_size">6</property>
</object>
<packing>
@ -202,7 +202,7 @@
<property name="yalign">0</property>
<property name="xpad">12</property>
<property name="ypad">12</property>
<property name="icon-name">cancel</property>
<property name="icon-name">dialog-error</property>
<property name="icon_size">6</property>
</object>
<packing>
@ -756,18 +756,27 @@
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkImage" id="error_status_icon">
<property name="can-focus">False</property>
<property name="margin-start">10</property>
<property name="icon-name">dialog-error</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkStatusbar" id="status_bar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">10</property>
<property name="margin-right">10</property>
<property name="margin-start">10</property>
<property name="margin-end">10</property>
<property name="margin-start">7</property>
<property name="margin-end">7</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<style>
<class name="status_bar"/>
</style>
@ -775,7 +784,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
@ -786,7 +795,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
<child>
@ -801,7 +810,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">3</property>
</packing>
</child>
</object>

View File

@ -343,6 +343,11 @@ class Window:
if tooltip is None:
tooltip = message
if context_id == CTX_ERROR:
self.get('error_status_icon').show()
else:
self.get('error_status_icon').hide()
status_bar = self.get('status_bar')
status_bar.push(context_id, message)
status_bar.set_tooltip_text(tooltip)

View File

@ -496,19 +496,28 @@ class TestIntegration(unittest.TestCase):
self.assertTrue(os.path.exists(f'{CONFIG_PATH}/presets/device 1/asdf.json'))
self.assertEqual(custom_mapping.get_character((EV_KEY, 14, 1)), 'b')
error_icon = self.window.get('error_status_icon')
status = self.window.get('status_bar')
tooltip = status.get_tooltip_text().lower()
self.assertIn('saved', tooltip)
self.assertFalse(error_icon.get_visible())
def test_check_macro_syntax(self):
status = self.window.get('status_bar')
error_icon = self.window.get('error_status_icon')
custom_mapping.change((EV_KEY, 9, 1), 'k(1))', None)
self.window.on_save_preset_clicked(None)
tooltip = status.get_tooltip_text().lower()
self.assertIn('brackets', tooltip)
self.assertTrue(error_icon.get_visible())
custom_mapping.change((EV_KEY, 9, 1), 'k(1)', None)
self.window.on_save_preset_clicked(None)
tooltip = status.get_tooltip_text().lower()
self.assertNotIn('brackets', tooltip)
self.assertIn('saved', tooltip)
self.assertFalse(error_icon.get_visible())
self.assertEqual(custom_mapping.get_character((EV_KEY, 9, 1)), 'k(1)')
@ -694,6 +703,7 @@ class TestPermissions(unittest.TestCase):
self.window = launch()
status = self.window.get('status_bar')
error_icon = self.window.get('error_status_icon')
tooltip = status.get_tooltip_text()
self.assertIn('sudo', tooltip)
@ -701,6 +711,7 @@ class TestPermissions(unittest.TestCase):
self.assertIn('error1', tooltip)
self.assertIn('error2', tooltip)
self.assertIn('error3', tooltip)
self.assertTrue(error_icon.get_visible())
def test_good(self):
def fake():
@ -710,8 +721,10 @@ class TestPermissions(unittest.TestCase):
self.window = launch()
status = self.window.get('status_bar')
error_icon = self.window.get('error_status_icon')
self.assertIsNone(status.get_tooltip_text())
self.assertFalse(error_icon.get_visible())
if __name__ == "__main__":