File: KCWin.pl

package info (click to toggle)
kildclient 2.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 5,016 kB
  • ctags: 1,649
  • sloc: ansic: 22,284; xml: 6,381; sh: 4,266; perl: 2,213; makefile: 178
file content (107 lines) | stat: -rw-r--r-- 3,171 bytes parent folder | download | duplicates (2)
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
package KCWin;
#: Version: 2.0.0
#: Description: Creates general-purpose windows with an input and output area
#: Author: Eduardo M Kalinowski
#
# $Id: KCWin.pl,v 1.2 2005/06/24 12:52:01 ekalin Exp $

BEGIN {
  eval "use Gtk2";
  die "This plugin requires the gtk2-perl bindings" if $@;
}


use base 'Gtk2::Window';


sub help {
  $::world->echonl(<<'EOHELP');
    This plugin defines a new type, KCWin, which is a small window
with an area for output and an entry box for input. These windows do
nothing by themselves, but they can be used by other plugins when they
need a window for input and output. The output area supports ANSI
colors and thus is like a mini MUD window.

    Use KCWin->new to create a new window. KCWin derives from Gtk2::Window
so you can use all of its methods.

    The widgets are accessible for customization. If $kcw is a KCWin, the
following widgets are available:

- $kcw->{VBOX}, Gtk2::VBox, the vertical box that contains the output and
  input areas.
- $kcw->{SCROLLWIN}, Gtk2::ScrolledWindow, this holds the TextView that
  is used for output.
- $kcw->{TEXTVIEW}, Gtk2::TextView, is the widget used for output.
- $kcw->{TEXTBUFFER}, Gtk2::TextBuffer, for convenience, the TextBuffer
  displayed in the window.
- $kcw->{CMDAREA}, Gtk2::HBox, a box that holds a button to clear the
  input area, and the input area itself.
- $kcw->{BTNCLEAR}, Gtk2::Button, a button that clears the input entry
  widget when clicked.
- $kcw->{ENTRY}, Gtk2::Entry, the input entry widget. Connect to the
  activate signal of this widget to do something when the user presses
  ENTER in this widget.

    The widgets can be used, and the window can be customized (by adding
other widgets, for example). Three common actions have functions in
KCWin as a shortcut:

$text = KCWin::get_text
    Returns the text in the entry box.

KCWin::set_text($text)
    Sets the text in the entry box.

KCWin::feed($text)
    Appends text to the output terminal widget. $text can contain ANSI
    color sequences. The colorize function can be useful in conjuntion
    with this function.
EOHELP
}


sub new {
  my $class = shift;

  my ($windowPTR,
      $vboxPTR, $scrollwinPTR, $txtViewPTR, $txtBufferPTR,
      $cmdareaPTR, $btnclearPTR, $entryPTR,
      $guiPTR) = KCWin::_new;

  my $self = bless Glib::Object->new_from_pointer($windowPTR),
                   $class;
  $self->{VBOX}       = Glib::Object->new_from_pointer($vboxPTR);
  $self->{SCROLLWIN}  = Glib::Object->new_from_pointer($scrollwinPTR);
  $self->{TEXTVIEW}   = Glib::Object->new_from_pointer($txtViewPTR);
  $self->{TEXTBUFFER} = Glib::Object->new_from_pointer($txtBufferPTR);
  $self->{CMDAREA}    = Glib::Object->new_from_pointer($cmdareaPTR);
  $self->{BTNCLEAR}   = Glib::Object->new_from_pointer($btnclearPTR);
  $self->{ENTRY}      = Glib::Object->new_from_pointer($entryPTR);
  $self->{_GUIPTR}    = $guiPTR;

  return $self;
}


sub destroy {
  my $self = shift;

  $self->_destroy();
  $self->SUPER::destroy();
}


sub get_text {
  my $self = shift;

  return $self->{ENTRY}->get_text;
}


sub set_text {
  my $self = shift;
  my ($text) = @_;

  return $self->{ENTRY}->set_text($text);
}