File: Config.pm

package info (click to toggle)
libdemeter-perl 0.9.27%2Bds6-9
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 74,028 kB
  • sloc: perl: 73,233; python: 2,196; makefile: 1,999; ansic: 1,368; lisp: 454; sh: 74
file content (663 lines) | stat: -rw-r--r-- 24,384 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
package Demeter::UI::Wx::Config;

=for Copyright
 .
 Copyright (c) 2006-2019 Bruce Ravel (http://bruceravel.github.io/home).
 All rights reserved.
 .
 This file is free software; you can redistribute it and/or
 modify it under the same terms as Perl itself. See The Perl
 Artistic License.
 .
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

=cut

use strict;
use warnings;
use Carp;
use File::Basename;
use List::MoreUtils qw(firstidx uniq);
use Text::Wrap;

use Wx qw( :everything );
use Wx::Event qw(EVT_BUTTON EVT_TREE_SEL_CHANGED EVT_TEXT_ENTER EVT_FONTPICKER_CHANGED);

use Demeter qw(:none);

use Demeter::UI::Wx::VerbDialog;
use Demeter::UI::Wx::Colours;
use Demeter::UI::Wx::ColourDatabase;
my $cdb = Demeter::UI::Wx::ColourDatabase->new;
my $aleft = Wx::TextAttr->new();
$aleft->SetAlignment(wxTEXT_ALIGNMENT_LEFT);

use base 'Wx::Panel';

sub new {
  my ($class, $parent, $callback, $main) = @_;
  my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxMAXIMIZE_BOX );
  $self->{parent}=$parent;

  my $mainsizer = Wx::BoxSizer->new( wxHORIZONTAL );
  $self -> SetSizer($mainsizer);

  my $font = wxNullFont;
  $font->SetStyle(wxBOLD);

  ## -------- list of parameters
  $self->{paramsbox} = Wx::StaticBox->new($self, -1, 'Parameters', wxDefaultPosition, wxDefaultSize);
  $self->{paramsboxsizer} = Wx::StaticBoxSizer->new( $self->{paramsbox}, wxVERTICAL );
  my $style = (Demeter->is_windows) ? wxTR_SINGLE|wxTR_HAS_BUTTONS : wxTR_SINGLE|wxTR_HAS_BUTTONS|wxTR_HIDE_ROOT;
  $self->{params} = Wx::TreeCtrl->new($self, -1, wxDefaultPosition, wxDefaultSize, $style);
  $self->{paramsboxsizer} -> Add($self->{params}, 1, wxEXPAND|wxALL, 0);
  $mainsizer -> Add($self->{paramsboxsizer}, 1, wxEXPAND|wxALL, 5);
  EVT_TREE_SEL_CHANGED( $self, $self->{params}, \&tree_select );

  my $right = Wx::BoxSizer->new( wxVERTICAL );
  $mainsizer -> Add($right, 3, wxEXPAND|wxALL, 5);

  ## -------- Grid of controls
  $self->{grid} = Wx::GridBagSizer -> new(5,10);

  my $this = Wx::GBPosition->new(0, 0);
  my $label = Wx::StaticText->new( $self, -1, 'Selection');
  $label -> SetFont( $font );
  $self->{grid} -> Add($label, $this); # wxDefaultSpan, wxALIGN_CENTER);
  $this = Wx::GBPosition->new(0, 1);
  my $span       = Wx::GBSpan->new(1,4);
  $self->{Name}  = Wx::StaticText->new( $self, -1, q{});
  $self->{grid} -> Add($self->{Name}, $this, $span);

  $this = Wx::GBPosition->new(1, 0);
  $label = Wx::StaticText->new( $self, -1, 'Type');
  $label -> SetFont( $font );
  $self->{grid} -> Add($label, $this);
  $this = Wx::GBPosition->new(1, 1);
  $self->{Type} = Wx::StaticText->new( $self, -1, q{});
  $self->{grid} -> Add($self->{Type}, $this);

  $this = Wx::GBPosition->new(2, 0);
  $label = Wx::StaticText->new( $self, -1, 'Your value');
  $label -> SetFont( $font );
  $self->{grid} -> Add($label, $this);
  $this = Wx::GBPosition->new(2, 1);
  $self->{Value} = Wx::Button->new( $self, -1, q{});
  $self->{grid} -> Add($self->{Value}, $this);
  EVT_BUTTON( $self, $self->{Value}, sub{my($self, $event) = @_; set_value($self, $event, 'default')} );
  $self->{default_color} = $self->{Value}->GetBackgroundColour;

#   $this = Wx::GBPosition->new(2, 2);
#   $label = Wx::StaticText->new( $self, -1, q{      });
#   $self->{grid} -> Add($label, $this);

  $this = Wx::GBPosition->new(3, 0);
  $label = Wx::StaticText->new( $self, -1, 'Demeter\'s value');
  $label -> SetFont( $font );
  $self->{grid} -> Add($label, $this);
  $this = Wx::GBPosition->new(3, 1);
  $self->{Default} = Wx::Button->new( $self, -1, q{});
  $self->{grid} -> Add($self->{Default}, $this);
  EVT_BUTTON( $self, $self->{Default}, sub{my($self, $event) = @_; set_value($self, $event, 'demeter')} );

  $this = Wx::GBPosition->new(4, 0);
  $label = Wx::StaticText->new( $self, -1, 'Set');
  $label -> SetFont( $font );
  $self -> {grid} -> Add($label, $this);
  $self -> {SetPosition} = Wx::GBPosition->new(4, 1);
  $self -> set_stub;

  $right -> Add($self->{grid}, 0, wxEXPAND|wxALL, 10);

  ## -------- Description text
  $self->{descbox} = Wx::StaticBox->new($self, -1, 'Description', wxDefaultPosition, wxDefaultSize);
  $self->{descboxsizer} = Wx::StaticBoxSizer->new( $self->{descbox}, wxVERTICAL );
  $self->{desc} = Wx::TextCtrl->new($self, -1, q{}, wxDefaultPosition, wxDefaultSize,
				    wxHSCROLL|wxTE_WORDWRAP|wxTE_READONLY|wxTE_MULTILINE|wxTE_RICH2);
  $self->{descboxsizer} -> Add($self->{desc}, 1, wxEXPAND|wxALL, 2);
  $self->{desc}->SetFont( Wx::Font->new( Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)->GetPointSize, wxTELETYPE, wxNORMAL, wxNORMAL, 0, "" ) );
  $self->{desc}->SetDefaultStyle($aleft);
  $right -> Add($self->{descboxsizer}, 1, wxEXPAND|wxALL, 5);

  ## -------- Button box
  my $buttonbox = Wx::BoxSizer->new( wxHORIZONTAL );
  $self->{apply} = Wx::Button->new( $self, -1, 'Apply', wxDefaultPosition, wxDefaultSize );
  $buttonbox -> Add($self->{apply}, 1, wxEXPAND|wxALL, 5);
  $self->{save} = Wx::Button->new( $self, -1, 'Apply and Save', wxDefaultPosition, wxDefaultSize );
  $buttonbox -> Add($self->{save}, 1, wxEXPAND|wxALL, 5);
  $right -> Add($buttonbox, 0, wxEXPAND|wxALL, 0);

  #$self->{reset_all} = Wx::Button->new( $self, -1, 'Reset all parameters to Demeter\'s defaults', wxDefaultPosition, wxDefaultSize );
  #$right -> Add($self->{reset_all}, 0, wxEXPAND|wxALL, 5);


  EVT_BUTTON( $self, $self->{apply}, sub{my($self, $event) = @_; $self->apply($callback, 0)} );
  EVT_BUTTON( $self, $self->{save},  sub{my($self, $event) = @_; $self->apply($callback, 1)} );
  #EVT_BUTTON( $self, $self->{reset_all},  sub{my($self, $event) = @_; $self->reset_all($main)} );

  $self -> SetSizerAndFit($mainsizer);

  return $self;
};

sub populate {
  my ($self, $grouplist) = @_;

  $grouplist ||= 'all';
  my @grouplist;
  my @removelist;
  my @templist = (ref($grouplist) eq 'ARRAY') ? @$grouplist : ($grouplist);
  foreach my $t (@templist) {
    if ($t eq 'base') {
      push @grouplist,  @{ Demeter->co->main_groups };
    } elsif ($t eq 'all' ) {
      push @grouplist,  Demeter->co->groups;
    } elsif ($t =~ m{\A\!(\w+)}) {
      push @removelist, $1;
    } else {
      push @grouplist, $t;
    };
  };

  @grouplist = uniq(@grouplist);
#  print join(" ", @grouplist), $/;
#  print join(" ", @removelist), $/;
  if (@removelist) {
    my $regex = join("|", @removelist);
    @grouplist = grep { $_ !~ m{(?:$regex)}  } @grouplist;
  };

  my $root = $self->{params} -> AddRoot('Root');
  foreach my $g (@grouplist) {
    my @params = Demeter->co->parameters($g);
    my $branch = $self->{params} -> AppendItem($root, $g);
    map {$self->{params} -> AppendItem($branch, $_) if ($_ !~ m{\Ac\d{1,2}\z})} @params;
  };
  if ($#grouplist == 0) {
    $self->{params}->ExpandAll;
    my ($first, $toss) = $self->{params}->GetFirstChild($root);
    $self->{params}->SelectItem($first);
    my $this = $self->{params}->GetItemText( $self->{params}->GetSelection );
    $self->{desc}->Clear;
    {				# this shouldnot be necessary, why doesn't wrapping work in TextCtrl?
      local $Text::Wrap::columns = 47;
      $self->{desc}  -> WriteText(wrap(q{}, q{}, Demeter->co->description($this)));
    };
  };
};

