summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/tcltklib/tcltklib.c25
-rw-r--r--ext/tk/lib/tk.rb47
-rw-r--r--ext/tk/lib/tkfont.rb18
-rw-r--r--ext/tk/lib/tktext.rb2
4 files changed, 70 insertions, 22 deletions
diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c
index e9c2b56fc1..7acbacdd94 100644
--- a/ext/tcltklib/tcltklib.c
+++ b/ext/tcltklib/tcltklib.c
@@ -120,6 +120,30 @@ ip_eval_rescue(failed, einfo)
return Qnil;
}
+/* restart Tk */
+static VALUE
+lib_restart(self)
+ VALUE self;
+{
+ struct tcltkip *ptr; /* tcltkip data struct */
+
+ /* get the data struct */
+ Data_Get_Struct(self, struct tcltkip, ptr);
+
+ /* destroy the root wdiget */
+ ptr->return_value = Tcl_Eval(ptr->ip, "destroy .");
+ /* ignore ERROR */
+ DUMP2("(TCL_Eval result) %d", ptr->return_value);
+
+ /* execute Tk_Init */
+ DUMP1("Tk_Init");
+ if (Tk_Init(ptr->ip) == TCL_ERROR) {
+ rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
+ }
+
+ return Qnil;
+}
+
static int
#if TCL_MAJOR_VERSION >= 8
ip_ruby(clientData, interp, argc, argv)
@@ -521,6 +545,7 @@ Init_tcltklib()
rb_define_method(ip, "_invoke", ip_invoke, -1);
rb_define_method(ip, "_return_value", ip_retval, 0);
rb_define_method(ip, "mainloop", lib_mainloop, 0);
+ rb_define_method(ip, "restart", lib_restart, 0);
main_thread = rb_thread_current();
#ifdef __MACOS__
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index a16694bf76..a935a55e16 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -450,11 +450,11 @@ module TkComm
end
def pack(*args)
- TkPack.configure *args
+ TkPack.configure(*args)
end
def grid(*args)
- TkGrid.configure *args
+ TkGrid.configure(*args)
end
def update(idle=nil)
@@ -495,18 +495,18 @@ module TkCore
myid = _curr_cmd_id
cmdid = install_cmd(cmd)
tk_call("after",ms,cmdid)
- return
- if false #defined? Thread
- Thread.start do
- ms = Float(ms)/1000
- ms = 10 if ms == 0
- sleep ms/1000
- cmd.call
- end
- else
- cmdid = install_cmd(cmd)
- tk_call("after",ms,cmdid)
- end
+# return
+# if false #defined? Thread
+# Thread.start do
+# ms = Float(ms)/1000
+# ms = 10 if ms == 0
+# sleep ms/1000
+# cmd.call
+# end
+# else
+# cmdid = install_cmd(cmd)
+# tk_call("after",ms,cmdid)
+# end
end
def after_idle(cmd=Proc.new)
@@ -620,6 +620,12 @@ module TkCore
TclTkLib.mainloop
end
+ def restart
+ TkCore::INTERP.restart
+ TkComm::Tk_WINDOWS.clear
+ nil
+ end
+
def event_generate(window, context, keys=nil)
window = window.path if window.kind_of? TkObject
if keys
@@ -651,10 +657,11 @@ module TkCore
end
def tk_call(*args)
- print args.join(" "), "\n" if $DEBUG
+ puts args.inspect if $DEBUG
args.collect! {|x|ruby2tcl(x)}
args.compact!
args.flatten!
+ print "=> ", args.join(" ").inspect, "\n" if $DEBUG
begin
res = INTERP._invoke(*args)
rescue NameError
@@ -670,7 +677,7 @@ module TkCore
if INTERP._return_value() != 0
fail RuntimeError, res, error_at
end
- print "==> ", res, "\n" if $DEBUG
+ print "==> ", res.inspect, "\n" if $DEBUG
return res
end
end
@@ -830,8 +837,8 @@ module Tk
if bar
@xscrollbar = bar
@xscrollbar.orient 'horizontal'
- self.xscrollcommand {|arg| @xscrollbar.set *arg}
- @xscrollbar.command {|arg| self.xview *arg}
+ self.xscrollcommand {|arg| @xscrollbar.set(*arg)}
+ @xscrollbar.command {|arg| self.xview(*arg)}
end
@xscrollbar
end
@@ -839,8 +846,8 @@ module Tk
if bar
@yscrollbar = bar
@yscrollbar.orient 'vertical'
- self.yscrollcommand {|arg| @yscrollbar.set *arg}
- @yscrollbar.command {|arg| self.yview *arg}
+ self.yscrollcommand {|arg| @yscrollbar.set(*arg)}
+ @yscrollbar.command {|arg| self.yview(*arg)}
end
@yscrollbar
end
diff --git a/ext/tk/lib/tkfont.rb b/ext/tk/lib/tkfont.rb
index 42cce80fa3..c84d0960ed 100644
--- a/ext/tk/lib/tkfont.rb
+++ b/ext/tk/lib/tkfont.rb
@@ -758,9 +758,25 @@ class TkFont
###################################
public
###################################
+ def method_missing(id, *args)
+ name = id.id2name
+ case args.length
+ when 1
+ configure name, args[0]
+ when 0
+ begin
+ configinfo name
+ rescue
+ fail NameError, "undefined local variable or method `#{name}' for #{self.to_s}", error_at
+ end
+ else
+ fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at
+ end
+ end
+
def call_font_configure(path, *args)
args += hash_kv(args.pop.update(@fontslot))
- tk_call *args
+ tk_call(*args)
Tk_FontUseTBL[path] = self
self
end
diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb
index 493506f7ed..75b28d8477 100644
--- a/ext/tk/lib/tktext.rb
+++ b/ext/tk/lib/tktext.rb
@@ -38,7 +38,7 @@ class TkText<TkTextWin
def self.new(*args, &block)
obj = super(*args){}
obj.init_instance_variable
- obj.instance_eval &block if defined? yield
+ obj.instance_eval(&block) if defined? yield
obj
end