I'm pretty new to Kivy and I'm trying to use the Slider widget. I don't want a function to be executed on_value but rather as soon as the slider is released. How can I implement something like on_release (which exists for Buttons) in the Slider class?
Ou seja, em vez de
Slider:
on_value: root.do_something()
eu quero ter
Slider:
on_release: root.do_something()
The event on_release is provided by the mixin class ButtonBehavior. The class Slider is not inherited from ButtonBehavior, that's why you can't expect that event in Slider. You may also have problem if you want to define a class inheriting from ButtonBehavior and Slider due to the on_touch_up event.
Check more on Kivy documentation.
You can make use of on_touch_up event. You have to pass touch object passed to on_touch_up (args[1]) and slider object (self), then check if event was fired because your slider was grabbed to avoid of firing on_slider_release method from other sources.
Here is and example:
Within your kv file:
Slider:
on_touch_up: root.on_slider_release(args[1], self)
Then on_slider_release implementation:
def on_slider_release(self, touch, widget):
if touch.grab_current == widget:
print('my_slider has been released')
Related
I am using a custom-created button on my HERE Map using the JS 3.0 library.
I followed a HERE support engineer's suggestion provided here: HERE Map UI JS - How to add custom buttons to the Map UI?
So far, I have been able to get it to work just fine, but I just found out that I need to be able to enable or disable the button depending on various business rules. But it looks like there is no "setDisabled" functionality for HERE Controls or Buttons?
https://developer.here.com/documentation/maps/api_reference/H.ui.Control.html
https://developer.here.com/documentation/maps/api_reference/H.ui.base.Button.html#.State (I saw that there was the option to initialize a button to be disabled, but not to change an existing one. Seems inefficient to create a new button every time I need to enable or disable it.)
Any suggestions?
Dont use the var ui = H.ui.UI.createDefault(map, maptypes, 'en-US'); line in order to disable buttons or find your self in an "if" statment to access this when a certain button is pressed or statement is passe
There is a setDisabled() method inherited from the parent class H.ui.base.Element which you can use:
// assume custom UI control exists
customControl.setDisabled(true) // <- disables the control
customControl.setDisabled(false) // <- enables the control
Here is jsfiddle working example of custom UI control which disables itself after click.
See H.ui.Control#setDisabled() for more details.
I'm attempting to utilise other button mappings for super-hands other than the defaults but I'm hitting trouble. For example, the abuttonup and abuttondown events for the Oculus Touch with progressive-controls.
When I use the following component, or any of the other reaction components, the grab-end or click events are not registering for custom button mappings.
clickable="startButtons: abuttonup; endButtons: abuttondown"
When I override the default startButtons and endButtons in the super-hands source, the buttons work as intended.
Many thanks.
The mappings I required have now been added to the aframe-super-hands library: Commit 95a3222
I'm pretty new to Kivy and I'm trying to use the Slider widget. I don't want a function to be executed on_value but rather as soon as the slider is released. How can I implement something like on_release (which exists for Buttons) in the Slider class?
I.e. instead of
Slider:
on_value: root.do_something()
I want to have
Slider:
on_release: root.do_something()
I don't think there's a built in event for this, so you'd need to override on_touch_up. Something like the following should work:
def on_touch_up(self, touch):
released = super(YourSliderSubclass, self).on_touch_up(touch)
if released:
do_something()
return released
This works because its on_touch_up returns True by default if it was actually released, otherwise it returns None.
If you want an event to bind to in kv, you could add your own new event to your slider subclass and dispatch that.
I'm trying to use the Buttonset widget in JQuery UI. I've got the package loaded and my template renders the radio buttons fine. I have a "rendered" function to call the JQ UI routine to setup the buttonset:
Template.teamList.rendered = function () {
$("#buttonsetID").buttonset();
}
But it looks like the rendered function is being called before the template is rendered! I stick a console.log in the function and it prints out to the console before there's anything on the screen. So none of the radio buttons are set up, therefore the .buttonset() call does nothing. If I make that call in the console after the page is rendered, JQuery UI does the right thing and my button set appears.
Isn't the .rendered function supposed to be called after everything's set up? Am I doing something wrong?
Thanks!
edit:
As an example, the same thing is seen in the leaderboard example.
If you add:
Template.leaderboard.rendered = function() {
alert($('.player').length);
}
When the page is displayed, it will show 0. This makes it difficult to access the DOM items if you need to add some JQuery events or, in this case, a JQuery UI element.
rendered only works for elements which will appear in the DOM the very first time the template is added to the page. Assume that subscription data takes infinitely long to arrive, then look at the template and see which elements would appear in the default state.
Using the leaderboard example, we can't assume that players are available when the leaderboard template renders (it depends on a subscription). To target a player, you should use the rendered callback on the player template.
It's hard to generalize a strategy for when to apply jQuery plugins, but here are some ideas:
Use the rendered callback if the element will always be added in the default state (e.g. the element is hard-coded and doesn't depend on a conditional).
Use the rendered callback of the most specific child template to target that child (e.g. the player template from above).
Consider using an event handler callback to target the element if it's appearance depends on an event (e.g. a button click).
Consider using a template autorun callback to target the element if it's appearance depends on reactive state. See this question for an example.
Flex 3 question:
I trying here to avoid having to bind resources to all my components labels ( ie a button) and find a way to have this automated.
Problem:
It corrupts the layout in design mode to bind directly in the mxml label="{resourceManager.getString('myResources', 'submit')}" and makes the design view useless. but when declaring bindings elsewhere, in actionScript or via a bind tag, it is counter productive and prone to many errors and miss.
Proposition:
I would like to create my own button that automatically invoke resources to localize a button label. So the author puts "Submit" in the mxml description of my button, and when running it would take the value of the label ie "submit" and use resourceManager.getString('myResources', 'submit').
but I can't find the way to override the set label function, Is it possible if yes how? else how can I go about it?
Maybe I am missing an essential process here that would make the use of resources more elegant, as well as how to override such thing as a button's label.
Thanks for your advices.
Create a component called MyButton, extending Button. Then use this:
override public function set label(value:String):void {
super.label = resourceManager.getString('myResources', value) || value;
}
Assuming the resource manager returns "null" or "undefined" this will work, and will only replace the value if it exists in "myResources".
If you don't want to override every component you need to do this with, then you can add a FlexEvent.CREATION_COMPLETE event on every component. Then use a single generic function to do your label localization.