Module: Tk::Grid

Included in:
Tile::TileWidget, Widget
Defined in:
lib/ffi-tk/command/grid.rb

Overview

Geometry manager that arranges widgets in a grid

The grid command is used to communicate with the grid geometry manager that arranges widgets in rows and columns inside of another window, called the geometry master (or master window).

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.anchor(master, anchor = None) ⇒ Object

The anchor value controls how to place the grid within the master when no row/column has any weight. The default anchor is nw.



19
20
21
# File 'lib/ffi-tk/command/grid.rb', line 19

def self.anchor(master, anchor = None)
  Tk.execute('grid', 'anchor', master, anchor)
end

.bbox(master, col1 = None, row1 = None, col2 = None, row2 = None) ⇒ Object

With no arguments, the bounding box (in pixels) of the grid is returned. The return value consists of 4 integers.

The first two are the pixel offset from the master window (x then y) of the top-left corner of the grid, and the second two integers are the width and height of the grid, also in pixels.

If only col1 and row1 are given, then the bounding box for that cell is returned, where the top left cell is numbered from zero. If col2 and col2 are given as well, then the bounding box spanning the rows and columns indicated is returned.



40
41
42
43
# File 'lib/ffi-tk/command/grid.rb', line 40

def self.bbox(master, col1 = None, row1 = None, col2 = None, row2 = None)
  bbox = Tk.execute('grid', 'bbox', master, column1, row1, column2, row2)
  bbox.map(&:to_i)
end

.columnconfigure(master, index, options = None) ⇒ Object

Query or set the column properties of the index column of the geometry master, master. The valid options are -minsize, -weight, -uniform and -pad. If one or more options are provided, then index may be given as a list of column indices to which the configuration options will operate on. Indices may be integers, window names or the keyword all. For all the options apply to all columns currently occupied be slave windows. For a window name, that window must be a slave of this master and the options apply to all columns currently occupied be the slave. The -minsize option sets the minimum size, in screen units, that will be permitted for this column. The -weight option (an integer value) sets the relative weight for apportioning any extra spaces among columns. A weight of zero (0) indicates the column will not deviate from its requested size. A column whose weight is two will grow at twice the rate as a column of weight one when extra space is allocated to the layout. The -uniform option, when a non-empty value is supplied, places the column in a uniform group with other columns that have the same value for -uniform. The space for columns belonging to a uniform group is allocated so that their sizes are always in strict proportion to their -weight values. See THE GRID ALGORITHM below for further details. The -pad option specifies the number of screen units that will be added to the largest window contained completely in that column when the grid geometry manager requests a size from the containing window. If only an option is specified, with no value, the current value of that option is returned. If only the master window and index is specified, all the current settings are returned in a list of “-option value” pairs.



74
75
76
# File 'lib/ffi-tk/command/grid.rb', line 74

def self.columnconfigure(master, index, options = None)
  Tk.execute('grid', 'columnconfigure', master, index, options.to_tcl_options?)
end

.configure(*arguments) ⇒ Object

The arguments consist of the names of one or more slave windows followed by pairs of arguments that specify how to manage the slaves. The characters -, x and ^, can be specified instead of a window name to alter the default location of a slave.



82
83
84
85
86
# File 'lib/ffi-tk/command/grid.rb', line 82

def self.configure(*arguments)
  options, slaves = arguments.partition{|arg| arg.respond_to?(:to_tcl_options?) }
  options = options.first
  Tk.execute('grid', 'configure', *slaves, options.to_tcl_options?)
end

.forget(*slaves) ⇒ Object

Removes each of the slaves from grid for its master and unmaps their windows. The slaves will no longer be managed by the grid geometry manager. The configuration options for that window are forgotten, so that if the slave is managed once more by the grid geometry manager, the initial default settings are used.



93
94
95
# File 'lib/ffi-tk/command/grid.rb', line 93

def self.forget(*slaves)
  Tk.execute('grid', 'forget', *slaves)
