Module: TkItemConfigMethod

Constant Summary

Constants included from TkUtil

TkUtil::None, TkUtil::RELEASE_DATE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TkItemConfigOptkeys

#__conv_item_keyonly_opts, #itemconfig_hash_kv

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

Methods included from TkTreatItemFont

#kanjifont_copy, #kanjitagfont_configure, #latintagfont_configure, #latintagfont_copy, #tagfont_configinfo, #tagfont_configure, #tagfont_copy

Class Method Details

.__IGNORE_UNKNOWN_CONFIGURE_OPTION__Object



124
125
126
# File 'lib/tk/itemconfig.rb', line 124

def TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
  @mode || false
end

.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) ⇒ Object



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

def TkItemConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode)
  @mode = (mode)? true: false
end

Instance Method Details

#__check_available_itemconfigure_options(tagOrId, keys) ⇒ Object



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/tk/itemconfig.rb', line 357

def __check_available_itemconfigure_options(tagOrId, keys)
  id = tagid(tagOrId)

  availables = self.__current_itemconfiginfo(id).keys

  # add non-standard keys
  availables |= __font_optkeys.map{|k|
    [k.to_s, "latin#{k}", "ascii#{k}", "kanji#{k}"]
  }.flatten
  availables |= __item_methodcall_optkeys(id).keys.map{|k| k.to_s}
  availables |= __item_keyonly_optkeys(id).keys.map{|k| k.to_s}

  keys = _symbolkey2str(keys)

  keys.delete_if{|k, v| !(availables.include?(k))}
end

#__current_itemconfiginfo(tagOrId, slot = nil) ⇒ Object



1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
# File 'lib/tk/itemconfig.rb', line 1185

def __current_itemconfiginfo(tagOrId, slot = nil)
  if TkComm::GET_CONFIGINFO_AS_ARRAY
    if slot
      org_slot = slot
      begin
        conf = __itemconfiginfo_core(tagOrId, slot)
        if ( ! __item_configinfo_struct(tagid(tagOrId))[:alias] \
            || conf.size > __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
          return {conf[0] => conf[-1]}
        end
        slot = conf[__item_configinfo_struct(tagid(tagOrId))[:alias]]
      end while(org_slot != slot)
      fail RuntimeError,
        "there is a configure alias loop about '#{org_slot}'"
    else
      ret = {}
      __itemconfiginfo_core(tagOrId).each{|conf|
        if ( ! __item_configinfo_struct(tagid(tagOrId))[:alias] \
            || conf.size > __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
          ret[conf[0]] = conf[-1]
        end
      }

      ret
    end
  else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
    ret = {}
    __itemconfiginfo_core(tagOrId, slot).each{|key, conf|
      ret[key] = conf[-1] if conf.kind_of?(Array)
    }
    ret
  end
end

#current_itemconfiginfo(tagOrId, slot = nil) ⇒ Object



1219
1220
1221
# File 'lib/tk/itemconfig.rb', line 1219

def current_itemconfiginfo(tagOrId, slot = nil)
  __current_itemconfiginfo(tagOrId, slot)
end

#itemcget(tagOrId, option) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/tk/itemconfig.rb', line 254

def itemcget(tagOrId, option)
  unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
    __itemcget_core(tagOrId, option)
  else
    begin
      __itemcget_core(tagOrId, option)
    rescue => e
      begin
        if __current_itemconfiginfo(tagOrId).has_key?(option.to_s)
          # not tag error & option is known -> error on known option
          fail e
        else
          # not tag error & option is unknown
          nil
        end
      rescue
        fail e  # tag error
      end
    end
  end
end

#itemcget_strict(tagOrId, option) ⇒ Object



275
276
277
278
# File 'lib/tk/itemconfig.rb', line 275

def itemcget_strict(tagOrId, option)
  # never use TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
  __itemcget_core(tagOrId, option)
end

#itemcget_tkstring(tagOrId, option) ⇒ Object



166
167
168
169
170
# File 'lib/tk/itemconfig.rb', line 166

def itemcget_tkstring(tagOrId, option)
  opt = option.to_s
  fail ArgumentError, "Invalid option `#{option.inspect}'" if opt.length == 0
  tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{opt}"))
end

#itemconfiginfo(tagOrId, slot = nil) ⇒ Object



1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
# File 'lib/tk/itemconfig.rb', line 1167

def itemconfiginfo(tagOrId, slot = nil)
  if slot && TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
    begin
      __itemconfiginfo_core(tagOrId, slot)
    rescue => e
      begin
        __itemconfiginfo_core(tagOrId)
        # not tag error -> option is unknown
        Array.new(__item_configinfo_struct.values.max).unshift(slot.to_s)
      rescue
        fail e  # tag error
      end
    end
  else
    __itemconfiginfo_core(tagOrId, slot)
  end
end

#itemconfigure(tagOrId, slot, value = None) ⇒ Object



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/tk/itemconfig.rb', line 374

def itemconfigure(tagOrId, slot, value=None)
  unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
    __itemconfigure_core(tagOrId, slot, value)
  else
    if slot.kind_of?(Hash)
      begin
        __itemconfigure_core(tagOrId, slot)
      rescue
        slot = __check_available_itemconfigure_options(tagOrId, slot)
        __itemconfigure_core(tagOrId, slot) unless slot.empty?
      end
    else
      begin
        __itemconfigure_core(tagOrId, slot, value)
      rescue => e
        begin
          if __current_itemconfiginfo(tagOrId).has_key?(slot.to_s)
            # not tag error & option is known -> error on known option
            fail e
          else
            # not tag error & option is unknown
            nil
          end
        rescue
          fail e  # tag error
        end
      end
    end
  end
  self
end

#tagid(tagOrId) ⇒ Object



158
159
160
161
# File 'lib/tk/itemconfig.rb', line 158

def tagid(tagOrId)
  # maybe need to override
  tagOrId
end