Class: Neuro::Display::MainWindow

Inherits:
Window
  • Object
show all
Defined in:
lib/neuro/display.rb

Overview

Main Window

Instance Method Summary collapse

Constructor Details

#initialize(max_height, network) ⇒ MainWindow

Returns a new instance of MainWindow.



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/neuro/display.rb', line 248

def initialize(max_height, network)
  super()
  @max_height = max_height
  @network = network

  # Actions
  signal_connect(:destroy) { quit }

  # Main Window
  set_border_width(0)
  @base_box = VBox.new(false, 0)
  add @base_box

  draw_network
  realize
  window.set_background(Gdk::Color.new(0, 0, 0))
end

Instance Method Details

#draw_network(input = [ 0.0 ] * @network.input_size, output = [ 0.0 ] * @network.output_size) ⇒ Object



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/neuro/display.rb', line 266

def draw_network( input = [ 0.0 ] * @network.input_size,
                  output = [ 0.0 ] * @network.output_size)
  canvas = Gnome::Canvas.new(true)
  canvas.freeze_notify

  root = Gnome::CanvasGroup.new(canvas.root, :x => 1, :y => 1)
  nd = NetworkDrawer.new(root, @network)
  nd.draw(input, output)
  canvas.set_scroll_region(0, 0, nd.width, nd.height)

  default_size = [
    nd.width,
    nd.height > @max_height ? @max_height : nd.height
  ]
  set_default_size(*default_size)

  background = Gnome::CanvasRect.new(
    canvas.root, :x1 => 0, :y1 => 0,
    :x2 => nd.width, :y2 => nd.height,
    :fill_color => "white",
    :outline_color => "gray",
    :width_pixels => 4.0
  )
  background.lower_to_bottom
  canvas.thaw_notify

  if @scrolled_window
    @base_box.remove(@scrolled_window) 
    @scrolled_window.destroy
  end
  @scrolled_window = ScrolledWindow.new
  @scrolled_window.add(canvas)
  @scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS)

  @base_box.pack_end(@scrolled_window, true, true, 0)
  @scrolled_window.show_all
end

#quitObject



304
305
306
# File 'lib/neuro/display.rb', line 304

def quit
  Gtk.main_quit
end