@@ -112,8 +112,18 @@ def __init__(self, parent=None, config=None, trace_color_callback=None):
112112 self .axes = self .canvas .figure .get_axes ()
113113 self .conf .relabel ()
114114 self .show_legend_cbs = []
115+ self .wids = {}
115116 self .DrawPanel ()
116-
117+ mbar = wx .MenuBar ()
118+ fmenu = wx .Menu ()
119+ MenuItem (self , fmenu , "Save Configuration\t Ctrl+S" ,
120+ "Save Configuration" ,
121+ self .save_config )
122+ MenuItem (self , fmenu , "Load Configuration\t Ctrl+R" ,
123+ "Load Configuration" ,
124+ self .load_config )
125+ mbar .Append (fmenu , 'File' )
126+ self .SetMenuBar (mbar )
117127
118128 def DrawPanel (self ):
119129 style = wx .DEFAULT_FRAME_STYLE
@@ -150,6 +160,55 @@ def DrawPanel(self):
150160 self .SetSize ((1050 , 475 ))
151161 self .Show ()
152162
163+ def save_config (self , evt = None ):
164+ self .conf .panel .config_save_dialog ()
165+
166+ def load_config (self , evt = None ):
167+ confdict = self .conf .panel .config_load_dialog ()
168+
169+ # check boxes
170+ for attr in ('auto_margins' , 'hidewith_legend' ,
171+ 'show_grid' , 'show_legend' , 'show_legend_frame' ):
172+ self .wids [attr ].SetValue (confdict [attr ])
173+ self .wids ['show_legend_2' ].SetValue (confdict ['show_legend' ])
174+ self .wids ['axes_style' ].SetValue ('box' == confdict ['axes_style' ])
175+
176+ # choices
177+ for attr in ('theme' , 'legend_loc' , 'legend_onaxis' , 'zoom_style' ):
178+ self .wids [attr ].SetStringSelection (confdict [attr ])
179+
180+ xscale = confdict ['xscale' ]
181+ yscale = confdict ['yscale' ]
182+ self .wids ['logchoice' ].SetStringSelection (f"x { xscale } / y { yscale } " )
183+
184+ # colors
185+ for attr in ('facecolor' , 'textcolor' , 'framecolor' , 'gridcolor' ,
186+ 'scatter_normalcolor' , 'scatter_normaledge' ,
187+ 'scatter_selectcolor' , 'scatter_selectedge' ):
188+ self .wids [attr ].SetColour (confdict [attr ])
189+
190+ # floats
191+ for attr in ('labelfont' , 'legendfont' , 'titlefont' ,
192+ 'viewpad' , 'scatter_size' ):
193+ self .wids [attr ].SetValue (confdict [attr ])
194+
195+ margin_vals = confdict ['margins' ]
196+ for i in range (4 ):
197+ self .wids ['margins' ][i ].SetValue (margin_vals [i ])
198+
199+ for i , trace in enumerate (confdict ['traces' ]):
200+ w = self .wids [f'trace_{ i } ' ]
201+ w ['color' ].SetColour (trace ['color' ])
202+ w ['style' ].SetStringSelection (trace ['style' ])
203+ w ['marker' ].SetStringSelection (trace ['marker' ])
204+ w ['drawstyle' ].SetStringSelection (trace ['drawstyle' ])
205+ w ['linewidth' ].SetValue (trace ['linewidth' ])
206+ w ['alpha' ].SetValue (trace ['alpha' ])
207+ w ['markersize' ].SetValue (trace ['markersize' ])
208+ w ['zorder' ].SetValue (trace ['zorder' ])
209+ w ['fill' ].SetValue (trace ['fill' ])
210+
211+
153212 def make_range_panel (self , parent , font = None ):
154213 # bounds, margins, scales
155214 panel = wx .Panel (parent )
@@ -163,6 +222,7 @@ def make_range_panel(self, parent, font=None):
163222 logchoice = wx .Choice (panel , choices = self .conf .log_choices , size = (200 ,- 1 ))
164223 logchoice .SetStringSelection ("x %s / y %s" % (self .conf .xscale , self .conf .yscale ))
165224 logchoice .Bind (wx .EVT_CHOICE , self .onLogScale )
225+ self .wids ['logchoice' ] = logchoice
166226
167227 sizer .Add (mtitle , (1 , 0 ), (1 ,1 ), labstyle , 2 )
168228 sizer .Add (logchoice , (1 , 1 ), (1 ,3 ), labstyle , 2 )
@@ -171,6 +231,8 @@ def make_range_panel(self, parent, font=None):
171231 # Zoom
172232 ztitle = wx .StaticText (panel , - 1 , 'Zoom Style: ' )
173233 zoomchoice = wx .Choice (panel , choices = self .conf .zoom_choices , size = (200 ,- 1 ))
234+ self .wids ['zoom_style' ] = zoomchoice
235+
174236 if self .conf .zoom_style in self .conf .zoom_choices :
175237 zoomchoice .SetStringSelection (self .conf .zoom_style )
176238 zoomchoice .Bind (wx .EVT_CHOICE , self .onZoomStyle )
@@ -256,6 +318,7 @@ def make_range_panel(self, parent, font=None):
256318 self .vpad_val = FloatSpin (panel , value = 2.5 , min_val = 0 , max_val = 100 ,
257319 increment = 0.5 , digits = 2 ,
258320 size = (FSPINSIZE , - 1 ), action = self .onViewPadEvent )
321+ self .wids ['viewpad' ] = self .vpad_val
259322
260323 if user_lims == 4 * [None ]:
261324 [w .Disable () for w in self .xbounds ]
@@ -335,6 +398,8 @@ def showtext(t):
335398 auto_m = wx .CheckBox (panel ,- 1 , ' Default ' , (- 1 , - 1 ), (- 1 , - 1 ))
336399 auto_m .Bind (wx .EVT_CHECKBOX ,self .onAutoMargin )
337400 auto_m .SetValue (self .conf .auto_margins )
401+ self .wids ['auto_margins' ] = auto_m
402+ self .wids ['margins' ] = (lmarg , rmarg , bmarg , tmarg )
338403
339404 msizer = wx .BoxSizer (wx .HORIZONTAL )
340405 msizer .AddMany ((ltitle , lmarg , rtitle , rmarg ,
@@ -386,6 +451,13 @@ def make_scatter_panel(self, parent, font=None):
386451 mpl_color (conf .scatter_selectedge ,
387452 default = (200 , 0 , 0 )),
388453 size = (25 , 25 ))
454+
455+ self .wids ['scatter_size' ] = ssize
456+ self .wids ['scatter_normalcolor' ] = nfcol
457+ self .wids ['scatter_normaledge' ] = necol
458+ self .wids ['scatter_selectcolor' ] = sfcol
459+ self .wids ['scatter_selectedge' ] = secol
460+
389461 nfcol .Bind (csel .EVT_COLOURSELECT , partial (self .onScatter , item = 'scatt_nf' ))
390462 necol .Bind (csel .EVT_COLOURSELECT , partial (self .onScatter , item = 'scatt_ne' ))
391463 sfcol .Bind (csel .EVT_COLOURSELECT , partial (self .onScatter , item = 'scatt_sf' ))
@@ -495,6 +567,10 @@ def make_text_panel(self, parent, font=None):
495567 self .title_fontsize = ttl_size
496568 self .legend_fontsize = leg_size
497569 self .label_fontsize = lab_size
570+ self .wids ['titlefont' ] = ttl_size
571+ self .wids ['labelfont' ] = lab_size
572+ self .wids ['legendfont' ] = leg_size
573+
498574
499575 sizer .Add (t0 , (irow , 0 ), (1 , 1 ), labstyle )
500576 sizer .Add (t1 , (irow , 1 ), (1 , 1 ), labstyle )
@@ -537,6 +613,12 @@ def make_text_panel(self, parent, font=None):
537613 show_lfr .Bind (wx .EVT_CHECKBOX ,partial (self .onShowLegend ,item = 'frame' ))
538614 show_lfr .SetValue (self .conf .show_legend_frame )
539615
616+ self .wids ['hidewith_legend' ] = togg_leg
617+ self .wids ['legend_loc' ] = leg_loc
618+ self .wids ['legend_onaxis' ] = leg_onax
619+ self .wids ['show_legend_2' ] = show_leg
620+ self .wids ['show_legend_frame' ] = show_lfr
621+
540622 lsizer = wx .BoxSizer (wx .HORIZONTAL )
541623
542624 lsizer .AddMany ((leg_ttl , show_leg , show_lfr , togg_leg ))
@@ -566,7 +648,7 @@ def make_linetrace_panel(self, parent, font=None):
566648 theme_names = list (cnf .themes .keys ())
567649 themechoice = Choice (panel , choices = theme_names , action = self .onTheme )
568650 themechoice .SetStringSelection (cnf .current_theme )
569-
651+ self . wids [ 'theme' ] = themechoice
570652
571653 textcol = csel .ColourSelect (panel , label = " Text " , size = (80 , - 1 ),
572654 colour = mpl_color (cnf .textcolor ))
@@ -577,8 +659,8 @@ def make_linetrace_panel(self, parent, font=None):
577659 fbgcol = csel .ColourSelect (panel , label = " Frame " , size = (80 , - 1 ),
578660 colour = mpl_color (self .canvas .figure .get_facecolor ()))
579661
580- self .colwids = { 'text ' : textcol , 'face ' : bgcol ,
581- 'grid ' : gridcol , 'frame ' : fbgcol }
662+ self .wids . update ({ 'textcolor ' : textcol , 'facecolor ' : bgcol ,
663+ 'gridcolor ' : gridcol , 'framecolor ' : fbgcol })
582664
583665 bgcol .Bind (csel .EVT_COLOURSELECT , partial (self .onColor , item = 'face' ))
584666 fbgcol .Bind (csel .EVT_COLOURSELECT , partial (self .onColor , item = 'frame' ))
@@ -588,16 +670,19 @@ def make_linetrace_panel(self, parent, font=None):
588670 show_grid = wx .CheckBox (panel ,- 1 , ' Show Grid ' )
589671 show_grid .Bind (wx .EVT_CHECKBOX ,self .onShowGrid )
590672 show_grid .SetValue (cnf .show_grid )
673+ self .wids ['show_grid' ] = show_grid
591674
592675 show_box = wx .CheckBox (panel ,- 1 , ' Show Top/Right Axes ' )
593676 show_box .Bind (wx .EVT_CHECKBOX , self .onShowBox )
594677 show_box .SetValue (cnf .axes_style == 'box' )
678+ self .wids ['axes_style' ] = show_box
595679
596680 show_leg = wx .CheckBox (panel ,- 1 , 'Show Legend ' )
597681 show_leg .Bind (wx .EVT_CHECKBOX ,partial (self .onShowLegend , item = 'legend' ))
598682 show_leg .SetValue (cnf .show_legend )
599683 if show_leg not in self .show_legend_cbs :
600684 self .show_legend_cbs .append (show_leg )
685+ self .wids ['show_legend' ] = show_leg
601686
602687 tsizer = wx .BoxSizer (wx .HORIZONTAL )
603688 tsizer .Add (wx .StaticText (panel , - 1 , ' Theme: ' ), 0 , labstyle , 3 )
@@ -632,10 +717,12 @@ def make_linetrace_panel(self, parent, font=None):
632717 tsizer .Add (wx .StaticText (panel , - 1 , ' Symbol Size: ' ), 0 , labstyle , 3 )
633718 tsizer .Add (msz , 0 , labstyle , 3 )
634719
720+ self .wids ['def_thickness' ] = allthk
721+ self .wids ['def_markersize' ] = msz
722+
635723 sizer .Add (tsizer , (3 , 0 ), (1 , 9 ), labstyle , 3 )
636724
637725 irow = 4
638-
639726 for t in ('#' ,'Label' ,'Color' , 'Alpha' , 'Fill' , 'Line Style' ,
640727 'Thickness' , 'Symbol' ,
641728 'Size' , 'Z Order' , 'Join Style' ):
@@ -668,8 +755,6 @@ def make_linetrace_panel(self, parent, font=None):
668755 col = csel .ColourSelect (panel , - 1 , "" , dcol , size = (25 , 25 ))
669756 col .Bind (csel .EVT_COLOURSELECT , partial (self .onColor , trace = i ))
670757
671- self .colwids [i ] = col
672-
673758 thk = FloatSpin (panel , size = (ISPINSIZE , - 1 ), value = dthk ,
674759 min_val = 0 , max_val = 20 , increment = 0.5 , digits = 1 ,
675760 action = partial (self .onThickness , trace = i ))
@@ -705,6 +790,12 @@ def make_linetrace_panel(self, parent, font=None):
705790 action = partial (self .onAlpha , trace = i ))
706791
707792
793+ self .wids [f'trace_{ i } ' ] = {'color' : col , 'alpha' : alp , 'fill' : ffil ,
794+ 'style' : sty , 'linewidth' : thk ,
795+ 'marker' : sym , 'markersize' : msz ,
796+ 'zorder' : zor , 'drawstyle' : jsty }
797+
798+
708799 sizer .Add (lab .label ,(irow ,0 ),(1 ,1 ),wx .ALIGN_LEFT | wx .ALL , 4 )
709800 sizer .Add (lab , (irow ,1 ),(1 ,1 ),wx .ALIGN_LEFT | wx .ALL , 4 )
710801 sizer .Add (col , (irow ,2 ),(1 ,1 ),wx .ALIGN_LEFT | wx .ALL , 4 )
@@ -734,7 +825,7 @@ def onColor(self, event=None, color=None, item='trace', trace=1, draw=True):
734825
735826 if item == 'trace' :
736827 self .conf .set_trace_color (color , trace = trace )
737- self .colwids [ trace ].SetColour (color )
828+ self .wids [ f'trace_ { trace } ' ][ 'color' ].SetColour (color )
738829 if self .conf .show_legend :
739830 self .conf .draw_legend ()
740831
@@ -754,10 +845,10 @@ def onTheme(self, event):
754845 theme = event .GetString ()
755846 conf = self .conf
756847 conf .set_theme (theme = theme )
757- self .colwids [ 'text ' ].SetColour (conf .textcolor )
758- self .colwids [ 'grid ' ].SetColour (conf .gridcolor )
759- self .colwids [ 'face ' ].SetColour (conf .facecolor )
760- self .colwids [ 'frame ' ].SetColour (conf .framecolor )
848+ self .wids [ 'textcolor ' ].SetColour (conf .textcolor )
849+ self .wids [ 'gridcolor ' ].SetColour (conf .gridcolor )
850+ self .wids [ 'facecolr ' ].SetColour (conf .facecolor )
851+ self .wids [ 'framecolor ' ].SetColour (conf .framecolor )
761852
762853 self .title_fontsize .SetValue (self .conf .titlefont .get_size ())
763854 self .legend_fontsize .SetValue (self .conf .legendfont .get_size ())
@@ -766,9 +857,9 @@ def onTheme(self, event):
766857 for i in range (ntrace_display ):
767858 try :
768859 lin = self .conf .traces [i ]
769- curcol = hexcolor (self .colwids [ i ].GetColour ())
860+ curcol = hexcolor (self .wids [ f'trace_ { i } ' ][ 'color' ].GetColour ())
770861 newcol = hexcolor (lin .color )
771- self .colwids [ i ].SetColour (newcol )
862+ self .wids [ f'trace_ { i } ' ][ 'color' ].SetColour (newcol )
772863 if newcol != curcol :
773864 self .conf .set_trace_color (newcol , trace = i )
774865 except KeyError :
0 commit comments