auto-scripts/auto-vala


Home Back

#!/bin/bash

AUTHOR="Fabio Di Matteo"
VERSION="0.1.0"

 
#Controllo se e' stato fornito il nome del progetto
if [ "$1" = "" ];then
    echo "E' necessario fornire il nome del progetto come parametro."
    exit 1 ;
fi
 
#Se la directory del progetto esiste gia' esco.
mkdir $1 2>/dev/null
if [ "$?" != 0 ];then
    echo "Il progetto esiste."
    exit 1 ;
fi
 
cd $1


echo "Make resorces folder..."
mkdir res


echo "Make main.vala..."
echo "
using Gtk;



public class mainWindow : GLib.Object {

    public  Button btn;
    public  Window window;
    public  Label myLabel;
    int c=0;

    public void on_button1_clicked ()
    {
        c++;
        window.set_title(\"You have clicked \"+ c.to_string()+\" times\");
        myLabel.set_text(\"You have clicked \"+ c.to_string()+\" times\");

    }
    
    public mainWindow()
    {

    }

    public void show()
    {
        try { 

            var builder = new Builder ();
            builder.add_from_resource(\"/app/res/gui.ui\");

            btn=builder.get_object (\"button1\") as Button;
            myLabel=builder.get_object(\"label1\") as Label;
            btn.clicked.connect(on_button1_clicked);

            window = builder.get_object (\"window1\") as Window;
            window.destroy.connect(Gtk.main_quit);
            window.show_all ();


        } catch (Error e) {
            stderr.printf (\"Problem on gui loading: %s\n\", e.message);

        }
    }



}

int main (string[] args)
{
    Gtk.init (ref args);
    mainWindow myWin = new mainWindow();
    myWin.show();

    Gtk.main ();
    return 0;
}

" > main.vala ;


echo "Make meson.build"
echo "
project('$1', 'vala', 'c')
gtk_dep = dependency('gtk+-3.0')


r = run_command('compile_resources.sh')
if r.returncode() != 0
   error('Errors on compile resources')
endif

#check os 
os=build_machine.system()

if os == 'linux'
  executable('$1', 'main.vala', 'resources.c', dependencies : [gtk_dep])
endif
if os == 'windows'
  executable('$1', 'main.vala', 'resources.c', dependencies : [gtk_dep], link_args : ['-mwindows'])
endif


" > meson.build;


echo "Make resources"
echo "
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<gresources>
  <gresource prefix=\"/app/res\">
    <file>gui.ui</file>
  </gresource>
</gresources>


" > res/resources.xml;


echo  "
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!-- Generated with glade 3.20.2 -->
<interface>
  <requires lib=\"gtk+\" version=\"3.20\"/>
  <object class=\"GtkWindow\" id=\"window1\">
    <property name=\"can_focus\">False</property>
    <child>
      <object class=\"GtkBox\">
        <property name=\"visible\">True</property>
        <property name=\"can_focus\">False</property>
        <property name=\"orientation\">vertical</property>
        <child>
          <object class=\"GtkLabel\" id=\"label1\">
            <property name=\"visible\">True</property>
            <property name=\"can_focus\">False</property>
            <property name=\"label\" translatable=\"yes\">You have clicked 0 times</property>
            <attributes>
              <attribute name=\"scale\" value=\"5\"/>
            </attributes>
          </object>
          <packing>
            <property name=\"expand\">False</property>
            <property name=\"fill\">True</property>
            <property name=\"position\">0</property>
          </packing>
        </child>
        <child>
          <object class=\"GtkButton\" id=\"button1\">
            <property name=\"label\" translatable=\"yes\">Cliccami</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>
    <child>
      <placeholder/>
    </child>
  </object>
</interface>


" > res/gui.ui ;

echo "#!/bin/bash

cd res
echo 'Building resources.c ...'
glib-compile-resources --generate-source resources.xml
mv resources.c ../


" > compile_resources.sh;
chmod +x compile_resources.sh



Powered by Code, a simple repository browser by Fabio Di Matteo