Page 25 of 26

Posted: Tue 31 Aug 2010, 14:36
by Mobeus
Hi Nicolas
You don't need to specify to close the file because it is automatically closed!
Oh that's quite awkward. That makes Vala the only language I have ever used that decides when the file can be closed instead of the programmer. :(

Consider:
Open a file for writing
Write a bash script to it.
Flush the file
chmod it
try to execute the new script from within your vala program
Error: File is busy!

I can code around this by putting the file writing in a sub-routine, the file is closed when the routine finishes and goes out of scope.

FileStream.close(fp) would be so much better. :?

Mobeus

Posted: Tue 31 Aug 2010, 15:11
by nikobordx
Try this:

Code: Select all

[indent=4]

// Build with valac --pkg gio-2.0 yourfile.gs
 
init
    create_new_file()

// Use this function when file is not exist
def static create_new_file ()
    var file = File.new_for_path("test.sh")
    var thefile_stream = file.create (FileCreateFlags.NONE, null)
    var data_stream = new DataOutputStream (thefile_stream)
    data_stream.put_string ("echo \"hello\"", null) // Write something in file
    FileUtils.chmod ("test.txt", 0755) // Chmod the file to executable
    Process.spawn_command_line_async("sh test.sh") // Exec the file

// Use this function when file already exist
def static use_file ()
    var file = File.new_for_path("test.sh")
    var renamed = file.set_display_name ("samplefile.bak", null)
    var thefile_stream = file.create (FileCreateFlags.NONE, null)
    var data_stream = new DataOutputStream (thefile_stream)
    data_stream.put_string ("echo \"hello\"", null) // Write something in file
    renamed.delete(null)
    FileUtils.chmod ("test.txt", 0755) // Chmod the file to executable
    Process.spawn_command_line_async("sh test.sh") // Exec the file
Nicolas.

Posted: Tue 31 Aug 2010, 23:53
by Mobeus
Hi Nicolas,

I appreciate your help and examples. I never would have thought to even try something like that. This is an example of what I used that “Failed to execute child process “/tmp/test.sh

XML-RPC

Posted: Wed 01 Sep 2010, 22:43
by growler
I think I took your example as the base - it looks like you converted from Evan Nemmerson's vala example. I posted the code I have been working with - slightly modified version of your code in this thread above. I did post it almost at the same time as the sqlite code I was playing with that you already figured out for me!

I was hoping that the xmlrpc_extract_method_response of the libsoup library might be the method to call to parse the xml returned from the response into an array of structs but I am at a complete loss as to how to call this. What is GValue? and how do we get at the **error parameter presumably an out array - seems to be an int and a string - perhaps a dict or a struct. There is something funny going on with the number of parameters as the /usr/share/vala/valide/libsoup.val or something like that file shows I think 5 parameters for xmlrpc_parse_method_response from memory (which is dangerously bad) and if I give any more than 4 I get compile errors. What does that method do anyway?

Many thanks again for your help Nicolas

Posted: Mon 06 Sep 2010, 03:05
by 01micko
Hi guys and gals

I know next to nought about genie programming but using Nicolas' template for tray icons I came up with something useful.. mainly coded in bash :lol: :roll: , depending on 2 tray icons compiled in genie.

It's a little daemon to monitor RAM usage and it actually works! It gives warnings when RAM usage is high and critical and offers to start pprocess (if installed) or top.

I just tried it out on my XO-1 and it worked a charm, with mavrothal's xopup based on lupu-510. Xo's only have 256M of RAM and I have no swap file. Once Puppy is loaded there is about 40M free, then you load Chromium and there is less than 5M left.. enter my program.

I called it freeramdaemon and it has a simple config gui too.

There is a menu entry under 'system'

Maybe the technosaur might want to expand on this..

Sources are included and I commented here and there.

Enjoy
Cheers

Edit1: just removed some useless code so now it's 0.1.1 (not changed in script tho :wink: )

