/usr/lib/ruby/1.8/tk/toplevel.rb is in libtcltk-ruby1.8 1.8.7.352-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | #
# tk/toplevel.rb : treat toplevel widget
#
require 'tk'
require 'tk/wm'
require 'tk/menuspec'
class Tk::Toplevel<TkWindow
include Wm
include TkMenuSpec
TkCommandNames = ['toplevel'.freeze].freeze
WidgetClassName = 'Toplevel'.freeze
WidgetClassNames[WidgetClassName] = self
################# old version
# def initialize(parent=nil, screen=nil, classname=nil, keys=nil)
# if screen.kind_of? Hash
# keys = screen.dup
# else
# @screen = screen
# end
# @classname = classname
# if keys.kind_of? Hash
# keys = keys.dup
# @classname = keys.delete('classname') if keys.key?('classname')
# @colormap = keys.delete('colormap') if keys.key?('colormap')
# @container = keys.delete('container') if keys.key?('container')
# @screen = keys.delete('screen') if keys.key?('screen')
# @use = keys.delete('use') if keys.key?('use')
# @visual = keys.delete('visual') if keys.key?('visual')
# end
# super(parent, keys)
# end
#
# def create_self
# s = []
# s << "-class" << @classname if @classname
# s << "-colormap" << @colormap if @colormap
# s << "-container" << @container if @container
# s << "-screen" << @screen if @screen
# s << "-use" << @use if @use
# s << "-visual" << @visual if @visual
# tk_call 'toplevel', @path, *s
# end
#################
def __boolval_optkeys
super() << 'container'
end
private :__boolval_optkeys
def __strval_optkeys
super() << 'screen'
end
private :__strval_optkeys
def __val2ruby_optkeys # { key=>proc, ... }
super().update('menu'=>proc{|v| window(v)})
end
private :__val2ruby_optkeys
def __methodcall_optkeys # { key=>method, ... }
TOPLEVEL_METHODCALL_OPTKEYS
end
private :__methodcall_optkeys
def _wm_command_option_chk(keys)
keys = {} unless keys
new_keys = {}
wm_cmds = {}
conf_methods = _symbolkey2str(__methodcall_optkeys())
keys.each{|k,v| # k is a String
if conf_methods.key?(k)
wm_cmds[conf_methods[k]] = v
elsif Wm.method_defined?(k)
case k
when 'screen','class','colormap','container','use','visual'
new_keys[k] = v
else
case self.method(k).arity
when -1,1
wm_cmds[k] = v
else
new_keys[k] = v
end
end
else
new_keys[k] = v
end
}
[new_keys, wm_cmds]
end
private :_wm_command_option_chk
def initialize(parent=nil, screen=nil, classname=nil, keys=nil)
my_class_name = nil
if self.class < WidgetClassNames[WidgetClassName]
my_class_name = self.class.name
my_class_name = nil if my_class_name == ''
end
if parent.kind_of? Hash
keys = _symbolkey2str(parent)
if keys.key?('classname')
keys['class'] = keys.delete('classname')
end
@classname = keys['class']
@colormap = keys['colormap']
@container = keys['container']
@screen = keys['screen']
@use = keys['use']
@visual = keys['visual']
if !@classname && my_class_name
keys['class'] = @classname = my_class_name
end
if @classname.kind_of? TkBindTag
@db_class = @classname
keys['class'] = @classname = @classname.id
elsif @classname
@db_class = TkDatabaseClass.new(@classname)
keys['class'] = @classname
else
@db_class = self.class
@classname = @db_class::WidgetClassName
end
keys, cmds = _wm_command_option_chk(keys)
super(keys)
cmds.each{|k,v|
if v.kind_of? Array
self.__send__(k,*v)
else
self.__send__(k,v)
end
}
return
end
if screen.kind_of? Hash
keys = screen
else
@screen = screen
if classname.kind_of? Hash
keys = classname
else
@classname = classname
end
end
if keys.kind_of? Hash
keys = _symbolkey2str(keys)
if keys.key?('classname')
keys['class'] = keys.delete('classname')
end
@classname = keys['class'] unless @classname
@colormap = keys['colormap']
@container = keys['container']
@screen = keys['screen'] unless @screen
@use = keys['use']
@visual = keys['visual']
else
keys = {}
end
if !@classname && my_class_name
keys['class'] = @classname = my_class_name
end
if @classname.kind_of? TkBindTag
@db_class = @classname
keys['class'] = @classname = @classname.id
elsif @classname
@db_class = TkDatabaseClass.new(@classname)
keys['class'] = @classname
else
@db_class = self.class
@classname = @db_class::WidgetClassName
end
keys, cmds = _wm_command_option_chk(keys)
super(parent, keys)
cmds.each{|k,v|
if v.kind_of? Array
self.send(k,*v)
else
self.send(k,v)
end
}
end
#def create_self(keys)
# if keys and keys != None
# tk_call_without_enc('toplevel', @path, *hash_kv(keys, true))
# else
# tk_call_without_enc('toplevel', @path)
# end
#end
#private :create_self
def specific_class
@classname
end
def add_menu(menu_info, tearoff=false, opts=nil)
# See tk/menuspec.rb for menu_info.
# opts is a hash of default configs for all of cascade menus.
# Configs of menu_info can override it.
if tearoff.kind_of?(Hash)
opts = tearoff
tearoff = false
end
_create_menubutton(self, menu_info, tearoff, opts)
end
def add_menubar(menu_spec, tearoff=false, opts=nil)
# See tk/menuspec.rb for menu_spec.
# opts is a hash of default configs for all of cascade menus.
# Configs of menu_spec can override it.
menu_spec.each{|info| add_menu(info, tearoff, opts)}
self.menu
end
def self.database_class
if self == WidgetClassNames[WidgetClassName] || self.name == ''
self
else
TkDatabaseClass.new(self.name)
end
end
def self.database_classname
self.database_class.name
end
def self.bind(*args, &b)
if self == WidgetClassNames[WidgetClassName] || self.name == ''
super(*args, &b)
else
TkDatabaseClass.new(self.name).bind(*args, &b)
end
end
def self.bind_append(*args, &b)
if self == WidgetClassNames[WidgetClassName] || self.name == ''
super(*args, &b)
else
TkDatabaseClass.new(self.name).bind_append(*args, &b)
end
end
def self.bind_remove(*args)
if self == WidgetClassNames[WidgetClassName] || self.name == ''
super(*args)
else
TkDatabaseClass.new(self.name).bind_remove(*args)
end
end
def self.bindinfo(*args)
if self == WidgetClassNames[WidgetClassName] || self.name == ''
super(*args)
else
TkDatabaseClass.new(self.name).bindinfo(*args)
end
end
end
#TkToplevel = Tk::Toplevel unless Object.const_defined? :TkToplevel
Tk.__set_toplevel_aliases__(:Tk, Tk::Toplevel, :TkToplevel)
|