GLib doesn't find the ui resource

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

GLib doesn't find the ui resource

Sascha Manns
Hello list,

i have written some ui files which are compiled through make [1]. I
installed the compiled file in /usr/share/gnome-publisher.

Also i used this lines to add stuff from the resource:
builder = Gtk.Builder()

builder.add_from_resource("/org/gnome/Publisher/ui/main_intro.ui") [2]

But if i'm running my app, i'm getting:

/home/sascha/PycharmProjects/gnome-publisher/.env/bin/python3
/home/sascha/PycharmProjects/gnome-publisher/bin/gnome-publisher
Traceback (most recent call last):
  File
"/home/sascha/PycharmProjects/gnome-publisher/src/gnome_publisher/__main__.py",
line 54, in do_startup
    builder.add_from_resource('/org/gnome/Publisher/gtk/app_menu.ui')
GLib.Error: g-resource-error-quark: The resource at
“/org/gnome/Publisher/gtk/app_menu.ui” does not exist (0)
Traceback (most recent call last):
  File
"/home/sascha/PycharmProjects/gnome-publisher/src/gnome_publisher/__main__.py",
line 96, in do_activate
    builder.add_from_resource("/org/gnome/Publisher/ui/main_intro.ui")
GLib.Error: g-resource-error-quark: The resource at
“/org/gnome/Publisher/ui/main_intro.ui” does not exist (0)

But where the GLib searches for the file?

[1]
https://github.com/saigkill/gnome-publisher/blob/master/data/org.gnome.Publisher.gresource.xml
[2]
https://github.com/saigkill/gnome-publisher/blob/master/src/gnome_publisher/__main__.py

--
Sascha Manns
Maifeldstraße 10
56727 Mayen

P: +49-2651-4014045
W: http://saigkill.tuxfamily.org




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

signature.asc (887 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: GLib doesn't find the ui resource

Mariusz W

Hi,

I can tell from C API perspective.

When you are using gtk-builder-add-from-resource (https://developer.gnome.org/gtk3/stable/GtkBuilder.html#gtk-builder-add-from-resource) system is looking for path from resource file compiled by glib-compile-resources (https://developer.gnome.org/gio/stable/glib-compile-resources.html)

Format for resource file is in https://developer.gnome.org/gio/stable/GResource.html

e.g. (in this case path is "data/splashscreen.png" - it is not real file only path to resource in compiled file - this path is use in call to gtk-builder-add-from-resource)

<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/org/gtk/Example">
    <file>data/splashscreen.png</file>
    <file compressed="true">dialog.ui</file>
    <file preprocess="xml-stripblanks">menumarkup.xml</file>
  </gresource>
</gresources>

It you want to load real ui (created by glade) file from filestystem you shoud use gtk-builder-add-from-file
 (https://developer.gnome.org/gtk3/stable/GtkBuilder.html#gtk-builder-add-from-file).

Maybe in python you should use another method from api therefore,

Regards,
Mariusz 

W dniu 2017-08-30 o 15:48, Sascha Manns pisze:
Hello list,

i have written some ui files which are compiled through make [1]. I
installed the compiled file in /usr/share/gnome-publisher.

Also i used this lines to add stuff from the resource:
builder = Gtk.Builder()

builder.add_from_resource("/org/gnome/Publisher/ui/main_intro.ui") [2]

But if i'm running my app, i'm getting:

/home/sascha/PycharmProjects/gnome-publisher/.env/bin/python3
/home/sascha/PycharmProjects/gnome-publisher/bin/gnome-publisher
Traceback (most recent call last):
  File
"/home/sascha/PycharmProjects/gnome-publisher/src/gnome_publisher/__main__.py",
line 54, in do_startup
    builder.add_from_resource('/org/gnome/Publisher/gtk/app_menu.ui')
GLib.Error: g-resource-error-quark: The resource at
“/org/gnome/Publisher/gtk/app_menu.ui” does not exist (0)
Traceback (most recent call last):
  File
"/home/sascha/PycharmProjects/gnome-publisher/src/gnome_publisher/__main__.py",
line 96, in do_activate
    builder.add_from_resource("/org/gnome/Publisher/ui/main_intro.ui")
GLib.Error: g-resource-error-quark: The resource at
“/org/gnome/Publisher/ui/main_intro.ui” does not exist (0)

But where the GLib searches for the file?

[1]
https://github.com/saigkill/gnome-publisher/blob/master/data/org.gnome.Publisher.gresource.xml
[2]
https://github.com/saigkill/gnome-publisher/blob/master/src/gnome_publisher/__main__.py



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


_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: GLib doesn't find the ui resource

Emmanuele Bassi
In reply to this post by Sascha Manns
On 30 August 2017 at 14:48, Sascha Manns <[hidden email]> wrote:
> Hello list,
>
> i have written some ui files which are compiled through make [1]. I
> installed the compiled file in /usr/share/gnome-publisher.
>
> Also i used this lines to add stuff from the resource:
> builder = Gtk.Builder()
>
> builder.add_from_resource("/org/gnome/Publisher/ui/main_intro.ui") [2]

Did you remember to load the GResource bundle you installed under your
datadir, when you start your Python application?

C libraries and applications can take advantage of constructor
functions called before main(), and the ability to embed the resources
into the binary; Python (and other languages) do not have support for
that, so you need to explicitly load the GResource.

In Python, you can use:

```
from gi.repository import Gio

datadir = ... # Set this one up from your configuration
resource = Gio.Resource.load(os.path.join(datadir, 'gnome-publisher',
'gnome-publisher.gresource'))
resoures.register()
```

This will load the bundle and register it.

Ciao,
 Emmanuele.

--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: GLib doesn't find the ui resource

Sascha Manns
Hi Emanuelle,

On 30.08.2017 17:42, Emmanuele Bassi wrote:

> On 30 August 2017 at 14:48, Sascha Manns <[hidden email]> wrote:
>> Also i used this lines to add stuff from the resource:
>> builder = Gtk.Builder()
>>
>> builder.add_from_resource("/org/gnome/Publisher/ui/main_intro.ui") [2]
>
> Did you remember to load the GResource bundle you installed under your
> datadir, when you start your Python application?
>
> C libraries and applications can take advantage of constructor
> functions called before main(), and the ability to embed the resources
> into the binary; Python (and other languages) do not have support for
> that, so you need to explicitly load the GResource.
>
> In Python, you can use:
>
> ```
> from gi.repository import Gio
>
> datadir = ... # Set this one up from your configuration
> resource = Gio.Resource.load(os.path.join(datadir, 'gnome-publisher',
> 'gnome-publisher.gresource'))
> resoures.register()
This tip works perfectly.

Thank you.

--
Sascha Manns
Maifeldstraße 10
56727 Mayen

P: +49-2651-4014045
W: http://saigkill.tuxfamily.org


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

signature.asc (887 bytes) Download Attachment