Added autoposition

This commit is contained in:
Christoffer Martinsson 2025-04-13 13:46:21 +02:00
parent 6c42d931b6
commit 7bae89a9d2
2 changed files with 32 additions and 1 deletions

View File

@ -5,3 +5,11 @@ SCPI viewer for OWON SPM6103 Powersupply/Multimeter
## SCPI command
- [ ] [OWON SPM SCPI manual](SPM_Series_programming_manual.pdf)
## Autostart
Add following to autostart app (Ubuntu):
''' bash
bash -c "sleep 3 && python3 /home/cm/spm6103_viewer/spm6103_viewer.py"
'''

View File

@ -2,8 +2,26 @@ import tkinter as tk
from tkinter.font import Font
import serial
import os
import json
os.environ['GDK_SCALE'] = '2'
# Load saved window geometry if exists
def load_window_geometry():
try:
with open("settings.json", "r") as f:
settings = json.load(f)
return settings.get("geometry", "1080x200+100+100") # Default geometry
except FileNotFoundError:
return "1080x200+100+100" # Default geometry if no settings file
# Save the window geometry when closing the app
def save_window_geometry():
geometry = app.geometry()
settings = {"geometry": geometry}
with open("settings.json", "w") as f:
json.dump(settings, f)
# Serial configuration
port = '/dev/ttyUSB0' # Adjust to your specific port
baud_rate = 115200 # Adjust to your device's baud rate
@ -99,9 +117,13 @@ def fetch_device_info():
app = tk.Tk()
app.title("OWON SPM6103")
app.geometry("1080x200")
# Load and apply the saved geometry (size + position)
app.geometry(load_window_geometry())
app.configure(bg="black")
# Add a window close event to save the geometry
app.protocol("WM_DELETE_WINDOW", lambda: [save_window_geometry(), app.quit()])
multimeter_type_var = tk.StringVar()
multimeter_data_var = tk.StringVar()
multimeter_range_var = tk.StringVar()
@ -113,6 +135,7 @@ fontBig = Font(size=24)
resize_after_id = None
def apply_font_resize():
width = app.winfo_width()