# Are these widgets worth adding as standard libraries of Ruby/Tk?

**URL:** <https://www.ruby-forum.com/t/are-these-widgets-worth-adding-as-standard-libraries-of-ruby-tk/171380>\
**Category:** Ruby\
**Created:** [July 1, 2009, 12:54pm UTC](https://www.ruby-forum.com/t/are-these-widgets-worth-adding-as-standard-libraries-of-ruby-tk/171380 "2009-07-01T12:54:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hidetoshi\_NAGAI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/49beb7/32.png) [@Hidetoshi\_NAGAI](https://www.ruby-forum.com/u/Hidetoshi_NAGAI)\
**Post date:** [July 1, 2009, 12:54pm UTC](https://www.ruby-forum.com/t/are-these-widgets-worth-adding-as-standard-libraries-of-ruby-tk/171380/1 "2009-07-01T12:54:42Z")

</div>

Hi,

I’m planning to upgrade some Ruby/Tk samples to standard widgets of  
Ruby/Tk. I want comments of yours about making each of widgets as a  
standard library.

Ruby’s source archive includes Ruby/Tk sample scripts.  
Some of them are only demonstration, but some of the others are  
usable as widget class libraries.  
The following sample script includes the classes which are candidates  
for upgrading (Probably, class names are modified and bug-fixed  
when upgrade).

- editable\_listbox.rb  
class Editable\_Listbox  
A listbox widget, but you can edit the text of each item with  
your keyboard.  
For example, when double-crick on an item of the listbox,  
a entry box is shown on the item to edit the text of the item.  
Of course, the result of editing is reflected on the listbox.

- scrollframe.rb  
class TkScrollFrame  
A frame widget, but it has a scrollable view window to see a  
part of the frame.  
For example, please remember a toolbar with many buttons, and  
the toolbar is very long than the window size.  
Then, you may want to scroll the toolbar buttons.  
TkScrollFrame can do that easily.

- tkalignbox.rb  
It may be a little difficult to keep same width/height of widgets  
(e.g. buttons with differnt length of text and different height of  
font) even if the window size is changed.  
The followings are kinds of Frame widget to make it easy.  
class Tk::HBox  
class Tk::HLBox  
class Tk::HRBox  
class Tk::VBox  
class Tk::VTBox  
class Tk::VBBox  
For example, Tk::HLBox.new(parent).add(b1, b2, b3, b4, …) adds  
buttons b1, b2, b3, b4, … from left to right on the HLBox frame  
widget, and gives and keeps same width/height on the buttons.  
A HLBox frame widget is a widget. So, of course, you can pack it  
as same as other widgets.

- tkballoonhelp.rb  
class TkBalloonHelp  
Add a balloonhelp tip on its parent widget.  
Of course, you can contoll its message, on-mouse interval  
before showing the balloonhelp, and so on.  
You can add a hook-method at showing. It means you can also  
show a different message for each line of a listbox.

- tkcombobox.rb  
class TkAutoScrollListbox  
A listbox widget, but has up/down autoscroll tabs when has items  
out of display range. (Mouse on the tab and don’t move mouse,  
then scroll listbox automatically.)

- 
## tktextframe.rb Based on TkTextFrame class, design Tk::ScrollbarComposite module. The module help to add scrollbars to a scrollable widget. For example, define

```
class ScrListbox < Tk::Listbox
  include Tk::ScrollbarComposite
  DEFALUT_HSCROLL = false
  def create_component(keys={})
    Tk::Listbox.new(@frame, keys)
  end
  private :create_component
end

```

* * *

then, you can treat listbox widgets with Y scrollbar,  
by calling ScrListbox.new().pack() and so on.

---

<div class="post-metadata">

**Author:** ![Hidetoshi\_NAGAI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/49beb7/32.png) [@Hidetoshi\_NAGAI](https://www.ruby-forum.com/u/Hidetoshi_NAGAI)\
**Post date:** [July 1, 2009, 11:41pm UTC](https://www.ruby-forum.com/t/are-these-widgets-worth-adding-as-standard-libraries-of-ruby-tk/171380/2 "2009-07-01T23:41:55Z")

</div>

Hi,  
these ruby megawidgets effectively resolve recurring problems, so  
according to  
me can be promoted into one library.  
In the future would be ideal to add tab(notebook) and tree ruby  
megawidget also. In this way we can avoid to use others tcl/tk libraries  
(like BWidget).

An osservation : in “editable\_listbox” and “combobox” when I set state  
to “disabled” the actions are not inhibited.

Anyway thanks for your work and a salute to all the supporters of  
ruby-tk

Antonio

Hidetoshi NAGAI wrote:

> Hi,
> 
> I’m planning to upgrade some Ruby/Tk samples to standard widgets of  
> Ruby/Tk. I want comments of yours about making each of widgets as a  
> standard library.
> 
> Ruby’s source archive includes Ruby/Tk sample scripts.  
> Some of them are only demonstration, but some of the others are  
> usable as widget class libraries.  
> The following sample script includes the classes which are candidates  
> for upgrading (Probably, class names are modified and bug-fixed  
> when upgrade).
> 
> - editable\_listbox.rb  
> class Editable\_Listbox  
> A listbox widget, but you can edit the text of each item with  
> your keyboard.  
> For example, when double-crick on an item of the listbox,  
> a entry box is shown on the item to edit the text of the item.  
> Of course, the result of editing is reflected on the listbox.
> 
> - scrollframe.rb  
> class TkScrollFrame  
> A frame widget, but it has a scrollable view window to see a  
> part of the frame.  
> For example, please remember a toolbar with many buttons, and  
> the toolbar is very long than the window size.  
> Then, you may want to scroll the toolbar buttons.  
> TkScrollFrame can do that easily.
> 
> - tkalignbox.rb  
> It may be a little difficult to keep same width/height of widgets  
> (e.g. buttons with differnt length of text and different height of  
> font) even if the window size is changed.  
> The followings are kinds of Frame widget to make it easy.  
> class Tk::HBox  
> class Tk::HLBox  
> class Tk::HRBox  
> class Tk::VBox  
> class Tk::VTBox  
> class Tk::VBBox  
> For example, Tk::HLBox.new(parent).add(b1, b2, b3, b4, …) adds  
> buttons b1, b2, b3, b4, … from left to right on the HLBox frame  
> widget, and gives and keeps same width/height on the buttons.  
> A HLBox frame widget is a widget. So, of course, you can pack it  
> as same as other widgets.
> 
> - tkballoonhelp.rb  
> class TkBalloonHelp  
> Add a balloonhelp tip on its parent widget.  
> Of course, you can contoll its message, on-mouse interval  
> before showing the balloonhelp, and so on.  
> You can add a hook-method at showing. It means you can also  
> show a different message for each line of a listbox.
> 
> - tkcombobox.rb  
> class TkAutoScrollListbox  
> A listbox widget, but has up/down autoscroll tabs when has items  
> out of display range. (Mouse on the tab and don’t move mouse,  
> then scroll listbox automatically.)
> 
> - 
> ## tktextframe.rb Based on TkTextFrame class, design Tk::ScrollbarComposite module. The module help to add scrollbars to a scrollable widget. For example, define
> 
> ```
> class ScrListbox < Tk::Listbox
> include Tk::ScrollbarComposite
> DEFALUT_HSCROLL = false
> def create_component(keys={})
> Tk::Listbox.new(@frame, keys)
> end
> private :create_component
> end
> 
> ```
> 
> * * *
> 
> then, you can treat listbox widgets with Y scrollbar,  
> by calling ScrListbox.new().pack() and so on.

---

<div class="post-metadata">

**Author:** ![Hidetoshi\_NAGAI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/49beb7/32.png) [@Hidetoshi\_NAGAI](https://www.ruby-forum.com/u/Hidetoshi_NAGAI)\
**Post date:** [July 2, 2009, 12:13am UTC](https://www.ruby-forum.com/t/are-these-widgets-worth-adding-as-standard-libraries-of-ruby-tk/171380/3 "2009-07-02T00:13:46Z")

</div>

Can anybody help me with this error? “Can’t Convert Symbol to string”

class StaticHtmlCacheExtension \< Radiant::Extension  
version “0.1a”  
description ““Static” (X)HTML Caching”  
def activate  
Radiant::Cache.instance\_eval :include, StaticHTMLCache  
end  
end

module StaticHTMLCache  
def self.included(base)  
base.instance\_eval do alias\_method\_chain :cache\_page, :html end  
end  
def cache\_page\_with\_html(metadata,content,path)  
return unless perform\_caching  
cache\_path=html\_cache\_path(path)  
logger.info(“Caching Page: #{cache\_path}”)  
metadata = YAML.load(metadata)  
if (File.extname(cache\_path).blank? || File.extname(cache\_path) ==  
“.seo”) && (metadata[‘Content-Type’].nil? ||  
metadata[‘Content-Type’].starts\_with?(‘text/html’))  
cache\_path = cache\_path + ‘.html’  
end  
begin  
FileUtils.makedirs(File.dirname(cache\_path))  
File.open(cache\_path, ‘wb’) { |f| f.write(content) }  
rescue Errno::EISDIR, Errno::EEXIST  
logger.error “StaticHTMLCache::NameCollisionError (Directory  
MisRepresentation):\n Strange Naming Scheme for URI: #{path}”  
nil  
end  
end  
def html\_cache\_path(path)  
cache\_path = page\_cache\_path(path)  
if (cache\_path.ends\_with?(’\_site-root’))  
cache\_path.sub!(/\_site-root$/, ‘index’)  
end  
cache\_path  
end  
end

---

<div class="post-metadata">

**Author:** ![Hidetoshi\_NAGAI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/49beb7/32.png) [@Hidetoshi\_NAGAI](https://www.ruby-forum.com/u/Hidetoshi_NAGAI)\
**Post date:** [July 2, 2009, 12:37am UTC](https://www.ruby-forum.com/t/are-these-widgets-worth-adding-as-standard-libraries-of-ruby-tk/171380/4 "2009-07-02T00:37:08Z")

</div>

Hi –

On Thu, 2 Jul 2009, Jordon B. wrote:

> Can anybody help me with this error? “Can’t Convert Symbol to string”

Where are you getting the error?

David

---

<div class="post-metadata">

**Author:** ![Hidetoshi\_NAGAI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/49beb7/32.png) [@Hidetoshi\_NAGAI](https://www.ruby-forum.com/u/Hidetoshi_NAGAI)\
**Post date:** [July 2, 2009, 12:23am UTC](https://www.ruby-forum.com/t/are-these-widgets-worth-adding-as-standard-libraries-of-ruby-tk/171380/5 "2009-07-02T00:23:27Z")

</div>

Jordon B. wrote:

> Can anybody help me with this error? “Can’t Convert Symbol to string”

o\_O whats wrong with you… don’t go posting questions like this in  
other people’s posts…

You sir, are less than intelligent.

- Mac

---

<div class="post-metadata">

**Author:** ![Hidetoshi\_NAGAI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/49beb7/32.png) [@Hidetoshi\_NAGAI](https://www.ruby-forum.com/u/Hidetoshi_NAGAI)\
**Post date:** [July 2, 2009, 12:47am UTC](https://www.ruby-forum.com/t/are-these-widgets-worth-adding-as-standard-libraries-of-ruby-tk/171380/6 "2009-07-02T00:47:04Z")

</div>

I honestly don’t know, this is the trace:  
I’m still really really new to Ruby so I don’t understand how to debug  
in  
the slightest bit 😛  
According to the trace it would be this line:  
“Radiant::Cache.instance\_eval  
:include, StaticHTMLCache” which is in the first part of the script I  
sent.

www:/var/app/radiant# rake production db:migrate:extensions --trace  
(in /var/app/radiant)  
\*\* Invoke production (first\_time)  
\*\* Execute production  
\*\* Invoke environment (first\_time)  
\*\* Execute environment  
rake aborted!  
can’t convert Symbol into String  
/var/app/radiant/vendor/extensions/static\_html\_cache/static\_html\_cache\_exten  
sion.rb:28:in `instance_eval' /var/app/radiant/vendor/extensions/static_html_cache/static_html_cache_exten sion.rb:28:in`activate’  
/var/app/radiant/vendor/radiant/lib/radiant/extension.rb:52:in  
`activate' /var/app/radiant/vendor/radiant/vendor/rails/activesupport/lib/active_suppor t/dependencies.rb:105:in`to\_proc’  
/var/app/radiant/vendor/radiant/lib/radiant/extension\_loader.rb:98:in  
`each' /var/app/radiant/vendor/radiant/lib/radiant/extension_loader.rb:98:in`activate\_extensions’  
/var/app/radiant/vendor/radiant/lib/radiant/initializer.rb:184:in  
`after_initialize' /var/app/radiant/vendor/radiant/vendor/rails/railties/lib/initializer.rb:177 :in`process’  
/var/app/radiant/vendor/radiant/vendor/rails/railties/lib/initializer.rb:113  
:in `send' /var/app/radiant/vendor/radiant/vendor/rails/railties/lib/initializer.rb:113 :in`run’  
/var/app/radiant/vendor/radiant/lib/radiant/initializer.rb:148:in `run' /var/app/radiant/config/environment.rb:12 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in`gem\_original\_require’  
/usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:31:in `require' /var/app/radiant/vendor/radiant/vendor/rails/activesupport/lib/active_suppor t/dependencies.rb:156:in`require’  
/var/app/radiant/vendor/radiant/vendor/rails/activesupport/lib/active\_suppor  
t/dependencies.rb:521:in `new_constants_in' /var/app/radiant/vendor/radiant/vendor/rails/activesupport/lib/active_suppor t/dependencies.rb:156:in`require’  
/var/app/radiant/vendor/radiant/vendor/rails/railties/lib/tasks/misc.rake:4  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in`execute’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in`execute’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in  
`invoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in`synchronize’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in  
`invoke_with_call_chain' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in`invoke’  
/var/www/envygeeks\_radiant/vendor/radiant/lib/tasks/environments.rake:10  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in`execute’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in`execute’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in  
`invoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in`synchronize’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in  
`invoke_with_call_chain' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in`invoke’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in`top\_level’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in`top\_level’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in  
`standard_exception_handling' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in`top\_level’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in`standard\_exception\_handling’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31 /usr/bin/rake:19:in`load’  
/usr/bin/rake:19  
www:/var/app/radiant# rake production db:migrate:extensions  
(in /var/app/radiant)  
rake aborted!  
can’t convert Symbol into String

(See full trace by running task with --trace)

---

<div class="post-metadata">

**Author:** ![Hidetoshi\_NAGAI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/49beb7/32.png) [@Hidetoshi\_NAGAI](https://www.ruby-forum.com/u/Hidetoshi_NAGAI)\
**Post date:** [July 13, 2009, 12:22pm UTC](https://www.ruby-forum.com/t/are-these-widgets-worth-adding-as-standard-libraries-of-ruby-tk/171380/7 "2009-07-13T12:22:11Z")

</div>

Hi,

## I committed updates of Ruby/Tk on trunk and ruby\_1\_8. Bug reports are welcome.

- ext/tk/extconf.rb: New strategy for searching Tcl/Tk libraries.

- ext/tk/\*: Support new features of Tcl/Tk8.6b1 and minor bug fixes.  
( [KNOWN BUG] Ruby/Tk on Ruby 1.9 may not work on Cygwin. )

- ext/tk/\*: Unify sources between Ruby 1.8 & 1.9.

- ext/tk/\*: Improve default\_widget\_set handling.

- ext/tk/\*: Multi-TkInterpreter (multi-tk.rb) works on Ruby 1.8 & 1.9.  
( [KNOWN BUG] On Ruby 1.8, join to a long term Thread on Tk  
callbacks may freeze. On Ruby 1.9, cannot create a second  
master interpreter (creating slaves are OK); supported master  
interpreter is the default master interpreter only. )

- ext/tk/lib/tkextlib/\*: Update supported versions of Tk extensions.  
Tcllib 1.8/Tklib 0.4.1 ==\> Tcllib 1.11.1/Tklib 0.5  
BWidgets 1.7 ==\> BWidgets 1.8  
TkTable 2.9 ==\> TkTable 2.10  
TkTreeCtrl 2005-12-02 ==\> TkTreeCtrl 2.2.9  
Tile 0.8.0/8.5.1 ==\> Tile 0.8.3/8.6b1  
IncrTcl 2005-02-14 ==\> IncrTcl 2008-12-15  
TclX 2005-02-07 ==\> TclX 2008-12-15  
Trofs 0.4.3 ==\> Trofs 0.4.4

* * *

I don’t guarantee, but this updates may work recent Ruby/Tk.  
If you try, please replace old ext/tk tree on your Ruby source to  
the new one, and make it (may be required reconfigure also).

From: Antonio G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: Are these widgets worth adding as standard libraries of  
Ruby/Tk?  
Date: Thu, 2 Jul 2009 06:41:57 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> these ruby megawidgets effectively resolve recurring problems, so  
> according to  
> me can be promoted into one library.  
> In the future would be ideal to add tab(notebook) and tree ruby  
> megawidget also. In this way we can avoid to use others tcl/tk libraries  
> (like BWidget).

It looks like a good idea.  
In the updates, althought the megawidgets are still sample scripts.  
those are defined in Tk::RbWidget module (e.g. Tk::RbWidget::Combobx).  
If create a Ruby’s MegaWidgets library in the future,  
classes/modules will be defined in/under Tk::RbWidget.

> An osservation : in “editable\_listbox” and “combobox” when I set state  
> to “disabled” the actions are not inhibited.

Thank you for your report. I fixed them.  
Please try the new Ruby/Tk. 😉
