Page 24 of 26

Posted: Wed 17 Feb 2010, 16:17
by amigo
I read it like this:
"writing something like Gtkdialog which uses gtkbuilder instead of glade"
and since there is a program to convert glade to gtkbuilder *.ui format, then existing scripts for gtkdialog would be easier to convert to the new 'language'.

Posted: Wed 17 Feb 2010, 19:50
by technosaurus
amigo wrote:I read it like this:
"writing something like Gtkdialog which uses gtkbuilder instead of glade"
and since there is a program to convert glade to gtkbuilder *.ui format, then existing scripts for gtkdialog would be easier to convert to the new 'language'.
Precisely...

Though after checking with the gtkdialog tips thread, Zigbert had no recollection of any glade based projects - nor do I... Perhaps there is something in the 3.X series since I think the glade builder was part of it.... so that made me think it would be better to patch gtkdialog to replace glade with gtkbuilder - something I don't have the C background to do, but I did find this straightforward explanation of how to port from glade to gtkbuilder http://library.gnome.org/devel/gtk/unst ... ilder.html Disciple has already done something similar with "glipper-lite"

Posted: Wed 17 Feb 2010, 20:22
by amigo
Yeah, but that was for compiled code. To convert/re-write gtkdialog, there would probably be some bit of work to do re-working the syntax parser -although the convertor mentioned should outline the necessary changes.
I have my doubts that the resulting program would be significantly faster than gtkdialog though. Most of time it takes to start up is consumed in parsing/interpreting the script(or *.xml file) and then in linking all the libs which are needed. vala/genie may link a little faster than libglade, but that still leaves a very long list of libs which still must be linked at runtime: gtk, glib, atk, cairo, pango. That's what makes ordinary GTK2 programs much slower to start than their gtk1 counterparts -plus the extra time for dynamically-loading icons from STOCK.
But, I don't mean to put a damper on any effort to 'port' gtkdialog to genie. If the functionality could be reliably duplicated and a reliable convertor created for converting Puppy's hude stock of gtkdialog proggies... otherwise, it would probably be a disservice -I mean you already have a split between existing gtkdialog apps which work (or not) based on at least two versios of gtkdialog. introducing a new class of similar, but not directly incompatible, apps would only compund the situation.

Meanwhile, since Puppy relies so heavily on gtkdialog, and startup times can be significant, it would probably help greatly to use a 'pre-linked' version of gtkdialo. that should significantly reduce startup times. It would imply, though, that the program always be re-compiled and re-linked any time any of the pre-linked libs (listed above) are changed. Pre-linking can make a big difference on applications which link in lots of libs.
On my system which uses src2pkg to track dependencies, I have a script which determines the build order of all installed programs. glade consistently comes in last on the list as it requires more pre-installed libs than anything else on my system. (kde apps would probably be worse, but i don't use or build them). The point is that anything that uses libglade can benefit more than nearly anything else from pre-linking.

Posted: Wed 17 Feb 2010, 21:30
by technosaurus
I have been meaning to test out the effects of prelinking and LD_PRELOAD anyways... so I'll give that a shot...

to prelink do you just add LDFLAGS=-Wl,-z,now (instead of the default "lazy")...

I'm not certain that libglade is always needed unless using a .glade file... so maybe it would benefit from --as-needed (or is prelinking mutually exclusive to --as-needed?)

I don't think that it would be too easy to properly port all of gtkdialog to vala/genie - it would be easier (for me at least) to learn enough C to patch it to remove the glade requirement and use Gtk's gtkbuilder components instead.

Since so few people have used the glade portion of gtkdialog I doubt that my original idea to have just a gtkbuilder executable has any merit.

Posted: Thu 18 Feb 2010, 09:41
by disciple
I just built gtkdialog without glade and tested Pburn with it. It didn't seem to startup any faster, and only used 1 MB less memory, but that's enough to be worth it :)
I don't know whether it would have more effect on a gtkdialog program which uses glade files. But does anyone even know of any gtkdialog programs which use glade files? I don't. So if we really wanted to get rid of glade, we could simply build gtkdialog without it...

Posted: Fri 19 Feb 2010, 00:42
by technosaurus
apart from the 2-3 examples in the devx - there are none as far as I know - maybe something from another distro... did you have to make any patches to compile without glade? I don't recall seeing a --disable-glade or --without-glade option.

Posted: Fri 19 Feb 2010, 05:05
by disciple
I was lazy, so I hand edited the makefile.
I deleted everything to do with glade, except the line that said something along the lines of HAS_LIBGLADE="yes", which I changed to "no"... I don't know whether I needed to do both those things :)

One of the comments in the changelog implies that it will still build if you don't have Glade installed, so I imagine it would be fairly easy to add a --disable-glade.

New version

Posted: Wed 07 Apr 2010, 09:05
by ljfr
Hi,
A new version released last week:
March 31, 2010: Vala 0.8.0 released
see:http://live.gnome.org/Vala
regards,

Posted: Thu 08 Apr 2010, 19:14
by technosaurus
pasang-emas board game was recently rewritten in vala

Posted: Sat 05 Jun 2010, 20:12
by technosaurus
TrayIcon template - hacked from Nic's Status Icon Test (still has the same references)

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_stock(STOCK_HOME)
        trayicon.set_tooltip_text ("Hello, i'm a tooltip !")
        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_ABOUT, 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("1.0")
        about.set_program_name("Simple StatusIcon Test")
        about.set_comments("This is a Simple StatusIcon Test")
        about.set_copyright("Nicolas alias nikobordx")
        about.run()
        about.hide()
 
    def private exit_app ()
        Gtk.main_quit();
Compile with:
valac -C --pkg gtk+-2.0 genietray.gs
gcc -Os `pkg-config --cflags --libs gtk+-2.0` -o genietray genietray.c -s

Multi-call binaries in Vala

Posted: Mon 07 Jun 2010, 06:03
by technosaurus
Multi-call binaries in Vala (like in busybox)

Here is a very basic example using the symlink method:
(just make a symlink called hello and another called goodbye)

Code: Select all

class Demo.HelloWorld : GLib.Object
{
	public static int main(string[] args)
	{
		if ("hello" in args[0]){stdout.printf("Hello World!\n");}
		if ("goodbye" in args[0]){stdout.printf("Good-Bye World!\n");}
		return 0;
    }
}
Notes:
to get the alternate behavior such as in busybox <command> use args[1] instead ... for a larger number of commands a "case" would be better than a bunch of "if"s

The number of libraries available to vala is growing - with something like this it becomes possible to create an entire desktop in a single binary, thus saving significant code size.

Posted: Tue 08 Jun 2010, 05:27
by technosaurus
Vala-0.9.1 was released today - it breaks compatibility with most of the plugin examples I have seen including Valide, so I un-patched that part.

http://git.gnome.org/browse/vala/commit ... 4c1e5cf826

I built Valide-0.7.0 against that and it works great so far - unfortunately I had to also add gdl and upgrade gtk>2.18, glib>2.22, and gtksourceview(I just went ahead and compiled the latest... still no genie support though) ... gtk and glib upgrades are available from the ibiblio repo

Image

Genie and Sqlite

Posted: Sat 28 Aug 2010, 07:43
by growler
Having a go with my first forays into Genie programming.... appreciated all the examples in this thread.

I am trying to understand how to use the sqlite bindings and as an exercise I tried to convert an example in Vala to get the code below:

Code: Select all

[indent=4]
uses Sqlite
 
class SqliteSample : Object
 
    def callback (n_columns: int, values : array of string, column_names : array of string ) : int
        for i:int = 0 to n_columns
            print ("%s = %s\n", column_names[i], values[i]);

        print ("\n");
        return 0;

    def main (args : array of string): int
        var db = new Database 
        rc :int
        if args.length != 2
            print ("Usage: %s DATABASE SQL-STATEMENT\n", args[0])
            return 1

        if !FileUtils.test (args[1], FileTest.IS_REGULAR)
            print ("Database %s does not exist or is directory\n", args[1])
            return 1
		
        rc = Database.open (args[1], out db)
		
        if rc != Sqlite.OK
            print ("Can't open database: %d, %s\n", rc, db.errmsg ())
            return 1
 
        rc = db.exec (args[2], callback, null)
        if rc != Sqlite.OK
            print ("SQL error: %d, %s\n", rc, db.errmsg ())
            return 1
	
        return 0

init
    var SQLLiteTest = new SqliteSample
    params: array of string = {"/root/my-applications/PointOfSale.sqlite", "SELECT * FROM currencies"}
    SQLLiteTest.main(params)

I get:

Code: Select all

# valac --pkg sqlite3 sqlite.gs
sqlite.gs:39.5-39.10: error: syntax error, expected identifier
    params: array of string = {"/root/my-applications/PointOfSale.sqlite", "SELECT * FROM currencies"}
    ^^^^^^
Compilation failed: 1 error(s), 0 warning(s)

Appreciate any pointers.

XML-RPC with libSOUP

Posted: Sat 28 Aug 2010, 07:58
by growler
I am trying to get data from another application (webERP) over XML-RPC and started to play with libsoup - again there is a vala example which I have tried to hack into Genie but coming unstuck.

I can get the following to compile:

Code: Select all

indent=4]
/* Build with "valac --thread --pkg libsoup-2.4 yourfile.gs */
uses 
    Soup
	
init 
    var session = new Soup.SessionAsync ()
    ItemCode:string = "DVD-TOPGUN"
    UserName:string = "admin"
    Password:string = "weberp"
    
    var message = Soup.xmlrpc_request_new ("http://localhost/webERP/api/api_xml-rpc.php", "weberp.xmlrpc_GetStockBalance", typeof(string),ItemCode, typeof(string), UserName, typeof(string), Password)
    
    session.send_message(message)
    
    ResponseData:string = message.response_body.flatten().data
    
    ErrorNumber:int = typeof(int)
    try    
        xmlrpc_parse_method_response (ResponseData, -1, ErrorNumber)
        print("Stock of %s = %s",ItemCode, ResponseData)
        print("Error number %d", ErrorNumber)
    except
        print("Could not get webERP API location stock over XML-RPC")

    /*Is this how to create an associative array

    struct LocQty
          quantity : double
          loccode : string

    var StockQuantities = new array of LocQty
    ErrorMessage:string
    xmlrpc_extract_method_response(ResponseData, -1, ErrorMessage, typeof(array of dict of string, double), StockQuantities)
	*/
However, I can't get the last bit to xmlrpc_extract_method_response call to work - I think this is supposed to parse the response XML to nice variables. I think the 3rd parameter is supposed to be the data type of the return variables - which is an array of structs - the program as compiled returns:

Code: Select all

# ./SoupXMLRPC 
Stock of DVD-TOPGUN = <?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><array>
<data>
<value><int>0</int></value>
<value><array>
<data>
<value><struct>
<member><name>quantity</name>
<value><string>-1</string></value>
</member>
<member><name>loccode</name>
<value><string>MEL</string></value>
</member>
</struct></value>
<value><struct>
<member><name>quantity</name>
<value><string>0</string></value>
</member>
<member><name>loccode</name>
<value><string>TOR</string></value>
</member>
</struct></value>
</data>
</array></value>
</data>
</array></value>
</param>
</params>
</methodResponse>
Error number 24

So it works with a good XML message returned.

Do I then have to parse the XML using xml as per Caleb's jwmconf example or does that method xmlrpc_extract_method_response do the trick....

This is very steep learning for me, I am in WAY over my head here!

Hope someone has done this before and can point me in the right direction

Genie and Sqlite

Posted: Sat 28 Aug 2010, 09:59
by nikobordx
Hi growler,

Can you try this:

Code: Select all

[indent=4]

uses
    Sqlite
 
class SqliteSample : Object

    db : Sqlite.Database
 
    def callback (n_columns: int, values : array of string, column_names : array of string ) : int
        for i:int = 0 to n_columns
            print ("%s = %s\n", column_names[i], values[i])

        print ("\n");
        return 0;

    def begin (args : array of string) : int
        rc : int
        if args.length != 2
            print ("Usage: %s DATABASE SQL-STATEMENT\n", args[0])
            return 1

        if !FileUtils.test (args[0], FileTest.IS_REGULAR)
            print ("Database %s does not exist or is directory\n", args[0])
            return 1
      
        rc = Database.open (args[0], out db)
      
        if rc != Sqlite.OK
            print ("Can't open database: %d, %s\n", rc, db.errmsg ())
            return 1
 
        rc = db.exec (args[1], callback, null)
        if rc != Sqlite.OK
            print ("SQL error: %d, %s\n", rc, db.errmsg ())
            return 1
   
        return 0

init
    var SQLLiteTest = new SqliteSample
    test : array of string = {"/root/my-applications/PointOfSale.sqlite", "SELECT * FROM currencies"}
    SQLLiteTest.begin(test) 
Do not use "def main" in fonction, and "params" for arrays of string.

Nicolas.

Genie and Sqlite

Posted: Sat 28 Aug 2010, 10:53
by growler
Not sure what the first parameter was meant to be I made the parameters array to have a blank element since the DB file was the second element and the SQL the third. et voila ...

Code: Select all

test : array of string = {"", "/root/my-applications/PointOfSale.sqlite", "SELECT * FROM currencies"} 
Merci beaucoup Nicolas!!

Posted: Tue 31 Aug 2010, 02:11
by Mobeus
With Vala I can't find a means to explicitly close a file opened with FileStream.open. Is there not a wrapper for fclose()? How is it done?

tia
Mobeus

Posted: Tue 31 Aug 2010, 09:31
by nikobordx
Hi everyone,

growler:
Why not using

Code: Select all

test : array of string = {"/root/my-applications/PointOfSale.sqlite", "SELECT * FROM currencies"}
and change number of your "args" ?

Mobeus:
You don't need to specify to close the file because it is automatically closed!
In GLib's vapi file you can see on the class "FileStream":

Code: Select all

[CCode (cname = "FILE", free_function = "fclose", cheader_filename = "stdio.h")]
See you,
Nicolas.

Posted: Tue 31 Aug 2010, 09:33
by growler
Yes your solution is better.

Have you ever used libsoup - I can't get to grips with the

xmlrpc_extract_method_response method. I find the documentation very cryptic and spartan!!

Posted: Tue 31 Aug 2010, 10:16
by nikobordx
I made only 2 small samples with libsoup:
http://code.valaide.org/content/genie-l ... ple-sample
http://code.valaide.org/content/genie-l ... ple-server

I can help you if you post your code (if your code is not top secret ! :D )

Nicolas.