Skip to content

Commit

Permalink
Merge pull request #134 from BallAerospace/add_sound
Browse files Browse the repository at this point in the history
Add sound option to System and enable sound in alerts #133
  • Loading branch information
jmthomas committed May 19, 2015
2 parents 7be96b6 + 7ff3003 commit 20354b7
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 31 deletions.
Binary file added data/critical.wav
Binary file not shown.
Binary file added data/information.wav
Binary file not shown.
Binary file added data/input.wav
Binary file not shown.
Binary file added data/message.wav
Binary file not shown.
Binary file added data/question.wav
Binary file not shown.
Binary file added data/warning.wav
Binary file not shown.
1 change: 1 addition & 0 deletions demo/config/system/system.txt
Expand Up @@ -29,6 +29,7 @@ PATH PROCEDURES ./procedures

ALLOW_ACCESS ALL

ENABLE_SOUND
# DISABLE_DNS
# STALENESS_SECONDS 30
# CMD_TLM_VERSION version
1 change: 1 addition & 0 deletions lib/cosmos/gui/dialogs/about_dialog.rb
Expand Up @@ -13,6 +13,7 @@ module Cosmos
class AboutDialog < Qt::Dialog
ABOUT_COSMOS = ''
ABOUT_COSMOS << "COSMOS application icons are courtesy of http://icons8.com.\n"
ABOUT_COSMOS << "COSMOS application sounds are courtesy of http://www.freesfx.co.uk.\n"
ABOUT_COSMOS << "\n"
ABOUT_COSMOS << "COSMOS utilizes the QtRuby (http://rubyforge.org/projects/korundum) library under "
ABOUT_COSMOS << "the GNU Lesser General Public License. QtRuby is a Ruby extension module that provides an "
Expand Down
33 changes: 12 additions & 21 deletions lib/cosmos/gui/qt.rb
Expand Up @@ -235,27 +235,8 @@ def self.load_cosmos_icon(name='COSMOS_64x64.png')

# Load the applications icon
def self.get_icon(name, fail_blank = true)
icon = nil
filename = File.join(::Cosmos::USERPATH, 'config', 'data', name)
begin
raise unless File.exist? filename
icon = Qt::Icon.new(filename)
raise if icon.isNull
rescue
begin
filename = File.join(::Cosmos::PATH, 'data', name)
raise unless File.exist? filename
icon = Qt::Icon.new(filename)
raise if icon.isNull
rescue
# Return a blank icon if we couldn't find an icon in either the user path or cosmos path
if fail_blank
icon = Qt::Icon.new
else
icon = nil
end
end
end
icon = Qt::Icon.new(Cosmos.data_path(name))
icon = nil if icon.isNull && !fail_blank
return icon
end
end
Expand Down Expand Up @@ -286,6 +267,16 @@ def exec
end
#### END TEMPORARY UNTIL INCLUDED IN QTBINDINGS ####

class Qt::Icon
def initialize(param = nil)
if param
super(param)
else
super()
end
end
end

class Qt::Dialog
def initialize(parent = Qt::Application.activeWindow,
flags = (Qt::WindowTitleHint | Qt::WindowSystemMenuHint))
Expand Down
43 changes: 43 additions & 0 deletions lib/cosmos/gui/utilities/script_module_gui.rb
Expand Up @@ -12,6 +12,49 @@

$cmd_tlm_gui_window = nil

class Qt::MessageBox
def exec(*args)
Cosmos.play_wav_file(Cosmos.data_path('message.wav')) if Cosmos::System.sound
method_missing(:exec, *args)
end
def self.critical(parent, title, text,
buttons = Qt::MessageBox::Ok,
defaultButton = Qt::MessageBox::NoButton)
# Windows overrides critical dialogs with its own alert sound
Cosmos.play_wav_file(Cosmos.data_path('critical.wav')) if Cosmos::System.sound
super(parent,title,text,buttons,defaultButton)
end
def self.information(parent, title, text,
buttons = Qt::MessageBox::Ok,
defaultButton = Qt::MessageBox::NoButton)
Cosmos.play_wav_file(Cosmos.data_path('information.wav')) if Cosmos::System.sound
super(parent,title,text,buttons,defaultButton)
end
def self.question(parent, title, text,
buttons = Qt::MessageBox::Ok,
defaultButton = Qt::MessageBox::NoButton)
Cosmos.play_wav_file(Cosmos.data_path('question.wav')) if Cosmos::System.sound
super(parent,title,text,buttons,defaultButton)
end
def self.warning(parent, title, text,
buttons = Qt::MessageBox::Ok,
defaultButton = Qt::MessageBox::NoButton)
# Windows overrides warning dialogs with its own alert sound
Cosmos.play_wav_file(Cosmos.data_path('warning.wav')) if Cosmos::System.sound
super(parent,title,text,buttons,defaultButton)
end
end

