Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextInput: Fix readonly mode preventing using cursor keys, wrapping, and more #7449

Merged
merged 21 commits into from Apr 8, 2021

Conversation

tshirtman
Copy link
Member

@tshirtman tshirtman commented Mar 27, 2021

Maintainer merge checklist

  • Title is descriptive/clear for inclusion in release notes.
  • Applied a Component: xxx label.
  • Applied the api-deprecation or api-break label.
  • Applied the release-highlight label to be highlighted in release notes.
  • Added to the milestone version it was merged into.
  • Unittests are included in PR.
  • Properly documented, including versionadded, versionchanged as needed.

@tshirtman tshirtman changed the title TextInput readonly shouldn't prevent using cursor keys Fix TextInput readonly mode preventing using cursor keys Mar 27, 2021
@tshirtman tshirtman added the Component: core-widget properties, eventdispatcher, widget.py, animation label Mar 27, 2021
gabriel pettier and others added 9 commits March 30, 2021 00:51
remove some unused variables and obsolete arguments to super()
some indentation cleanup
give clearer names to some variables
remove unnecessary operations
Might incure a cost from calling a function in a tight loop, but should make the code a bit easier to understand.
when False, even multiline text doesn't wrap
Add Stencil instructions to TextInput to mitigate glitches
Some more improvements taken from PR 6348

Co-authored-by: Vyacheslav Korneev <vchslv13@ukr.net>
@tshirtman tshirtman force-pushed the textinput_fix_cursor_keys_in_reatonly branch from 8677fc8 to d459b50 Compare March 31, 2021 23:46
Solves some artifacts that were still visible
@matham
Copy link
Member

matham commented Apr 1, 2021

Since you're working on textinput, I noticed when testing rtl with harfbuzz that the cursor appears in the wrong side of the text (on the right, rather than left). Feel free to ignore this though if it's unrelated to your changes. This would probably become hard quickly, especially since you can have rtl and ltr in the same text. But I guess rn we assume it just has one direction!?

@tshirtman
Copy link
Member Author

I'll see if i spot the issue, currently we assume one line has a direction, but it might be different from the lines before and after, and this assume that the provider can tell us the direction of a string of character (the base implementation always return 'rtl', and pango is the only core text provider to provide an alternative implementation, but maybe sdl2 could have its own override when harfbuzz is present.

@matham
Copy link
Member

matham commented Apr 1, 2021

Harfbuzz doesn't seem to have an API for getting the direction of text, so only pango can currently provide it. We'd need fribidi to implement it ourselves.

gabriel pettier added 3 commits April 2, 2021 02:56
Add a `managed_textinput` on WindowBase (False) to declare subclasses using
`on_textinput` to insert text, rather than testing the module name of the
Window instance in TextInput.
remove stencil from TextInput in style.kv
better fix for glitches when text outside of view
matham
matham previously approved these changes Apr 5, 2021
Copy link
Member

@matham matham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is your revenge for the giant properties PR, isn't it 😅🤣

One thing I noticed, which is probably a old bug, but since you fixed wrapping you may want to look at it, but don't feel obligated:

  • With a long line that wraps, if you place cursor at start of second line where it wraps and backspace, wrapping will break and it'll be a long line again
    • In the above situation, hitting home/end keys brings you to end of line but it's off screen, but right/left arrow does scroll to the right.

# Keycodes on OS X:
ctrl, cmd = 64, 1024
key, key_str = keycode
key, _ = keycode
win = EventLoop.window

