From: nagai@... Date: 2001-10-23T13:14:20+09:00 Subject: [ruby-talk:23015] Re: ANN: RuEdit - introspective Ruby editor Hi, From: Phlip Subject: [ruby-talk:22988] Re: ANN: RuEdit - introspective Ruby editor Date: Tue, 23 Oct 2001 04:29:42 +0900 Message-ID: <3BD3EE02.F8080384@celterra.com> > Has anyone seen a Python MegaWidgets library for Ruby? or will I need to > write my own notebook widget out of Tk primitives? Is it same to tixNoteBook widget on Tix extension? If it is right and you can use Tix extension on your Tcl/Tk, probably you can use the Tix extension on Ruby/Tk. Please get 'tcltk-ext' package from RAA, and test Tix.rb in the package. Tix.rb is *NOT* perfect, because it was only a sample generated *AUTOMATICALLY* by tcltk-ext library. But in many cases, it is enough to use the power of Tix library. For example, ========================================================================== require 'Tix' TkOption.add('*TixControl*entry.width', 10) TkOption.add('*TixControl*label.width', 18) TkOption.add('*TixControl*label.anchor', 'e') TkRoot.new.background 'gray' nb = TixNoteBook.new(nil, 'ipadx'=>6, 'ipady'=>6) nb.subwidget('nbframe', 'configure', 'backpagecolor'=>'gray') nb.add('hard_disk', 'label'=>'Hard Disk', 'underline'=>0) nb.add('network', 'label'=>'Network', 'underline'=>0) nb.pack('expand'=>true, 'fill'=>'both', 'padx'=>5, 'pady'=>5, 'side'=>'top') sw = nb.subwidget('hard_disk') f_nb = TkFrame.new(nb).pack('side'=>'left', 'padx'=>2, 'pady'=>2, 'fill'=>'both', 'expand'=>true, 'in'=>sw) f_common = TkFrame.new(nb).pack('side'=>'right', 'padx'=>2, 'pady'=>2, 'fill'=>'y', 'in'=>sw) a = TixControl.new(f_nb, 'value'=>12, 'label'=>'Access Time: ') w = TixControl.new(f_nb, 'value'=>400, 'label'=>'Write Throughput: ') r = TixControl.new(f_nb, 'value'=>400, 'label'=>'Read Throughput: ') c = TixControl.new(f_nb, 'value'=>1021, 'label'=>'Capacity: ') Tk.pack(a, w, r, c, 'side'=>'top', 'padx'=>20, 'pady'=>2) TkButton.new(f_common, 'text'=>'OK', 'width'=>6, 'command'=>'exit').pack('side'=>'top', 'padx'=>2, 'pady'=>2) TkButton.new(f_common, 'text'=>'Cancel', 'width'=>6, 'command'=>'exit').pack('side'=>'top', 'padx'=>2, 'pady'=>2) sw = nb.subwidget('network') f_nb = TkFrame.new(nb).pack('side'=>'left', 'padx'=>2, 'pady'=>2, 'fill'=>'both', 'expand'=>true, 'in'=>sw) f_common = TkFrame.new(nb).pack('side'=>'right', 'padx'=>2, 'pady'=>2, 'fill'=>'y', 'in'=>sw) a = TixControl.new(f_nb, 'value'=>12, 'label'=>'Access Time: ') w = TixControl.new(f_nb, 'value'=>400, 'label'=>'Write Throughput: ') r = TixControl.new(f_nb, 'value'=>400, 'label'=>'Read Throughput: ') c = TixControl.new(f_nb, 'value'=>1021, 'label'=>'Capacity: ') u = TixControl.new(f_nb, 'value'=>10, 'label'=>'Users: ') Tk.pack(a, w, r, c, 'side'=>'top', 'padx'=>20, 'pady'=>2) TkButton.new(f_common, 'text'=>'OK', 'width'=>6, 'command'=>'exit').pack('side'=>'top', 'padx'=>2, 'pady'=>2) TkButton.new(f_common, 'text'=>'Cancel', 'width'=>6, 'command'=>'exit').pack('side'=>'top', 'padx'=>2, 'pady'=>2) Tk.mainloop ========================================================================== This script is based on a sample script 'NoteBook.tcl' on Tix extension. It will show a window like following: +---------------------------------------------------------+ | tk | +---------------------------------------------------------+ | ----------- --------- | |/ Hard Disk \ / Network \ | || +------------------------------------------+| || Access Time: [ 12 ] [ OK ] || || Write Throughput: [ 400 ] [ Cancel ] || || Read Throughput: [ 400 ] || || Capacity: [ 1021 ] || |+-------------------------------------------------------+| +---------------------------------------------------------+ Current tcltk-ext library cannot recognize that 'subwidget' option is a widget command and generates a new widget. Therefore, in my example, I use the names of subwidgets and 'in' option of pack. Of course, better solution is to edit Tix.rb and define widget classes for subwidgets. -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)