Class: Cosmos::SetTlmDialog

Inherits:
Qt::Dialog show all
Defined in:
lib/cosmos/gui/dialogs/set_tlm_dialog.rb

Constant Summary collapse

IGNORED_ITEMS =
['RECEIVED_TIMESECONDS', 'RECEIVED_TIMEFORMATTED', 'RECEIVED_COUNT']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, title, done_label, cancel_label, target_name, packet_name, packet = nil) ⇒ SetTlmDialog



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/cosmos/gui/dialogs/set_tlm_dialog.rb', line 24

def initialize(parent, title, done_label, cancel_label, target_name, packet_name, packet = nil)
  super(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
  @target_name = target_name
  @packet_name = packet_name
  @current_item_name = nil

  extend Api if CmdTlmServer.instance

  if !packet
    @items = get_tlm_packet(@target_name, @packet_name)
  else
    @items = packet.read_all_with_limits_states
  end
  @items.delete_if {|item_name, _, _| ['RECEIVED_TIMESECONDS', 'RECEIVED_TIMEFORMATTED', 'RECEIVED_COUNT'].include?(item_name)}

  setWindowTitle(title)
  Cosmos.load_cosmos_icon

  layout = Qt::VBoxLayout.new
  @tab_book = Qt::TabWidget.new
  values_layout = Qt::FormLayout.new
  widget = Qt::Widget.new
  widget.layout = values_layout
  page_count = 1
  @tab_book.addTab(widget, "Page #{page_count}")
  @editors = []
  @items.each do |item_name, item_value, _|
    _, item = System.telemetry.packet_and_item(@target_name, @packet_name, item_name)
    if item.states
      @editors << Qt::ComboBox.new
      @editors[-1].setSizeAdjustPolicy(Qt::ComboBox::AdjustToContents)
      current_index = 0
      index = 0
      item.states.each do |state_name, state_value|
        @editors[-1].addItem(state_name)
        current_index = index if state_name == item_value
        index += 1
      end
      if item.states.length > 20
        @editors[-1].setMaxVisibleItems(20)
      else
        @editors[-1].setMaxVisibleItems(item.states.length)
      end
      @editors[-1].setCurrentIndex(current_index)
    else
      @editors << Qt::LineEdit.new
      @editors[-1].text = item_value.to_s
    end
    values_layout.addRow(item_name, @editors[-1])
    if ((@editors.length % 10) == 0 and @items.length > @editors.length)
      values_layout = Qt::FormLayout.new
      widget = Qt::Widget.new
      widget.layout = values_layout
      page_count += 1
      @tab_book.addTab(widget, "Page #{page_count}")
    end
  end

  layout.addWidget(@tab_book)
  @error_label = Qt::Label.new('')
  layout.addWidget(@error_label)

  button_layout = Qt::HBoxLayout.new
  # Create Done Button
  done_button = Qt::PushButton.new(done_label)
  connect(done_button, SIGNAL('clicked()'), self, SLOT('accept()'))
  button_layout.addWidget(done_button)

  # Create Cancel Button
  cancel_button = Qt::PushButton.new(cancel_label)
  connect(cancel_button, SIGNAL('clicked()'), self, SLOT('reject()'))
  button_layout.addWidget(cancel_button)
  layout.addLayout(button_layout)

  self.setLayout(layout)
end

Instance Attribute Details

#current_item_nameObject

Returns the value of attribute current_item_name.



22
23
24
# File 'lib/cosmos/gui/dialogs/set_tlm_dialog.rb', line 22

def current_item_name
  @current_item_name
end

#error_labelObject (readonly)

Returns the value of attribute error_label.



21
22
23
# File 'lib/cosmos/gui/dialogs/set_tlm_dialog.rb', line 21

def error_label
  @error_label
end

Class Method Details

.execute(parent, title, done_label, cancel_label, target_name, packet_name, packet = nil) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/cosmos/gui/dialogs/set_tlm_dialog.rb', line 110

def self.execute(parent, title, done_label, cancel_label, target_name, packet_name, packet = nil)
  dialog = self.new(parent, title, done_label, cancel_label, target_name, packet_name, packet)
  begin
    dialog.raise
    if dialog.exec == Qt::Dialog::Accepted
      dialog.set_items
      result = true
    else
      result = false
    end
  rescue => err
    dialog.error_label.setText("Error Setting #{dialog.current_item_name}: " + err.message)
    retry
  ensure
    dialog.dispose
  end
  result
end

Instance Method Details

#set_itemsObject



101
102
103
104
105
106
107
108
# File 'lib/cosmos/gui/dialogs/set_tlm_dialog.rb', line 101

def set_items
  index = 0
  @items.each do |item_name, _, _|
    @current_item_name = item_name
    set_tlm(@target_name, @packet_name, item_name, @editors[index].text)
    index += 1
  end
end