Skip to content

Uncaught TypeError: Unsupported type: function #53

Closed

Description

@sigmaSd
import { NamedArgument, python } from "https://deno.land/x/python@0.4.1/mod.ts";

const gi = python.import("gi");
gi.require_version("Gtk", "4.0");
const Gtk = python.import("gi.repository.Gtk");

function onActivate(app: any) {
  const win = Gtk.ApplicationWindow(new NamedArgument("application", app));
  win.present();
}

const app = Gtk.Application();
app.connect("activate", onActivate); // error here

app.run();
error: Uncaught TypeError: Unsupported type: function
        throw new TypeError(`Unsupported type: ${typeof v}`);
              ^
    at Function.from (https://deno.land/x/python@0.4.1/src/python.ts:533:15)
    at PyObject.call (https://deno.land/x/python@0.4.1/src/python.ts:760:57)
    at Proxy.object (https://deno.land/x/python@0.4.1/src/python.ts:258:20)
    at file:///home/mrcool/dev/deno/lab/a.ts:13:5

Activity

  1. DjDeveloperr commented on Nov 6, 2023

    @DjDeveloperr
    Member

    Here's an example for passing JS functions to Python land:

    Deno.test("callback", () => {

  2. sigmaSd commented on Nov 7, 2023

    @sigmaSd
    ContributorAuthor

    Nice this works indeed

    import { NamedArgument, python } from "https://deno.land/x/python@0.4.1/mod.ts";
    
    const gi = python.import("gi");
    gi.require_version("Gtk", "4.0");
    const Gtk = python.import("gi.repository.Gtk");
    
    const onActivate = python.callback(
      // deno-lint-ignore no-explicit-any
      (_kwargs: any, ...args: any[]): undefined => {
        const app = args[0];
        const win = Gtk.ApplicationWindow(new NamedArgument("application", app));
        win.present();
      },
    );
    const app = Gtk.Application();
    app.connect("activate", onActivate);
    
    app.run();
  3. sigmaSd commented on Nov 7, 2023

    @sigmaSd
    ContributorAuthor

    @DjDeveloperr I'm following this tutorial https://github.com/Taiko2k/GTK4PythonTutorial and this is what I reached so far

    import { NamedArgument, python } from "https://deno.land/x/python@0.4.1/mod.ts";
    
    const gi = python.import("gi");
    gi.require_version("Gtk", "4.0");
    gi.require_version("Adw", "1");
    const Gtk = python.import("gi.repository.Gtk");
    const Adw = python.import("gi.repository.Adw");
    
    class MainWindow extends Gtk.ApplicationWindow {
      constructor(kwargs) {
        super(kwargs);
    
     // question about this part
        const button = Gtk.Button(new NamedArgument("label", "Hello"));
        this.set_child(button);
      }
    }
    
    class MyApp extends Adw.Application {
      // deno-lint-ignore constructor-super
      constructor(...kwargs: any) {
        super().__init__(kwargs);
        this.connect("activate", this.onActivate);
      }
    
      onActivate = python.callback((kwargs, ...args) => {
        const app = args[0];
        const win = new MainWindow(new NamedArgument("application", app));
        win.present();
      });
    }
    const app = new MyApp(new NamedArgument("application_id", "com.example.com"));
    app.run(Deno.args);

    There are porbably other issues, but the immediate one I have is

      const button = Gtk.Button(new NamedArgument("label", "Hello"));
        this.set_child(button);

    if I change const button = to this.button = I get an error

    SystemError: <built-in method JSCallback:anonymous of NoneType object at 0x7fb24dedfc80> returned NULL without setting an exception
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions