예제 #1
0
    def updateDashboard(self):
        if self.IsUpdating:
            return
        self.IsUpdating = True
        print("updateDashboard")
        jobs = DBManager.getCurrentJobs()
        for j in jobs:
            for c in self.cds:
                if c.Id == j.Id:
                    c.CurrentJobCode = j.JobCode
                    c.CurrentJobParameters = j.JobParameters
                    break
        results = DBManager.getAllClientStatistics()
        for r in results:
            for c in self.cds:
                if c.Id == r.Id:
                    c.ResultAverage = r.ResultAverage
                    c.ResultStddev = r.ResultStddev
                    break
        data = DBManager.getAllClients()
        for d in data:
            for c in self.cds:
                if c.Id == d.Id:
                    c.IP = d.IP
                    c.Material = d.Material
                    c.Position = d.Position
                    c.Latin = d.Latin
                    c.AllowUserMode = d.AllowUserMode
                    c.IsActive = d.IsActive
                    break
        for cdv in self.cdvs:
            cdv.lblCurrentJob.setText("{} {}".format(cdv.clientDetails.CurrentJobCode, cdv.clientDetails.CurrentJobParameters))
            cdv.lblResultAverage.setText("{:.2f}±{:.2f}".format(cdv.clientDetails.ResultAverage, cdv.clientDetails.ResultStddev))
            cdv.lblResultStddev.setText("+-{}".format(cdv.clientDetails.ResultStddev))
            if cdv.clientDetails.IsBadStatistics():
                cdv.lblResultAverage.setStyleSheet("QLabel { color: \"red\"; }")
                cdv.lblResultStddev.setStyleSheet("QLabel { color: \"red\"; }")
            else:
                cdv.lblResultAverage.setStyleSheet("")
                cdv.lblResultStddev.setStyleSheet("")

        threadPool = concurrent.futures.ThreadPoolExecutor(THREAD_POOL_SIZE)
        threadFutures = [threadPool.submit(self.checkOnlineAndServiceStatusForClient, cdv.clientDetails) for cdv in self.cdvs]
        concurrent.futures.wait(threadFutures)

        for cdv in self.cdvs:
            cdv.chkUserMode.setChecked(cdv.clientDetails.AllowUserMode)
            cdv.chkIsActivated.setChecked(cdv.clientDetails.IsActive)
            cdv.refreshClientServiceStatus()
            if cdv.clientDetails.IsOnline:
                cdv.lblIsOnline.setPixmap(TORIcons.LED_GREEN)
            else:
                cdv.lblIsOnline.setPixmap(TORIcons.LED_RED)
        self.lblLastUpdateTime.setText("last update: {}".format(datetime.now().strftime("%H:%M:%S")))
        print("updateDashboard finished")
        self.IsUpdating = False
