Hi,
(I have attached three files - hope that's ok.)

I'm trying to make library that I then employ within Python3. I am hacking from the awesome work done here:
https://github.com/tliron/pygobject-example
(The example "Logging" object works very well.)


I'm trying to make a Clutter Actor (in Vala) and instantiate it from Python. So far not much is going on.

Quick howto:
1. Drop the three files into a directory.
2. Install these: ( apt-get bias, sorry ;) )
 apt-get install libgirepository1.0-dev
 apt-get install gobject-introspection
3. Run the build script (shell): ./build

I see the Clutter window open but only when I close the window do I see the "boo test." message.
There is no sign that the RedSquare constructor (in Vala) ever ran.

Could anyone help me along the path to getting this sucker running?

Tah,
\d
namespace Palelib {

	public class RedSquare : Clutter.Actor {

    //public or private?
    public Clutter.Canvas canvas;

    //Constructor - does not seem to run.
    public RedSquare() {
      stdout.printf( "RedSquare constructor not happening :(" );

      canvas = new Clutter.Canvas();
      canvas.set_size(300,300);
      this.set_size(300,300);
      this.set_content( canvas );
    
      //Connect to the draw signal.
      canvas.draw.connect(drawme);
    }

    private bool drawme( Cairo.Context ctx, int w, int h) {
      stdout.printf("drawme test.");
      ctx.set_source_rgb(255,0,0);
      ctx.rectangle(0,0,300,300);
      ctx.fill();
      return true;
    }


    public void boo() {
      stdout.printf( "boo test." );

      //Remarked the invalidate because it segfaults.
      //this.canvas.invalidate();
    }

	} //end RedSquare class

} //end namespace



#!/usr/bin/env python3

"""
tests the instance of our Vala actor.

I expect to see a red square on the white stage.

"""

import sys
from gi.repository import Palelib, Clutter

Clutter.init(sys.argv)
stage = Clutter.Stage()
stage.set_size(800, 400)
stage.set_title("Blah blah")
stage.connect('destroy', lambda x: Clutter.main_quit() )


# Make our Object:
# Note - It does make something, but the message in the constructor does not print. Is the contructor even running?
rs = Palelib.RedSquare()
#print(dir(rs)) # See that it is an Actor object.

stage.add_child(rs)

#Force rs to appear.
# Note 1 - this does not print the message in boo() to the console. I have no idea why.
# Note 2 - When the app is closed, the message prints.
rs.boo()

"""
For testing:
r1 = Clutter.Rectangle()
r1.set_size(50,50)
r1.set_position(0,0)
damnweird = Clutter.Color.new(0,0,0,255)
r1.set_color( damnweird  )

stage.add_child(r1)
"""

stage.show_all()
Clutter.main()
#!/bin/bash

#
# Script borrowed from Tal Liron at:
# https://github.com/tliron/pygobject-example
#
# I did these to get this script to work:
#
# apt-get install libgirepository1.0-dev
# apt-get install gobject-introspection
#


echo "Cleaning..."

rm -rf tmp
rm -rf lib
rm -rf type
rm -f test

mkdir tmp
mkdir lib
mkdir type

        echo "Building Vala library..."

        # Note 1: Ubuntu package for valac: valac-0.14
        # Note 2: Generates broken gir if --gir= has a directory prefixed to it
        # Note 3: The -X switches for gcc are necessary!
        # Note 4: The generated gir will include GObject-2.0. That gir is
        #         included in Ubuntu package: libgirepository1.0-dev

        valac \
  --pkg clutter-1.0 \
        --library=Palelib \
        --directory=tmp \
        --gir=Palelib-1.0.gir \
        --output=libpalelib.so \
        -X -shared \
        -X -fPIC \
        redsquare.vala
        
        mv tmp/libpalelib.so lib
        mv tmp/Palelib-1.0.gir type

        # Note: We cannot generate C code and compile in the same call
        #       (We don't need the C code to run the test, but we are curious
        #       as to what Vala is generating. The resulting code will be in
        #       logging.c)
        #valac \
        #--ccode \
        #redsquare.vala
        

echo "Building typelib..."

# Note 1: Ubuntu package for g-ir-compiler: gobject-introspection
# Note 2: The --shared-library switch is really only necessary when using
#         the gir produced by valac, because it does not include the
#         'shared-library' attribute in <namespace> tag.


g-ir-compiler \
--shared-library=libpalelib.so \
--output=type/Palelib-1.0.typelib \
type/Palelib-1.0.gir

echo "Test Python..."

# Note 1: Ubuntu's default path for typelib files seems to be:
#         /usr/lib/girepository-1.0/.
# Note 2: It is also possible to programmatically change the
#         GI_TYPELIB_PATH environment var in Python (os.environ API).
#         If you do so, make sure to set it before importing from
#         gi.repository.
LD_LIBRARY_PATH=lib \
GI_TYPELIB_PATH=type \
./test.py
_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to