builder gio::resource problem

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

builder gio::resource problem

Marty Moore-2
Hi all,
I'm trying to update from gtkmm-2.24 to gtkmm-3.18. As a dinosaur of a
previous age, I'm trying to move from manual menus to Gtk::Builder and
Gio::Resources. I've been through section 12 of the tutorial several
times, and have looked at the 3.18 source /demo/Makefile as a
reference. I'm using the example_builder.cc to learn how to load
resources int an app. 

So far, the program compiles, but I'm getting a runtime error:

marty@builder$./x
main 0:
Error loading example_builder.ui: The resource at
'/builder/example_builder.ui' does not exist

I'm obvioysly mis-understanding something about resources, and would
appreciate any help you can provide. I've been stewing over this for
weeks.
Thanks,
Marty
 
I'm running:
   Ubuntu-16.LTS g++-5 emacs-24
gresource.xml:

<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/builder">
    <file>example_builder.ui</file>
  </gresource>
</gresources

makefile:

PKGS = gtkmm-3.0  #epoxy
INCL = `pkg-config --cflags $(PKGS)`
LIBS = `pkg-config --libs   $(PKGS)`
COMP_RES = /usr/lib/x86_64-linux-gnu/glib-2.0/glib-compile-resources
SRCDIR = /home/marty/gtkmm3/builder

CC     = g++
CFLAGS = -g -Wall $(INCL)
EXE    = x

OBJS   =  example_builder.o resource.c

resource.c: gresource.xml example_builder.ui
        $(COM P_RES) --target=resource.c --generate-source
builder.gresource.xml

all: $(EXE)

$(EXE): $(OBJS)
        $(CC) $(OBJS) $(LIBS) -o $(EXE)

example_builder.o: example_builder.cc
        $(CC) $(CFLAGS) -c example_builder.cc


clean:
        rm *.o *.
example_builder.ui:

<?xml version="1.0" standalone="no"?>
<!--*- mode: xml -*-->
<interface>
  <object class="GtkListStore" id="liststore1">
    <columns>
      <column type="gchararray"/>
      <column type="gchararray"/>
      <column type="gint"/>
      <column type="gchararray"/>
    </columns>
    <data>
      <row>
        <col id="0" translatable="yes">John</col>
        <col id="1" translatable="yes">Doe</col>
        <col id="2">25</col>
        <col id="3" translatable="yes">This is the John Doe row</col>
      </row>
      <row>
        <col id="0" translatable="yes">Mary</col>
        <col id="1" translatable="yes">Unknown</col>
        <col id="2">50</col>
        <col id="3" translatable="yes">This is the Mary Unknown
row</col>
      </row>
    </data>
  </object>
  <object class="GtkAboutDialog" id="aboutdialog1">
    <property name="program-name" translatable="yes">Gtk::Builder
demo</property>
    <property name="logo-icon-name" translatable="yes">gtk3-
demo</property>
    <accessibility>
      <relation target="window1" type="subwindow-of"/>
    </accessibility>
  </object>
  <object class="GtkWindow" id="window1">
    <property name="default_height">250</property>
    <property name="default_width">440</property>
    <property name="title">Gtk::Builder demo</property>
    <child>
      <object class="GtkVBox" id="vbox1">
        <property name="visible">True</property>
        <child>
          <object class="GtkMenuBar" id="menubar1">
            <property name="visible">True</property>
            <child internal-child="accessible">
              <object class="AtkObject" id="a11y-menubar">
                <property name="AtkObject::accessible-name">The
menubar</property>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem">
                <property name="visible">True</property>
                <property name="label"
translatable="yes">_File</property>
                <property name="use-underline">True</property>
                <child type="submenu">
                  <object class="GtkMenu">
                    <child>
                      <object class="GtkMenuItem" id="new_item">
                        <property name="visible">True</property>
                        <property name="label"
translatable="yes">_New</property>
                        <property name="use-underline">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkMenuItem" id="open_item">
                        <property name="visible">True</property>
                        <property name="label"
translatable="yes">_Open</property>
                        <property name="use-underline">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkMenuItem" id="save_item">
                        <property name="visible">True</property>
                        <property name="label"
translatable="yes">_Save</property>
                        <property name="use-underline">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkMenuItem" id="save_as_item">
                        <property name="visible">True</property>
                        <property name="label" translatable="yes">Save
_As</property>
                        <property name="use-underline">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkSeparatorMenuItem">
                        <property name="visible">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkMenuItem" id="quit_item">
                        <property name="visible">True</property>
                        <property name="label"
translatable="yes">_Quit</property>
                        <property name="use-underline">True</property>
                        <property name="action-
name">win.quit</property>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem">
                <property name="visible">True</property>
                <property name="label"
translatable="yes">_Edit</property>
                <property name="use-underline">True</property>
                <child type="submenu">
                  <object class="GtkMenu">
                    <child>
                      <object class="GtkMenuItem" id="copy_item">
                        <property name="visible">True</property>
                        <property name="label"
translatable="yes">_Copy</property>
                        <property name="use-underline">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkMenuItem" id="cut_item">
                        <property name="visible">True</property>
                        <property name="label"
translatable="yes">_Cut</property>
                        <property name="use-underline">True</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkMenuItem" id="paste_item">
                        <property name="visible">True</property>
                        <property name="label"
translatable="yes">_Paste</property>
                        <property name="use-underline">True</property>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem">
                <property name="visible">True</property>
                <property name="label"
translatable="yes">_Help</property>
                <property name="use-underline">True</property>
                <child type="submenu">
                  <object class="GtkMenu">
                    <child>
                      <object class="GtkMenuItem" id="help_item">
                        <property name="visible">True</property>
                        <property name="label"
translatable="yes">_Help</property>
                        <property name="use-underline">True</property>
                        <property name="action-
name">win.help</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkMenuItem" id="about_item">
                        <property name="visible">True</property>
                        <property name="label"
translatable="yes">_About</property>
                        <property name="use-underline">True</property>
                        <property name="action-
name">win.about</property>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
          </packing>
        </child>
        <child>
          <object class="GtkToolbar" id="toolbar1">
            <property name="visible">True</property>
            <child internal-child="accessible">
              <object class="AtkObject" id="a11y-toolbar">
                <property name="AtkObject::accessible-name">The
toolbar</property>
              </object>
            </child>
            <child>
              <object class="GtkToolButton">
                <property name="visible">True</property>
                <property name="label"
translatable="yes">New</property>
                <property name="tooltip-text" translatable="yes">Create
a new file</property>
                <property name="icon-name">document-new</property>
              </object>
            </child>
            <child>
              <object class="GtkToolButton">
                <property name="visible">True</property>
                <property name="label"
translatable="yes">Open</property>
                <property name="tooltip-text" translatable="yes">Open a
file</property>
                <property name="icon-name">document-open</property>
              </object>
            </child>
            <child>
              <object class="GtkToolButton">
                <property name="visible">True</property>
                <property name="label"
translatable="yes">Save</property>
                <property name="tooltip-text" translatable="yes">Save a
file</property>
                <property name="icon-name">document-save</property>
                <property name="is-important">True</property>
              </object>
            </child>
            <child>
              <object class="GtkSeparatorToolItem">
                <property name="visible">True</property>
              </object>
            </child>
            <child>
              <object class="GtkToolButton">
                <property name="visible">True</property>
                <property name="label"
translatable="yes">Copy</property>
                <property name="tooltip-text" translatable="yes">Copy
selected object into the clipboard</property>
                <property name="icon-name">edit-copy</property>
              </object>
            </child>
            <child>
              <object class="GtkToolButton">
                <property name="visible">True</property>
                <property name="label"
translatable="yes">Cut</property>
                <property name="tooltip-text" translatable="yes">Cut
selected object into the clipboard</property>
                <property name="icon-name">edit-cut</property>
              </object>
            </child>
            <child>
              <object class="GtkToolButton">
                <property name="visible">True</property>
                <property name="label"
translatable="yes">Paste</property>
                <property name="tooltip-text" translatable="yes">Paste
object from the clipboard</property>
                <property name="icon-name">edit-paste</property>
              </object>
            </child>
          </object>
          <packing>
            <property name="position">1</property>
            <property name="expand">False</property>
          </packing>
        </child>
        <child>
          <object class="GtkScrolledWindow" id="scrolledwindow1">
            <property name="shadow_type">in</property>
            <property name="visible">True</property>
            <child>
              <object class="GtkTreeView" id="treeview1">
                <property name="visible">True</property>
                <property name="model">liststore1</property>
                <property name="tooltip-column">3</property>
                <child internal-child="accessible">
                  <object class="AtkObject" id="a11y-treeview">
                    <property name="AtkObject::accessible-name">Name
list</property>
                    <property name="AtkObject::accessible-description">
                                    A list of person with name, surname
and age columns
                                  </property>
                  </object>
                </child>
                <child>
                  <object class="GtkTreeViewColumn" id="column1">
                    <property name="title">Name</property>
                    <child>
                      <object class="GtkCellRendererText"
id="renderer1"/>
                      <attributes>
                        <attribute name="text">0</attribute>
                      </attributes>
                    </child>
                  </object>
                </child>
                <child>
                  <object class="GtkTreeViewColumn" id="column2">
                    <property name="title">Surname</property>
                    <child>
                      <object class="GtkCellRendererText"
id="renderer2"/>
                      <attributes>
                        <attribute name="text">1</attribute>
                      </attributes>
                    </child>
                  </object>
                </child>
                <child>
                  <object class="GtkTreeViewColumn" id="column3">
                    <property name="title">Age</property>
                    <child>
                      <object class="GtkCellRendererText"
id="renderer3"/>
                      <attributes>
                        <attribute name="text">2</attribute>
                      </attributes>
                    </child>
                  </object>
                </child>
              </object>
            </child>
          </object>
          <packing>
            <property name="position">2</property>
            <property name="expand">True</property>
          </packing>
        </child>
        <child>
          <object class="GtkStatusbar" id="statusbar1">
            <property name="visible">True</property>
          </object>
          <packing>
            <property name="position">3</property>
            <property name="expand">False</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface


example_builder.cc

 * Demonstrates an interface loaded from a XML description.
 */

#include "gtkmm.h"
#include "gtk/gtk.h"
#include <iostream> // For std::cout

class Example_Builder : public Gtk::Window
{
public:
    Example_Builder(BaseObjectType* cobject,
                    const Glib::RefPtr<Gtk::Builder>& builder);
    virtual ~Example_Builder();

protected:
    void on_file_quit();
    void on_help_about();
    void on_help_help();

    Glib::RefPtr<Gtk::Builder> m_builder;
};

//Called by DemoWindow:
Gtk::Window* do_builder()
{
    cout << "do_builder 0: << endl;
    // Load the XML file and instantiate its widgets:
    Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create();
    try
    {
    cout << "do_builder 1: << endl;
        builder->add_from_resource(
            "/builder/example_builder.ui");
    cout << "do_builder 99: << endl;
}
    catch (const Glib::Error& error)
    {
        std::cout << "Error loading example_builder.ui: " <<
error.what() << std::endl;
        return nullptr;
    }

    // Get the GtkBuilder-instantiated window:
    Example_Builder* pWindow = nullptr;
    builder->get_widget_derived("window1", pWindow);
    if (!pWindow)
    {
        std::cout << "Could not get 'window1' from the builder." <<
std::endl;
        return nullptr;
    }
    return pWindow;
}

Example_Builder::Example_Builder(
    BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder)
    : Gtk::Window(cobject),
      m_builder(builder)
{
    Gtk::Toolbar* pToolbar = nullptr;
    builder->get_widget("toolbar1", pToolbar);
    if (pToolbar)
        pToolbar->get_style_context()->add_class("primary-toolbar");

    Glib::RefPtr<Gio::SimpleActionGroup> refActions =
Gio::SimpleActionGroup::create();
    refActions->add_action("quit", sigc::mem_fun(*this,
&Example_Builder::on_file_quit));
    refActions->add_action("about", sigc::mem_fun(*this,
&Example_Builder::on_help_about));
    refActions->add_action("help", sigc::mem_fun(*this,
&Example_Builder::on_help_help));
    insert_action_group("win", refActions);

    Glib::RefPtr<Gtk::AccelGroup> refAccelGroup =
Gtk::AccelGroup::create();
    add_accel_group(refAccelGroup);

    Gtk::MenuItem* pMenuItem = nullptr;
    builder->get_widget("new_item", pMenuItem);
    if (pMenuItem)
        pMenuItem->add_accelerator("activate", refAccelGroup,
                                   GDK_KEY_n, Gdk::CONTROL_MASK,
Gtk::ACCEL_VISIBLE);

    builder->get_widget("open_item", pMenuItem);
    if (pMenuItem)
        pMenuItem->add_accelerator("activate", refAccelGroup,
                                   GDK_KEY_o, Gdk::CONTROL_MASK,
Gtk::ACCEL_VISIBLE);

    builder->get_widget("save_item", pMenuItem);
    if (pMenuItem)
        pMenuItem->add_accelerator("activate", refAccelGroup,
                                   GDK_KEY_s, Gdk::CONTROL_MASK,
Gtk::ACCEL_VISIBLE);

    builder->get_widget("quit_item", pMenuItem);
    if (pMenuItem)
        pMenuItem->add_accelerator("activate", refAccelGroup,
                                   GDK_KEY_q, Gdk::CONTROL_MASK,
Gtk::ACCEL_VISIBLE);

    builder->get_widget("copy_item", pMenuItem);
    if (pMenuItem)
        pMenuItem->add_accelerator("activate", refAccelGroup,
                                   GDK_KEY_c, Gdk::CONTROL_MASK,
Gtk::ACCEL_VISIBLE);

    builder->get_widget("cut_item", pMenuItem);
    if (pMenuItem)
        pMenuItem->add_accelerator("activate", refAccelGroup,
                                   GDK_KEY_x, Gdk::CONTROL_MASK,
Gtk::ACCEL_VISIBLE);

    builder->get_widget("paste_item", pMenuItem);
    if (pMenuItem)
        pMenuItem->add_accelerator("activate", refAccelGroup,
                                   GDK_KEY_v, Gdk::CONTROL_MASK,
Gtk::ACCEL_VISIBLE);

    builder->get_widget("help_item", pMenuItem);
    if (pMenuItem)
        pMenuItem->add_accelerator("activate", refAccelGroup,
                                   GDK_KEY_F1, (Gdk::ModifierType)0,
Gtk::ACCEL_VISIBLE);

    builder->get_widget("about_item", pMenuItem);
    if (pMenuItem)
        pMenuItem->add_accelerator("activate", refAccelGroup,
                                   GDK_KEY_F7, (Gdk::ModifierType)0,
Gtk::ACCEL_VISIBLE);

    show_all();
}

Example_Builder::~Example_Builder()
{
}

void Example_Builder::on_file_quit()
{
    hide();
}

void Example_Builder::on_help_about()
{
    Gtk::AboutDialog* pDialog = nullptr;
    m_builder->get_widget("aboutdialog1", pDialog);
    if (pDialog)
    {
        pDialog->set_transient_for(*this);
        pDialog->run();
        pDialog->hide();
    }
}

void Example_Builder::on_help_help()
{
    std::cout << "Help not available." << std::endl;
}



int main( int argc, char* argv[])
{
    std::cout << "main 0:" << std::endl;
    auto app = Gtk::Application::create( argc, argv);
    Gtk::Window* win = do_builder();
    return app->run(*win);


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

Re: builder gio::resource problem

Kjell Ahlstedt
Den 2017-04-08 kl. 18:14, skrev Marty Moore:
resource.c: gresource.xml example_builder.ui
	$(COM P_RES) --target=resource.c --generate-source
builder.gresource.xml

$(COM P_RES) looks wrong. Should be $(COMP_RES), I suppose. Strange that it builds. Does resource.c become an empty file? Or is this a bug only in your e-mail, but not in the makefile that you actually use?

Kjell


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

Re: builder gio::resource problem

Daniel Boles
Another bug in either the email or the real procedure is the missing > at the end of the gresource.xml file

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

Re: builder gio::resource problem

aitor_czr
In reply to this post by Marty Moore-2

Hi Marty,

On 04/09/2017 08:20 AM, Marty Moore [hidden email] wrote:
Hi all,
I'm trying to update from gtkmm-2.24 to gtkmm-3.18. As a dinosaur of a
previous age, I'm trying to move from manual menus to Gtk::Builder and
Gio::Resources. I've been through section 12 of the tutorial several
times, and have looked at the 3.18 source /demo/Makefile as a
reference. I'm using the example_builder.cc to learn how to load
resources int an app.?

So far, the program compiles, but I'm getting a runtime error:

[hidden email]
main 0:
Error loading example_builder.ui: The resource at
'/builder/example_builder.ui' does not exist

I'm obvioysly mis-understanding something about resources, and would
appreciate any help you can provide. I've been stewing over this for
weeks.
Thanks,
Marty

Please, can you attach the link to the example? I can't find it in the gnome development tutorial:

https://developer.gnome.org/gtkmm-tutorial/stable/index-info.html.en

Maybe, i can help you using CMake... Have a look at this example:

https://git.devuan.org/aitor_czr/simple-netaid-gtk/tree/master

I use a singleton class defining all the global variables, including the paths to the executables, output files, pixmaps, etc...

Cheers,

  Aitor.





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

Re: builder gio::resource problem

aitor_czr

Hi again,

On 04/09/2017 11:47 AM, aitor_czr wrote:

Hi Marty,

On 04/09/2017 08:20 AM, Marty Moore [hidden email] wrote:
Hi all,
I'm trying to update from gtkmm-2.24 to gtkmm-3.18. As a dinosaur of a
previous age, I'm trying to move from manual menus to Gtk::Builder and
Gio::Resources. I've been through section 12 of the tutorial several
times, and have looked at the 3.18 source /demo/Makefile as a
reference. I'm using the example_builder.cc to learn how to load
resources int an app.?

So far, the program compiles, but I'm getting a runtime error:

[hidden email]
main 0:
Error loading example_builder.ui: The resource at
'/builder/example_builder.ui' does not exist

I'm obvioysly mis-understanding something about resources, and would
appreciate any help you can provide. I've been stewing over this for
weeks.
Thanks,
Marty

Please, can you attach the link to the example? I can't find it in the gnome development tutorial:

https://developer.gnome.org/gtkmm-tutorial/stable/index-info.html.en

Maybe, i can help you using CMake... Have a look at this example:

https://git.devuan.org/aitor_czr/simple-netaid-gtk/tree/master

I use a singleton class defining all the global variables, including the paths to the executables, output files, pixmaps, etc...

Cheers,

  Aitor.

Ok, these are the files:

http://gnuinos.org/Example-Builder/

I'll try to build it this afternoon (12:15 here, in the north of Spain). More concretely, Basque country :)

Usually (and only for
convenience) i include all the headers in an unique header called <headers.h>, and, after finishing the project i do a right separation of the headers, when packaging, distinguishing between static/shared, runtime/libdevel, etc...

Cheers,

  Aitor.



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

Re: builder gio::resource problem

aitor_czr

Hi Marty,

On 04/09/2017 12:19 PM, aitor_czr wrote:

Hi again,

On 04/09/2017 11:47 AM, aitor_czr wrote:

Hi Marty,

On 04/09/2017 08:20 AM, Marty Moore [hidden email] wrote:
Hi all,
I'm trying to update from gtkmm-2.24 to gtkmm-3.18. As a dinosaur of a
previous age, I'm trying to move from manual menus to Gtk::Builder and
Gio::Resources. I've been through section 12 of the tutorial several
times, and have looked at the 3.18 source /demo/Makefile as a
reference. I'm using the example_builder.cc to learn how to load
resources int an app.?

So far, the program compiles, but I'm getting a runtime error:

[hidden email]
main 0:
Error loading example_builder.ui: The resource at
'/builder/example_builder.ui' does not exist

I'm obvioysly mis-understanding something about resources, and would
appreciate any help you can provide. I've been stewing over this for
weeks.
Thanks,
Marty

Please, can you attach the link to the example? I can't find it in the gnome development tutorial:

https://developer.gnome.org/gtkmm-tutorial/stable/index-info.html.en

Maybe, i can help you using CMake... Have a look at this example:

https://git.devuan.org/aitor_czr/simple-netaid-gtk/tree/master

I use a singleton class defining all the global variables, including the paths to the executables, output files, pixmaps, etc...

Cheers,

  Aitor.

Ok, these are the files:

http://gnuinos.org/Example-Builder/

I'll try to build it this afternoon (12:15 here, in the north of Spain). More concretely, Basque country :)

Usually (and only for
convenience) i include all the headers in an unique header called <headers.h>, and, after finishing the project i do a right separation of the headers, when packaging, distinguishing between static/shared, runtime/libdevel, etc...

Cheers,

  Aitor.

Now it builds succesfully:

http://gnuinos.org/Example-Builder/

I changed:

builder->add_from_resource("./src/example_builder.ui");

by:

builder->add_from_file("./src/example_builder.ui");

HTH,

  Aitor.




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

Re: builder gio::resource problem

Marty Moore-2
In reply to this post by Kjell Ahlstedt
Hi all,
Thanks for your replies.
I'm researching you comments, but here's some answers to your questions.

The example_builder.cc file cam from the source download:
   gtkmm-3.18.1/demo/gtk-demo/example_builder.cc

The COMP_RES line is a mix/alteration of the Programming with gtkmm3 chanpter 12 section on gio::resources and the makefile in the source download gtkmm-3.18.1/demos directory.

You were right... The problem is in the $(COMP_RES) line:
It turns out that there was a compiler error, although the result said ' compilation finished'.
I've been playing with that line, trying to adjust it to what the source download 'demos/Makefile' used: e.g.
   gtk-demo/demo_resources.c: gtk-demo/demo.gresource.xml $(GTK_DEMO_RESOURCES) $(GTK_DEMOS)
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(dir $<) --generate-source $<

So, here's my current makefile:
PKGS = gtkmm-3.0  #epoxy
INCL = `pkg-config --cflags $(PKGS)`
LIBS = `pkg-config --libs   $(PKGS)`
COMP_RES = /usr/lib/x86_64-linux-gnu/glib-2.0/glib-compile-resources

CC     = g++
CFLAGS = -g -Wall $(INCL)
EXE    = x

OBJS   =  example_builder.o resource.c
DIR = `pwd`

resource.c: gresource.xml example_builder.ui
$(COM P_RES) --target=$@   --sourcedir=$(DIR) --generate-source  $<

#$@ --sourcedir=$(dir $<) --generate-source $<

all: $(EXE)

$(EXE): $(OBJS)
$(CC) $(OBJS) $(LIBS) -o $(EXE)

example_builder.o: example_builder.cc
$(CC) $(CFLAGS) -c example_builder.cc


clean:
rm *.o *.
 
and here's the make output:

-*- mode: compilation; default-directory: "~/gtkmm3/builder/" -*-
Compilation started at Sun Apr  9 14:01:54

make -k 
target=resource.c   --sourcedir=`pwd` --generate-source  gresource.xml
/bin/sh: 1: --sourcedir=/home/marty/gtkmm3/builder: not found
makefile:14: recipe for target 'resource.c' failed
make: [resource.c] Error 127 (ignored)

Compilation finished at Sun Apr  9 14:01:5

But the 'missing' directory, /home/marty/gtkmm3/builder is my current working directory.

So, I've been trying to piece together what I can find that talks about using gio::resources. Unfortunately, the chapter 12 section talks about using gio::resources, but the examples in chapter 12 don't use gio::resource to load these files.
I nees to learn this since the example_glarea.cc example uses gio::resource to load the glsl dhadres, which is where I'm headed if I can figure this out.

My gresouce.xml file has a '>' at the end, so I must have a typo in my email.

That's the latest. I hope this helps.
Thanks again, I really appreciate your help!
Marty







On Sun, 2017-04-09 at 10:13 +0200, Kjell Ahlstedt wrote:
Den 2017-04-08 kl. 18:14, skrev Marty Moore:
resource.c: gresource.xml example_builder.ui
	$(COM P_RES) --target=resource.c --generate-source
builder.gresource.xml

$(COM P_RES) looks wrong. Should be $(COMP_RES), I suppose. Strange that it builds. Does resource.c become an empty file? Or is this a bug only in your e-mail, but not in the makefile that you actually use?

Kjell


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

Re: builder gio::resource problem

Daniel Boles
On 9 April 2017 at 21:42, Marty Moore <[hidden email]> wrote:

resource.c: gresource.xml example_builder.ui
$(COM P_RES) --target=$@   --sourcedir=$(DIR) --generate-source  $<

Is this another typo? There should not be a space in the variable name. That would explain this...

make -k 
target=resource.c   --sourcedir=`pwd` --generate-source  gresource.xml
/bin/sh: 1: --sourcedir=/home/marty/gtkmm3/builder: not found

Note that it appears to be sh itself giving the error - not glib-compile-resources

because the variable specifying the glib-compile-resources binary appears to be empty, probably because of that typo, so it expands to nothing, so the literal command executed is just that 2nd line quoted above. And, of course, there is no binary called --sourcedir=/home/marty/gtkmm3/builder for sh to execute

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

Re: builder gio::resource problem

aitor_czr
In reply to this post by Marty Moore-2

Hi,

On 04/09/2017 11:42 PM, aitor_czr wrote:

Hi Marty,

On 04/09/2017 12:19 PM, aitor_czr wrote:
Hi again,

On 04/09/2017 11:47 AM, aitor_czr wrote:
Hi Marty,

On 04/09/2017 08:20 AM, Marty Moore [hidden email] wrote:
Hi all,
I'm trying to update from gtkmm-2.24 to gtkmm-3.18. As a dinosaur of a
previous age, I'm trying to move from manual menus to Gtk::Builder and
Gio::Resources. I've been through section 12 of the tutorial several
times, and have looked at the 3.18 source /demo/Makefile as a
reference. I'm using the example_builder.cc to learn how to load
resources int an app.?

So far, the program compiles, but I'm getting a runtime error:

[hidden email]
main 0:
Error loading example_builder.ui: The resource at
'/builder/example_builder.ui' does not exist

I'm obvioysly mis-understanding something about resources, and would
appreciate any help you can provide. I've been stewing over this for
weeks.
Thanks,
Marty
Please, can you attach the link to the example? I can't find it in 
the gnome development tutorial:

https://developer.gnome.org/gtkmm-tutorial/stable/index-info.html.en

Maybe, i can help you using CMake... Have a look at this example:

https://git.devuan.org/aitor_czr/simple-netaid-gtk/tree/master

I use a singleton class defining all the global variables, including 
the paths to the executables, output files, pixmaps, etc...

Cheers,

  Aitor.
Ok, these are the files:

http://gnuinos.org/Example-Builder/

I'll try to build it this afternoon (12:15 here, in the north of 
Spain). More concretely, Basque country :)

