summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/tk.rb96
-rw-r--r--lib/tktext.rb14
2 files changed, 103 insertions, 7 deletions
diff --git a/lib/tk.rb b/lib/tk.rb
index 3891428..62b275b 100644
--- a/lib/tk.rb
+++ b/lib/tk.rb
@@ -26,6 +26,9 @@ module TkComm
private :error_at
def tk_tcl2ruby(val)
+ if val =~ /^rb_out (c\d+)/
+ return Tk_CMDTBL[$1]
+ end
if val.include? ?\s
return val.split.collect{|v| tk_tcl2ruby(v)}
end
@@ -34,8 +37,6 @@ module TkComm
val.to_i
when /^\./
Tk_WINDOWS[val]
- when /^rb_out (c\d+)/
- Tk_CMDTBL[$1]
when / /
val.split.collect{|elt|
tk_tcl2ruby(elt)
@@ -134,6 +135,7 @@ module TkComm
def _next_cmd_id
id = _curr_cmd_id
Tk_IDs[0] += 1
+ id
end
def install_cmd(cmd)
return '' if cmd == ''
@@ -237,6 +239,10 @@ module TkComm
TkPack.configure *args
end
+ def grid(*args)
+ TkGrid.configure *args
+ end
+
def after(ms, cmd=Proc.new)
myid = _curr_cmd_id
tk_call 'after', ms,
@@ -786,6 +792,70 @@ module TkPack
module_function :configure, :forget, :propagate
end
+module TkGrid
+ include Tk
+ extend Tk
+
+ def bbox(*args)
+ list(tk_call('grid', 'bbox', *args))
+ end
+
+ def configure(widget, *args)
+ if args[-1].kind_of?(Hash)
+ keys = args.pop
+ end
+ wins = [widget.path]
+ for i in args
+ wins.push i.epath
+ end
+ tk_call "grid", 'configure', *(wins+hash_kv(keys))
+ end
+
+ def columnconfigure(master, index, *args)
+ tk_call "grid", 'columnconfigure', master, index, *hash_kv(keys)
+ end
+
+ def rowconfigure(master, index, *args)
+ tk_call "grid", 'rowconfigure', master, index, *hash_kv(keys)
+ end
+
+ def add(widget, *args)
+ configure(widget, *args)
+ end
+
+ def forget(*args)
+ tk_call 'grid', 'forget', *args
+ end
+
+ def info(slave)
+ list(tk_call('grid', 'info', slave))
+ end
+
+ def location(master, x, y)
+ list(tk_call('grid', 'location', master, x, y))
+ end
+
+ def propagate(master, bool=None)
+ bool(tk_call('grid', 'propagate', master.epath, bool))
+ end
+
+ def remove(*args)
+ tk_call 'grid', 'remove', *args
+ end
+
+ def size(master)
+ tk_call 'grid', 'size', master
+ end
+
+ def slaves(*args)
+ list(tk_call('grid', 'slaves', *hash_kv(args)))
+ end
+
+ module_function :bbox, :forget, :propagate, :info
+ module_function :remove, :size, :slaves, :location
+ module_function :configure, :columnconfigure, :rowconfigure
+end
+
module TkOption
include Tk
extend Tk
@@ -833,10 +903,18 @@ class TkObject<TkKernel
end
end
+ def [](id)
+ cget id
+ end
+
def []=(id, val)
configure id, val
end
+ def cget(slot)
+ tk_tcl2ruby tk_call path, 'cget', "-#{slot}"
+ end
+
def configure(slot, value)
if value == FALSE
value = "0"
@@ -891,6 +969,16 @@ class TkWindow<TkObject
self
end
+ def grid(keys = nil)
+ tk_call 'grid', epath, *hash_kv(keys)
+ self
+ end
+
+ def ungrid(keys = nil)
+ tk_call 'grid', 'forget', epath
+ self
+ end
+
def place(keys = nil)
tk_call 'place', epath, *hash_kv(keys)
self
@@ -1131,6 +1219,10 @@ class TkScrollbar<TkWindow
end
class TkTextWin<TkWindow
+ def create_self
+ raise TypeError, "TkTextWin is abstract class"
+ end
+
def bbox(index)
tk_send 'bbox', index
end
diff --git a/lib/tktext.rb b/lib/tktext.rb
index ccd70a2..a940c31 100644
--- a/lib/tktext.rb
+++ b/lib/tktext.rb
@@ -27,8 +27,8 @@ class TkText<TkTextWin
def _addtag(name, obj)
@tags[name] = obj
end
- def tag_names
- tk_send('tag', 'names').collect{|elt|
+ def tag_names(index=nil)
+ tk_split_list(tk_send('tag', 'names', index)).collect{|elt|
if not @tags[elt]
elt
else
@@ -103,13 +103,17 @@ class TkTextTag<TkObject
tk_call @t.path, 'tag', 'add', @id, *index
end
+ def remove(*index)
+ tk_call @t.path, 'tag', 'remove', @id, *index
+ end
+
def configure(keys)
tk_call @t.path, 'tag', 'configure', @id, *hash_kv(keys)
end
- def bind(seq, cmd=Proc.new)
- id = install_cmd(cmd)
- tk_call @t, 'tag', 'bind', tag, "<#{seq}>", id
+ def bind(seq, cmd=Proc.new, args=nil)
+ id = install_bind(cmd, args)
+ tk_call @t, 'tag', 'bind', @id, "<#{seq}>", id
@t._addcmd cmd
end