예제 #2
0
    def __init__(self):
        super().__init__()

        self.IsBusy = False
        self.IsUpdating = False

        self.currentSelectedTabIndex = 0
        self.setWindowTitle("TOR")
        self.setWindowIcon(TORIcons.APP_ICON)

        self.cdvs = []
        self.cds = []
        clients = DBManager.getAllClients()
        layClientDetails = QHBoxLayout()
        layClientDetails.setContentsMargins(0, 0, 0, 0)
        grpClientDetailsRegions = [QGroupBox() for i in range(3)]
        for g in grpClientDetailsRegions:
            g.setObjectName("ClientGroup")
        grpClientDetailsRegions[0].setTitle("Front")
        grpClientDetailsRegions[1].setTitle("Middle")
        grpClientDetailsRegions[2].setTitle("Back")
        layClientDetailsRegions = [QGridLayout() for i in range(3)]
        for i in range(3):
            #layClientDetailsRegions[i].setContentsMargins(0, 0, 0, 0)
            #layClientDetailsRegions[i].setSpacing(0)
            grpClientDetailsRegions[i].setLayout(layClientDetailsRegions[i])
            #grpClientDetailsRegions[i].setContentsMargins(0, 0, 0, 0)
            for j in range(3):
                for k in range(3):
                    c = clients[i*9 + j*3 + k]
                    cdv = ClientDetailView()
                    cd = ClientDetails()
                    cd.Id = c.Id
                    cd.IP = c.IP
                    cd.Material = c.Material
                    cd.Position = c.Position
                    cd.Latin = c.Latin
                    cd.AllowUserMode = c.AllowUserMode
                    cd.IsActive = c.IsActive
                    cdv.clientDetails = cd
                    cdv.grpMainGroup.setTitle("#{}: {}...".format(cd.Position, cd.Latin[0:9]))
                    layClientDetailsRegions[i].addWidget(cdv, k, 3*i + j)
                    self.cdvs.append(cdv)
                    self.cds.append(cd)
            layClientDetails.addWidget(grpClientDetailsRegions[i])
        wdgClientDetails = QWidget()
        wdgClientDetails.setLayout(layClientDetails)


        self.btnStartAllTORPrograms = QPushButton()
        self.btnStartAllTORPrograms.setText("START installation")
        self.btnStartAllTORPrograms.clicked.connect(self.btnStartAllTORPrograms_clicked)
        self.btnStartAllTORPrograms.setStyleSheet("QPushButton { font-weight: bold }; ")

        self.btnStopAllTORPrograms = QPushButton()
        self.btnStopAllTORPrograms.setText("STOP installation")
        self.btnStopAllTORPrograms.clicked.connect(self.btnStopAllTORPrograms_clicked)
        self.btnStopAllTORPrograms.setStyleSheet("QPushButton { font-weight: bold }; ")

        self.btnStartAllClientService = QPushButton()
        self.btnStartAllClientService.setText("Start all active TORClients")
        self.btnStartAllClientService.clicked.connect(self.btnStartAllClientService_clicked)

        self.btnStopAllClientService = QPushButton()
        self.btnStopAllClientService.setText("Stop all TORClients")
        self.btnStopAllClientService.clicked.connect(self.btnStopAllClientService_clicked)

        self.btnSaveSettings = QPushButton()
        self.btnSaveSettings.setText("Save Settings")
        self.btnSaveSettings.clicked.connect(self.btnSaveSettings_clicked)

        self.btnRestoreSettings = QPushButton()
        self.btnRestoreSettings.setText("Restore Settings")
        self.btnRestoreSettings.clicked.connect(self.btnRestoreSettings_clicked)

        self.btnStartTORServer = QPushButton()
        self.btnStartTORServer.setText("Start TOR Server")
        self.btnStartTORServer.clicked.connect(self.btnStartTORServer_clicked)

        self.btnStopTORServer = QPushButton()
        self.btnStopTORServer.setText("Stop TOR Server")
        self.btnStopTORServer.clicked.connect(self.btnStopTORServer_clicked)

        self.btnStartTORInteractive = QPushButton()
        self.btnStartTORInteractive.setText("Start Visitor App")
        self.btnStartTORInteractive.clicked.connect(self.btnStartTORInteractive_clicked)

        self.btnStopTORInteractive = QPushButton()
        self.btnStopTORInteractive.setText("Stop Visitor App")
        self.btnStopTORInteractive.clicked.connect(self.btnStopTORInteractive_clicked)

        self.btnEndAllUserModes = QPushButton()
        self.btnEndAllUserModes.setText("End all visitor control")
        self.btnEndAllUserModes.clicked.connect(self.btnEndAllUserModes_clicked)

        self.btnTurnOnLEDs = QPushButton()
        self.btnTurnOnLEDs.setText("Turn ON all LEDs")
        self.btnTurnOnLEDs.clicked.connect(self.btnTurnOnLEDs_clicked)

        self.btnTurnOffLEDs = QPushButton()
        self.btnTurnOffLEDs.setText("Turn OFF all LEDs")
        self.btnTurnOffLEDs.clicked.connect(self.btnTurnOffLEDs_clicked)

        self.btnUpdateDashboard = QPushButton()
        self.btnUpdateDashboard.setText("Update dashboard")
        self.btnUpdateDashboard.clicked.connect(self.btnUpdateDashboard_clicked)

        self.lblLastUpdateTime = QLabel()

        spacerSize = 30
        layDashboardButtons = QVBoxLayout()
        layDashboardButtons.addSpacing(spacerSize)
        layDashboardButtons.addWidget(QLabel("<h3>Installation</h3>"))
        layDashboardButtons.addWidget(self.btnStartAllTORPrograms)
        layDashboardButtons.addWidget(self.btnStopAllTORPrograms)
        layDashboardButtons.addSpacing(spacerSize)
        layDashboardButtons.addWidget(QLabel("Clients"))
        layDashboardButtons.addWidget(self.btnStartAllClientService)
        layDashboardButtons.addWidget(self.btnStopAllClientService)
        layDashboardButtons.addSpacing(spacerSize)
        layDashboardButtons.addWidget(QLabel("LEDs"))
        layDashboardButtons.addWidget(self.btnTurnOnLEDs)
        layDashboardButtons.addWidget(self.btnTurnOffLEDs)
        layDashboardButtons.addSpacing(spacerSize)
        layDashboardButtons.addWidget(QLabel("Server"))
        layDashboardButtons.addWidget(self.btnStartTORServer)
        layDashboardButtons.addWidget(self.btnStopTORServer)
        layDashboardButtons.addSpacing(spacerSize)
        layDashboardButtons.addWidget(QLabel("Visitor App"))
        layDashboardButtons.addWidget(self.btnStartTORInteractive)
        layDashboardButtons.addWidget(self.btnStopTORInteractive)
        layDashboardButtons.addWidget(self.btnEndAllUserModes)
        layDashboardButtons.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding))
        layDashboardButtons.addWidget(self.btnUpdateDashboard)
        layDashboardButtons.addWidget(self.lblLastUpdateTime)


        wdgDashboardButtons = QWidget()
        wdgDashboardButtons.setLayout(layDashboardButtons)

        """
        layDashboardButtonsTop = QHBoxLayout()
        layDashboardButtonsTop.addWidget(self.btnStartAllClientService)
        layDashboardButtonsTop.addWidget(self.btnStopAllClientService)
        layDashboardButtonsTop.addWidget(self.btnSaveSettings)
        layDashboardButtonsTop.addWidget(self.btnRestoreSettings)
        wdgDashboardButtonsTop = QWidget()
        wdgDashboardButtonsTop.setLayout(layDashboardButtonsTop)

        layDashboardButtons2 = QHBoxLayout()
        layDashboardButtons2.addWidget(self.btnTurnOnLEDs)
        layDashboardButtons2.addWidget(self.btnTurnOffLEDs)
        wdgDashboardButtons2 = QWidget()
        wdgDashboardButtons2.setLayout(layDashboardButtons2)

        layDashboardButtonsBottom = QHBoxLayout()
        layDashboardButtonsBottom.addWidget(self.btnStartTORServer)
        layDashboardButtonsBottom.addWidget(self.btnStopTORServer)
        layDashboardButtonsBottom.addWidget(self.btnStartTORInteractive)
        layDashboardButtonsBottom.addWidget(self.btnStopTORInteractive)
        layDashboardButtonsBottom.addWidget(self.btnEndAllUserModes)
        wdgDashboardButtonsBottom = QWidget()
        wdgDashboardButtonsBottom.setLayout(layDashboardButtonsBottom)
        """

        layDashboard = QHBoxLayout()
        #layDashboard.addWidget(wdgDashboardButtonsTop)
        #layDashboard.addWidget(wdgDashboardButtons2)
        layDashboard.addWidget(wdgClientDetails)
        #layDashboard.addWidget(wdgDashboardButtonsBottom)
        layDashboard.addWidget(wdgDashboardButtons)

        wdgDashboard = QWidget()
        wdgDashboard.setLayout(layDashboard)


        programNames = DBManager.getAllJobProgramNames()
        self.jobProgramNames = [pn.Name for pn in programNames]
        self.cmbTour = QComboBox()
        self.cmbTour.insertItem(-1, NEW_PROGRAM_NAME)
        for i in range(len(self.jobProgramNames)):
            self.cmbTour.insertItem(i, self.jobProgramNames[i])
        self.cmbTour.currentIndexChanged.connect(self.cmbTour_currentIndexChanged)
        self.btnStartTour = QPushButton("Start")
        self.btnStartTour.clicked.connect(self.btnStartTour_clicked)
        self.btnEditTour = QPushButton("Edit")
        self.btnEditTour.clicked.connect(self.btnEditTour_clicked)

        layTourSelection = QHBoxLayout()
        layTourSelection.addWidget(QLabel("Program: "))
        layTourSelection.addWidget(self.cmbTour)
        layTourSelection.addSpacing(100)
        layTourSelection.addWidget(self.btnStartTour)
        layTourSelection.addWidget(self.btnEditTour)
        layTourSelection.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding))

        wdgTourSelection = QWidget()
        wdgTourSelection.setLayout(layTourSelection)

        self.jobListWidgets = []
        layJobList = QGridLayout()
        jobs = DBManager.getCurrentJobs()
        layJobList.addWidget(QLabel("<h3>Box</h3>"), 0, 0)
        layJobList.addWidget(QLabel("<h3>Quit</h3>"), 0, 1)
        layJobList.addWidget(QLabel("<h3>Wait</h3>"), 0, 2)
        layJobList.addWidget(QLabel("<h3>Run</h3>"), 0, 3)
        layJobList.addWidget(QLabel("<h3>Run & Wait</h3>"), 0, 4)
        layJobList.addWidget(QLabel("<h3>Parameters</h3>"), 0, 5)
        chkQuitAll = QCheckBox()
        chkQuitAll.clicked.connect(self.chkQuitAll_clicked)
        chkWaitAll = QCheckBox()
        chkWaitAll.clicked.connect(self.chkWaitAll_clicked)
        chkRunAll = QCheckBox()
        chkRunAll.clicked.connect(self.chkRunAll_clicked)
        chkRunAndWaitAll = QCheckBox()
        chkAllGroup = QButtonGroup(self)
        chkAllGroup.addButton(chkQuitAll)
        chkAllGroup.addButton(chkWaitAll)
        chkAllGroup.addButton(chkRunAll)
        chkAllGroup.addButton(chkRunAndWaitAll)
        chkRunAndWaitAll.clicked.connect(self.chkRunAndWaitAll_clicked)
        txtParametersAll = QLineEdit()
        txtParametersAll.textChanged.connect(self.txtParametersAll_textChanged)
        layJobList.addWidget(chkQuitAll, 1, 1)
        layJobList.addWidget(chkWaitAll, 1, 2)
        layJobList.addWidget(chkRunAll, 1, 3)
        layJobList.addWidget(chkRunAndWaitAll, 1, 4)
        layJobList.addWidget(txtParametersAll, 1, 5)
        row = 2
        clientCount = 0
        for c in self.cds:
            chkQuit = QCheckBox()
            chkWait = QCheckBox()
            chkRun = QCheckBox()
            chkRunAndWait = QCheckBox()
            txtParameters = QLineEdit()
            chkGroup = QButtonGroup(self)
            chkGroup.addButton(chkQuit)
            chkGroup.addButton(chkWait)
            chkGroup.addButton(chkRun)
            chkGroup.addButton(chkRunAndWait)
            layJobList.addWidget(QLabel("Pos {}: {}".format(c.Position, c.Latin)), row, 0)
            layJobList.addWidget(chkQuit, row, 1)
            layJobList.addWidget(chkWait, row, 2)
            layJobList.addWidget(chkRun, row, 3)
            layJobList.addWidget(chkRunAndWait, row, 4)
            layJobList.addWidget(txtParameters, row, 5)
            self.jobListWidgets.append([c.Id, chkQuit, chkWait, chkRun, chkRunAndWait, txtParameters])
            row += 1
            clientCount += 1
            if clientCount % 9 == 0 and clientCount < 27:
                line = QFrame()
                line.setGeometry(QRect())
                line.setFrameShape(QFrame.HLine)
                line.setFrameShadow(QFrame.Sunken)
                layJobList.addWidget(line, row, 0, 1, 6)
                row += 1

        self.fillJobList(jobs)

        self.wdgJobList = QWidget()
        self.wdgJobList.setEnabled(False)
        self.wdgJobList.setLayout(layJobList)

        lblJobDescriptionText = QLabel(
            """
                The parameters for Job 'W' are of the form 't' where 't' is optional<br>check every t seconds if there is another job to do
                <br><br><br> 
                The parameters for Job 'RW' are of the form 'r w t'<br>run r times, then wait w times for t seconds
            """)
        lblJobDescriptionText.setAlignment(Qt.AlignTop)

        layJobListAndDescriptions = QHBoxLayout()
        layJobListAndDescriptions.addWidget(self.wdgJobList)
        layJobListAndDescriptions.addSpacing(100)
        layJobListAndDescriptions.addWidget(lblJobDescriptionText)
        layJobListAndDescriptions.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding))

        wdgJobListAndDescriptions = QWidget()
        wdgJobListAndDescriptions.setLayout(layJobListAndDescriptions)

        layJobOverview = QVBoxLayout()
        #layJobOverview.addWidget(QLabel("Job Overview"))
        layJobOverview.addWidget(wdgTourSelection)
        layJobOverview.addWidget(wdgJobListAndDescriptions)

        wdgJobOverivew = QWidget()
        wdgJobOverivew.setLayout(layJobOverview)

        # Client Details

        self.cmbClient = QComboBox()
        self.cmbClient.setFixedWidth(180)
        self.cmbClient.insertItem(-1, "All", -1)
        for c in self.cds:
            self.cmbClient.insertItem(c.Position, "#{}: {}".format(c.Position, c.Latin), c.Position)
        self.cmbClient.currentIndexChanged.connect(self.cmbClient_currentIndexChanged)

        self.btnRereshClientDetails = QPushButton("Refresh")
        self.btnRereshClientDetails.clicked.connect(self.btnRereshClientDetails_clicked)

        layClientSelection = QHBoxLayout()
        layClientSelection.addWidget(QLabel("Box: "))
        layClientSelection.addWidget(self.cmbClient)
        layClientSelection.addSpacing(100)
        layClientSelection.addWidget(self.btnRereshClientDetails)
        layClientSelection.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Fixed))

        wdgClientSelection = QWidget()
        wdgClientSelection.setLayout(layClientSelection)

        self.tblResults = QTableView()
        self.tblResults.horizontalHeader().setStretchLastSection(True)
        self.tblResults.setWordWrap(False)
        self.tblResults.setTextElideMode(Qt.ElideRight)

        self.clientDetailInfoList = [
            ["Name", QLabel("-")],
            ["Position", QLabel("-")],
            ["ID", QLabel("-")],
            ["IP", QLabel("-")],
            ["MAC", QLabel("-")],
            ["Allow User Mode", QLabel("-")],
            ["User Mode Active", QLabel("-")],
            ["Is Active", QLabel("-")],
            ["Current State", QLabel("-")],
            ["Current Job", QLabel("-")],
            ["Recent results", QLabel("-")],
            ["Average contribution", QLabel("-")],
            ["Average result (3.5)", QLabel("-")],
            ["Results last hour", QLabel("-")],
            ["Results last 2 hours", QLabel("-")],
            ["Results today", QLabel("-")],
            ["Results Total", QLabel("-")]
        ]
        layClientDetailInfos = QGridLayout()
        for num, (text, widget) in enumerate(self.clientDetailInfoList):
            layClientDetailInfos.addWidget(QLabel(text), num, 0)
            layClientDetailInfos.addWidget(widget, num, 1)

        grpClientDetailInfos = QGroupBox()
        grpClientDetailInfos.setTitle("Details")
        grpClientDetailInfos.setLayout(layClientDetailInfos)

        layClientDetailsTop = QHBoxLayout()
        layClientDetailsTop.addWidget(self.tblResults)
        layClientDetailsTop.addSpacing(100)
        layClientDetailsTop.addWidget(grpClientDetailInfos)
        layClientDetailsTop.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Fixed))

        wdgClientDetailsTop = QWidget()
        wdgClientDetailsTop.setLayout(layClientDetailsTop)


        self.tblLogMessages = QTableView()
        self.tblLogMessages.horizontalHeader().setStretchLastSection(True)
        self.tblLogMessages.setWordWrap(False)
        self.tblLogMessages.setTextElideMode(Qt.ElideRight)

        self.tblResultStatistics = QTableView()
        #self.tblResultStatistics.horizontalHeader().setStretchLastSection(True)
        self.tblResultStatistics.setWordWrap(False)
        self.tblResultStatistics.setTextElideMode(Qt.ElideRight)
        self.tblResultStatistics.setSortingEnabled(True)

        layClientDetailsBottom = QHBoxLayout()
        layClientDetailsBottom.addWidget(self.tblLogMessages)
        layClientDetailsBottom.addSpacing(20)
        layClientDetailsBottom.addWidget(self.tblResultStatistics)
        #layClientDetailsBottom.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Fixed))

        wdgClientDetailsBottom = QWidget()
        wdgClientDetailsBottom.setLayout(layClientDetailsBottom)

        layDetails = QVBoxLayout()
        layDetails.addWidget(wdgClientSelection)
        layDetails.addWidget(QLabel("Results"))
        layDetails.addWidget(wdgClientDetailsTop)
        layDetails.addWidget(QLabel("Log messages"))
        layDetails.addWidget(wdgClientDetailsBottom)


        wdgDetails = QWidget()
        wdgDetails.setLayout(layDetails)


        layTORServer = QVBoxLayout()
        layTORServer.addWidget(QLabel("TOR server"))

        wdgTORServer = QWidget()
        wdgTORServer.setLayout(layTORServer)

        self.clientDetailsTabIndex = 2

        self.tabDashboard = QTabWidget()
        self.tabDashboard.addTab(wdgDashboard, "Dashboard")
        #self.tabDashboard.addTab(wdgTORServer, "TORServer")
        self.tabDashboard.addTab(wdgJobOverivew, "Jobs")
        self.tabDashboard.addTab(wdgDetails, "Detail View")
        self.dashboardTabIndex = 0
        self.tabDashboard.currentChanged.connect(self.tabDashboard_currentChanged)

        self.txtStatus = QPlainTextEdit()
        self.txtStatus.setReadOnly(True)

        layMain = QVBoxLayout()
        layMain.addWidget(self.tabDashboard)
        layMain.addWidget(self.txtStatus)

        wdgMain = QWidget()
        wdgMain.setLayout(layMain)
        self.setCentralWidget(wdgMain)

        self.initDashboard()
        self.updateDashboard()
        timerFetchData = QTimer(self)
        timerFetchData.timeout.connect(self.updateDashboardFromTimer)
        timerFetchData.start(120 * 1000)