Module: Tk::Image

Defined in:
lib/ffi-tk/command/image.rb

Class Method Summary collapse

Class Method Details

.create(type, name = None, options = None) ⇒ Object

Creates an image and a commend of the same name. Returns the name of the command containing the image.

type specifies the type of the image, which must be one of the types currently defined (e.g., bitmap or photo).

name specifies the name for the image; if it is ommitted then Tk picks a name of the form imagex, where x is an integer.

options may be a Hash containing configuration options for the new image.

The legal set of options is defined separately for each image type; see documentation of [Image] for built-in image types.

If a proc already exists with the given name, then it is replaced with the new image and any instances of that image will redisplay with the new contents. It is important to note that [create] will silently overwrite any existing images of the same name, so choose the name wisely.

It is recommended to use a separate namespace for image names, like “::img::logo” or “::img::large”



29
30
31
32
33
34
35
36
37
# File 'lib/ffi-tk/command/image.rb', line 29

def create(type, name = None, options = None)
  if None == name
    Tk.execute(:image, :create, type)
  elsif None == options && name.respond_to?(:to_hash)
    Tk.execute(:image, :create, type, name.to_tcl_options)
  elsif None != name && None != options
    Tk.exeucte(:image, :create, type, name, options.to_tcl_options)
  end
end

.delete(*names) ⇒ Object

Deletes each of the named images and returns an empty string. If there are instances of the images displayed in widgets, the images will not actually be deleted until all of the instances are released. However, the association between the instances and the image manager will be dropped. Existing instances will retain their sizes but redisplay as empty areas. If a deleted image is recreated with another call to image create, the existing instances will use the new image.



47
48
49
# File 'lib/ffi-tk/command/image.rb', line 47

def delete(*names)
  Tk.execute(:image, :delete, *names)
end

.height(name) ⇒ Object

Returns a decimal string giving the height of image name in pixels.



52
53
54
# File 'lib/ffi-tk/command/image.rb', line 52

def height(name)
  Tk.execute(:image, :height, name)
end

.inuse(name) ⇒ Object

Returns a boolean value indicating whether or not the image given by name is in use by any widgets.



58
59
60
# File 'lib/ffi-tk/command/image.rb', line 58

def inuse(name)
  Tk.execute(:image, :inuse, name).to_boolean
end

.namesObject

Returns a list containing the names of all existing images.



63
64
65
# File 'lib/ffi-tk/command/image.rb', line 63

def names
  Tk.execute(:image, :names).to_a
end

.type(name) ⇒ Object

Returns the type of image name (the value of the type argument to image create when the image was created).



69
70
71
# File 'lib/ffi-tk/command/image.rb', line 69

def type(name)
  Tk.execute(:image, :type, name).to_sym
end

.typesObject

Returns a list whose elements are all of the valid image types (i.e., all of the values that may be supplied for the type argument to image create).



76
77
78
# File 'lib/ffi-tk/command/image.rb', line 76

def types
  Tk.execute(:image, :types).to_a(&:to_sym)
end