callback

DialogFragment callback to Target Fragment using interface

邮差的信 提交于 2020-08-24 08:27:12
问题 I am trying to send some data from a dialogfragment to the targeted fragment but its not working. I have written the following code, but it through exception : java.lang.NullPointerException: Attempt to invoke interface method 'void com.x.x.FragmentAlertDialog$Communicator.setI(java.lang.String)' on a null object reference Code: public class FragmentAlertDialog extends DialogFragment { Communicator callback; public interface Communicator { void setI(String name); } public static

Cgo: can't find way to use callbacks with const char* argument

那年仲夏 提交于 2020-08-07 10:34:12
问题 I'm use C library from Go using Cgo and all good except callbacks. Library have callback setter, which takes pointer to callback func. Callback func itself written in go and exported using Cgo syntax. Problem: I can make and export function with char * argument, but can't with const char * . Code to illustrate: test.go : package main /* typedef void (*cb_func)(const char *, int); void callback(cb_func); void myFunc(const char *, int); */ import "C" import ( "fmt" "unsafe" ) //export myFunc

Cgo: can't find way to use callbacks with const char* argument

青春壹個敷衍的年華 提交于 2020-08-07 10:33:00
问题 I'm use C library from Go using Cgo and all good except callbacks. Library have callback setter, which takes pointer to callback func. Callback func itself written in go and exported using Cgo syntax. Problem: I can make and export function with char * argument, but can't with const char * . Code to illustrate: test.go : package main /* typedef void (*cb_func)(const char *, int); void callback(cb_func); void myFunc(const char *, int); */ import "C" import ( "fmt" "unsafe" ) //export myFunc

Event callback after a Tkinter Entry widget

ぃ、小莉子 提交于 2020-08-05 09:35:22
问题 From the first answer here: StackOverflow #6548837 I can call callback when the user is typing: from Tkinter import * def callback(sv): print sv.get() root = Tk() sv = StringVar() sv.trace("w", lambda name, index, mode, sv=sv: callback(sv)) e = Entry(root, textvariable=sv) e.pack() root.mainloop() However, the event occurs on every typed character. How to call the event when the user is done with typing and presses enter, or the Entry widget loses focus (i.e. the user clicks somewhere else)?

Replace a function pointer in a shared library with ctypes

╄→尐↘猪︶ㄣ 提交于 2020-07-28 04:49:48
问题 I am trying to replace an existing function pointer in a shared library with a callback defined in Python, through ctypes. The source of the shared library in C: #include <assert.h> #include <stdio.h> void (*plot)(); int c_main(int argc, void** argv) { printf("plot is %p\n", (void*)plot); assert(plot != NULL); plot(); return 0; } The source of the Python script: from sys import platform from pathlib import Path import ctypes import _ctypes FUNCTYPE = ctypes.WINFUNCTYPE if platform == 'win32'

Replace a function pointer in a shared library with ctypes

时光怂恿深爱的人放手 提交于 2020-07-28 04:49:12
问题 I am trying to replace an existing function pointer in a shared library with a callback defined in Python, through ctypes. The source of the shared library in C: #include <assert.h> #include <stdio.h> void (*plot)(); int c_main(int argc, void** argv) { printf("plot is %p\n", (void*)plot); assert(plot != NULL); plot(); return 0; } The source of the Python script: from sys import platform from pathlib import Path import ctypes import _ctypes FUNCTYPE = ctypes.WINFUNCTYPE if platform == 'win32'

Return an asyncio callback result from task creating function

谁都会走 提交于 2020-07-23 08:22:18
问题 I'm trying to wrap an async function up so that I can use it without importing asyncio in certain files. The ultimate goal is to use asynchronous functions but being able to call them normally and get back the result. How can I access the result from the callback function printing(task) and use it as the return of my make_task(x) function? MWE: #!/usr/bin/env python3.7 import asyncio loop = asyncio.get_event_loop() def make_task(x): # Can be used without asyncio task = loop.create_task(my