Re: don't understand file_get_contents



On 2010.12.05, at 15:25, Jean-Baptiste Bourgoin wrote:

> Hello,
> 
> I'm playing with Seed and Gi : i tried to write a little text editor.
> 
> I don't understand why i can't open a file.
> 
> There is the code :
> 
> ------------------------------------------------
> 
> #!/usr/bin/seed
> 
> GLib = imports.gi.GLib;
> Gtk = imports.gi.Gtk;
> GtkSource = imports.gi.GtkSource;
> GtkBuilder = imports.gtkbuilder;
> 
> 
> function load_file(filename) {
> 
>    var file = GLib.file_get_contents(filename);
> 
>    this.GtkSource.buffer.begin_not_undoable_action();
>    this.GtkSource.buffer.set_text(file);
>    this.GtkSource.buffer.end_not_undoable_action();
> }
> 
> // handlers of file menu
> 
> var handlers_menufile = {
>    // NEW FILE
>    on_mfilenew_activate: function(menuitem){
>    },
>    // OPEN FILE
>    on_mfileopen_activate: function(menuitem){
>        var dialog_open = new Gtk.FileChooserDialog({
>            title: "Open File",
>            action: Gtk.FileChooserAction.OPEN
>        });
>        dialog_open.add_button(Gtk.STOCK_CANCEL,
> Gtk.ResponseType.CANCEL);
>        dialog_open.add_button(Gtk.STOCK_OPEN, Gtk.ResponseType.OK);
>        dialog_open.run();
>        if (dialog_open.run() == Gtk.ResponseType.OK) {
>            var filename = dialog_open.get_filenames();
>            load_file(filename);
>        }
>        dialog_open.destroy();
>    },
>    // SAVE FILE
>    on_mfilesave_activate: function(menuitem){
>    },
>    // SAVE AS FILE
>    on_mfilesaveas_activate: function(menuitem){
>    },
>    // QUIT
>    on_mfilequit_activate: function(menuitem){
>        Seed.quit();
>    }
> };
> 
> // display
> 
> Gtk.init(Seed.argv);
> 
> b = new Gtk.Builder();
> b.add_from_file("graineed-main.glade");
> 
> b.connect_signals(handlers_menufile);
> 
> d = b.get_object("window1");
> 
> // d.Widget.set_size_request(400, 600);
> d.show_all();
> d.set_title("Graineed");
> 
> Gtk.main();
> 
> ------------------------------------------------
> 
> The error :
> 
> ** (seed:13225): WARNING **: Exception in closure (0xa082148) for signal
> handler (GtkBuilder) (handler [anonymous]). Line 10 in file_action.js:
> GInvokeError Too few "out" arguments (handling out)
> 
> The line 10 (in the original source code) is "var file =
> GLib.file_get_contents(filename);"
> 
> 
> You can get the source code here :
> https://github.com/jbbourgoin/Graineed
> 
> Load_file work, when I write a "print(filename);" before
> file_get_contents I have the file with his path. I don't understand the
> signification of the bug report.

Try reading the file like this example does:

http://git.gnome.org/browse/seed-examples/tree/quine.js

> If you have an idea, and I think you have, this is a simple problem
> after all ;) (except for a beginner !).
> 
> Thanks,
> 
> JBB
> 
> P.S. : You can identify faults in my prose, I'm not very good in
> english, but I want to improve it ;)
> 
> -- 
> http://www.jeanbaptiste-bourgoin.com
> http://www.inlibroveritas.net/auteur15123-oeuvres.html
> 
> _______________________________________________
> javascript-list mailing list
> javascript-list gnome org
> http://mail.gnome.org/mailman/listinfo/javascript-list



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