Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 25 May 2013, 03:48
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Vala and Genie programming
Post new topic   Reply to topic View previous topic :: View next topic
Page 8 of 35 [514 Posts]   Goto page: Previous 1, 2, 3, ..., 6, 7, 8, 9, 10, ..., 33, 34, 35 Next
Author Message
b100dian

Joined: 07 Apr 2009
Posts: 5

PostPosted: Wed 08 Apr 2009, 07:01    Post subject:  

Quote:
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
Back to top
View user's profile Send private message 
MUguest

Joined: 09 Dec 2006
Posts: 73

PostPosted: Wed 08 Apr 2009, 07:08    Post subject:  

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
Back to top
View user's profile Send private message 
Mr. Maxwell


Joined: 30 Aug 2008
Posts: 215
Location: Nebraska, USA

PostPosted: Fri 10 Apr 2009, 10:11    Post subject:  

I've got everything working except my GUI. Confused 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.

_________________
Super amazing game!
Back to top
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Fri 10 Apr 2009, 10:43    Post subject:  

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
butonandtext.jpg
 Description   
 Filesize   5.03 KB
 Viewed   823 Time(s)

butonandtext.jpg

buttonandtext.tar.gz
Description 
gz

 Download 
Filename  buttonandtext.tar.gz 
Filesize  6.53 KB 
Downloaded  254 Time(s) 

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Fri 10 Apr 2009, 11:19    Post subject:  

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

Code:
[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

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
b100dian

Joined: 07 Apr 2009
Posts: 5

PostPosted: Fri 10 Apr 2009, 11:56    Post subject:  

Quote:
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:
<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
Back to top
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Fri 10 Apr 2009, 12:07    Post subject:  

Great, thanks for the nice example, Vlad!

It contains a slight error, the return type must be void, or I get this error:
Quote:
# 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:
<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>


Very Happy
Mark

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
Mr. Maxwell


Joined: 30 Aug 2008
Posts: 215
Location: Nebraska, USA

PostPosted: Fri 10 Apr 2009, 21:27    Post subject:  

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

Source:
Code:
[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]
shakespeareain_insulter.tar.gz
Description 
gz

 Download 
Filename  shakespeareain_insulter.tar.gz 
Filesize  6.98 KB 
Downloaded  260 Time(s) 

_________________
Super amazing game!
Back to top
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Fri 10 Apr 2009, 21:34    Post subject:  

Laughing well done Very Happy
Mark

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15109
Location: Paradox Realm

PostPosted: Fri 10 Apr 2009, 22:49    Post subject:  

Looks simple - good Smile

I have called that insulter is.gs
(why would anyone want to insult Shakespeare?) - ahem Embarassed
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:
# 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 WIKI
Back to top
View user's profile Send private message Visit poster's website 
Mr. Maxwell


Joined: 30 Aug 2008
Posts: 215
Location: Nebraska, USA

PostPosted: Fri 10 Apr 2009, 22:55    Post subject:  

You have to call the compiler with the GTK package flag.
Code:
valac --pkg gtk+-2.0 is.gs

_________________
Super amazing game!
Back to top
View user's profile Send private message 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15109
Location: Paradox Realm

PostPosted: Sun 12 Apr 2009, 13:31    Post subject:  

Thanks Mr. Maxwell

Now able to compile for gtk Smile
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:
[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 WIKI
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Sun 12 Apr 2009, 14:43    Post subject:  

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
Lobster1.tar.gz
Description 
gz

 Download 
Filename  Lobster1.tar.gz 
Filesize  6 KB 
Downloaded  200 Time(s) 

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Sun 12 Apr 2009, 16:10    Post subject:  

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

such code works:

Code:
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:
Quote:
+++
------------
+++
+++
------------
+++
------------


So both methods run parallel.

Mark

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15109
Location: Paradox Realm

PostPosted: Sun 12 Apr 2009, 16:23    Post subject:  

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 WIKI
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 8 of 35 [514 Posts]   Goto page: Previous 1, 2, 3, ..., 6, 7, 8, 9, 10, ..., 33, 34, 35 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1132s ][ Queries: 13 (0.0133s) ][ GZIP on ]