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

<packing> tags not supported by builder #349

Closed
AndreiBiziuk opened this issue May 13, 2021 · 5 comments
Closed

<packing> tags not supported by builder #349

AndreiBiziuk opened this issue May 13, 2021 · 5 comments

Comments

@AndreiBiziuk
Copy link

AndreiBiziuk commented May 13, 2021

I'm trying to use builder to create UI from XML files created by Glade. Glade creates <packing> tags inside various controls tags.

Example ui file:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
  <requires lib="gtk+" version="3.0"/>
  <object class="GtkWindow" id="main_window">
    <property name="can-focus">False</property>
    <property name="title" translatable="yes">Main window</property>
    <child>
      <object class="GtkBox" id="main_box">
        <property name="visible">True</property>
        <property name="can-focus">False</property>
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkButton" id="recreate_button">
            <property name="label" translatable="yes">button1</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="receives-default">True</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkToggleButton" id="start_fit_button">
            <property name="label" translatable="yes">button2</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="receives-default">True</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <placeholder/>
        </child>
      </object>
    </child>
  </object>
</interface>

When I try to compile I get error:

failed to add UI from file main.ui: main.ui:21:1 Unhandled tag: <packing>

I have to manually remove this tags from file every time when I edit UI.

@garetxe
Copy link
Collaborator

garetxe commented May 13, 2021

Hi! Thanks for the report!

The haskell-gi autogenerated bindings do not have special support for .ui files, although it is in my list of potential future ideas. So I suspect that it is an incompatibility between gtk and glade. As a guess... are you using gi-gtk-3.* or gi-gtk-4.*? Perhaps the format of the ui files has changed between the two versions.

@AndreiBiziuk
Copy link
Author

I am using gi-gtk-4.0 and Glade uses gtk+ 3.x so probably this is the cause of the problem. Thank you for reply!

@garetxe
Copy link
Collaborator

garetxe commented May 13, 2021

I see, that's probably the explanation then.

I personally like glade, and I think that it's a real pity that it does not support gtk4. The alternative which is often proposed is to write the .ui XML by hand, but to be honest I don't think it's worth the pain in Haskell. Here is the Haskell code that would construct the same ui (I am intentionally leaving some unnecessary things in, like #visible := True, and so on, to make the comparison easier):

mainWindow :: IO Gtk.Window
mainWindow = do
  mainBox <- new Gtk.Box [ #visible := True
                         , #canFocus := False
                         , #orientation := Gtk.OrientationVertical ]

  recreateButton <- new Gtk.Button [ #label := "button1"
                                   , #visible := True
                                   , #canFocus := True
                                   , #receivesDefault := True
                                   , #valign := Gtk.AlignFill
                                   , #vexpand := False ]
  #append mainBox recreateButton

  startFitButton <- new Gtk.ToggleButton [ #label := "button2"
                                         , #visible := True
                                         , #canFocus := True
                                         , #receivesDefault := True
                                         , #valign := Gtk.AlignFill
                                         , #vexpand := False ]
  #append mainBox startFitButton

  new Gtk.Window [ #canFocus := False
                 , #title := "Main window"
                 , #child := mainBox ]

I would argue that this is as readable as the XML (perhaps more), and the types are checked at compile time.

Anyway, I am closing since it seems like there is little that we can do on the haskell-gi side to fix this. Thanks again for the bug report!

@garetxe garetxe closed this as completed May 13, 2021
@AndreiBiziuk
Copy link
Author

I found very useful command that convert .ui files from gtk3 to gtk4:

gtk4-builder-tool simplify --3to4 --replace ./main.ui

@garetxe
Copy link
Collaborator

garetxe commented May 14, 2021

Thanks, that seems useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants