File: EchoArea.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 (218 lines) | stat: -rw-r--r-- 4,549 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
package Demeter::UI::Wx::EchoArea;

=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 Wx qw( :everything );
##use Wx::Event qw(EVT_KEY_DOWN);
use base 'Wx::Panel';

my @buffer;

sub new {
  my ($class, $parent) = @_;
#  $maxlength ||= 0;
  my $self = $class->SUPER::new($parent, -1);
  my $sizer = Wx::BoxSizer->new( wxHORIZONTAL );
  $self->{prompt} = Wx::StaticText->new($self, -1, q{});
  $self->{text}   = Wx::TextCtrl($self, -1, q{}, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
  $sizer->Add($self->{prompt}, 0, wxALL, 0);
  $sizer->Add($self->{text},   1, wxALL, 0);
  $self->{prompt}->Hide;
  $self->SetSizerAndFit($sizer);
  #$self->SetFont( Wx::Font->new( 16, wxDEFAULT, wxNORMAL, wxBOLD, 0, "" ) );
  return $self;
};

sub SetStatusText {

};
sub PopStatusText {

};
sub PushStatusText {

};


sub echo {
  my ($self, $string) = @_;
  ## set default colors
  $self->SetValue($string);
  push @buffer, $string if $string !~ m{\A\s*\z};
#  if ($self->{maxlength} and ($#buffer >= $self->{maxlength})) {
#    shift @buffer;
#  };
  return $self;
};

sub buffer {
  my ($self) = @_;
  return @buffer;
};
sub buffer_as_text {
  my ($self) = @_;
  return join("\n", @buffer);
};

sub Length {
  my ($self) = @_;
  return $#buffer;
}

sub clear {
  my ($self) = @_;
  @buffer = ();
  $self->SetValue(q{});
  return $self;
};

sub Warn {
  my ($self, $string) = @_;
  ## change the colors
  $self->echo($string);
  return $self;
};

sub Error {
  my ($self, $string) = @_;
  ## change the colors
  $self->echo($string);
  return $self;
};

1;

=head1 NAME

Demeter::UI::Wx::EchoArea - A run-time feedback widget

=head1 VERSION

This documentation refers to Demeter version 0.9.26.

=head1 SYNOPSIS

An echo area an be added to a Wx application:

  my $echoarea = Demeter::UI::Wx::EchoArea->new($self);
  $sizer -> Add($echoarea, 0, wxEXPAND|wxALL, 3);

The argument to the constructor method is a reference to the parent in
which this is placed.  This is used as the echo area for all
Hephaestus utilities.

=head1 DESCRIPTION

This is derived from Wx::TextCrtl and is intended to serve as an echo
area in a Wx application in much the similar fashion as Emacs' echo
area.

=head1 METHODS

=over 4

=item C<echo>

Insert text into the echo area and push that text onto the echo buffer.

  $echoarea->echo("Hi there!");

To clear the echo area without clearing the echo buffer, give this
method an empty string:

  $echoarea->echo(q{});

This method returns the reference to the EchoArea widget.

=item C<buffer>

Return the contents of the echo buffer as an array.

  @contents = $echoarea->buffer;

=item C<buffer_as_text>

Return the contents of the echo buffer as a simply formatted text string.

  $contents = $echoarea->buffer_as_text;

=item C<Length>

Return the length of echo buffer.

  $len = $echoarea->Length

=item C<clear>

Clear the echo area and empty the echo buffer.

  $echoarea->clear;

This method returns the reference to the EchoArea widget.

=back

=head1 CONFIGURATION


=head1 DEPENDENCIES

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

=head1 BUGS AND LIMITATIONS

=over 4

=item *

Artemis & Athena will require a data entry mode.  That could be done
by liftingt he readonly flag, changing the background color, and
grabbing focus until carriage return is pressed.

=item *

Need configurable text color and max length.  Need warn and error
modes and configurable colors for those.

=back

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