29 from __future__
import division
32 from python_qt_binding
import loadUi
33 from python_qt_binding.QtWidgets
import QLabel, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QCheckBox, QWidget, QToolBar, QLineEdit, QPushButton
34 from python_qt_binding.QtCore
import Qt, QTimer
38 from threading
import RLock
45 super(TopWidgetItem, self).
__init__(parent)
48 col = self.treeWidget().sortColumn()
49 dtype = Top.SORT_TYPE[col]
50 return dtype(self.text(col)) < dtype(other.text(col))
54 NODE_FIELDS = [
'pid',
'get_cpu_percent',
'get_memory_percent',
'get_num_threads']
55 OUT_FIELDS = [
'node_name',
'pid',
'cpu_percent',
'memory_percent',
'num_threads' ]
56 FORMAT_STRS = [
'%s',
'%s',
'%0.2f',
'%0.2f',
'%s' ]
57 NODE_LABELS = [
'Node',
'PID',
'CPU %',
'Mem %',
'Num Threads' ]
58 SORT_TYPE = [str, str, float, float, float ]
60 0: (
'cmdline',
lambda x:
'\n'.join(textwrap.wrap(
' '.join(x)))),
61 3: (
'memory_info',
lambda x: (
'Resident: %0.2f MiB, Virtual: %0.2f MiB' % (x[0] / 2**20, x[1] / 2**20)))
66 name_filter = re.compile(
'')
71 self.setObjectName(
'Top')
74 from argparse
import ArgumentParser
75 parser = ArgumentParser()
77 parser.add_argument(
"-q",
"--quiet", action=
"store_true",
79 help=
"Put plugin in silent mode")
80 args, unknowns = parser.parse_known_args(context.argv())
92 self._regex_box.setText(
'regex')
93 self._toolbar.addWidget(QLabel(
'Filter'))
102 self._container.setWindowTitle(
'Process Monitor')
104 self._container.setLayout(self.
_layout)
106 self._layout.addWidget(self.
_toolbar)
110 self._table_widget.setObjectName(
'TopTable')
111 self._table_widget.setColumnCount(len(self.
NODE_LABELS))
112 self._table_widget.setHeaderLabels(self.
NODE_LABELS)
114 self._table_widget.setSortingEnabled(
True)
115 self._table_widget.setAlternatingRowColors(
True)
123 self._kill_button.clicked.connect(self.
_kill_node)
129 self._table_widget.resizeColumnToContents(0)
133 self._update_timer.setInterval(1000)
135 self._update_timer.start()
142 if self._regex_box.isChecked():
143 expr = self._filter_box.text()
145 expr = re.escape(self._filter_box.text())
157 self._table_widget.insertTopLevelItem(row, twi)
159 for col, (key, func)
in self.TOOLTIPS.items():
160 twi.setToolTip(col, func(info[key]))
164 twi.setSelected(
True)
166 twi.setHidden(len(self.name_filter.findall(info[
'node_name'])) == 0)
169 self._table_widget.clear()
170 infos = self._node_info.get_all_node_fields(self.
NODE_FIELDS)
171 for nx, info
in enumerate(infos):
175 self._update_timer.stop()
178 instance_settings.set_value(
'filter_text', self._filter_box.text())
179 instance_settings.set_value(
'is_regex', int(self._regex_box.checkState()))
182 self._filter_box.setText(instance_settings.value(
'filter_text'))
183 is_regex_int = instance_settings.value(
'is_regex')
185 self._regex_box.setCheckState(Qt.CheckState(is_regex_int))
187 self._regex_box.setCheckState(Qt.CheckState(0))
def __init__(self, context)
def _tableItemClicked(self, item, column)
def update_one_item(self, row, info)
def shutdown_plugin(self)
def save_settings(self, plugin_settings, instance_settings)
def restore_settings(self, plugin_settings, instance_settings)
def update_filter(self, args)