Class: ViGUI
- Inherits:
-
Object
- Object
- ViGUI
- Defined in:
- lib/ViGUI.rb
Instance Method Summary collapse
- #add_hardware(hardware) ⇒ Object
- #add_state(state) ⇒ Object
- #add_tasks(callback, index, tasks) ⇒ Object
- #color_callback(index) ⇒ Object
- #colors=(colors) ⇒ Object
- #create_events(w) ⇒ Object
- #create_hardware(w) ⇒ Object
- #create_overview(w) ⇒ Object
- #create_status(row, col, h, w) ⇒ Object
- #create_vmlist(row, col, h, w) ⇒ Object
- #create_widget(class_name, name, title, row, col, h, w) ⇒ Object
- #current_list_index ⇒ Object
- #draw_events(events) ⇒ Object
- #draw_list(list) ⇒ Object
- #enter_login ⇒ Object
- #get_h_w ⇒ Object
- #getchar ⇒ Object
- #handle_key(ch) ⇒ Object
-
#initialize ⇒ ViGUI
constructor
A new instance of ViGUI.
- #refresh ⇒ Object
- #select(choices) ⇒ Object
- #set_status(text) ⇒ Object
- #setup(focus_callback) ⇒ Object
- #show_messagebox(dialog, title) ⇒ Object
- #unload ⇒ Object
Constructor Details
Instance Method Details
#add_hardware(hardware) ⇒ Object
112 113 114 |
# File 'lib/ViGUI.rb', line 112 def add_hardware hardware @hardware.set_data hardware, @hardware.table_column_model end |
#add_state(state) ⇒ Object
109 110 111 |
# File 'lib/ViGUI.rb', line 109 def add_state state @overview.set_data state, @overview.table_column_model end |
#add_tasks(callback, index, tasks) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ViGUI.rb', line 92 def add_tasks callback, index, tasks col = @tw + 1 row = @h1 + 3 # move to a button list class TODO w = @form..collect { |w| w.class == Button ? w : nil } w.compact.each { |w| @form. w } @tasks.paint tasks.each do |task| b = Button.new @form do col col row row text task end b.command { |form| callback.call index, task } row += 1 end end |
#color_callback(index) ⇒ Object
118 119 120 |
# File 'lib/ViGUI.rb', line 118 def color_callback index @colors[index] || 'grey' end |
#colors=(colors) ⇒ Object
203 204 205 206 |
# File 'lib/ViGUI.rb', line 203 def colors= colors @colors = colors @tree.instance_eval "@repaint_required = true" # XXX end |
#create_events(w) ⇒ Object
148 149 150 151 |
# File 'lib/ViGUI.rb', line 148 def create_events w colnames = DefaultTableColumnModel.new %w[name target canceled status user start] @events.set_data [], colnames end |
#create_hardware(w) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/ViGUI.rb', line 141 def create_hardware w w1 = w / 2 - w / 4 colnames = DefaultTableColumnModel.new %w[device summary] colnames.column(0).width w1 colnames.column(1).width w - w1 - 3 @hardware.set_data [], colnames end |
#create_overview(w) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/ViGUI.rb', line 134 def create_overview w w1 = w / 2 - w / 4 colnames = DefaultTableColumnModel.new %w[key value] colnames.column(0).width w1 colnames.column(1).width w - w1 - 3 @overview.set_data [], colnames end |
#create_status(row, col, h, w) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/ViGUI.rb', line 163 def create_status row, col, h, w @status = Label.new @form do name 'status' row row col col height h display_length w color 'white' bgcolor 'blue' attr 'bold' end end |
#create_vmlist(row, col, h, w) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ViGUI.rb', line 121 def create_vmlist row, col, h, w renderer = VMTreeItemRenderer.new self, self.method(:color_callback), w-2 @tree = Listbox.new @form do name 'vmlist' title 'VMs' row row col col height h width w list_variable Variable.new [] cell_renderer renderer end end |
#create_widget(class_name, name, title, row, col, h, w) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ViGUI.rb', line 152 def class_name, name, title, row, col, h, w class_name.new @form do name name title title row row col col height h width w focusable false end end |
#current_list_index ⇒ Object
175 176 177 178 |
# File 'lib/ViGUI.rb', line 175 def current_list_index @current_list_toprow = @tree.toprow @current_list_index = @tree.current_index end |
#draw_events(events) ⇒ Object
115 116 117 |
# File 'lib/ViGUI.rb', line 115 def draw_events events @events.set_data events, @events.table_column_model end |
#draw_list(list) ⇒ Object
196 197 198 199 200 201 202 |
# File 'lib/ViGUI.rb', line 196 def draw_list list @tree.list_data_model.remove_all list.each { |i| @tree.list_data_model.append i } @tree.current_index = @current_list_index @tree.instance_eval "@toprow = #{@current_list_toprow}" # adapt library XXX refresh end |
#enter_login ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ViGUI.rb', line 36 def enter_login dialog = Form.new nil inputs = ['host','username','password'] inputs.each_with_index do |text,i| Label.new dialog do col 4 row 4 + i*2 text text+":" attr 'reverse' end Field.new dialog do name text col 14 row 4 + i*2 display_length 41 maxlen 99 end end dialog, 'Login Configuration' Hash[*inputs.collect{|i| [i,dialog.by_name[i].getvalue]}.flatten] end |
#get_h_w ⇒ Object
57 58 59 60 61 62 |
# File 'lib/ViGUI.rb', line 57 def get_h_w h = [] w = [] Ncurses.getmaxyx Ncurses.stdscr, h, w return h[0] -2, w[0] end |
#getchar ⇒ Object
187 188 189 |
# File 'lib/ViGUI.rb', line 187 def getchar @window.getchar end |
#handle_key(ch) ⇒ Object
190 191 192 |
# File 'lib/ViGUI.rb', line 190 def handle_key ch @form.handle_key ch end |
#refresh ⇒ Object
193 194 195 |
# File 'lib/ViGUI.rb', line 193 def refresh @form.repaint end |
#select(choices) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ViGUI.rb', line 22 def select choices dialog = Form.new nil list = Listbox.new dialog do row 2 col 3 bgcolor 'white' color 'black' height 8 width 54 list_variable Variable.new choices end dialog, 'Please Select' list.list[list.current_index] end |
#set_status(text) ⇒ Object
183 184 185 186 |
# File 'lib/ViGUI.rb', line 183 def set_status text @status.text = " "+text refresh end |
#setup(focus_callback) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ViGUI.rb', line 70 def setup focus_callback @tw = tw = 40 h, w = get_h_w h1 = (h - 1)/3 h2 = h/4 - 2 h3 = h/4 + 1 h4 = h - h1 - h2 - h3 - 4 @h1 = h1 + h2 create_vmlist 0, 0, h, tw @overview = Table, 'overview', 'Overview', 0, tw, h1, w - tw create_overview w - tw @hardware = Table, 'hardware', 'Hardware', h1 + 1, tw, h2, w - tw create_hardware w - tw @tasks = TextArea, 'tasks', 'Tasks', h1 + h2 + 2, tw, h3, w - tw @events = Table, 'events', 'Events', h1 + h2 + h3 + 3, tw, h4, w - tw create_events w - tw create_status h, tw, 1, w - tw refresh @tree.bind(:ENTER_ROW, focus_callback) do |tree,callback| focus_callback.call tree.current_index end end |
#show_messagebox(dialog, title) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/ViGUI.rb', line 63 def dialog, title h, w = get_h_w MessageBox.new dialog do title title layout 14, 60, h/2 - 7, w/2 - 30 end end |
#unload ⇒ Object
179 180 181 182 |
# File 'lib/ViGUI.rb', line 179 def unload @window.destroy if !@window.nil? VER::stop_ncurses end |