diff --git a/lib/cosmos/gui/choosers/telemetry_chooser.rb b/lib/cosmos/gui/choosers/telemetry_chooser.rb index 7289e09d6..d1f372c16 100644 --- a/lib/cosmos/gui/choosers/telemetry_chooser.rb +++ b/lib/cosmos/gui/choosers/telemetry_chooser.rb @@ -134,7 +134,6 @@ def initialize( @item_changed_callback = nil @select_button_callback = nil @support_latest = support_latest - update() end # Update items diff --git a/lib/cosmos/gui/dialogs/progress_dialog.rb b/lib/cosmos/gui/dialogs/progress_dialog.rb index 2b7212725..c931f9f6b 100644 --- a/lib/cosmos/gui/dialogs/progress_dialog.rb +++ b/lib/cosmos/gui/dialogs/progress_dialog.rb @@ -125,6 +125,8 @@ def initialize(parent, title, width = 500, height = 300, show_overall = true, sh @thread = nil @cancel_callback = nil + @overall_progress = 0 + @step_progress = 0 end def self.canceled? @@ -199,17 +201,21 @@ def complete end def set_step_progress (value) - unless @complete + progress_int = (value * 100).to_i + if !@complete and @step_progress != progress_int + @step_progress = progress_int Qt.execute_in_main_thread(false) do - @step_bar.setValue(value * 100.0) if @step_bar + @step_bar.setValue(progress_int) if @step_bar end end end def set_overall_progress (value) - unless @complete + progress_int = (value * 100).to_i + if !@complete and @overall_progress != progress_int + @overall_progress = progress_int Qt.execute_in_main_thread(false) do - @overall_bar.setValue(value * 100.0) if @overall_bar + @overall_bar.setValue(progress_int) if @overall_bar end end end diff --git a/lib/cosmos/gui/dialogs/splash.rb b/lib/cosmos/gui/dialogs/splash.rb index 7b2d5c6d7..92cf5b740 100644 --- a/lib/cosmos/gui/dialogs/splash.rb +++ b/lib/cosmos/gui/dialogs/splash.rb @@ -37,19 +37,27 @@ def initialize(parent) layout.addWidget(@message_box) @progress_bar = Qt::ProgressBar.new layout.addWidget(@progress_bar) - setLayout(layout) + + @progress = 0 + @complete = false end def message=(message) - Qt.execute_in_main_thread(true) do - @message_box.setText(message) + unless @complete + Qt.execute_in_main_thread(false) do + @message_box.setText(message) + end end end def progress=(progress) - Qt.execute_in_main_thread(true) do - @progress_bar.setValue(progress * 100) + progress_int = (progress * 100).to_i + if !@complete and @progress != progress_int + @progress = progress_int + Qt.execute_in_main_thread(false) do + @progress_bar.setValue(progress_int) + end end end @@ -82,7 +90,6 @@ def self.execute(parent, wait_for_complete = false, &block) # Qt.execute_in_main_thread(true) do # < Update the GUI > # end - complete = false Thread.new do error = nil begin @@ -91,6 +98,8 @@ def self.execute(parent, wait_for_complete = false, &block) error = e end + @complete = true + # If the block threw an error show it before allowing the application to crash if error Qt.execute_in_main_thread(true) do @@ -101,12 +110,25 @@ def self.execute(parent, wait_for_complete = false, &block) Qt.execute_in_main_thread(true) do # Once the block has completed we hide and dispose the dialog to allow the main application to take over dialog.hide - dialog.dispose unless wait_for_complete + + unless wait_for_complete + # Need to make sure all Qt.execute_in_main_thread() have completed before disposing or + # we will segfault + Qt::RubyThreadFix.queue.pop.call until Qt::RubyThreadFix.queue.empty? + + dialog.dispose + end end - complete = true end - dialog.exec if wait_for_complete - dialog.dispose if wait_for_complete + if wait_for_complete + dialog.exec + + # Need to make sure all Qt.execute_in_main_thread() have completed before disposing or + # we will segfault + Qt::RubyThreadFix.queue.pop.call until Qt::RubyThreadFix.queue.empty? + + dialog.dispose + end end end diff --git a/lib/cosmos/packets/limits.rb b/lib/cosmos/packets/limits.rb index d53c80dcd..849078f38 100644 --- a/lib/cosmos/packets/limits.rb +++ b/lib/cosmos/packets/limits.rb @@ -201,7 +201,8 @@ def get(target_name, packet_name, item_name, limits_set = nil) # @return [Array1,"FALSE"=>0} i.state_colors = {"TRUE"=>:GREEN,"FALSE"=>:RED} + p.update_limits_items_cache(i) p.write("TEST1",0) p.enable_limits("TEST1") p.append_item("test2", 16, :UINT) @@ -579,7 +580,7 @@ module Cosmos i.limits.values = {:DEFAULT=>[1,2,4,5]} p.write("TEST2",3) p.enable_limits("TEST2") - p.update_limits_items_cache + p.update_limits_items_cache(i) p.check_limits vals = p.read_all_with_limits_states @@ -813,14 +814,17 @@ module Cosmos it "calls the limits_change_callback for all non STALE items" do p = Packet.new("tgt","pkt") p.append_item("test1", 8, :UINT) - p.get_item("TEST1").limits.values = {:DEFAULT=>[1,2,4,5]} + i = p.get_item("TEST1") + i.limits.values = {:DEFAULT=>[1,2,4,5]} + p.update_limits_items_cache(i) p.append_item("test2", 16, :UINT) - p.get_item("TEST2").limits.values = {:DEFAULT=>[1,2,4,5]} + i = p.get_item("TEST2") + i.limits.values = {:DEFAULT=>[1,2,4,5]} + p.update_limits_items_cache(i) p.write("TEST1",3) p.write("TEST2",3) p.enable_limits("TEST1") p.enable_limits("TEST2") - p.update_limits_items_cache callback = double("callback", :call => true) p.limits_change_callback = callback @@ -845,11 +849,11 @@ module Cosmos test1 = p.get_item("TEST1") test1.limits.values = {:DEFAULT=>[1,2,4,5]} - p.update_limits_items_cache + p.update_limits_items_cache(test1) expect(p.limits_items).to eql [test1] test2 = p.get_item("TEST2") test2.limits.values = {:DEFAULT=>[1,2,4,5]} - p.update_limits_items_cache + p.update_limits_items_cache(test2) expect(p.limits_items).to eql [test1, test2] end end @@ -858,14 +862,17 @@ module Cosmos it "returns an array indicating all items out of limits" do p = Packet.new("tgt","pkt") p.append_item("test1", 8, :UINT) - p.get_item("TEST1").limits.values = {:DEFAULT=>[1,2,4,5]} + i = p.get_item("TEST1") + i.limits.values = {:DEFAULT=>[1,2,4,5]} + p.update_limits_items_cache(i) p.enable_limits("TEST1") p.write("TEST1",3) p.append_item("test2", 16, :UINT) - p.get_item("TEST2").limits.values = {:DEFAULT=>[1,2,4,5]} + i = p.get_item("TEST2") + i.limits.values = {:DEFAULT=>[1,2,4,5]} + p.update_limits_items_cache(i) p.write("TEST2",3) p.enable_limits("TEST2") - p.update_limits_items_cache p.check_limits expect(p.out_of_limits).to eql [] @@ -882,12 +889,15 @@ module Cosmos it "sets all limits states to the given state" do p = Packet.new("tgt","pkt") p.append_item("test1", 8, :UINT) - p.get_item("TEST1").limits.values = {:DEFAULT=>[1,2,4,5]} + i = p.get_item("TEST1") + i.limits.values = {:DEFAULT=>[1,2,4,5]} + p.update_limits_items_cache(i) p.enable_limits("TEST1") p.append_item("test2", 16, :UINT) - p.get_item("TEST2").limits.values = {:DEFAULT=>[1,2,4,5]} + i = p.get_item("TEST2") + i.limits.values = {:DEFAULT=>[1,2,4,5]} + p.update_limits_items_cache(i) p.enable_limits("TEST2") - p.update_limits_items_cache expect(p.out_of_limits).to eql [] PacketItemLimits::OUT_OF_LIMITS_STATES.each do |state| @@ -927,6 +937,7 @@ module Cosmos expect(test1.limits.enabled).to be_falsey test1.states = {"TRUE"=>1,"FALSE"=>0} test1.state_colors = {"TRUE"=>:GREEN,"FALSE"=>:RED} + @p.update_limits_items_cache(test1) @p.write("TEST1", 0) @p.enable_limits("TEST1") test2 = @p.get_item("TEST2") @@ -935,7 +946,7 @@ module Cosmos test2.state_colors = {"TRUE"=>:RED,"FALSE"=>:GREEN} @p.write("TEST2", 0) @p.enable_limits("TEST2") - @p.update_limits_items_cache + @p.update_limits_items_cache(test2) # Mock the callback so we can see if it is called properly callback = double("callback", :call => true) @@ -963,18 +974,20 @@ module Cosmos @test1 = @p.get_item("TEST1") expect(@test1.limits.enabled).to be_falsey @test1.limits.values = {:DEFAULT=>[1,2,4,5]} # red yellow + @p.update_limits_items_cache(@test1) @p.enable_limits("TEST1") @test2 = @p.get_item("TEST2") expect(@test2.limits.enabled).to be_falsey @test2.limits.values = {:DEFAULT=>[1,2,6,7,3,5]} # red yellow and blue + @p.update_limits_items_cache(@test2) @p.enable_limits("TEST2") @test3 = @p.get_item("TEST3") expect(@test3.limits.enabled).to be_falsey @test3.limits.values = {:DEFAULT=>[1,1.5,2.5,3]} # red yellow + @p.update_limits_items_cache(@test3) @p.enable_limits("TEST3") - @p.update_limits_items_cache # Mock the callback so we can see if it is called properly @callback = double("callback", :call => true) @@ -1224,12 +1237,15 @@ module Cosmos it "sets all limits states to stale" do p = Packet.new("tgt","pkt") p.append_item("test1", 8, :UINT) - p.get_item("TEST1").limits.values = {:DEFAULT=>[1,2,4,5]} + i = p.get_item("TEST1") + i.limits.values = {:DEFAULT=>[1,2,4,5]} + p.update_limits_items_cache(i) p.enable_limits("TEST1") p.append_item("test2", 16, :UINT) - p.get_item("TEST2").limits.values = {:DEFAULT=>[1,2,4,5]} + i = p.get_item("TEST2") + i.limits.values = {:DEFAULT=>[1,2,4,5]} + p.update_limits_items_cache(i) p.enable_limits("TEST2") - p.update_limits_items_cache expect(p.out_of_limits).to eql [] expect(p.stale).to be_truthy