Module: TclTk

Defined in:
lib/tcltk.rb

Overview

module TclTk: collection of tcl/tk utilities (supplies namespace.)

Class Method Summary collapse

Class Method Details

._addcallback(ca) ⇒ Object

TclTk._addcallback(ca): register callback

ca: callback(TclTkCallback)


53
54
55
56
# File 'lib/tcltk.rb', line 53

def TclTk._addcallback(ca)
  print("_addcallback: ", ca.to_s(), "\n") if $DEBUG
  @callback[ca.to_s()] = ca
end

._callcallback(key, arg) ⇒ Object

TclTk._callcallback(key, arg): invoke registered callback

key: key to select callback (to_s value of the TclTkCallback)
arg: parameter from tcl/tk interpreter


61
62
63
64
65
66
67
# File 'lib/tcltk.rb', line 61

def TclTk._callcallback(key, arg)
  print("_callcallback: ", @callback[key].inspect, "\n") if $DEBUG
  @callback[key]._call(arg)
  # throw out callback value
  # should return String to satisfy rb_eval_string()
  return ""
end

._newname(prefix) ⇒ Object

TclTk._newname(prefix): generate unique name(String)

prefix: prefix of the unique name


71
72
73
74
75
76
77
78
79
80
81
# File 'lib/tcltk.rb', line 71

def TclTk._newname(prefix)
  # generated name counter is stored in @namecnt
  if !@namecnt.key?(prefix)
    # first appearing prefix, initialize
    @namecnt[prefix] = 1
  else
    # already appeared prefix, generate next name
    @namecnt[prefix] += 1
  end
  return "#{prefix}#{@namecnt[prefix]}"
end

.dcb(ca, wid, w) ⇒ Object

TclTk.dcb(ca, wid, W): call TclTk.deletecallbackkey() for each callbacks

  in an array.
  this is for callback for top-level <Destroy>
ca: array of callbacks(TclTkCallback)
wid: top-level widget(TclTkWidget)
w: information about window given by %W(String)


43
44
45
46
47
48
49
# File 'lib/tcltk.rb', line 43

def TclTk.dcb(ca, wid, w)
  if wid.to_s() == w
    ca.each{|i|
      TclTk.deletecallbackkey(i)
    }
  end
end

.deletecallbackkey(ca) ⇒ Object

TclTk.deletecallbackkey(ca): remove callback from TclTk module

  this does not remove callbacks from tcl/tk interpreter
  without calling this method, TclTkInterpreter will not be GCed
ca: callback(TclTkCallback)


32
33
34
35
# File 'lib/tcltk.rb', line 32

def TclTk.deletecallbackkey(ca)
  print("deletecallbackkey: ", ca.to_s(), "\n") if $DEBUG
  @callback.delete(ca.to_s)
end

.mainloopObject

TclTk.mainloop(): call TclTkLib.mainloop()



22
23
24
25
26
# File 'lib/tcltk.rb', line 22

def TclTk.mainloop()
  print("mainloop: start\n") if $DEBUG
  TclTkLib.mainloop()
  print("mainloop: end\n") if $DEBUG
end