Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Marriage is the only adventure open to the cowardly. -- Voltaire


devel / comp.lang.ada / GtkAda's "On_Edited"

SubjectAuthor
* GtkAda's "On_Edited"John Perry
`* Re: GtkAda's "On_Edited"Dmitry A. Kazakov
 `* Re: GtkAda's "On_Edited"John Perry
  `* Re: GtkAda's "On_Edited"Dmitry A. Kazakov
   `- Re: GtkAda's "On_Edited"John Perry

1
GtkAda's "On_Edited"

<fa06c2df-0b2b-4ddc-9534-b025df4d3f76n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6954&group=comp.lang.ada#6954

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:5744:0:b0:2f3:d85a:a518 with SMTP id 4-20020ac85744000000b002f3d85aa518mr41857281qtx.465.1653888521863;
Sun, 29 May 2022 22:28:41 -0700 (PDT)
X-Received: by 2002:a81:7c45:0:b0:300:2f8c:7cf2 with SMTP id
x66-20020a817c45000000b003002f8c7cf2mr29278012ywc.255.1653888521705; Sun, 29
May 2022 22:28:41 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Sun, 29 May 2022 22:28:41 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=2601:3c3:400:b30:5bbb:11d1:c956:9424;
posting-account=JSxOkAoAAADa00TJoz2WZ_46XrZCdXeS
NNTP-Posting-Host: 2601:3c3:400:b30:5bbb:11d1:c956:9424
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fa06c2df-0b2b-4ddc-9534-b025df4d3f76n@googlegroups.com>
Subject: GtkAda's "On_Edited"
From: devo...@yahoo.com (John Perry)
Injection-Date: Mon, 30 May 2022 05:28:41 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2893
 by: John Perry - Mon, 30 May 2022 05:28 UTC

I'm trying to edit a cell in a Tree_View with a List_Store, and saw in GtkAda's User Guide that it offers the On_Edited procedure. I set up a callback this way with the following procedure:

