Module: Tk::Tile::Style
Constant Summary collapse
- TkkStyleCmd =
'ttk::style'.freeze
Constants included from Cget
Class Method Summary collapse
-
.configure(style = nil, options = {}) ⇒ Object
Sets the default value of the specified option(s) in style.
-
.element_create(name, type, args = nil, options = {}) ⇒ Object
Creates a new element in the current theme of type type.
-
.element_names ⇒ Object
Returns the list of elements defined in the current theme.
-
.element_options(name) ⇒ Object
Returns the list of element’s options.
-
.layout(name, layout_spec) ⇒ Object
Define the widget layout for style style.
-
.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.
-
.map(style, options = {}) ⇒ Object
Sets dynamic values of the specified option(s) in style.
-
.theme_create(name, options = {}, &block) ⇒ Object
Creates a new theme.
-
.theme_names ⇒ Object
Returns a list of all known themes.
-
.theme_settings(name, &block) ⇒ Object
Temporarily sets the current theme to themeName, evaluate script, then restore the previous theme.
-
.theme_use(name) ⇒ Object
Sets the current theme to themeName, and refreshes all widgets.
Methods included from 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, ={}) style.kind_of?(Hash) && (keys, style = style, nil) style = '.' unless style Tk.execute_only('ttk::style','configure', style, .) 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, ={}) if type == 'image' || type == :image Tk.execute_only('ttk::style', 'element', 'create', name, 'image', args, .) else #Tk.execute_only('ttk::style', 'element', 'create', name, type) end end |
.element_names ⇒ Object
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.(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, ={}) style.kind_of?(Hash) && (, style = style, nil) style = '.' unless style Tk.execute_only('ttk::style', 'map', style, . ) 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.
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, ={}, &block) raise ArgumentError if theme_names.include? name = . if block id = Tk.uuid(:proc){|uuid| Tk.callbacks[uuid] = block } << " -settings { RubyFFI::callback #{id} }" end res = Tk.execute_only('ttk::style', 'theme', 'create', name, ) Tk.callbacks.delete(id) if id res end |
.theme_names ⇒ Object
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.
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 |