class CompoundDisplay
Compound widget for displaying multiple data visualization widgets in a grid layout (default dimensions: 3x2). Specific position configurations, e.g. which port gets displayed in which widget at which position) can be saved to and restored from YAML files. The grid will be a row_count x col_count matrix. The numbering sequence is left to right, top-down.
Example of a 2x3 widget position layout:
0 1 2 3 4 5
@author Allan Conquest <allan.conquest@dfki.de>
Attributes
Public Class Methods
# File lib/vizkit/widgets/compound_display/compound_display.rb, line 23 def initialize(row_count = 2, col_count = 3, parent = nil) super(parent) @container_hash = Hash.new # holds the container widgets set_window_title("CompoundDisplay") resize(600,400) layout = Qt::HBoxLayout.new set_layout(layout) @gui = Vizkit.load(File.join(File.dirname(__FILE__),'compound_display.ui'),self) @grid = @gui.grid_layout show_menu(true) layout.add_widget(@gui) set_grid_dimensions(row_count, col_count) # Allow user to set grid dimensions once @grid_dimensions_set = false ## Configure configuration import / export @gui.load_button.connect(SIGNAL :clicked) do configure_by_yaml end @gui.save_button.connect(SIGNAL :clicked) do save_yaml end self end
Public Instance Methods
Selective configuration of one element at position pos. The
connection is being established automatically with respect to the
configuration.
# File lib/vizkit/widgets/compound_display/compound_display.rb, line 57 def configure(pos, task, port, widget, policy = Hash.new) @container_hash[pos].configure(task, port, widget, policy) connect(pos) end
Import configuration from YAML file located at path.
TODO: Currently, the whole configuration will be replaced.
The format of the yaml file is as follows:
--- <pos>: !ruby/object:CompoundDisplayConfig task: <task name> port: <port name> widget: <widget name> connection_policy: <option hash> <pos>: !ruby/object:CompoundDisplayConfig task: <task name> ...
Example for the 4th element (bottom center):
--- 4: !ruby/object:CompoundDisplayConfig task: front_camera port: frame widget: ImageView connection_policy:
# File lib/vizkit/widgets/compound_display/compound_display.rb, line 161 def configure_by_yaml(path=nil) unless path # Display file explorer path = Qt::FileDialog.getOpenFileName(self, "Open configuration file", ".", "YAML Files (*.yml *.yaml)") end begin # Load configuration from YAML hash = YAML.load(open(path)) # Sanity checks: error = nil if hash.keys.max > @container_hash.keys.max error = "Higher position value in file than #containers available." elsif hash.size > @container_hash.size error = "More config items in file than containers available." end if error msg_box = Qt::MessageBox.new msg_box.set_text("Problem with YAML import:") msg_box.set_informative_text(error) msg_box.exec return end # Disconnect, update configuration and connect for each container hash.each do |pos, config| container = @container_hash[pos] container.disconnect container.configure_by_obj(config) container.connect if config end rescue Exception => e Vizkit.error "A problem occured while trying to open '#{path}': \n#{e.message}" Vizkit.error e.backtrace.inspect end end
Establish a connection between the port and widget specified in config for
element at pos.
# File lib/vizkit/widgets/compound_display/compound_display.rb, line 63 def connect(pos) @container_hash[pos].connect end
Close a connection between the port and widget specified in config for
element at pos. The content widget gets destroyed but the
configuration will remain save until it gets overriden by a new one.
# File lib/vizkit/widgets/compound_display/compound_display.rb, line 69 def disconnect(pos) @container_hash[pos].disconnect end
# File lib/vizkit/widgets/compound_display/compound_display.rb, line 234 def resizeEvent(event) #puts "Resized to #{event.size.width},#{event.size.height}" end
Save complete configuration in YAML format to a file located at
path.
# File lib/vizkit/widgets/compound_display/compound_display.rb, line 207 def save_yaml(path=nil) unless path # Display file explorer path = Qt::FileDialog.getSaveFileName(self, "Save configuration file", "./myconfig.yml", "YAML Files (*.yml *.yaml)") end begin config_hash = Hash.new @container_hash.each do |pos, container| config_hash[pos] = container.config end File.open(path, "w") {|f| f.write(config_hash.to_yaml) } rescue Exception => e Vizkit.error "A problem occured while trying to write configuration to '#{path}': \n#{e.message}" end end
Configures the dimensions of the grid layout. The grid will be a row_count x col_count matrix. The numbering sequence is left to right, top-down.
TODO: Does not work reliably at runtime! => Configure once at startup.
Examples:
row_count: 4, col_count: 2:
0 1 2 3 4 5 6 7
row_count: 3, col_count: 3
0 1 2 3 4 5 6 7 8
# File lib/vizkit/widgets/compound_display/compound_display.rb, line 91 def set_grid_dimensions(row_count, col_count) # Forbid resetting grid dimensions if @grid_dimensions_set Vizkit.warn("Error: You may set grid dimensions before configuration only.") return else @grid_dimensions_set = true end # Remove all parent widgets from grid. child = nil while(child = @grid.take_at(0)) widget = child.widget widget.set_parent(nil) widget = nil child = nil end # Generate container widgets with label if not yet existent counter = 0 for row in 0..row_count-1 do for col in 0..col_count-1 do container = nil if not @container_hash[counter] widget_pos = (row * col_count) + col container = ContainerWidget.new(widget_pos) @container_hash[counter] = container else container = @container_hash[counter] end # Add parent widget to grid @grid.add_widget(container, row, col) # TODO does this make @grid the parent of the widget? container.show counter = counter + 1 end end # Delete useless container widgets if any @container_hash.delete_if {|pos, conatiner| pos >= counter} end
# File lib/vizkit/widgets/compound_display/compound_display.rb, line 230 def sizeHint return Qt::Size.new(700,700) end