# Would you mind turning fxruby program into ruby-gtk+?

**URL:** <https://www.ruby-forum.com/t/would-you-mind-turning-fxruby-program-into-ruby-gtk/226067>\
**Category:** Ruby-Gnome 2\
**Created:** [May 30, 2010, 7:22am UTC](https://www.ruby-forum.com/t/would-you-mind-turning-fxruby-program-into-ruby-gtk/226067 "2010-05-30T07:22:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [May 30, 2010, 7:22am UTC](https://www.ruby-forum.com/t/would-you-mind-turning-fxruby-program-into-ruby-gtk/226067/1 "2010-05-30T07:22:40Z")

</div>

there is a fxruby program,would you mind turning it into ruby-gtk+?

#!/usr/bin/env ruby  
require ‘rubygems’  
require ‘fox16’  
require ‘date’

include Fox

class TableWindow \< FXMainWindow

def initialize(app)

# Call the base class initializer first

super(app, “Table Widget Test”, :opts =\> DECOR\_ALL)

# Tooltip

tooltip = FXToolTip.new(getApp())

# Icon used in some cells

# Menubar

menubar = FXMenuBar.new(self, LAYOUT\_SIDE\_TOP|LAYOUT\_FILL\_X)

# Separator

FXHorizontalSeparator.new(self,  
LAYOUT\_SIDE\_TOP|LAYOUT\_FILL\_X|SEPARATOR\_GROOVE)

# Contents

contents = FXVerticalFrame.new(self,  
LAYOUT\_SIDE\_TOP|FRAME\_NONE|LAYOUT\_FILL\_X|LAYOUT\_FILL\_Y)

frame = FXVerticalFrame.new(contents,  
FRAME\_SUNKEN|FRAME\_THICK|LAYOUT\_FILL\_X|LAYOUT\_FILL\_Y, :padding =\> 0)

# Table

@table = FXTable.new(frame,  
:opts =\>  
TABLE\_COL\_SIZABLE|TABLE\_ROW\_SIZABLE|LAYOUT\_FILL\_X|LAYOUT\_FILL\_Y,  
:padding =\> 2)

@table.visibleRows = 20  
@table.visibleColumns = 8

@table.setTableSize(50, 14)

@table.setBackColor(FXRGB(255, 255, 255))  
@table.setCellColor(0, 0, FXRGB(255, 255, 255))  
@table.setCellColor(0, 1, FXRGB(255, 240, 240))  
@table.setCellColor(1, 0, FXRGB(240, 255, 240))  
@table.setCellColor(1, 1, FXRGB(240, 240, 255))

# Initialize the scrollable part of the table

(0…49).each do |r|  
(0…13).each do |c|  
@table.setItemText(r, c, “r:#{r} c:#{c}”)  
end  
end

# Initialize column headers

(0…12).each { |c| @table.setColumnText(c, Date::MONTHNAMES[c+1]) }

# Initialize row headers

(0…50).each { |r| @table.setRowText(r, “Row#{r}”) }

@table.setItemText(10, 10, “This is multi-\nline text”)  
@table.setItemJustify(10, 10,  
FXTableItem::CENTER\_X|FXTableItem::CENTER\_Y)

@table.setItem(3, 3, nil)  
@table.setItem(5, 6, @table.getItem(5, 5))  
@table.setItem(5, 7, @table.getItem(5, 5))  
@table.setItemText(5, 5, “Spanning Item”)  
@table.setItemJustify(5, 5, FXTableItem::CENTER\_X|FXTableItem::CENTER\_Y)

@table.getItem( 9, 9).borders =  
FXTableItem::TBORDER|FXTableItem::LBORDER|FXTableItem::BBORDER  
@table.getItem( 9, 10).borders =  
FXTableItem::TBORDER|FXTableItem::RBORDER|FXTableItem::BBORDER

@table.getItem(40, 13).borders =  
FXTableItem::LBORDER|FXTableItem::TBORDER|FXTableItem::RBORDER|FXTableItem::BBORDER  
@table.getItem(49, 13).borders =  
FXTableItem::LBORDER|FXTableItem::TBORDER|FXTableItem::RBORDER|FXTableItem::BBORDER  
@table.getItem( 5, 0).borders =  
FXTableItem::LBORDER|FXTableItem::TBORDER|FXTableItem::RBORDER|FXTableItem::BBORDER

@table.getItem(6, 6).iconPosition = FXTableItem::ABOVE # icon above the  
text  
@table.getItem(6, 6).justify =  
FXTableItem::CENTER\_X|FXTableItem::CENTER\_Y

@table.getItem(3, 4).stipple = STIPPLE\_CROSSDIAG

# File Menu

filemenu = FXMenuPane.new(self)  
FXMenuCommand.new(filemenu, “&Quit\tCtl-Q”, nil, getApp(),  
FXApp::ID\_QUIT)  
FXMenuTitle.new(menubar, “&File”, nil, filemenu)

# Options Menu

tablemenu = FXMenuPane.new(self)  
FXMenuCheck.new(tablemenu, “Horizontal grid”, @table,  
FXTable::ID\_HORZ\_GRID)  
FXMenuCheck.new(tablemenu, “Vertical grid”, @table,  
FXTable::ID\_VERT\_GRID)  
FXMenuTitle.new(menubar, “&Options”, nil, tablemenu)

# Manipulations Menu

manipmenu = FXMenuPane.new(self)  
FXMenuCommand.new(manipmenu, “Delete Column\tCtl-C”, nil,  
@table, FXTable::ID\_DELETE\_COLUMN)  
FXMenuCommand.new(manipmenu, “Delete Row\tCtl-R”, nil,  
@table, FXTable::ID\_DELETE\_ROW)  
FXMenuCommand.new(manipmenu, “Insert Column\tCtl-Shift-C”, nil,  
@table, FXTable::ID\_INSERT\_COLUMN)  
FXMenuCommand.new(manipmenu, “Insert Row\tCtl-Shift-R”, nil,  
@table, FXTable::ID\_INSERT\_ROW)  
FXMenuCommand.new(manipmenu, “Resize table…”).connect(SEL\_COMMAND,  
method(:onCmdResizeTable))  
FXMenuTitle.new(menubar, “&Manipulations”, nil, manipmenu)

# Selection Menu

selectmenu = FXMenuPane.new(self)  
FXMenuCommand.new(selectmenu, “Select All”, nil, @table,  
FXTable::ID\_SELECT\_ALL)  
FXMenuCommand.new(selectmenu, “Select Cell”, nil, @table,  
FXTable::ID\_SELECT\_CELL)  
FXMenuCommand.new(selectmenu, “Select Row”, nil, @table,  
FXTable::ID\_SELECT\_ROW)  
FXMenuCommand.new(selectmenu, “Select Column”, nil, @table,  
FXTable::ID\_SELECT\_COLUMN)  
FXMenuCommand.new(selectmenu, “Deselect All”, nil, @table,  
FXTable::ID\_DESELECT\_ALL)  
FXMenuCommand.new(selectmenu, “Cut to Clipboard”, nil, @table,  
FXTable::ID\_CUT\_SEL)  
FXMenuCommand.new(selectmenu, “Copy to Clipboard”, nil, @table,  
FXTable::ID\_COPY\_SEL)  
FXMenuCommand.new(selectmenu, “Paste from Clipboard”, nil, @table,  
FXTable::ID\_PASTE\_SEL)  
FXMenuCommand.new(selectmenu, “Delete”, nil, @table,  
FXTable::ID\_DELETE\_SEL)  
FXMenuTitle.new(menubar, “&Selection”, nil, selectmenu)  
end

# Resize the table

def onCmdResizeTable(sender, sel, ptr)

# Create an empty dialog box

dlg = FXDialogBox.new(self, “Resize Table”)

# Set up its contents

frame = FXHorizontalFrame.new(dlg, LAYOUT\_FILL\_X|LAYOUT\_FILL\_Y)  
FXLabel.new(frame, “Rows:”, nil, LAYOUT\_SIDE\_LEFT|LAYOUT\_CENTER\_Y)  
rows = FXTextField.new(frame, 5,  
:opts =\>  
JUSTIFY\_RIGHT|FRAME\_SUNKEN|FRAME\_THICK|LAYOUT\_SIDE\_LEFT|LAYOUT\_CENTER\_Y)  
FXLabel.new(frame, “Columns:”, nil, LAYOUT\_SIDE\_LEFT|LAYOUT\_CENTER\_Y)  
cols = FXTextField.new(frame, 5,  
:opts =\>  
JUSTIFY\_RIGHT|FRAME\_SUNKEN|FRAME\_THICK|LAYOUT\_SIDE\_LEFT|LAYOUT\_CENTER\_Y)  
FXButton.new(frame, “Cancel”, nil, dlg, FXDialogBox::ID\_CANCEL,  
FRAME\_RAISED|FRAME\_THICK|LAYOUT\_SIDE\_LEFT|LAYOUT\_CENTER\_Y)  
FXButton.new(frame, " OK ", nil, dlg, FXDialogBox::ID\_ACCEPT,  
FRAME\_RAISED|FRAME\_THICK|LAYOUT\_SIDE\_LEFT|LAYOUT\_CENTER\_Y)

# Initialize the text fields’ contents

oldnr, oldnc = @table.numRows, @table.numColumns  
rows.text = oldnr.to\_s  
cols.text = oldnc.to\_s

# FXDialogBox#execute will return non-zero if the user clicks OK

if dlg.execute != 0  
nr, nc = rows.text.to\_i, cols.text.to\_i  
nr = 0 if nr \< 0  
nc = 0 if nc \< 0  
@table.setTableSize(nr, nc)  
(0…nr).each { |r|  
(0…nc).each { |c|

# @table.setItemText(r, c, “r:#{r+1} c:#{c+1}”)

}  
}  
end  
return 1  
end

# Create and show this window

def create  
super  
show(PLACEMENT\_SCREEN)  
end  
end

# Start the whole thing

if **FILE** == $0

# Make application

application = FXApp.new(“TableApp”, “FoxTest”)

# Make window

TableWindow.new(application)

# Create app

application.create

# Run

application.run  
end

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [May 31, 2010, 7:15am UTC](https://www.ruby-forum.com/t/would-you-mind-turning-fxruby-program-into-ruby-gtk/226067/2 "2010-05-31T07:15:56Z")

</div>

dear MikeC:  
i am not a professinoal programmer,want to do a tool for myself,to  
improve my work effencienceã€‚what i want to do is an valuation  
table(model)to valuate stock’s price,i am pleased to see there is a  
sample in fxruby web which i send in the first letter.  
i want to revise something and add something to let it work for my  
goal.  
at first i see the sample in  
[http://www.fxruby.org/examples/table.rb](http://www.fxruby.org/examples/table.rb)  
ha,that’s what i want ,unluckily,there two problems i can’t solve  
1.the fxruby table can’t display chinese,i can’t input chinese into  
fxruby table textfield too.  
2.the fxruby make my mouse deadblock,i can’t use my mouse right key.  
when i run a simple ruby gtk+ program, i found chinese can be  
used(display\input),mouse can be used too.  
i am going to change the fxruby into ruby gtk ,but i have no ability to  
write it in ruby gtk+,i am glad to learn to write an program myself,  
glad to hear from you too.  
wounld anyone mind telling me why the following simple program can’t  
display chinses?  
require ‘rubygems’  
require ‘fox16’  
require ‘jcode’  
$KCODE = ‘u’  
include Fox  
application = FXApp.new(“æµ‹è¯•”, “æµ‹è¯•”)  
main = FXMainWindow.new(application, “Hello”, nil, nil, DECOR\_ALL)  
FXButton.new(main, “&æµ‹è¯•, æµ‹è¯•!”, nil, application, FXApp::ID\_QUIT)  
application.create()  
main.show(PLACEMENT\_SCREEN)  
application.run()  
æµ‹è¯• is the meaning of “test” in english.

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [May 31, 2010, 12:38pm UTC](https://www.ruby-forum.com/t/would-you-mind-turning-fxruby-program-into-ruby-gtk/226067/3 "2010-05-31T12:38:13Z")

</div>

Hello Pen 🙂

I’m not sure about the problem with fxruby. I have never used  
it. But I will try to explain what I know. I guess you  
are using a Unix like system with X Windows. If it is Windows  
or Mac OS, I can’t help, because I don’t use them. All X Windows  
programs can use an input method. An input method is the way that  
you type non-roman characters like Chinese or Japanese.  
For most X Windows programs you have to set up the input method  
before you start X Windows. I forget how to do it, but I think you  
have to set an environment variable.

When GTK+ (and QT, too) was written, they thought the normal  
way to set an input method in X Windows was bad. So they made  
a new way. That’s why you can right click on a window in GTK+ programs  
and select the input method. It also works the old way.  
Since most X Windows programs use GTK+ or QT these days,  
nobody uses the old X Windows input method technique. But probably  
FXWindows uses the old way. If you learn how to set it up, you will  
be able to use your input method. Or at least that is my guess. I  
haven’t used it, so I don’t know.

As for writing the program in ruby-gtk, it is probably best to start  
from the beginning. I am a little bit busy today, but I will try to  
help you get started tomorrow. Even if you aren’t a professional  
programmer, I think you can learn how to do what you want.

Anyway, if you have any questions, feel free to ask 🙂

```
    MikeC
```

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [May 30, 2010, 2:51pm UTC](https://www.ruby-forum.com/t/would-you-mind-turning-fxruby-program-into-ruby-gtk/226067/4 "2010-05-30T14:51:54Z")

</div>

On 30 May 2010 14:22, Pen T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> there is a fxruby program,would you mind turning it into ruby-gtk+?

Perhaps you could give some background on what you are hoping  
to learn. If you are mostly interested to learn how these things  
work in ruby-gtk, there are numerous very good tutorials on  
everything in your program.

[http://ruby-gnome2.sourceforge.jp/hiki.cgi?tutorials](http://ruby-gnome2.sourceforge.jp/hiki.cgi?tutorials)

Or maybe there was something I missed that you have a particular  
question about?

If you are just looking for someone to do this work for you,  
I suppose it doesn’t hurt to ask, but it seems kind of  
cheeky to me 😉

Anyway, somebody may be able to write the code you  
want, but if you have a specific question I’ll do my best  
to help you.

```
      MikeC

```

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [May 31, 2010, 3:42pm UTC](https://www.ruby-forum.com/t/would-you-mind-turning-fxruby-program-into-ruby-gtk/226067/5 "2010-05-31T15:42:35Z")

</div>

sorry , web say The attached file is too large.i have more attachments  
to upload, can you give an email ?

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [May 31, 2010, 3:37pm UTC](https://www.ruby-forum.com/t/would-you-mind-turning-fxruby-program-into-ruby-gtk/226067/6 "2010-05-31T15:37:23Z")

</div>

dear MikeC:  
my job is a stock broker in china ,coding is my hobby, my system is  
ubuntu10.04.  
i have learned a little ruby myself .  
there is an choice for me to select.  
fxruby or ruby-gtk+ is better?  
fxruby:  
1.i have gotten a ebook:  
fxruby :create lean and mean GUI with ruby.  
2.the fxruby sample is fit for my goal,maybe i can make little revision  
to let it work for me.

ruby gtk+:  
1.i can run ruby gtk+ program which is no any question(display\input  
chinese,mouse right key ) .

i want to learn from beginning,maybe ruby gtk+ is better for me ?

I would appreciate ruby community’s helping,especially ,MikeC.

install chinese input  
1.  
sudo add-apt-repository ppa:shawn-p-huang/ppa  
sudo apt-get update  
sudo apt-get install ibus-gtk ibus-qt4 ibus-pinyin  
ibus-pinyin-db-open-phrase

2.select ibus  
please see attachment(installchinese1\installchinese2)  
maybe you can install and try it in fxruby or ruby-gtk+.

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [May 31, 2010, 3:55pm UTC](https://www.ruby-forum.com/t/would-you-mind-turning-fxruby-program-into-ruby-gtk/226067/7 "2010-05-31T15:55:50Z")

</div>

after  
sudo add-apt-repository ppa:shawn-p-huang/ppa  
sudo apt-get update  
sudo apt-get install ibus-gtk ibus-qt4 ibus-pinyin  
ibus-pinyin-db-open-phrase

system-preferences-ibus prefereces- chinese :please select pinyin .

here is more you can see  
[http://code.google.com/p/ibus/wiki/Install](http://code.google.com/p/ibus/wiki/Install)  
[http://wiki.ubuntu.org.cn/Qref/More](http://wiki.ubuntu.org.cn/Qref/More)

ä¸­æ–‡è¾“å…¥æ³•ibus é…ç½®åŠç›¸å…³

æ¥æºï¼š[Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/ibus/wiki/Ubuntu)

1. ä¿®æ”¹ /etc/apt/sources.listæ–‡ä»¶ï¼Œåœ¨æºä¸­æ·»åŠ å¦‚ä¸‹è¡Œå†…å®¹  
å¦‚æžœæ˜¯9.10 Karmicï¼Œè¿™æ”¹ä¸ºè¿™è¡Œå†…å®¹  
deb [Index of /lidaobing/ibus-910/ubuntu](http://ppa.launchpad.net/lidaobing/ibus-910/ubuntu) karmic main

å¦‚æžœæ˜¯9.04,åˆ™æ”¹ä¸ºè¿™è¡Œå†…å®¹  
deb [http://ppa.launchpad.net/ibus-dev/ppa/ubuntu](http://ppa.launchpad.net/ibus-dev/ppa/ubuntu) jaunty main

å¦‚æžœæ˜¯8.10,åˆ™æ”¹ä¸ºè¿™è¡Œå†…å®¹  
deb [http://ppa.launchpad.net/ibus-dev/ppa/ubuntu](http://ppa.launchpad.net/ibus-dev/ppa/ubuntu) intrepid main

1. è¿è¡Œå‘½ä»¤ï¼Œæ›´æ–°æº ï¼ˆæ³¨1ï¼‰  
$ sudo apt-get update

2. è¿è¡Œå‘½ä»¤ï¼Œå®‰è£…ibuså’Œibus-pinyin  
$ sudo apt-get install ibus ibus-pinyin ibus-gtk  
è‹¥éœ€è¦ä½¿ç”¨å…¶ä»–è¾“å…¥æ³•åˆ™åŒæ—¶å®‰è£…ibus-chewingç­‰ä¸åŒå¼•æ“Ž

3. å°†è¾“å…¥æ³•åˆ‡æ¢ä¸ºibus  
$ im-switch -s ibus

4. æ³¨é”€åŽé‡æ–°ç™»å½•ã€‚é‡æ–°ç™»å½•åŽå¯èƒ½éœ€è¦ä¿®æ”¹ibusçš„é…ç½®ï¼Œæ‰‹åŠ¨æ·»åŠ ibus-pingyinå¼•æ“Ž
