New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script Runner Crash Using message_box With Boolean Parameter #326

Closed
Pie56694 opened this Issue Sep 7, 2016 · 1 comment

Comments

Projects
None yet
3 participants
@Pie56694

Pie56694 commented Sep 7, 2016

I want to remove the default "Cancel" button when calling message_box. COSMOS 3.8.0 crashes immediately with:
message_box("Text", "Button Text", false)

@jmthomas

This comment has been minimized.

Show comment
Hide comment
@jmthomas

jmthomas Sep 9, 2016

Member

It crashes because all the items must be Strings which get turned into button text. For now you can put the following code in your lib folder to achieve what you want:

require 'cosmos/script/script'
module Cosmos
  module Script
    private
    def my_message_box(string, *buttons)
      loop do
        result = nil
        _get_main_thread_gui do |window|
          msg = Qt::MessageBox.new(window)
          msg.setText(string)
          msg.setWindowTitle("Message Box")
          buttons.each {|text| msg.addButton(text, Qt::MessageBox::AcceptRole)}
          msg.exec()
          Logger.info "User pressed '#{msg.clickedButton.text}' for '#{string}'"
          result = msg.clickedButton.text
          msg.dispose
        end
        return result
      end
    end
  end # module Script

If the file is called my_script.rb you would use it like so in Script Runner:

load 'my_script.rb'
my_message_box("Text", "Yes", "No", "Maybe")
Member

jmthomas commented Sep 9, 2016

It crashes because all the items must be Strings which get turned into button text. For now you can put the following code in your lib folder to achieve what you want:

require 'cosmos/script/script'
module Cosmos
  module Script
    private
    def my_message_box(string, *buttons)
      loop do
        result = nil
        _get_main_thread_gui do |window|
          msg = Qt::MessageBox.new(window)
          msg.setText(string)
          msg.setWindowTitle("Message Box")
          buttons.each {|text| msg.addButton(text, Qt::MessageBox::AcceptRole)}
          msg.exec()
          Logger.info "User pressed '#{msg.clickedButton.text}' for '#{string}'"
          result = msg.clickedButton.text
          msg.dispose
        end
        return result
      end
    end
  end # module Script

If the file is called my_script.rb you would use it like so in Script Runner:

load 'my_script.rb'
my_message_box("Text", "Yes", "No", "Maybe")

@jmthomas jmthomas closed this Sep 28, 2016

@ryanatball ryanatball added the feature label Dec 6, 2016

@ryanatball ryanatball added this to the v3.8.3 milestone Dec 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment