yeahhhh
This commit is contained in:
114
mucapy/main.py
114
mucapy/main.py
@@ -16,6 +16,7 @@ from PyQt5.QtGui import (QImage, QPixmap, QIcon, QColor, QKeySequence, QPainter,
|
|||||||
QPen, QBrush)
|
QPen, QBrush)
|
||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
|
import subprocess
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -1452,10 +1453,44 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
# File Menu
|
# File Menu
|
||||||
file_menu = menubar.addMenu('File')
|
file_menu = menubar.addMenu('File')
|
||||||
|
|
||||||
|
# Save Settings action
|
||||||
|
save_settings_action = QAction('Save Settings...', self)
|
||||||
|
save_settings_action.setShortcut('Ctrl+S')
|
||||||
|
save_settings_action.setStatusTip('Save current settings to a file')
|
||||||
|
save_settings_action.triggered.connect(self.save_settings_to_file)
|
||||||
|
file_menu.addAction(save_settings_action)
|
||||||
|
|
||||||
|
# Load Settings action
|
||||||
|
load_settings_action = QAction('Load Settings...', self)
|
||||||
|
load_settings_action.setShortcut('Ctrl+O')
|
||||||
|
load_settings_action.setStatusTip('Load settings from a file')
|
||||||
|
load_settings_action.triggered.connect(self.load_settings_from_file)
|
||||||
|
file_menu.addAction(load_settings_action)
|
||||||
|
|
||||||
|
file_menu.addSeparator()
|
||||||
|
|
||||||
|
# Export Screenshots Directory action
|
||||||
|
export_screenshots_action = QAction('Export Screenshots Directory...', self)
|
||||||
|
export_screenshots_action.setStatusTip('Open the screenshots directory')
|
||||||
|
export_screenshots_action.triggered.connect(self.open_screenshots_directory)
|
||||||
|
file_menu.addAction(export_screenshots_action)
|
||||||
|
|
||||||
|
file_menu.addSeparator()
|
||||||
|
|
||||||
about_action = QAction("About", self)
|
about_action = QAction("About", self)
|
||||||
about_action.triggered.connect(self.show_menu)
|
about_action.triggered.connect(self.show_menu)
|
||||||
file_menu.addAction(about_action)
|
file_menu.addAction(about_action)
|
||||||
|
|
||||||
|
file_menu.addSeparator()
|
||||||
|
|
||||||
|
# Exit action
|
||||||
|
exit_action = QAction('Exit', self)
|
||||||
|
exit_action.setShortcut('Ctrl+Q')
|
||||||
|
exit_action.setStatusTip('Exit application')
|
||||||
|
exit_action.triggered.connect(self.close)
|
||||||
|
file_menu.addAction(exit_action)
|
||||||
|
|
||||||
# Model menu
|
# Model menu
|
||||||
model_menu = menubar.addMenu('Model')
|
model_menu = menubar.addMenu('Model')
|
||||||
load_model_action = QAction('Load Model Directory...', self)
|
load_model_action = QAction('Load Model Directory...', self)
|
||||||
@@ -1959,6 +1994,85 @@ class MainWindow(QMainWindow):
|
|||||||
dialog.exec_()
|
dialog.exec_()
|
||||||
# Refresh camera list after dialog closes
|
# Refresh camera list after dialog closes
|
||||||
self.populate_camera_menu()
|
self.populate_camera_menu()
|
||||||
|
|
||||||
|
def save_settings_to_file(self):
|
||||||
|
"""Save current settings to a JSON file"""
|
||||||
|
file_path, _ = QFileDialog.getSaveFileName(
|
||||||
|
self,
|
||||||
|
"Save Settings",
|
||||||
|
os.path.expanduser("~"),
|
||||||
|
"JSON Files (*.json)"
|
||||||
|
)
|
||||||
|
|
||||||
|
if file_path:
|
||||||
|
try:
|
||||||
|
settings = {
|
||||||
|
'model_dir': self.detector.model_dir,
|
||||||
|
'fps': self.fps_spin.value(),
|
||||||
|
'layout': self.layout_combo.currentIndex(),
|
||||||
|
'network_cameras': self.detector.network_cameras,
|
||||||
|
'confidence_threshold': self.detector.confidence_threshold
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(file_path, 'w') as f:
|
||||||
|
json.dump(settings, f, indent=4)
|
||||||
|
QMessageBox.information(self, "Success", "Settings saved successfully!")
|
||||||
|
except Exception as e:
|
||||||
|
QMessageBox.critical(self, "Error", f"Failed to save settings: {str(e)}")
|
||||||
|
|
||||||
|
def load_settings_from_file(self):
|
||||||
|
"""Load settings from a JSON file"""
|
||||||
|
file_path, _ = QFileDialog.getOpenFileName(
|
||||||
|
self,
|
||||||
|
"Load Settings",
|
||||||
|
os.path.expanduser("~"),
|
||||||
|
"JSON Files (*.json)"
|
||||||
|
)
|
||||||
|
|
||||||
|
if file_path:
|
||||||
|
try:
|
||||||
|
with open(file_path, 'r') as f:
|
||||||
|
settings = json.load(f)
|
||||||
|
|
||||||
|
# Apply loaded settings
|
||||||
|
if 'model_dir' in settings and os.path.exists(settings['model_dir']):
|
||||||
|
self.detector.load_yolo_model(settings['model_dir'])
|
||||||
|
self.model_label.setText(f"Model: {os.path.basename(settings['model_dir'])}")
|
||||||
|
|
||||||
|
if 'fps' in settings:
|
||||||
|
self.fps_spin.setValue(settings['fps'])
|
||||||
|
|
||||||
|
if 'layout' in settings:
|
||||||
|
self.layout_combo.setCurrentIndex(settings['layout'])
|
||||||
|
|
||||||
|
if 'network_cameras' in settings:
|
||||||
|
self.detector.network_cameras = settings['network_cameras']
|
||||||
|
self.populate_camera_menu()
|
||||||
|
|
||||||
|
if 'confidence_threshold' in settings:
|
||||||
|
self.detector.confidence_threshold = settings['confidence_threshold']
|
||||||
|
|
||||||
|
QMessageBox.information(self, "Success", "Settings loaded successfully!")
|
||||||
|
except Exception as e:
|
||||||
|
QMessageBox.critical(self, "Error", f"Failed to load settings: {str(e)}")
|
||||||
|
|
||||||
|
def open_screenshots_directory(self):
|
||||||
|
"""Open the screenshots directory in the system's file explorer"""
|
||||||
|
screenshot_dir = self.config.load_setting('screenshot_dir', os.path.expanduser('~/Pictures/MuCaPy'))
|
||||||
|
|
||||||
|
if not os.path.exists(screenshot_dir):
|
||||||
|
os.makedirs(screenshot_dir, exist_ok=True)
|
||||||
|
|
||||||
|
# Open directory using the appropriate command for the OS
|
||||||
|
try:
|
||||||
|
if sys.platform.startswith('win'):
|
||||||
|
os.startfile(screenshot_dir)
|
||||||
|
elif sys.platform.startswith('darwin'): # macOS
|
||||||
|
subprocess.run(['open', screenshot_dir])
|
||||||
|
else: # Linux and other Unix-like
|
||||||
|
subprocess.run(['xdg-open', screenshot_dir])
|
||||||
|
except Exception as e:
|
||||||
|
QMessageBox.warning(self, "Warning", f"Could not open directory: {str(e)}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|||||||
Reference in New Issue
Block a user