[#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:02055] Re: English Ruby/Gtk Tutorial?

From: SUGIHARA Hiroshi (SugHimsi) <manamist@...>
Date: 2000-03-21 15:17:47 UTC
List: ruby-talk #2055
SugHimsi again.

I wrote:
> * gtkrc.html         (Dai.K.)
>     => (I have it, and will ask him...)

Here's his part (-; with a little refinement > Dai).

-- 
SugHimsi (SUGIHARA Hiroshi)
manamist@white.diamond.ne.jp
 ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 

Attachments (1)

gtkrc.html (6.97 KB, text/html)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>

<head>
<title>Ruby/Gtk Programming; Gtkrc</title>
    <!-- This baselink is temporal one. -->
    <base href="http://ruby.freak.ne.jp/gtk/">
</head>

<!-- Background white, links blue (unvisited), red (active) -->
<BODY
  BGCOLOR="#FFFFFF"
  TEXT="#000000"
  LINK="#0000FF"
  VLINK="#800080"
  ALINK="#FF0000"
>

<h2>RC file</h2>

GTK gives you a way to set a style(colors, fonts, etc..) of just about any widgets by using its own rc files.

<hr noshade><strong>+ Gtk::RC</strong><p>
<hr noshade><strong>* Gtk::RC</strong><p>

Using an rc file, you should invoke a method defined in the Gtk::RC module:

<dl>
<dt><code>Gtk::RC.parse</code> '<i>filename</i>'
<dd>This method parses the file assigned by <i>filename</i>, and use the style defined there.<br>

<dt><code>Gtk::RC.parse_string</code> <i>string</i>
<dd>This method parses a given string and use the style described in it.<br>
This way is usually used with here document. for example:
<pre>
Gtk::RC.parse_string &lt;&lt;EOS
style "default"
{
  fontset = "-*-helvetica-medium-r-normal--14-*,-*-fixed-medium-r-normal--14-*"
}
widget_class "*" style "default"
EOS
</pre>

</dl>

<hr noshade><strong>* simple examples</strong><p>

Generally speaking, in the GTK's rc file, <code>style</code> statement defines a style, and <code>widget</code> or <code>widget_class</code> statement assigns its style to a widget.


<p>
Following sample shows a pink button:

sample script <a href="rc-hello.rb">rc-hello.rb</a>:<br>
<pre>
require 'gtk'
<b>
Gtk::RC.parse_string &lt;&lt;EOS
style "button"
{
  bg[NORMAL] = {1.0, 0.8, 0.8}
}
widget_class "*GtkButton" style "button"
EOS
</b>
window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
button = Gtk::Button.new('Hello World')
window.add button
button.show
window.show
Gtk.main
</pre><p>

result screen shot:<br>
<img src="imgs/rc-hello.gif">
<p>
The "<code>Gtk::RC.parse_string</code>" loads GTK's rc strings and sets the style. The following documents to the line of EOS is passed to <code>Gtk::RC.parse_string</code> as an argument and parsed by GTK.<p>


Here is a description of the string:
<ul>
<li><code>style "button"</code><br>
It creates the new style named as a "button" defined by following strings between <code>{</code> and <code>}</code>.

<li><code>bg[NORMAL] = {1.0, 0.8, 0.8}</code><br>
It sets the background color in the "NORMAL" state. 
The following 3 decimals means the three primary colors, Red, Green, Blue in the order of appearance, are values in the range from 0.0 to 1.0. They must be in floating-point style, or they will register as 0. So note that simple "1" will not work, it must be "1.0".

<li><code>widget_class "*GtkButton" style "button"</code><br>
This sets a style of a widget of "GtkButton" class to the "button" style defined above.
The directive of "widget_class" uses a class name to determine widgets. Note that the word of ``class name'' in this context is NOT Ruby's class name but GTK's class name, which is equals to Ruby's class name except "::".
(ex: The GTK's classname of Gtk::Button is "GtkButton".)
</ul>

<hr noshade><strong>+ RC file format</strong><p>
<dl>
<dt><code>style "<i>style name</i>"</code>
<dt><code>style "<i>style name</i>" = "<i>existing style name</i>"</code>
<dd>
It defines a style.
The content closed by {} is the definition itself.
You can copy a existing style then describe differences with second syntax.

<p>
<ul>
<li><code>To specify a color:</code><br>
You can specify a color with following format:
<ul>
<li><code>fg[state] = {red, green, blue}  # set a foreground color of a widget.</code><br>
<li><code>bg[state] = {red, green, blue}  # set a background color of a widget.</code><br>
</ul>

The 3 decimals means the three primary colors, Red, Green, Blue in the order of appearance, are values in the range from 0.0 to 1.0. They must be in floating-point format. A black is expressed by {0.0, 0.0, 0.0}, and a white is by {1.0, 1.0, 1.0}.<br>
ex:<br>
<code>fg[NORMAL] = {0.0, 0.0, 0.0}<br>
bg[NORMAL] = {0.8, 0.8, 0.8}</code>


<li><code>state:</code><br>
<ul>
<li><code>NORMAL -- a normal state of the widget.</code><br>
<li><code>PRELIGHT -- a mouse cursor is over the widget(but not pressed).</code><br>
<li><code>ACTIVE -- the widget is pressed or clicked.</code><br>
<li><code>INSENSITIVE -- non-active state of the widget.</code><br>
<li><code>SELECTED -- the widget is selected.</code><br>
</ul>

<li><code>To specify a background pixmap:</code><br>
you can specify a background pixmap with following format.
<ul>
<li><code>bg_pixmap[state] = "<i>filename</i>"</code><br>
</ul>
a pixmap file is searched in the pixmap_path(mentioned later).

<li><code>font:</code><br>
<ul>
<li><code>font = "<i>font name</i>"</code><br>
<li><code>fontset = "<i>font name</i>"</code><br>
</ul>

This specifies a font or fontset in the XLFD format.

</ul>
<p>

<dt><code>pixmap_path "<i>path</i>:<i>path</i>:..."</code>
<dd>
This is used for searching a pixmap file specified by the bg_pixmap.
Searching path is separated by a colon(:).
<p>

<dt><code>widget_class "<i>widget class set</i>" style "<i>style name</i>"</code>
<dt><code>widget "<i>widget set</i>" style "<i>style name</i>"</code>
<dd>
This assignes the style specified by a "style name" to the widget given by a "widget class set" or "widget set".

<p>
The directive of <code>widget_class</code> uses a class name to determine widgets. Note that the word of ``class name'' in this context is not Ruby's class name but GTK's class name, which is equals to Ruby's class name except "::".
(ex: The GTK's classname of Gtk::Button is "GtkButton".)

The directive of <code>widget</code> is specified by name. widget name is set by a method of Gtk::Widget#set_name. On my experience, if you don't set it, it becomes same to class name.
<p>

A widget class set or a widget set is specified widget has-a tree. For example, if a Gtk::Button is added to Gtk::Window, the button is specified by "GtkWindow.GtkButton" in a class name form. A wildcard `*' is also available in this syntax, so "*GtkButton" expresses all widget of GtkButton class.

</dl>

ex:
<pre>
Gtk::RC.parse_string &lt;&lt;EOS
pixmap_path "."
style "default"
{
  fg[NORMAL] = {0.0, 0.0, 1.0}
  bg_pixmap[NORMAL] = "stone.xpm"
  font = "-adobe-courier-bold-r-normal--18-*"
}
widget_class "*" style "default"
EOS
</pre>

This code sets whole widgets' foreground color to blue, background to stone.xpm, and font to courier 18pt bold.
<br>
Following snapshot show this sample:<br>
<img src="imgs/rc-menu.gif">
<p>

<a href="diff.html">next</a>
<hr noshade>
<a href="../">[TOP]</a>
<a href="../ml/topics.html">[ML topics]</a>
<a href="./">[GTK]</a>
<a href="../goo/">[Today's goo analyzer]</a>
<br>
Written by
<a href="mailto:akaishi@ruby.freak.ne.jp">akaishi@ruby.freak.ne.jp</a>
<br>
Translated by
<a href="mailto:MAP2303@mapletown.net">MAP2303@mapletown.net</a>
<br>

</body>
</html>

In This Thread