class Tk::Toplevel - tk-0.2.0 Documentation

# class Tk::Toplevel

### Constants

TkCommandNames
WidgetClassName

### Public Class Methods

bind(*args, &b) click to toggle source
Calls superclass method TkBindCore#bind

    # File lib/tk/toplevel.rb, line 232
    def self.bind(*args, &b)
      if self == WidgetClassNames[WidgetClassName] || self.name == ''
        super(*args, &b)
      else
        TkDatabaseClass.new(self.name).bind(*args, &b)
      end
    end

bind_append(*args, &b) click to toggle source
Calls superclass method TkBindCore#bind_append

    # File lib/tk/toplevel.rb, line 239
    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

bind_remove(*args) click to toggle source
Calls superclass method TkBindCore#bind_remove

    # File lib/tk/toplevel.rb, line 246
    def self.bind_remove(*args)
      if self == WidgetClassNames[WidgetClassName] || self.name == ''
        super(*args)
      else
        TkDatabaseClass.new(self.name).bind_remove(*args)
      end
    end

bindinfo(*args) click to toggle source
Calls superclass method TkBindCore#bindinfo

    # File lib/tk/toplevel.rb, line 253
    def self.bindinfo(*args)
      if self == WidgetClassNames[WidgetClassName] || self.name == ''
        super(*args)
      else
        TkDatabaseClass.new(self.name).bindinfo(*args)
      end
    end

database_class() click to toggle source

    # File lib/tk/toplevel.rb, line 221
    def self.database_class
      if self == WidgetClassNames[WidgetClassName] || self.name == ''
        self
      else
        TkDatabaseClass.new(self.name)
      end
    end

database_classname() click to toggle source

    # File lib/tk/toplevel.rb, line 228
    def self.database_classname
      self.database_class.name
    end

new(parent=nil, screen=nil, classname=nil, keys=nil) click to toggle source
Calls superclass method TkWindow.new

    # File lib/tk/toplevel.rb, line 99
    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

### Public Instance Methods

add_menubar(menu_spec, tearoff=false, opts=nil) click to toggle source

    # File lib/tk/toplevel.rb, line 213
    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

specific_class() click to toggle source

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

    # File lib/tk/toplevel.rb, line 198
    def specific_class
      @classname
    end

tktrans_get_image() click to toggle source

    # File lib/tkextlib/tktrans/tktrans.rb, line 62
    def tktrans_get_image()
      tk_send('tktrans::settoplevel', @path)
    end

tktrans_set_image(img) click to toggle source

    # File lib/tkextlib/tktrans/tktrans.rb, line 58
    def tktrans_set_image(img)
      tk_send('tktrans::settoplevel', @path, img)
      self
    end

### Private Instance Methods

__boolval_optkeys() click to toggle source

    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

Calls superclass method TkConfigMethod#__boolval_optkeys

    # File lib/tk/toplevel.rb, line 49
    def __boolval_optkeys
      super() << 'container'
    end

__methodcall_optkeys() click to toggle source

    # File lib/tk/toplevel.rb, line 64
    def __methodcall_optkeys  # { key=>method, ... }
      TOPLEVEL_METHODCALL_OPTKEYS
    end

__strval_optkeys() click to toggle source
Calls superclass method TkConfigMethod#__strval_optkeys

    # File lib/tk/toplevel.rb, line 54
    def __strval_optkeys
      super() << 'screen'
    end

__val2ruby_optkeys() click to toggle source
Calls superclass method TkConfigMethod#__val2ruby_optkeys

    # File lib/tk/toplevel.rb, line 59
    def __val2ruby_optkeys  # { key=>proc, ... }
      super().update('menu'=>proc{|v| window(v)})
    end

_wm_command_option_chk(keys) click to toggle source

    # File lib/tk/toplevel.rb, line 69
    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