js_on_event on Div widget in bokeh - bokeh

Is it possible to use js_on_event for Div widgets? I would ultimately like to trigger a callback in python whenever an event is triggered on a Div widget (tap, press, mouse enter, mouse leave, etc), and I suppose going through js_on_event is the way to do that(?). Anyways, I have tried the following:
from bokeh import events
from bokeh.layouts import layout
from bokeh.models import CustomJS, Div
from lib.bokeh.util.bokeh_util import display
div = Div(style={'background': 'gray', 'min-width': '500px', 'min-height': '500px'})
div.js_on_event(events.Tap, CustomJS(code="""
console.log("Does this work?")
"""))
display(layout(div, sizing_mode='stretch_both'))
But this does not seem to have any effect.
display is a convenience function that fires up a bokeh Server.

To trigger Python callbacks, you'd need on_event. js_on_event is for triggering JS code in browser, without any communication with the server.
But either way, the Tap event works only on instances of Plot - it doesn't work on any other model, even if it has a visual representation.
There are two ways to solve your problem. If you just need something simple like the Tap event, you can (and probably should) use the regular Button. But if you need something more complicated, you can create a custom Bokeh model that would process any JS events, convert them to Bokeh events, and send them to the server.

Related

JavaFX - Keeping Focus on a "Default" Component

I'm looking for the most concise way to deal with focus in an application which renders a map in a canvas component. You can pan the map location using arrow keys or ASWD keys. So far, I've been giving the canvas focus at startup and handling key pressed events via canvas.setOnKeyPressed().
This works fine, but I've always known that a problem was on the horizon when other components enter the picture. Once you interact with another component, it gains focus, and you're unable to scroll around the canvas map. I can prevent this from happening with some components like Hyperlinks or Buttons (I don't need tab-navigation) with something like this for those components:
sidePanel.getChildren().forEach(node -> node.setFocusTraversable(false));
But, when we get to things like TextArea or TextField, those do need to hold focus while they're being edited. And I'll need some way to return focus back (or at least unfocus those components) without being an annoyance to the user. (I don't want to have to click the canvas for it to regain focus.)
The options I see for returning focus back to the canvas after the user is done with those fields seem to be:
Add a key handler (ex. ESC or ENTER keypress) on EACH of these components which returns focus back to the canvas.
Maybe not so concise, and a bit of a pain... also feels a bit fragile; if I miss something and the canvas loses focus, it would fail - I need a 100% reliable solution.
Extend each of these components and add similar code to return focus back to Canvas
Even nastier and requires using custom components in Scene Builder, which
is not ideal.
Add a global event handler on the Scene and transmit events to the controller which owns the canvas
I believe an event filter would accomplish this - but on the other hand if the user is simply using arrow keys to move around a TextArea, I wouldn't want the Canvas map to move!
To solve the above problem, possibly the global event handler could ignore ASWD and arrow keypresses if the focus is on certain types of components? Is this worth trying, or am I neglecting a problem this would create?
Are there any other simple options out there that I've missed - and what would you suggest as the best option here? I'd like an automatic solution that doesn't require remembering to add some workaround code every time a UI component is added.

Is there a way to delay the rendering of a component in react

I have a component that is using React Transition Group to animate a component as it changes from one component to the next.
The problem I am having is that the next component is loading before the current animation is finished, so it looks a bit odd.
I think i could solve this if it were possible to delay the render() method when the component updates, as it never really unmounts, and this is why the component flashes the next image.
there is FAR too much code involved to paste it all here so i made my github public, and created an issue there to show what I am experiencing.
also you can view the site as it is live for this debugging session.
stevensheaves.me
Also, no judgy, its not 100% finished.
You can simply use the callback of the Transition Group namely onEntered.
A callback fired immediately after the 'enter' or 'appear' classes are removed and the done class is added to the DOM node.
You can use a flag variable to display your content. Set it to true when the callback is fired and to false when it's onEntering

Qt - selectively allow a click to fall through to a lower application window

Is it possible to receive a mouse click even in a Qt application, evaluate it, and if necessary, let it fall through to whatever might happen to be below the Qt application window?
Note that Qt::WA_TransparentForMouseEvents doesn't facilitate evaluating the click before passing it through.
And since the click evaluation incorporates some dynamic logic, it is not applicable to set a static mask either, on top of this having a visual impact as well.
Ideally, I would like a way to selectively allow the mouse click to pass through the application window in a platform portable way, ideally from QML and without bringing in the widgets module, or at the very least, without involving digging into private C++ internal APIs.
Qt::WA_TransparentForMouseEvents is used to filter mouse events out. The name is a bit of a misnomer: it allows widgets that would otherwise consume mouse events, not to consume them. E.g. you could make a button not notice any mouse events. If you're writing a custom widget, there's never any need for this attribute, since it's up to you to inspect the mouse events and simply not handle them: they are automatically passed to the parent widget.
But all of this doesn't matter much, since the WA_ attributes are for widgets, and do nothing for windows. You want something else entirely: to make the window itself transparent for input. Thus, in QML:
window.flags = window.flags | Qt.WindowTransparentForInput
use QWidget.setMask to set the repsonsible area of window:
def resizeEvent(self, event):
geo = self.frameGeometry()
path = QtGui.QPainterPath()
path.addEllipse(0, 0, 300, 200)
poly = path.toFillPolygon().toPolygon()
reg = QtGui.QRegion(poly)
print('resize event', geo, poly)
self.setMask(reg)

How to listen for two simultaneous touch events in React Native?

Our goal is to have two button-like views in our React Native game. They will each consist of a View wrapping around some animated image or alike. The views should be touchable at the same time.
This means: We want to trigger some action on the onTouchStart (like add a symbol to a text) and change the state of the view while it is pressed (for example to change the image in the background or something like that).
Using onTouchStart did not work, since on Android (and only there) we had a Problem: When keeping the first button pressed, pressing the second button with a second finger caused the first callback to trigger, not the second one.
How should we implement this correctly without messing with native code?

Best way to do loaders in a flex application?

What is the best way to do a loader in a flex application? I have an animated .gif that is to be used as our loader (whenever I need to wait for an action to complete), and I am not sure the best way to do it.
This is how I am thinking:
Have the loader be a custom component.
On the parent application, add an event listener for my custom event AceEvent.SHOW_LOADER.
In the event listener, use the PopUpManager to show the loader.
Listen for AceEvent.HIDE_LOADER.
Get rid fo the loader via PopUpManager.
What do you think about this? Is there a better way to do it?
Thanks!
Andrew
Well, last I checked, animated gifs don't work in Flex unless you have a workaround. Still, I wouldn't use an animated gif to create an animation because of their low quality. I would just recreate it using Flash.
The way I would do the loader however would be very different. personally, I don't believe in 'system loaders' unless it's your application's preloader. The reason for this is that there could be more than one thing loading at the same time (which might not know about each other) which means that the loader popup could disappear before everything is loaded (first one loads, dispatches event and removes popup, while the other is still loading).
What I like to do is create a custom component for the popup loader (since it will be reused quite a bit) and from there I can either use states the are appropriate for my view or have a boolean flag binded to show the popup when true (this can easily be done using frameworks like Parsley). The popup would only cover the part of the system that's actually loading data (since I doubt that your whole app is loading data at the same time) which makes for a better UX.
I ended up using as3gif (until I can get this recreated as a .swf). The way I do this is by using my custom event class (AceEvent.SHOW_LOADER and AceEvent.HIDE_LOADER), which bubbles up to the top. I then use the PopUpManager to add/remove this with modal to disable the application.

Resources