Thread overview
Embed glade file into a binary
Sep 17, 2016
Geert
Sep 17, 2016
llmp
Sep 17, 2016
Geert
Sep 17, 2016
Lodovico Giaretta
Sep 17, 2016
Geert
September 17, 2016
I've compiled a small application, and it runs when i execute it at the same directory where is the glade file.

Is there a way to embed a glade file into a binary?
September 17, 2016
On Saturday, 17 September 2016 at 18:18:37 UTC, Geert wrote:
> I've compiled a small application, and it runs when i execute it at the same directory where is the glade file.
>
> Is there a way to embed a glade file into a binary?

enum fileContent = import(file);

fileContent is a static array of ubyte.
the compiler must know the path to "file" via -J"dir/subdir"
September 17, 2016
On Saturday, 17 September 2016 at 18:36:52 UTC, llmp wrote:
> On Saturday, 17 September 2016 at 18:18:37 UTC, Geert wrote:
>> I've compiled a small application, and it runs when i execute it at the same directory where is the glade file.
>>
>> Is there a way to embed a glade file into a binary?
>
> enum fileContent = import(file);
>
> fileContent is a static array of ubyte.
> the compiler must know the path to "file" via -J"dir/subdir"



Thanks!
I've just tried that, but i get an error message with the xml file content, and this at the end:

// More XML here...

                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">2</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">True</property>
            <property name="fill">True</property>
            <property name="position">6</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>
': File name too long

// End of message.




This is part of the application code:

public import gtk.Main;
import gtk.TreeIter, gtk.TreeModel, gtk.TreeModelIF;
import std.concurrency, core.thread, std.math, std.parallelism;
import modelo, extra;

enum fileContent = import("vista.glade");

// More code here ...


class Vista{
private:
    Window window;
    string gladefile = "vista.glade";
    Modelo obj_model = new Modelo();

public:
    Button btn_exit;
    Button btn_format;
    ComboBoxList cbo_list;
    Switch swi_bnivel;
    Label lbl_info;
    Entry txt_et;
    int test_val = 3;

    //this(){ } // constructor

    void init_ui(){
        Builder g = new Builder();
        g.addFromFile(fileContent);

        window = cast(Window)g.getObject("Win_01");
    }

    // More code here ...
}

// Compile command:
// ldc -w -disable-linker-strip-dead -deps=txt_deps.txt  main.d extra.d vista.d modelo.d X.d Xlib.d -J="/home/directory_glade_file_path/" -L-lX11 `pkg-config --cflags --libs gtkd-3`

September 17, 2016
On Saturday, 17 September 2016 at 19:01:10 UTC, Geert wrote:
> On Saturday, 17 September 2016 at 18:36:52 UTC, llmp wrote:
>> On Saturday, 17 September 2016 at 18:18:37 UTC, Geert wrote:
>>> I've compiled a small application, and it runs when i execute it at the same directory where is the glade file.
>>>
>>> Is there a way to embed a glade file into a binary?
>>
>> enum fileContent = import(file);
>>
>> fileContent is a static array of ubyte.
>> the compiler must know the path to "file" via -J"dir/subdir"
>
> Thanks!
> I've just tried that, but i get an error message with the xml file content, and this at the end:
>
> // More XML here...
>
>                 <property name="visible">True</property>
>                 <property name="can_focus">True</property>
>                 <property name="receives_default">True</property>
>               </object>
>               <packing>
>                 <property name="expand">True</property>
>                 <property name="fill">True</property>
>                 <property name="position">2</property>
>               </packing>
>             </child>
>           </object>
>           <packing>
>             <property name="expand">True</property>
>             <property name="fill">True</property>
>             <property name="position">6</property>
>           </packing>
>         </child>
>       </object>
>     </child>
>   </object>
> </interface>
> ': File name too long
>
> // End of message.
>
> This is part of the application code:
>
> [...]
>
> enum fileContent = import("vista.glade");
>
> [...]
>
>         g.addFromFile(fileContent);
>
>         window = cast(Window)g.getObject("Win_01");
>     }
>
>     // More code here ...
> }
>
> [...]

addFromFile expects the *name* of the file. Because you already have the *contents* of the file, you should change method. Maybe addFromString is the correct one, but I'm not sure.
September 17, 2016
On Saturday, 17 September 2016 at 19:07:33 UTC, Lodovico Giaretta wrote:
>
> addFromFile expects the *name* of the file. Because you already have the *contents* of the file, you should change method. Maybe addFromString is the correct one, but I'm not sure.


"g.addFromString(fileContent);"

It works now. Thanks Lodovico and llmp!