~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to ext/tk/lib/tkextlib/tcllib/getstring.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
#  tkextlib/tcllib/getstring.rb
 
3
#                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
 
4
#
 
5
#   * Part of tcllib extension
 
6
#   * A dialog which consists of an Entry, OK, and Cancel buttons.
 
7
#
 
8
 
 
9
require 'tk'
 
10
require 'tk/entry'
 
11
require 'tkextlib/tcllib.rb'
 
12
 
 
13
# TkPackage.require('getstring', '0.1')
 
14
TkPackage.require('getstring')
 
15
 
 
16
module Tk::Tcllib
 
17
  class GetString_Dialog < TkWindow
 
18
    PACKAGE_NAME = 'getstring'.freeze
 
19
    def self.package_name
 
20
      PACKAGE_NAME
 
21
    end
 
22
 
 
23
    def self.package_version
 
24
      begin
 
25
        TkPackage.require('getstring')
 
26
      rescue
 
27
        ''
 
28
      end
 
29
    end
 
30
  end
 
31
end
 
32
 
 
33
 
 
34
class Tk::Tcllib::GetString_Dialog
 
35
  TkCommandNames = ['::getstring::tk_getString'.freeze].freeze
 
36
  WidgetClassName = 'TkSDialog'.freeze
 
37
  WidgetClassNames[WidgetClassName] = self
 
38
 
 
39
  def self.show(*args)
 
40
    dialog = self.new(*args)
 
41
    dialog.show
 
42
    [dialog.status, dialog.value]
 
43
  end
 
44
  def self.display(*args)
 
45
    self.show(*args)
 
46
  end
 
47
 
 
48
  def initialize(*args)   # args = (parent=nil, text='', keys=nil)
 
49
    keys = args.pop
 
50
    if keys.kind_of?(Hash)
 
51
      text = args.pop
 
52
      @keys = _symbolkey2str(keys)
 
53
      args.push(keys)
 
54
    else
 
55
      text = keys
 
56
      @keys = {}
 
57
    end
 
58
    if text
 
59
      @text = text.dup
 
60
    else
 
61
      @text = ''
 
62
    end
 
63
 
 
64
    @variable = TkVariable.new
 
65
    @status = nil
 
66
 
 
67
    super(*args)
 
68
  end
 
69
 
 
70
  def create_self(keys)
 
71
    # dummy
 
72
  end
 
73
  private :create_self
 
74
 
 
75
  def show
 
76
    @variable.value = ''
 
77
    @status = bool(tk_call(self.class::TkCommandNames[0], 
 
78
                           @path, @variable, @text, *hash_kv(@keys)))
 
79
  end
 
80
  alias display show
 
81
 
 
82
  def status
 
83
    @status
 
84
  end
 
85
 
 
86
  def value
 
87
    @variable.value
 
88
  end
 
89
 
 
90
  def cget(slot)
 
91
    slot = slot.to_s
 
92
    if slot == 'text'
 
93
      @text
 
94
    else
 
95
      @keys[slot]
 
96
    end
 
97
  end
 
98
 
 
99
  def configure(slot, value=None)
 
100
    if slot.kind_of?(Hash)
 
101
      slot.each{|k, v| configure(k, v)}
 
102
    else
 
103
      slot = slot.to_s
 
104
      value = _symbolkey2str(value) if value.kind_of?(Hash)
 
105
      if value && value != None
 
106
        if slot == 'text'
 
107
          @text = value.to_s
 
108
        else
 
109
          @keys[slot] = value
 
110
        end
 
111
      else
 
112
        if slot == 'text'
 
113
          @text = ''
 
114
        else
 
115
          @keys.delete(slot)
 
116
        end
 
117
      end
 
118
    end
 
119
    self
 
120
  end
 
121
 
 
122
  def configinfo(slot = nil)
 
123
    if slot
 
124
      slot = slot.to_s
 
125
      [ slot, nil, nil, nil, ( (slot == 'text')? @text: @keys[slot] ) ]
 
126
    else
 
127
      @keys.collect{|k, v| [ k, nil, nil, nil, v ] }   \
 
128
      << [ 'text', nil, nil, nil, @text ]
 
129
    end
 
130
  end
 
131
end