Edit2: updated to 0.2. It seemed more logical to give warnings when the actual amount of RAM becomes critical, not the percentage. :roll: . I found this out on my fast box when I was getting the warning when I still had 200M of free RAM! :lol: Now the 'warning' kicks in at 32M and the critical warning kicks in at 8M, giving the user enough chance to do something about the situation without losing their work. :wink:

Posted: Mon 06 Sep 2010, 18:40
by Mobeus
I too am new to Genie and have just posted my first utility written with it. It’s a tiny GUI firewall installer and configuration tool. The source code is available there too. http://www.murga-linux.com/puppy/viewto ... 608#448608

Thanks go to Barry for his Genie pages and to Nicolas and everyone else in this thread for the help and examples.

Mobeus

GValueArray

Posted: Mon 06 Sep 2010, 23:28
by growler
Getting some great looking little apps coming together - judging by Mobeus's firewall config GUI and Mickos memory usage tray icon. Nice work guys.

I am struggling with this XML-RPC thing.

It seems that xmlprc_parse_method_response is meant to return the values from the message into a GValueArray. However, it seems that I can't iterate through the GValueArray in a for loop - the compiler complains that there is no iterable method for a GValueArray - How then to enumerate the values returned from the GValueArray - when the values could be different data types?

Appreicate any ideas as always.

I have found it hard to start with genie due to the lack of documentation and it would have been completely impossible to even approach without Barry's docs and Nicolas's patience so once again I am indebted to the puppy team.

Trying to figure out how to call the library functions from examiniation of the bindings /usr/share/vala/vapi files and valadoc.org is pretty hit and miss for me too. In some ways a knowlege of C seems to be required to get anywhere with genie. Ironic really as why I was trying to learn genie was to avoid C/C++/Java type syntax!! I am making progress ... I think.

I hope I can produce something worthwhile to give back - but certainly having fun learning.

Posted: Tue 07 Sep 2010, 05:29
by 01micko
Congrats Mobeus on a proper genie app, it might be a good replacement for our tired looking firewall app :wink: . I like the look of it and will give you feedback once I have tested.

I updated the freeramdaemon app, see the comments in "Edit 2" in my post above.

Thanks growler, but credit for the genie part must go to Nicolas. 8) . I put his and my forum names in the info window.

Cheers

Posted: Tue 07 Sep 2010, 05:48
by Lobster
Great stuff guys :)

Mobeus you might like to add some of my GROWL code to your firewall app :)
http://murga-linux.com/puppy/viewtopic. ... 216#335216

Posted: Fri 10 Sep 2010, 22:04
by 01micko
Further to Nicolas' work with tray icons, I figured out how you can use any icon (well I only tried .xpm, but I guess .png might work, perhaps .gif).

It uses gtk and gdk. I made a working battery monitor for the XO-1 olpc machine, using 12 of these compiled execs and a small bash daemon tying them together. Not very orthodox, but nonetheless useful. :lol: (and small.. 10K compressed :wink: .. will post in XO thread at a later date)

Here it is:

Code: Select all

/*power applet, 01micko 20100910*/
/*thanks to technosaurus and nikobordx*/
/*icons must be in /usr/share/icons*/

[indent=4]
 
/* Build with valac --pkg gtk+-2.0 --pkg gdk-x11-2.0 eightychg.gs */
 
uses
    Gtk
    Gdk
 
init
    Gtk.init (ref args)
    var test = new StatusIconTest ()
    Gdk.init (ref args)
    test.show_all ()
    Gtk.main ()
 
class StatusIconTest : Widget
 
    trayicon : StatusIcon
    menu : Menu
 
    init
        /* Create tray icon */
        trayicon = new StatusIcon.from_file("/usr/share/icons/eightychg.xpm")
        trayicon.set_tooltip_text ("Bat 80%")
        trayicon.set_visible(true)
        trayicon.activate += icon_clicked
        create_menu()
 
        /* Create menu */
    def private create_menu ()
        menu = new Menu()
        var menuItem = new ImageMenuItem.from_stock(STOCK_INFO, null)
        menuItem.activate += about_clicked
        menu.append(menuItem)
        var menuItem2 = new ImageMenuItem.from_stock(STOCK_QUIT, null)
        menuItem2.activate += exit_app
        menu.append(menuItem2)
        menu.show_all()
        trayicon.popup_menu += def (button, time)
            show_popup(button, time)
 
        /* Show popup menu */
    def private show_popup (button : uint, time : uint)
        menu.popup(null, null, null, button, time)
 
    def private icon_clicked ()
        print("I know you have clicked on the icon !!")
 
