我已经在python3和Gtk3中编写了一个脚本,当我点击“关闭”菜单项时我希望它关闭窗口,但是当我这样做时没有任何附加内容。我使用的是Ubuntu 16.10 这是脚本:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class MenuTest(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title='MenuTest')
Box=Gtk.VBox()
self.add(Box)
Menubar=Gtk.MenuBar()
Menu1=Gtk.Menu()
Mfile=Gtk.MenuItem("_File")
Mfile.set_submenu(Menu1)
Clos=Gtk.MenuItem("Close")
Menu1.append(Clos)
Clos.connect('button-press-event', Gtk.main_quit)
Menubar.append(Mfile)
Box.pack_start(Menubar, expand=True, fill=True, padding=0)
Wind=MenuTest()
Wind.connect('delete-event', Gtk.main_quit)
Wind.show_all()
Gtk.main()
我在哪里做错了?
答案 0 :(得分:2)
您需要使用“激活”信号而不是“按钮按事件”。
"button-press-event"
信号来自Gtk.Widget
类Gtk.MenuItem
派生自Gdk.EventMask.BUTTON_PRESS_MASK
。当按下通常来自鼠标的按钮时,会发出此信号。需要为窗口小部件设置事件掩码,以便为此信号接收此信号Gtk.MenuItem
。通常不需要这个信号。
"activate signal"
具有@Service
public class MetricService {
@Autowired
private MetricProcessor processor;
private LinkedBlockingQueue<Metric> queue;
@Scheduled(fixedDelay = 60000)
public void queryExternalService() {
List<Metrics> metrics = new ArrayList<>();
metrics = processor.getMetrics();
//this is horrible and I'm a horrible human being
try {
Thread.sleep(10000); //wait for the requests to come back
}
catch (Exception e) {
e.printStackTrace();
}
queue.addAll(metrics);
}
}
,当项目被激活时会发出@Component
public class MetricProcessor {
@Autowired
private AsyncClient externalClient;
public List<Metrics> getMetrics() {
List<Metrics> returnObj = new Arraylist<>();
for(Blah blah : bleh) {
Request request = new Request("abc");
externalClient.getMetricAsync(request, new AsyncHandler<request, result>() {
@Override
public void onError(Exception e) {
System.out.println("Error");
}
@Override
public void onSuccess(Request request, Result result) {
returnObj.add(new Metric(result.getKey(), result.getValue()));
}
});
}
return returnObj;
}
}
。这可以通过鼠标按钮以及键盘,触摸屏等...