単純なツールボタンを作成するときに、Toolbar example from the Vala guideのようにclicked.connectインターフェイスを使用できます。ボタンをHeaderBarに追加するインターフェイスは、その例に示されているものと似ています。しかし、クリックされた接続を処理する方法は異なるようです(または、私が紛失しているものがあります)。ToolButtonクリック信号(HeaderBar内)の使用方法は?
次の例は、開いているダイアログボタンがヘッダーバーにパックされている小さなテキストエディタの例です。ただし、clicked.connection構文はエラーを返します。コンパイル時に
[indent=4]
uses
Gtk
init
Gtk.init (ref args)
var app = new Application()
app.show_all()
Gtk.main()
// This class holds all the elements from the GUI
class Application : Gtk.Window
_view:Gtk.TextView
construct()
// Prepare Gtk.Window:
this.window_position = Gtk.WindowPosition.CENTER
this.destroy.connect (Gtk.main_quit)
this.set_default_size (400, 400)
// Headerbar definition
headerbar:Gtk.HeaderBar = new Gtk.HeaderBar()
headerbar.show_close_button = true
headerbar.set_title("My text editor")
// Headerbar buttons
open_button:Gtk.ToolButton = new ToolButton.from_stock(Stock.OPEN)
open_button.clicked.connect (openfile)
// Add everything to the toolbar
headerbar.pack_start (open_button)
show_all()
this.set_titlebar(headerbar)
// Box:
box:Gtk.Box = new Gtk.Box (Gtk.Orientation.VERTICAL, 1)
this.add (box)
// A ScrolledWindow:
scrolled:Gtk.ScrolledWindow = new Gtk.ScrolledWindow (null, null)
box.pack_start (scrolled, true, true, 0)
// The TextView:
_view = new Gtk.TextView()
_view.set_wrap_mode (Gtk.WrapMode.WORD)
_view.buffer.text = "Lorem Ipsum"
scrolled.add (_view)
open_button.clicked.connectリターン:ここ
はコードであるtext_editor-exercise_7_1.gs:134.32-134.39: error: Argument 1: Cannot convert from `Application.openfile' to `Gtk.ToolButton.clicked'
open_button.clicked.connect (openfile)
ないものがHeaderBarウィジェットを使用している場合、その信号の変化を処理する方法はありますか?
コードは、行がコメントされている限り機能しています(openfile関数のスタブを追加することができます)。エラーは、私が上記の添付ボディに実際になかったので
おかげ
UPDATE
この質問は、更新に値します。
エラーは関数の定義にありました。私が書いた:
def openfile (self:Button)
私が代わりにきたはずです時:単に
def openfile (self:ToolButton)
または:あなたは、あなたのコード内のクリックハンドラが含まれていませんでした
def openfile()