Hi, 

From: Ferenc Engard <ferenc / engard.hu>
Subject: tk application name
Date: Mon, 12 Jan 2004 10:25:42 +0900
Message-ID: <4001F7A0.9A5178C5 / engard.hu>
> Dealing with ruby/tk and option database, I have found that ruby sets
> the application name (which can be read by 'tk appname' in tcl/tk)
> always as 'Tk'. I think it should be the same as $0.

'tcltklib' doesn't set the application name. 
The name is the default of the Tk library.
But your request is reasonable. 
I'll edit tcltklib.c to use $0 when ip_name is not given. 
Although you may have troubles on using option database when $0 
includes dots (e.g. 'xxx.rb'), aren't you worried about it?

If you want to use the application class to deal with option 
database on current Ruby/Tk, please read 'ext/tcltklib/MANUAL.eng' 
(an English-like broken text). 

-----------------------------------------------
class TclTkIp
  [class methods]
      new(ip_name=nil, options='')
         : Generate an instance of TclTkIp class. 
         : If 'ip_name' argument is given as a string, it is the name
         : of the Tk interpreter which is shown by 'winfo interps'
         : command. 
         : 'options' argument accepts a string which is the command 
         : line options of wish; such as '-geometry' or '-use'. 
         : The information is used to generate the root widget of the 
         : interpreter. 
         : ( e.g. TclTkIp.new('FOO', '-geometry 500x200 -use 0x2200009') )
         : If is given nil or falsr for the 'option' argument, generates
         : the Tcl interpreter without Tk library. Then the interpreter 
         : doesn't need GUI environment. Therefore, even if a window
         : system doesn't exist or cannot be used, Ruby can control the
         : Tcl interpreter and the extention libraries loaded on the 
         : interpreter. 
-----------------------------------------------

After that, please read 'ext/tk/lib/tk.rb'.

-----------------------------------------------
module TkCore
  include TkComm
  extend TkComm

  unless self.const_defined? :INTERP
    if self.const_defined? :IP_NAME
      name = IP_NAME.to_s
    else
      name = nil
    end
    if self.const_defined? :IP_OPTS
      if IP_OPTS.kind_of?(Hash)
	opts = hash_kv(IP_OPTS).join(' ')
      else
	opts = IP_OPTS.to_s
      end
    else
      opts = ''
    end

    INTERP = TclTkIp.new(name, opts)
-----------------------------------------------

And now, you will know how to give the interpreter name.
For example,

-----------------------------------------------
module TkCore
  IP_NAME = 'XXX' #=> app-class is 'Xxx' (the first letter is capitalized)
  IP_OPTS = {:geometry=>'500x200'}
end
require 'tk'
p Tk.appname  #=> 'XXX'
p TkRoot.new.winfo_class  #=> 'Xxx'
TkOptionDB.add 'Xxx*Text', 'AAA'
TkButton.new.pack  #=> show a button widget with a label text 'AAA'
Tk.mainloop
-----------------------------------------------

( See also 'ext/tk/sample/tkoptdb.rb' )

-- 
                                  Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)