Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Unsupported type: function #53

Closed
sigmaSd opened this issue Nov 5, 2023 · 3 comments
Closed

Uncaught TypeError: Unsupported type: function #53

sigmaSd opened this issue Nov 5, 2023 · 3 comments

Comments

@sigmaSd
Copy link
Contributor

sigmaSd commented Nov 5, 2023

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
@DjDeveloperr
Copy link
Member

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

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

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Nov 7, 2023

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

@sigmaSd sigmaSd closed this as completed Nov 7, 2023
@sigmaSd
Copy link
Contributor Author

sigmaSd commented Nov 7, 2023

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants