| Author |
Message |
2byte
Joined: 09 Oct 2006 Posts: 356
|
Posted: Fri 20 Aug 2010, 20:48 Post subject:
Genie global and static variables? |
|
Trying to learn something so I can use Genie. This one has me stumped. How to define a global or static variable in Genie?
In the following code, in the signal handler on_new_clicked (), I would like to know how the variable 'count' could be defined as static, and how could it be defined outside the class as global? | Code: | [indent=4]
uses
Gtk
init
Gtk.init (ref args)
var test = new Testwin ()
test.show_all ()
Gtk.main ()
class Testwin : Window
init
title = "Test"
default_height = 100
default_width = 300
window_position = WindowPosition.CENTER
destroy += on_exit_clicked
var toolbar = new Toolbar ()
var new_button = new ToolButton.from_stock (STOCK_NEW)
var quit_button = new ToolButton.from_stock (STOCK_QUIT)
toolbar.add (new_button)
toolbar.add (quit_button)
new_button.clicked += on_new_clicked
quit_button.clicked += on_exit_clicked
var vbox = new VBox (false, 0)
vbox.pack_start (toolbar, false, true, 0)
add (vbox)
def private on_new_clicked ()
var count = 1
count += 1
var myStr = "New has been clicked " + count.to_string() + " times"
print("%s",myStr)
def private on_exit_clicked ()
Gtk.main_quit()
|
_________________
|
|
Back to top
|
|
 |
nikobordx
Joined: 23 May 2009 Posts: 84 Location: Bordeaux, France
|
Posted: Mon 30 Aug 2010, 05:41 Post subject:
Genie global and static variables? |
|
Hi,
Can you try this:
| Code: |
[indent=4]
uses
Gtk
init
Gtk.init (ref args)
var test = new Testwin ()
test.show_all ()
Gtk.main ()
count : int = 1
class Testwin : Window
init
title = "Test"
default_height = 100
default_width = 300
window_position = WindowPosition.CENTER
destroy.connect(on_exit_clicked)
var toolbar = new Toolbar ()
var new_button = new ToolButton.from_stock (STOCK_NEW)
var quit_button = new ToolButton.from_stock (STOCK_QUIT)
toolbar.add (new_button)
toolbar.add (quit_button)
new_button.clicked.connect(on_new_clicked)
quit_button.clicked.connect(on_exit_clicked)
var vbox = new VBox (false, 0)
vbox.pack_start (toolbar, false, true, 0)
add (vbox)
def private on_new_clicked ()
count += 1
var myStr = "New has been clicked " + count.to_string() + " times"
print("%s",myStr)
def private on_exit_clicked ()
Gtk.main_quit()
|
Do not use "new_button.clicked += on_new_clicked" but "new_button.clicked.connect(on_new_clicked)" because it's a deprecated syntax
Nicolas.
|
|
Back to top
|
|
 |
2byte
Joined: 09 Oct 2006 Posts: 356
|
Posted: Mon 30 Aug 2010, 08:48 Post subject:
|
|
Thank you Nicolas!
I kept trying to define it as var count or var count = 0 etc. I see you must use a different syntax for this purpose. It's confusing when you must use different ways to do things and there is no guide to go by. Of course I expect to have difficulties with any new programming language but Genie is pretty friendly to the self taught beginner. I really wish there were more tutorials and examples available.
There must be a decent source of information about Genie somewhere. So far the best I can find is Barry's Genie pages and this forum.
And thanks for the tip about the deprecated syntax. Saves me from asking another dumb question
_________________
|
|
Back to top
|
|
 |
nikobordx
Joined: 23 May 2009 Posts: 84 Location: Bordeaux, France
|
Posted: Mon 30 Aug 2010, 13:49 Post subject:
|
|
It's a pleasure to help.
I made some samples here: http://code.valaide.org/search/node/genie
You can find some informations here: http://live.gnome.org/Genie
Nicolas.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Mon 30 Aug 2010, 13:49 Post subject:
|
|
I will be glad when we get a stable version of vala/genie and the code that worked last month continues to work the next. I don't know how you keep up with it.
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
|