-
Notifications
You must be signed in to change notification settings - Fork 1
/
rig_computers.py
110 lines (84 loc) · 3.27 KB
/
rig_computers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import datetime
import json
import os
import pathlib
import sys
import time
import numpy as np
import requests
try:
from PySide6 import QtCore, QtGui, QtWidgets
except ModuleNotFoundError:
from PyQt5 import QtCore, QtGui, QtWidgets
import pyqtgraph as pg
from pyqtgraph.console import ConsoleWidget
from pyqtgraph.dockarea.Dock import Dock
from pyqtgraph.dockarea.DockArea import DockArea
from pyqtgraph.Qt import QtWidgets
class RigComputerModel(QtGui.QStandardItemModel):
def __init__(self, parent=None, label=None, *args, **kwargs):
super().__init__(parent=parent, *args, **kwargs)
self.label = "rig details"
self.addRigs()
def launch_rdc(self, index):
item = self.itemFromIndex(index)
if 'stim' in item.comp.lower():
s = input("stim pc connection requested - may be displaying\ncontinue?\n>>")
if s.lower() != 'y':
print('cancelled')
return
os.system(f"mstsc /v:{item.hostname}")
def addRigs(self):
for comp, hostname in self.get_np_computers().items():
display_name = f"{comp} | {hostname}"
textual_item = QtGui.QStandardItem(display_name)
textual_item.hostname = hostname
textual_item.comp = comp
textual_item.setEditable = False
# Add the item to the model
self.appendRow(textual_item)
def get_np_computers(self, rigs=None, comp=None):
if rigs is None:
rigs = [0, 1, 2]
if not isinstance(rigs, list):
rigs = [int(rigs)]
if comp is None:
comp = ['sync', 'acq', 'mon', 'stim']
if not isinstance(comp, list):
comp = [str(comp)]
comp = [c.lower() for c in comp]
np_idx = ["NP." + str(idx) for idx in rigs]
all_pc = requests.get("http://mpe-computers/v2.0").json()
a = {}
for k, v in all_pc['comp_ids'].items():
if any([sub in k for sub in np_idx]) and any([s in k.lower() for s in comp]):
a[k] = v['hostname'].upper()
return a
class RigComputerView(QtWidgets.QTreeView):
def __init__(self, parent=None, label=None, *args, **kwargs):
super().__init__(parent=parent, *args, **kwargs)
self.label = "rig computer list display"
self.setMinimumSize(200, 200)
self.model = RigComputerModel()
# Apply the model to the list view
self.setModel(self.model) # todo move to controller
# this enables the view to do some optimizations:
# self.setUniformItemSizes(True)
self.expandAll()
self.doubleClicked.connect(self.model.launch_rdc)
# # todo move some of this to controller
# self.proxy = FileFilterProxyModel()
# self.setModel(self.proxy)
# self.source = self.proxy.sourceModel()
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None, label=None, *args, **kwargs):
super().__init__(parent=parent, *args, **kwargs)
self.title = "RDC launcher"
self.setCentralWidget(RigComputerView())
if __name__ == "__main__":
app = pg.mkQApp("docked widget GUI")
win = MainWindow()
# win.add_docked_widgets([]) # FolderTreeView()
# app.exec()
win.show()
sys.exit(pg.exec())