Usually (and only for convenience) i include all the headers in an 
unique header called <headers.h>, and, after finishing the project i 
do a right separation of the headers, when packaging, distinguishing 
between static/shared, runtime/libdevel, etc...

Cheers,

  Aitor.
Now it builds succesfully:

http://gnuinos.org/Example-Builder/

I changed:

builder->add_from_resource("./src/example_builder.ui");

by:

builder->add_from_file("./src/example_builder.ui");

HTH,

   Aitor.

I added the
precompilation directives to the headers, so that they will be read only once :)

http://gnuinos.org/Example-Builder/include/

Cheers,

  Aitor.





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

Re: builder gio::resource problem

aitor_czr

Hi

On 04/10/2017 12:49 AM, aitor_czr wrote:

Hi,

On 04/09/2017 11:42 PM, aitor_czr wrote:

Hi Marty,

On 04/09/2017 12:19 PM, aitor_czr wrote:
Hi again,

On 04/09/2017 11:47 AM, aitor_czr wrote:
Hi Marty,

On 04/09/2017 08:20 AM, Marty Moore [hidden email] wrote:
Hi all,
I'm trying to update from gtkmm-2.24 to gtkmm-3.18. As a dinosaur of a
previous age, I'm trying to move from manual menus to Gtk::Builder and
Gio::Resources. I've been through section 12 of the tutorial several
times, and have looked at the 3.18 source /demo/Makefile as a
reference. I'm using the example_builder.cc to learn how to load
resources int an app.?

