Class: NodeNetworkView
- Defined in:
- lib/gui/node_network_view.rb
Constant Summary
Constants inherited from NodeView
NodeView::MIN_MOVE, NodeView::NODE_SIZE
Instance Attribute Summary
Attributes inherited from NodeView
#bg_text, #group, #icon, #image, #node, #notification_count, #notification_sev, #selected, #text
Instance Method Summary collapse
- #hide_tooltips ⇒ Object
-
#initialize(rootcanvas, nd, status, icon_file, label) ⇒ NodeNetworkView
constructor
A new instance of NodeNetworkView.
- #setup_ellipse(root, status, icon_file, label) ⇒ Object
-
#show_tooltips ⇒ Object
define a tooltip.
Methods inherited from NodeView
#add_notification, #del_notification, #destroy, #get_node_size, #get_size, #get_text, #hide, #hide_link, #hide_selected_node_link, #hide_text, #icon_color, #move, #move_down, #move_left, #move_right, #move_up, #reload_bg_text, #reload_label_colors, #reparent, #reset_notification, #resize, #select, #selected?, #set_image, #set_text, #set_text_color, #show, #show_link, #show_selected_node_link, #show_text, #unlink_node, #unselect
Constructor Details
#initialize(rootcanvas, nd, status, icon_file, label) ⇒ NodeNetworkView
Returns a new instance of NodeNetworkView.
177 178 179 180 181 182 183 184 |
# File 'lib/gui/node_network_view.rb', line 177 def initialize(rootcanvas, nd, status, icon_file, label) @dragging=false @size=get_node_size() @tooltips=nil self.node=nd self.selected=false setup_ellipse(rootcanvas, status, icon_file, label) end |
Instance Method Details
#hide_tooltips ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/gui/node_network_view.rb', line 168 def hide_tooltips() if @tooltips != nil @tooltips.hide() #with this the tooltips is always refreshed @tooltips.destroy @tooltips=nil end end |
#setup_ellipse(root, status, icon_file, label) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 |
# File 'lib/gui/node_network_view.rb', line 3 def setup_ellipse(root, status, icon_file, label) node_size = get_node_size() @group = Goo::CanvasGroup.new(root,{:x => 0.0,:y => 0.0, :can_focus => true}) @group.visibility = Goo::CanvasItem::HIDDEN @icon=Goo::CanvasEllipse.new(@group, node.x+node_size/2, node.y+node_size/2, node_size/2, node_size/2, :fill_color_rgba => status, :stroke_color => "black", :line_width => 1.0) if (icon_file == nil) || (!FileTest.exist?(icon_file)) icon_file="#{PIXMAP_PATH}/unknown.png" end @image=nil if FileTest.exist?(icon_file) im=Gdk::Pixbuf.new(icon_file) #the network type icon @image=Goo::CanvasImage.new(@group, im, @icon.x1, @icon.y1, :width => node_size*80/100.0, :height => node_size*80/100.0, :can_focus => false, :scale_to_fit => true ) @image.x= @icon.x1+(node_size/2.0)-@image.width/2.0 @image.y= @icon.y1+(node_size/2.0)-@image.height/2.0 else puts "Could not find img #{icon_file}" end #box for the network label background, pos will be fixed by resize method cl = Integer("0x#{rgb_to_hex_color(Gdk::Color.new($config.label_bg[0],$config.label_bg[1],$config.label_bg[2]))}ff") @bg_text=Goo::CanvasRect.new(@group,@icon.x1-3*label.size/2, @icon.y2+node_size/5-5, node_size+3*label.size, node_size/5+5, :fill_color_rgba => cl, :stroke_color_rgba => cl, :line_width => 1.0) #the label, pos will be fixed by resize method @text=Goo::CanvasText.new(@group, label, @icon.x1+node_size/2, @icon.y2+2+node_size/5, 0, Gtk::ANCHOR_CENTER, :fill_color_rgba => Integer("0x#{rgb_to_hex_color(Gdk::Color.new($config.label_text[0],$config.label_text[1],$config.label_text[2]))}ff"), :font => "Sans 8") setup_item(@group) #set_tooltips() end |
#show_tooltips ⇒ Object
define a tooltip
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/gui/node_network_view.rb', line 54 def show_tooltips() if @tooltips==nil @tooltips=Gtk::Window.new(Gtk::Window::POPUP) @tooltips.set_decorated(false) @tooltips.set_size_request(-1,-1) @tooltips.set_window_position(Gtk::Window::POS_NONE) @tooltips.border_width=1 x,y=$win.position @tooltips.move(node.x+x+50, node.y+y+40) @tooltips.app_paintable=true @tooltips.realize drawable=@tooltips.window gc = Gdk::GC.new(drawable) @tooltips.modify_bg(Gtk::STATE_NORMAL,$light_yellow) @tooltips.signal_connect("expose-event") do |win, evt| tooltips_width, tooltips_height=@tooltips.size drawable.draw_rectangle(gc,false, 0, 0, tooltips_width-1, tooltips_height-1) drawable.draw_rectangle(gc,false, 1, 1, tooltips_width-3, tooltips_height-3) false end vbox=Gtk::VBox.new vbox.border_width=5 ttips_text="<span weight=\"bold\" size=\"small\">IP: </span>#{self.node.ip}" ttips_text+="\n<span weight=\"bold\" size=\"small\">Mask: </span>#{self.node.netmask}" if self.node.dns_domain? ttips_text+="\n<span weight=\"bold\" size=\"small\">Dns domain: </span>#{self.node.dns_domain}" end if self.node.name? ttips_text+="\n<span weight=\"bold\" size=\"small\">Name: </span>#{self.node.name}" end if self.node.description?() &&( self.node.description != "") ttips_text+="\n<span weight=\"bold\" size=\"small\">Description: </span>#{self.node.description}" end label = Gtk::Label.new.set_markup(ttips_text) label.set_alignment(0,0.5) vbox.add label if self.node.os && (self.node.os != "unknown") hbox=Gtk::HButtonBox.new hbox.set_layout_style(Gtk::ButtonBox::START) vbox.add hbox label_os = Gtk::Label.new.set_markup("<span weight=\"bold\" size=\"small\">OS: </span>") label_os.set_alignment(0,0.5) label_os.show hbox.add label_os pxb = Gdk::Pixbuf.new(PIXMAP_PATH+"/#{find_extension("os/#{self.node.os}")}",20,20) pxb_pixmap,pxb_mask=pxb.render_pixmap_and_mask(128) img=Gtk::Image.new(pxb_pixmap,pxb_mask) img.show hbox.add img hbox.show end if self.node.type ttype=Gtk::Table.new(1,0,false) vbox.add ttype label_type = Gtk::Label.new.set_markup("<span weight=\"bold\" size=\"small\">Type: </span>") label_type.set_alignment(0,0.5) label_type.show ttype.add label_type pxb = Gdk::Pixbuf.new(PIXMAP_PATH+"/#{find_extension("type/#{self.node.type}")}",20,20) pxb_pixmap,pxb_mask=pxb.render_pixmap_and_mask(128) img=Gtk::Image.new(pxb_pixmap,pxb_mask) img.show ttype.attach(img,0,1,0,1, Gtk::FILL) ttype.show end if self.node.nb_node() > 0 label_nbhost=Gtk::Label.new.set_markup("<span weight=\"bold\" size=\"small\">Nb host: </span>#{self.node.nb_node}") label_nbhost.set_alignment(0,0.5) label_nbhost.show vbox.add label_nbhost table = Gtk::Table.new(1,2,false) table.show vbox.add table label_status=Gtk::Label.new.set_markup("<span weight=\"bold\" size=\"small\">Status: </span>") label_status.show table.attach(label_status,0,1,0,1, Gtk::FILL) #do stat for each internal node network severity sev_stat=Array.new($status_value.size,0) node.get_node().each_value do |n| sev_stat[$status_value.index(n.status)]+=1 end status_index=0 $status.each do |stat| if sev_stat[status_index] > 0 label_sev = Gtk::Label.new.set_markup("<span color=\"##{rgb_to_hex_color(get_color_from_status(stat))}\">#{sev_stat[status_index]} #{stat}</span>") label_sev.show table.attach(label_sev,1,2,status_index,status_index+1, Gtk::FILL) end status_index+=1 end end vbox.show label.show @tooltips.add vbox end if !@tooltips.visible? @tooltips.show() end end |