# This allows *either* ctrl *or* cmd, but not both.
modifiers = set(modifiers) - {'capslock', 'numlock'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
modifiers = set(modifiers) - {'capslock', 'numlock'}
modifiers = set(modifiers)

Comment on lines +2714 to +2715
modifiers == {'ctrl'}
or _is_osx and modifiers == {'meta'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
modifiers == {'ctrl'}
or _is_osx and modifiers == {'meta'}
'ctrl' in modifiers and 'meta' not in modifiers
or _is_osx and 'ctrl' not in modifiers and 'meta' in modifiers

I think this is safer because numlock/capslock may not be the only modifiers active, but we can't know what they would be. But I don't feel very strongly about this.

kivy/uix/textinput.py Show resolved Hide resolved
@matham matham added this to the 2.1.0 milestone Apr 5, 2021
@matham matham changed the title Fix TextInput readonly mode preventing using cursor keys TextInput: Fix readonly mode preventing using cursor keys Apr 5, 2021
@tshirtman
Copy link
Member Author

I think we still have issues with cursor management indeed, that i would like to fix, regarding cursor management, i've seen some when do_wrap is False, and i'll look for the one you mention when it's True.

It's not a revenge PR, it's just that you said the code wasn't clear, and i very much agreed, so i tried to improve the situation, a bit all over the place (yes, it is revenge).

I'm not sure i can consider this done yet, i've also seen some glitches when backspacing on long lines, that would need to be addressed, hopefully i'll find the cause.

Thanks for the suggestions, i'll look at what they mean :).

Use triggered to call the scrollupdate after other things are computed
There might be a more subtle solution, but i didn't see it.
fix #6953
@tshirtman tshirtman force-pushed the textinput_fix_cursor_keys_in_reatonly branch from ddbab7b to 47053a3 Compare April 5, 2021 22:38
@matham
Copy link
Member

matham commented Apr 7, 2021

Looks like all the tests are failing. Lemme know if you're at a point that needs review (it looks ok to me besides the set comments above, but I didn't test the recent changes).

@tshirtman
Copy link
Member Author

I had missed a part of the commit and forgot to check if the tests were passing >_>

@tshirtman tshirtman force-pushed the textinput_fix_cursor_keys_in_reatonly branch from 935261d to 2c29d32 Compare April 8, 2021 00:44
@tshirtman tshirtman force-pushed the textinput_fix_cursor_keys_in_reatonly branch from 2c29d32 to 9758a1e Compare April 8, 2021 00:49
@@ -176,10 +176,12 @@ def insert_text(self, substring, from_undo=False):


if 'KIVY_DOC' in environ:
def triggered(*_):
def triggered(*_, **__):
def func(*args, **kwargs):
return func(*args, **kwargs)
return func
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem is that it is named func but both return triggered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i was tired i guess, max recursion 😆

kivy/uix/textinput.py Outdated Show resolved Hide resolved
kivy/uix/textinput.py Outdated Show resolved Hide resolved
kivy/uix/textinput.py Outdated Show resolved Hide resolved
@tshirtman
Copy link
Member Author

Ok, just the mouse test failing now.

@matham
Copy link
Member

matham commented Apr 8, 2021

There's a few more things I noticed as I was playing with it, but you don't have to fix it in this PR if you don't feel like it, these have been there for a while probably.

  1. Look at the top box as I change the window width:
    image
  2. With a long line that wraps, if you backspace before the first character on second line, the previous line stops wrapping.
  3. With a line that wraps across multiple lines or multi-line text, if you use up-arrow, it doesn't keep its position horizontally based on the pixel number offset from left, but rather based on number of characters. So with non-uniform character font, it looks weird and is different than e.g. firefox.

@tshirtman tshirtman merged commit da306e1 into master Apr 8, 2021
@tshirtman tshirtman deleted the textinput_fix_cursor_keys_in_reatonly branch April 8, 2021 07:40
@tshirtman
Copy link
Member Author

There's a few more things I noticed as I was playing with it, but you don't have to fix it in this PR if you don't feel like it, these have been there for a while probably.

Yeah, this one is large enough :D

1. Look at the top box as I change the window width:
   ![image](https://user-images.githubusercontent.com/1644286/113986057-d11f6780-981a-11eb-8f2d-19adf6c76121.png)

2. With a long line that wraps, if you backspace before the first character on second line, the previous line stops wrapping.

Funnily enough, i was able to reproduce this once a few days ago, but not on subsequent attempts, will have to try again.

3. With a line that wraps across multiple lines or multi-line text, if you use up-arrow, it doesn't keep its position horizontally based on the pixel number offset from left, but rather based on number of characters. So with non-uniform character font, it looks weird and is different than e.g. firefox.

Nice catch, i guess we could use the get_cursor_from_xy at the new y pos and the old x pos and move to that new index, or maybe there is a way to only do one jump.

@tshirtman
Copy link
Member Author

Merged, i hope i didn’t break anything, pretty sure that did more good than harm though :D, at least it should be a tad easier to fix bugs in places the code was clarified.

@matham matham changed the title TextInput: Fix readonly mode preventing using cursor keys TextInput: Fix readonly mode preventing using cursor keys, wrapping, and more Apr 8, 2021
hamlet4401 pushed a commit to tytgatlieven/kivy that referenced this pull request Jul 3, 2021
* Fix: readonly shouldn't prevent using cursor keys
* Meature: add do_wrap option (default True)
  - when False, even multiline text doesn't wrap
* More complete example in `__main__` guard
* Add a `managed_textinput` on WindowBase (False) to declare subclasses using
  `on_textinput` to insert text, rather than testing the module name of the Window
   instance in TextInput.
* Use triggered to call the scrollupdate after other things are computed
  Fixes offset lagging one motion behind cursor
  There might be a more subtle solution, but i didn't see it.
  fix kivy#6953
* fix: if inserting a tab while there is a selection, delete the selection
* Solve glitches when backspacing a long line
* Cleanup
  - remove some unused variables and obsolete arguments to super()
  - some indentation cleanup
  - give clearer names to some variables
  - remove unnecessary operations
  - extract `_draw_line` method from `_update_graphics`
     Might incure a cost from calling a function in a tight loop, but should make the code a bit easier to understand.
  - clarify and optimize _update_graphics_selection
  - clarify and optimize cursor_index
  - improvements taken from PR kivy#6348
  - pep8 fixes
  - don't show a line rectangle at all if horizontal scroll > line width
  - solve some artifacts that were still visible
  - clarify the logic handling keys a bit further
  - always return cursor as ints
  - selection drawing improvements

Co-authored-by: Vyacheslav Korneev <vchslv13@ukr.net>
@Alspb
Copy link
Contributor

Alspb commented Sep 19, 2021

There is a problem if do_wrap is False: long lines are represented as black rectangles.
E.g. TextInput('aaaaa'+'\n'+'b'*3000+'\n'+'ccccc') looks like:

Long lines bug

The reason is that the same holds true for Label (and textinput lines are in fact Labels). But for Label it's not a big issue (don't see any reason for using such long lines), while for TextInput it seems to be significant.

misl6 added a commit that referenced this pull request Mar 6, 2022
* Add tests for f-string support in kvlang

* Add missing versionchanged for f-strings in kvlang documentation

* document recyclelayout properties.

* Use lazy property creation.

* Switch to descriptor __set_name__.

* Add tests and switch properties to pytest so we can use parameterize.

* Consistently check for specific types.

* Pass storage as arg to prevent uneeded lookup.

* Pass storage to dispatch to prevent uneeded lookup.

* Broaden accepted list types to before.

* Test complex widget.

* Fix fbind returning uid and prop inheritance order, add test.

* Focus: Allow modifiers (e.g. numlock) be present to tab cycle focus (#7372)

* allow modifiers besides 'shift' to trigger get_focus_previous(), fixes #7364

* restrict modifiers that can trigger get_focus_previous()

* fix typo, use 'in' instead of '&'

* Prevent Dropdown position calculation if parent is None.

* Fixed assigning of y value for mouse position in WindowSDL provider.

* added OnCompletionListener class

* set completion listener for media player

* Fix PEP E501: line too long

* Added TouchRippleBehavior and TouchRippleButtonBehavior to factory_registers.py module.

* replace --build-bottle with --build-from-source

* Fix typos

* nit, capitalize start of sentence.

* Add missing parentheses around inline if statement

This caused the string "requested vsync failedsucceeded" to be logged instead of the intended "requested vsync failed, trying fallback to 1: succeeded"

* Fix incorrect assumption property doesn't exist in class after instance added it

* DropDown: Prevent position calculation if attached widget is not visible. (#7426)

* Print remaining events before next frame upon too much iteration error.

* Add versionadded.

* Fix misc. typos (#7432)

* Fix misc. typos

Found via `codespell`

* Fix source typos

Changes to API

* ModalView: code cleanup regarding detection of main-Window: (#7434)

* ModalView: code cleanup regarding detection of main-Window (WIP):

#7412 -discussion-follow-up from 14-Mar-2021 with @matham (pinging @tshirtman).

- removed unneeded _search_window() method and attach_to property.
- added undocumented events on_pre_open and on_pre_dismiss to module docstring.
- allow stacking of multiple ModalView instances.
- simplified demo code.
- simplified unit test (test_uix_modal.py).

* ModalView: code cleanup regarding detection of main-Window - Part 2 (all unit tests passing):

#7412 -discussion-follow-up from 14-Mar-2021 with @matham (pinging @tshirtman).

- removed _window property.
- added _is_open property.

* ModalView: code cleanup regarding detection of main-Window - Part 3 (tests passing):

- restored the `_window` property of `ModalView` to bind Window.size
  to the overlay canvas rectangle instruction.
- extended unit tests.

* ModalView: code cleanup regarding detection of main-Window - Part/commit 4:

- added a note in the module docstring regarding the remove of the
  unneeded `attach_to` property.

* ModalView: code cleanup regarding detection of main-Window - Part/commit 5:

- resolved conversations from code review.
- python3 and code style enhancements (pylint/PyCharm).

* Apply suggestions from code review

Co-authored-by: matham <moiein2000@gmail.com>

* check for "sphinx" in command line

* `suggestion_text` property broken for empty values

Seems the code was never really functionnal for this case, making the
feature quite weird to use, as it would hide te whole text if the
suggested text was set to an empty string.
Also adapted the example to make it slightly more realistic

* Actually remove suggestion_text feature.

We now support native suggestions through the FocusBehavior & Window support for suggestions, which makes this feature confusing, and considering its limitations that have gone unresolved for 5 years, it seems better to drop it entirely.

* Drop long and document numpy issues.

* Moved Config import in compoundselection.py to fix creating of docs.

* Removed/replaced all basestring with str.

* Mouse: Fix computation of relative touch position in MouseMotionEventProvider (#7425)

* Fixed computation of relative value for touch position in MouseMotionEventProvider and absolute value in MouseEvent.

* Updated MouseMotionEventProvider prevent zero division error when computing touch relative position.

* Updated MotionEvent.scale_for_screen to ensure non-negative max value for x, y and z.

* Updated MultitouchSimulatorTestCase, AsyncUnitTestTouch and UnitTestTouch classes.

* Fix Type Error when creating bytes from array (in Python 3.8.6)

The original line `buf = b''.join(map(chr, buf))` raises the following error in 3.8.6:
    `TypeError: sequence item 0: expected a bytes-like object, str found`

* Added OnePlus 6t

* Only check for threading issues once graphics is initialized

* Fix for scroll bar areas blocking clicks when scroll is disabled (#7457)

* Fix for scroll bar areas blocking clicks when scroll is disabled

See issue #7456 for details

Co-authored-by: Gabriel Pettier <gabriel.pettier@gmail.com>

* EventDispatcher: Rename method unregister_event_types to unregister_event_type (#7445)

* Renamed EventDispatcher method unregister_event_types to unregister_event_type.

* Deprecated method unregister_event_types in EventDispatcher.

* AsyncImageTestCase: Fix for test_reload_asyncimage method and cleanup (#7461)

* Cleanup of AsyncImageTestCase and fixed test_reload_asyncimage method.

* Mouse: Update MouseMotionEventProvider to dispatch hover events (#7387)

* Updated MouseMotionEventProvider to dispatch hover events.

* Fixed relative position for hover event in MouseMotionEventProvider.

* Fixed super call in MouseMotionEvent.

* Updated MouseMotionEventProvider to include density when computing mouse position for hover event.

* Updated MultitouchSimulatorTestCase to work changes in MouseMotionEventProvider.

* Added MouseHoverEventTestCase to test hover event from MouseMotionEventProvider.

* Fixed MouseHoverEventTestCase.

* Moved MouseMotionEventProvider from global to local import in MouseHoverEventTestCase and MultitouchSimulatorTestCase.

* Updated MouseHoverEventTestCase to use one handler for on_touch_xxx events.

* 🚨 Add test commands for missing lines

* 🔨 Made including lines the default

* 🔨 Revert back to previosu metho

* Text: Raise when registering a font_regular with None (#7467)

Raise when registering a font_regular with None

* Add unit test, fix pytest warning

* TextInput: various fixes and refactoring (#7449)

* Fix: readonly shouldn't prevent using cursor keys
* Meature: add do_wrap option (default True)
  - when False, even multiline text doesn't wrap
* More complete example in `__main__` guard
* Add a `managed_textinput` on WindowBase (False) to declare subclasses using
  `on_textinput` to insert text, rather than testing the module name of the Window
   instance in TextInput.
* Use triggered to call the scrollupdate after other things are computed
  Fixes offset lagging one motion behind cursor
  There might be a more subtle solution, but i didn't see it.
  fix #6953
* fix: if inserting a tab while there is a selection, delete the selection
* Solve glitches when backspacing a long line
* Cleanup
  - remove some unused variables and obsolete arguments to super()
  - some indentation cleanup
  - give clearer names to some variables
  - remove unnecessary operations
  - extract `_draw_line` method from `_update_graphics`
     Might incure a cost from calling a function in a tight loop, but should make the code a bit easier to understand.
  - clarify and optimize _update_graphics_selection
  - clarify and optimize cursor_index
  - improvements taken from PR #6348
  - pep8 fixes
  - don't show a line rectangle at all if horizontal scroll > line width
  - solve some artifacts that were still visible
  - clarify the logic handling keys a bit further
  - always return cursor as ints
  - selection drawing improvements

Co-authored-by: Vyacheslav Korneev <vchslv13@ukr.net>

* Merge pull request #7418 from kivy/fix-7417

Fixes video thread that sleep before dispatching eos.

* Add support for preview image to Video (#7471)

* Add support for preview image to Video
* Overhaul preview image support in video widget. Add set_texture_from_resource function on image widget
* Update documentation of Video widget
* Allow None for source related string properties in Video widget
* only update source when preview_source changes in video widget.

Co-authored-by: matham <matt@einhorn.dev>

* Skip MouseHoverEventTestCase on Windows platform on CI.

* ✨ Remove unused variable assignment

* 🚧 Added test for config callbacks

* ⬆️ Added test for config reading

* 🚧 Added test for configparser defaults

* 🔨 Fix relaitve path issue

* ✨ Siplify assertion

* ♻️ Switch to more standard assertions

* Doc: Properties spelling fix (#7481)

* properties.pyx one-line spelling fix

* Better fix

Co-authored-by: matham <matt@einhorn.dev>

Co-authored-by: matham <matt@einhorn.dev>

* Fix assumption that modifiers is always a set. (#7488)

* Accept str-subclass where we accept strings. (#7459)

* WindowBase: Add to_normalized_pos method (#7484)

* Added to_relative_pos method to WindowBase.

* Added test for WindowBase.to_relative_pos method.

* Renamed Window method to_relative_pos to to_normalized_pos.

* Updated doc and unit test of method Window.to_normalize_pos.

* Restoring system_size with the same type in WindowBaseTest.test_to_normalize_pos method.

* MouseHoverEventTestCase: Enabled on Windows CI (#7483)

* Enabled MouseHoverEventTestCase on Windows CI.

* Updated MouseHoverEventTestCase to skip test methods dispatching 'on_close' on Windows CI.

* Updated MouseHoverEventTestCase to restore values of Window properties.

* Removed unused id_rsa.enc. ssh keys are in the secret env (#7495)

* Update events.rst (#7497)

Remove the Python 2 compatible use of `super()`, it still works in Python 3, but is no longer idiomatic for  a framework supporting Python 3.5-3.9.

* MultitouchSimulatorTestCase: Don't render widgets and set framecount to 3.

* Switch rsa ssh key to ed25519 for server upload [build wheel]. (#7509)

* App: Process app quit event while paused (#7508)

* Fix case when app receives quit event while paused

* Fix case when app receives app_terminating event while paused

* Latest pyinstaller includes required fixes for tests. (#7513)

* EventLoopBase: Start/stop event loop only once.

* EventLoopBase: Remove provider from auto-remove list.

* MouseHoverEventTestCase: Dispatching event on_cursor_leave to cleanup some tests (#7494)

* MouseHoverEventTestCase: Dispatching event on_cursor_leave to cleanup some tests.

* MouseHoverEventTestCase: Disable on_window_flip method.

* MouseMotionEventProvider: Refactor of provider and tests (#7492)

* Refactor MouseMotionEventProvider and its tests.

* Swap arguments of MouseMotionEventProvider.create_hover method.

* Don't accept on_mouse_xxx events in MouseMotionEventProvider so that user can handle them too.

* Minor refactor in MouseMotionEventProvider.

* GraphicUnitTest: Added clear_window_and_event_loop method.

* GraphicUnitTest: Fix signature of tearDown method to use (*args, **kwargs).

* MouseHoverEventTestCase: Removed skip of test methods on Windows CI.

* Core: Use importlib's __import__ for compatibility with patching (#7517)

* use importlib.__import__

* fix line length

Co-authored-by: hiaselhans <simon.klemenc@gmail.com>

* Fix case when unload of kivy.uix.video.Video gets called before core video triggers eos

* EventDispatcher: Add nicer error message for non-existing properties (#7536)

* nicer error message for unknown properties

* edit kivy/tests/test_widget.py

* edit kivy/_event.pyx

* edit kivy/_event.pyx, edit kivy/tests/test_widget.py

* edit kivy/_event.pyx

* edit kivy/_event.pyx

* edit kivy/tests/test_widget.py, edit kivy/_event.pyx

* edit kivy/tests/test_widget.py

* edit kivy/tests/test_widget.py

* edit kivy/_event.pyx

* more tests

* test

* test

* edit kivy/_event.pyx

* move tests

* fix ALL the things

* Update kivy/_event.pyx

Co-authored-by: matham <matt@einhorn.dev>

* edit kivy/_event.pyx

* pytestify

* remove kivy/graphics/cgl.h

* edit kivy/tests/test_properties.py

* edit kivy/tests/test_properties.py, edit kivy/_event.pyx

* typeerror

* fix

Co-authored-by: matham <matt@einhorn.dev>

* Inititalize disabled color when creating label and disabled (#7527)

* SoundLoader: Fix play calls not working in ffpyplayer after the first (#7541)

* seek on play in ffpyplayer

* remove kivy/graphics/cgl.h, edit .gitignore

* MouseMotionEventProvider: Add disable_hover property (#7549)

* MouseMotionEventProvider: Added disable_hover property.

* MouseMotionEventProvider: Added doc for disable_hover property.

* MouseMotionEventProvider: PEP8 fix.

* MouseMotionEventProvider: Updated doc of disable_hover property.

* MouseMotionEventProvider: Updated doc.

* Comment references the wrong layout (#7560)

There is no BoxLayout anywhere, it should be FloatLayout.

* Typo on docs, missing word (#7561)

* Fix line number references in basic.rst (#7580)

* Fixes double word in docs. (#7581)

Co-authored-by: meow464 <meow464>

* Fixes issue #7514 ('auto_halign_r' referenced before assignment) (#7548)

* Fix PermissionError when reconnecting mtdev input devices (#7587)

The Linux kernel creates input devices then hands permission management off
to udev. This results in a period of time when the device exists, but is
readable only by root. The MTDMotionEventProvider handles reconnects by
spinning in a loop waiting for the device to reappear. As soon as the
device reappears, the provider immediately attempts to create a new mtdev
Device. This happens faster than udev can update the file permissions so
the Device construction fails raising an error causing no further
reconnects to be attempted.

This patch adds some spinning code to the Device object to re-try opening
the device file for a period of time if a PermissionError was received. The
retries will be applied on initial connection to the MT device (in case the
device happened to be newly attached just as the application was starting)
as well as reconnection attempts. Attempts are time-limited so that real
system configuration errors will still be detected, but long enough of a
duration that any reasonable system should have enough time for udev to fix
the permissions. For reference, a Raspberry Pi 4 (a small single-board
computer) takes about 0.6s between creating the file and fixing the
permissions.

* Fix missing word in doc/guide/events.rst

* Fixed unexpected overscrolling when using mouse wheel (#7612)

* Fix install command for zsh

`python -m pip install kivy[base] kivy_examples --no-binary kivy` throws the error `zsh: no matches found: kivy[base]`, you need to use `python -m pip install "kivy[base]" kivy_examples --no-binary kivy` instead

* removed print and added logging to flipVert

Removed unnecessary print statement and made use of Logger

* Fixed TextInput visual selection bugs while scrolling (#7618)

Fixed TextInput visual selection bugs in multiline mode while scrolling vertically.
Removed unecessary operation.

* Sphinx: Use class instead of instance in add_lexer + Fixes search on sphinx>1.7.9 (#7623)

* Use class instead of instance in add_lexer

* Fixes search with newer sphinx

* Fixes missing documentation_options (#7624)

* Fixes TextInput cursor issues when resizing/scrolling (#7622)

* Fixes text input cursor issues when resizing/scrolling

* refactoring

* Fixed inconsistent behavior of TextInput bubble and handles (#7621)

* Fixed inconsistent behavior of TextInput bubble and handles

The entirety of the bugs resolution is conditioned to the approval of #7618

* Fix the bug that do not limit selection to the current line using handles

Fix the bug that do not limit selection to the current line, while using handles and in multiline mode

* Refactoring

* bugfix: tutorials pong score countup on right side (#7603)

The ball wasn't acting correctly when touching the right side:
The score countup occured when the ball's left side touched the right
wall.

* Replace modname_tkinter with 'tkinter' (#7605)

* Update line number refs (& remove one unclear one) (#7625)

* Fixed unexpected overscrolling bug when using mouse wheel, complement to #7612  (#7615)

* Update textinput.py

* refactoring for readability/identification

* refactoring

* TextInput loading time optimisation for large texts

* Added Custom titlebar support (#7637)

* added SDL_SetWindowHitTest function definitions, and data types
* Added custom_titlebar, custom_titlebar_handler_callback to handle titlebar and resize logic
* added custom_titlebar function
* removed SDL_WINDOWEVENT_HIT_TEST from WindowEventID
* made SDL_HITTEST_DRAGGABLE conditional
* added custom_titlebar in graphics section
* added custom_titlebar as WindowBase propetry
* added custom_titlebar in setup_window
* added custom_titlebar to setup_screen and post init set_border_state
* changed default_language_version to python3
* Implemented Window specific API to Support Aero Snapping
* when custom_title, set borderless state according to platform
* Added conditionl calling of in_drag_function; check for propretry draggable
* Set borderless state depending on platform
* add condition to compile windows specific code on windows only
* group windows code together
* fix resize issue after first drag of window (on windows platform)
* Made use of class _WindowsSysDPIWatch to set WM_NCCALCSIZE
* added variable WM_NCCALCSIZE
* moved the winproc hook code to window_sdl.py
* added handling when custom_titlebar is false on windows
* set_custom_titlebar returns True on 0
* added example for set_custom_titlebar
* changed checking conditions in set_custom_titlebar
* added custom_titlebar_border; bump up config version
* fixed Win32 patform test
* check for resizeable when using custom_titlebar

closes #5279

* MouseMotionEventProvider: Updated doc of disable_hover property.

* Added scroll from swipe feature in TextInput (#7610)

Textinput updated to allow scroll from swipe

* Improve consistency of scroll feature when text input is multiline
* Removing unnecessary calculation in minimum_width variable
  I believe it is unnecessary to perform the calculation using the
` _get_text_width` method, when `self._lines_rects[-1].texture.size[0] `
  already provides the calculated value.
* allows scrolling while text is selected and more...
* bug fixes in the middle handle (which comes out of the text input bounding
  box when scrolling from the swipe) and in the display balloon (which was
  never displayed when using double/triple tap).
* Added descriptive names and comments to explain logic

Co-authored-by: Gabriel Pettier <gabriel.pettier@gmail.com>

* WindowBase: Change type of clearcolor property to ColorProperty. (#7647)

* Rebase pr 2212 (#4546)

* added new type color for a colorpicker setting.

* removed not used textinput property in SettingColor

* added text_size to the color label to allow word wrapping. Looks nicer on smaller screens e.g. 320x480

* change white background rectangle of selected color to a white border.

* Added vesionadded.

* Corrected PEP8.

* Added Type color to doc string.

* ColorSetting: Update versionadded, fix demo config key

* Update kivy/uix/settings.py

update versionadded

* don't import kivy utils from style.kv

as it prevents tests from passing

* pep8 remove duplicate import

Co-authored-by: Alexander Wolf <awolf2904@gmail.com>

* WindowBase: Add transform_motion_event_2d method (#7648)

* WindowBase: Added transform_motion_event_2d method.

* fix various docs (#7672)

* fix kivy/effects/*.py docs
* add 'kivy.clock.triggered' to the doc

* temporary force python3.9 use in the ci (#7674)

* MotionEvent: Fix scale_for_screen method (#7659)

* Fixed scale_for_screen to compute all absolute coords from normalized coords.
* Updating dz only if argument p is passed.
* Updated doc of to_absolute_pos method.
* Renamed arguments of to_absolute_pos method.
* Removed default value for rotation in to_absolute_pos method.
* Minor updated in scale_for_scren and doc update in to_absolute_pos method.
* Minor updated in scale_for_scren and doc update in to_absolute_pos method.I
* Fixed to_absolute_pos for case when rotation is 270 degrees.
* Simplified offset calculation for "scale" keyboard mode in scale_for_screen method.
* Added test_motion_event.py module.
  * Fixed assert message in test_to_absolute_pos method.
  * Added create_dummy_motion_event method.

* Fix dds header comparison (#7688)

* Remove wording and functions specific to Python 2 (#7693)

* Moved support-request to v2. v1 has been shut down. (#7676)

* [WIP] refactor kivy.lang (#7703)

* remove unnecessary list creations
* remove unnecessary 'len()' calls
* remove unused import statements
* use dict.items() instead of dict.keys()
* replace deprecated stuffs with not-deprecated ones
* remove unnecessary list creation
* explicitly specify file encoding

* Add an option  to force a custom search path for SDL2 frameworks + fixes ARCHFLAGS (#7711)

* Allow to force a custom search path for SDL2 frameworks + fixes ARCHFLAGS

* Removes additional flags that were preventing to build a universal2 wheel.

* change method name to get_color_from_hex (#7706)

* MotionEvent: Fix keeping of the previous normalized position (#7691)

* MotionEvent: Fix keeping of the previous normalized position.
* MotionEvent: Synchronizing normalizied opos, ppos and pos until the first dispatch.
* MotionEvent: Renamed attribute keep_first_prev_pos to sync_with_dispatch.
* MotionEvent: Fixed synchronization of normalized positions until the first dispatch.
* EventLoopBase: Moved me.dispatch_done call to post_dispatch_input method.
* MotionEvent: Moved synchronization until the first dispatch from move to depack method.
* MotionEvent: Fixed commend in depack method.
* MotionEvent: Fixed docstring of method "move".

* MotionEvent: Fixed calculation of z values in scale_for_screen when p is None. (#7679)

* MouseMotionEventProvider: Update simulated touch position on window reisze or rotate. (#7714)

* deprecate 'kivy.utils.SafeList' (#7701)

* deprecate SafeList

* MotionEvent: Fix docstring in dispatch_done method to reference post_dispatch_input. (#7717)

* Textinput:  Fixes issues #7165, #7236, #7235 (#7641)

* Fixed #7165

* Fixed #7236

* Fixed #7235

* Minor refactoring

* Enable pressure for touches in android (and ios?) (#7684)

* enable pressure four touches in android (and some ios devices)

* style fixes

* Add support for Apple Silicon on CI/CD [build wheel osx] [build app osx] (#7678)

* Added support for universal2 wheels, and adds unit testing on our self-hosted Apple Silicon M1 runner

* Improve job name readability

* CodeInput: fixed disappearing lines after inserting text (#7737)

* Textinput on double tap improvement (#7636)

* Improved on_double_tap in textinput - words are selected considering commas, brackets, etc.

* Created separate method for word selection

* Minor refactoring

* Add python3.10 in the ci configuration [build wheel linux] [build wheel osx] [build wheel win] (#7663)

* Add python3.10 in the ci configuration

* Update setup.cfg and setup.py for python3.10

* also update pyproject.toml to allow using latest cython

* update kivy-deps.sdl2 required version in setup.cfg

* bump kivy-deps.sdl2 version

* use develop version of pyinstaller for python3.10 support

* osx try simplified build

* force usage of next funcparserlib release that doesnt use 2to3 in setup.py

* 3.6 reached EOL on 2021-12-23

* macOS: add cp310-macosx_universal2

* We don't install anymore the full version. So ffmpeg dependency is not needed anymore. I expect to have a universal2 whl for ffpyplayer when we will switch back to full,dev

* manylinux2010 --> manylinux2014 (via cibuildwheel)

* Remove dependencies, so we can check delocating. Installs dev version cause support for 3.10 in ffpyplayer is missing

* Update manylinux sdl2 version and max cython version.

* Bump win deps.

Co-authored-by: Mirko Galimberti <me@mirkogalimberti.com>
Co-authored-by: Matt Einhorn <moiein2000@gmail.com>
Co-authored-by: Matthew Einhorn <matt@einhorn.dev>

* Improves docs on mobile, fixes duplicated getting started

* Fixes some bugs in the TextInput if the text is right-aligned or center-aligned and not multiline. (#7631)

* "Partially" fixes the center and right horizontal alignment bug

The bug appears when using multiline equal to false.
The only thing that hasn't been fixed is the appearance of a spacing when you start deleting characters from text larger than the viewport

* Fix the horizontal alignment bug

* pep8

* Minor fix and refactoring

* minor fix

* Update README.md (#7757)

* collections fix for python 3.10 (#7749)

* collections fix for python 3.10

* do not support old versions

* do not support old versions

Co-authored-by: Sander Land <sander@chatdesk.com>

* Fixes benchmark tests on wheels

* Window.softinput_mode fix for "pan" and "below_target" modes when using kivy virtual keyboard. (#7726)

* Softinput_mode fix for pan and below target modes

Fixes issues related to correct Kivy virtual keyboard display for soft_input modes: `pan` and `bellow_target`

* Refactoring

* Removal of unreachable code.

* refactoring and fixes

* pep8

* macOS deps: Update SDL to 2.0.20 and update SDL_ttf to 2.0.18

* Removed Python3.6 from the supported ones, it reached EOL

* Update license year

* Add support for older Sphinx versions

* WindowBase: Removed binding to softinput_mode and keyboard_height from system_size, size, width and height properties.

* Add Linux AArch64 wheel build support

* WindowBase: Add _density to bind list of width and height and remove caching center property.

* Explain the '--' separator for option parsing.

* wip

* Fix widget.disabled handling of value change of equal truthiness

Comparing for equality is too strict, when what we want is to know if
thue value is Truthy or Falsy, this mismatch in condition created cases
where a widget was set to disabled, but wasn't, as well as widgets
staying disabled, when they should have been enabled again.

* Revert "wip"

This reverts commit eb5ea49.

* ScrollEffect: Fix layout when ScrollView gets resized

* TextInput: easier tokenize delimiters setting; quotes removed from default delimiters (#7740)

* Docs review before release 2.1.0 (#7773)

* Docs review - part 1

* Docs review - part 2

* Docs review - part 3

* Docs review - part 4

* Docs review - part 5

* Docs review - part 6

* Docs review - part 6 (Fixes linters automations :/ )

* Docs review - part 7

* Docs review - part 8

* Change default input_type to null. Add some warning regarding TYPE_TEXT_FLAG_NO_SUGGESTIONS (#7744)

* Change default input_type to null. Add some warning regarding TYPE_TEXT_FLAG_NO_SUGGESTIONS

* Improve docs

* Use latest ubuntu to run CI

* Replace ubuntu 18.04 to latest everywhere.

* Bump to 2.1.0rc1 (#7777)

* Updates action-gh-release and use the default token (#7780)

* PyInstaller develop version isn't needed anymore (#7781)

* Revert to 2.1.0.dev0 for test release.

* Feature: EventManagerBase (#7658)

* Added EventManagerBase class and event_managers attribute to WindowBase class.
* Added on_motion event to Widget class.
* Updated post_dispatch_input in EventLoopBase to skip non-touch events.
* Using type ids in MouseMotionEventProvider.
* Added on_motion method to Widget subclasses.
* Updated Widget.on_motion method to dispatch to filtered widgets if 'pos' is not in me.profile.
* Changed motion_filter property in Widget to store key to list values.
* Updated Widget.on_motion to not dispatch event to children if widget is disabled.
* Widget: Using flags to control dispatching in on_motion method.
* Widget: Don't dispatch on_motion to children if only self is registered.
* Widget: Removed collision on disabled check from on_motion method.
* Widget: Added docstrings for motion_filter and related methods.
* EventManager: Moved motion event flags to eventmanager/__init__.py module.
* ScreenManager: Overrode the on_motion method.
* WindowBase: Using attributes event_managers and event_managers_dict.
* WindowBase: Added doc for register_event_manager and unregister_event_manager methods.
* Widget: Improved default dispatch to stop after the last registered widgets.
* EventManagerBase: Added initial docs class and module.
* Widget: Added experimental warnings to motion_filter property and to on_motion and (un)register_for_motion_event methods.
* WindowBase: Added docs for event_managers and event_managers_dict attributes.
* MotionEvent: Added type_id and flags to push_attrs list.
* EventManagerBase: Added versionadded tag on all flags.
* EventManagerBase: Use dispatch modes instead of flags.

* Input providers: Assigned type_id to MotionEvent subclasses.

* WindowBase: Don't return motion event in transform_motion_event_2d method. (#7778)

* made code examples user friendly; fixes #7720 [WIP] (#7790)

* fixes #7720; see sphinx-doc/sphinx#8320 for reference

* applied vendor prefix for safari

* use ::before pseudo element to make line numbers unselectable

* removed trim

* css cleanup; moved the rule to appropriate posotion

* more descriptive comment

* WindowBase: Add on_drop_begin, on_droptext and on_drop_end events (#7786)

* WindowBase: Added on_drop_begin, on_droptext and on_drop_end events.

* WindowBase: Renamed on_dropfile event/method to on_drop_file.

* WindowSDL: Dispatching mouse pos with dropbegin event.

* WindowBase: Updated docs for on_drop_xxx events.

* WindowBase: Removed code from on_drop_file method.

* WindowBase: Updated docs for on_drop_begin and on_drop_end events.

* WindowSDL: Updated _mouse_(x|y) attributes on dropbegin event.

* SDL2: Change return type from Uint8 to Uint32 for mouse state functions to match their signature from SDL_mouse.h.

* WindowSDL: Update mouse_pos value and dispatch of on_cursor_enter event.

* WindowBase: Use same type for mouse_pos (tuple) and _density (float) properties.

* WindowBase: Passing window relative mouse pos in on_drop_begin event and skip mousewheel if the cursor pos is not within the window size.

* Linux AArch64 wheel build optimization (#7784)

* Linux AArch64 wheel build optimisation [build wheel linux]

* Address review comments

* WindowBase|WindowSDL: Added drop position for all on_drop_xxx events.

* WindowBase: Don't dispatch position for the deprecated on_dropfile event.

* Bring perf_test_textinput  inline with changes in TextInput

* WindowBase: Added *args to the default event handlers.

* EventManagerBase: Fix indentation and typos in the doc.

* made Generic Prompt unselectable; fixes #7800

* Dark Theme support for docs (#7799)

* added dark theme css

* merged both theme files; removed dark.css

* removed unrequired variable

* add fuction to switch themes

* add button to switch themes; removed dark.css; load fresh.css after pygements.css;

* Update doc/sources/.templates/layout.html

* add jquery to keep the current 'active' element on API reference be always in center

* remove DRY voilations; beautify css

* removed unnecessary rules

* add toggle button to switch between themes

* add button callback; store prefered theme in localStorage

* made theme toggle button responsive

* improved alingment for mobile screens

* removed unnecessary css; added comments; formated css

* use prefers-color-scheme when localStorage is not initlized

* fix FOIT

* removed code to center active li element in api index (left side panel)

* Bump to 2.1.0rc1 (#7802)

* Use the `KIVY_RPI_VERSION` env variable to force the build of `egl_rpi` in non Raspi CI builds (#7804)

* Use the `USE_RPI` env variable to force the platform to `rpi`

* Update doc/sources/installation/installation-rpi.rst

Co-authored-by: Matt Einhorn <matt@einhorn.dev>

* Introduce new env variable `FORCE_RPI_VERSION` for forcing `egl_rpi`
instead of reusing `USE_RPI`, which has a different connotation.

* Update docs for `FORCE_RPI_VERSION` variable

* Update setup.py

Co-authored-by: Matt Einhorn <matt@einhorn.dev>

* Rename variable to `KIVY_RPI_VERSION`

Co-authored-by: Matt Einhorn <matt@einhorn.dev>

Co-authored-by: Matt Einhorn <matt@einhorn.dev>

* Track whether the clock has started. (#7810)

* Bump cython and kivy_deps versions to latest.

* Textinput: Simplified the swipe feature logic. Fixed a bug that was preventing to show the select all / paste bubble (#7807)

* Simplifies the swipe feature logic. Fixes a bug that was preventing to show the select all / paste bubble

* Update kivy/uix/textinput.py

Co-authored-by: Dexer <73297572+DexerBR@users.noreply.github.com>

Co-authored-by: Dexer <73297572+DexerBR@users.noreply.github.com>

* ⚡ Prevent crash when scrollbar is hidden (#7814)

* MotionEvent: Fix indentation in module doc. (#7815)

* VideoPlayer: Defer before the next frame the default thumbnail and annotations loading (#7816)

* VideoPlayer: Defer before the next frame the default thumbnail and annotations loading.

* Avoid on_ usage, reset thumbnail and add some tests

* Check if annotation is not empty and added a relevant test

* Fix typo

* Patch gst current release to look for dlls in correct place for win store. (#7820)

* Bump to 2.1.0rc2 (#7821)

* Bump to 2.1.0rc3 (#7822)

* Increase timeout to avoid failing tests on windows-2022 (#7827)

* add GitHub URL for PyPi (#7826)

* EventManager: Fix typo in module doc. (#7830)

* Add 2.1.0 changelog (#7831)

* Prepare 2.1.0 release (#7835)

Co-authored-by: Gabriel Pettier <gabriel.pettier@gmail.com>
Co-authored-by: Matthew Einhorn <moiein2000@gmail.com>
Co-authored-by: xayhewalo <7256157+xayhewalo@users.noreply.github.com>
Co-authored-by: AndiEcker <aecker2@gmail.com>
Co-authored-by: pythonic64 <pythonic64@gmail.com>
Co-authored-by: allerter <45076212+Allerter@users.noreply.github.com>
Co-authored-by: Ilya Kochankov <ilyakochankov@yandex.ru>
Co-authored-by: Dominik Spicher <dominikspicher@gmail.com>
Co-authored-by: Kristian Sloth Lauszus <lauszus@gmail.com>
Co-authored-by: luzpaz <luzpaz@users.noreply.github.com>
Co-authored-by: salt-die <53280662+salt-die@users.noreply.github.com>
Co-authored-by: VIGNESH KUMAR <45727291+VICTORVICKIE@users.noreply.github.com>
Co-authored-by: snuq <snuq@snuq.com>
Co-authored-by: zencode <zenkey.zencode@gmail.com>
Co-authored-by: Vyacheslav Korneev <vchslv13@ukr.net>
Co-authored-by: Mathieu Virbel <mat@kivy.org>
Co-authored-by: Robert Niederreiter <office@squarewave.at>
Co-authored-by: matham <matt@einhorn.dev>
Co-authored-by: dirtbirb <11340521+dirtbirb@users.noreply.github.com>
Co-authored-by: Anthon van der Neut <anthon@mnt.org>
Co-authored-by: Kostiantyn Syrykh <cs.this@gmail.com>
Co-authored-by: simon klemenc <hiaselhans@users.noreply.github.com>
Co-authored-by: hiaselhans <simon.klemenc@gmail.com>
Co-authored-by: Sander Land <48946947+sanderland@users.noreply.github.com>
Co-authored-by: meow464 <70211708+meow464@users.noreply.github.com>
Co-authored-by: outdooracorn <43674967+outdooracorn@users.noreply.github.com>
Co-authored-by: Dean Serenevy <dean@serenevy.net>
Co-authored-by: oshotton <oliver@swanbarton.com>
Co-authored-by: Akshay Arora <akshayaurora@gmail.com>
Co-authored-by: Dexer <73297572+DexerBR@users.noreply.github.com>
Co-authored-by: willow <willowjl1117@gmail.com>
Co-authored-by: Vibhakar Solanki <solankivibhakar82@gmail.com>
Co-authored-by: SubaruArai <78188579+SubaruArai@users.noreply.github.com>
Co-authored-by: eric15342335 <70310617+eric15342335@users.noreply.github.com>
Co-authored-by: Geo Maciolek <geoffmaciolek@gmail.com>
Co-authored-by: Alspb <alvspb@protonmail.com>
Co-authored-by: Alexander Wolf <awolf2904@gmail.com>
Co-authored-by: 水戸う納豆齋(Nattōsai Mitō) <flow4re2c@gmail.com>
Co-authored-by: Stanislav Syekirin <Zabolekar@users.noreply.github.com>
Co-authored-by: Alspb <73047043+Alspb@users.noreply.github.com>
Co-authored-by: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com>
Co-authored-by: Sander Land <sander@chatdesk.com>
Co-authored-by: odidev <odidev@puresoftware.com>
Co-authored-by: quanon <akshay@kivy.org>
Co-authored-by: Alexander Lais <alexander.lais@gmail.com>
Co-authored-by: Andrii Oriekhov <andriyorehov@gmail.com>
@maltfield
Copy link

maltfield commented Jul 10, 2022

See also https://stackoverflow.com/questions/72927741/kivy-read-only-textinput-but-with-ability-to-select-all-ctrla

(adding here to make it easier to find for others on search engines)

How can I make a TextInput in a python GUI app built with kivy that's read-only, but where the user can still select all of the text with crtl+a?

Consider the following simplified example program with a TextInput containing over 9000 characters

import random

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput

class MyApp(App):

	def build(self):
		layout = BoxLayout()

		# generate some random ASCII content
		textinput_contents = ''.join( [chr( random.randint(32,127) ) for i in range(0,9001)] )

		# add the textinput
		self.textinput1 = TextInput(
		 text=textinput_contents,
		 readonly=True
		)
		layout.add_widget(self.textinput1)

		return layout

if __name__ == "__main__":
	MyApp().run()

I don't want the user to be able to edit the contents of the TextInput, but I do want them to be able to click around, select text, copy from it, etc. Unfortunaetly, in the above example, typing ctrl+a (for the Select All shortcut) does nothing.

However, if I omit the readonly attribute, then ctrl+a works again!

import random

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput

class MyApp(App):

	def build(self):
		layout = BoxLayout()

		# generate some random ASCII content
		textinput_contents = ''.join( [chr( random.randint(32,127) ) for i in range(0,9001)] )

		# add the textinput
		self.textinput1 = TextInput(
		 text=textinput_contents
		)
		layout.add_widget(self.textinput1)

		return layout

if __name__ == "__main__":
	MyApp().run()

How can I make the kivy TextInput read-only without disabling Select-All (ctrl+a)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: core-widget properties, eventdispatcher, widget.py, animation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants