2017-01-16 8 views
1

키를 누르면 Genie에서이 위젯을 어떻게 멈출 수 있습니까?Gtk.Spinner를 중지 하시겠습니까?

 
// compila con valac --pkg gtk+-3.0 nombre_archivo.gs 
uses Gtk 
init  
    Gtk.init (ref args) 
    var test = new TestVentana() 
    test.show_all()  
    Gtk.main() 

class TestVentana: Window 

    spinner: Gtk.Spinner  

    init   
     title = "Ejemplo Gtk"  
     default_height = 300 
     default_width = 300 
     border_width = 50  
     window_position = WindowPosition.CENTER  
     destroy.connect(Gtk.main_quit) 

     var spinner = new Gtk.Spinner()   
     spinner.active = true  
     add (spinner) 

     //key_press_event += tecla // OBSOLETO 
     key_press_event.connect(tecla) 

    def tecla(key : Gdk.EventKey):bool  
     //spinner.active = false ??? 
     //spinner.stop()   ??? 
     return true 

편집 :

 
// compila con valac --pkg gtk+-3.0 nombre_archivo.gs 
uses Gtk 
init  
    Gtk.init (ref args) 
    var test = new TestVentana() 
    test.show_all()  
    Gtk.main() 

class TestVentana: Window 

    spinner: Gtk.Spinner   

    init   
     title = "Ejemplo Gtk"  
     default_height = 300 
     default_width = 300 
     border_width = 50  
     window_position = WindowPosition.CENTER  
     destroy.connect(Gtk.main_quit) 

     spinner = new Gtk.Spinner()   
     spinner.active = true  
     add (spinner) 

     // key_press_event += tecla // OBSOLETO 
     key_press_event.connect(tecla) 

    def tecla(key : Gdk.EventKey):bool  
     spinner.active = false  
     return true 

답변

2

당신은 완전히 범위의 개념을 적용하지했습니다 (이 범위의 문제였다) 솔루션을 제공하는 알 토마스에게 감사드립니다. 당신의 생성자에서 라인 :

var spinner = new Gtk.Spinner()

이 생성자의 범위에서, spinner을 새 변수를 만듭니다. var 키워드를 제거하고 작동합니다 : 그것은 이제 클래스의 범위에 선언 된 스피너 변수를 사용합니다

spinner = new Gtk.Spinner()

그래서 당신의 tecla 클래스 메소드에서 사용할 수 있습니다.

또한 변수를 private으로 설정하기 위해 밑줄을 추가 했으므로 클래스의 범위에서만 이 표시되고 클래스를 인스턴스화하는 프로그램 의 부분으로는 표시되지 않습니다.

// compila con valac --pkg gtk+-3.0 nombre_archivo.gs 
[indent=4] 
uses Gtk 

init 
    Gtk.init(ref args) 
    var test = new TestVentana() 
    test.show_all() 
    Gtk.main() 

class TestVentana:Window 

    _spinner: Gtk.Spinner 

    construct() 
     title = "Ejemplo Gtk" 
     default_height = 300 
     default_width = 300 
     border_width = 50 
     window_position = WindowPosition.CENTER 
     destroy.connect(Gtk.main_quit) 

     _spinner = new Gtk.Spinner() 
     _spinner.active = true 
     add(_spinner) 

     key_press_event.connect(tecla) 

    def tecla(key:Gdk.EventKey):bool 
     _spinner.active = false 
     return true 
+0

내 질문을 편집 해 주셔서 감사합니다. – Webierta