Module: Tk::Tile::Style

Extended by:
ParseStyleLayout, TkCore
Defined in:
lib/tkextlib/tile/style.rb,
lib/tkextlib/tile/style.rb

Constant Summary collapse

TkCommandNames =
['::ttk::style'.freeze].freeze

Constants included from TkCore

TkCore::EventFlag, TkCore::INTERP, TkCore::INTERP_MUTEX, TkCore::INTERP_ROOT_CHECK, TkCore::INTERP_THREAD, TkCore::INTERP_THREAD_STATUS, TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD, TkCore::WIDGET_DESTROY_HOOK, TkCore::WITH_ENCODING, TkCore::WITH_RUBY_VM

Constants included from TkComm

TkComm::GET_CONFIGINFO_AS_ARRAY, TkComm::GET_CONFIGINFOwoRES_AS_ARRAY, TkComm::TkExtlibAutoloadModule, TkComm::Tk_CMDTBL, TkComm::Tk_IDs, TkComm::Tk_WINDOWS, TkComm::USE_TCLs_LIST_FUNCTIONS, TkComm::WidgetClassNames

Constants included from TkUtil

TkUtil::None, TkUtil::RELEASE_DATE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TkCore

_tk_call_to_list_core, after, after_cancel, after_idle, appname, appsend, appsend_deny, appsend_displayof, callback, callback_break, callback_continue, callback_return, chooseColor, chooseDirectory, do_one_event, event_generate, getMultipleOpenFile, getMultipleSaveFile, getOpenFile, getSaveFile, get_eventloop_tick, get_eventloop_weight, get_no_event_wait, inactive, inactive_displayof, info, ip_eval, ip_eval_with_enc, ip_eval_without_enc, ip_invoke, ip_invoke_with_enc, ip_invoke_without_enc, is_mainloop?, load_cmd_on_ip, mainloop, mainloop_exist?, mainloop_thread?, mainloop_watchdog, messageBox, rb_appsend, rb_appsend_displayof, reset_inactive, reset_inactive_displayof, restart, scaling, scaling_displayof, set_eventloop_tick, set_eventloop_weight, set_no_event_wait, tk_call, tk_call_to_list, tk_call_to_list_with_enc, tk_call_to_list_without_enc, tk_call_to_simplelist, tk_call_to_simplelist_with_enc, tk_call_to_simplelist_without_enc, tk_call_with_enc, tk_call_without_enc, windowingsystem

Methods included from TkComm

_at, _callback_entry?, _callback_entry_class?, _curr_cmd_id, _fromUTF8, _genobj_for_tkwidget, _next_cmd_id, _toUTF8, array2tk_list, #bind, #bind_all, #bind_append, #bind_append_all, #bind_remove, #bind_remove_all, #bindinfo, #bindinfo_all, bool, image_obj, #install_cmd, install_cmd, list, num_or_nil, num_or_str, number, procedure, simplelist, slice_ary, string, #subst, tk_tcl2ruby, uninstall_cmd, #uninstall_cmd, window

Methods included from TkEvent

#install_bind, #install_bind_for_event_class

Methods included from TkUtil

_conv_args, #_conv_args, #_fromUTF8, #_get_eval_enc_str, _get_eval_enc_str, #_get_eval_string, _get_eval_string, #_symbolkey2str, _symbolkey2str, #_toUTF8, #bool, bool, callback, eval_cmd, hash_kv, #hash_kv, install_cmd, num_or_nil, #num_or_nil, #num_or_str, num_or_str, #number, number, string, #string, uninstall_cmd, untrust

Class Method Details

.configure(style = nil, keys = nil) ⇒ Object Also known as: default


159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/tkextlib/tile/style.rb', line 159

