Posted: Tue 07 Apr 2009, 22:38
Sorry for the additional work involved, MUguest. I fixed this in 0.2.5-1.To compile it, I first installed vala 0.6.0.
This installed the required header.
READ-ONLY Archive
https://oldforum.puppylinux.com/
Sorry for the additional work involved, MUguest. I fixed this in 0.2.5-1.To compile it, I first installed vala 0.6.0.
This installed the required header.
Well I am only another Vala user, but thanks for the thanks:)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
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 ()
(Shameless plug, I know... )Here is the same result, but now without libglade, coded "by hand" with the native Gtk bindings.
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>
Here is the same code with void instead of int:# gtkamlc --pkg gtk+-2.0 buttonandtext.gtkaml
buttonandtext.vala:11.3-11.17: error: missing return statement at end of method body
Segmentation fault
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>
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 ()
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)
#
Code: Select all
valac --pkg gtk+-2.0 is.gs
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 ()
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);
So both methods run parallel.+++
------------
+++
+++
------------
+++
------------