Module: TkFont::Chooser

Extended by:
TkCore
Defined in:
lib/tk/fontchooser.rb

Constant Summary

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

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

.[](slot) ⇒ Object



122
123
124
# File 'lib/tk/fontchooser.rb', line 122

def [](slot)
  cget slot
end

.[]=(slot, val) ⇒ Object



126
127
128
129
# File 'lib/tk/fontchooser.rb', line 126

def []=(slot, val)
  configure slot, val
  val
end

.__configinfo_value(key, val) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/tk/fontchooser.rb', line 39

def __configinfo_value(key, val)
  case key
  when 'parent'
    window(val)
  when 'title'
    val
  when 'font'
    if (lst = tk_split_simplelist(val)).size == 1
      lst[0]
    else
      lst.map{|elem| num_or_str(elem)}
    end
  when 'command'
    tk_tcl2ruby(val)
  when 'visible'
    bool(val)
  else # unknown
    val
  end
end

.cget(slot) ⇒ Object



118
119
120
# File 'lib/tk/fontchooser.rb', line 118

def cget(slot)
  configinfo slot
end

.command(cmd = nil, &b) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/tk/fontchooser.rb', line 108

def command(cmd=nil, &b)
  if cmd
    configure_cmd('command', cmd)
  elsif b
    configure_cmd('command', Proc.new(&b))
  else
    cget('command')
  end
end

.configinfo(option = nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/tk/fontchooser.rb', line 61

def configinfo(option=nil)
  if !option && TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
    lst = tk_split_simplelist(tk_call('tk', 'fontchooser', 'configure'))
    ret = []
    TkComm.slice_ary(lst, 2){|k, v|
      k = k[1..-1]
      ret << [k, __configinfo_value(k, v)]
    }
    ret
  else
    current_configinfo(option)
  end
end

.configure(option, value = None) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/tk/fontchooser.rb', line 92

def configure(option, value=None)
  if option.kind_of? Hash
    tk_call('tk', 'fontchooser', 'configure',
            *hash_kv(_symbolkey2str(option)))
  else
    opt = option.to_s
    fail ArgumentError, "Invalid option `#{option.inspect}'" if opt.empty?
    tk_call('tk', 'fontchooser', 'configure', "-#{opt}", value)
  end
  self
end

.configure_cmd(slot, value) ⇒ Object



104
105
106
# File 'lib/tk/fontchooser.rb', line 104

def configure_cmd(slot, value)
  configure(slot, install_cmd(value))
end

.current_configinfo(option = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/tk/fontchooser.rb', line 75

def current_configinfo(option=nil)
  if option
    opt = option.to_s
    fail ArgumentError, "Invalid option `#{option.inspect}'" if opt.empty?
    __configinfo_value(option.to_s, tk_call('tk','fontchooser',
                                            'configure',"-#{opt}"))
  else
    lst = tk_split_simplelist(tk_call('tk', 'fontchooser', 'configure'))
    ret = {}
    TkComm.slice_ary(lst, 2){|k, v|
      k = k[1..-1]
      ret[k] = __configinfo_value(k, v)
    }
    ret
  end
end

.hideObject



136
137
138
139
# File 'lib/tk/fontchooser.rb', line 136

def hide
  tk_call('tk', 'fontchooser', 'hide')
  self
end

.method_missing(id, *args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tk/fontchooser.rb', line 17

def method_missing(id, *args)
  name = id.id2name
  case args.length
  when 1
    if name[-1] == ?=
      configure name[0..-2], args[0]
      args[0]
    else
      configure name, args[0]
      self
    end
  when 0
    begin
      cget(name)
    rescue
      super(id, *args)
    end
  else
    super(id, *args)
  end
end

.set_for(target, title = "Font") ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/tk/fontchooser.rb', line 146

def set_for(target, title="Font")
  if target.kind_of? TkFont
    configs = {
      :font=>target.actual_hash,
      :command=>proc{|fnt, *args|
        target.configure(TkFont.actual_hash(fnt))
      }
    }
  elsif target.kind_of? Hash
    # key=>value list or OptionObj
    fnt = target[:font] rescue ''
    fnt = fnt.actual_hash if fnt.kind_of?(TkFont)
    configs = {
      :font => fnt,
      :command=>proc{|fnt, *args|
        target[:font] = TkFont.actual_hash(fnt)
      }
    }
  else
    configs = {
      :font=>target.cget_tkstring(:font),
      :command=>proc{|fnt, *args|
        target.font = TkFont.actual_hash_displayof(fnt, target)
      }
    }
  end

  configs[:title] = title if title
  configure(configs)
  target
end

.showObject



131
132
133
134
# File 'lib/tk/fontchooser.rb', line 131

def show
  tk_call('tk', 'fontchooser', 'show')
  self
end

.toggleObject



141
142
143
144
# File 'lib/tk/fontchooser.rb', line 141

def toggle
  cget(:visible) ?  hide: show
  self
end

.unsetObject



178
179
180
# File 'lib/tk/fontchooser.rb', line 178

def unset
  configure(:command, nil)
end