internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: kivy/kivy

Issue:
multi line TextInput doesn't allow selection after scrolling vertically
It does allow selection on the last line using mouse and using keyboard one is be able to select everything.

The problem is on a multi-line textinput box that has enough lines in it to have made it scroll vertically.
One can not move the cursor using the mouse/touch to anything but the last line, and thus it's seems
impossible to select anything before the last line using only the mouse/touch



Discussion:

Resolving patch:
diff --git a/kivy/uix/textinput.py b/kivy/uix/textinput.py
--- a/kivy/uix/textinput.py
+++ b/kivy/uix/textinput.py
@@ -322,7 +322,9 @@ def get_cursor_from_xy(self, x, y):
         l = self._lines
         dy = self.line_height + self._line_spacing
         cx = x - self.x
-        cy = (self.top - self.padding_y + self.scroll_y * dy) - y
+        scrl_y = self.scroll_y
+        scrl_y = scrl_y/ dy if scrl_y > 0 else 0
+        cy = (self.top - self.padding_y + scrl_y * dy) - y
         cy = int(boundary(round(cy / dy), 0, len(l) - 1))
         dcx = 0
         for i in xrange(1, len(l[cy])+1):
@@ -346,6 +348,8 @@ def cancel_selection(self):
     def delete_selection(self):
         '''Delete the current text selection (if any)
         '''
+        scrl_x = self.scroll_x
+        scrl_y = self.scroll_y
         if not self._selection:
             return
         v = self.text
@@ -355,6 +359,8 @@ def delete_selection(self):
         text = v[:a] + v[b:]
         self.text = text
         self.cursor = self.get_cursor_from_index(a)
+        self.scroll_x = scrl_x
+        self.scroll_y = scrl_y
         self.cancel_selection()
 
     def _update_selection(self, finished=False):


Test patch:
Repository: kivy/kivy

Issue:
Bubble Widget remains open even when TextInput is removed...
from it's parent.



Discussion:
I was going to open an issue for this one last week, but i forgot. Need to be resolved before the next release :)


Resolving patch:
diff --git a/kivy/uix/textinput.py b/kivy/uix/textinput.py
--- a/kivy/uix/textinput.py
+++ b/kivy/uix/textinput.py
@@ -455,21 +455,27 @@ def on_touch_up(self, touch):
                     'Cannot show bubble, unable to get root window')
                 return True
             if self.selection_to != self.selection_from:
-                self._show_cut_copy_paste(touch, win)
+                self._show_cut_copy_paste(touch.pos, win)
             else:
                 win.remove_widget(self._bubble)
             return True
 
-    def _show_cut_copy_paste(self, touch, win):
+    def _show_cut_copy_paste(self, pos, win, parent_changed = False, *l):
         # Show a bubble with cut copy and paste buttons
         bubble = self._bubble
         if bubble is None:
             self._bubble = bubble = TextInputCutCopyPaste(textinput=self)
+            self.bind(parent = partial(self._show_cut_copy_paste,
+                pos, win, True))
         else:
-            win.remove_widget(self._bubble)
+            win.remove_widget(bubble)
+            if not self.parent:
+                return
+        if parent_changed:
+            return
 
         # Search the position from the touch to the window
-        x, y = touch.pos
+        x, y = pos
         t_pos = self.to_window(x, y)
         bubble_size = bubble.size
         win_size = win.size


Test patch:
Repository: kivy/kivy

Issue:
Markup Label width is not calculated properly
To reproduce the problem:

```
1) start the rest editor in the examples directory.
2) Type a set of characters that use kerning like:
     Kivvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvy Hello or
     wwwwwwwwwwwwwwwwwwwwwwwww Hello or
     vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv Hello or
     ///////////////////////////////////////////////////////////////////////// Hello or
    AAAAAAAAAAAAAAAAAAAAAAAAAAAA hello or
     ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff Hello or 
    jjjjjjjjjjjjjjjjjjjjjjjJJJJJJJJJJJJJJJJJJJJJJJJJ Hello or 
    XXXXXXXXXXXXXXXXXXXXXXXXXXXX Hello or
3) Look at the rst document on the right, the space before "Hello" is just one space character but displayed like multiple spaces.
```

