Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
Empty file added pygui/calib/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions pygui/calib/andor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Move to the working directory
cd /home/observer/focus || exit 1

prefix=$(find /data/latest/acam -maxdepth 1 -type f -name 'focusloop_*_*.fits' -print0 \
| xargs -0 -n1 basename \
| sed -E 's/^focusloop_([0-9]{8}-[0-9]{6})_.*/\1/' \
| sort | tail -1) \
&& /home/developer/Software/run/focus_andor.py -fk TELFOCUS "/data/latest/acam/focusloop_${prefix}_*.fits"

98 changes: 66 additions & 32 deletions pygui/calib/calibration.py
Original file line number Diff line number Diff line change
@@ -1,87 +1,121 @@
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QTabWidget, QVBoxLayout, QLabel, QPushButton, QWidget, QDesktopWidget
from tabs.commands_tab import CommandsTab
from tabs.afternoon_tab import AfternoonTab
from tabs.focus_tab import FocusTab
from tabs.science_tab import ScienceTab
import os
from PyQt5.QtWidgets import (
QMainWindow, QApplication, QTabWidget, QDesktopWidget,
QVBoxLayout, QTextEdit, QWidget, QPushButton
)
from PyQt5.QtCore import pyqtSignal

from calib.tabs.commands_tab import CommandsTab
from calib.tabs.afternoon_tab import AfternoonTab
from calib.tabs.focus_tab import FocusTab
from calib.tabs.science_tab import ScienceTab


class CalibrationGUI(QMainWindow):
log_signal = pyqtSignal(str)

def __init__(self):
super().__init__()
self.setWindowTitle("Calibrations")
self.setGeometry(100, 100, 600, 400)
self.initUI()

def initUI(self):
# Create a QTextEdit for logging
self.log_text_edit = QTextEdit(self)
self.log_text_edit.setReadOnly(True)
self.log_text_edit.setPlaceholderText("Log messages will appear here...")
self.log_text_edit.setMinimumHeight(150)

# Connect signal to safe GUI update method
self.log_signal.connect(self.append_log)

# Define the thread-safe logging callback function
def log_message(msg):
self.log_signal.emit(msg)

# Create the QTabWidget
tab_widget = QTabWidget()

# Create the tabs
commands_tab = CommandsTab()
afternoon_tab = AfternoonTab()
focus_tab = FocusTab()
science_tab = ScienceTab()
self.afternoon_tab = AfternoonTab(log_message_callback=self.log_signal.emit)
self.commands_tab = CommandsTab()
self.focus_tab = FocusTab(log_message_callback=self.log_signal.emit)
self.science_tab = ScienceTab()

# Add tabs to the tab widget
tab_widget.addTab(focus_tab, "Focus")
tab_widget.addTab(afternoon_tab, "Afternoon")
tab_widget.addTab(science_tab, "Science")
tab_widget.addTab(commands_tab, "Commands")

# Set the tab widget as the central widget of the main window
self.setCentralWidget(tab_widget)

tab_widget.addTab(self.afternoon_tab, "Afternoon")
tab_widget.addTab(self.focus_tab, "Focus")
tab_widget.addTab(self.science_tab, "Science")
tab_widget.addTab(self.commands_tab, "Commands")

# Set up layout and widgets
main_layout = QVBoxLayout()
main_layout.addWidget(tab_widget, stretch=3)
main_layout.addWidget(self.log_text_edit, stretch=2)

# Optionally, add a button to clear the log
clear_log_button = QPushButton("Clear Log", self)
clear_log_button.clicked.connect(self.clear_log)
main_layout.addWidget(clear_log_button, stretch=0)

# Create a QWidget and set the layout
central_widget = QWidget(self)
central_widget.setLayout(main_layout)
self.setCentralWidget(central_widget)

self.load_stylesheet("styles.qss")

# Adjust window size based on screen resolution
self.adjust_window_size()

def append_log(self, message):
"""Safely append a log message to the QTextEdit widget from the main thread."""
self.log_text_edit.append(message)

def clear_log(self):
"""Clear the log messages."""
self.log_text_edit.clear()

def adjust_window_size(self):
screen = QDesktopWidget().screenGeometry() # Get screen size
screen = QDesktopWidget().screenGeometry()
width = screen.width()
height = screen.height()

# Set a default window size as a percentage of screen size (for example, 80% width and 60% height)
new_width = int(width * 0.4)
new_height = int(height * 0.6)

self.setFixedSize(new_width, new_height) # Set window size dynamically
self.setFixedSize(new_width, new_height)

def resizeEvent(self, event):
# Maintain 4:3 aspect ratio on window resizing
aspect_ratio = 4 / 3
current_width = self.width()
current_height = self.height()

# Calculate the new width/height to preserve aspect ratio
if current_width / current_height > aspect_ratio:
new_width = int(current_height * aspect_ratio) # Ensure integer type
new_width = int(current_height * aspect_ratio)
new_height = current_height
else:
new_height = int(current_width / aspect_ratio) # Ensure integer type
new_height = int(current_width / aspect_ratio)
new_width = current_width

# Resize the window to maintain aspect ratio
self.resize(new_width, new_height)

# Call the original resizeEvent
super().resizeEvent(event)

def load_stylesheet(self, filename):
"""Load and apply the stylesheet from a .qss file"""
if os.path.exists(filename):
with open(filename, "r") as file:
stylesheet = file.read()
self.setStyleSheet(stylesheet)
else:
print(f"Stylesheet file {filename} not found.")
self.log_signal.emit(f"Stylesheet file {filename} not found.")


def main():
app = QApplication(sys.argv)
main_window = CalibrationGUI()
main_window.show()
main_window.log_signal.emit("Calibration started...") # Thread-safe initial log
sys.exit(app.exec_())


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions pygui/calib/fake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/bash -f
echo "Executing \"$@\""
exec $@
sleep 0.5
Loading