Re: Unparenting from GtkWidget "destroy"

Baldvin Kovacs via gtkmm-list <[email protected]> Mon, 1 Aug 2022 18:01:54 +0200
Newsgroups gmane.comp.gnome.gtkmm
Message-ID <CAAw7jaiGznoEQmsG4Jkq4vQ7kUWWxOZu-3h=BWO-bbf9Oq4xow@mail.gmail.com>
--===============8732005799058885121==
Content-Type: multipart/alternative; boundary="0000000000000d978f05e5301f7b"

--0000000000000d978f05e5301f7b
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Kjell Ahlstedt <[email protected]> ezt =C3=ADrta (id=C5=91pont: 2022.=
 aug. 1.,
H, 11:05):

> Den 2022-07-31 kl. 00:37, skrev Baldvin Kovacs:
>
> I took a stab at it, PTAL. Another option is to not do this, but document
> in both the howtos, and the documentation
> of Gtk::Widget that container-like custom widgets are not supported.
>
> Thx,
> Baldvin
>
>
> I have updated the custom container example in the gtkmm tutorial,
> https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/tree/master/examples=
/book/custom/custom_container.
> Now it's more like a simplified vertical Box. It works well, except if it=
's
> a managed widget. I've noted this restriction in a comment in the source
> code. If you think it's too complicated the explain how to use a
> signal_destroy(), we can leave it at that for the moment.
>
Hello,

I took a look at your CL, and indeed it is making it clearer. However, it
wouldn't have helped me to avoid spending the few days on this question,
and here's why: When I was trying to learn how to use gtkmm, I was
primarily interested in learning how to write clean, idiomatic code,
preparing on a long journey. One of the questions in my mind were: shall I
prefer inheritance, or composition? When I was a kid, it was all about
inheritance, but basically every language (e.g. Go) that appeared in the
last decade strongly prefers composition. And then I find that Gtk was
recently refactored in a "prefer composition over inheritance" manner.
Therefore, just reading the comment in the example "this cannot be used as
managed" wouldn't have stopped me trying to figure out --- maybe it's just
the example that tries to be too simple? And I would have engaged in the
exact same deep dive, learning all the deep details of the Gtk destroy
sequence over a few days. Just because when I'm in "let's learn the new
thing" mode, then I need to get the answers to these fundamental questions.

I think that I would have stopped and accepted to use the inheritance
pattern only if:

1.
https://developer-old.gnome.org/gtkmm-tutorial/stable/chapter-customwidgets=
.html.en
says it explicitly, that gtkmm does not allow a composition pattern in
managed mode, and that's why there's no such example
2. the comment in the example says what you say there now, extended with
something along the lines of: "and it's not possible, don't even try".

I think the comment for the destroy signal is not bad (
https://gitlab.gnome.org/GNOME/gtkmm/-/merge_requests/71/diffs). It is
something that gives people hints and points them to the right direction.

I'm not super happy with it though. Trusting users to unparent from both
places without the framework enforcing or at least verifying it is
problematic. However, arguably, the current mechanism is problematic,
because it says nowhere that managed mode doesn't work in all cases, and
the only way to learn about this is from the _extremely_ cryptic error
message that have sent me to the bushes.

=C2=AF\_(=E3=83=84)_/=C2=AF

Please read the phrasing I have at
https://gitlab.gnome.org/GNOME/gtkmm/-/merge_requests/71/diffs , and make a
decision. I'm happy with both ways.

Baldvin












> Kjell
>

--0000000000000d978f05e5301f7b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"></div><br><div class=3D"gmail_quote"><div=
 dir=3D"ltr" class=3D"gmail_attr">Kjell Ahlstedt &lt;<a href=3D"mailto:kjel=
[email protected]">[email protected]</a>&gt; ezt =C3=ADrta (id=C5=
=91pont: 2022. aug. 1., H, 11:05):<br></div><blockquote class=3D"gmail_quot=
e" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204)=
;padding-left:1ex">
 =20
   =20
 =20
  <div>
    <div>Den 2022-07-31 kl. 00:37, skrev Baldvin
      Kovacs:<br>
    </div>
    <blockquote type=3D"cite">
     =20
      <div dir=3D"ltr">I took a stab at it, PTAL. Another option is to not
        do this, but document in both the howtos, and the documentation
        <div class=3D"gmail_quote">
          <div>of Gtk::Widget that container-like custom widgets are not
            supported.</div>
          <div><br>
          </div>
          <div>Thx,</div>
          <div>Baldvin</div>
          <div><br>
          </div>
          <br>
        </div>
      </div>
    </blockquote>
    <p>I have updated the custom container example in the gtkmm
      tutorial,