sub tree_select {
  my ($self, $event) = @_;
  my $clickedon = $event->GetItem;
  my $param     = $self->{params}->GetItemText($clickedon);
  my $parent    = q{};
  my $is_parent = $self->{params}->ItemHasChildren($clickedon);
  $self->{desc}->Clear;
  $self->{grid}->Detach($self->{Set});
  $self->{Set} ->Destroy;
  $self->{grid}->Layout;

  if (not $is_parent) {
    $parent = $self->{params}->GetItemParent($clickedon);
    $parent = $self->{params}->GetItemText($parent);

    my $description = Demeter->co->description($parent, $param);
    if (Demeter->co->units($parent, $param)) {
      $description .= $/ x 3 . "Units: " . Demeter->co->units($parent, $param);
    };
    if (Demeter->co->restart($parent, $param)) {
      $description .= $/ x 3 . "A change in this parameter will take effect the next time you start this application.";
    };
    {				# this shouldnot be necessary, why doesn't wrapping work in TextCtrl?
      local $Text::Wrap::columns = 47;
      $self->{desc}  -> WriteText(wrap(q{}, q{}, $description));
    };
    $self->{Name}  -> SetLabel(join(' --> ', $parent, $param));
    $self->{Type}  -> SetLabel(Demeter->co->Type($parent, $param));
    my $type = Demeter->co->Type($parent, $param);

    if ($type eq 'boolean') {
      $self->{Value}   -> SetLabel(Demeter->truefalse( Demeter->co->default($parent, $param) ));
      $self->{Default} -> SetLabel(Demeter->truefalse( Demeter->co->demeter($parent, $param) ));
    } else {
      $self->{Value} -> SetLabel(Demeter->co->default($parent, $param));
      $self->{Default} -> SetLabel(Demeter->co->demeter($parent, $param));
    };
    $self->{Value}   -> SetOwnBackgroundColour($wxBGC);
    $self->{Value}   -> Enable;
    $self->{Default} -> SetOwnBackgroundColour($wxBGC);
    $self->{Default} -> Enable;
    $self->{apply}   -> Enable;
    $self->{save}    -> Enable;
    $self->{apply}   -> Disable if Demeter->co->restart($parent, $param);

  WIDGET: {
      $self->set_string_widget($parent, $param, $type), last WIDGET if ($type =~ m{(?:string|real|regex|absolute energy)});
      $self->set_list_widget($parent, $param),          last WIDGET if ($type eq 'list');
      $self->set_spin_widget($parent, $param),          last WIDGET if ($type eq 'positive integer');
      $self->set_boolean_widget($parent, $param),       last WIDGET if ($type eq 'boolean');
      $self->set_color_widget($parent, $param),         last WIDGET if ($type eq 'color');
      $self->set_font_widget($parent, $param),          last WIDGET if ($type eq 'font');
      $self->set_file_widget($parent, $param),          last WIDGET if ($type eq 'file');

      ## fall back
      $self->set_stub;
    };

  } else {
    $self->set_stub;
    $self->{Name}    -> SetLabel($param);
    $self->{Type}    -> SetLabel('Parameter group');
    $self->{Value}   -> SetLabel(q{});
    $self->{Value}   -> SetOwnBackgroundColour($wxBGC);
    $self->{Value}   -> Disable;
    $self->{Default} -> SetLabel(q{});
    $self->{Default} -> SetOwnBackgroundColour($wxBGC);
    $self->{Default} -> Disable;
    { # this shouldnot be necessary, why doesn't wrapping work in TextCtrl?
      local $Text::Wrap::columns = 47;
      $self->{desc}  -> WriteText(wrap(q{}, q{}, Demeter->co->description($param)));
    };
    $self->{apply}   -> Disable;
    $self->{save}    -> Disable;
  };
  $self->{grid} -> Add($self->{Set}, $self->{SetPosition});
  $self->{grid} -> Layout;

}


sub apply {
  my ($self, $callback, $save) = @_;
  my $selected = $self->{params}->GetSelection;
  my $param    = $self->{params}->GetItemText($selected);
  my $parent   = $self->{params}->GetItemParent($selected);
  $parent      = $self->{params}->GetItemText($parent);

  my $value;
  my $type = Demeter->co->Type($parent, $param);
 WIDGET: {
    $value = $self->{Set}->GetValue,           last WIDGET if ($type =~ m{(?:string|real|regex|absolute energy)});
    $value = $self->{Set}->GetPath,            last WIDGET if ($type eq 'file');
    $value = $self->{Set}->GetStringSelection, last WIDGET if ($type eq 'list');
    $value = $self->{Set}->GetValue,           last WIDGET if ($type eq 'positive integer');
    $value = Demeter->onezero($self->{Set}->GetValue), last WIDGET if ($type eq 'boolean');
    $value = $self->{Set}->GetColour->GetAsString(wxC2S_HTML_SYNTAX), last WIDGET if ($type eq 'color');
    if ($type eq 'font') {
      $value = $self->{Set}->GetSelectedFont->GetNativeFontInfoDesc;
      $value =~ s{\s+\d+\z}{};
      last WIDGET;
    };
  };

  Demeter->co->set_default($parent, $param, $value);
  if ($type eq 'boolean') {
    $self->{Value}   -> SetLabel(Demeter->truefalse( Demeter->co->default($parent, $param) ));

  } elsif ($type eq 'color') {
    my $color;
    my $this = Demeter->co->default($parent, $param);
    if ($this =~ m{\A\#}) {
      my $col = Wx::Colour->new($this);
      $self->{Value} -> SetBackgroundColour( $col );
      $color = $col;
    } else {
      $self->{Value} -> SetBackgroundColour( $cdb->Find($this) );
      $color = $cdb->Find($this);
    };

    $this = Demeter->co->demeter($parent, $param);
    if ($this =~ m{\A\#}) {
      my $col = Wx::Colour->new($this);
      $self->{Default}->SetBackgroundColour( $col );
    } else {
      $self->{Default}->SetBackgroundColour( $cdb->Find($this) );
    };

  } else {
    $self->{Value} -> SetLabel(Demeter->co->default($parent, $param));
  };
  Demeter->co->write_ini if $save;
  $self->$callback($parent, $param, $value, $save);
};

sub set_value {
  my ($self, $event, $which) = @_;
  my $selected = $self->{params}->GetSelection;
  my $param    = $self->{params}->GetItemText($selected);
  my $parent   = $self->{params}->GetItemParent($selected);
  $parent      = $self->{params}->GetItemText($parent);
  my $value    = Demeter->co->$which($parent, $param);
  #print join(" ", $which, $param, $parent, $value), $/;

  my $type = Demeter->co->Type($parent, $param);
 WIDGET: {
    $self->{Set}->SetValue($value),                     last WIDGET if ($type =~ m{(?:string|real|regex|absolute energy)});

    ($type eq 'list') and do {
      $self->{Set}->SetSelection(firstidx {$_ eq $value} split(" ", Demeter->co->options($parent, $param)));
      last WIDGET;
    };

    $self->{Set}->SetValue($value),                     last WIDGET if ($type eq 'positive integer');

    $self->{Set}->SetPath($value),                      last WIDGET if ($type eq 'file');

    $self->{Set}->SetValue(Demeter->onezero($value)),   last WIDGET if ($type eq 'boolean');

    ($type eq 'color') and do {
      if ($value =~ m{\A\#}) {
	my $col = Wx::Colour->new($value);
	$self->{Set}   -> SetColour( $col );
      } else {
	$self->{Set}   -> SetColour( $cdb->Find($value) );
      };
      last WIDGET;
    };

  };
};

sub set_stub {
  my ($self) = @_;
  $self->{Set} = Wx::StaticText->new( $self, -1, q{});
  return $self->{Set};
};

sub reset_all {
  my ($self, $main) = @_;
  my $yesno = Demeter::UI::Wx::VerbDialog->new($self, -1,
					       "Do you really wish to reset all parameters to their default values?  This will reset all parameters for Athena, Artemis, and Hephaestus without regard for any parameters you yourself may have set.",
					       "Really reset all parameters?",
					       "Reset");
  if ($yesno->ShowModal == wxID_NO) {
    $self->report($main, "Not resetting Demeter's configuration paremeters.");
    return;
  };
  Demeter->co->reset_all;
  $self->{params}->DeleteAllItems;
  $self->populate($main->{prefgroups});
  $self->{params}->Expand($self->{params}->GetRootItem);
  $self->report($main, "All configuration parameters have been reset to Demeter's defaults.");
  return;
};

sub report {
  my ($self, $main, $message) = @_;
  if (ref($main) =~ m{Hephaestus}) {
    $main->SetStatusText($message);
  } else {			# Atoms, Artemis, Athena
    $main->status($message);
  };
};


## x  string                Entry
## x  regex                 Entry
## x  real                  Entry  -- validates to accept only numbers
## x  positive integer      Entry with incrementers, restricted to be >= 0
## x  list                  Menubutton or some other multiple selection widget
## x  boolean               Checkbutton
##   keypress              Entry  -- rigged to display one character at a time
## x  color                 Button -- launches color browser
## x  font                  Button -- launches font picker control
## x  absolute energy

sub set_string_widget {
  my ($self, $parent, $param, $type) = @_;
  $self->{Value} -> SetBackgroundColour( $self->{default_color} );
  $self->{Default} -> SetBackgroundColour( $self->{default_color} );
  my $this = Demeter->co->default($parent, $param);
  $self->{Set} = Wx::TextCtrl->new( $self, -1, $this, [-1, -1], [200, -1], wxTE_PROCESS_ENTER );
  EVT_TEXT_ENTER($self, $self->{Set}, sub{1});
  ## use $type to set validation

  return $self->{Set};
};


sub set_list_widget {
  my ($self, $parent, $param) = @_;
  $self->{Value} -> SetBackgroundColour( $self->{default_color} );
  $self->{Default} -> SetBackgroundColour( $self->{default_color} );
  my @choices  = split(" ", Demeter->co->options($parent, $param));
  $self->{Set} = Wx::Choice->new( $self, -1, [-1, -1], [-1, -1], \@choices );
  my $value    = Demeter->co->default($parent, $param);
  $self->{Set}->SetSelection(firstidx {$_ eq $value} split(" ", Demeter->co->options($parent, $param)));
  return $self->{Set};
};

sub set_spin_widget {
  my ($self, $parent, $param) = @_;
  $self->{Value} -> SetBackgroundColour( $self->{default_color} );
  $self->{Default} -> SetBackgroundColour( $self->{default_color} );
  my $this = Demeter->co->default($parent, $param);
  $self->{Set} = Wx::SpinCtrl->new($self, -1, $this, wxDefaultPosition, [-1,-1]);
  $self->{Set} -> SetRange(Demeter->co->minint($parent, $param),
			   Demeter->co->maxint($parent, $param));
  return $self->{Set};
};

sub set_boolean_widget {
  my ($self, $parent, $param) = @_;
  $self->{Value} -> SetBackgroundColour( $self->{default_color} );
  $self->{Default} -> SetBackgroundColour( $self->{default_color} );
  my $this = Demeter->co->default($parent, $param);
  $self->{Set} = Wx::CheckBox->new($self, -1, $param, wxDefaultPosition, [-1,-1]);
  $self->{Set}->SetValue($this);
  return $self->{Set};
};

sub set_color_widget {
  my ($self, $parent, $param) = @_;

  my $color;
  my $this = Demeter->co->default($parent, $param);
  if ($this =~ m{\A\#}) {
    my $col = Wx::Colour->new($this);
    $self->{Value} -> SetBackgroundColour( $col );
    $color = $col;
  } else {
    $self->{Value} -> SetBackgroundColour( $cdb->Find($this) );
    $color = $cdb->Find($this);
  };

  $this = Demeter->co->demeter($parent, $param);
  if ($this =~ m{\A\#}) {
    my $col = Wx::Colour->new($this);
    $self->{Default}->SetBackgroundColour( $col );
  } else {
    $self->{Default}->SetBackgroundColour( $cdb->Find($this) );
  };

  $self->{Set} = Wx::ColourPickerCtrl->new( $self, -1, $color, [-1, -1],
					    [-1, -1] );

  #EVT_COLOURPICKER_CHANGED( $self, $self->{Set}, sub{ my ($self, $event) = @_; $self->color_picker; } );

  return $self->{Set};
};


sub set_font_widget {
  my ($self, $parent, $param) = @_;
  $self->{Value} -> SetBackgroundColour( $self->{default_color} );
  $self->{Default} -> SetBackgroundColour( $self->{default_color} );
  my $font = Wx::Font->new(10,
			   wxDEFAULT, wxNORMAL, wxNORMAL, 0,
			   Demeter->co->default($parent, $param));
  $self->{Set} = Wx::FontPickerCtrl->new($self, -1, $font, [-1,-1], [200,-1]);
  return $self->{Set};
};

sub set_file_widget {
  my ($self, $parent, $param) = @_;
  $self->{Value} -> SetBackgroundColour( $self->{default_color} );
  $self->{Default} -> SetBackgroundColour( $self->{default_color} );
  $self->{Set} = Wx::FilePickerCtrl->new($self, -1, Demeter->co->default($parent, $param), "Select a file for $param", "All files|*.*", [-1,-1], [200,-1]);
  #$self->{Set}->SetPath();
  return $self->{Set};
};


1;

=head1 NAME

Demeter::UI::Wx::Config - A configuration widget for Demeter applications

=head1 VERSION

This documentation refers to Demeter version 0.9.26.

=head1 SYNOPSIS

A configuration widget can be added to a Wx application:

  my $config = Demeter::UI::Wx::Config -> new($parent, \&callback);
  $sizer -> Add($config, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);

The first argument is the window in which the configuration widget is
to be packed.  The second is a reference to a callback that will be
called whenever a parameter is altered.

=head1 DESCRIPTION

This is a widget for managing the rather dizzying array of
configuration parameters controled by the L<Demeter::Config> object.
Creating and packing the widget will give your user a way of examining
the various parameters and and altering their values.

To use this widget, you must provide a reference to a callback that
will be called when a parameter value is changed.  For the example in
the synopsis, the callback will be called like so:

  $config -> &$callback($group, $parameter, $value, $save);

Thus the callback must be a method of the object using this widget.
The other things passed are the group and name of the configuration
parameter, its new value, and a flag which is true if the ini file was
saved.

=head1 METHODS

=over 4

=item populate

This is the only user servicable method of this widget.  It is used to
populate the parameter tree with the desired subset of parameters.

   $config->populate('all');
     or
   $config->populate('plot', 'bkg', 'fft', 'bft');
     or
   $config->populate('hephaestus');

The second example might be used for a simple Athena-like application
while the third example is what is actually used in Hephaestus.

=over 4

=item C<all>

Display all groups known to the Config object.

=item C<base>

Display all groups known that are part of Demeter's principle set of
groups.  Those are the ones that are imported into the Config object
regardless of what the application is.  As an example of the
difference between C<all> and C<base>, Hephaestus defines an
application-specific parameter group called C<hephaestus>.  The
C<hephaestus> group will be included in C<all> but not in C<base>.

=item a list of specific groups

The other option is to specify a list of one or more specific
parameter groups to display in the tree.

=back

The default is to display all groups.

=back

=head1 USING THE CONFIGURATION WIDGET

=head2 Using the tree

Each parameter group is displayed to the right of an expander button.
Under wxGtk, this is a little triangle that points down when the group
is expaned and to the right when the group is collapsed.  Click on
this button to open or close the parameter group.

When you click on a parameter group, its description will be displayed
in the description box.

When you click on a parameter from a group that has been expanded in
the list, its description will be displayed in the description box and
other information will be displayed in the other controls on the right
side of the window.

You can only alter the value of a parameter that is selected in the
tree.

=head2 Using the controls

A control appropriate to the type of widget will be displayed just
above the description box.  For many parameter types, this is a box
for entering text.  For integer-valued parameters, this is spin box
that you can alter by typing in it directly or by clicking the little
up and down arrows.  For true/false parameters, a check box is used.
For color-valued parameters, a button which pops up a color picker is
used.

The buttons labeled as "your value" and "Demeter's value" can be used
to restore the value of the control used to set the parameter value.
"Demeter's value" is the system-wide default read from Demeter's
configuration files, while the other value is the user's own value
read from the user's ini file.

=head2 Applying and saving parameter values

To alter a parameter value for use within the current instance of a
Demeter-based application, click the "Apply" button.  This will set
the current parameter value in the Config object.  To alter a
paremeter value I<and> save it for future use, click the button which
says "Apply and save".  This will also write out the user's ini file.

If a parameter is flagged as only taking effect when the application
is restarted, the "Apply" button will be disabled.

=head1 DEPENDENCIES

Demeter's dependencies are in the F<Build.PL> file.

=head1 BUGS AND LIMITATIONS

Please report problems to the Ifeffit Mailing List
(L<http://cars9.uchicago.edu/mailman/listinfo/ifeffit/>)

Patches are welcome.

=head1 AUTHOR

Bruce Ravel, L<http://bruceravel.github.io/home>

L<http://bruceravel.github.io/demeter/>

=head1 LICENCE AND COPYRIGHT

Copyright (c) 2006-2019 Bruce Ravel (L<http://bruceravel.github.io/home>). All rights reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlgpl>.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

=cut