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

Added necessary files for memory widget

parent 39282bb9
No related branches found
No related tags found
No related merge requests found
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2021 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# This file is part of the mantidqt package
#
#
from psutil import virtual_memory
def getMemoryUsed():
memory_used = virtual_memory().used
memory_available = virtual_memory().available
memory_free_percent = int(round(memory_used * 100 / memory_available))
return memory_free_percent
from qtpy.QtCore import QTimer
from random import random
from workbench.plugins.memoryinfo import getMemoryUsed
class MemoryPresenter(object):
def __init__(self, view):
self.view = view
self.updateMemoryUsage()
self.view.updateSignal.connect(self.updateMemoryUsage)
self.timer = QTimer()
self.timer.timeout.connect(self.view.onUpdateRequest)
self.timer.start(10)
def updateMemoryUsage(self):
memory_used = getMemoryUsed()
#memory_used = int(random() * 100)
self.view.setValue(memory_used)
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2017 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# This file is part of the mantid workbench.
#
#
from qtpy.QtWidgets import QWidget, QProgressBar
from qtpy.QtCore import Signal
from mantidqt.utils.qt import load_ui
NORMAL_STYLE = """
QProgressBar::chunk {
background-color: lightgreen;
}
"""
CRITICAL_STYLE = """
QProgressBar::chunk {
background-color: red;
}
"""
def fromNormalToCritical(critical, currentValue, newValue)->bool:
return (currentValue < critical and newValue >= critical)
def fromCriticalToNormal(critical, currentValue, newValue)->bool:
return (currentValue >= critical and newValue < critical)
class MemoryView(QWidget):
updateSignal = Signal()
def __init__(self, parent):
super(MemoryView, self).__init__(parent)
self.critical = 90
# For the future use, if needed
#self.ui = load_ui(__file__, 'memorybar.ui', baseinstance=self)
self.memory_bar = QProgressBar()
def setBarColor(self, currentValue, newValue):
if (fromNormalToCritical(self.critical, currentValue, newValue)):
self.memory_bar.setStyleSheet(CRITICAL_STYLE)
elif (fromCriticalToNormal(self.critical, currentValue, newValue)):
self.memory_bar.setStyleSheet(NORMAL_STYLE)
else:
pass
def setValue(self, newValue):
currentValue = self.memory_bar.value()
if currentValue != newValue:
self.setBarColor(currentValue, newValue)
self.memory_bar.setValue(newValue)
def onUpdateRequest(self):
self.updateSignal.emit()
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright &copy; 2017 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# This file is part of the mantid workbench.
#
#
from qtpy.QtWidgets import QVBoxLayout
from workbench.plugins.base import PluginWidget
from workbench.plugins.memoryview import MemoryView
from workbench.plugins.memorypresenter import MemoryPresenter
class MemoryWidget(PluginWidget):
def __init__(self, parent, view=None):
super(MemoryWidget, self).__init__(parent)
view = MemoryView(self)
self.presenter = MemoryPresenter(view)
self.view = view if view else MemoryView(self)
layout = QVBoxLayout()
layout.addWidget(view.memory_bar)
self.setLayout(layout)
self.setWindowTitle(self.get_plugin_title())
# ----------------- Plugin API --------------------
def get_plugin_title(self):
return "Memory"
def readSettings(self, _):
pass
def writeSettings(self, _):
pass
def register_plugin(self, menu=None):
self.main.add_dockwidget(self)
\ No newline at end of file
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