def configure(style=nil, keys=nil)
  if style.kind_of?(Hash)
    keys = style
    style = nil
  end
  style = '.' unless style

  if Tk::Tile::TILE_SPEC_VERSION_ID < 7
    sub_cmd = 'default'
  else
    sub_cmd = 'configure'
  end

  if keys && keys != None
    tk_call(TkCommandNames[0], sub_cmd, style, *hash_kv(keys))
  else
    tk_call(TkCommandNames[0], sub_cmd, style)
  end
end

.element_create(name, type, *args) ⇒ Object


233
234
235
236
237
238
239
240
241
# File 'lib/tkextlib/tile/style.rb', line 233

def element_create(name, type, *args)
  if type == 'image' || type == :image
    element_create_image(name, *args)
  elsif type == 'vsapi' || type == :vsapi
    element_create_vsapi(name, *args)
  else
    tk_call(TkCommandNames[0], 'element', 'create', name, type, *args)
  end
end

.element_create_image(name, *args) ⇒ Object


243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/tkextlib/tile/style.rb', line 243

def element_create_image(name, *args)
  fail ArgumentError, 'Must supply a base image' unless (spec = args.shift)
  if (opts = args.shift)
    if opts.kind_of?(Hash)
      opts = _symbolkey2str(opts)
    else
      fail ArgumentError, 'bad option'
    end
  end
  fail ArgumentError, 'too many arguments' unless args.empty?

  if spec.kind_of?(Array)
    # probably, command format is tile 0.8+ (Tcl/Tk8.5+) style
    if Tk::Tile::TILE_SPEC_VERSION_ID >= 8
      if opts
        tk_call(TkCommandNames[0],
                'element', 'create', name, 'image', spec, opts)
      else
        tk_call(TkCommandNames[0], 'element', 'create', name, 'image', spec)
      end
    else
      fail ArgumentError, 'illegal arguments' if opts.key?('map')
      base = spec.shift
      opts['map'] = spec
      tk_call(TkCommandNames[0],
              'element', 'create', name, 'image', base, opts)
    end
  else
    # probably, command format is tile 0.7.8 or older style
    if Tk::Tile::TILE_SPEC_VERSION_ID >= 8
      spec = [spec, *(opts.delete('map'))] if opts.key?('map')
    end
    if opts
      tk_call(TkCommandNames[0],
              'element', 'create', name, 'image', spec, opts)
    else
      tk_call(TkCommandNames[0], 'element', 'create', name, 'image', spec)
    end
  end
end

.element_create_vsapi(name, class_name, part_id, *args) ⇒ Object


284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/tkextlib/tile/style.rb', line 284

def element_create_vsapi(name, class_name, part_id, *args)
  # supported on Tcl/Tk 8.6 or later

  # argument check
  if (state_map = args.shift || None)
    if state_map.kind_of?(Hash)
      opts = _symbolkey2str(state_map)
      state_map = None
    end
  end
  opts = args.shift || None
  fail ArgumentError, "too many arguments" unless args.empty?

  # define a Microsoft Visual Styles element
  tk_call(TkCommandNames[0], 'element', 'create', name, 'vsapi',
          class_name, part_id, state_map, opts)
end

.element_namesObject


302
303
304
# File 'lib/tkextlib/tile/style.rb', line 302

def element_names()
  list(tk_call(TkCommandNames[0], 'element', 'names'))
end

.element_options(elem) ⇒ Object


306
307
308
# File 'lib/tkextlib/tile/style.rb', line 306

def element_options(elem)
  simplelist(tk_call(TkCommandNames[0], 'element', 'options', elem))
end

.layout(style = nil, spec = nil) ⇒ Object


219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/tkextlib/tile/style.rb', line 219

def layout(style=nil, spec=nil)
  if style.kind_of?(Hash)
    spec = style
    style = nil
  end
  style = '.' unless style

  if spec
    tk_call(TkCommandNames[0], 'layout', style, spec)
  else
    _style_layout(list(tk_call(TkCommandNames[0], 'layout', style)))
  end
end

.lookup(style, opt, state = None, fallback_value = None) ⇒ Object


