Genie global and static variables?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
2byte
Posts: 353
Joined: Mon 09 Oct 2006, 18:10

Genie global and static variables?

#1 Post by 2byte »

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: Select all

[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()



nikobordx
Posts: 84
Joined: Sat 23 May 2009, 09:08
Location: Bordeaux, France

Genie global and static variables?

#2 Post by nikobordx »

Hi,

Can you try this:

Code: Select all

[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.

2byte
Posts: 353
Joined: Mon 09 Oct 2006, 18:10

#3 Post by 2byte »

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 :?


nikobordx
Posts: 84
Joined: Sat 23 May 2009, 09:08
Location: Bordeaux, France

#4 Post by nikobordx »

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.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#5 Post by technosaurus »

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.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Post Reply