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

« back to all changes in this revision

Viewing changes to ext/tk/lib/tk/grid.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
# tk/grid.rb : control grid geometry manager
 
3
#
 
4
require 'tk'
 
5
 
 
6
module TkGrid
 
7
  include Tk
 
8
  extend Tk
 
9
 
 
10
  TkCommandNames = ['grid'.freeze].freeze
 
11
 
 
12
  def anchor(master, anchor=None)
 
13
    # master = master.epath if master.kind_of?(TkObject)
 
14
    master = _epath(master)
 
15
    tk_call_without_enc('grid', 'anchor', master, anchor)
 
16
  end
 
17
 
 
18
  def bbox(master, *args)
 
19
    # master = master.epath if master.kind_of?(TkObject)
 
20
    master = _epath(master)
 
21
    args.unshift(master)
 
22
    list(tk_call_without_enc('grid', 'bbox', *args))
 
23
  end
 
24
 
 
25
  def configure(win, *args)
 
26
    if args[-1].kind_of?(Hash)
 
27
      opts = args.pop
 
28
    else
 
29
      opts = {}
 
30
    end
 
31
    params = []
 
32
    params.push(_epath(win))
 
33
    args.each{|win|
 
34
      case win
 
35
      when '-', 'x', '^'  # RELATIVE PLACEMENT
 
36
        params.push(win)
 
37
      else
 
38
        params.push(_epath(win))
 
39
      end
 
40
    }
 
41
    opts.each{|k, v|
 
42
      params.push("-#{k}")
 
43
      params.push((v.kind_of?(TkObject))? v.epath: v)
 
44
    }
 
45
    if Tk::TCL_MAJOR_VERSION < 8 ||
 
46
        (Tk::TCL_MAJOR_VERSION == 8 && Tk::TCL_MINOR_VERSION <= 3)
 
47
      if params[0] == '-' || params[0] == 'x' || params[0] == '^'
 
48
        tk_call_without_enc('grid', *params)
 
49
      else
 
50
        tk_call_without_enc('grid', 'configure', *params)
 
51
      end
 
52
    else
 
53
      tk_call_without_enc('grid', 'configure', *params)
 
54
    end
 
55
  end
 
56
  alias grid configure
 
57
 
 
58
  def columnconfigure(master, index, args)
 
59
    # master = master.epath if master.kind_of?(TkObject)
 
60
    master = _epath(master)
 
61
    tk_call_without_enc("grid", 'columnconfigure', 
 
62
                        master, index, *hash_kv(args))
 
63
  end
 
64
 
 
65
  def rowconfigure(master, index, args)
 
66
    # master = master.epath if master.kind_of?(TkObject)
 
67
    master = _epath(master)
 
68
    tk_call_without_enc("grid", 'rowconfigure', master, index, *hash_kv(args))
 
69
  end
 
70
 
 
71
  def columnconfiginfo(master, index, slot=nil)
 
72
    # master = master.epath if master.kind_of?(TkObject)
 
73
    master = _epath(master)
 
74
    if slot
 
75
      case slot
 
76
      when 'uniform', :uniform
 
77
        tk_call_without_enc('grid', 'columnconfigure', 
 
78
                            master, index, "-#{slot}")
 
79
      else
 
80
        num_or_str(tk_call_without_enc('grid', 'columnconfigure', 
 
81
                                       master, index, "-#{slot}"))
 
82
      end
 
83
    else
 
84
      #ilist = list(tk_call_without_enc('grid','columnconfigure',master,index))
 
85
      ilist = simplelist(tk_call_without_enc('grid', 'columnconfigure', 
 
86
                                             master, index))
 
87
      info = {}
 
88
      while key = ilist.shift
 
89
        case key
 
90
        when 'uniform'
 
91
          info[key[1..-1]] = ilist.shift
 
92
        else
 
93
          info[key[1..-1]] = tk_tcl2ruby(ilist.shift)
 
94
        end
 
95
      end
 
96
      info
 
97
    end
 
98
  end
 
99
 
 
100
  def rowconfiginfo(master, index, slot=nil)
 
101
    # master = master.epath if master.kind_of?(TkObject)
 
102
    master = _epath(master)
 
103
    if slot
 
104
      case slot
 
105
      when 'uniform', :uniform
 
106
        tk_call_without_enc('grid', 'rowconfigure', 
 
107
                            master, index, "-#{slot}")
 
108
      else
 
