[RFC] Are these widgets worth adding as standard libraries ofRuby/Tk?

  • Thread starter Hidetoshi NAGAI
  • Start date
H

Hidetoshi NAGAI

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

class TkCombobox
A combobox widget, but its select-listbox has autoscroll tabs.


* 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
 
A

Antonio Galeone

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
 
J

Jordon Bedwell

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=20
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=3Dhtml_cache_path(path)
logger.info("Caching Page: #{cache_path}")
metadata =3D YAML.load(metadata)
if (File.extname(cache_path).blank? || File.extname(cache_path) =3D=3D =
".seo") && (metadata['Content-Type'].nil? || =
metadata['Content-Type'].starts_with?('text/html'))
cache_path =3D 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 =3D page_cache_path(path)
if (cache_path.ends_with?('_site-root'))
cache_path.sub!(/_site-root$/, 'index')
end
cache_path
end
end
 
M

Michael Linfield

Jordon said:
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
 
J

Jordon Bedwell

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 :p
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)

-----Original Message-----
From: David A. Black [mailto:[email protected]]
Sent: Wednesday, July 01, 2009 5:36 PM
To: ruby-talk ML
Subject: Re: Can't Convert Symbol to String

Hi --

Can anybody help me with this error? "Can't Convert Symbol to string"

Where are you getting the error?


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Now available: The Well-Grounded Rubyist (http://manning.com/black2)
"Ruby 1.9: What You Need To Know" Envycasts with David A. Black
http://www.envycasts.com
 
H

Hidetoshi NAGAI

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 Galeone <[email protected]>
Subject: Re: Are these widgets worth adding as standard libraries of Ruby/Tk?
Date: Thu, 2 Jul 2009 06:41:57 +0900
Message-ID: said:
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. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top