Vala and Genie programming

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
nikobordx
Posts: 84
Joined: Sat 23 May 2009, 09:08
Location: Bordeaux, France

#421 Post by nikobordx »


caleb72
Posts: 57
Joined: Fri 15 May 2009, 12:44

#422 Post by caleb72 »

This topic hasn't really moved much for a while.

I'm trying again to find time to teach myself Genie and I've got some ideas in mind for some utilities but as we know a huge amount of documentation isn't on hand although there are some good examples in this thread.

What I thought I might do to start teaching myself Gtk programming in Genie is to translate the current Vala Gtk+ Examples into Genie syntax.

I thought it might be useful to have a direct document that could help me see the same examples in Genie syntax that newcomers to Vala have been enjoying previously.

Ideally it would be nice to flesh it out into a full tutorial, but I doubt I would find the time. In any case I really learn by example alot of the time and can't guarantee that I would explain the underlying theories of what's happening with great accuracy as I really know nothing about Gtk in general and am relying on just being able to understand how to use it much like people learning a foreign language through emersion.

Anyway - to my question. Would such an exercise be worthwhile to publish somewhere for other Puppyites?

At the least it's a personal exercise to get me across Gtk programming in Genie - but it could potentially be added somewhere for common reference if it's going to be useful.

Regards
Caleb

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

#423 Post by nikobordx »

Hi Caleb,

I've created some gtk examples in http://code.valaide.org/

I'm also working on a code generator for genie, and i will make a website with many sample.

Nicolas.

caleb72
Posts: 57
Joined: Fri 15 May 2009, 12:44

#424 Post by caleb72 »

Oooh - thanks for that. I didn't realise there were so many samples available. I've bookmarked it for future reference.

Actually - that makes me more determined to do what I was doing so that I can compare the code that I think looks right with how other people are doing the same thing. Thanks for that.

Regards
Caleb

caleb72
Posts: 57
Joined: Fri 15 May 2009, 12:44

#425 Post by caleb72 »

I've been managing to convert the Vala GTK+ examples I've seen quite easily into Genie - even managed to convert a GtkBuilder example.

Although I have to say, it's a bit weird implementing callback methods via GtkBuilder (in Vala anyway). I haven't tried these peculiarities in Genie. Things like this:
If you declare the callback methods inside a class and/or namespace you have to prefix the callback method in Glade with the namespace/class name in lower case letters and with underscores. For example, Foo.MyBar.on_button_clicked would be foo_my_bar_on_button_clicked in Glade
And this:
If you want the callback methods to be instance methods instead of static methods you have to annotate them with the [CCode(instance_pos=-1)] attribute and pass the instance to connect_signals(...) instead of null
Bizarre.

My instinct in coding these signals/callback methods is to have the GUI XML file as per normal and then I would have an Application class which defines all the callback methods, initiates the gui interface and interacts with the other classes that define the application model as a whole. If the advice above applies to Genie that would mean either I have to create slightly weird signals in that they won't look exactly the same as the callback methods they trigger, or I would need to include this weird CCode thingy in my code which looks incomprehensible to me.

I'm guessing I could also define the callback methods outside of the Application class I create, but that seems a bit weird to me.

Just wondering if there are other people out there using GtkBuilder either in Vala or Genie that could put some perspective on this for me. It may be that I'm just not getting it.

Regards
Caleb

User avatar
ttuuxxx
Posts: 11171
Joined: Sat 05 May 2007, 10:00
Location: Ontario Canada,Sydney Australia
Contact:

#426 Post by ttuuxxx »

Why doesn't someone add tabs to NicoEdit and then I could ditch Geany ??
ttuuxxx
http://audio.online-convert.com/ <-- excellent site
http://samples.mplayerhq.hu/A-codecs/ <-- Codec Test Files
http://html5games.com/ <-- excellent HTML5 games :)

caleb72
Posts: 57
Joined: Fri 15 May 2009, 12:44

#427 Post by caleb72 »

ttuuxxx wrote:Why doesn't someone add tabs to NicoEdit and then I could ditch Geany ??
ttuuxxx
I actually like Geany - but it doesn't have syntax highlighting for Genie which is a bit of a bummer. In fact, the Genie syntax highlighting is the only reason I use NicoEdit. I know there's others I could use for that but NicoEdit came with 4.3 so I figure - why not?

It would be nice to have a pIDE though don't you think? Something like Geany but possibly lighter, developed in something like vala or genie and developed/maintained by Puppy people.

Regards
Caleb

User avatar
ttuuxxx
Posts: 11171
Joined: Sat 05 May 2007, 10:00
Location: Ontario Canada,Sydney Australia
Contact:

#428 Post by ttuuxxx »

caleb72 wrote:
ttuuxxx wrote:Why doesn't someone add tabs to NicoEdit and then I could ditch Geany ??
ttuuxxx
I actually like Geany - but it doesn't have syntax highlighting for Genie which is a bit of a bummer. In fact, the Genie syntax highlighting is the only reason I use NicoEdit. I know there's others I could use for that but NicoEdit came with 4.3 so I figure - why not?

It would be nice to have a pIDE though don't you think? Something like Geany but possibly lighter, developed in something like vala or genie and developed/maintained by Puppy people.

Regards
Caleb
I actually like codebrowser but the only thing I don't like about it is that you have to rt click the document and select on the list close page, it should have a close tab on the main gui user interface.
http://www.murga-linux.com/puppy/viewto ... 6ddcb65e87 and at 178kb pet its 1/4 the size of Geany and its smaller than nicoedit if you remove all the vala and genie deps that you need to install to run it on say 2.14X or 3, early 4 series. etc

ttuuxxx
http://audio.online-convert.com/ <-- excellent site
http://samples.mplayerhq.hu/A-codecs/ <-- Codec Test Files
http://html5games.com/ <-- excellent HTML5 games :)

caleb72
Posts: 57
Joined: Fri 15 May 2009, 12:44

#429 Post by caleb72 »

Hmmm - anyone know if you can split source over multiple lines or have multi-line string values in Genie source?

eg:

Code: Select all

do_action(parameter1, parameter2, parameter3,
        parameter4, parameter5)
and:

Code: Select all

this_string = """I am a multi-line string.
Hope this is what you were looking for."""
These examples are Python syntax, but I'm hoping there is a way in Genie to accomplish the same tasks. So far none of the example I've seen break a line of code over multiple lines of source and I can't find any reference to the notion. So I'm wondering if Genie just doesn't have this.

Regards
Caleb

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

#430 Post by nikobordx »

Hi Caleb,

For the first i don't know !
Try this:

def do_action (
parameter1
parameter2
)

For the second i use:

test : string = """
blah blah blah
blah blah blah blah blah
blah blah blah blah blah blah blah
"""

And it's work !

Nicolas.

caleb72
Posts: 57
Joined: Fri 15 May 2009, 12:44

#431 Post by caleb72 »

Thanks Nicholas - don't know why I was having trouble with that second one. :oops:

The first idea didn't seem to work. Oh well - it's just handy if you've got a massive list of parameters sometimes to break it up over multiple lines for readability. I can, of course, live without it.

Regards
Caleb

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

#432 Post by nikobordx »

Hi Caleb,

If you have another question you can contact the "genie" creator Jamie at jamie.mccrack@gmail.com

Nicolas.

caleb72
Posts: 57
Joined: Fri 15 May 2009, 12:44

#433 Post by caleb72 »

You know - that's an excellent idea. I'm not sure if he's inundated with email about Genie - but if not, he might even get a kick out of knowing people are learning the Genie syntax.

Regards
Caleb

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#434 Post by Lobster »

Barry has announced a focus on Genie, with updates
http://www.puppylinux.com/blog/?viewDetailed=01181

This page much of it based on Barry's page could do with splitting into Genie and Vala and updating
http://puppylinux.org/wikka/GenieProgramming

:)
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

caleb72
Posts: 57
Joined: Fri 15 May 2009, 12:44

#435 Post by caleb72 »

Just put together a small example of using the libxml library in Genie.

The program just reads in the .jwmrc-tray file and prints out its components - nodes, attributes and text.

It's fairly meaningless on its own but I put it together to learn a bit more about the libxml library as I am working on something related to parsing JWM configuration files.

Code: Select all

[indent=3]
uses 
	Xml

class JWMReader : Object
	path : string

	init
		Parser.init()

	final
		Parser.cleanup()

	def run()
		var doc = Parser.parse_file(path)
		var node = doc->get_root_element()
		parse_node(node)

	def set_source(pathname : string)
		path = pathname

	def private parse_node(node : Xml.Node*)
		if node is null
			return
		case node->type
			when ElementType.ELEMENT_NODE
				print "NODE: %s", node->name
				if node->properties is not null
					get_attributes(node, node->properties)
				if node->children is null
					node = node->next
				else
					node = node->children
			when ElementType.TEXT_NODE
				if not (node->content.strip() is "")
					print "TEXT: %s", node->content.strip()
				if node->next is null
					node = node->parent->next
				else
					node = node->next
			when ElementType.COMMENT_NODE
				node = node->next
			default
				print("DO NOT RECOGNISE NODE!")
				return	
		parse_node(node)

	def private get_attributes(node : Xml.Node*, properties : Xml.Attr*)
		if properties is null
			return
		print "ATTR: %s VALUE: %s", properties->name, node->get_prop(properties->name)
		properties = properties->next
		get_attributes(node, properties)

init
	var reader = new JWMReader()
	reader.set_source("/root/.jwmrc-tray")
	reader.run()
If you actually wanted to compile this, the command would be:

Code: Select all

valac --pkg libxml-2.0 indent.gs
You'll get a warning about unreachable code but it doesn't stop anything from running. Perhaps I should have used an 'if/else' construct rather than just an 'if' what I used there - but I believe it's doing what I wanted it to.

If you feel compelled to pick this to pieces - that's fine. I might learn something out of it.

A note about libxml. I've only just tried to get my head around this and I come from a Python background where I don't have to worry too much about memory management. Genie doesn't either except I believe if pointers are specifically created. Apparently this is your way of saying I want to handle this manually.

There are pointers in the above code and I have not specifically cleaned them up so this code in a larger program may cause issues. The Parser.cleanup() line may not actually completely clean this stuff up.

That may all be complete bollocks, but it's just the understanding I have right now. I will be looking into how to handle these pointers better as I progress.

Regards
Caleb

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#436 Post by rarsa »

disciple wrote:And how much easier do you think it would be to learn vala than C?
C : Pretty easy to learn, and there are a lot of resources. The problem is that it is not easy to program well. It's very easy to write crappy code that's difficult to understand and maintain.

Vala : Although the language is simple, documentation is still lacking so you must resort to look at examples in other languages to understand how to do some things in Vala. It is easier to write maintainable programs. Vala is a more modern language which takes care of many of C pitfalls (e.g. memory management) but to use it properly you better have an Object Oriented background. (most of the examples I've seen are spaghetti code)
Last edited by rarsa on Mon 02 Nov 2009, 03:39, edited 1 time in total.
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#437 Post by rarsa »

OK, I'm jumping into the Vala wagon.

I started today with Genie but found several little annoyances which, without proper documentation, gave me a headache.

So I moved to Vala and it just feels natural.

I wrote a little test application that uses Gtk, Glade, and SQLite. Creating multiple windows defined in separate classes and source files. Some of those things are not well documented but I drew from experiences from other languages.

I know I'm at the bottom of the learning curve but I hope to put my new learnings to a good use. (time permitting)
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#438 Post by BarryK »

rarsa,
Great to "hear" from you again!

Ah yes, I always remember your statement that anything with the name "Basic" in it makes you break out in a rash! :)
[url]https://bkhome.org/news/[/url]

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#439 Post by rarsa »

BarryK wrote:Great to "hear" from you again!
Thanks!
BarryK wrote:Ah yes, I always remember your statement that anything with the name "Basic" in it makes you break out in a rash! :)
Oh, I wouldn't put Genie in the same leage as Basic.

I think it is a nice language which I will surely get into once I get my head around Vala which is better documented.

I am also a python guy so Genie seemed familiar just that I wasted time with some very basic things:

I mixed tabs and spaces and the interpreted got confused until I added the [indent..].

When setting an object method as the event handler I had to do

Code: Select all

button.clicked += def () myMethod()
But if it was a global method

Code: Select all

button.clicked += myMethod()
which wasn't documented anywhere. In Vala the def() is not required.

Most examples use global methods, not classes so it was quite an experience.

So this combined with the indent issue was quite confusing: The myMethod() looked indented as other class methods (4 spaces), but it really wasn't due to using tabs (1 tab) so it was interpreted as a global method outside the class but without visibility to the private members of the class.

:) enough rambling, I like both languages, I just decided to start with Vala to understand the programing model and then try Genie.
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#440 Post by BarryK »

Oh, I didn't want to imply that Basic and Genie are in the same league. It is just that my memory was jogged, about the comment you made about "anything with Basic in the name" long ago -- or I think it was you, maybe my memory is faulty.

It is probably unwise to stir up that tabs versus spaces thing again. It is interesting that Jamie decided to use tabs as the default.

Personally, I like tab indents. Very easy to indent consistently, also easy when editing existing text. As long as nobody opens/edits my code in a text editor configured to convert tabs to spaces...
[url]https://bkhome.org/news/[/url]

Post Reply