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

Fix TextInputCutCopyPaste widget #7905

Merged
merged 1 commit into from Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 19 additions & 18 deletions kivy/data/style.kv
Expand Up @@ -46,8 +46,6 @@
background_disabled_normal: 'atlas://data/images/defaulttheme/bubble_btn'
background_disabled_down: 'atlas://data/images/defaulttheme/bubble_btn_pressed'
border: (0, 0, 0, 0)
size_hint_y: None
height: dp(30)

<Slider>:
canvas:
Expand Down Expand Up @@ -201,29 +199,32 @@
rgba: self.disabled_foreground_color if self.disabled else (self.hint_text_color if not self.text else self.foreground_color)

<TextInputCutCopyPaste>:
content: content.__self__
but_cut: cut.__self__
but_copy: copy.__self__
but_paste: paste.__self__
but_selectall: selectall.__self__

size_hint: None, None
size: '150sp', '50sp'
BubbleButton:
id: cut
text: 'Cut'
on_release: root.do('cut')
BubbleButton:
id: copy
text: 'Copy'
on_release: root.do('copy')
BubbleButton:
id: paste
text: 'Paste'
on_release: root.do('paste')
BubbleButton:
id: selectall
text: 'Select All'
on_release: root.do('selectall')
BubbleContent:
id: content
BubbleButton:
id: cut
text: 'Cut'
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm do we have many places with hardcoded strings in kivy?

on_release: root.do('cut')
BubbleButton:
id: copy
text: 'Copy'
on_release: root.do('copy')
BubbleButton:
id: paste
text: 'Paste'
on_release: root.do('paste')
BubbleButton:
id: selectall
text: 'Select All'
on_release: root.do('selectall')

<CodeInput>:
font_name: 'data/fonts/RobotoMono-Regular.ttf'
Expand Down
9 changes: 8 additions & 1 deletion kivy/tests/test_uix_textinput.py
Expand Up @@ -8,7 +8,7 @@

from kivy.core.window import Window
from kivy.tests.common import GraphicUnitTest, UTMotionEvent
from kivy.uix.textinput import TextInput
from kivy.uix.textinput import TextInput, TextInputCutCopyPaste
from kivy.uix.widget import Widget
from kivy.clock import Clock

Expand Down Expand Up @@ -546,6 +546,13 @@ def make_scrollable_text_input(self, num_of_lines=30, n_lines_to_show=10):
self.advance_frames(1)
return ti

def test_cutcopypastebubble_content(self):
tibubble = TextInputCutCopyPaste(textinput=TextInput())
assert tibubble.but_copy.parent == tibubble.content
assert tibubble.but_cut.parent == tibubble.content
assert tibubble.but_paste.parent == tibubble.content
assert tibubble.but_selectall.parent == tibubble.content


def ti_height_for_x_lines(ti, x):
"""Calculate TextInput height required to display x lines in viewport.
Expand Down
8 changes: 3 additions & 5 deletions kivy/uix/textinput.py
Expand Up @@ -164,7 +164,7 @@ def insert_text(self, substring, from_undo=False):
from kivy.graphics.texture import Texture

from kivy.uix.widget import Widget
from kivy.uix.bubble import Bubble, BubbleContent
from kivy.uix.bubble import Bubble
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.image import Image

Expand Down Expand Up @@ -306,8 +306,6 @@ def __init__(self, **kwargs):
super().__init__(**kwargs)
self._check_parent_ev = Clock.schedule_interval(self._check_parent, .5)
self.matrix = self.textinput.get_window_matrix()
self.bubble_content = BubbleContent
self.add_widget(self.bubble_content)

with self.canvas.before:
Callback(self.update_transform)
Expand Down Expand Up @@ -374,7 +372,7 @@ def on_parent(self, instance, value):
mode = self.mode

if parent:
self.bubble_content.clear_widgets()
self.content.clear_widgets()
if mode == 'paste':
# show only paste on long touch
self.but_selectall.opacity = 1
Expand All @@ -389,7 +387,7 @@ def on_parent(self, instance, value):
widget_list = (self.but_cut, self.but_copy, self.but_paste)

for widget in widget_list:
self.bubble_content.add_widget(widget)
self.content.add_widget(widget)

def do(self, action):
textinput = self.textinput
Expand Down