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

Made changes to fix flake warnings

and a few other
parent 035dc23c
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ Bugfixes
- For the elliptical shell of integrated peaks, the background is correct when plotting with varying background thicknesses
- Fixed a bug which occurred when switching to a log scale in sliceviewer with negative data.
- Fixed a bug that use wrong help links in certain interfaces
- Fixed a bug that would not let the user input the bounding box of a shape in the instrument viewer.
- If the facility in Mantid.user.properties is empty, it is consistently reflected as empty in the GUI
- First time dialog box will not appear recurrently, if user selected their choice of facility
and instrument at least once and checked "Do not show again until next version"
......
......@@ -10,10 +10,11 @@
from psutil import virtual_memory
conversion_factor_to_GB = 1.0 / (1024 * 1024 * 1024)
def get_memory_info():
mem_used = virtual_memory().used
mem_used = virtual_memory().used
mem_total = virtual_memory().total
mem_used_percent = min(int(round(mem_used * 100 / mem_total)),100)
mem_used_percent = min(int(round(mem_used * 100 / mem_total)), 100)
mem_used_GB = mem_used * conversion_factor_to_GB
mem_total_GB = mem_total * conversion_factor_to_GB
return mem_used_percent, mem_used_GB, mem_total_GB
......@@ -6,20 +6,20 @@ from ..memorywidget.memoryinfo import get_memory_info
class MemoryPresenter(object):
def __init__(self, view):
self.view = view
self.timer = QTimer()
self.update_memory_usage()
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):
if current_value >= 90:
self.view.set_bar_color(0, current_value)
elif (current_value < 90):
elif current_value < 90:
self.view.set_bar_color(100, current_value)
else:
pass
......
......@@ -21,11 +21,13 @@ QProgressBar::chunk {
}
"""
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, current_value, new_value)->bool:
return (current_value >= critical and new_value < critical)
def from_normal_to_critical(critical, current_value, new_value) -> bool:
return current_value < critical <= new_value
def from_critical_to_normal(critical, current_value, new_value) -> bool:
return current_value >= critical > new_value
class MemoryView(QWidget):
......@@ -36,9 +38,9 @@ class MemoryView(QWidget):
self.memory_bar = QProgressBar(self)
def set_bar_color(self, current_value, new_value):
if (from_normal_to_critical(self.critical, 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, current_value, new_value)):
elif from_critical_to_normal(self.critical, current_value, new_value):
self.memory_bar.setStyleSheet(NORMAL_STYLE)
else:
pass
......@@ -49,6 +51,6 @@ class MemoryView(QWidget):
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"%new_value+"%" +")"
display_str = "%3.1f" % mem_used + "/" + "%3.1f" % mem_avail + " GB " \
+ "(" + "%d" % new_value + "%" + ")"
self.memory_bar.setFormat(display_str)
......@@ -20,7 +20,7 @@ class MemoryWidget(PluginWidget):
self.view = view if view else MemoryView(self)
self.presenter = MemoryPresenter(self.view)
layout = QVBoxLayout()
layout.addWidget(self.view.memory_bar)
......@@ -28,7 +28,7 @@ class MemoryWidget(PluginWidget):
self.setWindowTitle(self.get_plugin_title())
# 70 is chosen as a good value after testing
# how it looks for different values
self.setMaximumHeight(70)
self.setMaximumHeight(70)
# ----------------- Plugin API --------------------
......@@ -42,4 +42,4 @@ class MemoryWidget(PluginWidget):
pass
def register_plugin(self, menu=None):
self.main.add_dockwidget(self)
\ No newline at end of file
self.main.add_dockwidget(self)
......@@ -18,5 +18,6 @@ class MemoryInfoTest(unittest.TestCase):
self.assertTrue(isinstance(mem_used_percent, int))
self.assertTrue(0 <= mem_used_percent <= 100)
if __name__ == "__main__":
unittest.main()
......@@ -31,7 +31,7 @@ class MemoryPresenterTest(unittest.TestCase):
def test_presenter(self):
self.assertTrue(from_normal_to_critical(self.presenter.view.critical,
75, 95))
self.assertFalse(from_critical_to_normal(self.presenter.view.critical,
self.assertFalse(from_critical_to_normal(self.presenter.view.critical,
75, 95))
self.assertFalse(from_normal_to_critical(self.presenter.view.critical,
......
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