Skip to content
Snippets Groups Projects
dmStationUi.py 4.46 KiB
Newer Older
#!/usr/bin/env python

import sys
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
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)
        # Create a stacked layout to connect the various pages
        self.stackedLayout = QStackedLayout()
        self.stackedLayout.currentChanged.connect(self.currentChanged)
 
        # Create the tab windows
        self.initialTab = InitialTab(self.stationName, self)
        self.experimentsTab = ExperimentsTab(self.stationName, self)
        self.daqsTab = DaqsTab(self.stationName, self)
        self.uploadsTab = UploadsTab(self.stationName, self)
        self.addExperimentTab = AddExperimentTab(self.stationName, self)
        self.manageUsersTab = ManageUsersTab(self.stationName, self)
        # Add the windows to the stack.
        self.stackedLayout.addWidget(self.initialTab.initialTabWidget)
        self.stackedLayout.addWidget(self.experimentsTab.experimentsTabWidget)
        self.stackedLayout.addWidget(self.daqsTab.daqsTabWidget)
        self.stackedLayout.addWidget(self.uploadsTab.uploadsTabWidget)
        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)
        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.')

    # 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)

    def currentChanged(self, index):
        newIndex = index
            ManageUsersTab.updateUsers(self.manageUsersTab)

    def getTab(self):
        return self.stackedLayout.currentIndex()


if __name__ == "__main__":
        app = QApplication(sys.argv)
        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)