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

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

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
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.

Hello Pen :slight_smile:

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 :slight_smile:

    MikeC

On 30 May 2010 14:22, Pen T. [email protected] 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

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 :wink:

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

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

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+.

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://wiki.ubuntu.org.cn/Qref/More

中文输入法ibus 配置及相关

来源:Google Code Archive - Long-term storage for Google Code Project Hosting.

  1. 修改 /etc/apt/sources.listæ–‡ä»¶ï¼Œåœ¨æºä¸­æ·»åŠ å¦‚ä¸‹è¡Œå†…å®¹
    如果是9.10 Karmic,这改为这行内容
    deb Index of /lidaobing/ibus-910/ubuntu karmic main

如果是9.04,则改为这行内容
deb http://ppa.launchpad.net/ibus-dev/ppa/ubuntu jaunty main

如果是8.10,则改为这行内容
deb 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引擎