end

.info(slave) ⇒ Object

Returns a list whose elements are the current configuration state of the slave given by slave in the same option-value form that might be specified to grid configure. The first two elements of the list are “-in master” where master is the slave’s master.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ffi-tk/command/grid.rb', line 102

def self.info(slave)
  info = Tk.execute('grid', 'info', slave).to_s
  hash = {}

  info.scan(/(?:-(\w+))\s+([^-][\S]*)/) do
    key = $1.to_sym
    case key
    when :column, :row, :columnspan, :rowspan, :ipadx, :ipady, :padx, :pady
      hash[key] = Integer($2)
    else
      hash[key] = $2.to_str
    end
  end

  hash
end

.location(master, x, y) ⇒ Object

Given x and y values in screen units relative to the master window, the column and row number at that x and y location is returned. For locations that are above or to the left of the grid, -1 is returned.



122
123
124
# File 'lib/ffi-tk/command/grid.rb', line 122

def self.location(master, x, y)
  Tk.execute('grid', 'location', master, x, y)
end

.propagate(master, boolean = None) ⇒ Object

If boolean has a true boolean value such as 1 or on then propagation is enabled for master, which must be a window name (see GEOMETRY PROPAGATION below). If boolean has a false boolean value then propagation is disabled for master. In either of these cases an empty string is returned. If boolean is omitted then the command returns 0 or 1 to indicate whether propagation is currently enabled for master. Propagation is enabled by default.



134
135
136
# File 'lib/ffi-tk/command/grid.rb', line 134

def self.propagate(master, boolean = None)
  Tk.execute('grid', 'propagate', master, boolean)
end

.remove(*slaves) ⇒ Object

Removes each of the slaves from grid for its master and unmaps their windows. The slaves will no longer be managed by the grid geometry manager. However, the configuration options for that window are remembered, so that if the slave is managed once more by the grid geometry manager, the previous values are retained.



174
175
176
# File 'lib/ffi-tk/command/grid.rb', line 174

def self.remove(*slaves)
  Tk.execute('grid', 'remove', *slaves)
end

.rowconfigure(master, index, options = None) ⇒ Object

Query or set the row properties of the index row of the geometry master, master. The valid options are -minsize, -weight, -uniform and -pad. If one or more options are provided, then index may be given as a list of row indices to which the configuration options will operate on. Indices may be integers, window names or the keyword all. For all the options apply to all rows currently occupied be slave windows. For a window name, that window must be a slave of this master and the options apply to all rows currently occupied be the slave. The -minsize option sets the minimum size, in screen units, that will be permitted for this row. The -weight option (an integer value) sets the relative weight for apportioning any extra spaces among rows. A weight of zero (0) indicates the row will not deviate from its requested size. A row whose weight is two will grow at twice the rate as a row of weight one when extra space is allocated to the layout. The -uniform option, when a non-empty value is supplied, places the row in a uniform group with other rows that have the same value for -uniform. The space for rows belonging to a uniform group is allocated so that their sizes are always in strict proportion to their -weight values. See THE GRID ALGORITHM below for further details. The -pad option specifies the number of screen units that will be added to the largest window contained completely in that row when the grid geometry manager requests a size from the containing window. If only an option is specified, with no value, the current value of that option is returned. If only the master window and index is specified, all the current settings are returned in a list of “-option value” pairs.



165
166
167
# File 'lib/ffi-tk/command/grid.rb', line 165

def self.rowconfigure(master, index, options = None)
  Tk.execute('grid', 'rowconfigure', master, index, options.to_tcl_options?)
end

.size(master) ⇒ Object

Returns the size of the grid (in columns then rows) for master. The size is determined either by the slave occupying the largest row or column, or the largest column or row with a minsize, weight, or pad that is non-zero.



182
183
184
# File 'lib/ffi-tk/command/grid.rb', line 182

def self.size(master)
  Tk.execute('grid', 'size', master)
end

.slave(*arguments) ⇒ Object

