Class: Glimmer::DSL::Tk::BuiltInDialogExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/glimmer/dsl/tk/built_in_dialog_expression.rb

Instance Method Summary collapse

Instance Method Details

#can_interpret?(parent, keyword, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
# File 'lib/glimmer/dsl/tk/built_in_dialog_expression.rb', line 29

def can_interpret?(parent, keyword, *args, &block)
  keyword = "get_#{keyword}" if keyword.start_with?('open')
  (keyword.start_with?('get') or keyword.start_with?('choose')) and
  (
    (block.nil? and ::Tk.respond_to?(keyword.camelcase)) or
    keyword == 'choose_font'
  )
end

#interpret(parent, keyword, *args, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/glimmer/dsl/tk/built_in_dialog_expression.rb', line 38

def interpret(parent, keyword, *args, &block)
  if args.first.is_a?(Hash)
    options = args.first.symbolize_keys
    options[:initialcolor] = options.delete(:initial_color) if options.keys.include?(:initial_color)
    options[:filetypes] = options.delete(:file_types) if options.keys.include?(:file_types)
    options[:filetypes] = options[:filetypes].map { |key, value| "{#{key}} {#{value}}" } if options[:filetypes].is_a?(Hash)
    options[:parent] = options[:parent].tk if options[:parent].is_a?(Glimmer::Tk::RootProxy)
    args[0] = options
  end
  keyword = "get_#{keyword}" if keyword.start_with?('open') || keyword.start_with?('save') || keyword.start_with?('multiple')
  if keyword == 'choose_font'
    TkFont::Fontchooser.configure(:font => args, :command => block)
    TkFont::Fontchooser.show
  else
    ::Tk.send(keyword.camelcase, *args)
  end
end