Class: WMIRefWindow
- Inherits:
-
Object
- Object
- WMIRefWindow
- Defined in:
- lib/gui/wmi_ref_window.rb
Instance Method Summary collapse
- #add_gui_wmi_ref ⇒ Object
- #add_modify_wmi_ref(add_boolean, wmi_ref_name = nil) ⇒ Object
- #clear_ls ⇒ Object
- #edit_wmi_ref(wmi_ref_name) ⇒ Object
-
#initialize ⇒ WMIRefWindow
constructor
A new instance of WMIRefWindow.
-
#populate_ls ⇒ Object
populate listview with saved values.
Constructor Details
#initialize ⇒ WMIRefWindow
Returns a new instance of WMIRefWindow.
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 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 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 |
# File 'lib/gui/wmi_ref_window.rb', line 15 def initialize() #save wmiref hash @wmirefs_backup=$wmi_refs.dup @window=Gtk::Window.new @window.set_title("WMI Request Ref configuration") @window.set_size_request(300, 200) @window.signal_connect("key_press_event") {|w,e| if e.keyval == Gdk::Keyval::GDK_Escape @window.destroy end } frame = Gtk::Frame::new frame.border_width=5 frame.show vbox_root=Gtk::VBox::new vbox_root.show @window.add vbox_root vbox_root.add frame vbox = Gtk::VBox.new(false,0) vbox.show frame.add vbox @wmi_ref_ls = Gtk::ListStore.new(String, String) @wmi_ref_view = Gtk::TreeView.new(@wmi_ref_ls) @wmi_ref_view.show column1 = Gtk::TreeViewColumn.new("Name", Gtk::CellRendererText.new, {:text => 0}) column1.set_sort_column_id(0) column2 = Gtk::TreeViewColumn.new("Description", Gtk::CellRendererText.new, {:text => 1}) column2.set_sort_column_id(1) @wmi_ref_view.append_column(column1) @wmi_ref_view.append_column(column2) scroll = Gtk::ScrolledWindow.new(nil, nil) scroll.border_width=2 scroll.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC) scroll.add @wmi_ref_view scroll.show # Create a menu = Gtk::Menu.new item_add = Gtk::ImageMenuItem.new("Add WMI Ref") image_item_add = Gtk::Image.new() image_item_add.set_stock(Gtk::Stock::ADD) item_add.set_image(image_item_add) item_add.signal_connect("activate") { add_gui_wmi_ref() } .append(item_add) item_del = Gtk::ImageMenuItem.new("Delete selected WMI Ref") image_item_del = Gtk::Image.new() image_item_del.set_stock(Gtk::Stock::REMOVE) item_del.set_image(image_item_del) item_del.signal_connect("activate") { if @wmi_ref_view.selection.selected!=nil if WMIRef::del_wmi_ref(@wmi_ref_view.selection.selected[0]) @wmi_ref_view.model.remove(@wmi_ref_view.selection.selected) else dialog = Gtk::MessageDialog.new(@window, Gtk::Dialog::DESTROY_WITH_PARENT, Gtk::MessageDialog::ERROR, Gtk::MessageDialog::BUTTONS_OK, "You can't delete! WMI Ref in use") dialog.run dialog.destroy end end } .append(item_del) item_edit = Gtk::ImageMenuItem.new("Edit WMI Ref") image_item_edit = Gtk::Image.new() image_item_edit.set_stock(Gtk::Stock::EDIT) item_edit.set_image(image_item_edit) item_edit.signal_connect("activate") { if @wmi_ref_view.selection.selected != nil edit_wmi_ref(@wmi_ref_view.selection.selected[0]) end } .append(item_edit) @wmi_ref_view.signal_connect("button_press_event") do |, event| if event.kind_of? Gdk::EventButton and event. == 3 if @wmi_ref_view.selection.selected == nil item_del.set_sensitive(false) item_edit.set_sensitive(false) else item_del.set_sensitive(true) item_edit.set_sensitive(true) end .popup(nil, nil, event., event.time) elsif (@wmi_ref_view.selection.selected != nil) && (event.event_type == Gdk::Event::BUTTON2_PRESS) edit_wmi_ref(@wmi_ref_view.selection.selected[0]) end end .show_all populate_ls() vbox.add(scroll) bbox = Gtk::HBox::new(FALSE, 10) bbox.border_width=10 bbox.show = Gtk::Button.new(Gtk::Stock::OK) .show .signal_connect("clicked") { WMIRef::write_db_wmiref() @window.destroy } = Gtk::Button.new(Gtk::Stock::CANCEL) .show .signal_connect("clicked") { $wmi_refs=@wmirefs_backup @window.destroy } .set_flags(Gtk::Widget::CAN_DEFAULT) bbox.pack_start(, TRUE, TRUE, 0) .set_flags(Gtk::Widget::CAN_DEFAULT) bbox.pack_start(, TRUE, TRUE, 0) separator = Gtk::HSeparator::new() separator.show vbox_root.pack_start(separator, FALSE, TRUE, 0) vbox_root.pack_start(bbox, FALSE, TRUE, 0) @window.show end |
Instance Method Details
#add_gui_wmi_ref ⇒ Object
148 149 150 |
# File 'lib/gui/wmi_ref_window.rb', line 148 def add_gui_wmi_ref() add_modify_wmi_ref(true) end |
#add_modify_wmi_ref(add_boolean, wmi_ref_name = nil) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 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 228 229 230 231 232 233 234 235 236 237 238 239 240 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 |
# File 'lib/gui/wmi_ref_window.rb', line 156 def add_modify_wmi_ref(add_boolean, wmi_ref_name=nil) window=Gtk::Window.new window.set_modal(true) lbl="Edit WMI Ref" if add_boolean lbl="Add WMI Ref" end window.set_title(lbl) window.set_size_request(460, 160) window.signal_connect("key_press_event") {|w,e| if e.keyval == Gdk::Keyval::GDK_Escape window.destroy end } frame = Gtk::Frame::new frame.border_width=10 frame.show vbox_root=Gtk::VBox::new vbox_root.show window.add vbox_root vbox_root.add frame vbox = Gtk::VBox.new vbox.show frame.add vbox table = Gtk::Table.new(3,2,false) table.show label_name = Gtk::Label.new "Name" label_name.show if add_boolean entry_name = Gtk::Entry.new else entry_name = Gtk::Entry.new entry_name.set_editable false entry_name.set_text(wmi_ref_name) end entry_name.show table.attach(label_name,0,1,0,1) table.attach(entry_name,1,2,0,1) entry_description = Gtk::Entry.new if !add_boolean entry_description.set_text($wmi_refs[entry_name.text()].description) unless entry_name.text() == "" end entry_description.show label_description = Gtk::Label.new "Description" label_description.show table.attach(label_description,0,1,1,2) table.attach(entry_description,1,2,1,2) entry_value = Gtk::Entry.new if !add_boolean entry_value.set_text($wmi_refs[entry_name.text()].value) unless entry_name.text() == "" end entry_value.show label_value = Gtk::Label.new "Value" label_value.show table.attach(label_value,0,1,2,3) table.attach(entry_value,1,2,2,3) if !add_boolean entry_name.signal_connect("changed") {|e| if e.text() != "" entry_description.set_text($wmi_refs[e.text()].description) entry_value.set_text($wmi_refs[e.text()].value) end } end bbox =Gtk::HBox::new(FALSE, 10) bbox.border_width=10 bbox.show = Gtk::Button.new(Gtk::Stock::OK) .show .signal_connect("clicked") { if add_boolean #new entry! if $wmi_refs[entry_name.text()] == nil WMIRef::add_wmi_ref(entry_name.text(),entry_description.text(),entry_value.text()) iter = @wmi_ref_ls.append iter[0] = entry_name.text() iter[1] = entry_description.text() window.destroy else dialog = Gtk::MessageDialog.new(window, Gtk::Dialog::DESTROY_WITH_PARENT, Gtk::MessageDialog::ERROR, Gtk::MessageDialog::BUTTONS_OK, "WMI Ref '#{entry_name.text()}' already exists!") dialog.run dialog.destroy end else #modify existing entry $wmi_refs[entry_name.text()].description=entry_description.text() $wmi_refs[entry_name.text()].value=entry_value.text() @wmi_ref_ls.each do |model,path,iter| if iter[0] == entry_name.text() iter[1]=entry_description.text() break end end window.destroy end } = Gtk::Button.new(Gtk::Stock::CANCEL) .show .signal_connect("clicked") { window.destroy } .set_flags(Gtk::Widget::CAN_DEFAULT) bbox.pack_start(, TRUE, TRUE, 0) .set_flags(Gtk::Widget::CAN_DEFAULT) bbox.pack_start(, TRUE, TRUE, 0) vbox.add(table) separator = Gtk::HSeparator::new() separator.show vbox_root.pack_start(separator, FALSE, TRUE, 0) vbox_root.pack_start(bbox, FALSE, TRUE, 0) window.show end |
#clear_ls ⇒ Object
3 4 5 |
# File 'lib/gui/wmi_ref_window.rb', line 3 def clear_ls() @wmi_ref_ls.clear() end |
#edit_wmi_ref(wmi_ref_name) ⇒ Object
152 153 154 |
# File 'lib/gui/wmi_ref_window.rb', line 152 def edit_wmi_ref(wmi_ref_name) add_modify_wmi_ref(false, wmi_ref_name) end |
#populate_ls ⇒ Object
populate listview with saved values
7 8 9 10 11 12 13 |
# File 'lib/gui/wmi_ref_window.rb', line 7 def populate_ls() $wmi_refs.each_key do |name| iter = @wmi_ref_ls.append iter[0] = name iter[1] = $wmi_refs[name].description end end |