summaryrefslogtreecommitdiff
path: root/ext/tk
diff options
context:
space:
mode:
Diffstat (limited to 'ext/tk')
-rw-r--r--ext/tk/lib/tk.rb49
-rw-r--r--ext/tk/lib/tkcanvas.rb3
-rw-r--r--ext/tk/lib/tkclass.rb2
-rw-r--r--ext/tk/lib/tkentry.rb105
4 files changed, 150 insertions, 9 deletions
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index 54d5d861f8..e5c2c2ece0 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -269,40 +269,61 @@ module TkComm
end
class Event
- def initialize(seq,b,f,h,k,s,t,w,x,y,aa,ee,kk,nn,ww,tt,xx,yy)
+ def initialize(seq,a,b,c,d,f,h,k,m,o,p,s,t,w,x,y,
+ aa,bb,dd,ee,kk,nn,rr,ss,tt,ww,xx,yy)
@serial = seq
+ @above = a
@num = b
+ @count = c
+ @detail = d
@focus = (f == 1)
@height = h
@keycode = k
+ @mode = m
+ @override = (o == 1)
+ @place = p
@state = s
@time = t
@width = w
@x = x
@y = y
@char = aa
+ @borderwidth = bb
+ @wheel_delta = dd
@send_event = (ee == 1)
@keysym = kk
@keysym_num = nn
+ @rootwin_id = rr
+ @subwindow = ss
@type = tt
@widget = ww
@x_root = xx
@y_root = yy
end
attr :serial
+ attr :above
attr :num
+ attr :count
+ attr :detail
attr :focus
attr :height
attr :keycode
+ attr :mode
+ attr :override
+ attr :place
attr :state
attr :time
attr :width
attr :x
attr :y
attr :char
+ attr :borderwidth
+ attr :wheel_delta
attr :send_event
attr :keysym
attr :keysym_num
+ attr :rootwin_id
+ attr :subwindow
attr :type
attr :widget
attr :x_root
@@ -319,7 +340,8 @@ module TkComm
id = install_cmd(proc{|arg|
TkUtil.eval_cmd cmd, Event.new(*arg)
})
- id + ' %# %b %f %h %k %s %t %w %x %y %A %E %K %N %W %T %X %Y'
+ id + ' %# %a %b %c %d %f %h %k %m %o %p %s %t %w %x %y' +
+ ' %A %B %D %E %K %N %R %S %T %W %X %Y'
end
end
@@ -550,6 +572,10 @@ module TkCore
tk_call 'tk_chooseColor', *hash_kv(keys)
end
+ def chooseDirectory(keys = nil)
+ tk_call 'tk_chooseDirectory', *hash_kv(keys)
+ end
+
def tk_call(*args)
print args.join(" "), "\n" if $DEBUG
args.collect! {|x|ruby2tcl(x)}
@@ -2352,7 +2378,7 @@ class TkRadiobutton<TkButton
configure 'variable', tk_trace_variable(v)
end
end
-tkRadioButton = TkRadiobutton
+TkRadioButton = TkRadiobutton
class TkCheckbutton<TkRadiobutton
WidgetClassNames['Checkbutton'] = self
@@ -2377,6 +2403,7 @@ class TkMessage<TkLabel
tk_call 'message', @path
end
end
+TkRadiobutton = TkRadioButton
class TkScale<TkWindow
WidgetClassName = 'Scale'.freeze
@@ -2405,6 +2432,7 @@ class TkScale<TkWindow
set val
end
end
+TkCheckbutton = TkCheckButton
class TkScrollbar<TkWindow
WidgetClassName = 'Scrollbar'.freeze
@@ -2702,6 +2730,9 @@ class TkMenu<TkWindow
def postcommand(cmd=Proc.new)
configure_cmd 'postcommand', cmd
end
+ def tearoffcommand(cmd=Proc.new)
+ configure_cmd 'tearoffcommand', cmd
+ end
def menutype(index)
tk_send 'type', index
end
@@ -2747,6 +2778,17 @@ class TkMenu<TkWindow
end
end
+class TkMenuClone<TkMenu
+ def initialize(parent, type=nil)
+ unless parent.kind_of?(TkMenu)
+ fail ArgumentError, "parent must be TkMenu"
+ end
+ @parent = parent
+ install_win(@parent)
+ tk_call @parent.path, 'clone', @path, type
+ end
+end
+
module TkSystemMenu
def initialize(parent, keys=nil)
fail unless parent.kind_of? TkMenu
@@ -2932,6 +2974,7 @@ autoload :TkImage, 'tkcanvas'
autoload :TkBitmapImage, 'tkcanvas'
autoload :TkPhotoImage, 'tkcanvas'
autoload :TkEntry, 'tkentry'
+autoload :TkSpinbox, 'tkentry'
autoload :TkText, 'tktext'
autoload :TkDialog, 'tkdialog'
autoload :TkMenubar, 'tkmenubar'
diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb
index 5f4bdadaee..88a91ae5d2 100644
--- a/ext/tk/lib/tkcanvas.rb
+++ b/ext/tk/lib/tkcanvas.rb
@@ -781,6 +781,9 @@ class TkImage<TkObject
def height
number(tk_call('image', 'height', @path))
end
+ def inuse
+ bool(tk_call('image', 'inuse', @path))
+ end
def itemtype
tk_call('image', 'type', @path)
end
diff --git a/ext/tk/lib/tkclass.rb b/ext/tk/lib/tkclass.rb
index f5673d7fe7..fe49c55826 100644
--- a/ext/tk/lib/tkclass.rb
+++ b/ext/tk/lib/tkclass.rb
@@ -10,7 +10,7 @@ Frame = TkFrame
Label = TkLabel
Button = TkButton
Radiobutton = TkRadiobutton
-Checkbutton = TkCheckButton
+Checkbutton = TkCheckbutton
Message = TkMessage
Entry = TkEntry
Text = TkText
diff --git a/ext/tk/lib/tkentry.rb b/ext/tk/lib/tkentry.rb
index 5207d9b895..6c050d7cf1 100644
--- a/ext/tk/lib/tkentry.rb
+++ b/ext/tk/lib/tkentry.rb
@@ -18,6 +18,10 @@ class TkEntry<TkLabel
tk_call 'entry', @path
end
+ def bbox(index)
+ tk_send 'bbox', index
+ end
+
def delete(s, e=None)
tk_send 'delete', s, e
end
@@ -59,14 +63,77 @@ class TkEntry<TkLabel
tk_send 'selection', 'to', index
end
- def validate
- if tk_send('validate') == '0'
- false
- else
- true
+ def validate(mode = nil)
+ if mode
+ configure 'validate', mode
+ else
+ if tk_send('validate') == '0'
+ false
+ else
+ true
+ end
end
end
+ class ValidateCmd
+ include TkComm
+
+ class ValidateArgs
+ def initialize(d,i,s,v,pp,ss,vv,ww)
+ @action = d
+ @index = i
+ @current = s
+ @type = v
+ @value = pp
+ @string = ss
+ @triggered = vv
+ @widget = ww
+ end
+ attr :action
+ attr :index
+ attr :current
+ attr :type
+ attr :value
+ attr :string
+ attr :triggered
+ attr :widget
+ end
+
+ def initialize(cmd = Proc.new, args=nil)
+ if args
+ @id = install_cmd(proc{|*arg|
+ TkUtil.eval_cmd cmd, *arg
+ }) + " " + args
+ else
+ @id = install_cmd(proc{|arg|
+ TkUtil.eval_cmd cmd, ValidateArgs.new(*arg)
+ }) + ' %d %i %s %v %P %S %V %W'
+ end
+ end
+
+ def to_eval
+ @id
+ end
+ end
+
+ def validatecommand(cmd = ValidateCmd.new, args = nil)
+ if cmd.kind_of?(ValidateCmd)
+ configure('validatecommand', cmd)
+ else
+ configure('validatecommand', ValidateCmd.new(cmd, args))
+ end
+ end
+ alias vcmd validatecommand
+
+ def invalidcommand(cmd = ValidateCmd.new, args = nil)
+ if cmd.kind_of?(ValidateCmd)
+ configure('invalidcommand', cmd)
+ else
+ configure('invalidcommand', ValidateCmd.new(cmd, args))
+ end
+ end
+ alias invcmd invalidcommand
+
def value
tk_send 'get'
end
@@ -75,3 +142,31 @@ class TkEntry<TkLabel
tk_send 'insert', 0, val
end
end
+
+class TkSpinbox<TkEntry
+ WidgetClassName = 'Spinbox'.freeze
+ WidgetClassNames[WidgetClassName] = self
+ def self.to_eval
+ WidgetClassName
+ end
+
+ def create_self
+ tk_call 'spinbox', @path
+ end
+
+ def identify(x, y)
+ tk_send 'identify', x, y
+ end
+
+ def spinup
+ tk_send 'invoke', 'spinup'
+ end
+
+ def spindown
+ tk_send 'invoke', 'spindown'
+ end
+
+ def set(str)
+ tk_send 'set', str
+ end
+end