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 Mon 20 Oct 2014, 17:27
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Genie global and static variables?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [5 Posts]  
Author Message
2byte

Joined: 09 Oct 2006
Posts: 357

PostPosted: 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
View user's profile Send private message 
nikobordx

Joined: 23 May 2009
Posts: 84
Location: Bordeaux, France

PostPosted: 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
View user's profile Send private message 
2byte

Joined: 09 Oct 2006
Posts: 357

PostPosted: 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 Confused

_________________

Back to top
View user's profile Send private message 
nikobordx

Joined: 23 May 2009
Posts: 84
Location: Bordeaux, France

PostPosted: 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
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: 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.
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [5 Posts]  
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.0547s ][ Queries: 11 (0.0043s) ][ GZIP on ]