Is there a way to scroll text when readonly is True

219 views
Skip to first unread message

Beebee

unread,
Jan 18, 2022, 12:10:01 PM1/18/22
to Kivy users support
I have this .kv code, it scrolls when read only is false, but when read only is true, it doesn't scroll. Please how can I make it to scroll with read only set as true. Thanks

<January1Window>:
    name: "January1"
    nameFeb: January1
    scroll:scroll
    direction:'tb-lr'
    size:(1480, 854)
    ScrollView:
            id:scroll
            bar_color:(0, 0, 0, 0.4)
            bar_inactiv_color:(0, 0, 0.7, 0.4)
            bar_margin:2
            bar_width:8
            on_scroll_x:January1.focus = True
            on_scroll_y:January1.focus = True
            TextInput:
                   size_hint:(0.8, None)
                   height: self.minimum_height

                   id:January1
                   text: root.showJanuary1()
                    readonly: True
                   do_scroll_x:True
                   do_scroll_y:True

Elliot Garbus

unread,
Jan 18, 2022, 3:01:16 PM1/18/22
to kivy-...@googlegroups.com

I suspect you have a different problem, readonly should not impact scrolling.

I see a few things that are errors in your kv code:

The attributes do_scroll_x, do_scroll_y are attributes of ScrollView, not TextInput.

The readonly attribute in TextInput is not properly indented.  I don’t know what layout January1Windows is derived from, I will assume it is a screen.  You have a potential problem that you are setting the size, but not setting the size_hint: None, None.  The size will be ignored if the hint is not turned off.

 

I created a small example that scrolls the textInput and switches the readonly attribute.

Here is an example:

from kivy.app import App
from kivy.lang import Builder

kv =
"""
BoxLayout:
    orientation: 'vertical'
    Label:
        text: 'Scroll TextInput'
        size_hint_y: None
        height: 48
    ToggleButton:
        size_hint_y: None
        height: 48
        text: 'Set Read-Only'
        on_state: text_input.readonly = True if self.state else False
    ScrollView:

        bar_color:(0, 0, 0, 0.4)
        bar_inactiv_color:(0, 0, 0.7, 0.4)
        bar_margin:2
        bar_width:8
        do_scroll_x:True
        do_scroll_y:True
        TextInput:
            id: text_input
            size_hint: .8, None
            height: self.minimum_height
            text: 'This is a long long long set of words
\\n' * 100
"""


class ScrollTextApp(App):
   
def build(self):
       
return Builder.load_string(kv)


ScrollTextApp().run()

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/7c75e712-0853-4d16-8ecb-a7550f547491n%40googlegroups.com.

 

Beebee

unread,
Jan 18, 2022, 5:00:05 PM1/18/22
to Kivy users support
Before clicking the ToggleButton, the text field in not readonly but i can scroll with both the mouse wheel and keyboard arrows. After clicking the  ToggleButton, the text field becomes readonly but i can no longer scroll with the keyboard arrows only the mouse wheel scrolls.
Plese can you help me with a situation whereby the textfield will be read only and i can scroll with both the keyboard arrows and mouse wheel.
Thank you so much

Elliot Garbus

unread,
Jan 18, 2022, 5:31:03 PM1/18/22
to kivy-...@googlegroups.com

When you not in readonly mode, the text is scrolling with in the TextInput, you are not scrolling the ScrollView. 

I suggest you capture the keyboard arrows and use the key press to modify the scroll value (see scroll_x and scroll_y).  This will give you a consistent experience when scrolling with keys or the mouse wheel.

Beebee

unread,
Jan 18, 2022, 11:29:58 PM1/18/22
to Kivy users support
Thank you so much, this is really helpful but it only worked on desktop, it didn't work on mobile. Please how can i make it work on mobile phone? Thanks

Elliot Garbus

unread,
Jan 18, 2022, 11:47:52 PM1/18/22
to kivy-...@googlegroups.com

I have not done any mobile development.  If you share a minimal executable example I’ll be happy to take a look.

I’m not exactly sure what you are trying to achieve.  On mobile I would think it would be more natural to scroll with a finger, than typing arrows.

Bibi Eme

unread,
Jan 31, 2022, 7:01:03 AM1/31/22
to kivy-...@googlegroups.com
Thanks a lot this was really helpful

Reply all
Reply to author
Forward
0 new messages