Skip to content

Commit

Permalink
Issue/56 plot gui (#113)
Browse files Browse the repository at this point in the history
First attempt a minimal working GUI via PyQt5
  • Loading branch information
rdoddanavar authored Sep 7, 2024
1 parent 5a407ed commit 7e1cf23
Show file tree
Hide file tree
Showing 11 changed files with 613 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit-test-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Install python packages
run: pip install -r requirements.txt
- name: Run unit test
run: ./hpr-sim.py -i input/unit_test.yml output/ && ls -l output/*/*
run: ./hpr-sim.py -i input/unit_test.yml output/ --headless && ls -l output/*/*
pyinstaller-ubuntu:
runs-on: ubuntu-22.04
needs: build-ubuntu
Expand All @@ -65,4 +65,4 @@ jobs:
- name: PyInstaller build
run: python tools/pyinstaller_build.py
- name: Run unit test
run: cd build/pyinstaller/dist/hpr-sim && ./hpr-sim -i input/unit_test.yml output/ && ls -l output/*/*
run: cd build/pyinstaller/dist/hpr-sim && ./hpr-sim -i input/unit_test.yml output/ --headless && ls -l output/*/*
4 changes: 2 additions & 2 deletions .github/workflows/unit-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Install python packages
run: pip install -r requirements.txt
- name: Run unit test
run: ./hpr-sim.py -i input/unit_test.yml output/ && ls -l output/*/*
run: ./hpr-sim.py -i input/unit_test.yml output/ --headless && ls -l output/*/*
pyinstaller-windows:
runs-on: windows-2022
defaults:
Expand All @@ -74,4 +74,4 @@ jobs:
- name: PyInstaller build
run: python tools/pyinstaller_build.py
- name: Run unit test
run: cd build/pyinstaller/dist/hpr-sim && ./hpr-sim -i input/unit_test.yml output/ && ls -l output/*/*
run: cd build/pyinstaller/dist/hpr-sim && ./hpr-sim -i input/unit_test.yml output/ --headless && ls -l output/*/*
14 changes: 9 additions & 5 deletions hpr-sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import multiprocessing as mp

# Path modifications
paths = ["build/src", "src/exec", "src/preproc", "src/postproc", "src/util"]
paths = ["build/src", "src/exec", "src/gui", "src/preproc", "src/postproc", "src/util"]

for item in paths:
addPath = pathlib.Path(__file__).parent / item
sys.path.append(addPath.resolve().as_posix())

# Project modules
import exec
import gui_main
import postproc_flight

#------------------------------------------------------------------------------#
Expand All @@ -26,15 +27,18 @@

# Parse CLI
parser = argparse.ArgumentParser()
parser.add_argument('-i', "--input" , type=str, help="Input file path")
parser.add_argument('output', type=str, help="Output file path")
parser.add_argument("--headless", action="store_true", help="Headless mode (no GUI)")
parser.add_argument("-i", "--input", type=str, help="Input file path")
parser.add_argument("output", type=str, help="Output file path")

args = parser.parse_args()
inputPath = pathlib.Path(args.input)
outputPath = pathlib.Path(args.output)
configPath = pathlib.Path(__file__).parent / "config"

if inputPath is not None:
exec.exec(inputPath, outputPath, configPath)
if not(args.headless):
gui_main.exec()
elif inputPath is not None:
exec.run(inputPath, outputPath, configPath)
else:
postproc_flight.postproc(outputPath)
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ pyyaml
tqdm
colorama
pyinstaller
pyqt5
pyqtgraph
2 changes: 1 addition & 1 deletion src/exec/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def cli_intro(metadata):

#------------------------------------------------------------------------------#

def exec(inputPath, outputPath, configPath):
def run(inputPath, outputPath, configPath):

"""
Executes simluation using paramters defined in input file
Expand Down
83 changes: 83 additions & 0 deletions src/gui/gui_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# System modules
import pathlib
import functools
from PyQt5.QtWidgets import(
QLabel,
QPushButton,
QSpinBox,
QFileDialog,
QSizePolicy
)

from PyQt5.QtCore import Qt
import pyqtgraph as pg

#------------------------------------------------------------------------------#

def pyqtgraph_setup():

pg.setConfigOptions(background='w')
pg.setConfigOptions(foreground='k')
pg.setConfigOptions(antialias=True)

#------------------------------------------------------------------------------#

class Label(QLabel):

# QLabel w/ desired default settings

def __init__(self, text):

super().__init__(text)

# Center text
self.setAlignment(Qt.AlignCenter)

class PushButton(QPushButton):

# QPushButton w/ desired default settings

def __init__(self, text):

super().__init__(text)

# Automatic rescaling in both dimensions
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

class SpinBox(QSpinBox):

# QSpinBox w/ desired default settings

def __init__(self, min, max):

super().__init__()

self.setMinimum(min)
self.setMaximum(max)

spinBoxMax = 2147483647 # Enforced by QSpinBox.setMaximum

#------------------------------------------------------------------------------#

def action_get_file(parent, target):
return functools.partial(get_file, parent, target)

def get_file(parent, target):

fileName = QFileDialog.getOpenFileName(parent, "Select Input File", pathlib.Path(".").resolve().as_posix(), "Input Files (*.yml *.yaml)")
target.setText(fileName[0])

#------------------------------------------------------------------------------#

def action_get_directory(parent, target):
return functools.partial(get_directory, parent, target)

def get_directory(parent, target):

directory = QFileDialog.getExistingDirectory(parent, "Select Output Directory", pathlib.Path(".").resolve().as_posix())
target.setText(directory)

#------------------------------------------------------------------------------#

if __name__ == "__main__":
pass
Loading

0 comments on commit 7e1cf23

Please sign in to comment.