Embed glade file into a binary

Geert via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 17 12:01:10 PDT 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`



More information about the Digitalmars-d-learn mailing list