Class: Cosmos::Screen
- Defined in:
- lib/cosmos/tools/tlm_viewer/screen.rb
Defined Under Namespace
Classes: Widgets
Constant Summary collapse
- @@open_screens =
The list of all open screens so they can be shutdown when close_all_screens is called
[]
Instance Attribute Summary collapse
-
#full_name ⇒ Object
Returns the value of attribute full_name.
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
-
#window ⇒ Object
Returns the value of attribute window.
Class Method Summary collapse
Instance Method Summary collapse
- #closeEvent(event) ⇒ Object
- #get_named_widget(widget_name) ⇒ Object
- #get_target_name(target_name) ⇒ Object
- #graceful_kill ⇒ Object
-
#initialize(full_name, filename, notify_on_close = nil, mode = :REALTIME, x_pos = nil, y_pos = nil, original_target_name = nil, substitute = nil, force_substitute = false, single_screen = false) ⇒ Screen
constructor
A new instance of Screen.
- #mode ⇒ Object
- #named_widgets ⇒ Object
- #process(filename) ⇒ Object
- #process_widget(parser, keyword, parameters, layout_stack, global_settings, global_subsettings) ⇒ Object
- #shutdown ⇒ Object
- #widgets ⇒ Object
Constructor Details
#initialize(full_name, filename, notify_on_close = nil, mode = :REALTIME, x_pos = nil, y_pos = nil, original_target_name = nil, substitute = nil, force_substitute = false, single_screen = false) ⇒ Screen
Returns a new instance of Screen.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 202 def initialize(full_name, filename, notify_on_close = nil, mode = :REALTIME, x_pos = nil, y_pos = nil, original_target_name = nil, substitute = nil, force_substitute = false, single_screen = false) super(nil) # The full name of the widget which goes in the title @full_name = full_name # The method 'notify' will be called on this object if it is given @notify_on_close = notify_on_close # X position to display the screen @x_pos = x_pos # Y position to display the screen @y_pos = y_pos # Original target name where this screen is defined @original_target_name = original_target_name.to_s.upcase # Substitute target name to use when actually retrieving data @substitute = substitute # Whether to automatically substitute the target name when requesting # telemetry @force_substitute = force_substitute # Whether this screen was launched as a command line option to be # displayed as a stand alone screen and not launched as a part of the # regular TlmViewer application @single_screen = single_screen = Widgets.new(self, mode) @window = process(filename) @@open_screens << self if @window end |
Instance Attribute Details
#full_name ⇒ Object
Returns the value of attribute full_name.
24 25 26 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 24 def full_name @full_name end |
#height ⇒ Object
Returns the value of attribute height.
24 25 26 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 24 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
24 25 26 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 24 def width @width end |
#window ⇒ Object
Returns the value of attribute window.
24 25 26 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 24 def window @window end |
Class Method Details
.close_all_screens(closer) ⇒ Object
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 468 def self.close_all_screens(closer) Widgets.closing_all = true screens = @@open_screens.clone screens.each do |screen| screen.window.graceful_kill if screen.window end screens.each do |screen| begin screen.window.close rescue # Screen probably already closed - continue end end Widgets.closing_all = false end |
.open_screens ⇒ Object
464 465 466 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 464 def self.open_screens @@open_screens end |
Instance Method Details
#closeEvent(event) ⇒ Object
428 429 430 431 432 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 428 def closeEvent(event) super(event) @@open_screens.delete(self) shutdown() end |
#get_named_widget(widget_name) ⇒ Object
448 449 450 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 448 def () .named[.upcase] end |
#get_target_name(target_name) ⇒ Object
452 453 454 455 456 457 458 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 452 def get_target_name(target_name) if @substitute and (@original_target_name == target_name.upcase or @force_substitute) @substitute else target_name end end |
#graceful_kill ⇒ Object
460 461 462 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 460 def graceful_kill .graceful_kill end |
#mode ⇒ Object
237 238 239 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 237 def mode .mode end |
#named_widgets ⇒ Object
233 234 235 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 233 def .named end |
#process(filename) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 241 def process(filename) layout_stack = [] layout_stack[0] = nil = nil = nil global_settings = {} global_subsettings = {} begin parser = ConfigParser.new parser.parse_file(filename) do |keyword, parameters| if keyword case keyword when 'SCREEN' parser.verify_num_parameters(3, 3, "#{keyword} <Width or AUTO> <Height or AUTO> <Polling Period>") @width = parameters[0].to_i @height = parameters[1].to_i .polling_period = parameters[2].to_f setWindowTitle(@full_name) = Qt::Widget.new() setCentralWidget() frame = Qt::VBoxLayout.new() .setLayout(frame) layout_stack[0] = frame Cosmos.load_cosmos_icon if @single_screen when 'END' parser.verify_num_parameters(0, 0, "#{keyword}") = layout_stack.pop() # Call the complete method to allow layout widgets to do things # once all their children have been added # Need the respond_to? to protect against the top level widget # added by the SCREEN code above. It adds a Qt::VBoxLayout # to the stack and that class doesn't have a complete method. .complete() if .respond_to? :complete when 'SETTING' parser.verify_num_parameters(1, nil, "#{keyword} <Setting Name> <Setting Values... (optional)>") if parameters.length > 1 .set_setting(parameters[0], parameters[1..-1]) else .set_setting(parameters[0], []) end when 'SUBSETTING' parser.verify_num_parameters(2, nil, "#{keyword} <Widget Index (0..?)> <Setting Name> <Setting Values... (optional)>") if parameters.length > 2 .set_subsetting(parameters[0], parameters[1], parameters[2..-1]) else .set_subsetting(parameters[0], parameters[1], []) end when 'GLOBAL_SETTING' parser.verify_num_parameters(2, nil, "#{keyword} <Widget Type> <Setting Name> <Setting Values... (optional)>") klass = Cosmos.require_class(parameters[0].to_s.downcase + '_widget') global_settings[klass] ||= [] global_settings[klass] << parameters[1..-1] when 'GLOBAL_SUBSETTING' parser.verify_num_parameters(3, nil, "#{keyword} <Widget Type> <Widget Index (0..?)> <Setting Name> <Setting Values... (optional)>") klass = Cosmos.require_class(parameters[0].to_s.downcase + '_widget') global_subsettings[klass] ||= [] global_subsettings[klass] << [parameters[1]].concat(parameters[2..-1]) else = (parser, keyword, parameters, layout_stack, global_settings, global_subsettings) end # case keyword end # if keyword end # parser.parse_file rescue Exception => err begin raise $!, "In file #{filename} at line #{parser.line_number}:\n\n#{$!}", $!.backtrace rescue => err ExceptionDialog.new(self, err, "Screen #{File.basename(filename)}", false) end shutdown() return nil end unless .invalid.empty? Qt::MessageBox.information(self, "Screen #{@full_name}", "The following telemetry items could not be created: \n" + .invalid.join("\n")) end # Process all settings before we show the screen .process_settings if @width > 0 and @height > 0 resize(@width, @height) elsif @width <= 0 and height > 0 resize(self.width, @height) elsif @width > 0 and height <= 0 resize(@width, self.height) end if @x_pos or @y_pos x = @x_pos || 0 y = @y_pos || 0 move(x,y) end show() # Start the update thread now that the screen is displayed .start_updates() return self end |
#process_widget(parser, keyword, parameters, layout_stack, global_settings, global_subsettings) ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 346 def (parser, keyword, parameters, layout_stack, global_settings, global_subsettings) = nil if keyword == 'NAMED_WIDGET' parser.verify_num_parameters(2, nil, "#{keyword} <Widget Name> <Widget Type> <Widget Settings... (optional)>") = parameters[0].upcase keyword = parameters[1].upcase parameters = parameters[2..-1] else parser.verify_num_parameters(0, nil, "#{keyword} <Widget Settings... (optional)>") end = nil klass = Cosmos.require_class(keyword.downcase + '_widget') if klass.takes_value? parser.verify_num_parameters(3, nil, "#{keyword} <Target Name> <Packet Name> <Item Name> <Widget Settings... (optional)>") begin if @substitute and (@original_target_name == parameters[0].upcase or @force_substitute) System.telemetry.packet_and_item(@substitute, parameters[1], parameters[2]) = klass.new(layout_stack[-1], @substitute, *parameters[1..(parameters.length - 1)]) else System.telemetry.packet_and_item(*parameters[0..2]) = klass.new(layout_stack[-1], *parameters) end rescue .invalid << parameters.join(" ") return nil end else if parameters[0] != nil = klass.new(layout_stack[-1], *parameters) else = klass.new(layout_stack[-1]) end end # Assign screen .screen = self # Assign polling period if .polling_period .polling_period = .polling_period else raise "SCREEN keyword must appear before any widgets" end # Add to Layout Stack if Necessary if klass.layout_manager? layout_stack.push() end # Apply Global Settings global_settings.each do |global_klass, settings| if .class == global_klass settings.each do |setting| if setting.length > 1 .set_setting(setting[0], setting[1..-1]) else .set_setting(setting[0], []) end end end end # Apply Global Subsettings global_subsettings.each do |global_klass, settings| if .class == global_klass settings.each do |setting| = setting[0] if setting.length > 2 .set_subsetting(, setting[1], setting[2..-1]) else .set_subsetting(, setting[1], []) end end end end .(klass, parameters, , , @substitute, @original_target_name, @force_substitute) return end |
#shutdown ⇒ Object
434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 434 def shutdown # Shutdown Value Gathering Thread .shutdown # Notify Owner if Necessary @notify_on_close.notify(self) if @notify_on_close if @single_screen QtTool.restore_io end self.dispose end |
#widgets ⇒ Object
229 230 231 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 229 def . end |