In normal usage when typing something like this "from kivy.uix.button import Button" the difference
 between buttton>import and import->Button is clearly visible



Discussion:

Resolving patch:
diff --git a/kivy/core/text/markup.py b/kivy/core/text/markup.py
--- a/kivy/core/text/markup.py
+++ b/kivy/core/text/markup.py
@@ -226,9 +226,10 @@ def _pre_render_label(self, word, options, lines):
 
             # calculate the size of the part
             # (extract all extents of the part,
-            # sum the width, and get the maximum height)
+            # calculate width through extents due to kerning
+            # and get the maximum height)
             pg = [cache[g] for g in part]
-            pw = sum([g[0] for g in pg])
+            pw = get_extents(part)[0]
             ph = max([g[1] for g in pg])
 
             options = copy(options)


Test patch:
Repository: kivy/kivy

Issue:
Label Text Clipped Horizontally (Moved)
**Originally reported as a continuation of #576 by esbullington**

I think I'm having trouble with this same issue.  I'm trying to use markup with a Label, and am finding that my Label text is cut-off along the horizontal axis if I have markup set to True.  This probably is only occurring with the latest development version, even after the above path was pulled.  The problem does not occur with Kivy 1.3.0.  If needed, I can re-install the development version and make a screen shot, but for now I'm working with Kivy 1.3.0. 

I've only started working with Kivy in the past few days, so I'm not yet in a place where I feel comfortable sending in a patch.  (awesome framework, by the way, congrats on the great work!).

Oh, and it doesn't look like I can re-open the issue, so someone else may wish to do so, or else tell me to open another issue for the problem.

UPDATE: I coped markup.py from Kivy 1.3 to Kivy1.4-dev and it resolved this issue for me.  I may now have problems with rst, but at least my markdown labels aren't cut in half.



Discussion:
@esbullington, In addition to cloning the latest development version, would you mind fetching rev #5f2af7c and testing? I recently pushed some changes to the core text provider classes and might have introduced regressions. I'll take a more thorough look tomorrow when I have more time.

Meanwhile, I'll diff the two versions of markup.py to see if I can spot a trivial difference.


Resolving patch:
diff --git a/kivy/core/text/markup.py b/kivy/core/text/markup.py
--- a/kivy/core/text/markup.py
+++ b/kivy/core/text/markup.py
@@ -266,7 +266,7 @@ def _real_render(self):
         y = 0
         w, h = self._size
         refs = self._refs
-        no_of_lines = len(self._lines)-1
+        no_of_lines = len(self._lines)
 
         for line in self._lines:
             lh = line[1]


Test patch:
diff --git a/kivy/tests/test_issue_609.py b/kivy/tests/test_issue_609.py
new file mode 100644
--- /dev/null
+++ b/kivy/tests/test_issue_609.py
@@ -0,0 +1,19 @@
+from common import GraphicUnitTest
+
+
+class Issue609(GraphicUnitTest):
+
+    def test_markup_pos(self):
+        from kivy.uix.label import Label
+        from kivy.uix.gridlayout import GridLayout
+
+        lbl = Label(text="TextToTest")
+        lbl.bind(text_size=lbl.setter('size'))
+        mrkp = Label(text="TextToTest", markup = True)
+        mrkp.bind(text_size=mrkp.setter('size'))
+
+        grid = GridLayout(rows=1, size_hint=(1, 1))
+        grid.add_widget(lbl)
+        grid.add_widget(mrkp)
+
+        self.render(grid, 2)
Repository: kivy/kivy

Issue:
Image don't have attribute keep_data (crash)
```
 Traceback (most recent call last):
   File "testimage.py", line 3, in <module>
     a = Image('atlas://data/images/defaulttheme/button')
   File "/home/tito/code/kivy/kivy/core/image/__init__.py", line 399, in __init__
     self.filename = arg
   File "/home/tito/code/kivy/kivy/core/image/__init__.py", line 565, in _set_filename
     if not image.keep_data and self._keep_data:
 AttributeError: 'Image' object has no attribute 'keep_data'
```

Can be trigger with: 

```
from kivy.core.image import Image
a = Image('atlas://data/images/defaulttheme/button')
a = Image('atlas://data/images/defaulttheme/button')
```

After a bisect, the commit 965abf4b12618e0a689b2f08b3e44da6df0c2c7d is responsible :)



Discussion:

Resolving patch:
diff --git a/kivy/core/image/__init__.py b/kivy/core/image/__init__.py
--- a/kivy/core/image/__init__.py
+++ b/kivy/core/image/__init__.py
@@ -569,7 +569,10 @@ def _set_filename(self, value):
         if image:
             # we found an image, yeah ! but reset the texture now.
             self.image = image
-            if not image.keep_data and self._keep_data:
+            # if image.__class__ is core image then it's a texture
+            # from atlas or other sources and has no data so skip
+            if (image.__class__ != self.__class__ and
+                not image.keep_data and self._keep_data):
                 self.remove_from_cache()
                 self._filename = ''
                 self._set_filename(value)


Test patch:
Repository: kivy/kivy

Issue:
Shortening text on the button problem.
I wrote a simple code which creates the button with the long text. the text is shortened thanks to the shorten=True parameter. The size of the button and length of the text change thanks to a slider. As I understand the shorten=True parameter allows to display the text in one line (not multiline text) by cutting the text. But sometimes there is the second line. If to start the script and play with slider it is possible to see the bug (I think so).

``` python
#!/usr/bin/python
# -*- coding: utf-8 -*-

import kivy

from kivy.uix.button import Button
from kivy.app import App
from kivy.uix.widget import Widget


class MyApp(App):

    def build(self):

        # button_size and text_size refreshing
        def pr(instance, value):            
            bt.size=(s.value, 20)
            bt.text_size=(s.value, 20)

        # root wiget                    
        parent = Widget()
        from kivy.uix.slider import Slider


        # slider widget
        s = Slider(min=100, max=1000, value=100, width=600, x=10)
        parent.add_widget(s)
        s.bind(value_pos=pr)

        # text for button
        my_text=u"Here very long text which has to be displayed in one line thanks to the parameter <shorten=True> . But sometimes the last word appears to the second line. Why it occurs I don't know. Help please! "

        # button wiget  
        bt = Button(text=my_text, font_size=14, size_hint=(None, None), size=(s.value, 20), height=20,  halign='left', valign="middle", text_size=(s.value, None), shorten=True, pos=(10,200), background_color=(1, 0, 0, 1))       
        parent.add_widget(bt)       


        return parent


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

```



Discussion:
It is somehow connected with spaces (spacebar of the keyboard). As the continuous text (without spaces) is displayed correctly.


Resolving patch:
diff --git a/kivy/core/text/__init__.py b/kivy/core/text/__init__.py
--- a/kivy/core/text/__init__.py
+++ b/kivy/core/text/__init__.py
@@ -204,9 +204,11 @@ def shorten(self, text, margin=2):
         else:
             width = int(self.text_size[0])
 
-        letters = text + '...'
-        letter_width = textwidth(letters) // len(letters)
-        max_letters = width // letter_width
+        letters = ' ... ' + text
+        while textwidth(letters) > width:
+            letters = letters[: letters.rfind(' ')]
+
+        max_letters = len(letters) - 2
         segment = (max_letters // 2)
 
         if segment - margin > 5:
@@ -279,7 +281,9 @@ def render(self, real=False):
 
             # Shorten the text that we actually display
             text = self.text
-            if options['shorten'] and get_extents(text)[0] > uw:
+            last_word_width = get_extents(text[text.rstrip().rfind(' '):])[0]
+            if (options['shorten'] and get_extents(text)[0] >
+                uw - last_word_width):
                 text = self.shorten(text)
 
             # first, split lines


Test patch:
Repository: kivy/kivy

Issue:
No console warning when setting Image.source = "some/file/that/does/not/exist"
When you load a file into an Image widget by setting .source = "some/file/name.png" there is a message printed on the console:

[DEBUG  ] [ImagePygame ] Load <data/tiles/dirt.png>

If you set .source = to a filename that does not exist, there is no feedback. No debug message is printed, and the Image widget remains blank.



Discussion:
Oh, sorry, forgot to mention I was testing with Kivy 1.5.1 on Ubuntu Linux


Resolving patch:
diff --git a/kivy/uix/image.py b/kivy/uix/image.py
--- a/kivy/uix/image.py
+++ b/kivy/uix/image.py
@@ -47,6 +47,7 @@ class FullImage(Image):
 from kivy.properties import StringProperty, ObjectProperty, ListProperty, \
         AliasProperty, BooleanProperty, NumericProperty
 from kivy.loader import Loader
+from kivy.logger import Logger
 
 
 class Image(Widget):
@@ -210,7 +211,8 @@ def texture_update(self, *largs):
         else:
             filename = resource_find(self.source)
             if filename is None:
-                return
+                return Logger.error('Image: Error reading file {filename}'.
+                                    format(filename=self.source))
             mipmap = self.mipmap
             if self._coreimage is not None:
                 self._coreimage.unbind(on_texture=self._on_tex_change)


Test patch:
Repository: kivy/kivy

Issue:
GridLayout doesn't honour size_hint
To reproduce the issue::

1)  Run Kivy catalog, Choose the Button labeled 'GridLayout' from the left.

Notice that GridLayout takes up less area than is available to it if all the widget's in a row/column don't have size_hint_x/y set either None or between 0/1. 

I feel the expected behaviour should be to honour width/height for the col/row only if all the widgets are setting size_hint_x/y to None and to ignore the width/height otherwise. 



Discussion:

Resolving patch:
diff --git a/kivy/uix/gridlayout.py b/kivy/uix/gridlayout.py
--- a/kivy/uix/gridlayout.py
+++ b/kivy/uix/gridlayout.py
@@ -320,13 +320,17 @@ def update_minimum_size(self, *largs):
 
                 # compute minimum size / maximum stretch needed
                 if shw is None:
-                    cols[col] = max(cols[col], w)
+                    if not cols_sh[col]:
+                        cols[col] = max(cols[col], w)
                 else:
                     cols_sh[col] = max(cols_sh[col], shw)
+                    cols[col] = 0
                 if shh is None:
-                    rows[row] = max(rows[row], h)
+                    if not rows_sh[row]:
+                        rows[row] = max(rows[row], h)
                 else:
                     rows_sh[row] = max(rows_sh[row], shh)
+                    rows[row] = 0
 
                 # next child
                 i = i - 1


Test patch:
Repository: kivy/kivy

Issue:
Updating ScrollView from outside and scrolling with mouse after.
When I set ScrollView's scroll_y(x) property from outside (by some button), position of content is updated as supposed. But then when you try to scroll (with mouse wheel) after increasing scroll_y value (still in range 0-1), content and its move animation starts from place before 'outside' updating. When decreasing scroll_y and then scrolls with mouse, it works nicely though.

Test code in gist: https://gist.github.com/Goffrey/5299929
Steps to see problem:
1. Scrolls completely down with wheel.
2. Scroll UP to middle with Up button.
3. Now scroll with mouse wheel:
    \* when scrolling up - it jumps down to little scrolled height from bottom
    \* when scrolling down - it jump completely to the bottom
## <bountysource-plugin>

Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/295785-updating-scrollview-from-outside-and-scrolling-with-mouse-after?utm_campaign=plugin&utm_content=tracker%2F42681&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F42681&utm_medium=issues&utm_source=github).
</bountysource-plugin>



Discussion:

