def load():
    """
    Load video streams available.
    """
    global VIDEO_CONFIG, VIDEO_LIST, VIDEO_MULTI_THREAD
    VIDEO_CONFIG = ConfigParser()
    try:
        if not os.path.exists("videos.ini"):
            with open("videos.ini", "w") as configfile:
                VIDEO_CONFIG.write(configfile)
        else:
            VIDEO_CONFIG.read("videos.ini")

        for k, v in VIDEO_CONFIG.items():
            if k is "DEFAULT":
                continue

            res = getResolution(v.get("scaling", "(0,0)"))
            bounds = getBounds(v.get("bounds", "(0,0,0,0)"))
            VIDEO_LIST[k] = createVideoDict(v.get("source", ""),
                                            int(v.get("color", "0")), res[0],
                                            res[1], bounds[0], bounds[1],
                                            bounds[2], bounds[3])

        VIDEO_MULTI_THREAD = (cfg.SETTINGS.get("main",
                                               "multithread") == "True")
        cam_thread_mngr.initialize(VIDEO_MULTI_THREAD)
    except:
        warning.showWarning("Fatal Error", "Unable to read/create videos.ini",
                            None)
Пример #2
0
    def plotGraph(self):
        try:
            selectedType = self.frameGraphSettings.findChild(QComboBox, "plotDataType").currentIndex()
            startDate = datetime.datetime.fromtimestamp(self.frameGraphSettings.findChild(QDateTimeEdit, "plotTimeStart").dateTime().toMSecsSinceEpoch() / 1000)
            endDate = datetime.datetime.fromtimestamp(self.frameGraphSettings.findChild(QDateTimeEdit, "plotTimeEnd").dateTime().toMSecsSinceEpoch() / 1000)
            minValue = float(self.frameGraphSettings.findChild(QLineEdit, "fieldMinVal").text())
            maxValue = float(self.frameGraphSettings.findChild(QLineEdit, "fieldMaxVal").text())
            useValueRange = self.frameGraphSettings.findChild(QCheckBox, "plotCheckMinMax").isChecked()

            data = database.Event.findTypeWithin(selectedType, startDate, endDate, True)
            if len(data) <= 0:
                showWarning("Error!", "No data available for the selected type or within the selected timespan!", self)
                return

            # Filter out 'broken' values.
            values = list()
            for d in data:
                v = getValueForDBEvent(d)
                if v:
                    if useValueRange and not (v >= minValue and v <= maxValue):
                        continue

                    values.append(v)

            self.graph.clearGraph()
            self.graph.plot("", values, 111)
        except:
            showWarning("Error!", "Invalid input(s) inserted!", self)
Пример #3
0
def loadSettings():
    """
    Loads global settings, creates a new settings.ini file with default
    values if not found.
    """
    global SETTINGS
    try:
        if not os.path.exists("settings.ini"):
            for section in DEFAULT_SECTIONS:
                SETTINGS.add_section(str(section))

            for key, value in DEFAULT_MAIN_SETTINGS.items():
                SETTINGS.set(str("main"), str(key), str(value))

            for key, value in DEFAULT_DATABASE_SETTINGS.items():
                SETTINGS.set(str("database"), str(key), str(value))

            for key, value in DEFAULT_COMMUNICATION_SETTINGS.items():
                SETTINGS.set(str("communication"), str(key), str(value))

            with open("settings.ini", "w") as configfile:
                SETTINGS.write(configfile)
        else:
            SETTINGS.read("settings.ini")
    except:
        warning.showWarning("Fatal Error",
                            "Unable to read/create settings.ini", None)
Пример #4
0
 def createDatabase(self):
     if warning.showPrompt(
             "Disclaimer!",
             "Create a new database? You may have to restart the program!",
             self) == QMessageBox.Yes:
         try:
             database.createDatabase(self.databaseDB.text())
         except Exception as e:
             warning.showWarning("Fatal Error", str(e), self)
def save():
    """
    Save video streams.
    """
    global VIDEO_CONFIG
    try:
        with open("videos.ini", "w") as configfile:
            VIDEO_CONFIG.write(configfile)
    except:
        warning.showWarning("Fatal Error", "Unable to write videos.ini", None)
Пример #6
0
def saveSettings():
    """
    Save global settings to settings.ini
    """
    global SETTINGS, SETTINGSEVENT
    try:
        with open("settings.ini", "w") as configfile:
            SETTINGS.write(configfile)

        SETTINGSEVENT.raiseEvent(SETTINGS)
    except Exception as e:
        warning.showWarning("Fatal Error", "Unable to write settings.ini",
                            None)
Пример #7
0
    def addNewCamera(self):
        name = self.fieldCameraName.text()
        src = self.fieldCameraSource.text()

        if len(name) <= 0 or len(src) <= 0:
            warning.showWarning("Fatal Error", "Invalid or missing input(s)!",
                                self)
            return

        if not vm.addVideo(name, src):
            warning.showWarning("Fatal Error", "This camera ID already exist!",
                                self)
            return

        idx = self.cameraList.rowCount()
        self.cameraList.insertRow(idx)
        self.cameraList.setItem(idx, 0, QTableWidgetItem(name))
        self.cameraList.setItem(idx, 1, QTableWidgetItem(src))
        self.mainwindow.populateCameraMenu()