def private about_clicked ()
        var about = new AboutDialog ()
        about.set_version("0.2")
        about.set_program_name("Battery Widget")
        about.set_comments("Your battery is 80% charging")
        about.set_copyright("Copyright (c)01micko, GPL 2010")
        about.run()
        about.hide()
 
    def private exit_app ()
        Gtk.main_quit();
Have fun! :D

Cheers

Posted: Sat 11 Sep 2010, 03:31
by technosaurus
@micko - I posted almost the same thing a couple pages back, but seeing it again after adding a loop to iterate each parameter for a minimp3 player to play multiple files it sparked an idea that could greatly reduce resource usage if the same tray app worked for all the various status updates

this is what I used in C to loop through passed parameters:

Code: Select all

int w = 0;
for(w = 1; w < (argc) ;w++){
    //argv[w] will be the Nth parameter passed to the program
}
I know vala can but can genie even use argv and argc?

if so it could make it possible to use an ash script to act as a daemon to periodically update the changing parameters in a file that is read by the program or in the case of icons change a symlink

for icons something like

Code: Select all

trayicon = new StatusIcon.from_file(HOME, "/.trayapp/", argv[w], ".png")
//the ash script will change the symlink in /root/.trayapp/current_parameter.png
I can't recall the code to read from a file in vala/genie but it would resemble something like

Code: Select all

string infobox = read_contents_of_file(HOME, "/.trayapp/", argv[w], ".nfo")
//the ash script will update /root/.trayapp/current_parameter.nfo with current status info
The possibilities are endless here (I previously posted a script that will read info for battery status in jemimah's vattery thread as well as an ash script that will generate a basic percentage bar as an xpm icon)

here are some basics that could be used:

Code: Select all

#!/bin/ash
getprocinfo() {
#/proc/file string_number_in_line string_always_in_line_but_not_others
   grep $3 $1 |sed "s/: */ /" |cut -d " " -f $2
}
BATREMAIN=`getprocinfo /proc/acpi/battery/BAT1/state 3 remaining`
BATFULL=`getprocinfo /proc/acpi/battery/BAT1/info 4 last`
echo mAh remaining $BATREMAIN
echo mAh capacity $BATFULL
BATPERCENT=$((100*$BATREMAIN/$BATFULL))
BATSTATE=`getprocinfo /proc/acpi/battery/BAT1/state 3 charging`
echo percent charged $BATPERCENT
echo the battery is $BATSTATE
CPU0TEMP=`getprocinfo /proc/acpi/thermal_zone/TZ00/temperature 2 temp`
echo CPU Temperature is $CPU0TEMP C
LIDSTATUS=`getprocinfo /proc/acpi/button/lid/LID/state 2 state`
echo Lid is $LIDSTATUS
PLUGSTATUS=`getprocinfo /proc/acpi/ac_adapter/ACAD/state 2 state`
echo AC adapter is $PLUGSTATUS
KERNVER=`getprocinfo /proc/version 3 Linux`
echo Your Kernel is version $KERNVER
UPTIMESECS=`getprocinfo /proc/uptime 1 "."`
echo Your computer has been running for $UPTIMESECS seconds
IDLETIMESECS=`getprocinfo /proc/uptime 2 "."`
echo Your computer has been idle for $IDLETIMESECS seconds
MEMTOT=`getprocinfo /proc/meminfo 2 MemTotal`
echo Total RAM is $MEMTOT kb
MEMFREE=`getprocinfo /proc/meminfo 2 MemFree`
echo Total free RAM is $MEMFREE kb
SWPTOT=`getprocinfo /proc/meminfo 2 SwapTotal`
echo Total Swap is $SWPTOT kb
SWPFREE=`getprocinfo /proc/meminfo 2 SwapFree`
echo Total free Swap is $SWPFREE kb
and the xpm percent bar generator:

Code: Select all

#!/bin/ash
FILENAME=barimage
FGCOLOR=\#000
BGCOLOR=None
PERCENT=50
WIDTH=100
HEIGHT=24
BARSTRING=""
q=0 #should have used for loops
y=0 #not while loops - oops
#get values from input
for x in $@; do
case $x in
   width*)WIDTH=`echo $x |cut -d = -f 2`;;
   height*)HEIGHT=`echo $x |cut -d = -f 2`;;
   fg*)FGCOLOR=`echo $x |cut -d = -f 2`
      [ "$FGCOLOR" != "None" ] && FGCOLOR=\#$FGCOLOR;;
   bg*)BGCOLOR=`echo $x |cut -d = -f 2`
      [ "$BGCOLOR" != "None" ] && BGCOLOR=\#$BGCOLOR;;
   name*)FILENAME=`echo $x |cut -d = -f 2`;;
   *%)PERCENT=`echo $x |cut -d % -f 1`;;
   vert*)VERTICAL="true";;
   *)   echo "usage "$0" XX% name=filename fgcolor=XXX bgcolor=XXX height=XXX width=XXX [vertical]
      colors can be 3 or 6 digit hexadecimal or None ... default is horizontal bars" && exit
      ;;