So far, the program compiles, but I'm getting a runtime error:

[hidden email]
main 0:
Error loading example_builder.ui: The resource at
'/builder/example_builder.ui' does not exist

I'm obvioysly mis-understanding something about resources, and would
appreciate any help you can provide. I've been stewing over this for
weeks.
Thanks,
Marty
Please, can you attach the link to the example? I can't find it in 
the gnome development tutorial:

https://developer.gnome.org/gtkmm-tutorial/stable/index-info.html.en

Maybe, i can help you using CMake... Have a look at this example:

https://git.devuan.org/aitor_czr/simple-netaid-gtk/tree/master

I use a singleton class defining all the global variables, including 
the paths to the executables, output files, pixmaps, etc...

Cheers,

  Aitor.
Ok, these are the files:

http://gnuinos.org/Example-Builder/

I'll try to build it this afternoon (12:15 here, in the north of 
Spain). More concretely, Basque country :)

Usually (and only for convenience) i include all the headers in an 
unique header called <headers.h>, and, after finishing the project i 
do a right separation of the headers, when packaging, distinguishing 
between static/shared, runtime/libdevel, etc...

Cheers,

  Aitor.
Now it builds succesfully:

http://gnuinos.org/Example-Builder/

I changed:

builder->add_from_resource("./src/example_builder.ui");

by:

builder->add_from_file("./src/example_builder.ui");

HTH,

   Aitor.

I added the
precompilation directives to the headers, so that they will be read only once :)

http://gnuinos.org/Example-Builder/include/

Cheers,

  Aitor.

BTW, I'm working on a dinamic gtkmm popup menu for Openbox. Here you are a video:

http://gnuinos.org/popup-menu.mpg

Cheers,

  Aitor.




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

[SOLVED] Re: builder gio::resource problem

Marty Moore-2
Hi Aitor,
It finally  works! Thank you all for your help!

It all boiled down to the makefile. It turns out that resouces need to be compiled twice, once by Glib::compile_resources, and again by g++.  This was not clear in chapter 12.4 of "Programming with gtkmm", at least for dinosaurs like me. 

I suggest that chapter 12.4 be rewitten with more detail and examples of each stage of creating and loading gio::resources.  I would also suggest that a complete, simple, and working example including a makefile be added to chapter 12.4. While not everyone uses makefile, it would be a simple reference for all users.  The example of 12.5 don't work, because their focus in on menus, and some required pieces (.glade files, makefiles) are missing. 

Below are the final working parts of the example_window from gtkmm-3-18.1/demos/gtk-demo.

Hopefully, I didn't make any typos.... I hope this help others trying to figure out how to use gio::resource.