Resolving patch:
diff --git a/kivy/uix/scrollview.py b/kivy/uix/scrollview.py
--- a/kivy/uix/scrollview.py
+++ b/kivy/uix/scrollview.py
@@ -176,8 +176,10 @@ def update_from_scroll(self, *largs):
 
         if self.do_scroll_x:
             self.scroll_x = min(1, max(0, self.scroll_x))
+            self._scroll_x_mouse = self.scroll_x
         if self.do_scroll_y:
             self.scroll_y = min(1, max(0, self.scroll_y))
+            self._scroll_y_mouse = self.scroll_y
 
         # update from size_hint
         if vp.size_hint_x is not None:


Test patch:
Repository: kivy/kivy

Issue:
StackLayout spacing added to top padding
When using a StackLayout, the spacing is added to the top padding.

To see the problem, run kivycatalog and change the spacing property for the StackLayout example to 20.

Tested on 1.6.0 and master.



Discussion:
This happens whenever the orientation starts with 'tb' or 'rl'.


Resolving patch:
diff --git a/kivy/uix/stacklayout.py b/kivy/uix/stacklayout.py
--- a/kivy/uix/stacklayout.py
+++ b/kivy/uix/stacklayout.py
@@ -216,7 +216,7 @@ def do_layout(self, *largs):
             sv += lv + spacing_v
             for c2 in lc:
                 if urev:
-                    u -= c2.size[innerattr] + spacing_u
+                    u -= c2.size[innerattr]
                 p = [0, 0]  # issue #823
                 p[innerattr] = u
                 p[outerattr] = v
@@ -226,7 +226,9 @@ def do_layout(self, *largs):
                     # we need to subtract the height/width from the position.
                     p[outerattr] -= c2.size[outerattr]
                 c2.pos = tuple(p)  # issue #823
-                if not urev:
+                if urev:
+                    u -= spacing_u
+                else:
                     u += c2.size[innerattr] + spacing_u
 
             v += deltav * lv
@@ -241,14 +243,16 @@ def do_layout(self, *largs):
             sv += lv + spacing_v
             for c2 in lc:
                 if urev:
-                    u -= c2.size[innerattr] + spacing_u
+                    u -= c2.size[innerattr]
                 p = [0, 0]  # issue #823
                 p[innerattr] = u
                 p[outerattr] = v
                 if vrev:
                     p[outerattr] -= c2.size[outerattr]
                 c2.pos = tuple(p)  # issue #823
-                if not urev:
+                if urev:
+                    u -= spacing_u
+                else:
                     u += c2.size[innerattr] + spacing_u
 
         minsize = self.minimum_size[:]  # issue #823


Test patch:
diff --git a/kivy/tests/test_issue_1091.py b/kivy/tests/test_issue_1091.py
new file mode 100644
--- /dev/null
+++ b/kivy/tests/test_issue_1091.py
@@ -0,0 +1,18 @@
+import unittest
+from kivy.uix.stacklayout import StackLayout
+from kivy.uix.widget import Widget
+
+class PaddingSpacingTestCase(unittest.TestCase):
+    def test_tb_lr_stacklayout(self):
+        stacklayout = StackLayout(
+                orientation='tb-lr',
+                size=(200, 200),
+                padding=20,
+                spacing=10,
+                )
+
+        widget = Widget(width=100, size_hint=(0.2, 0.4))
+        stacklayout.add_widget(widget)
+        stacklayout.do_layout()
+
+        self.assertEqual(stacklayout.top - widget.top, 20)
Repository: kivy/kivy

Issue:
filechooser within a scrollview responds to outside touches.
When running the following code:

```
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
from kivy.lang import Builder

Builder.load_string('''
<X@BoxLayout>:
    orientation: 'vertical'
    ScrollView:
        FileChooserListView
    Button

''')

class X(BoxLayout):
    pass

class TestApp(App):
    def build(self):
        return X()

TestApp().run()
```

make sure that you have _directories_ extending bellow the scrollview's bounding box, i.e. there's some vertical scrolling available. If you then click on the button, it'll open directories in the filechooser.