212
213
214
215
# File 'lib/tkextlib/tile/style.rb', line 212

def lookup(style, opt, state=None, fallback_value=None)
  tk_call(TkCommandNames[0], 'lookup', style,
          '-' << opt.to_s, state, fallback_value)
end

.map(style = nil, keys = nil) ⇒ Object Also known as: map_configure


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/tkextlib/tile/style.rb', line 180

def map(style=nil, keys=nil)
  if style.kind_of?(Hash)
    keys = style
    style = nil
  end
  style = '.' unless style

  if keys && keys != None
    if keys.kind_of?(Hash)
      tk_call(TkCommandNames[0], 'map', style, *hash_kv(keys))
    else
      simplelist(tk_call(TkCommandNames[0], 'map', style, '-' << keys.to_s))
    end
  else
    ret = {}
    Hash[*(simplelist(tk_call(TkCommandNames[0], 'map', style)))].each{|k, v|
      ret[k[1..-1]] = list(v)
    }
    ret
  end
end

.map_configinfo(style = nil, key = None) ⇒ Object


203
204
205
206
# File 'lib/tkextlib/tile/style.rb', line 203

def map_configinfo(style=nil, key=None)
  style = '.' unless style
  map(style, key)
end

.map_default_configinfo(key = None) ⇒ Object


208
209
210
# File 'lib/tkextlib/tile/style.rb', line 208

def map_default_configinfo(key=None)
  map('.', key)
end

.theme_create(name, keys = nil) ⇒ Object


310
311
312
313
314
315
316
317
318
# File 'lib/tkextlib/tile/style.rb', line 310

def theme_create(name, keys=nil)
  name = name.to_s
  if keys && keys != None
    tk_call(TkCommandNames[0], 'theme', 'create', name, *hash_kv(keys))
  else
    tk_call(TkCommandNames[0], 'theme', 'create', name)
  end
  name
end

.theme_namesObject


327
328
329
# File 'lib/tkextlib/tile/style.rb', line 327

def theme_names()
  list(tk_call(TkCommandNames[0], 'theme', 'names'))
end

.theme_settings(name, cmd = nil, &b) ⇒ Object


320
321
322
323
324
325
# File 'lib/tkextlib/tile/style.rb', line 320

def theme_settings(name, cmd=nil, &b)
  name = name.to_s
  cmd = Proc.new(&b) if !cmd && b
  tk_call(TkCommandNames[0], 'theme', 'settings', name, cmd)
  name
end

.theme_use(name) ⇒ Object


331
332
333
334
335
# File 'lib/tkextlib/tile/style.rb', line 331

def theme_use(name)
  name = name.to_s
  tk_call(TkCommandNames[0], 'theme', 'use', name)
  name
end

Instance Method Details

#__define_wrapper_proc_for_compatibility__!Object


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tkextlib/tile/style.rb', line 35

def __define_wrapper_proc_for_compatibility__!
  __define_themes_and_setTheme_proc__!

  unless Tk.info(:commands, '::ttk::style').empty?
    # fail RuntimeError,
    #      "can't define '::ttk::style' command (already exist)"

    # do nothing !!!
    warn "Warning: can't define '::ttk::style' command (already exist)" if $DEBUG
    return
  end
  TkCore::INTERP.add_tk_procs('::ttk::style', 'args', <<-'EOS')
  if [string equal [lrange $args 0 1] {element create}] {
    if [string equal [lindex $args 3] image] {
      set spec [lindex $args 4]
      set map  [lrange $spec 1 end]
      if [llength $map] {
        # return [eval [concat [list ::style element create [lindex $args 2] image [lindex $spec 0] -map $map] [lrange $args 5 end]]]
        return [uplevel 1 [list ::style element create [lindex $args 2] image [lindex $spec 0] -map $map] [lrange $args 5 end]]
      }
    }
  }
  # return [eval "::style $args"]
  return [uplevel 1 ::style $args]
EOS
  #########################
end