<a href=3D"https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/tree/master=
/examples/book/custom/custom_container" target=3D"_blank">https://gitlab.gn=
ome.org/GNOME/gtkmm-documentation/-/tree/master/examples/book/custom/custom=
_container</a>.
      Now it&#39;s more like a simplified vertical Box. It works well,
      except if it&#39;s a managed widget. I&#39;ve noted this restriction =
in a
      comment in the source code. If you think it&#39;s too complicated the
      explain how to use a signal_destroy(), we can leave it at that for
      the moment.</p></div></blockquote><div>Hello,</div><div><br></div><di=
v>I took a look at your CL, and indeed it is making it clearer. However, it=
 wouldn&#39;t have helped me to avoid spending the few days on this questio=
n, and here&#39;s why: When I was trying to learn how to use gtkmm, I was p=
rimarily interested in learning how to write clean, idiomatic code, prepari=
ng on a long journey. One of the questions in my mind were: shall I prefer =
inheritance, or composition? When I was a kid, it was all about inheritance=
, but basically every language (e.g. Go) that appeared in the last decade s=
trongly prefers composition. And then I find that Gtk was recently refactor=
ed in a &quot;prefer composition over inheritance&quot; manner. Therefore, =
just reading the comment in the example &quot;this cannot be used as manage=
d&quot; wouldn&#39;t have stopped me trying to figure out --- maybe it&#39;=
s just the example that tries to be too simple? And I would have engaged in=
 the exact same deep dive, learning all the deep details of the Gtk destroy=
 sequence over a few days. Just because when I&#39;m in &quot;let&#39;s lea=
rn the new thing&quot; mode, then I need to get the answers to these fundam=
ental questions.</div><div><br></div><div>I think that I would have stopped=
 and accepted to use the inheritance pattern only if:</div><div><br></div><=
div>1.=C2=A0<a href=3D"https://developer-old.gnome.org/gtkmm-tutorial/stabl=
e/chapter-customwidgets.html.en">https://developer-old.gnome.org/gtkmm-tuto=
rial/stable/chapter-customwidgets.html.en</a> says it explicitly, that gtkm=
m does not allow a composition pattern in managed mode, and that&#39;s why =
there&#39;s no such example</div><div>2. the comment in the example says wh=
at you say there now, extended with something along the=C2=A0lines of: &quo=
t;and it&#39;s not possible, don&#39;t even try&quot;.</div><div><br></div>=
<div>I think the comment for the destroy signal is not bad (<a href=3D"http=
s://gitlab.gnome.org/GNOME/gtkmm/-/merge_requests/71/diffs">https://gitlab.=
gnome.org/GNOME/gtkmm/-/merge_requests/71/diffs</a>). It is something that =
gives people hints and points them to the right direction.</div><div><br></=
div><div>I&#39;m not super happy with it though. Trusting users to unparent=
 from both places without the framework enforcing or at least verifying it =
is problematic. However, arguably, the current mechanism is problematic, be=
cause it says nowhere that managed mode doesn&#39;t work in all cases, and =
the only way to learn about this is from the _extremely_ cryptic error mess=
age that have sent me to the bushes.</div><div><br></div><div>=C2=AF\_(=E3=
=83=84)_/=C2=AF<br></div><div><br></div><div>Please read the phrasing I hav=
e at=C2=A0<a href=3D"https://gitlab.gnome.org/GNOME/gtkmm/-/merge_requests/=
71/diffs">https://gitlab.gnome.org/GNOME/gtkmm/-/merge_requests/71/diffs</a=
> , and make a decision. I&#39;m happy with both ways.</div><div><br></div>=
<div>Baldvin</div><div><br></div><div><br></div><div><br></div><div><br></d=
iv><div><br></div><div><br></div><div><br></div><div><br></div><div><br></d=
iv><div><br></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex"><div>
    <p>Kjell<br>
    </p>
  </div>

</blockquote></div></div>

--0000000000000d978f05e5301f7b--

--===============8732005799058885121==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
gtkmm-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gtkmm-list

--===============8732005799058885121==--