esac
done


#write header to file
echo '/* XPM */' >${FILENAME}.xpm
echo 'static char *'$FILENAME'_xpm[] = {' >>${FILENAME}.xpm
echo '"'$WIDTH $HEIGHT '2 1",' >>${FILENAME}.xpm
echo '"0 c '$BGCOLOR'",' >>${FILENAME}.xpm
echo '"1 c '$FGCOLOR'",' >>${FILENAME}.xpm

if [ "$VERTICAL" == "true" ];then #vertical bars
BARTOP=$(($HEIGHT*$PERCENT/100))
#generate each line of the image
   while [ "$q" -lt $HEIGHT ]; do
   q=$(($q + 1))
      if [ "$q" -lt $BARTOP ];then
         while [ "$z" -lt $WIDTH ]; do
            BARSTRING=${BARSTRING}0
            z=$(($z + 1))
         done
      else
         while [ "$z" -lt $WIDTH ]; do
            BARSTRING=${BARSTRING}1
            z=$(($z + 1))
         done
      fi
   echo '"'$BARSTRING'"' >>${FILENAME}.xpm
   BARSTRING=""
   z=0
   done
else #horizontal bars
#generate one line of the image
   BARMAX=$(($WIDTH*$PERCENT/100))
   while [ "$q" -lt $BARMAX ]; do
      q=$(($q + 1))
      BARSTRING=${BARSTRING}1
   done
   while [ "$q" -le $WIDTH ]; do
      BARSTRING=${BARSTRING}0
      q=$(($q + 1))
   done
#write a line for each pixel of height
   while [ "$y" -le $HEIGHT ]; do
   echo '"'$BARSTRING'"' >>${FILENAME}.xpm
      y=$(($y + 1))
   done
fi

echo '};' >>${FILENAME}.xpm
#defaultimageeditor ${FILENAME}.xpm

Posted: Sat 11 Sep 2010, 09:09
by nikobordx
Hi Micko,

I made some changes in your code to avoid warnings !

Code: Select all

/*power applet, 01micko 20100910*/
/*thanks to technosaurus and nikobordx*/
/*icons must be in /usr/share/icons*/

[indent=4]
 
/* Build with valac --pkg gtk+-2.0 --pkg gdk-x11-2.0 eightychg.gs */
 
uses
    Gtk
    Gdk
 
init
    Gtk.init (ref args)
    var test = new StatusIconTest ()
    Gdk.init (ref args)
    test.show_all ()
    Gtk.main ()
 
