Vala and Genie programming

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Mr. Maxwell
Posts: 215
Joined: Sat 30 Aug 2008, 23:56
Location: Nebraska, USA

#91 Post by Mr. Maxwell »

Now I have another problem. I have a list with many doubles in it, I wish to get rid of these doubles. If I try this code:

Code: Select all

for num:int in num_list
    if num not in finished_num_list
        finished_num_list.add(num)
I get this error:

Code: Select all

test.gs:16.18-16.20: error: syntax error, expected end of line but got `!' with previous identifier
        if num not in finished_num_list
               ^^^
test.gs:21-1-21-0: error: syntax error, expected identifier

Compilation failed: 2 error(s), 0 warning(s)
When I try this code:

Code: Select all

for num:int in num_list
    if not (num in finished_num_list)
        finished_num_list.add(num)
It compiles just fine but I get this message when I try to run it:

Code: Select all

Segmentation fault
Both of those work fine in python and should work with other launguages. Any ideas?
[url=http://www.tribalwars.net/3389956.html]Super amazing game![/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#92 Post by MU »

Ok, I used a testprogram:

Code: Select all

[indent=2]
init

  var num_list = new list of int
  num_list.add(1)
  num_list.add(2)
  
  var finished_num_list = new list of int

  for num in num_list
    print("testing: %d" , num)
    if not finished_num_list.contains(num) 

      print("adding: %d" , num)
      finished_num_list.add(num)

  print("bye")
Looks slightly different to your code, but does the same (I also tested yours, and then mine, to check where the error ould be).
When I compile and run it in the IDE, it never reaches "bye".
Running in console, I also get the segmentation fault.
If I run it in the debugger, I get:
# valac --pkg=gee-1.0 main.gs
# gdb ./main
GNU gdb 6.7
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-t2-linux-gnu"...
(no debugging symbols found)
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) run
Starting program: /root/valide/gee1/main
(no debugging symbols found)
(no debugging symbols found)
testing: 1
adding: 1
testing: 2

Program received signal SIGSEGV, Segmentation fault.
0xb7ea1476 in g_int_equal () from /usr/lib/libglib-2.0.so.0
(gdb) backtrace
#0 0xb7ea1476 in g_int_equal () from /usr/lib/libglib-2.0.so.0
#1 0xb7f3d1d9 in gee_array_list_real_index_of (base=0x804f670, item=0x2) at arraylist.c:185
#2 0xb7f438ef in gee_list_index_of (self=0x804f670, item=0x2) at list.c:61
#3 0xb7f3e4d0 in gee_array_list_real_contains (base=0x804f670, item=0x2) at arraylist.c:174
#4 0xb7f3eabf in gee_collection_contains (self=0x804f670, item=0x2) at collection.c:39
#5 0x08048764 in _main ()
#6 0x08048829 in main ()
(gdb) quit
The program is running. Exit anyway? (y or n) y
#
So there is a bug concerning int types in lists.
I then used "uint" instead.
This works.
You just need to "cast" it to int, if you want to compare it to other integers, or print it.
This is done with

Code: Select all

(int) variablename
Here is a working example:

Code: Select all

[indent=2]

init

  var num_list = new list of uint
  num_list.add(1)
  num_list.add(2)
  
  var finished_num_list = new list of uint
  var a=0   
   
  for num in num_list 
    a = (int) num
    if not (num in finished_num_list) 
      print("adding: %d" , a)    
      finished_num_list.add(num)
      print("added: %d" , a)


  print("bye")

 
Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
Mr. Maxwell
Posts: 215
Joined: Sat 30 Aug 2008, 23:56
Location: Nebraska, USA

#93 Post by Mr. Maxwell »

Thanks much better. :D I'm going to start working on the GUI now so I hope you're ready for more questions. :D
[url=http://www.tribalwars.net/3389956.html]Super amazing game![/url]

mymas
Posts: 3
Joined: Sun 29 Mar 2009, 14:07
Location: japan

#94 Post by mymas »

hi. I try to do cairo-sample in genie. :)
So, window open ok, but I cannot do picture-image output in window ...

Code: Select all

[indent=2]
uses 
  Gtk
  GLib
  Cairo
    
init 
  Gtk.init (ref args)
  var test = new CairoSample ()
  test.show_all ()
  Gtk.main ()

class CairoSample : Window
  init
    title = "Cairo Genie Demo"
    default_height = 550
    default_width = 450
    window_position = WindowPosition.CENTER
    
    destroy += Gtk.main_quit
    
    var drawing_area = new DrawingArea ()
    drawing_area.expose_event += on_expose
    add (drawing_area)
    
  def on_expose (da: DrawingArea, event: Gdk.EventExpose) : bool
    var ctx = Gdk.cairo_create (da.window)
    var surf = new Cairo.ImageSurface (Cairo.Format.ARGB32,240,80)
    ctx.save ()
    
    ctx.select_font_face ('serif', Cairo.FontSlant.NORMAL, Cairo.FontWeight.BOLD)
    ctx.set_font_size (32.0)
    ctx.set_source_rgb (0, 0, 1)
    ctx.move_to (10,50)
    ctx.show_text ('Hello, World')
    
    ctx.restore ()
    surf.write_to_png ('genie_cairotext.png')
    return true
umm... My code is not tidy... :(

aragon
Posts: 1698
Joined: Mon 15 Oct 2007, 12:18
Location: Germany

#95 Post by aragon »

New Version of Vala => 0.6

http://live.gnome.org/Vala/Release

aragon

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#96 Post by MU »

I made an iso with vala related stuff, like the IDE.
http://www.murga-linux.com/puppy/viewto ... 970#290970

It also includes Monodevelop with Valasupport.
There is a huge screenshot showing both IDEs in the end of that message.

I'll upgrade it to vala 0.6 next week, thanks aragon! :)

mymas,
sorry, I was too busy to try out your example :(
Hopefully can have a look at it this weekend.
Please let us know, if you have success!

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#97 Post by MU »

mymas

if I replace the singlequotes with doublequotes , your code works fine.
I changed 2 lines:
ctx.select_font_face ("serif", Cairo.FontSlant.NORMAL, Cairo.FontWeight.BOLD)
and:
ctx.show_text ("Hello, World")

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

aragon
Posts: 1698
Joined: Mon 15 Oct 2007, 12:18
Location: Germany

#98 Post by aragon »

hi mark,

heavy development, 0.7 is out...
http://live.gnome.org/Vala/Release

maybe thios is also something interesting

gtkaml: http://code.google.com/p/gtkaml/
gtkaml is an XML parser that extends the Vala.Parser (literally) and transforms all your tags into a valid Gtk+ UI class described in the Vala language.
aragon

MUguest
Posts: 73
Joined: Sat 09 Dec 2006, 16:40

#99 Post by MUguest »

vala 0.7.0, compiled in Puppy 4.12:
http://dotpups.de/puppy4/dotpups/Programming/Vala/

I could not compile gtkaml.
Vala 0.7.0 no longer has all the headers in /usr/include/vala-1.0.
The headers were removed since 0.7.0, see official announcement.
Vala 0.5.7 was missing the required "valacodenode.h".

I could search for older versions of that file, but this might cause problems, so I prefer to wait, until a "proper" solution was found.
If someone urgently wants to test it, I might create a "unproper" pack using a external, older file.

Mark

MUguest
Posts: 73
Joined: Sat 09 Dec 2006, 16:40

#100 Post by MUguest »

I added gtkaml-0.2.5-i486.pet.
To compile it, I first installed vala 0.6.0.
This installed the required header.
Then I installed again 0.7.0, and compiled gtkaml.

I did not test this library.

Mark

b100dian
Posts: 5
Joined: Tue 07 Apr 2009, 22:35

#101 Post by b100dian »

To compile it, I first installed vala 0.6.0.
This installed the required header.
Sorry for the additional work involved, MUguest. I fixed this in 0.2.5-1.

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#102 Post by MU »

b100dian,
thank you very much.
I wanted to send you a mail about it tomorrow, but you were faster, great!

I will update the pet tomorrow to your latest version.

:D
Mark

(P.S. Just to avoid confusion, I'm MUguest, I write from school using a second login.)
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

b100dian
Posts: 5
Joined: Tue 07 Apr 2009, 22:35

#103 Post by b100dian »

luckily I was watching the referrals since yesterday's release was downloaded before being announced.. :) don't hesitate to file bugs or write me if this version doesn't fix it.

Vlad

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#104 Post by MU »

yes, I'll mail you, when I find issues, or people report them.
As you can see by this long thread, Vala/Genie really have found great interest by several Puppy users, and even Barry Kauler, the Puppy founder, is very attracted.
It always was hard for programming languages to enter Puppy, because size/dependencies play a big role in this small system.
I remember 2005, when wxBasic (2 MB compressed with upx, 6 MB uncompressed) was rejected, because it was too "bloated" :lol:

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
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

MUguest
Posts: 73
Joined: Sat 09 Dec 2006, 16:40

#105 Post by MUguest »

Updated Gtkaml to 0.2.5.1.
Mark

b100dian
Posts: 5
Joined: Tue 07 Apr 2009, 22:35

#106 Post by b100dian »

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
Well I am only another Vala user, but thanks for the thanks:)

However, I have one question regarding Vala/Genie, Puppy Linux and Gtkaml: I am in the process of re-writing the parsing to better integrate with Vala's parser and symbol resolver, and to expand Gtkaml's features.

Q: How do you feel about the libxml2 dependency (given the Puppy Linux constraints) and would a GLib/GMarkup approach be favored?

Thanks, and sorry for the offtopic.
Vlad

MUguest
Posts: 73
Joined: Sat 09 Dec 2006, 16:40

#107 Post by MUguest »

Hi Vlad,
I think libxml2 is in Puppy since ages, and will stay in it, as many programs depend on it. So it is ok, if you stay with it.
Mark

User avatar
Mr. Maxwell
Posts: 215
Joined: Sat 30 Aug 2008, 23:56
Location: Nebraska, USA

#108 Post by Mr. Maxwell »

I've got everything working except my GUI. :? All I need is a button and a text entry field, the problem is I have no idea how to 1) pack the widgets so the text entry field is on top of the button 2) how to make, display text, and delete text in a text entry field.

Thanks in advance.
[url=http://www.tribalwars.net/3389956.html]Super amazing game![/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#109 Post by MU »

I attach an example.
It uses project.glade, that can be modified with Glade.

If you do not want to use libglade, I would need your program, so that I could add the code you miss to it.

Note, that you must compile it with libglade and gobject.
If you don't use the ValaIDE, compile it with:
valac -C --pkg gtk+-2.0 --pkg libglade-2.0 --pkg gmodule-2.0 main.gs

If you use the valaide, add those libraries in the options.
On my current system, the ide crashes, if I go to the options, so I added them with an editor to buttonandtext.vide.

Mark
Attachments
butonandtext.jpg
(5.03 KiB) Downloaded 1256 times
buttonandtext.tar.gz
(6.53 KiB) Downloaded 466 times
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#110 Post by MU »

Here is the same result, but now without libglade, coded "by hand" with the native Gtk bindings.

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

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

Post Reply