Newer
Older
from PyQt4.QtCore import *
from PyQt4.QtGui import QMainWindow, QStackedLayout, QApplication, QWidget
from dm.common.constants import dmStatus
from dm.common.exceptions.dmException import DmException
from dm.common.exceptions.configurationError import ConfigurationError
from dm.common.utility.loggingManager import LoggingManager
from dm.common.utility.configurationManager import ConfigurationManager
from experimentsTab import ExperimentsTab
from daqsTab import DaqsTab
from uploadsTab import UploadsTab
from initialTab import InitialTab
Collin A. Schmitz
committed
from addExperiment import AddExperimentTab
from manageUsersTab import ManageUsersTab
class DmStationUi(QMainWindow):
def __init__(self):
self.__configure()
self.logger.debug('Starting UI for DM Station: %s' % self.stationName)
super(DmStationUi, self).__init__()
self.setWindowTitle('DM Station: %s' % self.stationName)
self.setGeometry(0, 0, 800, 400)
# Variable to hold the user instances
self.currentUsers = []
# Create a stacked layout to connect the various pages
self.stackedLayout = QStackedLayout()
Collin A. Schmitz
committed
self.stackedLayout.currentChanged.connect(self.currentChanged)
Collin A. Schmitz
committed
self.initialTab = InitialTab(self.stationName, self)
self.experimentsTab = ExperimentsTab(self.stationName, self)
self.daqsTab = DaqsTab(self.stationName, self)
self.uploadsTab = UploadsTab(self.stationName, self)
Collin A. Schmitz
committed
self.addExperimentTab = AddExperimentTab(self.stationName, self)
self.manageUsersTab = ManageUsersTab(self.stationName, self)
# Add the windows to the stack.
Collin A. Schmitz
committed
self.stackedLayout.addWidget(self.initialTab.initialTabWidget)
self.stackedLayout.addWidget(self.experimentsTab.experimentsTabWidget)
self.stackedLayout.addWidget(self.daqsTab.daqsTabWidget)
self.stackedLayout.addWidget(self.uploadsTab.uploadsTabWidget)
Collin A. Schmitz
committed
self.stackedLayout.addWidget(self.addExperimentTab.addExperimentTabWidget)
self.stackedLayout.addWidget(self.manageUsersTab.manageUsersTabWidget)
# Set a central widget to hold everything
self.centralWidget = QWidget()
self.centralWidget.setLayout(self.stackedLayout)
self.setCentralWidget(self.centralWidget)
Collin A. Schmitz
committed
self.stackedLayout.setCurrentIndex(0)
self.center()
self.show()
def __configure(self):
self.logger = LoggingManager.getInstance().getLogger(self.__class__.__name__)
configManager = ConfigurationManager.getInstance()
self.stationName = configManager.getInstance().getStationName()
if not self.stationName:
raise ConfigurationError('DM_STATION_NAME environment variable is not defined.')
Collin A. Schmitz
committed
# Centers window on the screen where the mouse is detected
def center(self):
frameGeo = self.frameGeometry()
screen = QApplication.desktop().screenNumber(QApplication.desktop().cursor().pos())
screenCenter = QApplication.desktop().screenGeometry(screen).center()
frameGeo.moveCenter(screenCenter)
self.move(frameGeo.topLeft())
# Calls for the table to be resized when a resize event is called
#def resizeEvent(self, event):
# windowSize = event.size().width()
# currentIndex = self.getTab()
# if currentIndex == 0:
# return
# elif currentIndex == 1:
# ExperimentsTab.resizeTable(self.experimentsTab, windowSize)
# elif currentIndex == 2:
# DaqsTab.resizeTable(self.daqsTab, windowSize)
# elif currentIndex == 3:
# UploadsTab.resizeTable(self.uploadsTab, windowSize)
# elif currentIndex == 4:
# AddExperimentTab.resizeTable(self.addExperimentTab, windowSize)
# elif currentIndex == 5:
# ManageUsersTab.resizeTable(self.manageUsersTab, windowSize)
Collin A. Schmitz
committed
def currentChanged(self, index):
newIndex = index
if newIndex == 5:
ManageUsersTab.updateUsers(self.manageUsersTab)
Collin A. Schmitz
committed
def getTab(self):
return self.stackedLayout.currentIndex()
Collin A. Schmitz
committed
#try:
app = QApplication(sys.argv)
Collin A. Schmitz
committed
window = DmStationUi()
window.show()
window.raise_()
sys.exit(app.exec_())
#except DmException, ex:
# print >>sys.stderr, 'ERROR: %s' % ex
# raise SystemExit(ex.getErrorCode())
#except Exception, ex:
# print >>sys.stderr, '%s' % ex
# raise SystemExit(dmStatus.DM_ERROR)