class Qt::InputDialog
def self.getText(parent, title, label,
mode = Qt::LineEdit::Normal,
text = '', ok = 0, flags = 0,
inputMethodHints = Qt::ImhNone)
Cosmos.play_wav_file(Cosmos.data_path('input.wav')) if Cosmos::System.sound
super(parent, title, label, mode, text, ok, flags, inputMethodHints)
end
end

module Cosmos

# Cosmos script changes to handle hazardous commands and prompts
Expand Down
2 changes: 1 addition & 1 deletion lib/cosmos/processors/new_packet_log_processor.rb
Expand Up @@ -24,7 +24,7 @@ def initialize(packet_log_writer_name = 'ALL')
#
# See Processor#call
def call(packet, buffer)
if CmdTlmServer.instance
if CmdTlmServer.instance and $0 !~ /Replay/
CmdTlmServer.instance.start_logging(@packet_log_writer_name)
end
end
Expand Down
10 changes: 1 addition & 9 deletions lib/cosmos/script/scripting.rb
Expand Up @@ -19,15 +19,7 @@ module Script
include Extract

def play_wav_file(wav_filename)
if defined? Qt
Qt.execute_in_main_thread(true) do
if Qt::CoreApplication.instance and Qt::Sound.isAvailable
Cosmos.set_working_dir do
Qt::Sound.play(wav_filename.to_s)
end
end
end
end
Cosmos.play_wav_file(wav_filename)
end

def status_bar(message)
Expand Down
8 changes: 8 additions & 0 deletions lib/cosmos/system/system.rb
Expand Up @@ -39,6 +39,8 @@ class System
instance_attr_reader :default_packet_log_writer
# @return [PacketLogReader] Class used to read log files
instance_attr_reader :default_packet_log_reader
# @return [Boolean] Whether to use sound for alerts
instance_attr_reader :sound
# @return [Boolean] Whether to use DNS to lookup IP addresses or not
instance_attr_reader :use_dns
# @return [String] Stores the initial configuration file used when this
Expand Down Expand Up @@ -81,6 +83,7 @@ def initialize(filename = nil)
@cmd_tlm_version = nil
@default_packet_log_writer = PacketLogWriter
@default_packet_log_reader = PacketLogReader
@sound = false
@use_dns = true
@acl = nil
@staleness_seconds = 30
Expand Down Expand Up @@ -267,6 +270,11 @@ def process_file(filename, configuration_directory = nil)
parser.verify_num_parameters(1, 1, usage)
@default_packet_log_reader = Cosmos.require_class(parameters[0])

when 'ENABLE_SOUND'
usage = "#{keyword}"
parser.verify_num_parameters(0, 0, usage)
@sound = true

when 'DISABLE_DNS'
usage = "#{keyword}"
parser.verify_num_parameters(0, 0, usage)
Expand Down
28 changes: 28 additions & 0 deletions lib/cosmos/top_level.rb
Expand Up @@ -136,6 +136,20 @@ def self.add_to_search_path(path, front = true)
end
end

# Searches the COSMOS::USERPATH/config/data directory and then the core
# COSMOS/data directory for the given file name. Returns the absolute file
# path or nil if the file could not be found. This allows for user configuration
# files to override COSMOS data file defaults.
def self.data_path(name)
filename = File.join(::Cosmos::USERPATH, 'config', 'data', name)
return filename if File.exist? filename

filename = File.join(::Cosmos::PATH, 'data', name)
return filename if File.exist? filename

nil
end

# Creates a marshal file by serializing the given obj
#
# @param marshal_filename [String] Name of the marshal file to create
Expand Down Expand Up @@ -673,4 +687,18 @@ def self.close_socket(socket)
end
end

# Play a wav file
# @param wav_filename filename of the wav file
def self.play_wav_file(wav_filename)
if defined? Qt and wav_filename
Qt.execute_in_main_thread(true) do
if Qt::CoreApplication.instance and Qt::Sound.isAvailable
Cosmos.set_working_dir do
Qt::Sound.play(wav_filename.to_s)
end
end
end
end
end

end

0 comments on commit 20354b7

Please sign in to comment.