Skip to content

Commit

Permalink
Create component ref and hook into the kernelspy.
Browse files Browse the repository at this point in the history
This using the IPython extension and using `?` on an existing object, it
should pop out the right docstring.

    %load_ext papyri

    import numpy as np
    np.einsum?
  • Loading branch information
Carreau committed Jan 22, 2024
1 parent 1fe20d2 commit fdbb53f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion papyri-lab/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ const plugin: JupyterFrontEndPlugin<void> = {
}

const kernelSpy = new KernelSpyModel(notebookTracker);
kernelSpy.questionMarkSubmitted.connect((_, args) => {
kernelSpy.questionMarkSubmitted.connect((_, args: any) => {
console.info('KSpy questionMarkSubmitted args:', args);
if (args !== undefined) {
widget.content.updateSeachTerm(args.qualname);
console.info('DO your thing here.');
}
});
Expand Down
9 changes: 8 additions & 1 deletion papyri-lab/src/widgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,22 @@ class PapyriComponent extends React.Component {
// This seem to be the way to have an adapter between lumino and react, and
// allow to render react inside a JupyterLab panel
export class PapyriPanel extends ReactWidget {
comp: any;
constructor() {
super();
this.addClass('jp-ReactWidget');
this.id = 'papyri-browser';
this.title.label = 'Papyri browser';
this.title.closable = true;
this.comp = React.createRef();
}

updateSeachTerm(str: string) {
this.comp.current.setSearchTerm(str);
this.comp.current.search(str);
}

render(): JSX.Element {
return <PapyriComponent />;
return <PapyriComponent ref={this.comp} />;
}
}

0 comments on commit fdbb53f

Please sign in to comment.