Sha256: 88c9e259d7633120ff55a0759bb43729feae9bcd4f1c5ac91ffe0aa96ae69ff4

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

module Clevic

module ActionBuilder
  # Create a new separator and add a new separator.
  def separator
    Qt::Action.new( parent ) do |action|
      action.separator = true
      add_action action
      collect_actions << action
    end
  end
    
  def create_action( &block )
    Qt::Action.new( parent, &block )
  end
  
  # TODO move this into Action, like the swing adapter
  def create_key_sequence( sequence )
    Qt::KeySequence.new( sequence )
  end

  # set up the code to be executed when an action is triggered,
  def action_method_or_block( qt_action, options, &block )
    signal_name = "triggered(#{options.has_key?( :checkable ) ? 'bool' : ''})"
    
    # connect the action to some code
    if options.has_key?( :method )
      qt_action.connect SIGNAL( signal_name ) do |active|
        action_triggered do
          send_args = [ options[:method], options.has_key?( :checkable ) ? active : nil ].compact
          send( *send_args )
        end
      end
    else
      unless block.nil?
        action_triggered do
          qt_action.connect SIGNAL( signal_name ) do |active|
            # need this rescue here because otherwise Qt
            # doesn't catch it and the whole app comes down
            begin
              yield( active )
            rescue
              # TODO how to display this in the UI?
              puts $!.message
              puts $!.backtrace
            end
          end
        end
      end
    end
  end

end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
clevic-0.13.0.b9 lib/clevic/qt/action_builder.rb
clevic-0.13.0.b6 lib/clevic/qt/action_builder.rb
clevic-0.13.0.b5 lib/clevic/qt/action_builder.rb