Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gtkf-sketcher.f90: important features are still missing in the GTK 4 version #207

Open
vmagnin opened this issue Jun 19, 2020 · 7 comments
Assignees
Labels
GTK 4 GTK 4 only

Comments

@vmagnin
Copy link
Owner

vmagnin commented Jun 19, 2020

[ 87%] Building Fortran object sketcher/CMakeFiles/gtkf-sketcher.dir/gtkf-sketcher.f90.o
/home/osboxes/gtk-fortran/sketcher/gtkf-sketcher.f90:151:43:

  151 |   use gtk, only: gtk_builder_add_from_file, gtk_builder_connect_signals, gtk_buil&
      |                                           1
Error: Symbol ‘gtk_builder_connect_signals’ referenced at (1) not found in module ‘gtk’
/home/osboxes/gtk-fortran/sketcher/gtkf-sketcher.f90:153:75:

  153 |   &FALSE, c_null_char, c_null_ptr, TRUE, gtk_init, gtk_builder_get_objects, gtk_builder_connect_signals_full,&
      |                                                                           1
Error: Symbol ‘gtk_builder_connect_signals_full’ referenced at (1) not found in module ‘gtk’
/home/osboxes/gtk-fortran/sketcher/gtkf-sketcher.f90:157:76:

  157 |   gtk_toggle_button_get_active, gtk_toggle_button_set_active,GTK_BUTTONS_OK,&
      |                                                                            1
Error: Symbol ‘gtk_widget_is_toplevel’ referenced at (1) not found in module ‘gtk’
/home/osboxes/gtk-fortran/sketcher/gtkf-sketcher.f90:158:96:

  158 |   gtk_widget_is_toplevel, gtk_list_store_append, gtk_list_store_set_value, gtk_list_store_clear,&
      |                                                                                                1
Error: Symbol ‘gtk_dialog_run’ referenced at (1) not found in module ‘gtk’
/home/osboxes/gtk-fortran/sketcher/gtkf-sketcher.f90:231:7:

  231 |   use connect
      |       1
Fatal Error: Cannot open module file ‘connect.mod’ for reading at (1): No such file or directory
compilation terminated.

Concerning GtkBuilder see: #178

The *.glade will also need to be ported (deprecated properties, widgets...). There is a tool to help: #188

Concerning gtk_dialog_run see: 07771a8#diff-97fecfaa97d43167048d8b722f36eb71

https://developer.gnome.org/gtk4/unstable/ch40s02.html#id-1.7.4.4.62

gtk_widget_is_toplevel has been removed
gtk_widget_is_toplevel() has been removed. Use GTK_IS_ROOT, GTK_IS_NATIVE or GTK_IS_WINDOW instead, as appropriate.

See also the hl_gtk_file_chooser_show issue: #202

@vmagnin vmagnin added the GTK 4 GTK 4 only label Jun 19, 2020
@vmagnin
Copy link
Owner Author

vmagnin commented Jun 20, 2020

https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-is-toplevel

gtk_widget_is_toplevel ()
gboolean
gtk_widget_is_toplevel (GtkWidget *widget);
Determines whether widget is a toplevel widget.
Currently only GtkWindow and GtkInvisible (and out-of-process GtkPlugs) are toplevel widgets. Toplevel widgets have no parent widget.

@vmagnin
Copy link
Owner Author

vmagnin commented Jun 22, 2020

I have commented:

  • lines with gtk_builder_connect_signals and gtk_builder_connect_signals_full
  • ! if (fbool(gtk_widget_is_toplevel(gpointer))) then

I have replaced:

    integer(c_int) :: dialog
    dialog = gtk_dialog_run (about_dialog)
    call gtk_widget_hide (about_dialog)

by this code (already used in bazaar.f90):

    call gtk_widget_show(widget)
    call g_signal_connect_swapped (widget, "response"//c_null_char, &
                              & c_funloc(gtk_window_destroy), widget)

As a result, gtkf-sketcher.f90 is built by CMake, but of course it does no function. At the moment, 10 critical errors appears on launch and no window appears:

[osboxes@localhost sketcher]$ ./gtkf-sketcher
 PWD: /home/osboxes/gtk-fortran/build/sketcher

(gtkf-sketcher:4348): Gtk-CRITICAL **: 10:05:27.875: gtk_combo_box_set_active: assertion 'GTK_IS_COMBO_BOX (combo_box)' failed
...

@vmagnin
Copy link
Owner Author

vmagnin commented Oct 16, 2020

In GTK 3.99.2, gtk_buildable_get_name() has become gtk_buildable_get_buildable_id()
The change was made in the gtk4-vmagnin branch.

@vmagnin
Copy link
Owner Author

vmagnin commented Jan 19, 2021

I used $ gtk4-builder-tool simplify --3to4 gtkf-sketcher.glade to identify and remove deprecated properties from that Glade file. Then $ gtk4-builder-tool validate gtkf-sketcher.glade to identify and remove deprecated signals and objects. Finally I used $ gtk4-builder-tool simplify --3to4 --replace gtkf-sketcher.glade to port it to GTK 4. And I have done some more cleanup. By now in the gtk4-sketcher branch.
I replaced the deprecated GtkMenuBar by simply two buttons, "File open" and "About". It's far more simple than to create a menu with GTK 4...
As a result, gtkf-sketcher can be launched with its GUI.

@vmagnin
Copy link
Owner Author

vmagnin commented Jan 19, 2021

The only big remaining problem is how to parse the signals of each object in the UI file: we need to store them in that array:

type signal_connection
    character(len=64)::object_name
    character(len=64)::signal_name
    character(len=64)::handler_name
  end type signal_connection

  type(signal_connection), dimension(:), allocatable::connections

Example of an object in a UI file:

        <object class="GtkButton" id="button1">
          <property name="hexpand">1</property>
          <property name="label" translatable="yes">Button1</property>
          <property name="receives_default">1</property>
          <signal name="clicked" handler="hello" swapped="no"/>
        </object>

Note that there could also be several signals.

In GTK3, it was made using two times gtk_builder_connect_signals_full() (removed from GTK 4): the subroutines count_connections (builder, object, signal_name, handler_name, connect_object, flags, user_data) and get_connections (builder, object, signal_name, handler_name, connect_object, flags, user_data) were defined as callback functions which were launched for each signal by gtk_builder_connect_signals_full().

I am not sure the answer given in the GTK Discourse is an answer to our problem:
https://discourse.gnome.org/t/gtk-4-how-to-replace-gtk-builder-connect-signals/3561/2

@vmagnin
Copy link
Owner Author

vmagnin commented Jan 21, 2021

Another problem in gtkf-sketcher is that in GTK 3, gtk_widget_is_toplevel() was used to identify the toplevel object in the UI file. In GTK 4, that function is gone.
Updated: replaced by this code which give the name of the toplevel widget of a widget:

root =  gtk_buildable_get_buildable_id(gtk_widget_get_root(gpointer))
call C_F_string_ptr(root, f_string)

@vmagnin vmagnin changed the title gtkf-sketcher.f90 need porting to GTK 4 gtkf-sketcher.f90 ported to GTK 4, but some features are still missing Jan 21, 2021
@vmagnin
Copy link
Owner Author

vmagnin commented Aug 31, 2021

@vmagnin vmagnin changed the title gtkf-sketcher.f90 ported to GTK 4, but some features are still missing gtkf-sketcher.f90 ported to GTK 4, but important features are still missing Apr 30, 2022
@vmagnin vmagnin changed the title gtkf-sketcher.f90 ported to GTK 4, but important features are still missing gtkf-sketcher.f90: important features are still missing in th e GTK 4 version Apr 30, 2022
@vmagnin vmagnin changed the title gtkf-sketcher.f90: important features are still missing in th e GTK 4 version gtkf-sketcher.f90: important features are still missing in the GTK 4 version Apr 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GTK 4 GTK 4 only
Projects
None yet
Development

No branches or pull requests

2 participants