77 lines
3.1 KiB
Python
77 lines
3.1 KiB
Python
# Import Header
|
|
import os
|
|
import sys
|
|
import cv2
|
|
import json
|
|
import urllib.parse
|
|
import numpy as np
|
|
from PyQt5.QtWidgets import (QApplication, QMainWindow, QVBoxLayout, QHBoxLayout,
|
|
QWidget, QLabel, QPushButton, QComboBox, QSpinBox,
|
|
QFileDialog, QMessageBox, QMenu, QAction, QMenuBar,
|
|
QActionGroup, QSizePolicy, QGridLayout, QGroupBox,
|
|
QDockWidget, QScrollArea, QToolButton, QDialog,
|
|
QShortcut, QListWidget, QFormLayout, QLineEdit,
|
|
QCheckBox, QTabWidget, QListWidgetItem, QSplitter)
|
|
from PyQt5.QtCore import Qt, QTimer, QDir, QSize, QSettings, QDateTime, QRect, QThread, pyqtSignal, QMutex
|
|
from PyQt5.QtGui import (QImage, QPixmap, QIcon, QColor, QKeySequence, QPainter,
|
|
QPen, QBrush)
|
|
import time
|
|
import requests
|
|
import subprocess
|
|
|
|
|
|
class Config:
|
|
def __init__(self):
|
|
# Use platform-specific user directory for config
|
|
if sys.platform.startswith('win'):
|
|
config_dir = os.path.join(os.environ.get('APPDATA', os.path.expanduser('~')), 'MuCaPy')
|
|
pictures_dir = os.path.join(os.environ.get('USERPROFILE', os.path.expanduser('~')), 'Pictures', 'MuCaPy')
|
|
else:
|
|
config_dir = os.path.join(os.path.expanduser('~'), '.config', 'mucapy')
|
|
pictures_dir = os.path.join(os.path.expanduser('~'), 'Pictures', 'MuCaPy')
|
|
|
|
# Create config directory if it doesn't exist
|
|
os.makedirs(config_dir, exist_ok=True)
|
|
|
|
self.config_file = os.path.join(config_dir, 'config.json')
|
|
self.settings = {
|
|
'network_cameras': {}, # Store network cameras configuration
|
|
'last_model_dir': '',
|
|
'last_screenshot_dir': pictures_dir,
|
|
'last_layout': 0,
|
|
'last_fps': 10,
|
|
'last_selected_cameras': [],
|
|
'window_geometry': None,
|
|
'confidence_threshold': 0.35,
|
|
}
|
|
self.load_config()
|
|
|
|
def load_config(self):
|
|
"""Load configuration from JSON file"""
|
|
try:
|
|
if os.path.exists(self.config_file):
|
|
with open(self.config_file, 'r') as f:
|
|
loaded_settings = json.load(f)
|
|
# Update settings while preserving default values for new keys
|
|
self.settings.update(loaded_settings)
|
|
except Exception as e:
|
|
print(f"Error loading config: {e}")
|
|
|
|
def save_config(self):
|
|
"""Save configuration to JSON file"""
|
|
try:
|
|
# Ensure the file's directory exists
|
|
os.makedirs(os.path.dirname(self.config_file), exist_ok=True)
|
|
with open(self.config_file, 'w') as f:
|
|
json.dump(self.settings, f, indent=4)
|
|
except Exception as e:
|
|
print(f"Error saving config: {e}")
|
|
|
|
def save_setting(self, key, value):
|
|
"""Save a setting to configuration"""
|
|
self.settings[key] = value
|
|
self.save_config()
|
|
|
|
def load_setting(self, key, default=None):
|
|
"""Load a setting from configuration"""
|
|
return self.settings.get(key, default) |