我如何知道用户点击了Gtk笔记本的哪个页面?

我如何知道用户点击了Gtk笔记本的哪个页面?,gtk,vala,popupmenu,pagecontrol,Gtk,Vala,Popupmenu,Pagecontrol,我有一个Gtk.Notebook,它有一个自定义的弹出菜单,当用户右键单击任何页面按钮时显示 我如何知道用户单击了哪个笔记本页面?我想在菜单中添加一个操作,使其成为当前页面 notebook.button_press_event.connect( (wid,evt) => { if ( evt.button==3 ) { // which page button did the user click on? notebook.set_current_

我有一个Gtk.Notebook,它有一个自定义的弹出菜单,当用户右键单击任何页面按钮时显示

我如何知道用户单击了哪个笔记本页面?我想在菜单中添加一个操作,使其成为当前页面

notebook.button_press_event.connect( (wid,evt) => {
    if ( evt.button==3 ) {
        // which page button did the user click on?
        notebook.set_current_page( «clicked no tab» );
        // ... make it the current page
    }
}
我尝试按位置查找选项卡:

int numtab = notebook.get_tab_at_pos((int)evt.x, (int)evt.y);

但似乎没有“在位置获取选项卡”或类似的方法。

一种解决方案可能是使用Gtk.EventBox PHP代码:

$window = new GtkWindow();
$window->set_size_request(400, 240);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());

// setup notebook
$notebook = new GtkNotebook(); // note 1
$vbox->pack_start($notebook);

// add two tabs of GtkLabel
add_new_tab($notebook, new GtkLabel('Notebook 1'), 'Label #1');
add_new_tab($notebook, new GtkLabel('Notebook 2'), 'Label #2');

// add a thrid tab of GtkTextView
$buffer = new GtkTextBuffer();
$view = new GtkTextView();
$view->set_buffer($buffer);
$view->set_wrap_mode(Gtk::WRAP_WORD);
add_new_tab($notebook, $view, 'TextView');

$window->show_all();
Gtk::main();

// add new tab
function add_new_tab($notebook, $widget, $tab_label) {
    $eventbox = new GtkEventBox();
    $label = new GtkLabel($tab_label);
    $eventbox->add($label); // note 2
    $label->show(); // note 3
    $eventbox->connect('button-press-event', 'on_tab', $tab_label); // note 4
    $notebook->append_page($widget, $eventbox); // note 5
}

// function that is called when user click on tab
function on_tab($widget, $event, $tab_label) {  // note 6
    echo "tab clicked = $tab_label\n";
}

那么,当用户右键单击选项卡时,您想调用gtk_notebook_set_current_页面?这就是鼠标左键通常使用的功能,为什么还要使用鼠标右键呢?因为我显示了一个菜单,可以在此选项卡上执行操作,而鼠标左键对其他操作很有用,感谢您的干预鼠标左键:切换选项卡例如,我仍然不确定我是否正确理解了您要执行的操作。你应该添加一个完整的代码示例和/或更长的描述,说明你正在尝试做什么,以及你遇到的问题是什么。英语对我来说很难,但我想选择我右键单击的选项卡,将其转到当前页面。这都是在试图理解、适应,我告诉你也许不会马上谢谢你,它工作得很完美。这有点复杂,标签的标题=图片+标签,在标签中循环找到正确的标签。再次感谢。