If the first argument to grid is suitable as the first slave argument to grid configure, either a window name (any value starting with .) or one of the characters x or ^ (see the RELATIVE PLACEMENT section below), then the command is processed in the same way as grid configure.



12
13
14
# File 'lib/ffi-tk/command/grid.rb', line 12

def self.slave(*arguments)
  Tk.execute('grid', 'slave', *arguments)
end

.slaves(master, options = {}) ⇒ Object

If no options are supplied, a list of all of the slaves in master are returned, most recently manages first. Option can be either -row or -column which causes only the slaves in the row (or column) specified by value to be returned.



190
191
192
# File 'lib/ffi-tk/command/grid.rb', line 190

def self.slaves(master, options = {})
  Tk.execute('grid', 'slaves')
end

Instance Method Details

#grid_anchor(anchor = None) ⇒ Object

See Also:

  • Grid::anchor


200
201
202
# File 'lib/ffi-tk/command/grid.rb', line 200

def grid_anchor(anchor = None)
  Grid.anchor(self, anchor)
end

#grid_bbox(col1 = None, row1 = None, col2 = None, row2 = None) ⇒ Object

See Also:

  • Grid::bbox


205
206
207
# File 'lib/ffi-tk/command/grid.rb', line 205

def grid_bbox(col1 = None, row1 = None, col2 = None, row2 = None)
  Grid.bbox(self, col1, row1, col2, row2)
end

#grid_columnconfigure(index, options = None) ⇒ Object

See Also:

  • Grid::columnconfigure


210
211
212
# File 'lib/ffi-tk/command/grid.rb', line 210

def grid_columnconfigure(index, options = None)
  Grid.columnconfigure(self, index, options)
end

#grid_configure(options = None) ⇒ Object

See Also:

  • Grid::configure


215
216
217
# File 'lib/ffi-tk/command/grid.rb', line 215

def grid_configure(options = None)
  Grid.configure(self, options)
end

#grid_forgetObject

See Also:

  • Grid::forget


220
221
222
# File 'lib/ffi-tk/command/grid.rb', line 220

def grid_forget
  Grid.forget(self)
end

#grid_infoObject

See Also:

  • Grid::info


225
226
227
# File 'lib/ffi-tk/command/grid.rb', line 225

def grid_info
  Grid.info(self)
end

#grid_location(x, y) ⇒ Object

See Also:

  • Grid::location


230
231
232
# File 'lib/ffi-tk/command/grid.rb', line 230

def grid_location(x, y)
  Grid.location(self, x, y)
end

#grid_propagate(boolean = None) ⇒ Object

See Also:

  • Grid::propagte


235
236
237
# File 'lib/ffi-tk/command/grid.rb', line 235

def grid_propagate(boolean = None)
  Grid.propagate(self, boolean)
end

#grid_removeObject

See Also:

  • Grid::remove


245
246
247
# File 'lib/ffi-tk/command/grid.rb', line 245

def grid_remove
  Grid.remove(self)
end

#grid_rowconfigure(index, options = None) ⇒ Object

See Also:

  • Tk::Grid.gridgrid::rowconfigure


240
241
242
# File 'lib/ffi-tk/command/grid.rb', line 240

def grid_rowconfigure(index, options = None)
  Grid.rowconfigure(self, index, options)
end

#grid_sizeObject

See Also:

  • Grid::size


250
251
252
# File 'lib/ffi-tk/command/grid.rb', line 250

def grid_size
  Grid.size(self)
end

#grid_slave(options = {}) ⇒ Object

See Also:

  • Grid::slave


195
196
197
# File 'lib/ffi-tk/command/grid.rb', line 195

def grid_slave(options = {})
  Grid.slave(self, options)
end

#grid_slaves(options = {}) ⇒ Object

See Also:

  • Grid::slaves


255
256
257
# File 'lib/ffi-tk/command/grid.rb', line 255

def grid_slaves(options = {})
  Grid.slaves(self, options)
end