Module: Tk::Tile::Style

Extended by:
Cget, Configure
Defined in:
lib/ffi-tk/widget/tile/style.rb

Constant Summary collapse

TkkStyleCmd =
'ttk::style'.freeze

Constants included from Cget

Cget::CGET_MAP

Class Method Summary collapse

Methods included from Configure

configure

Methods included from Cget

cget, option_hash_to_tcl, option_to_ruby, type_to_ruby

Class Method Details

.configure(style = nil, options = {}) ⇒ Object

Sets the default value of the specified option(s) in style.



96
97
98
99
100
101
# File 'lib/ffi-tk/widget/tile/style.rb', line 96

def self.configure(style=nil, options={})
  style.kind_of?(Hash) && (keys, style = style, nil)
  style = '.' unless style

  Tk.execute_only('ttk::style','configure', style, options.to_tcl_options)
end

.element_create(name, type, args = nil, options = {}) ⇒ Object

Creates a new element in the current theme of type type. The only built-in element type is image (see ttk_image(n)), although themes may define other element types (see Ttk_RegisterElementFactory).



69
70
71
72
73
74
75
# File 'lib/ffi-tk/widget/tile/style.rb', line 69

def self.element_create(name, type, args=nil, options={})
  if type == 'image' || type == :image
    Tk.execute_only('ttk::style', 'element', 'create', name, 'image', args, options.to_tcl_options)
  else
    #Tk.execute_only('ttk::style', 'element', 'create', name, type)
  end
end

.element_namesObject

Returns the list of elements defined in the current theme.



56
57
58
# File 'lib/ffi-tk/widget/tile/style.rb', line 56

def self.element_names
  Tk.execute('ttk::style', 'element', 'names')
end

.element_options(name) ⇒ Object

Returns the list of element’s options.



61
62
63
64
# File 'lib/ffi-tk/widget/tile/style.rb', line 61

def self.element_options(name)
  return unless element_names.include? name
  Tk.execute('ttk::style', 'element', 'options', name).to_a
end

.layout(name, layout_spec) ⇒ Object

Define the widget layout for style style. See LAYOUTS below for the format of layoutSpec. If layoutSpec is omitted, return the layout specification for style style.



81
82
83
# File 'lib/ffi-tk/widget/tile/style.rb', line 81

def self.layout(name, layout_spec)
  Tk.execute_only('ttk::style', 'layout', name, layout_spec)
end

.lookup(style, option, state = Tk::None, default = Tk::None) ⇒ Object

Returns the value specified for -option in style style in state state, using the standard lookup rules for element options. state is a list of state names; if omitted, it defaults to all bits off (the “normal” state). If the default argument is present, it is used as a fallback value in case no specification for -option is found.



109
110
111
# File 'lib/ffi-tk/widget/tile/style.rb', line 109

def self.lookup(style, option, state=Tk::None, default=Tk::None)
  Tk.execute('ttk::style', 'lookup', style, option.to_tcl_option, state, default).to_s
end

.map(style, options = {}) ⇒ Object

Sets dynamic values of the specified option(s) in style. Each statespec / value pair is examined in order; the value corresponding to the first matching statespec is used.



88
89
90
91
92
93
# File 'lib/ffi-tk/widget/tile/style.rb', line 88

def self.map(style, options={})
  style.kind_of?(Hash) && (options, style = style, nil)
  style = '.' unless style

  Tk.execute_only('ttk::style', 'map', style, options.to_tcl_options )
end

.theme_create(name, options = {}, &block) ⇒ Object

Creates a new theme. It is an error if themeName already exists. If -parent is specified, the new theme will inherit styles, elements, and layouts from the parent theme basedon. If -settings is present, script is evaluated in the context of the new theme as per ttk::style theme settings.

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ffi-tk/widget/tile/style.rb', line 41

def self.theme_create(name, options={}, &block)
  raise ArgumentError if theme_names.include? name
  options = options.to_tcl_options

  if block
    id = Tk.uuid(:proc){|uuid| Tk.callbacks[uuid] = block }
    options << " -settings { RubyFFI::callback #{id} }"
  end
  res = Tk.execute_only('ttk::style', 'theme', 'create', name, options)
  Tk.callbacks.delete(id) if id
  res
end

.theme_namesObject

Returns a list of all known themes.



12
13
14
# File 'lib/ffi-tk/widget/tile/style.rb', line 12

def self.theme_names
  Tk.execute('ttk::style', 'theme', 'names')
end

.theme_settings(name, &block) ⇒ Object

Temporarily sets the current theme to themeName, evaluate script, then restore the previous theme. Typically script simply defines styles and elements, though arbitrary Tcl code may appear.

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ffi-tk/widget/tile/style.rb', line 25

def self.theme_settings(name, &block)
  return unless block
  raise ArgumentError unless theme_names.include? name

  id = Tk.uuid(:proc){|uuid| Tk.callbacks[uuid] = block }
  cmd = "{ RubyFFI::callback #{id} }"
  Tk.eval "ttk::style theme settings #{name} #{cmd}"
  #Tk.execute_only('ttk::style', 'theme', 'settings', name, cmd)
  Tk.callbacks.delete(id) if id
  name
end

.theme_use(name) ⇒ Object

Sets the current theme to themeName, and refreshes all widgets.



17
18
19
20
# File 'lib/ffi-tk/widget/tile/style.rb', line 17

def self.theme_use(name)
  return unless theme_names.include? name
  Tk.execute_only('ttk::style', 'theme', 'use', name) && name
end