Kivy: Shift+Tab does not work with TextInput - tabs

I am trying to cycle backwards through my TextInputs by hitting Shift+Tab (I know nothing special). And I just don't know how to get it to work. It always jumps to the next TextInput. I didn't find anything in Google.
Additionally, I want the whole TextInput.text to be selected, when focus=True. Didn't get that to work properly, either.
PLEASE, help me out :-D
Here is my minimal example btw:
import kivy
kivy.require('1.11.0')
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
Builder.load_string('''
<CustomInput#TextInput>:
text: "Blindtext"
size_hint_y: 0.1
pos_hint: {"center_y": 0.5}
multiline: False
write_tab: False
<Box>:
padding: 20,0,20,0
spacing: 10
CustomInput
CustomInput
CustomInput
''')
class Box(BoxLayout):
pass
class TestApp(App):
def build(self):
return Box()
if __name__ == "__main__":
TestApp().run()
Highly appreciated!
Cheers,
smarwin

Solved it with this post: https://github.com/kivy/kivy/issues/6560
You have to change the if ['shift'] == modifiers: line to if modifiers == {'shift'}: in the keyboard_on_key_down method of focus.py. You will find this file in your kivy folder in uix/behaviors/.
def keyboard_on_key_down(self, window, keycode, text, modifiers):
if keycode[1] == 'tab': # deal with cycle
if ['shift'] == modifiers:
next = self.get_focus_previous()
else:
next = self.get_focus_next()
if next:
self.focus = False
next.focus = True
return True
return False
No guarantees, but it works fine for me so far.
Cheers,
smarwin

Deleting characters(with backspace) stopped working for me with smarwin's workaround.
Calling super right before final return False fixed it for me.
E.g.
...
next.focus = True
return True
super().keyboard_on_key_down(window, keycode, text, modifiers)
return False
There was some info about it in docs

Related

is there a name for this conditional-checking technique?

so, theres a technique I use in a fair amount of programming languages and projects; and I'm wondering if it has a general, language-agnostic "official" term to describe it.
basically, I nicknamed it "trip switch checking." Its where if you need to check that several variables have specific values, possibly of different types, you first set a boolean to "false" and then in either a loop or several if statements, you check what you need to by setting the boolean to true if any of the other variables don't meet your requirements.
I call it trip-switching because the boolean remains false if the "switch" isn't "tripped," using an analogy from a common safety mechanism on industrial machinery where if something moves too far or gets too close or etc. a physical switch is actually bumped into and it shuts the whole thing down. the idea is not to switch it back off until the obstruction is cleared- the machine cant turn itself back on automatically.
pseudocode example, a function that returns true if the trip switch wasn't hit:
function tripswitchcheck()
{
boolean tripswitch = false
if(idontnwantthis == true)
{
tripswitch = true
}
if(iwantthis == false)
{
tripswitch = true
}
//...etc...basically do stuff to check stuff. if any values are undesired, true the tripswitch.
return !tripswitch
}
It may be bad practice depending on the language and nature of the project, but it works, and that's outside of the scope of this question.
First of all, why would you not just have a positive flag in that example:
function tripswitchcheck()
{
boolean success = true;
if(idontnwantthis == true)
{
success = false;
}
if(iwantthis == false)
{
success = false;
}
//...etc...basically do stuff to check stuff. if any values are undesired, falsify success
return success
}
Secondly, why check the conditions if you already know you have failure. Say that we don't have a forward goto in the language, or else, or early returns (or we don't want to return because something else is done based on the success flag before returning):
function tripswitchcheck()
{
boolean success = true;
if(idontnwantthis == true)
{
success = false;
}
if(success && iwantthis == false) // if success is false, fall through
{
success = false;
}
if(success && !othercondition()) // likewise
{
success = false;
}
//...etc...
return success
}
There are reasons not to use else if some of the conditions make use of earlier results.
Anyway, this just comes from basic logic and scientific reasoning: we have a hypothesis and look for reasons why it is not true.
The name for it is perhaps "single exit rule" and such: the function exits through a single return statement.

Forge Viewer : Turning "Display Edges" per model instead of Global settings

We are displaying an architectural Revit model and adding a fairly detailled site context.
In the Forge Viewer Settings I can turn On or Off "Display Edges" globally.
However we'd like to have the Edges "On" for the Revit Model but "Off" for the context. Is there a way to achieve this?
I found this post and I tried to load the site model with:
viewer.loadDocumentNode(doc, viewables,{
placementTransform: m.matrix,
keepCurrentModels: true,
globalOffset: {x:0,y:0,z:0},
isAEC: false //!<<< Tried this to prevent Edges
})
But it did not change anything and it still depends on the Global settings.
I found another setting and also tried the following but no luck either:
const models = viewer.impl.modelQueue().getModels()
const contextModel = models.filter(m => m.loader.svfUrn === contextURN);
if (Array.isArray(models) && models.length) {
models[0].hasEdges = false;
}
Any help much appreciated!
Not sure which model format of your road model is, but passing the createWireframe: false option should help turn off the model edges with my research.
viewer.loadDocumentNode(doc, bubble, {createWireframe: false, keepCurrentModels: true})

Dash core component for basic Button with click event?

