Source

miuler-blacknote / src / main / scala / com / miuler / blacknote / BackNote.scala

Full commit
package com.miuler.blacknote

import org.gnome.gtk.Window
import org.gnome.gtk.Gtk
import org.gnome.gtk.Widget
import org.gnome.gtk.Window.DeleteEvent
import org.gnome.gdk.Event

import Events.newMethodEventsToWindow
import org.gnome.gtk.Button

class WindowConnect(window: Window) {

  def connect2 (eventType: AnyRef, function: (Widget, Event)=>Boolean) {
    
    val deleteEvent = classOf[Window.DeleteEvent]
    
    eventType match {
      case deleteEvent => {
        window.connect(new Window.DeleteEvent() {
          def onDeleteEvent(source: Widget, event: Event) = function(source, event)
        })
      }
    }

  }
}

object Events {
  implicit def newMethodEventsToWindow(window: Window) : WindowConnect = new WindowConnect(window)
}




object BackNote {

  def main(args: Array[String]) {
    val prueba = new Prueba1
    prueba.init(args)
  }

}


class Prueba1 {
  
  val self = this
  var window:Window = null

  def init(args: Array[String]) {
    Gtk init (args)
    initWindow ()
    Gtk main ()
  }
  
  def initWindow() {
    window = new Window()
    
    val button = new Button("clickeame")
    window.add(button)

    window.connect2(classOf[Window.DeleteEvent], onDeleteEvent)
    window showAll ()
  }
  
  def onDeleteEvent (source: Widget, event: Event) = {
    println("Saliendo")
    Gtk.mainQuit
    false
  }
  
}