import os from PyQt4 import QtGui, QtCore, uic from labels import cm base_dir = os.path.dirname(os.path.realpath(__file__)) class GroupingWindow(QtGui.QWidget): def __init__(self, main_window, parent=None): QtGui.QWidget.__init__(self, parent) uic.loadUi("%s/ui/grouping.ui" % base_dir, self) self.main_window = main_window self.units = self.main_window.units self.addAttribute = lambda dev, attr: self.main_window.addAttribute(dev, attr) self.list_layout = QtGui.QVBoxLayout() self.ContentFrame.setLayout(self.list_layout) self.liberas = {} def addLibera(self, dev): print "[ INFO]: grouping: add Libera %s" % dev libera = GroupingWidget(self.main_window, dev) self.connect(self, QtCore.SIGNAL("update"), libera.update) self.liberas[dev] = libera self.list_layout.addWidget(libera) def addGlobal(self, orbit, magnet): print "[ INFO]: grouping: global: orbit %s; magnet %s" % (orbit, magnet) w = GlobalWidget(self.main_window, orbit, magnet) self.connect(self, QtCore.SIGNAL("update"), w.update) self.list_layout.addWidget(w) def update(self, cache): self.emit(QtCore.SIGNAL("update"), cache) def showEvent(self, evt): self.emit(QtCore.SIGNAL("show")) evt.accept() def hideEvent(self, evt): self.emit(QtCore.SIGNAL("hide")) evt.accept() class GroupingWidget(QtGui.QWidget): def __init__(self, main_window, device, parent=None): QtGui.QWidget.__init__(self, parent) uic.loadUi("%s/ui/groupingwidget.ui" % base_dir, self) self.main_window = main_window self.units = self.main_window.units self.addAttribute = lambda dev, attr: self.main_window.addAttribute(dev, attr) self.device = device self.IDLabel.setText(device) self.SFP3StatusLabel.setModel(device, "GdxSFP3Status") self.SFP4StatusLabel.setModel(device, "GdxSFP4Status") def update(self, cache): self.emit(QtCore.SIGNAL("update"), cache) class GlobalWidget(QtGui.QWidget): def __init__(self, main_window, orbit, magnet, parent=None): QtGui.QWidget.__init__(self, parent) uic.loadUi("%s/ui/globalwidget.ui" % base_dir, self) self.main_window = main_window self.units = self.main_window.units self.addAttribute = lambda dev, attr: self.main_window.addAttribute(dev, attr) self.orbit = orbit self.magnet = magnet self.GlobalOrbitIDLabel.setText(orbit) self.GlobalOrbitStateLabel.setModel(orbit, "GdxOrbitStatus") self.GlobalOrbitStateLabel.setColorMap(cm.GREEN_BOOL) self.GlobalMagnetIDLabel.setText(magnet) self.GlobalMagnetStateLabel.setModel(orbit, "GdxMagnetStatus") self.GlobalMagnetStateLabel.setColorMap(cm.GREEN_BOOL) def update(self, cache): self.emit(QtCore.SIGNAL("update"), cache)