Skip to content
Snippets Groups Projects
Commit adf779ad authored by Srikanth Ravipati's avatar Srikanth Ravipati Committed by Peterson, Peter
Browse files

Made a few miscellaneous changes

parent 9b70f7c1
No related branches found
No related tags found
No related merge requests found
......@@ -7,10 +7,15 @@ class MemoryPresenter(object):
def __init__(self, view):
self.view = view
self.update_memory_usage()
# Initial bar color has to be set explicitly
# as the initial value of the progress bar is
# undefined
self.set_bar_color_at_start()
self.update_at_regular_intervals()
def update_at_regular_intervals(self):
self.timer = QTimer()
self.timer.timeout.connect(self.update_memory_usage)
self.timer.start(10)
def set_bar_color_at_start(self):
current_value = self.view.memory_bar.value()
if (current_value >= 90):
self.view.set_bar_color(0, current_value)
......@@ -19,10 +24,6 @@ class MemoryPresenter(object):
else:
pass
self.timer = QTimer()
self.timer.timeout.connect(self.update_memory_usage)
self.timer.start(10)
def update_memory_usage(self):
mem_used_percent, mem_used, mem_avail = get_memory_info()
self.view.set_value(mem_used_percent, mem_used, mem_avail)
......@@ -21,11 +21,11 @@ QProgressBar::chunk {
}
"""
def from_normal_to_critical(critical, currentValue, newValue)->bool:
return (currentValue < critical and newValue >= critical)
def from_normal_to_critical(critical, current_value, new_value)->bool:
return (current_value < critical and new_value >= critical)
def from_critical_to_normal(critical, currentValue, newValue)->bool:
return (currentValue >= critical and newValue < critical)
def from_critical_to_normal(critical, current_value, new_value)->bool:
return (current_value >= critical and new_value < critical)
class MemoryView(QWidget):
......@@ -35,20 +35,20 @@ class MemoryView(QWidget):
self.critical = 90
self.memory_bar = QProgressBar(self)
def set_bar_color(self, currentValue, newValue):
if (from_normal_to_critical(self.critical, currentValue, newValue)):
def set_bar_color(self, current_value, new_value):
if (from_normal_to_critical(self.critical, current_value, new_value)):
self.memory_bar.setStyleSheet(CRITICAL_STYLE)
elif (from_critical_to_normal(self.critical, currentValue, newValue)):
elif (from_critical_to_normal(self.critical, current_value, new_value)):
self.memory_bar.setStyleSheet(NORMAL_STYLE)
else:
pass
def set_value(self, newValue, mem_used, mem_avail):
def set_value(self, new_value, mem_used, mem_avail):
# newValue is the mem_used_percent(int)
currentValue = self.memory_bar.value()
if currentValue != newValue:
self.set_bar_color(currentValue, newValue)
self.memory_bar.setValue(newValue)
current_value = self.memory_bar.value()
if current_value != new_value:
self.set_bar_color(current_value, new_value)
self.memory_bar.setValue(new_value)
display_str = "%3.1f"%mem_used + "/" + "%3.1f"%mem_avail + " GB " + \
"(" + "%d"%newValue+"%" +")"
"(" + "%d"%new_value+"%" +")"
self.memory_bar.setFormat(display_str)
......@@ -18,14 +18,16 @@ from unittest import mock
class MemoryPresenterTest(unittest.TestCase):
def setUp(self):
self.view = mock.create_autospec(MemoryView)
self.mock_view_internals()
self.presenter = MemoryPresenter(self.view)
def mock_view_internals(self):
self.view.critical = 90
self.view.memory_bar = mock.Mock()
self.view.memory_bar.value.return_value = 0
self.view.set_bar_color = mock.Mock()
self.view.set_value = mock.Mock()
self.presenter = MemoryPresenter(self.view)
def test_presenter(self):
self.assertTrue(from_normal_to_critical(self.presenter.view.critical,
75, 95))
......@@ -38,6 +40,7 @@ class MemoryPresenterTest(unittest.TestCase):
95, 75))
self.assertEqual(self.presenter.view.set_value.call_count, 1)
self.assertEqual(self.presenter.view.set_bar_color.call_count, 1)
self.presenter.update_memory_usage()
self.assertEqual(self.presenter.view.set_value.call_count, 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment