Why is it impossible to make a Markup TextInput in kivy? - kivy

So i am trying like for months using different techniques to make a markup textinput. However their are a million issues that arises. However if we would see TextInput.py we can see that the textinput uses a label for displaying text. so I tried dding a markup = True to that label. However I see no good result. So why is it that kivy textinput have no markup. and is it possible to add a markup.

TextInput uses labels, but it doesn't inherit the Label class. Even though you set markup = True, nothing happens because TextInput doesn't have the attribute. The kivy document says
The TextInput widget provides a box for editable plain text.

So why is it that kivy textinput have no markup.
Ultimately, because it's hard and nobody has both wanted to and had time to implement that feature.
and is it possible to add a markup.
It is certainly technically possible, but you'd need to read the TextInput source and work out how to add it.

You can extend TextInput to create a markup capable TextInput by importing MarkupLabel as Label like this:
from kivy.core.text.markup import MarkupLabel as Label
from kivy.cache import Cache
from kivy.graphics.texture import Texture
Cache_get = Cache.get
Cache_append = Cache.append
class MarkupTextInput(TextInput):
def _create_line_label(self, text, hint=False):
# Copy this method from TextInput with no changes
The _create_line_label() method creates a Label and uses the Texture from that Label in the TextInput. Normally kivy.core.text.Label is used, but the above mentioned import results in kivy.core.text.markup.MarkupLabel being used instead.
That will give you a MarkupTextInput where you can type in markups (like[b] and [/b]). It is still not complete because the cursor position will be incorrect. When you type in [b], those three characters suddenly disappear, but the cursor position won't back up. Fixing that is the hard part. Maybe someone can figure that part.

Related

Kivy search box with suggestion?

I am beginner to kivy so seniors pls help me how we can bind textinput box to suggestion so that user and touch and select the suggestions?so user can touch(suggestion) ,select and open(suggestion)in Label.I have a long multi text file so i want to open it by chapter or by title.thanks a million for your helpgetting suggestion from search bar
opening suggestion keyword(text)to new screen/Label
it is easier to understand your questions, when you write it more specific and adding the code, e.g. of the TextInput etc.
However, if you want suggestions pop up while the user is typing anything into the TextInput: use the `on_text' method. it gets called when the text is changing.
e.g.
class SearchBar(TextInput):
def on_text(self, widget, value):
#value is the currently typed text
#call function that gets the suggestsions based on the typed text
# use add_widget() function to create Widgets into the layout for the suggestisons....
pass

Custom iOS keyboard - Custom font output

I am trying to create a custom keyboard using the app keyboard extension. I am happy with the layout but the output is depended on the UITextField's font.
Is there a way to force a different font (use special characters?) while using the keyboard ?
Thank you
It depends.
Text field (or any other view that draws text) uses 2 informations on how to show some text. One is the sequence of characters called String and the other one is how the string should be represented. The second one is then split it things like fonts, colors, line height, line breaking and wrapping...
So the keyboard alone is not enough to for instance present a certain part of word using different fonts. You need at least a bit of access to the item that represents the text. So if you have no access to your text field then the answer is; No, you can not fore a different font when using different keyboard.
If you do have the access then the answer should lie in NSAttributedString. It is a string you can assign to most items under attributedText. This class wraps your raw string and can add many properties to parts of text you want to change. That includes using a different font.
Another approach would be using HTML tags. Again you will need to process this using for instance NSAttributedString or display it with another element like web view.
I would try it with using NSAttributedString. Hook up to delegate and implement textField(: shouldChangeCharactersIn: replacementString:. The implementation itself may still not be easy though.

Vaadin Grid wrap labels in componentColumns

I'm currently working on a webapp project in Vaadin 10. On the main page there's an overview of your current chats. Each chat is displayed as a bubble looking like:
It contains an image and a label.
I placed the bubbles in a Grid to ensure fast loading and flexibility like this:
`Grid<VisualGroup> cloudGrid = new Grid<VisualGroup>();
cloudGrid.setWidth("100%");
cloudGrid.setHeight("100%");
cloudGrid.getElement().getStyle().set("border","white");
cloudGrid.addComponentColumn(VisualGroupComponent::new);
cloudGrid.setItems(groups);`
My problem is that the label does not wrap when I put the components in the grid. If I create the component independently the text wraps correctly like:
But if I use the grid like described above it looks:
Does anyone know how to get text wrapping working in ComponentColumns in Vaadin?
If anyone knows the exact attribute I need to overwrite to get just the wrapping working and not delete every thing else that would probably the best solution. But for now that is a workaround.

data-placeholder and jQueryUI autocomplete

Is there a simple way to have a default text in the textbox using jQueryUI's autocomplete ?
I have tried using data-placeholder but it doesn't seem to work.
I have searched online, and people suggest using the textbox value to display the text, and clear it on focus. But then I would need to change the font style just for the default text, and check onKeyUp when the text is manually erased etc...
Is there no easier way to do this ? or am I missing something ?
A lot of people will use a span that is positioned to be over the text box. When the text box gets focus then you hide the span. When the text box blurs and has a value, you don't show it. If it doesn't have a value then you can show it again.
You can style the span however you want independently of the text box so you would not have to change the font style on the text box itself. You would have to subscribe to the focus and blur events, but it would be much easier if you created a jQuery plugin to do this. In fact, I'm sure there are ones that already exist that do this.

Forcing Vaadin Component to occupy it's space in invisible state

I have a Label and a Progess Indicator in my Vaadin indicator. It is dynamically made visible in the UI. There is a Tree below this Progress Indicator.
When the program dynamically sets the visibility of the Progress Indicator to true, the tree shifts down and the UI shakes due to the shifting.
Is there any way to make a Vaadin component occupy it's space, even if it is invisible and hence, when made visible it must not try to borrow space from other UI components?
What I am looking for is a feature similar to setRendered(true) in flex and actionscript programming.
Thanks for your help.
Finally I got an answer to my question. I just replaced the invisible components with a dummy visible label with no text.
And used it alternatively to switch between visible and invisible.
I asked the question in the Vaadin forum, and here's the response I got, from Kim Leppanen:
With Vaadin 7, if you set a component's visibility to false, then the component's information is not sent to the browser at all - it is just as if the component wouldn't exist in the layout at all.
I can quickly come up with two solutions. If you know the size of the component whose visibility you want to toggle, then you can use placeholder components - such as a Label. Put a label with the correct size in the place where you want the component. When you want to set a component as visible, then replace the label with the actual component.
The second option is to use css. Apply the css attribute "visibility: hidden" for the component you want to hide. Note that the component is not "truly" hidden. Let's say that it is a button. A user could still inspect the DOM tree and see the button in the code, change the visibility of the component on the client side (eg using developer tools or firebug) and then see and use the button as if it would be visible in the layout.
I am putting it here because people might add some more useful answers there. For a detailed explanation please see this.
Use this following example to the component you want set invisible but keeping its occupied space:
Image home = new Image();
home.setSource(HOME);
home.addStyleName("visibility: hidden");
OR
home.addStyleName("visibility: collapse");

Resources