109
        num_or_str(tk_call_without_enc('grid', 'rowconfigure', 
 
110
                                       master, index, "-#{slot}"))
 
111
      end
 
112
    else
 
113
      #ilist = list(tk_call_without_enc('grid', 'rowconfigure', master, index))
 
114
      ilist = simplelist(tk_call_without_enc('grid', 'rowconfigure', 
 
115
                                             master, index))
 
116
      info = {}
 
117
      while key = ilist.shift
 
118
        case key
 
119
        when 'uniform'
 
120
          info[key[1..-1]] = ilist.shift
 
121
        else
 
122
          info[key[1..-1]] = tk_tcl2ruby(ilist.shift)
 
123
        end
 
124
      end
 
125
      info
 
126
    end
 
127
  end
 
128
 
 
129
  def add(widget, *args)
 
130
    configure(widget, *args)
 
131
  end
 
132
 
 
133
  def forget(*args)
 
134
    return '' if args.size == 0
 
135
    wins = args.collect{|win|
 
136
      # (win.kind_of?(TkObject))? win.epath: win
 
137
      _epath(win)
 
138
    }
 
139
    tk_call_without_enc('grid', 'forget', *wins)
 
140
  end
 
141
 
 
142
  def info(slave)
 
143
    # slave = slave.epath if slave.kind_of?(TkObject)
 
144
    slave = _epath(slave)
 
145
    #ilist = list(tk_call_without_enc('grid', 'info', slave))
 
146
    ilist = simplelist(tk_call_without_enc('grid', 'info', slave))
 
147
    info = {}
 
148
    while key = ilist.shift
 
149
      #info[key[1..-1]] = ilist.shift
 
150
      info[key[1..-1]] = tk_tcl2ruby(ilist.shift)
 
151
    end
 
152
    return info
 
153
  end
 
154
 
 
155
  def location(master, x, y)
 
156
    # master = master.epath if master.kind_of?(TkObject)
 
157
    master = _epath(master)
 
158
    list(tk_call_without_enc('grid', 'location', master, x, y))
 
159
  end
 
160
 
 
161
  def propagate(master, mode=None)
 
162
    # master = master.epath if master.kind_of?(TkObject)
 
163
    master = _epath(master)
 
164
    if mode == None
 
165
      bool(tk_call_without_enc('grid', 'propagate', master))
 
166
    else
 
167
      tk_call_without_enc('grid', 'propagate', master, mode)
 
168
    end
 
169
  end
 
170
 
 
171
  def remove(*args)
 
172
    return '' if args.size == 0
 
173
    wins = args.collect{|win|
 
174
      # (win.kind_of?(TkObject))? win.epath: win
 
175
      _epath(win)
 
176
    }
 
177
    tk_call_without_enc('grid', 'remove', *wins)
 
178
  end
 
179
 
 
180
  def size(master)
 
181
    # master = master.epath if master.kind_of?(TkObject)
 
182
    master = _epath(master)
 
183
    list(tk_call_without_enc('grid', 'size', master))
 
184
  end
 
185
 
 
186
  def slaves(master, args)
 
187
    # master = master.epath if master.kind_of?(TkObject)
 
188
    master = _epath(master)
 
189
    list(tk_call_without_enc('grid', 'slaves', master, *hash_kv(args)))
 
190
  end
 
191
 
 
192
  module_function :bbox, :forget, :propagate, :info
 
193
  module_function :remove, :size, :slaves, :location
 
194
  module_function :grid, :configure, :columnconfigure, :rowconfigure
 
195
  module_function :columnconfiginfo, :rowconfiginfo
 
196
end
 
197
=begin
 
198
def TkGrid(win, *args)
 
199
  if args[-1].kind_of?(Hash)
 
200
    opts = args.pop
 
201
  else
 
202
    opts = {}
 
203
  end
 
204
  params = []
 
205
  params.push((win.kind_of?(TkObject))? win.epath: win)
 
206
  args.each{|win|
 
207
    case win
 
208
    when '-', 'x', '^'  # RELATIVE PLACEMENT
 
209
      params.push(win)
 
210
    else
 
211
      params.push((win.kind_of?(TkObject))? win.epath: win)
 
212
    end
 
213
  }
 
214
  opts.each{|k, v|
 
215
    params.push("-#{k}")
 
216
    params.push((v.kind_of?(TkObject))? v.epath: v)
 
217
  }
 
218
  tk_call_without_enc("grid", *params)
 
219
end
 
220
=end