与 Gtk+ 的聊天窗口

发布于 2024-12-27 08:18:11 字数 1824 浏览 1 评论 0原文

我正在使用Gtk+(技术上GtkAda)在Ada中编写某种聊天内容。我对一些Gtk有疑问。我的窗口由 EntryTextViewButton(“发送”)组成。

困难的部分是在处理程序 On_Button_Send_Clicked 中(处理按钮上“单击”信号的过程)。我想读取文本表单 Entry 并将其放入 TextView 中,但是如何访问 TextViewEntry一个只能访问 Button 的过程,因为我以这种方式将信号与处理程序连接起来:

package Handlers is new Gtk.Handlers.Callback
    (Widget_Type => Gtk_Widget_Record);

procedure On_Button_Send_Clicked
    (Object : access Gtk_Widget_Record'Class);
...

Handlers.Connect
   (Button, "clicked", Handlers.To_Marshaller (On_Button_Send_Clicked'access);

我的问题是:是否有像 Get_Gtk_Entry 这样的方法代码> 或Get_Text_View,哪一个是最简单的方法?或者还有其他方法,但仍然简单?

我还遇到了一个解决方案,其中我声明一条记录:

type Widget_Collection_Record is new Glib.Object.GObject_Record with record
    Terminal   : Gtk.GEntry.Gtk_Entry;
    Text_Field : Gtk.Text_View.Gtk_Text_View;
end record;

并以这种方式进行回调:

package Widget_Collection_Cb is new Gtk.Handlers.Callback
    (Widget_Type => Widget_Collection_Record);

procedure On_Button_Send_Clicked
    (Object : access Widget_Collection_Record'Class);

但现在我有另一个问题:如何将来自 Button 的信号与处理程序连接起来,因为小部件 Button 不是我的 Widget_Collection_Record 的一部分?

我不确定我听起来是否清楚......

所以,如果你知道可以解决我的问题的东西,请发帖 - 它可能是 C、C++、Python - 我会尝试将其转换为 Ada ;D

和我的问题摘要是:

如何编写一个处理程序,以便在单击 Button 时从 Entry 读取并在 Text_View 上写入?

编辑:问题已结束。我知道不清楚我的要求,这就是我选择将 User_Data 记录传递给回调的方式...现在我的新问题是 此处

I'm writing some sort of chat in Ada using Gtk+ (technically GtkAda). And I have of problem with some Gtk. My window consists of an Entry, TextView and Button ("Send").

The hard part is in handler On_Button_Send_Clicked (procedure that deals with signal 'clicked' on button). I want to read text form Entry and place it in TextView, but how can I access TextView and Entry from a procedure that has only access to Button, as I connect the signal with a handler in this way:

package Handlers is new Gtk.Handlers.Callback
    (Widget_Type => Gtk_Widget_Record);

procedure On_Button_Send_Clicked
    (Object : access Gtk_Widget_Record'Class);
...

Handlers.Connect
   (Button, "clicked", Handlers.To_Marshaller (On_Button_Send_Clicked'access);

My question is: are there any methods like Get_Gtk_Entry or Get_Text_View, which would be the simples way? Or is there another way, but still simple?

I have also come across a solution in which I declare a record:

type Widget_Collection_Record is new Glib.Object.GObject_Record with record
    Terminal   : Gtk.GEntry.Gtk_Entry;
    Text_Field : Gtk.Text_View.Gtk_Text_View;
end record;

and make the callback this way:

package Widget_Collection_Cb is new Gtk.Handlers.Callback
    (Widget_Type => Widget_Collection_Record);

procedure On_Button_Send_Clicked
    (Object : access Widget_Collection_Record'Class);

But now I have another question: how do I connect a signal from a Button with a handler, since the widget Buttonis not a part of my Widget_Collection_Record?

I'm not sure whether I sound clear...

So please, if you know something that may solve my problem, please post - it could be C, C++, Python - I'll try to convert it to Ada ;D

And the summary of my problem is:

How can I write a handler to read from an Entry and write on a Text_View when a Button clicked?

Edit: Question closed. I'm aware that it's not clear what I asked for, and that's way I've chosen the way to pass record of User_Data to callback... and now my new problem is here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

去了角落 2025-01-03 08:18:11

通常我使用此参考: http:// /www.univ-orleans.fr/sciences/info/ressources/webada/doc/gtkada/gtkada_rm/index.html

您没有提供有关您的组织的太多信息 项目。
但如果你有一个简单的程序来声明所有内容,那么:

procedure foo is
    -- variables
    E : GTk_GEntry;
    T : Gtk_Text_View;
    ...
    procedure On_Button_Send_Clicked (Object : access Gtk_Widget_Record'Class) is
    begin
       S : String := Get_Text (E);
       B : Gtk_Text_Buffer := Get_Buffer (T);
    begin
       Set_Text (B, S);
       ...
    end On_Button_Send_Clicked;
begin
   ...
   Handlers.Connect
      (Button, "clicked", Handlers.To_Marshaller (On_Button_Send_Clicked'access);
   ...
end foo

Usually I use this reference : http://www.univ-orleans.fr/sciences/info/ressources/webada/doc/gtkada/gtkada_rm/index.html

You didn't provide much informations about the organization of your project.
But if you have a simple procedure where you declare everything then :

procedure foo is
    -- variables
    E : GTk_GEntry;
    T : Gtk_Text_View;
    ...
    procedure On_Button_Send_Clicked (Object : access Gtk_Widget_Record'Class) is
    begin
       S : String := Get_Text (E);
       B : Gtk_Text_Buffer := Get_Buffer (T);
    begin
       Set_Text (B, S);
       ...
    end On_Button_Send_Clicked;
begin
   ...
   Handlers.Connect
      (Button, "clicked", Handlers.To_Marshaller (On_Button_Send_Clicked'access);
   ...
end foo
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文