Discussion:

Resolving patch:
diff --git a/kivy/uix/filechooser.py b/kivy/uix/filechooser.py
--- a/kivy/uix/filechooser.py
+++ b/kivy/uix/filechooser.py
@@ -301,6 +301,12 @@ def __init__(self, **kwargs):
                   rootpath=self._trigger_update)
         self._trigger_update()
 
+    def on_touch_up(self, touch):
+        # don't respond to touchs outside self
+        if not self.collide_point(*touch.pos):
+            return True
+        return super(FileChooserController, self).on_touch_up(touch)
+
     def _update_item_selection(self, *args):
         for item in self._items:
             item.selected = item.path in self.selection


Test patch:
Repository: kivy/kivy

Issue:
Feature request in Carousel
Changing index you can decide to the slide with or without animation



Discussion:
Currently, when the index is changed programmatically, the displayed slide is changed without an animation.
An animation should occur in the same direction as the equivalent swipe or swipes.


Resolving patch:
diff --git a/examples/widgets/carousel_buttons.py b/examples/widgets/carousel_buttons.py
--- a/examples/widgets/carousel_buttons.py
+++ b/examples/widgets/carousel_buttons.py
@@ -19,8 +19,14 @@
     Button
     Button
     Button
+        text: 'prev'
+        on_release:
+            root.parent.parent.load_previous()
     Button
     Button
+        text: 'next'
+        on_release:
+            root.parent.parent.load_next()
 ''')
 
 class Page(GridLayout):
diff --git a/kivy/uix/carousel.py b/kivy/uix/carousel.py
--- a/kivy/uix/carousel.py
+++ b/kivy/uix/carousel.py
@@ -235,6 +235,30 @@ def __init__(self, **kwargs):
                 self._position_visible_slides, -1)
         super(Carousel, self).__init__(**kwargs)
 
+    def load_previous(self):
+        '''Animate previous slide in.
+
+        .. versionadded:: 1.7.0
+        '''
+        self.load_next(mode='prev')
+
+    def load_next(self, mode='next'):
+        '''Animate next slide in.
+
+        .. versionadded:: 1.7.0
+        '''
+        h, w = self.size
+        _direction = {
+                    'top': -h / 2,
+                    'bottom': h / 2,
+                    'left': w / 2,
+                    'right': -w / 2}
+        _offset = _direction[self.direction]
+        if mode == 'prev':
+            _offset = -_offset
+        self._offset = _offset
+        self._start_animation()
+
     def get_slide_container(self, slide):
         return slide.parent
 


Test patch:
Repository: kivy/kivy

Issue:
ListItemButton ignores deselected_color passed by args_converter.
Passing a deselected_colour to a ListItemButton using args_converter has no effect. The ListItemButton retains the default Button's background_color. https://gist.github.com/Ian-Foote/5804118



Discussion:

Resolving patch:
diff --git a/kivy/uix/listview.py b/kivy/uix/listview.py
--- a/kivy/uix/listview.py
+++ b/kivy/uix/listview.py
@@ -283,6 +283,12 @@ def __init__(self, **kwargs):
     ListItemLabel and ListItemButton, or custom classes like them, and not the
     bare Label nor Button classes, are to be used in the listview system.
 
+.. warning::
+
+    ListItemButton inherits the `background_normal` and `background_down`
+    properties from the Button widget, so the `selected_color` and
+    `deselected_color` are not represented faithfully by default.
+
 Here is an args_converter for use with the built-in
 :class:`~kivy.uix.listview.ListItemButton`, specified as a normal Python
 function::
@@ -637,8 +643,8 @@ class ListItemButton(SelectableView, Button):
     def __init__(self, **kwargs):
         super(ListItemButton, self).__init__(**kwargs)
 
-        # Set deselected_color to be default Button bg color.
-        self.deselected_color = self.background_color
+        # Set Button bg color to be deselected_color.
+        self.background_color = self.deselected_color
 
     def select(self, *args):
         self.background_color = self.selected_color


Test patch: