Commit 2a47eacf authored by AJ Fite's avatar AJ Fite 🛫

Fully configurable

parent 586b57bc
......@@ -25,12 +25,12 @@
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>TextLabel</string>
<string>Bash (or compatible shell) path</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
<widget class="QLineEdit" name="shellPath"/>
</item>
</layout>
</item>
......@@ -39,12 +39,12 @@
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>TextLabel</string>
<string>Lepton-Graber Working Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_4"/>
<widget class="QLineEdit" name="leptonWorkingDir"/>
</item>
</layout>
</item>
......@@ -53,12 +53,12 @@
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>TextLabel</string>
<string>Sudo path</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2"/>
<widget class="QLineEdit" name="sudoPath"/>
</item>
</layout>
</item>
......@@ -67,25 +67,15 @@
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>TextLabel</string>
<string>Python Path</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_3"/>
<widget class="QLineEdit" name="pythonPath"/>
</item>
</layout>
</item>
<item row="13" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel</set>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
......@@ -98,28 +88,35 @@
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>TextLabel</string>
<string>dbg_ffc_interval</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_2"/>
<widget class="QSpinBox" name="ffcInterval">
<property name="minimum">
<number>-9999</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="12" column="0">
<item row="13" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>TextLabel</string>
<string>dbg_serial_csv (Generate CSV)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_4">
<widget class="QRadioButton" name="csvEnable">
<property name="text">
<string>RadioButton</string>
<string>Enab&amp;le</string>
</property>
<attribute name="buttonGroup">
<string notr="true">dbgcsvgroup</string>
......@@ -127,9 +124,9 @@
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_2">
<widget class="QRadioButton" name="csvDisable">
<property name="text">
<string>RadioBu&amp;tton</string>
<string>&amp;Disable</string>
</property>
<attribute name="buttonGroup">
<string notr="true">dbgcsvgroup</string>
......@@ -143,12 +140,19 @@
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>TextLabel</string>
<string>dbg_capture_count (Number of images to capture)</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox"/>
<widget class="QSpinBox" name="captureCount">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
</layout>
</item>
......@@ -157,28 +161,38 @@
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>TextLabel</string>
<string>dbg_interval (capture interval in seconds)</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_3"/>
<widget class="QSpinBox" name="capInterval">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="11" column="0">
<item row="12" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>TextLabel</string>
<string>dbg_png (Generate pngs)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_3">
<widget class="QRadioButton" name="pngEnable">
<property name="text">
<string>RadioB&amp;utton</string>
<string>E&amp;nable</string>
</property>
<attribute name="buttonGroup">
<string notr="true">dbgpnggroup</string>
......@@ -186,9 +200,9 @@
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton">
<widget class="QRadioButton" name="pngDisable">
<property name="text">
<string>RadioB&amp;utton</string>
<string>Disable</string>
</property>
<attribute name="buttonGroup">
<string notr="true">dbgpnggroup</string>
......@@ -224,6 +238,37 @@
</property>
</widget>
</item>
<item row="14" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::RestoreDefaults|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
<item row="11" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>dbg_lepton_set (Number of leptons)</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="leptonSet">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
......@@ -262,7 +307,7 @@
</connection>
</connections>
<buttongroups>
<buttongroup name="dbgpnggroup"/>
<buttongroup name="dbgcsvgroup"/>
<buttongroup name="dbgpnggroup"/>
</buttongroups>
</ui>
......@@ -2,7 +2,7 @@ import os
from configparser import SafeConfigParser
from PyQt5 import uic
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog
from PyQt5.QtWidgets import QDialog, QDialogButtonBox
class Config:
......@@ -19,41 +19,59 @@ class Config:
"""
# paths
lepton_grabber_working_dir = "lepton-grabber"
python_path = "/usr/bin/python3"
sudo_path = "sudo"
lepton_grabber_working_dir = str()
python_path = str()
sudo_path = str()
# Note that bash can be replaced by other compatible shells
# All I use is echo, quit, printf, and the piping command "|"
bash_path = "bash"
bash_path = str()
# lepton-grabber launch options
dbg_interval = 10
dbg_png = True
dbg_ffc_interval = -180
dbg_capture_count = 720
dbg_serial_csv = True
dbg_interval = int()
dbg_png = bool()
dbg_ffc_interval = int()
dbg_capture_count = int()
dbg_serial_csv = bool()
dbg_lepton_set = int()
def read_config(self, parser):
parser.read(self.config_name)
@staticmethod
def defaults():
Config.lepton_grabber_working_dir = "lepton-grabber"
Config.python_path = "/usr/bin/python3"
Config.sudo_path = "sudo"
Config.bash_path = "bash"
Config.dbg_interval = 10
Config.dbg_png = True
Config.dbg_ffc_interval = -180
Config.dbg_capture_count = 720
Config.dbg_serial_csv = True
Config.dbg_lepton_set = 7
@staticmethod
def read_config(parser):
parser.read(Config.config_name)
# Get Paths
self.lepton_grabber_working_dir = parser.get(
Config.lepton_grabber_working_dir = parser.get(
'Paths', 'lepton_grabber_working_dir')
self.python_path = parser.get('Paths', 'python_path')
self.sudo_path = parser.get('Paths', 'sudo_path')
self.bash_path = parser.get('Paths', 'bash_path')
Config.python_path = parser.get('Paths', 'python_path')
Config.sudo_path = parser.get('Paths', 'sudo_path')
Config.bash_path = parser.get('Paths', 'bash_path')
# Get lepton config
self.dbg_interval = parser.getint('LeptonGrabberLaunchOptions',
'dbg_interval')
self.dbg_png = parser.getboolean('LeptonGrabberLaunchOptions',
'dbg_png')
self.dbg_ffc_interval = parser.getint('LeptonGrabberLaunchOptions',
'dbg_ffc_interval')
self.dbg_capture_count = parser.getint('LeptonGrabberLaunchOptions',
'dbg_capture_count')
self.dbg_serial_csv = parser.getboolean('LeptonGrabberLaunchOptions',
'dbg_serial_csv')
Config.dbg_interval = parser.getint('LeptonGrabberLaunchOptions',
'dbg_interval')
Config.dbg_png = parser.getboolean('LeptonGrabberLaunchOptions',
'dbg_png')
Config.dbg_ffc_interval = parser.getint('LeptonGrabberLaunchOptions',
'dbg_ffc_interval')
Config.dbg_capture_count = parser.getint('LeptonGrabberLaunchOptions',
'dbg_capture_count')
Config.dbg_serial_csv = parser.getboolean('LeptonGrabberLaunchOptions',
'dbg_serial_csv')
Config.dbg_lepton_set = parser.getint('LeptonGrabberLaunchOptions',
'dbg_lepton_set')
@staticmethod
def write_config(parser):
......@@ -75,6 +93,8 @@ class Config:
str(Config.dbg_capture_count))
parser.set('LeptonGrabberLaunchOptions', 'dbg_serial_csv',
str(Config.dbg_serial_csv))
parser.set('LeptonGrabberLaunchOptions', 'dbg_lepton_set',
str(Config.dbg_lepton_set))
with open(Config.config_name, 'w') as file:
parser.write(file)
......@@ -82,10 +102,11 @@ class Config:
def __init__(self):
parser = SafeConfigParser(allow_no_value=True)
if os.path.isfile(self.config_name):
if os.path.isfile(Config.config_name):
self.read_config(parser)
else:
# Generate new config
self.defaults()
self.write_config(parser)
......@@ -94,3 +115,52 @@ class ConfigEditor(QDialog):
super().__init__(flags=Qt.WindowStaysOnTopHint)
uic.loadUi('SettingsDialog.ui', self)
self.show()
self.update_configs()
# Init handlers
self.buttonBox.accepted.connect(self.apply_settings)
self.buttonBox.button(QDialogButtonBox.RestoreDefaults).clicked\
.connect(self.apply_defaults)
def update_configs(self):
self.leptonWorkingDir.setText(Config.lepton_grabber_working_dir)
self.pythonPath.setText(Config.python_path)
self.sudoPath.setText(Config.sudo_path)
self.shellPath.setText(Config.bash_path)
self.capInterval.setValue(Config.dbg_capture_count)
self.ffcInterval.setValue(Config.dbg_ffc_interval)
self.captureCount.setValue(Config.dbg_capture_count)
self.leptonSet.setValue(Config.dbg_lepton_set)
self.pngEnable.setChecked(Config.dbg_png)
self.pngDisable.setChecked(not Config.dbg_png)
self.csvEnable.setChecked(Config.dbg_serial_csv)
self.csvDisable.setChecked(not Config.dbg_serial_csv)
def apply_settings(self):
parser = SafeConfigParser(allow_no_value=True)
# Set the settings
Config.lepton_grabber_working_dir = self.leptonWorkingDir.text()
Config.python_path = self.pythonPath.text()
Config.sudo_path = self.sudoPath.text()
Config.bash_path = self.shellPath.text()
Config.dbg_ffc_interval = self.capInterval.value()
Config.dbg_interval = self.capInterval.value()
Config.dbg_capture_count = self.captureCount.value()
Config.dbg_lepton_set = self.leptonSet.value()
Config.dbg_png = self.pngEnable.isChecked()
Config.dbg_serial_csv = self.csvEnable.isChecked()
Config.write_config(parser)
def apply_defaults(self):
parser = SafeConfigParser(allow_no_value=True)
Config.defaults()
self.update_configs()
Config.write_config(parser)
......@@ -150,7 +150,6 @@ class MainWindow(QMainWindow):
# Note this is a kinda hacky way to get the script to execute
# with sudo permissions, likely a better way to do this at the system
# level
# TODO: Could expand configurability
self.simfProcess.start(Config.bash_path)
self.simfProcess.writeData(("printf -v pw \"%q\\n\" \""
+ password + "\"\n").encode('utf-8'))
......@@ -166,7 +165,9 @@ class MainWindow(QMainWindow):
" --dbg_capture_count "
+ str(Config.dbg_capture_count) +
" --dbg_serial_csv "
+ str(int(Config.dbg_serial_csv)) + "\n")
+ str(int(Config.dbg_serial_csv)) +
"--dbg_lepton_set"
+ str(Config.dbg_lepton_set) + "\n")
.encode('utf-8'))
self.simfProcess.writeData("exit\n".encode('utf-8'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment