Vala and Genie programming

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
b100dian
Posts: 5
Joined: Tue 07 Apr 2009, 22:35

#101 Post by b100dian »

To compile it, I first installed vala 0.6.0.
This installed the required header.
Sorry for the additional work involved, MUguest. I fixed this in 0.2.5-1.
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#102 Post by MU »

b100dian,
thank you very much.
I wanted to send you a mail about it tomorrow, but you were faster, great!

I will update the pet tomorrow to your latest version.

:D
Mark

(P.S. Just to avoid confusion, I'm MUguest, I write from school using a second login.)
b100dian
Posts: 5
Joined: Tue 07 Apr 2009, 22:35

#103 Post by b100dian »

luckily I was watching the referrals since yesterday's release was downloaded before being announced.. :) don't hesitate to file bugs or write me if this version doesn't fix it.

Vlad
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#104 Post by MU »

yes, I'll mail you, when I find issues, or people report them.
As you can see by this long thread, Vala/Genie really have found great interest by several Puppy users, and even Barry Kauler, the Puppy founder, is very attracted.
It always was hard for programming languages to enter Puppy, because size/dependencies play a big role in this small system.
I remember 2005, when wxBasic (2 MB compressed with upx, 6 MB uncompressed) was rejected, because it was too "bloated" :lol:

So Vala/Genie are really on a good way, if they find interest even under such "critical" conditions :)

Thanks very much for your work, Mark
MUguest
Posts: 73
Joined: Sat 09 Dec 2006, 16:40

#105 Post by MUguest »

Updated Gtkaml to 0.2.5.1.
Mark
b100dian
Posts: 5
Joined: Tue 07 Apr 2009, 22:35

#106 Post by b100dian »

So Vala/Genie are really on a good way, if they find interest even under such "critical" conditions

Thanks very much for your work, Mark
Well I am only another Vala user, but thanks for the thanks:)

However, I have one question regarding Vala/Genie, Puppy Linux and Gtkaml: I am in the process of re-writing the parsing to better integrate with Vala's parser and symbol resolver, and to expand Gtkaml's features.

Q: How do you feel about the libxml2 dependency (given the Puppy Linux constraints) and would a GLib/GMarkup approach be favored?

Thanks, and sorry for the offtopic.
Vlad
MUguest
Posts: 73
Joined: Sat 09 Dec 2006, 16:40

#107 Post by MUguest »

Hi Vlad,
I think libxml2 is in Puppy since ages, and will stay in it, as many programs depend on it. So it is ok, if you stay with it.
Mark
User avatar
Mr. Maxwell
Posts: 215
Joined: Sat 30 Aug 2008, 23:56
Location: Nebraska, USA

#108 Post by Mr. Maxwell »

I've got everything working except my GUI. :? All I need is a button and a text entry field, the problem is I have no idea how to 1) pack the widgets so the text entry field is on top of the button 2) how to make, display text, and delete text in a text entry field.

Thanks in advance.
[url=http://www.tribalwars.net/3389956.html]Super amazing game![/url]
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#109 Post by MU »

I attach an example.
It uses project.glade, that can be modified with Glade.

If you do not want to use libglade, I would need your program, so that I could add the code you miss to it.

Note, that you must compile it with libglade and gobject.
If you don't use the ValaIDE, compile it with:
valac -C --pkg gtk+-2.0 --pkg libglade-2.0 --pkg gmodule-2.0 main.gs

If you use the valaide, add those libraries in the options.
On my current system, the ide crashes, if I go to the options, so I added them with an editor to buttonandtext.vide.

Mark
Attachments
butonandtext.jpg
(5.03 KiB) Downloaded 1256 times
buttonandtext.tar.gz
(6.53 KiB) Downloaded 469 times
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#110 Post by MU »

Here is the same result, but now without libglade, coded "by hand" with the native Gtk bindings.

Code: Select all

[indent=2]

//-- declare global variables --
entry : Gtk.Entry


//-- define the methods --

def on_button_clicked ()

  entry.set_text("text changed!")


//-- main program --

init
  Gtk.init (ref args)

  //-- build the window --

  var window = new Gtk.Window (Gtk.WindowType.TOPLEVEL)
  window.set_default_size (300, 10)
  window.destroy += Gtk.main_quit
  
  
  var vbox = new Gtk.VBox(false , 1)
  vbox.border_width = 10
  vbox.spacing = 10
  window.add (vbox)

  
  //-- the entry is global, so that it can be modified later --

  entry = new Gtk.Entry ()
  entry.set_editable(false)
  entry.set_text("hello")
  vbox.pack_start (entry, false, true, 0);


  var button = new Gtk.Button.with_label("ok")
  vbox.pack_start (button, false, true, 0);


  //-- define actions --

  button.clicked += on_button_clicked;


  //-- show the window, hand over to the Gtk mainloop --
  
  window.show_all ()
  Gtk.main ()

Mark
b100dian
Posts: 5
Joined: Tue 07 Apr 2009, 22:35

#111 Post by b100dian »

Here is the same result, but now without libglade, coded "by hand" with the native Gtk bindings.
(Shameless plug, I know... )

Here is the same code "by hand" with gtkaml (Mark, you once said you 'haven't tested the library')

Code: Select all

<Window xmlns="Gtk" xmlns:g="http://gtkaml.org/0.2"
  g:name="ButtonAndText" destroy="{Gtk.main_quit}" type="{WindowType.TOPLEVEL}">

  <VBox homogeneous="false" spacing="10" border-width="10">
    <Entry g:public="entry" editable="false" text="hello" expand="false" />
    <Button label="ok" expand="false" clicked='entry.text="text changed!"'/>
  </VBox>

<![CDATA[

  static int main (string [] args)
  {
    Gtk.init (ref args);
    var window = new ButtonAndText();
    window.set_default_size (300, 10);
    window.show_all ();
    Gtk.main ();
  }

]]>
</Window>
Compiles with:
gtkamlc --pkg gtk+-2.0 buttonandtext.gtkaml

(Unfortunately gtkaml only supports vala atm, not genie)

Vlad
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#112 Post by MU »

Great, thanks for the nice example, Vlad!

It contains a slight error, the return type must be void, or I get this error:
# gtkamlc --pkg gtk+-2.0 buttonandtext.gtkaml
buttonandtext.vala:11.3-11.17: error: missing return statement at end of method body
Segmentation fault
Here is the same code with void instead of int:

Code: Select all

<Window xmlns="Gtk" xmlns:g="http://gtkaml.org/0.2" 
  g:name="ButtonAndText" destroy="{Gtk.main_quit}" type="{WindowType.TOPLEVEL}"> 

  <VBox homogeneous="false" spacing="10" border-width="10"> 
    <Entry g:public="entry" editable="false" text="hello" expand="false" /> 
    <Button label="ok" expand="false" clicked='entry.text="text changed!"'/> 
  </VBox> 

<![CDATA[ 

  static void main (string [] args) 
  { 
    Gtk.init (ref args); 
    var window = new ButtonAndText(); 
    window.set_default_size (300, 10); 
    window.show_all (); 
    Gtk.main (); 
  } 

]]> 
</Window>
:D
Mark
User avatar
Mr. Maxwell
Posts: 215
Joined: Sat 30 Aug 2008, 23:56
Location: Nebraska, USA

#113 Post by Mr. Maxwell »

I got my first complete Genie program done! It's a shakespeareain insulter! :lol:

Source:

Code: Select all

[indent=4]

uses
    GLib

//-- declare global variables --
entry : Gtk.Entry


//-- define the methods --

def on_button_clicked ()

    cola:array of string = {"artless", "bawdy", "beslubbering", "bootless", "churlish", "cockered", "clouted", "craven", "currish", "dankish", "dissembling", "droning", "errant", "fawning", "fobbing", "froward", "frothy", "gleeking", "goatish", "gorbellied", "impertinent", "infectious", "jarring", "loggerheaded", "lumpish", "mammering", "mangled", "mewling", "paunchy", "pribbling", "puking", "puny", "qualling", "rank", "reeky", "roguish", "ruttish", "saucy", "spleeny", "spongy", "surly", "tottering", "unmuzzled", "vain", "venomed", "villainous", "warped", "wayward", "weedy", "yeasty"}
    colb:array of string = {"base-court", "bat-fowling", "beef-witted", "beetle-headed", "boil-brained", "clapper-clawed", "clay-brained", "common-kissing", "crook-pated", "dismal-dreaming", "dizzy-eyed", "doghearted", "dread-bolted", "earth-vexing", "elf-skinned", "fat-kidneyed", "fen-sucked", "flap-mouthed", "fly-bitten", "folly-fallen", "fool-born", "full-gorged", "guts-griping", "half-faced", "hasty-witted", "hedge-born", "hell-hated", "idle-headed", "ill-breeding", "ill-nurtured", "knotty-pated", "milk-livered", "motley-minded", "onion-eyed", "plume-plucked", "pottle-deep", "pox-marked", "reeling-ripe", "rough-hewn", "rude-growing", "rump-fed", "shard-borne", "sheep-biting", "spur-galled", "swag-bellied", "tardy-gaited", "tickle-brained", "toad-spotted", "unchin-snouted", "weather-bitten"}
    colc:array of string = {"apple-john", "baggage", "barnacle", "bladder", "boar-pig", "bugbear", "bum-bailey", "canker-blossom", "clack-dish", "clotpole", "coxcomb", "codpiece", "death-token", "dewberry", "flap-dragon", "flax-wench", "flirt-gill", "foot-licker", "fustilarian", "giglet", "gudgeon", "haggard", "harpy", "hedge-pig", "horn-beast", "hugger-mugger", "joithead", "lewdster", "lout", "maggot-pie", "malt-worm", "mammet", "measle", "minnow", "miscreant", "moldwarp", "mumble-news", "nut-hook", "pigeon-egg", "pignut", "puttock", "pumpion", "ratsbane", "scut", "skainsmate", "strumpet", "varlot", "vassal", "whey-face", "wagtail"}

    insult:string = "Thou "
    insult = insult.concat(cola[GLib.Random.int_range(0, 49)], " ", colb[GLib.Random.int_range(0, 49)], " ", colc[GLib.Random.int_range(0, 49)], "!")
    entry.set_text(insult)

//-- main program --

init
    Gtk.init (ref args)

    //-- build the window --

    var window = new Gtk.Window (Gtk.WindowType.TOPLEVEL)
    window.set_default_size (400, 10)
    window.destroy += Gtk.main_quit
 
 
    var vbox = new Gtk.VBox(false , 1)
    vbox.border_width = 10
    vbox.spacing = 10
    window.add (vbox)

 
    //-- the entry is global, so that it can be modified later --

    entry = new Gtk.Entry ()
    entry.set_editable(false)
    entry.set_text("")
    vbox.pack_start (entry, false, true, 0);


    var button = new Gtk.Button.with_label("Insult me again!")
    vbox.pack_start (button, false, true, 0);


    //-- define actions --

    button.clicked += on_button_clicked;
    on_button_clicked()


    //-- show the window, hand over to the Gtk mainloop --
 
    window.show_all ()
    Gtk.main ()
The source and binary are attached.[/code]
Attachments
shakespeareain_insulter.tar.gz
(6.98 KiB) Downloaded 475 times
[url=http://www.tribalwars.net/3389956.html]Super amazing game![/url]
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#114 Post by MU »

:lol: well done :D
Mark
User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#115 Post by Lobster »

Looks simple - good :)

I have called that insulter is.gs
(why would anyone want to insult Shakespeare?) - ahem :oops:
This is what I get - have had similar problems with other gtk programs.
Am I missing a library (using Puppy 4.2.smp)?
Should I use Puppy 4.12 for Genie?

Code: Select all

# valac si.gs
si.gs:7.9-7.11: error: The symbol `Gtk' could not be found
entry : Gtk.Entry
        ^^^
Compilation failed: 1 error(s), 0 warning(s)
#
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D
User avatar
Mr. Maxwell
Posts: 215
Joined: Sat 30 Aug 2008, 23:56
Location: Nebraska, USA

#116 Post by Mr. Maxwell »

You have to call the compiler with the GTK package flag.

Code: Select all

valac --pkg gtk+-2.0 is.gs
[url=http://www.tribalwars.net/3389956.html]Super amazing game![/url]
User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#117 Post by Lobster »

Thanks Mr. Maxwell

Now able to compile for gtk :)
We are now trying to combine the earlier random monkey generator
with your code as a basis

so far we can input text - say 'in'
but need another output window?
some way of putting the generated random letters in a second window . . .

Anyway the code we have so far:

Code: Select all

[indent=4]

//outputting random generated text from input and outputting result 

uses
    GLib

//-- declare global variables --
entry : Gtk.Entry


//-- define the methods --

def getRandomNumber(RangeFrom:int, RangeTo:int) : int  /* function to create random number between range */
    return GLib.Random.int_range(RangeFrom,RangeTo)

def getRandomChar() : char                             /* function to generate ascii codes from a-z and space (32) */
    num:int = getRandomNumber(0,27)
    if num == 0
        num = 32
    else
        num = num + 96
    return (char) num

def addRandomChar(myText:string) : string              /* function add text from command line */
    var retText = new StringBuilder
    retText.append(myText)
    retText.append_c(getRandomChar())
    return retText.str

def IsEmpty(theText:string) : bool
    if theText == null
        return true
    if theText == ""
        return true
    return false

def on_button_clicked ()
    theText:string = entry.get_text()
    if IsEmpty(theText) 
        entry.set_text("Please enter some text")
        return
    entry.set_text("running")
    theText = theText.down()
    myText:string = ""

    timer : Timer = new Timer()
    timer.start()

    do
        do
            myText = addRandomChar(myText)
        while theText.len() != myText.len()
        if theText != myText
            myText = ""
    while theText != myText
    entry.set_text(myText)

//-- main program --

init
    Gtk.init (ref args)

    //-- build the window --

    var window = new Gtk.Window (Gtk.WindowType.TOPLEVEL)
    window.set_default_size (400, 50)
    window.destroy += Gtk.main_quit
 
    var vbox = new Gtk.VBox(false , 1)
    vbox.border_width = 10
    vbox.spacing = 10
    window.add (vbox)
 
    //-- the entry is global, so that it can be modified later --

    entry = new Gtk.Entry ()
    entry.set_editable(true)
    entry.set_text("")
    vbox.pack_start (entry, false, true, 0);

    var button = new Gtk.Button.with_label("Insult me again!")
    vbox.pack_start (button, false, true, 0);

    //-- define actions --

    button.clicked += on_button_clicked;
    on_button_clicked()

    //-- show the window, hand over to the Gtk mainloop --
 
    window.show_all ()
    Gtk.main ()


Any help or tips?
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#118 Post by MU »

I attach an example, Lobster.

I have one problem:
I would like to display the random words in the label in the second window.
But it does not get updated, until the whole function has finished.

It might be doable with threads, but I found no example yet, how to use threads in Genie.
Mark
Attachments
Lobster1.tar.gz
(6 KiB) Downloaded 400 times
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#119 Post by MU »

ah fine, threads can be used.
but together with gtk it is complicated.

such code works:

Code: Select all

def mythread2() : int
    for var i = 1 to 100 
        print ("%s" , "+++")
        Thread.usleep(100)

    return 0

def mythread3() : int
    for var i = 1 to 100
        print ("%s" , "------------")
        Thread.usleep(100)

    return 0

def static on_button_clicked () 


    //mythread()

    Thread.create( (ThreadFunc)mythread3, false);
    Thread.create( (ThreadFunc)mythread2, false);

must be used in a full program, and compiled with:
valac --thread --pkg gtk+-2.0 main.gs

This will print stuff like:
+++
------------
+++
+++
------------
+++
------------
So both methods run parallel.

Mark
User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#120 Post by Lobster »

Thanks Mark - hopefully will look at it tomorrow with Shadow

Threads in particular are interesting - and the first example is using a library you are using in NewyearPup? - does not seem to be in 4.2 . . .

Really appreciate the help.
In fact I might suggest Shadow uses your Genie + Java ISO that might be ideal for him . . .
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D
Post Reply