Re: [Vala] Genie error !



Hi,

quoting from [1]:

        init blocks do not have any parameters. A construct block is
        used to define a creation method which requires parameters.

You need to use new PoppleSample(), without parameters. If you need to
pass some parameters, then you need to define a "construct" block. Hope
it was clear enough...

cheers
alberto

[1]
http://live.gnome.org/Genie#head-fa4a76035d436d5e8d25288f418324dc3f965696


On Fri, 2009-05-22 at 12:56 +0200, Nicolas wrote:
Hi,

I try to port simple pdf viewer from vala to genie.

But i have this error:

pdfview.gs:53.18-53.44: error: Too many arguments, method 
`PopplerSample.new' does not take 1 arguments
    var sample = new PopplerSample (args[1])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)

What's wrong in code ?

[indent=4]

/* Build with valac --pkg gtk+-2.0 --pkg poppler-glib yourfile.gs */

uses
    Gtk
    Poppler

class PopplerSample : Window
    document : Poppler.Document
    image : Image
    index:int = 0
    init
        title = "Simple PDF Viewer"
        default_height = 350
        default_width = 500
        window_position = WindowPosition.CENTER
        destroy += Gtk.main_quit
   
    def PopplerSample (pdf_filename : string)
        try
            this.document = new Poppler.Document.from_file 
(Filename.to_uri (pdf_filename), "");
        except e:OptionError
            print ("%s", e.message)
        // Create an image and render first page to image
        var pixbuf = new Gdk.Pixbuf (Gdk.Colorspace.RGB, false, 8, 800, 
600);
        this.image = new Image.from_pixbuf (pixbuf);
        render_page ()
        add (this.image)
        this.key_press_event += on_key_pressed
        this.destroy += Gtk.main_quit

    def private on_key_pressed (source : PopplerSample, key : 
Gdk.EventKey) : bool
        if (key.str is "q")
            Gtk.main_quit ()
        // Render the next page, or the first if we were at the last
        this.index++
        this.index %= this.document.get_n_pages ()
        render_page ()
        return false

    def private render_page ()
        var pixbuf = this.image.get_pixbuf ()
        var page = this.document.get_page (this.index)
        page.render_to_pixbuf (0, 0, 800, 600, 1.0, 0, pixbuf)
        this.image.set_from_pixbuf (pixbuf)


init
    if (args.length != 2)
        print ("Usage: %s /full/path/to/some.pdf\n", args[0])
    Gtk.init (ref args)
    var sample = new PopplerSample (args[1])
    sample.show_all ()
    Gtk.main ()

Thank you in advance,
Nicolas.


This email has been scanned for all viruses by the MessageLabs Email
Security System.
-- 
Alberto Colombo, MSc

PhD student at Digital Imaging Research Centre
Kingston University, London

e-mail: a colombo kingston ac uk
 phone: +44 (0)20 8547 8642
  http://cism.kingston.ac.uk/people/details.php?AuthorID=925

This email has been scanned for all viruses by the MessageLabs Email
Security System.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]