Giter Site home page Giter Site logo

Comments (11)

kenseehart avatar kenseehart commented on May 22, 2024 2

Here's my workaround:

import traceback

class MyUI:
    def __init__(self, canvas, model):
        self.canvas = canvas
        self.model = model
        canvas.on_mouse_down(self.mouse_down)

    def mouse_down(self, x, y):
        try:
            do_some_stuff()
        except:
            self.print_traceback()
            
    def print_traceback(self):
        self.canvas.fill_style = '#ff8888'
        self.canvas.fill_rect(10, 10, 300, 300)
        self.canvas.fill_style = '#000000'
        s = traceback.format_exc()
        for i, si in enumerate(s.split('\n')):
            canvas.fill_text(si, 20, 30+15*i)    

Works great. Now my code is debugable.

from ipycanvas.

martinRenou avatar martinRenou commented on May 22, 2024 1

Thanks a lot for opening an issue. I suppose this is unexpected behavior. I am not sure what is causing this. I will have a look in two weeks.

from ipycanvas.

janfreyberg avatar janfreyberg commented on May 22, 2024 1

that's a really neat workaround, thanks @kenseehart

from ipycanvas.

martinRenou avatar martinRenou commented on May 22, 2024

That is really weird. I could also see something similar in ipyleaflet today, see jupyter-widgets/ipyleaflet#455 (comment).

I really don't know where this comes from.

Maybe you already know about it, but you can use the Output widget in order to capture the stream explicitly, and put it where you want.

from ipycanvas.

janfreyberg avatar janfreyberg commented on May 22, 2024

Yes - the issue is more for debugging when it's hard to know where to capture output. I don't know why this might be happening, but the jupyter lab log console is discussed here: jupyterlab/jupyterlab#7386

They specifically mention un-handled messages being logged; I don't know how a message being "handled" is defined though.

from ipycanvas.

kenseehart avatar kenseehart commented on May 22, 2024

Looks like the CallbackDispatcher is consuming stdin and stdout for some reason. It's not about exceptions per se. Probably the exception is be handled in the normal way, but when the traceback is written to stdout, it gets consumed.

from ipycanvas.

ianhi avatar ianhi commented on May 22, 2024

The CallbackDispatcher is being created a little bit differently in ipycanvas and the ipywidgets button. In the button it is created in the constructor:
https://github.com/jupyter-widgets/ipywidgets/blob/6be18d9b75353f7b4a1c328c6ea06d8959f978f6/ipywidgets/widgets/widget_button.py#L57-L60

whereas here it is wrapped in at traitlets Instance function and explicitly added:
https://github.com/martinRenou/ipycanvas/blob/a97d7810745afb61e4daed71bd92b998304e36fd/ipycanvas/canvas.py#L180

from ipycanvas.

martinRenou avatar martinRenou commented on May 22, 2024

@ianhi do you think that could be the cause of the issue?

Indeed having the object instantiated as a kind-of static property does not sound right at all.

from ipycanvas.

ianhi avatar ianhi commented on May 22, 2024

@martinRenou oops I forgot to include any context for that comparison. Yes, my intention was to imply that this may be the cause as this seems to be the only relevant difference between ipycanvas and the ipywidgets.Button

from ipycanvas.

ahrm avatar ahrm commented on May 22, 2024

Hi! Why is this issue closed? Is it fixed in the new versions?

from ipycanvas.

ianhi avatar ianhi commented on May 22, 2024

Hi @ahrm this issue is still open. You see this at the top of the page:
image

from ipycanvas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.