Thanks again for your help.
Marty

makefile:
PKGS = gtkmm-3.0 
INCL = `pkg-config --cflags $(PKGS)`
LIBS = `pkg-config --libs   $(PKGS)`
COMP_RES = /usr/lib/x86_64-linux-gnu/glib-2.0/glib-compile-resources

CC     = g++
CFLAGS = -g -Wall $(INCL)
EXE    = x
OBJS   =  example_builder.o resource.o
DIR = `pwd`

$(EXE): $(OBJS)
$(CC) $(OBJS) $(LIBS) -o $(EXE)

example_builder.o: example_builder.cc
$(CC) $(CFLAGS) -c example_builder.cc 

resource.o:  resource.c
$(CC)  $(INCL) -c resource.c -o resource.o

resource.c:  gresource.xml  example_builder.ui
$(COMP_RES) --target=$@ --sourcedir=$(DIR)   --generate-source  $<


.phony:
clean:
rm *.o *~ *.h~ *.cc~ *.c *.c~ x

gresources.xml:

<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/builder">
    <file>example_builder.ui</file>
  </gresource>
</gresources>

example_builder.ui:

<?xml version="1.0" standalone="no"?>
<!--*- mode: xml -*-->
<interface>
  <object class="GtkListStore" id="liststore1">
    <columns>
      <column type="gchararray"/>
      <column type="gchararray"/>
      <column type="gint"/>
      <column type="gchararray"/>
    </columns>
    <data>

example_builder.cc:

// File: example_builder.cc
//    (from gtkmm-3.18.1/demos/gtkcemo)
//    main function added at end of file.

/* Builder
 *
 * Demonstrates an interface loaded from a XML description.
 */

#include "gtkmm.h"
#include "gtk/gtk.h"
#include <iostream> // For std::cout

using std::cout;
using std::endl;

class Example_Builder : public Gtk::Window
{
public:
    Example_Builder(BaseObjectType* cobject,
    const Glib::RefPtr<Gtk::Builder>& builder);
    virtual ~Example_Builder();

protected:
    void on_file_quit();
    void on_help_about();
    void on_help_help();

    Glib::RefPtr<Gtk::Builder> m_builder;
};

//Called by DemoWindow:
Gtk::Window* do_builder()
{
    cout << "do_builder 0:" << endl;
    // Load the XML file and instantiate its widgets:
    Glib::RefPtr<Gtk::Builder> builder =
Gtk::Builder::create();
    try
    {
builder->add_from_resource(
    "/builder/example_builder.ui");
}
    catch (const Glib::Error& error)
    {
std::cout << "Error loading example_builder.ui: " << error.what() << std::endl;
return nullptr;
    }

    // Get the GtkBuilder-instantiated window:
    Example_Builder* pWindow = nullptr;
    builder->get_widget_derived("window1", pWindow);
    if (!pWindow)
    {
std::cout << "Could not get 'window1' from the builder." << std::endl;
return nullptr;
    }
    return pWindow;
}

Example_Builder::Example_Builder(
    BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder)
    : Gtk::Window(cobject),
      m_builder(builder)
{
    Gtk::Toolbar* pToolbar = nullptr;
    builder->get_widget("toolbar1", pToolbar);
    if (pToolbar)
pToolbar->get_style_context()->add_class("primary-toolbar");

    Glib::RefPtr<Gio::SimpleActionGroup> refActions = Gio::SimpleActionGroup::create();
    refActions->add_action("quit", sigc::mem_fun(*this, &Example_Builder::on_file_quit));
    refActions->add_action("about", sigc::mem_fun(*this, &Example_Builder::on_help_about));
    refActions->add_action("help", sigc::mem_fun(*this, &Example_Builder::on_help_help));
    insert_action_group("win", refActions);

    Glib::RefPtr<Gtk::AccelGroup> refAccelGroup = Gtk::AccelGroup::create();
    add_accel_group(refAccelGroup);

    Gtk::MenuItem* pMenuItem = nullptr;
    builder->get_widget("new_item", pMenuItem);
    if (pMenuItem)
pMenuItem->add_accelerator("activate", refAccelGroup,
   GDK_KEY_n, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);

    builder->get_widget("open_item", pMenuItem);
    if (pMenuItem)
pMenuItem->add_accelerator("activate", refAccelGroup,
   GDK_KEY_o, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);

    builder->get_widget("save_item", pMenuItem);
    if (pMenuItem)
pMenuItem->add_accelerator("activate", refAccelGroup,
   GDK_KEY_s, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);

    builder->get_widget("quit_item", pMenuItem);
    if (pMenuItem)
pMenuItem->add_accelerator("activate", refAccelGroup,
   GDK_KEY_q, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);

    builder->get_widget("copy_item", pMenuItem);
    if (pMenuItem)
pMenuItem->add_accelerator("activate", refAccelGroup,
   GDK_KEY_c, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);

    builder->get_widget("cut_item", pMenuItem);
    if (pMenuItem)
pMenuItem->add_accelerator("activate", refAccelGroup,
   GDK_KEY_x, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);

    builder->get_widget("paste_item", pMenuItem);
    if (pMenuItem)
pMenuItem->add_accelerator("activate", refAccelGroup,
   GDK_KEY_v, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);

    builder->get_widget("help_item", pMenuItem);
    if (pMenuItem)
pMenuItem->add_accelerator("activate", refAccelGroup,
   GDK_KEY_F1, (Gdk::ModifierType)0, Gtk::ACCEL_VISIBLE);

    builder->get_widget("about_item", pMenuItem);
    if (pMenuItem)
pMenuItem->add_accelerator("activate", refAccelGroup,
   GDK_KEY_F7, (Gdk::ModifierType)0, Gtk::ACCEL_VISIBLE);

    show_all();
}

Example_Builder::~Example_Builder()
{
}

void Example_Builder::on_file_quit()
{
    hide();
}

void Example_Builder::on_help_about()
{
    Gtk::AboutDialog* pDialog = nullptr;
    m_builder->get_widget("aboutdialog1", pDialog);
    if (pDialog)
    {
pDialog->set_transient_for(*this);
pDialog->run();
pDialog->hide();
    }
}

void Example_Builder::on_help_help()
{
    std::cout << "Help not available." << std::endl;
}



int main( int argc, char* argv[])
{
    cout << "main 0:" << endl;
    auto app = Gtk::Application::create( argc, argv);
        Gtk::Window* win = do_builder();
    return app->run(*win);
}

// end of example_builder files.


On Mon, 2017-04-10 at 09:20 +0200, aitor_czr wrote:

Hi Marty,

On 04/10/2017 04:26 AM, Marty Moore wrote:
Hi Aitor,
Thanks for you video. Unfortuantely, I have very little eyesight, and can't watch videos. Golld luck on your project though.

I fixed my compiler error. I had missed correcting the $(COM P_RES) error. I was re-reading the advice and found it again.

My example_builder project now compiles, and generates a large  resouce.c file.

Here's the compiler output:
make -k 
/usr/lib/x86_64-linux-gnu/glib-2.0/glib-compile-resources --target=resource.c --sourcedir=`pwd` --generate-source  gresource.xml

Compilation finished at Sun Apr  9 19:49:54

Unfortunately, I get the following run-time error:

main 0:
Error loading example_builder.ui: The resource at '/builder/example_builder.ui' does not exist

As i said, i changed:

builder->add_from_resource( ... );

by:

builder->add_from_file( ... );

On the other hand, there were some mistakes in the .glade file, i think. Download this one:

http://gnuinos.org/Example-Builder/src/example_builder.ui

My questions are:
1. Is /builder/example_vuilder.ui the correct name for the resource?
2. where does that name come from? There isn't an actual file with that name, but it seems like that's the way resources are named. Does it come out of the .xml file?

Sorry for the confusion with the makefile error.
Thanks from the mountains of SW Colorado,
Marty

You can call this file *.ui, *.glade or *.xml...

You can also include the code of this file in a *.cpp, for example:

https://developer.gnome.org/gtkmm-tutorial/stable/sec-menus-examples.html.en

Take a look at the lines:
Glib::ustring ui_info =
    "<interface>"
    "  <!-- menubar -->"
    "  <menu id='menu-example'>"
    "    <submenu>"

[ ... etc ...]

Cheers,

  Aitor.









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

Re: builder gio::resource problem

aitor_czr
In reply to this post by Marty Moore-2

Dear Marty,

On 04/14/2017 10:06 PM, Marty Moore [hidden email] wrote:
Hi Aitor,
It finally ?works! Thank you all for your help!
It all boiled down to the makefile. It turns out that resouces need to
be compiled twice, once by Glib::compile_resources, and again by g++.
?This was not clear in chapter 12.4 of "Programming with gtkmm", at
least for dinosaurs like me.?

The only dinosaurs existent in the world are the cocodriles an the komodo dragons :)

  Aitor.




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

Re: [SOLVED] Re: builder gio::resource problem

Kjell Ahlstedt-2
In reply to this post by Marty Moore-2
Like you've noticed, most of the examples  in the gtkmm tutorial don't
contain makefiles. There's only one Makefile.am for building all of the
examples, and that's an input file to automake, which generates a huge
makefile.

The examples in the fairly new chapter 31 "Building applications",
https://developer.gnome.org/gtkmm-tutorial/stable/chapter-building-applications.html.en,
contain makefiles, called Makefile.example. These files are not listed
in the tutorial, it's just briefly mentioned that they exist. You have
to go to the source code, e.g.
https://git.gnome.org//browse/gtkmm-documentation/tree/examples/book/buildapp/step2?h=gtkmm-3-22 
to see them.

Kjell

Den 2017-04-14 kl. 22:06, skrev Marty Moore:

> Hi Aitor,
> It finally  works! Thank you all for your help!
>
> It all boiled down to the makefile. It turns out that resouces need to
> be compiled twice, once by Glib::compile_resources, and again by g++.
>  This was not clear in chapter 12.4 of "Programming with gtkmm", at
> least for dinosaurs like me.
>
> I suggest that chapter 12.4 be rewitten with more detail and examples
> of each stage of creating and loading gio::resources.  I would also
> suggest that a complete, simple, and working example including a
> makefile be added to chapter 12.4. While not everyone uses makefile,
> it would be a simple reference for all users.  The example of 12.5
> don't work, because their focus in on menus, and some required pieces
> (.glade files, makefiles) are missing.
>

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