[#1649] Re: New Ruby projects — Yukihiro Matsumoto <matz@...>
The following message is a courtesy copy of an article
[#1672] Re: Ruby 1.4 stable manual bug? — Yukihiro Matsumoto <matz@...>
The following message is a courtesy copy of an article
[#1673] Re: Possible problem with ext/socket in 1.5.2 — itojun@...
[#1694] Conventions for our Ruby book — Dave Thomas <Dave@...>
[#1715] Install postgresql support — Ikhlasul Amal <amal@...>
Hi all,
Hi,
[#1786] Is this a bug? — Clemens Hintze <clemens.hintze@...>
(mailed & posted)
[#1814] Objects nested sometimes. — Hugh Sasse Staff Elec Eng <hgs@...>
I am attemptiong to write a package which consists of a workspace
[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>
Hi all,
Hi,
Yukihiro Matsumoto writes:
Hi,
Hi,
[#1834] enum examples? — Hugh Sasse Staff Elec Eng <hgs@...>
Has anyone any examplse of using the Enumerable module? I've had a
[#1844] Minor irritation, can't figure out how to patch it though! — Hugh Sasse Staff Elec Eng <hgs@...>
I was considering how difficult it would be to patch Ruby to accept
[#1889] [ruby-1.5.3] require / SAFE — ts <decoux@...>
[#1896] Ruby Syntax similar to other languages? — "David Douthitt" <DDouthitt@...>
[#1900] Enumerations and all that. — Hugh Sasse Staff Elec Eng <hgs@...>
Thank you to the people who responded to my questions about Enumerated
Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> writes:
On 16 Mar 2000, Dave Thomas wrote:
[#1929] Re: Class Variables — "David Douthitt" <DDouthitt@...>
| "David Douthitt" <DDouthitt@cuna.com> writes:
[#1942] no Fixnum#new ? — Quinn Dunkan <quinn@...>
Ok, I can add methods to a built-in class well enough (yes I know about succ,
[#1981] Time::at — "David Douthitt" <DDouthitt@...>
or whatever the right syntax is :-)
[#1989] English Ruby/Gtk Tutorial? — schneik@...
Hi,
SugHimsi(%HeIsSaidJustToLoseHisPatienceOnThisSubject;-).
[#2022] rb_global_entry — ts <decoux@...>
[#2036] Anonymous and Singleton Classes — B_DAVISON <Bob.Davison@...>
I am a Ruby newbie and having some problems getting my mind around certain
[#2069] Ruby/GTK+ question about imlib --> gdk-pixbug — schneik@...
[#2073] Re: eval.rb fails — "Dat Nguyen" <thucdat@...>
The doc is fine, this happens only if you try to execute 'until' block
On Wed, 22 Mar 2000, Dat Nguyen wrote:
[#2084] Scope violated by import via 'require'? — Clemens Hintze <c.hintze@...>
Hi,
[#2104] ARGF or $< — Hugh Sasse Staff Elec Eng <hgs@...>
Has anyone any examples of how to use ARGF or $< as I cannot find much
Hi.
[#2165] Ruby strict mode and stand-alone executables. — "Conrad Schneiker" <schneiker@...>
Some people want Ruby to have a strict compile mode.
[#2203] Re: parse bug in 1.5 — schneik@...
[#2212] Re: Ruby/Glade usage questions. — ts <decoux@...>
>>>>> "m" == mrilu <mrilu@ale.cx> writes:
[#2241] setter() for local variables — ts <decoux@...>
[#2256] Multiple assignment of pattern match results. — schneik@...
[#2267] Re: Ruby and Eiffel — h.fulton@...
[#2309] Question about attribute writers — Dave Thomas <Dave@...>
[ruby-talk:02014] Re: English Ruby/Gtk Tutorial?
SugHimsi(%HeIsSaidJustToLoseHisPatienceOnThisSubject;-).
>Mr. Schneiker wrote:
>>
>> Is there an interim version (however primitive) of the English Ruby/Gtk
>> Tutorial available?
>> (snip)
This document is written over 6 months ago, but I think it still invaluable
for introductory study on Ruby/Gtk.
Mr. Igarashi wrote on Ruby/Gtk Tutorial:
>
>Sorry, it is not yet available.
>There are some fragments in ML articles:
>[ruby-list:18724][ruby-list:18731][ruby-talk:00909]
The entire documents (and their translators -- all non-native) are below:
(((pressure?! :-):-):-)
* intro.html (akaishi)
* install.html (Fukushima)
(UNIX centric, but we already have
[ruby-talk:01513] [ruby-talk:01527] ;-)
* hello.html (Fukushima)
* signal.html (gotoken)
=> [ruby-talk:00909]
* japanese.html (gotoken)
(Japanese centric, so gotoken had planned
to enlarge & revise it to l10n.html ...)
* packing.html (IGARASHI)
* widgets.html (IGARASHI)
* style.html (thitoshi)
* button.html (thitoshi)
* pixmap.html (IGARASHI)
* entry.html (IGARASHI)
* calc.html (SugHimsi:-)
* clist.html (aamine)
* text.html (aamine)
* menu.html (dellin)
* fileselection.html (dellin)
* texteditor.html (SugHimsi:-)
* tree.html (adachi)
=> [ruby-list:18724], uuencoded.
* toolbar.html (SugHimsi)
=> [ruby-list:18731]
* gtkrc.html (Dai.K.)
=> (I have it, and will ask him...)
* diff.html (adachi)
=> [ruby-list:18724], uuencoded.
(Should remove lines 143-147 and 34-41.)
* imlib.html (akaishi)
* links.html (maki)
* index.html (maki)
>The original author/maintainer of the tutorial seems to busy.
>I will call translators for the rest of chapters again instead of him.
Here are the rest of my part.
---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ----
calc.html, texteditor.html (already HTML format, uuencoded).
--
SugHimsi (SUGIHARA Hiroshi)
manamist@white.diamond.ne.jp
Attachments (2)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="author" content="akaishi@ruby.freak.ne.jp">
<meta name="title" content="Ruby/Gtk Programming: A Calculator">
<meta name="keywords" content="Ruby,Gtk,calculator,text widget,file selection,scroll bar,menu,textedit.rb">
<meta name="description" content="Ruby/Gtk tutorial">
<!--
translated 1999.09.23 by maili31s@clio.ne.jp
-->
<title>Ruby/Gtk Programming: A Calculator</title>
<style type="text/css">
<!--
body {
background: white;
color: black;
}
a:link { color: blue }
a:visited { color: purple }
a:active { color: red }
-->
</style>
</head>
<body>
<h2>Example: A Calculator</h2>
<p>
The program in this chapter is quoted from
<a href="/cgi-bin/goto?dest=l15294">[ruby-list:15294]</a>.<!-- reconsider this link! -->
</p>
<hr>
<p>
It is a program of the <u>calculator</u>, a combination of the button, the entry, and the table, all of which you already have been examined.
</p><p>
<img src="imgs/calc.gif">
</p><p>
Program <a href="gtkcalc.rb">gtkcalc.rb</a>:
</p>
<pre>
#!/usr/bin/env ruby
require 'gtk'
class Calculator
MAX_DIGIT = 12
ADD = "add"; SUB = "sub"; MUL = "mul"; DIV = "div"
def initialize
num = ""; dot = false # the number what is putting together
erred = false # error, or not?
operation = nil # one of {nil, ADD, SUB, MUL, DIV}
operandl = 0.0 # operand(left)
window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
window.set_title('calculator')
window.signal_connect('destroy') {Gtk.main_quit}
window.border_width = 5
table = Gtk::Table.new(5, 5, true)
window.add(table)
table.show
disp = Gtk::Entry.new # display of the calculator
disp.set_editable(false)
table.attach(disp, 0, 5, 0, 1)
disp.show
digit_clicked = proc {|widget, digit|
unless erred
if disp.get_text.length < MAX_DIGIT
num = num + digit.to_s
disp.set_text(num)
end
end
}
dot_clicked = proc {
unless erred
if disp.get_text.length < MAX_DIGIT - 1 and not dot
dot = true
num = num + '.'
disp.set_text(num)
end
end
}
equ_clicked = proc {
unless erred
x = Float(disp.get_text)
case operation
when ADD
answer = operandl + x
when SUB
answer = operandl - x
when MUL
answer = operandl * x
when DIV
if x == 0.0
disp.set_text('Error')
erred = true
else
answer = operandl / x
end
end
unless erred
num = ''; dot = false
unless operation == nil
operation = nil
disp.set_text(answer.to_s)
end
end
end
}
sign_clicked = proc {
unless erred
x = Float(disp.get_text)
answer = -x
disp.set_text(answer.to_s)
num = ''; dot = false
end
}
op_clicked = proc {|widget, opcode|
unless num == '' then equ_clicked.call end
unless erred
operation = opcode
operandl = Float(disp.get_text)
num = ''; dot = false
end
}
cle_clicked = proc {
unless erred
if num == '' then operation = nil end
disp.set_text('0')
num = ''; dot = false
end
}
clr_clicked = proc {
erred = false
operation = nil
cle_clicked.call
}
[
["7", 0, 1, 1, 2, digit_clicked, 7],
["8", 1, 2, 1, 2, digit_clicked, 8],
["9", 2, 3, 1, 2, digit_clicked, 9],
["/", 3, 4, 1, 2, op_clicked, DIV],
["C", 4, 5, 1, 2, clr_clicked, nil],
["4", 0, 1, 2, 3, digit_clicked, 4],
["5", 1, 2, 2, 3, digit_clicked, 5],
["6", 2, 3, 2, 3, digit_clicked, 6],
["*", 3, 4, 2, 3, op_clicked, MUL],
["CE", 4, 5, 2, 3, cle_clicked, nil],
["1", 0, 1, 3, 4, digit_clicked, 1],
["2", 1, 2, 3, 4, digit_clicked, 2],
["3", 2, 3, 3, 4, digit_clicked, 3],
["-", 3, 4, 3, 4, op_clicked, SUB],
["=", 4, 5, 3, 5, equ_clicked, nil],
["0", 0, 1, 4, 5, digit_clicked, 0],
[".", 1, 2, 4, 5, dot_clicked, nil],
["+/-",2, 3, 4, 5, sign_clicked, nil],
["+", 3, 4, 4, 5, op_clicked, ADD]
].each {|label, la, ra, ta, ba, func, arg|
button = Gtk::Button.new(label)
table.attach(button, la, ra, ta, ba)
button.signal_connect('clicked', arg, &func)
button.show
}
window.show
cle_clicked.call
end
end
if __FILE__ == $0
Calculator.new
Gtk.main
end
</pre>
<p>
<a href="clist.html">Next</a>
</p>
<hr noshade>
<p>
<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>
</p>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="author" content="akaishi@ruby.freak.ne.jp">
<meta name="title" content="Ruby/Gtk Programming: Text Editor">
<meta name="keywords" content="Ruby,Gtk,editor,text widget,file selection,scroll bar,menu,textedit.rb">
<meta name="description" content="Ruby/Gtk tutorial">
<!--
translated 1999.09.23 by maili31s@clio.ne.jp
-->
<title>Ruby/Gtk Programming: Text Editor</title>
<style type="text/css">
<!--
body {
background: white;
color: black;
}
a:link { color: blue }
a:visited { color: purple }
a:active { color: red }
-->
</style>
</head>
<body>
<h2>Example: Text Editor</h2>
<p>
Now let us make a tiny <u>text editor</u>.
We are ready to handle the text widget, the scroll bar, the menu, and the file selection (<u>FS</u> hereafter, among this section), and combinate them.
</p><p>
This look (below) is a copy which has been in the chapter of the menu.
</p><p>
<img src="imgs/menu.gif">
</p><p>
When we select `Open' or `Save' in the menu, the FS dialogue appears.
</p>
<ul>
<li>
The case `Open':
reads the file designated in the FS.
<li>
The case `Save':
writes the contents of the text widget to the designated file.
</ul>
<p>
<b>Bold part</b> is added to the program in the chapter of the menu.
</p><p>
Program <a href="textedit.rb">textedit.rb</a>:
</p>
<pre>
require 'gtk'
window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
mbar = Gtk::MenuBar.new
filemitem = Gtk::MenuItem.new('File')
filemitem.show
filemenu = Gtk::Menu.new
item1 = Gtk::MenuItem.new('Open')
item1.show
filemenu.add item1
item2 = Gtk::MenuItem.new('Save')
item2.show
filemenu.add item2
item3 = Gtk::MenuItem.new('Quit')
item3.show
filemenu.add item3
filemitem.set_submenu filemenu
mbar.append filemitem
mbar.show
vadj = Gtk::Adjustment.new(0,0,0,0,0,0)
text = Gtk::Text.new(nil, vadj)
vs = Gtk::VScrollbar.new(vadj)
text.set_editable true
hbox = Gtk::HBox.new(false, 0)
hbox.pack_start text, true, true, 0
hbox.pack_start vs, false, false, 0
vbox = Gtk::VBox.new(false, 0)
vbox.pack_start mbar, false, false, 0
vbox.pack_start hbox, true, true, 0
vbox.show
<b>
fs = Gtk::FileSelection.new('')
fs.ok_button.signal_connect('clicked') {
fs.hide
$callback.call fs.get_filename
}
fs.cancel_button.signal_connect('clicked') {
fs.hide
}
item1.signal_connect('activate') {
fs.set_title 'Open File'
$callback = proc {|filename|
text.set_point 0
text.forward_delete text.get_length
open(filename) {|f| text.insert_text f.read, 0}
}
fs.show
}
item2.signal_connect('activate') {
fs.set_title 'Save File'
$callback = proc {|filename|
open(filename, 'w+') {|f| f.write(text.get_chars 0, -1)}
}
fs.show
}
</b>
item3.signal_connect('activate') {
exit
}
window.add vbox
text.show
vs.show
hbox.show
window.show
Gtk.main
</pre>
<p>
Explanation<!--Illustration?--> of the program above:
</p>
<dl>
<dt>
<pre>
fs = Gtk::FileSelection.new('')
</pre>
</dt>
<dd>
At first, a new FS widget is made here.
This FS is for common use with `Open' and `Save'.
So at this time, this FS is titleless, and is not displayed.
</dd>
<dt>
<pre>
fs.ok_button.signal_connect('clicked') {
fs.hide
$callback.call fs.get_filename
}
</pre>
</dt>
<dd>
Here we define the `ok' handler, which works when the `OK' button of the FS clicked.
By the click:
<ul>
<li>
First, it keeps the FS unseen.
Notice that it's <u>not destroyed</u>: merely it's not displayed temporarily.
</li>
<li>
Second, it get the filename designated by the FS by `get_filename' method, and it call back the procedure designated by a global variable `$callback', with the filename for its argument.
</li>
</ul>
</dd>
<dt>
<pre>
fs.cancel_button.signal_connect('clicked') {
fs.hide
}
</pre>
</dt>
<dd>
Here we define the `cancel' handler, which works when the `Cancel' button of the FS clicked.<br>
Only what it does is to hide the FS.
</dd>
<dt>
<pre>
item1.signal_connect('activate') {
fs.set_title 'Open File'
$callback = proc {|filename|
text.set_point 0
text.forward_delete text.get_length
open(filename) {|f| text.insert_text f.read, 0}
}
fs.show
}
</pre>
</dt>
<dd>
Next to define is the `open' signal handler, when `Open' in the menu is selected.
It sets the title of the FS as 'Open File',
substitutes the procedure of the case when `OK' button is pushed for the global variable `$callback',
and displays the FS (which should be generated).<br>
The inside of the procedure of `$callback' is:
<ul>
<li>
Deletes all of the contents of the text widget,
</li>
<li>
Reads the file with designated name, and
</li>
<li>
Inserts the contents in the text widget.
</li>
</ul>
</dd>
<dt>
<pre>
item2.signal_connect('activate') {
fs.set_title 'Save File'
$callback = proc {|filename|
open(filename, 'w+') {|f| f.write(text.get_chars 0, -1)}
}
fs.show
}
</pre>
</dt>
<dd>
And last, we define the `save' signal handler, when `Save' in the menu is selected.
It sets the title of the FS as 'Save File',
and substitutes the procedure of the case when `OK' button is pushed for the global variable `$callback',
and displays the FS.<br>
The inside of the procedure of `$callback' is:
<ul>
<li>
Reads all of the contents of the text widget, and
</li>
<li>
Writes it to the designated file.
</li>
</ul>
</dd>
</dl>
<p>
<a href="tree.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>
</p>
</body>
</html>