[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:02049] Re: English Ruby/Gtk Tutorial?

From: Minero Aoki <aamine@...>
Date: 2000-03-21 09:22:32 UTC
List: ruby-talk #2049
Hi,

  In mail "[ruby-talk:02014] Re: English Ruby/Gtk Tutorial?"
    SUGIHARA Hiroshi (SuHi or SugHimsi) <manamist@white.diamond.ne.jp> wrote:

> SugHimsi(%HeIsSaidJustToLoseHisPatienceOnThisSubject;-).

> The entire documents (and their translators -- all non-native) are below:
> (((pressure?! :-):-):-)

^^;;;

> * clist.html         (aamine)
> * text.html          (aamine)

Then, here's my part.

Minero Aoki

#======================================================================
/nextfile clist.html

/chap CList widget

Gtk::CList is a multi-column list widget. It will replace Gtk::List class
(of course, Gtk::List is still available).

#----------------------------------------------------------------------
/section ex: Display Environmental Variables

Here is the simple example of CList class.
This program displayes all environmental variables.
<p>

/proginsert clist.rb

Result<br>
(attention: this result depends gtk-1.0.x. If you execute this program
 with version 1.2.x, little changes will be occur in look & feel.)<br>
<img src="imgs/clist.gif">
<p>

Discription<br>
<ul>
=c clist = Gtk::CList.new(['name', 'value'])
This creates a 2 columns CList widget object, which titles are
'name' and 'value'.

=c clist.set_usize(300, 200)
This set the widget 300 pixels width, 200 pixels height.

=c clist.set_column_width 0, 100
This set the first column 100 pixels width.
The index of the first column is 0.

=c ENV.keys.sort.each {|k| clist.append [k, ENV[k]]}
"ENV" is built-in constant of Ruby. It is (pseudo) Hash which contains
environment variable.
This adds the pair of one variable name and its value to list.
The length of array for "append" method must be equal to the number of
CList columns.
</ul>

#----------------------------------------------------------------------
/section Methods of CList Widget

<dl>
=d <code><b>Gtk::CList.new</b></code>(<i>columns</i>)
=d <code><b>Gtk::CList.new</b></code>([<i>'title1', 'title2', ... </i>])
<dd>
This method creates a CList widget.
When using first style, created CList have "columns" columns but no title.
When using second style, created CList have columns with title.

=d <code><b>set_policy</b></code>(<i>vscrollbar_policy</i>, <i>hscrollbar_polic
y</i>)

</dl>

#/write
#======================================================================
#=begin
/nextfile text.html

/chap Text Widget

#----------------------------------------------------------------------
/section Creating Text Widget

Gtk::Text is the widget to edit multi-lines text.
Gtk::Text.new creates Text widget.
<p>

/proginsert text.rb

Result<br>
<img src="imgs/text.gif">
<p>

Text widget doesn't receive user's input as default.
It is done by using "set_editable" method.

<pre>
text = Gtk::Text.new
text.set_editable true
</pre>

#----------------------------------------------------------------------
/section Using Scrollbar with Text Widget

Gtk::Adjustment class represents abstruct data structure to fetch
a part of fuge data (Gtk::Adjustment is NOT a widget).
<p>
Using the Gtk::Adjustment enable to scroll text in Text widget.
<p>
Here's a sample of Text widget with a scroll bar.
<p>

/proginsert text3.rb

Result<br>
<img src="imgs/text-scroll.gif">
<p>

Discription<br>
<ul>
=c vadj = Gtk::Adjustment.new(0,0,0,0,0,0)
This creates Adjustment object.
Both Text widget and Scrollbar widget owns this object.

=c text = Gtk::Text.new(nil, vadj)
This creates Text widget.
First argument is the Adjustment for horizontal direction, and
second is also the Adjustmen for vertical direction.
Argument "nil" means using default adjustments.
(attention: Text widget does not support horizontal Adjustment yet)

=c vs = Gtk::VScrollbar.new(vadj)
This creates scrollbar. VScrollbar is vertical scrollbar,
HScrollbar is horizontal one.
Argument "vadj" is the Adjustment object which is same one for Text widget.

=c hbox = Gtk::HBox.new(false, 0)
=c hbox.pack_start text, true, true, 0
=c hbox.pack_start vs, false, false, 0
This creates horizontal box and pack Text and Scrollbar.
</ul>

#----------------------------------------------------------------------
/section Methods of Text widget

Here's main methods of Text widget.

<dl>
=d <i>text</i>.<code><b>set_point</b>(<i>index</i>)</code>
<dd>
This method set the "inserting point".
<i>index</i> is the index of the string in Text widget.

=d <code><i>index</i> = <i>text</i>.<b>get_point</b></code>
<dd>
This method returns the current "inserting point".

=d <code><i>length</i> = <i>text</i>.<b>get_length</b></code>
<dd>
This method returns the length of the string in Text widget.
It also includes the length of carrige return or line feed.

=d <i>text</i>.<code><b>insert_text</b>(<i>chars</i>, <i>index</i>)</code>
<dd>
This method insert string to Text widget.
It is inherited from Gtk::Editable.
This insert the string <i>chars</i> into the <i>index</i>.

=d <i>text</i>.<code><b>get_chars</b>(<i>start_pos</i>, <i>end_pos</i>)</code>
<dd>
This method returns the string from <i>start_pos</i> to <i>end_pos</i>.
Gtk::Text.get_chars is inherited from Gtk::Editable.

=d <i>text</i>.<code><b>insert</b>(<i>font</i>, <i>fore</i>, <i>back</i>, <i>ch
ars</i>)</code>
<dd>
This method inserts string into current "inserting point".
Font, foreground color, Background color, can be designated.
<i>font</i> is Gdk::Font、<i>fore</i> and <i>back</i> is Gdk::Color object.
Argument "nil" for font/color means using default value (one of widget style).

=d <i>text</i>.<code><b>backward_delete</b>(<i>nchars</i>)</code>
=d <i>text</i>.<code><b>forward_delete</b>(<i>nchars</i>)</code>
<dd>
These methods delete <i>nchars</i> characters from current "inserting point".
"backward_delete" delete string from right to left.
"forward_delete" delete string from left to right.

</dl>

#/write

In This Thread