Update Tk

(Hidetoshi NAGAI) #1


I’ve updated Tk libraries on CVS. This update includes some important
supports. And probably, the eventloop with threads has quicker response
than before. Please try!

  • tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.

  • tkafter.rb: Add self to 1st argument of interval- and loop-proc
    TkAfter#current_interval returns an interval (sleep) time value
    TkAfter#current_args returns an array of arguments
    TkAfter#return_value returns a return value of last loop-proc
    proc{|obj| 500 - obj.current_interval}, 10,
    [proc{|obj| p obj.current_args}, ‘proc’, 1],
    proc{|obj| p obj.current_args; [‘return’, 2]},
    p obj.return_value
    p [‘proc’, obj.current_args[0].call(obj.return_value[1],
    proc{|*args| args[0] + args[1]}, 1],
    proc{p [‘proc’, 4]} ).start(100)

  • tk*.rb: Allow to use Symbols for parameters.
    Allow new notation of constructor (also allow old notation).
    f = TkFrame.new(base, :classname=>‘ButtonFrame’).pack
    :parent => f,
    :text => ‘Quit’,
    :command => proc{exit}
    :fill => :x,
    :pady => 2

  • tkcanvas.rb: (TkcItem) Add ‘coords’ parameter to the canvas item
    constructor (for new notation of constructor).
    c = TkCanvas.new.pack
    l = TkcLine.new(c, :coords=>[[0,0], [100,100]])

  • tcltklib.c: New ‘mainloop’ and ‘mainloop_watchdog’.
    The priority of their event-loop can be controlled.
    They accept an optional argument.
    If it false, they don’t exit although the root widget is destroyed.
    This function is sometimes useful, if it is used with ‘restart’.
    ‘mainloop’ can’t treat Thread#join/value in a callback routine.
    (e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
    ‘mainloop_watchdog’ can treat them, but watchdog thread is always running
    (so, a little heavier than ‘mainloop’).
    If the purpose of using Thread#join/value is to do something under some
    safe-level, please use Proc object.
    (e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})

  • tk.rb: Support functions of new ‘mainloop’ and ‘mainloop_watchdog’.

  • tk.rb: (Tk.restart) Add ‘app-name’ paramater and ‘use’ parameter.
    ‘app-name’ specifies the name and the resource class of the
    application. If ‘app-name’ is specified to ‘xxx’, the application
    class on the resource database is set to ‘Xxx’ and the application
    name is changed by the same rule of Tk.appname method. 'use’
    specifies the main window for embedding the root widget instead of
    generating a new window.

  • tk.rb: Add new parameter ‘widgetname’ to the widget constructor to
    support effective use of Resource Database. For example, the
    resource ‘Xxx*quit.text: QUIT’ can set the text of the button
    generated by the following code.
    TkButton.new(nil, ‘widgetname’=>‘quit’, ‘command’=>proc{exit}).pack

  • tk.rb: TkOption::get always returns a tainted string.
    Add TkOption::new_proc_class.
    It generates a class to import procedures defined on the resource
    database. For example, there is a following resource file.
    ----< resource-test >------------
    *CMD.foo: {|*args| p [$SAFE, :foo, args]}
    *CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
    *Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}

  The following code is a sample of use of the resource file. 
      require 'tk'
      TkOption.readfile 'resource-test'
      p TkOption.new_proc_class(:CMD, [:foo], 1)
      p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)

Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)