diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-07-17 05:12:48 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-07-17 05:12:48 +0000 |
commit | c2fa49a9b453621dbe80630f3be88223fe10ab29 (patch) | |
tree | b7c9e8cc04031fd40639c05c2e96544d80934c1b /lib/tkdialog.rb | |
parent | 20e305950e9fb53e1b1cb338f9b04b1be43fd7bb (diff) |
1.1c0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/tkdialog.rb')
-rw-r--r-- | lib/tkdialog.rb | 91 |
1 files changed, 85 insertions, 6 deletions
diff --git a/lib/tkdialog.rb b/lib/tkdialog.rb index 011d431951..1133db6ae9 100644 --- a/lib/tkdialog.rb +++ b/lib/tkdialog.rb @@ -1,15 +1,84 @@ require "tk" class TkDialog < TkWindow + extend Tk + # initialize tk_dialog - def initialize - super + def initialize(keys = nil) + super() @var = TkVariable.new id = @var.id - INTERP._eval('eval {global '+id+';'+ + + @title = title + + @message = message + @message_config = message_config + + @bitmap = bitmap + @bitmap_config = message_config + + @default_button = default_button + + @buttons = buttons + @button_configs = proc{|num| button_configs num} + + if keys.kind_of? Hash + @title = keys['title'] if keys['title'] + @message = keys['message'] if keys['message'] + @bitmap = keys['bitmap'] if keys['bitmap'] + @default_button = keys['default'] if keys['default'] + @buttons = keys['buttons'] if keys['buttons'] + + @command = keys['prev_command'] + + @message_config = keys['message_config'] if keys['message_config'] + @bitmap_config = keys['bitmap_config'] if keys['bitmap_config'] + @button_configs = keys['button_configs'] if keys['button_configs'] + end + + if @title.include? ?\s + @title = '{' + @title + '}' + end + + @buttons = tk_split_list(@buttons) if @buttons.kind_of? String + @buttons = @buttons.collect{|s| + if s.kind_of? Array + s = s.join(' ') + end + if s.include? ?\s + '{' + s + '}' + else + s + end + } + + config = "" + if @message_config.kind_of? Hash + config << format("%s.msg configure %s\n", + @path, hash_kv(@message_config).join(' ')) + end + if @bitmap_config.kind_of? Hash + config << format("%s.msg configure %s\n", + @path, hash_kv(@bitmap_config).join(' ')) + end + if @button_configs.kind_of? Proc + @buttons.each_index{|i| + if (c = @button_configs.call(i)).kind_of? Hash + config << format("%s.button%s configure %s\n", + @path, i, hash_kv(c).join(' ')) + end + } + end + config = 'after idle {' + config + '};' if config != "" + + if @command.kind_of? Proc + @command.call(self) + end + + INTERP._eval('eval {global '+id+';'+config+ 'set '+id+' [tk_dialog '+ - @path+" "+title+" \"#{message}\" "+bitmap+" "+ - String(default_button)+" "+buttons+']}') + @path+" "+@title+" {#{@message}} "+@bitmap+" "+ + String(@default_button)+" "+@buttons.join(' ')+']}') end def value return @var.value.to_i @@ -25,14 +94,24 @@ class TkDialog < TkWindow def message return "MESSAGE" end + def message_config + return nil + end def bitmap return "info" end + def bitmap_config + return nil + end def default_button return 0 end def buttons - return "BUTTON1 BUTTON2" + #return "BUTTON1 BUTTON2" + return ["BUTTON1", "BUTTON2"] + end + def button_configs(num) + return nil end end |