procedure Editing_Done
( Self : access Gtk_Cell_Renderer_Text_Record'Class;
Path : Glib.UTF8_String; -- this is the row
New_Text : Glib.UTF8_String
) is
begin
Tio.Put_Line( Get_Property(Self, Gtk.Cell_Renderer_Text.Text_Property)'Image ); -- line 1
Tio.Put_Line(Path'Image); -- line 2
Tio.Put_Line(New_Text'Image); -- line 3
Set_Property(Self, Gtk.Cell_Renderer_Text.Text_Property, New_Text);
Self.Stop_Editing( False );
Tio.Put_Line( Get_Property(Self, Gtk.Cell_Renderer_Text.Text_Property)'Image ); -- line 4
end Editing_Done;

I didn't really expect this to work, and it doesn't, but here's what I have verified it does do, in order:

* prints the data that was in the cell before editing (line 1)
* prints the row that was edited (line 2)
* prints the new text (line 3)
* prints the data that is in the cell as the procedure ends (line 4)

Lines 3 and 4 agree, which is great! But what I see in the TreeView is that the cell reverts after editing to the value in Line 1.

My questions:

1) The documentation of On_Edited states that I am supposed to "update the model and store New_Text at the position indicated by Path." How do I get the model? I understand that "Path" indicates the row in the List_Store / TreeView, but Get_Model's Signature requires a TreeView, which I do not have.

2) What else might I be missing from a correct implementation of the On_Edited callback?

thanks in advance
john perry

Re: GtkAda's "On_Edited"

<t71p94$obr$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6955&group=comp.lang.ada#6955

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!sk0Beg7Zrzno4hcHZ70Y5A.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: GtkAda's "On_Edited"
Date: Mon, 30 May 2022 08:47:01 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t71p94$obr$1@gioia.aioe.org>
References: <fa06c2df-0b2b-4ddc-9534-b025df4d3f76n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="24955"; posting-host="sk0Beg7Zrzno4hcHZ70Y5A.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Mon, 30 May 2022 06:47 UTC

On 2022-05-30 07:28, John Perry wrote:
> I'm trying to edit a cell in a Tree_View with a List_Store, and saw in GtkAda's User Guide that it offers the On_Edited procedure. I set up a callback this way with the following procedure:
>
> procedure Editing_Done
> ( Self : access Gtk_Cell_Renderer_Text_Record'Class;
> Path : Glib.UTF8_String; -- this is the row
> New_Text : Glib.UTF8_String
> ) is
> begin
> Tio.Put_Line( Get_Property(Self, Gtk.Cell_Renderer_Text.Text_Property)'Image ); -- line 1
> Tio.Put_Line(Path'Image); -- line 2
> Tio.Put_Line(New_Text'Image); -- line 3
> Set_Property(Self, Gtk.Cell_Renderer_Text.Text_Property, New_Text);
> Self.Stop_Editing( False );
> Tio.Put_Line( Get_Property(Self, Gtk.Cell_Renderer_Text.Text_Property)'Image ); -- line 4
> end Editing_Done;
>
> I didn't really expect this to work, and it doesn't, but here's what I have verified it does do, in order:
>
> * prints the data that was in the cell before editing (line 1)
> * prints the row that was edited (line 2)
> * prints the new text (line 3)
> * prints the data that is in the cell as the procedure ends (line 4)
>
> Lines 3 and 4 agree, which is great! But what I see in the TreeView is that the cell reverts after editing to the value in Line 1.
>
> My questions:
>
> 1) The documentation of On_Edited states that I am supposed to "update the model and store New_Text at the position indicated by Path." How do I get the model? I understand that "Path" indicates the row in the List_Store / TreeView, but Get_Model's Signature requires a TreeView, which I do not have.

On_* procedures are useless most of the time. Instead, you have to
instantiate Gtk.Handlers.User_Callback with a parameter indicating the
widget:

package Edited_Handlers is
new Gtk.Handlers.User_Callback
( Gtk_Cell_Renderer_Text_Record,
My_Widget_Where_The_Tree_View_Lives_Ptr
);

The parameter could be Tree_Vuew as well, but having a widget is always
a better design.

Usually you derive your widget from some container like Gtk_Grid. The
extension holds children and anything else you would need. E.g.:

type My_Widget_Where_The_Tree_View_Lives is new Gtk_Grid_Record with
View : Gtk_Tree_View;
Store : Gtk_List_Store;
Fancy_Button : Gtk_Button;
...
end record;

Define Gtk_New and override Initialize. In the Initialize after you
called Gtk_Grid's Initialize you create all children and connect to the
signal "editing-done" to the renderer:

procedure Editing_Done
( Self : access Gtk_Cell_Renderer_Text_Record'Class;
Path : UTF8_String;
New_Text : UTF8_String;
Widget : My_Widget_Where_The_Tree_View_Lives_Ptr
)

Now when it is called you have the tree View and the list store (= the
model) in the callback. Use Get_Iter_From_String in order to get the
iterator from Path. Change the store at the iterator if you accept the
edit. That's all.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: GtkAda's "On_Edited"

<ea3ce162-277d-487a-af19-8126892d2ef9n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6956&group=comp.lang.ada#6956

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:d87:b0:67b:311c:ecbd with SMTP id q7-20020a05620a0d8700b0067b311cecbdmr36576148qkl.146.1653896799970;
Mon, 30 May 2022 00:46:39 -0700 (PDT)
X-Received: by 2002:a25:33c6:0:b0:648:b8a1:a30e with SMTP id
z189-20020a2533c6000000b00648b8a1a30emr52480073ybz.44.1653896799787; Mon, 30
May 2022 00:46:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Mon, 30 May 2022 00:46:39 -0700 (PDT)
In-Reply-To: <t71p94$obr$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:3c3:400:b30:5bbb:11d1:c956:9424;
posting-account=JSxOkAoAAADa00TJoz2WZ_46XrZCdXeS
NNTP-Posting-Host: 2601:3c3:400:b30:5bbb:11d1:c956:9424
References: <fa06c2df-0b2b-4ddc-9534-b025df4d3f76n@googlegroups.com> <t71p94$obr$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ea3ce162-277d-487a-af19-8126892d2ef9n@googlegroups.com>
Subject: Re: GtkAda's "On_Edited"
From: devo...@yahoo.com (John Perry)
Injection-Date: Mon, 30 May 2022 07:46:39 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2234
 by: John Perry - Mon, 30 May 2022 07:46 UTC

> On_* procedures are useless most of the time.

I guess you mean in GtkAda? I've found them invaluable in other contexts. If so, that's disappointing. To be fair, in the hours of reading on this I did notice that Gtk+ itself makes this difficult; the On_* procedures seem to be a GtkAda enhancement.

In the end I made it work with an On_* design, but it was your suggestion that helped! I used the second form of On_Edited and passed a TreeView in the slot. To get the model:

Tree_View: Gtk_Tree_View := Gtk_Tree_View(Self);
Model: Gtk_Tree_Model := Get_Model( Tree_View );
Iter : Gtk_Tree_Iter := Get_Iter_From_String(Model, Path);
Store: Gtk_List_Store := Gtk_List_Store( To_Object(Model) );

Getting the rest wasn't too hard after I had that. What I hadn't understood at first was that the Model had to be converted from the Interface via the To_Object function.

Thank you very much, and also for the quick answer!

john perry

PS If anyone knows how to make the first form of On_Edited work, I'd be delighted to know.

Re: GtkAda's "On_Edited"

<t7342i$1set$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6957&group=comp.lang.ada#6957

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!sk0Beg7Zrzno4hcHZ70Y5A.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: GtkAda's "On_Edited"
Date: Mon, 30 May 2022 20:57:23 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t7342i$1set$1@gioia.aioe.org>
References: <fa06c2df-0b2b-4ddc-9534-b025df4d3f76n@googlegroups.com>
<t71p94$obr$1@gioia.aioe.org>
<ea3ce162-277d-487a-af19-8126892d2ef9n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="61917"; posting-host="sk0Beg7Zrzno4hcHZ70Y5A.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Mon, 30 May 2022 18:57 UTC

On 2022-05-30 09:46, John Perry wrote:
>> On_* procedures are useless most of the time.
>
> I guess you mean in GtkAda?

Yes.

> I've found them invaluable in other contexts. If so, that's disappointing. To be fair, in the hours of reading on this I did notice that Gtk+ itself makes this difficult; the On_* procedures seem to be a GtkAda enhancement.

Yes, GtkAda adds a typed layer on top of untyped GTK signals.

> In the end I made it work with an On_* design, but it was your suggestion that helped! I used the second form of On_Edited and passed a TreeView in the slot. To get the model:
>
> Tree_View: Gtk_Tree_View := Gtk_Tree_View(Self);
> Model: Gtk_Tree_Model := Get_Model( Tree_View );
> Iter : Gtk_Tree_Iter := Get_Iter_From_String(Model, Path);
> Store: Gtk_List_Store := Gtk_List_Store( To_Object(Model) );
>
> Getting the rest wasn't too hard after I had that. What I hadn't understood at first was that the Model had to be converted from the Interface via the To_Object function.

If that is OK to you, but in production code you need a lot of stuff to
do in a handler, most of it is unrelated to the tree view. This is why a
custom widget is always advisable. Using a slot is a matter of taste/ I
never use slots and avoid run-time type conversions.

BTW, derived widgets is also a GtkAda feature, in GTK a derived widget
require a lot of work. In GtkAda they are trivial.

Typically in a renderer edit commit you would maintain undo/redo
buffers, change the active cell for smooth navigation, [un]gray/hide a
couple of buttons (like Save). Same goes with the buttons and basically
with all signals.

The design pattern you need to keep in mind is that a signal sent to a
visual element like renderer or button, logically, is rather sent to
some container widget a couple layers above. If you do not follow this
logic, you will have a very complicated fragile code.

> PS If anyone knows how to make the first form of On_Edited work, I'd be delighted to know.

The first form can be used with a static layout and global variables. (:-))

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: GtkAda's "On_Edited"

<409bb984-2e7f-45e6-a5c1-7b637bec2c22n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6964&group=comp.lang.ada#6964

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ad4:4bcb:0:b0:464:692c:6985 with SMTP id l11-20020ad44bcb000000b00464692c6985mr2758359qvw.48.1654053509640;
Tue, 31 May 2022 20:18:29 -0700 (PDT)
X-Received: by 2002:a81:70f:0:b0:2fb:79b3:27a8 with SMTP id
15-20020a81070f000000b002fb79b327a8mr67664636ywh.335.1654053509506; Tue, 31
May 2022 20:18:29 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Tue, 31 May 2022 20:18:29 -0700 (PDT)
In-Reply-To: <t7342i$1set$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=73.121.127.66; posting-account=JSxOkAoAAADa00TJoz2WZ_46XrZCdXeS
NNTP-Posting-Host: 73.121.127.66
References: <fa06c2df-0b2b-4ddc-9534-b025df4d3f76n@googlegroups.com>
<t71p94$obr$1@gioia.aioe.org> <ea3ce162-277d-487a-af19-8126892d2ef9n@googlegroups.com>
<t7342i$1set$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <409bb984-2e7f-45e6-a5c1-7b637bec2c22n@googlegroups.com>
Subject: Re: GtkAda's "On_Edited"
From: devo...@yahoo.com (John Perry)
Injection-Date: Wed, 01 Jun 2022 03:18:29 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2072
 by: John Perry - Wed, 1 Jun 2022 03:18 UTC

On Monday, May 30, 2022 at 1:57:30 PM UTC-5, Dmitry A. Kazakov wrote:
> > In the end I made it work with an On_* design...
> If that is OK to you, but in production code you need a lot of stuff to
> do in a handler, most of it is unrelated to the tree view.

I agree with what you write, and learned a bit. I've never been in a situation where I had to implement a TreeView-like object before, so I never had to think about it much. I probably won't pursue it since the project I'm working on is a small, personal project with corresponding amounts of time available.

> BTW, derived widgets is also a GtkAda feature, in GTK a derived widget
> require a lot of work. In GtkAda they are trivial.

Interesting! I'll probably look into this more at some future point.

thanks again
john perry

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor