Skip to content
Open
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
46 changes: 28 additions & 18 deletions aviary/interface/graphical_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
import json
import os
import platform
import pprint
import shutil
import subprocess
import tkinter as tk # base tkinter
import tkinter.ttk as ttk # used for combobox
from tkinter import filedialog, font, messagebox
Expand All @@ -24,6 +21,32 @@
from numpy import trapezoid as trapz


def _format_phase_info_value(value, indent_level):
indent = ' ' * indent_level
inner = ' ' * (indent_level + 1)

if isinstance(value, dict):
if not value:
return '{}'
lines = ['{\n']
for k, v in value.items():
lines.append(f'{inner}{k!r}: {_format_phase_info_value(v, indent_level + 1)},\n')
lines.append(f'{indent}}}')
return ''.join(lines)

if isinstance(value, (list, tuple)):
open_b, close_b = ('[', ']') if isinstance(value, list) else ('(', ')')
if not value:
return open_b + close_b
items = [_format_phase_info_value(item, indent_level + 1) for item in value]
one_line = open_b + ', '.join(items) + close_b
if len(one_line) <= 60:
return one_line
return open_b + '\n' + ''.join(f'{inner}{item},\n' for item in items) + f'{indent}{close_b}'

return repr(value)


def get_screen_geometry():
"""
Taken from: https://stackoverflow.com/questions/3129322/how-do-i-get-monitor-resolution-in-python/56913005#56913005
Expand Down Expand Up @@ -1701,21 +1724,8 @@ def create_bounds(center):
# write a python file with the phase information
with open(filename, 'w') as f:
f.write('phase_info = ')
pp = pprint.PrettyPrinter(indent=4, stream=f, sort_dicts=False)
pp.pprint(phase_info)

# Check for 'ruff' and format the file
if shutil.which('ruff'):
subprocess.run(['ruff', filename])
else:
if shutil.which('autopep8'):
subprocess.run(['autopep8', '--in-place', '--aggressive', filename])
print("File formatted using 'autopep8'")
else:
print(
"'ruff' or 'autopep8' are not installed. Please consider installing one of them "
'for better formatting.'
)
f.write(_format_phase_info_value(phase_info, 0))
f.write('\n')

print(f'Phase info has been saved and formatted in {filename}')

Expand Down
Loading