I'm trying to create an app with multiple tabs for different sets of information. My first thought was to use html Buttons but there's not dash_core_component for this, and I can't find documentation on anything I can use in it's place. Basically, when I click a button (or link), I'd like to get a "clicked" event with the id of the button so I can redraw the layout for the selected page.
Is there a way to do this with existing components? Is there documentation on how to create new components that can be wired into the callback system? I feel like I must be missing something obvious, but I've failed to find anything after a lot of searching.
Thanks!
In fact, they do have a click event available for a button in the latest dash_html_components, but it doesn't appear to be fully documented yet. The creator, chriddyp, has stated that the Event object may not be future-proof, but that State should be.
Using State like:
#app.callback(
Output('output', 'children'),
[Input('button-2', 'n_clicks')],
state=[State('input-1', 'value'),
State('input-2', 'value'),
State('slider-1', 'value')])
you can use values as inputs, without initiating the callback if they change -- instead waiting for the Input('button', 'n_clicks') to fire off the callback.
Copying full code example below from the link:
import dash
from dash.dependencies import Input, Output, State
import dash_html_components as html
import dash_core_components as dcc
app = dash.Dash()
app.layout = html.Div([
html.Button('Click Me', id='button'),
html.H3(id='button-clicks'),
html.Hr(),
html.Label('Input 1'),
dcc.Input(id='input-1'),
html.Label('Input 2'),
dcc.Input(id='input-2'),
html.Label('Slider 1'),
dcc.Slider(id='slider-1'),
html.Button(id='button-2'),
html.Div(id='output')
])
#app.callback(
Output('button-clicks', 'children'),
[Input('button', 'n_clicks')])
def clicks(n_clicks):
return 'Button has been clicked {} times'.format(n_clicks)
#app.callback(
Output('output', 'children'),
[Input('button-2', 'n_clicks')],
state=[State('input-1', 'value'),
State('input-2', 'value'),
State('slider-1', 'value')])
def compute(n_clicks, input1, input2, slider1):
return 'A computation based off of {}, {}, and {}'.format(
input1, input2, slider1
)
if __name__ == '__main__':
app.run_server(debug=True)
Aha! Finally found the answer, documented here: https://plot.ly/dash/urls
It would be nice to link this into the User Guide in a more obvious way (in the index?)

Why does KeyboardEvent.target object return false on "is" condition comparing it to its type?

I have a custom skinned spark's RichEditableText component. And I have a listener for keyboard events in my application for some custom hotkeys. I wanted to skip those hotkeys if I'm writing into the RichEditableText so I've added this:
if (event.target is RichEditableText) {
return;
}
But for some reason that didn't work. So I used getQualifiedClassName(event.target) and got spark.components::RichEditableText. I have it imported like this:
import spark.components.RichEditableText;
Why could the original conditional not work?
EDIT:
Here is more thorough logging:
log.info("event.target is RichEditableText " + (event.target is RichEditableText));
log.info("event.target instanceof RichEditableText " + (event.target instanceof RichEditableText));
log.info("event.target.constructor == RichEditableText " + (event.target.constructor == RichEditableText));
log.info("Class(getDefinitionByName(getQualifiedClassName(event.target))) == RichEditableText " + (Class(getDefinitionByName(getQualifiedClassName(event.target))) == RichEditableText));
log.info("event.target actually is " + getQualifiedClassName(event.target));
And the results:
false
false
false
true
spark.components::RichEditableText
For some reason only the slowest and the most complex method worked. I can use it, but if somebody could share their thoughts on why others don't work, that would be great.
This could happen when the listener and the source of the event are in different application domains. This way you can have exactly the same qualified names, but different classes behind them.
getDefinitionByName() uses the current application domain of the scope you are calling it from. So, in the only successful log line you are comparing the class you have in current domain with RichEditableText reference, which is also in current domain, which naturally yields true.

Checking whether a checkbox is checked

I have not found any inbuilt function for checking whether a checkbox is set true or false,
isChecked() is not available is apps-script (if i am right).
Any idea on how to find it or we shall have a value change handler to count the number of times the value changed and find if it is checked or not?
You should assign your checkbox a name so that you can retrieve its value in a handler function with e.parameter.checkboxname : this value is boolean.
var chkmode = app.createCheckBox("description").setName("chk1").setId("chk1")
with the ID you can modify its state from the handler function (or from any other) if necessary (getElementbyId())
note that the handler can be on the checkbox itself (a change handler) or on any other element in the UI, depending on your needs.
I might be wrong, however I believe there is a problem with the checkBox status, even though its status looks like boolean, it doesn't behave like boolean but like string
if you print in a spreadsheet e.parameter.myCheckBox you will get TRUE or FALSE
if you print in a spreadsheet e.parameter you will get the whole object and see myCheckBox=true or myCheckBox=false
however, if (e.parameter.myCheckBox) will always return True
the workaround I am using is: if (e.parameter.myCheckBox == "true") will return the actual myCheckBox status
Just in case, I am opening a new ticket in the issue tracker
I hope this would help you
ps. confirmed with Google, e.parameter.myCheckBox is a string, not a boolean
if you want to use it as boolean it would be like (e.parameter.myCheckBox == "true")
var handler = app.createServerClickHandler('tellStatus');
and then (as example showing it in a label)
function tellStatus(e){
var app = UiApp.getActiveApplication();
app.getElementById('yourStatusLabel').setText('Checkbox checked: ' + e.parameter.yourCheckbox)
return app;
}
You should use handler function look like below.
I found example from https://sites.google.com/site/scriptsexamples/learn-by-example/uiapp-examples-code-snippets/check-box
if(e.parameter['checkbox_isChecked_'] == 'true'){
itemsSelected+= e.parameter['checkbox_value_']+',';
}