11#!/usr/bin/python
22#
33# wxmplott GUI to Configure Line Plots
4- #
5- import os
4+
5+ from pathlib import Path
66from functools import partial
77import yaml
88import numpy as np
1313
1414from wxutils import get_cwd
1515
16- from .utils import LabeledTextCtrl , MenuItem , Choice , FloatSpin
16+ from .utils import LabeledTextCtrl , MenuItem , Choice , FloatSpin , fix_filename
1717from .config import PlotConfig
1818from .colors import hexcolor , mpl_color , GUI_COLORS
1919
@@ -128,7 +128,13 @@ def __init__(self, parent=None, config=None, trace_color_callback=None):
128128 mbar .Append (fmenu , 'File' )
129129 self .SetMenuBar (mbar )
130130
131- def save_config (self , evt = None , fname = 'wxmplot.yaml' ):
131+ def save_config (self , evt = None , fname = 'wxmplot' ):
132+ conf = self .conf .get_config ()
133+ title = conf .get ('title' , '' ).strip ()
134+ if len (title ) < 2 :
135+ title = fname
136+ fname = fix_filename (f'{ title } .yaml' )
137+
132138 file_choices = 'YAML Config File (*.yaml)|*.yaml'
133139 dlg = wx .FileDialog (self , message = 'Save plot configuration' ,
134140 defaultDir = get_cwd (),
@@ -137,10 +143,11 @@ def save_config(self, evt=None, fname='wxmplot.yaml'):
137143 style = wx .FD_SAVE | wx .FD_CHANGE_DIR )
138144
139145 if dlg .ShowModal () == wx .ID_OK :
140- conf = self .conf .get_current_config ()
141- ppath = os .path .abspath (dlg .GetPath ())
146+ conf = self .conf .get_config ()
147+ text = yaml .dump (conf , default_flow_style = None , indent = 13 , sort_keys = False )
148+ ppath = Path (dlg .GetPath ())
142149 with open (ppath , 'w' , encoding = 'utf-8' ) as fh :
143- fh .write ("%s \n " % yaml . dump ( conf ) )
150+ fh .write (f" { text } \n " )
144151
145152
146153 def load_config (self , evt = None ):
@@ -151,7 +158,7 @@ def load_config(self, evt=None):
151158 style = wx .FD_OPEN )
152159
153160 if dlg .ShowModal () == wx .ID_OK :
154- conf = yaml .safe_load (open (os . path . abspath (dlg .GetPath ()), 'r' ).read ())
161+ conf = yaml .safe_load (open (Path (dlg .GetPath ()), 'r' ).read ())
155162 self .conf .load_config (conf )
156163
157164 def DrawPanel (self ):
0 commit comments