c-在GTK中,如何在允许主循环继续的同时等待按钮被按下



我正在编写一个Z80模拟器,它的GUI运行在GTK上(https://github.com/clancyj4/z80sim/tree/dev对于感兴趣的人(。

我的问题是,我需要捕获IN操作码,并允许编辑一个窗口来提供IO代码。让我向你展示我迄今为止的成果:

/* get a byte (char?) from the input part of the Port window */
/* What we really want to do is have a queue */
BYTE IOPort_IN(int port)
{
char whole_buffer[IOINBUFLEN * 4];            /* 4x in case of Hex */
BYTE c;
int i;
if (IOPort[port] == NULL)                             /* struct exists? */
Create_IOPort_Struct(port);
printf("IOPort_IN: port=%d in_len=%d in_ptr=%dn",
port, IOPort[port]->in_len, IOPort[port]->in_ptr);
if (IOPort[port]->in_len == 0)
{
sprintf(tstr, "Port %d requires input", port);
Add_to_Log(tstr);
show_log(TRUE);
gtk_text_buffer_set_text(inportprompt_textbuffer, "Input Required", -1);
/* somehow keep the gtk main loop running so the interface updates and allows the editing of the ioportin_textbuffer,
but wait for the input submission button the be pressed */
i = gtk_text_buffer_get_char_count(ioportin_textbuffer);
printf("in port buff len is %d.n", i);
}
return(c);
}

操作码的捕获是可以的,并且调用此函数。问题是我不知道如何实现在中间的评论。

目的是保持模拟的其余部分,但GTK主循环仍在运行,因此日志窗口等会更新,我可以在IO窗口中输入字符串。但它会等待,直到按下提交按钮。我可以通过设置一个标志来冻结Z80模拟,所以这没有问题。

我有一种不愉快的感觉,我没有很好地表达这个问题,所以请耐心等待我,并提出任何可以澄清情况的问题。

干杯,

贾斯汀。

我回避了这个问题,并在没有输入队列的情况下强制返回00。当然,还有很多警告。

我仍然想知道如何让GTK在主线程上保持执行,直到激活了一个子窗口。当我知道的时候,我会把答案放在这里。

这个问题有点不清楚。这将为函数设置回调,它将调用您通过它传递的任何函数

void button_connect_callback(GtkWidget *button, void *button_callback)
{
g_signal_connect(button, "clicked", G_CALLBACK(button_callback), NULL);
}

我有一些教程可能会在这里有所帮助

最新更新