与Gtk +聊天的窗口 [英] Chat window with Gtk+

查看:127
本文介绍了与Gtk +聊天的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Gtk + (在技术上是 GtkAda )在 Ada 中进行某种形式的聊天。我有一些 Gtk 问题。我的窗口包含一个条目 TextView Button ( 发送)。

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").

最困难的部分是处理程序 On_Button_Send_Clicked (处理按钮上被点击信号的过程)。我想阅读文本形式的 Entry 并将其放在 TextView 中,但是如何访问我只能连接到只能访问 Button 的过程中的TextView 条目

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);

我的问题是:是否有 Get_Gtk_Entry Get_Text_View ,这是最简单的方法吗?还是还有另一种方法,但是仍然很简单?

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);

但是我现在另一个问题:由于小部件 Button 不是一个控件,我该如何连接 Button 和处理程序的信号? Widget_Collection_Record 的一部分?

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...

所以请,如果您知道一些可以解决我问题的信息,请发布-可能是C,C ++,Python-我将尝试将其转换为Ada; D

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

我如何编写处理程序以从读取项并单击按钮并在 Text_View 上写?

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

修改:问题已结束。我知道我不清楚我要的是什么,这就是我选择了将 User_Data 的记录传递给回调的方法……这是我的新问题是此处

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

推荐答案

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

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

这篇关于与Gtk +聊天的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