class StatusIconTest : Widget
 
    trayicon : StatusIcon
    menu : Menu
 
    init
        /* Create tray icon */
        trayicon = new StatusIcon.from_file("/usr/share/icons/eightychg.xpm")
        trayicon.set_tooltip_text ("Bat 80%")
        trayicon.set_visible(true)
        trayicon.activate.connect(icon_clicked) // Changed
        create_menu()
 
        /* Create menu */
    def private create_menu ()
        menu = new Menu()
        var menuItem = new ImageMenuItem.from_stock(Stock.INFO, null) // Changed
        menuItem.activate.connect(about_clicked) // Changed
        menu.append(menuItem)
        var menuItem2 = new ImageMenuItem.from_stock(Stock.QUIT, null) // Changed
        menuItem2.activate.connect(exit_app) // Changed
        menu.append(menuItem2)
        menu.show_all()
        trayicon.popup_menu.connect(show_popup) // Changed
 
        /* Show popup menu */
    def private show_popup (button : uint, time : uint)
        menu.popup(null, null, null, button, time)
 
    def private icon_clicked ()
        print("I know you have clicked on the icon !!")
 
    def private about_clicked ()
        var about = new AboutDialog ()
        about.set_version("0.2")
        about.set_program_name("Battery Widget")
        about.set_comments("Your battery is 80% charging")
        about.set_copyright("Copyright (c)01micko, GPL 2010")
        about.run()
        about.hide()
 
    def private exit_app ()
        Gtk.main_quit()
Nicolas.

Trying to add small launcher program to the status icon...

Posted: Sun 12 Sep 2010, 11:18
by paulhomebus
What I would like to know, is there any way to stop it loading multiple windows of xampp_start.sh??


xampp_start.sh

Code: Select all

#!/bin/sh

export MAIN_DIALOG="
<window title=\"XAMPP Webserver\" icon-name=\"xampp\" window-position=\"1\">

<vbox>

	<vbox>
		<hbox>
			<frame Start Webserver>
				<button>
					<input file>/usr/share/midi-icons/go48.png</input>
					<action>/opt/lampp/lampp start &</action>
				 </button>
			</frame>
			<frame Stop Webserver>
				<button>
					<input file>/usr/share/midi-icons/shutdown48.png</input>
					<action>/opt/lampp/lampp stop &</action>
				</button>
			</frame>
			<frame XAMPP Config>
				<button>
					<input file>/usr/share/midi-icons/setup48.png</input>
					<action>geany /opt/lampp/etc/httpd.conf &</action>
				 </button>
			</frame>
		</hbox>
	</vbox>

	<vbox>
		<hbox>
			<frame Start Mysql>
				<button>
					<input file>/usr/share/midi-icons/go48.png</input>
					<action>/opt/lampp/lampp startmysql &</action>
				 </button>
			</frame>

			<frame Stop Mysql>
				<button>
					<input file>/usr/share/midi-icons/shutdown48.png</input>
					<action>/opt/lampp/lampp stopmysql &</action>
				</button>
			</frame>
			<frame Mysql Config>
				<button>
					<input file>/usr/share/midi-icons/setup48.png</input>
					<action>geany /opt/lampp/etc/my.cnf &</action>
				</button>
			</frame>
		</hbox>
	</vbox>
	
	<vbox>
		<hbox>
			<frame Start Apache>
				<button>
					<input file>/usr/share/midi-icons/go48.png</input>
					<action>/opt/lampp/lampp startapache &</action>
				 </button>
			</frame>

			<frame Stop Apache>
				<button>
					<input file>/usr/share/midi-icons/shutdown48.png</input>
					<action>/opt/lampp/lampp stopapache &</action>
				</button>
			</frame>
			<frame PHP Config>
				<button>
					<input file>/usr/share/midi-icons/setup48.png</input>
					<action>geany /opt/lampp/etc/php.ini &</action>
				</button>
			</frame>
		</hbox>
	</vbox>
	
	<vbox>
		<hbox>
			<frame Start ProFTP>
				<button>
					<input file>/usr/share/midi-icons/go48.png</input>
					<action>/opt/lampp/lampp startftp &</action>
				 </button>
			</frame>
			<frame Stop ProFTP>
				<button>
					<input file>/usr/share/midi-icons/shutdown48.png</input>
					<action>rxvt -e /opt/lampp/lampp stopftp &</action>
				</button>
			</frame>
			<frame ProFTP config>
				<button>
					<input file>/usr/share/midi-icons/setup48.png</input>
					<action>geany /opt/lampp/etc/proftpd.conf &</action>
				 </button>
			</frame>

		</hbox>
	</vbox>	
	
	<vbox>
		<hbox>
			<frame View Log>
				<button>
					<input file>/usr/local/lib/X11/pixmaps/edit48.png</input>
					<action>geany /opt/lampp/logs/access_log &</action>
				 </button>
			</frame>

			<frame View Errors>
				<button>
					<input file>/usr/local/lib/X11/pixmaps/edit48.png</input>
					<action>geany /opt/lampp/logs/error_log &</action>
				</button>
			</frame>

			<frame Open WWW folder>
				<button>
					<input file>/usr/local/lib/X11/pixmaps/folder48.png</input>
					<action>rox /opt/lampp/htdocs &</action>
				</button>
			</frame>

			<frame Start Security>
				<button>
					<input file>/usr/share/midi-icons/security64.png</input>
					<action>rxvt -e /opt/lampp/lampp security &</action>
				</button>
			</frame>
			<frame Start ApacheSSL>
				<button>
					<input file>/usr/share/midi-icons/security64.png</input>
					<action>/opt/lampp/lampp startssl &</action>
				</button>
			</frame>
		</hbox>
	</vbox>	
	
</vbox>
		
</window>
"
gtkdialog3 --program=MAIN_DIALOG
unset MAIN_DIALOG

xampp.gs
using the statusicon example code..

Code: Select all

[indent=4] 
  
/* Build with valac --pkg gtk+-2.0 yourfile.gs */ 
  
uses 
    Gtk 
  
init 
    Gtk.init (ref args) 
    var test = new StatusIconTest () 
    test.show_all () 
    Gtk.main () 
  
class StatusIconTest : Widget 
  
    trayicon : StatusIcon 
    menu : Menu 
  
    init 
        /* Create tray icon */ 
        trayicon = new StatusIcon.from_file("/usr/share/icons/hicolor/64x64/apps/xampp.png") 
        trayicon.set_tooltip_text ("Click to activate XAMPP Webserver Menu") 
        trayicon.set_visible(true) 
        trayicon.activate.connect(icon_clicked) 
        create_menu() 
  
        /* Create menu */ 
    def private create_menu () 
        menu = new Menu() 
        var menuItem0 = new ImageMenuItem.from_stock("Open XAMPP Webserver Menu", null) 
        menuItem0.activate.connect(icon_clicked) 
        menu.append(menuItem0)
        var menuItem = new ImageMenuItem.from_stock(STOCK_ABOUT, null) 
        menuItem.activate.connect(about_clicked) 
        menu.append(menuItem) 
        var menuItem2 = new ImageMenuItem.from_stock(STOCK_QUIT, null) 
        menuItem2.activate.connect(exit_app) 
        menu.append(menuItem2) 
        menu.show_all() 
        trayicon.popup_menu.connect(show_popup)
  
        /* Show popup menu */ 
    def private show_popup (button : uint, time : uint) 
        menu.popup(null, null, null, button, time) 
  
    def private icon_clicked () 
        Process.spawn_command_line_async("sh /usr/sbin/xampp_start.sh") // Exec the file 
  
def private about_clicked () 
        var about = new AboutDialog () 
        about.set_version("1.0") 
        about.set_program_name("XAMPP MENU 1.0") 
        about.set_comments("by paulhomebus 4 Puppylinux") 
        about.set_copyright("Copyright (c)paulhomebus, GPL 2010") 
        about.run() 
        about.hide() 
  
    def private exit_app () 
        Gtk.main_quit();

Posted: Sun 12 Sep 2010, 12:25
by 01micko
At the top of the bash script you can find the process ID and kill it if it's running I guess before the gtkdialog is executed, I've done this before with gtkdialog apps.

HTH

Cheers

PS, oh yeah, as a habit of mine I name the gtkdialog variable anything but 'MAIN_DIALOG', usually giving it a unique name.. the command ps will find it and you can grep it out.

Posted: Sun 12 Sep 2010, 22:26
by paulhomebus
Got it....

bottom of my bash script...

Code: Select all

</window>
"
    if [[ "`which XAMPP`" != "" && "`ps | grep XAMPP | wc -l`" != 2 ]]; then
    
	unset XAMPP &
		
		else
			      	gtkdialog3 --program=XAMPP

    fi
Man that was simple, pity it took me 2hrs to figure it out! doh - lol :oops:

Geany with Genie syntax highlightling

Posted: Wed 22 Sep 2010, 06:50
by growler
I have been using Nicolas's Nicoedit but I have previously used geany and become accustomed to it's short-cuts for indentation etc... it may be chunckier but I am not good with different.

The geany guys have made my day with syntax highlighting for genie!! In case others wish to know...

Close file

Posted: Thu 07 Oct 2010, 10:25
by nikobordx
Hi Mobeus and other,

In fact you can close the file if you want !
Use pointer !

Code: Select all

 [indent=4]

init
    fn : string = "/tmp/test.sh"
    doit(fn)
   
def doit (filename : string)
    fp0 : FileStream* = FileStream.open (filename, "w")
    fp1 : unowned FileStream = fp0
    fp1.puts ("ls /root")
    fp1.flush()
    delete(fp0) // Close the file !
    FileUtils.chmod (filename, 0750)
    try
        Process.spawn_command_line_async (filename)
    except ex : GLib.Error
        print ("%s", ex.message)
I hope this is correct.

See you,
Nicolas.

Posted: Mon 11 Oct 2010, 20:59
by technosaurus
@all - improved gtkbuilder example
This one works with the default values from glade3 and uses a user input gtkbuilder xml file (from glade)

//save as gtkbox.vala

Code: Select all

using Gtk;

int main (string[] args) {     
    Gtk.init (ref args);

    try {
        var builder = new Builder ();
        builder.add_from_file (args[1]);
        builder.connect_signals (null);
        var window = builder.get_object ("window1") as Window;
        window.destroy.connect(Gtk.main_quit);
        window.show_all ();
        Gtk.main ();
    } catch (Error e) {
        stderr.printf ("Could not load UI: %s\n", e.message);
        return 1;
    }
    return 0;
}

to build:
valac --pkg gtk+-2.0 --pkg gmodule-2.0 gtkbox.vala

to run:
./gtkbox anygtkbuilderui

Note: glade sets the gtkwindow id to window1 - don't change it
... may change it later to require the id to be the same as the basename of the ui file (if I can figure out basename in vala)

how to connect signals?

Posted: Sun 05 Dec 2010, 19:17
by hoggie
Many of the existing code examples contain depricated code by connecting Signals.
i.E.

Code: Select all

destroy += Gtk.main_quit
is replaced by

Code: Select all

destroy.connect(Gtk.main_quit)
but i didn't find out how to repace the following Syntax:

Code: Select all

button.clicked += def (btn)
	title = "Hello World"
	btn.label = "Hello World"
Has anyone a Idea how to do this?

hello-gtk

Posted: Fri 24 Dec 2010, 09:12
by foxtwo
How about this code?

[indent=4]
/* Build with valac --pkg gtk+-2.0 hello-gtk.gs
valac --version 0.7.4 */
uses
Gtk

init
Gtk.init(ref args)
var test = new TestWindow()
test.show_all()
Gtk.main()

class TestWindow : Window

button : Button

init
title = "Test Window"
default_height = 250
default_width = 250
window_position = WindowPosition.CENTER
destroy.connect (Gtk.main_quit)
button = new Button.with_label("Click Me")
button.clicked.connect (btnclick)
add(button)

def btnclick ()
title = "you have clicked"
button.label = "Hello World"