Class | TestApp |
In: |
test/ui/wx/nodeproperties_demo.rb
test/ui/wx/popupmenu_demo.rb test/ui/wx/propertiespane_demo.rb |
Parent: | Wx::App |
# File test/ui/wx/propertiespane_demo.rb, line 37 def on_fromxml out = [] props = XmlSimple.xml_in( @text.get_value ) props['property'].each do |prop| #p prop value = prop['value'].first case prop['type'].to_s when 'Fixnum' value = value.to_i when 'TrueClass', 'FalseClass' value = (value == 'true') ? true : false end out << Property.new( prop['key'].first, prop['name'].first, value) end props['multiplechoiceproperty'].each do |prop| #p prop out << MultipleChoiceProperty.new( prop['key'].first, prop['name'].first, prop['values'].first['value'], prop['options'].first['option'], prop['multiple'].first == "true" ? true : false ) end #out.each do |prop| p prop end @pane.show_properties(1, out) end
# File test/ui/wx/propertiespane_demo.rb, line 69 def on_init frame = Wx::Frame.new( nil, Wx::ID_ANY, "dradis WxWidgets test window", Wx::DEFAULT_POSITION, Wx::Size.new(800, 600) ) set_top_window(frame) @pane = Ui::WxWidgets::Widgets::PropertiesPane.new(frame) props = [ Property.new( :ip, 'IP address', '10.0.0.1'), MultipleChoiceProperty.new( :protocols, 'IP protocol dialects', ['ipv4', 'ipv6'], ['ipv4', 'ipv6'], true), Property.new( :uptime, 'Miliseconds since last reboot', 103421), Property.new( :live, 'Is the host alive?', true), MultipleChoiceProperty.new( :role, 'Host role in the network', 'web server', ['web server', 'database server', 'file server'], false) ] @pane.show_properties(1, props) toxml = Wx::Button.new( frame, Wx::ID_ANY, '-->') fromxml = Wx::Button.new( frame, Wx::ID_ANY, '<--') @text = Wx::TextCtrl.new( frame, Wx::ID_ANY, '', Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, Wx::TE_MULTILINE) s_v = Wx::BoxSizer.new(Wx::VERTICAL) s_v.add toxml, 0, Wx::ALL, 5 s_v.add fromxml, 0, Wx::ALL, 5 sizer = Wx::BoxSizer.new(Wx::HORIZONTAL) sizer.add @pane, 1, Wx::ALL|Wx::EXPAND, 5 sizer.add s_v, 0, Wx::ALL, 5 sizer.add @text, 1, Wx::ALL|Wx::EXPAND, 5 frame.set_sizer( sizer ) frame.show evt_button(toxml.get_id) { on_toxml } evt_button(fromxml.get_id) { on_fromxml } return true end
# File test/ui/wx/nodeproperties_demo.rb, line 68 def on_init frame = Wx::Frame.new( nil, Wx::ID_ANY, "dradis WxWidgets test window", Wx::DEFAULT_POSITION, Wx::Size.new(800, 600) ) set_top_window(frame) label = Wx::StaticText.new( frame, Wx::ID_ANY, "Use the text box to paste a universe.xml file. Then click on 'Load'") @text = Wx::TextCtrl.new( frame, Wx::ID_ANY, '', Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, Wx::TE_MULTILINE) if not File.exists?("#{$path}/tempuniverse/universe.xml") @text.set_value(UNIVERSE_XML) else @text.set_value(File.read("#{$path}/tempuniverse/universe.xml")) end @load = Wx::Button.new(frame, Wx::ID_ANY, 'Load') evt_button(@load.get_id) { on_load } splitter = Wx::SplitterWindow.new(frame, Wx::ID_ANY) @nodes = Wx::ListBox.new(splitter, Wx::ID_ANY) evt_listbox(@nodes) { |event| on_node_click(event) } @properties = Ui::WxWidgets::Widgets::PropertiesPane.new(splitter) splitter.split_vertically(@nodes, @properties, 200) sizer = Wx::BoxSizer.new(Wx::VERTICAL) sizer.add label, 0, Wx::ALL, 5 sizer.add @text, 0, Wx::ALL|Wx::EXPAND, 5 sizer.add @load, 0, Wx::ALL, 5 sizer.add splitter, 1, Wx::ALL|Wx::EXPAND, 5 frame.set_sizer_and_fit(sizer) frame.show return true end
# File test/ui/wx/popupmenu_demo.rb, line 71 def on_init frame = Wx::Frame.new( nil, Wx::ID_ANY, "dradis WxWidgets test window", Wx::DEFAULT_POSITION, Wx::Size.new(800, 600) ) set_top_window(frame) @text = Wx::TextCtrl.new( frame, Wx::ID_ANY, '', Wx::DEFAULT_POSITION, Wx::Size.new(300,300), Wx::TE_MULTILINE) if not File.exists?("#{$path}/tempuniverse/universe.xml") @text.set_value(UNIVERSE_XML) else @text.set_value(File.read("#{$path}/tempuniverse/universe.xml")) end evt_right_down do |event| on_popupmenu end label1 = Wx::StaticText.new( frame, Wx::ID_ANY, "The contents of this text box will be stored in a file in #{$path} and will be loaded by the Multiverse service provider.") label2 = Wx::StaticText.new( frame, Wx::ID_ANY, 'Right-click in the text box to see the magic') sizer = Wx::BoxSizer.new(Wx::VERTICAL) sizer.add label1, 0, Wx::ALL, 5 sizer.add label2, 0, Wx::ALL, 5 sizer.add @text, 1, Wx::ALL|Wx::EXPAND, 5 frame.set_sizer_and_fit(sizer) frame.show return true end
# File test/ui/wx/nodeproperties_demo.rb, line 52 def on_load $logger.debug { 'Saving contents of the text box into ./tempuniverse/universe.xml'} save_file $logger.debug { 'Done. Loading the Multiverse...'} provider = Core::Providers::Multiverse::Provider.new(:path => $path) $logger.debug { 'Done.'} @nodes.clear provider.service_multiverse_universe_list.each do |universe| next if universe.nodes.size.zero? universe.nodes.each do |node| @nodes.append "#{node[:type]}: #{node[:name]}", node[:properties].values end end end
# File test/ui/wx/nodeproperties_demo.rb, line 40 def on_node_click(event) $logger.debug { "Node clicked: [#{event.get_string}]"} @properties.show_properties(1, event.get_client_data) end
# File test/ui/wx/popupmenu_demo.rb, line 47 def on_popupmenu menu = Wx::Menu.new addchild = Wx::Menu.new $logger.debug { 'Saving contents of the text box into ./tempuniverse/universe.xml'} save_file $logger.debug { 'Done. Loading the Multiverse...'} provider = Core::Providers::Multiverse::Provider.new(:path => $path) $logger.debug { 'Done.'} uid = 0 provider.service_multiverse_universe_list.each do |universe| next if universe.nodes.size.zero? universemenu = Wx::Menu.new universe.nodes.each do |node| uid += 100 universemenu.append uid, node[:name] end addchild.append_menu Wx::ID_ANY, universe.meta[:name], universemenu end menu.append_menu Wx::ID_ANY, 'add child', addchild get_top_window().popup_menu menu end
# File test/ui/wx/propertiespane_demo.rb, line 34 def on_toxml @text.set_value( @pane.get_properties().to_xml(:root => 'properties') ) end
# File test/ui/wx/nodeproperties_demo.rb, line 45 def save_file Dir.mkdir("#{$path}/tempuniverse/") if not File.exists?("#{$path}/tempuniverse/") universe = File.new("#{$path}/tempuniverse/universe.xml", 'w+') universe.puts @text.get_value universe.close end