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

Issue:
kivy/examples/android/takepicture/ fails on Android
Example cloned form GIT build with:
buildozer android debug
deployed to Android 4.4.4 crashes, from adb logcat output teh following lines seem to be relevant:

I/python  (25790):  /data/data/org.test.takepicture/files/lib/python2.7/site-packages/kivy/core/image/img_pygame.py:13: RuntimeWarning: import cdrom: No module named cdrom

I/python  (25790):  Traceback (most recent call last):
I/python  (25790):    File "/home/jb/python/mread/.buildozer/android/app/main.py", line 32, in <module>
I/python  (25790):  ImportError: No module named PIL
I/python  (25790): Python for android ended.

Second line indicates problem with image library, unfortunately I have no clue how to fix it.



Discussion:
Show your .spec file, probably you didn't included `pil` into `requirements = kivy` in that file.

File buildozer.spec was (git) cloned yesterday and it had:
requirements = kivy
Following your suggestion I've changed it to
requirements = kivy, pil
Now it works, similar change should be made to the repository file. Thank you for prompt help.

Yes, this needs to be changed in our examples. Reopening.


Resolving patch:
diff --git a/examples/android/takepicture/main.py b/examples/android/takepicture/main.py
--- a/examples/android/takepicture/main.py
+++ b/examples/android/takepicture/main.py
@@ -23,7 +23,7 @@
 from kivy.app import App
 from os.path import exists
 from jnius import autoclass, cast
-from android import activity
+from android import activity, mActivity
 from functools import partial
 from kivy.clock import Clock
 from kivy.uix.scatter import Scatter
@@ -32,7 +32,6 @@
 from PIL import Image
 
 Intent = autoclass('android.content.Intent')
-PythonActivity = autoclass('org.renpy.android.PythonActivity')
 MediaStore = autoclass('android.provider.MediaStore')
 Uri = autoclass('android.net.Uri')
 Environment = autoclass('android.os.Environment')
@@ -61,7 +60,7 @@ def take_picture(self):
         self.uri = Uri.parse('file://' + self.last_fn)
         self.uri = cast('android.os.Parcelable', self.uri)
         intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
-        PythonActivity.mActivity.startActivityForResult(intent, 0x123)
+        mActivity.startActivityForResult(intent, 0x123)
 
     def on_activity_result(self, requestCode, resultCode, intent):
         if requestCode == 0x123:


Test patch:
Repository: kivy/kivy

Issue:
Loader never uses error_image on image loading error
I am using an AsyncImage to load network images, and sometimes the images are not available (404 Error) or cannot be loaded by some other reasons. In those cases, I would expect to get the Loader.error_image, but instead the Loader.loading_image keeps being used, which is pretty annoying.

The debug shows that the exception is catched, but still, the error_image not used:

```
[ERROR  ] [Loader      ] Failed to load image <http://www.laorbitadeendor.com/iTunes/LODE5x29.jpg>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/kivy/loader.py", line 313, in _load_urllib
    fd = urllib_request.urlopen(filename)
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 404: Not Found
an integer is required
```

Surfing into the code, the problem seems to be inside the exception catching code in line 348. It tries to close the temporary file on `out_osfd`,  which is None. I've been able to solve it by checking if `_out_osfd` is initiallized before trying to close it.

```
     except Exception:
            Logger.exception('Loader: Failed to load image <%s>' % filename)
            # close file when remote file not found or download error
            try:
                if _out_osfd:
                    close(_out_osfd)
            except OSError:
                pass
            return self.error_image
```

Additionaly, I'd like to put a +1 on related issue #4062.



Discussion:

Resolving patch:
diff --git a/kivy/loader.py b/kivy/loader.py
--- a/kivy/loader.py
+++ b/kivy/loader.py
@@ -348,7 +348,8 @@ def gettype(info):
             Logger.exception('Loader: Failed to load image <%s>' % filename)
             # close file when remote file not found or download error
             try:
-                close(_out_osfd)
+                if _out_osfd:
+                    close(_out_osfd)
             except OSError:
                 pass
             return self.error_image


Test patch:
Repository: kivy/kivy

Issue:
TextInput.hint_text too long for TextInput.size_hint_x locks the app
If I have a TextInput whose `size_hint_x` makes it too small to hold all its `hint_text`, my app freezes (apparently in an infinite loop) instead of truncating the `hint_text` as I'd expect.

Steps to reproduce:
1. Make a TextInput, give it long hint_text and small size_hint_x (or put it in a BoxLayout so that a "large" size_hint_x still makes it too small)
2. Launch app

Expected behavior: get an app window that I can interact with
Actual behavior: app eats 100% CPU and doesn't display anything

Example code:

```
from kivy.base import runTouchApp
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout


class TestBoxLayout(BoxLayout):
    pass


Builder.load_string("""
<TestBoxLayout>:
    orientation: 'vertical'
    Widget:
        id: foo
    Widget:
        id: bar
    BoxLayout:
        TextInput:
            hint_text: 'Some hint text'
            size_hint_x: 0.5
        Widget:
            id: spam
        Widget:
            id: eggs
""")


if __name__ == '__main__':
    runTouchApp(TestBoxLayout())
```



Discussion:
It works as expected with 1.9.1.

@kived has found the buggy commit: 29e7f851a8ae58ba018c9a0a3d639b8a20c0b69e.


Resolving patch:
diff --git a/kivy/uix/textinput.py b/kivy/uix/textinput.py
--- a/kivy/uix/textinput.py
+++ b/kivy/uix/textinput.py
@@ -2200,7 +2200,7 @@ def _split_smart(self, text):
                 x = 0
             if is_newline:
                 flags |= FL_IS_LINEBREAK
-            elif width > 0 and w > width:
+            elif width >= 1 and w > width:
                 while w > width:
                     split_pos, split_width = self._split_word(word, width)
                     lines_append(word[:split_pos])


Test patch:
Repository: kivy/kivy

Issue:
TextInput.hint_text too long for TextInput.size_hint_x locks the app
If I have a TextInput whose `size_hint_x` makes it too small to hold all its `hint_text`, my app freezes (apparently in an infinite loop) instead of truncating the `hint_text` as I'd expect.

Steps to reproduce:
1. Make a TextInput, give it long hint_text and small size_hint_x (or put it in a BoxLayout so that a "large" size_hint_x still makes it too small)
2. Launch app

Expected behavior: get an app window that I can interact with
Actual behavior: app eats 100% CPU and doesn't display anything

Example code:

```
from kivy.base import runTouchApp
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout


class TestBoxLayout(BoxLayout):
    pass


Builder.load_string("""
<TestBoxLayout>:
    orientation: 'vertical'
    Widget:
        id: foo
    Widget:
        id: bar
    BoxLayout:
        TextInput:
            hint_text: 'Some hint text'
            size_hint_x: 0.5
        Widget:
            id: spam
        Widget:
            id: eggs
""")


if __name__ == '__main__':
    runTouchApp(TestBoxLayout())
```



Discussion:
It works as expected with 1.9.1.

@kived has found the buggy commit: 29e7f851a8ae58ba018c9a0a3d639b8a20c0b69e.


Resolving patch:
diff --git a/kivy/uix/textinput.py b/kivy/uix/textinput.py
--- a/kivy/uix/textinput.py
+++ b/kivy/uix/textinput.py
@@ -2167,17 +2167,6 @@ def _tokenize(self, text):
             oldindex = index + 1
         yield text[oldindex:]
 
-    def _split_word(self, text, width):
-        x = 0
-        split_pos = 0
-        for c in text:
-            cw = self._get_text_width(c, self.tab_width, self._label_cached)
-            if x + cw > width:
-                break
-            x += cw
-            split_pos += 1
-        return split_pos, x
-
     def _split_smart(self, text):
         # Do a "smart" split. If autowidth or autosize is set,
         # we are not doing smart split, just a split on line break.
@@ -2219,7 +2208,19 @@ def _split_smart(self, text):
                 flags |= FL_IS_LINEBREAK
             elif width >= 1 and w > width:
                 while w > width:
-                    split_pos, split_width = self._split_word(word, width)
+                    split_width = split_pos = 0
+                    # split the word
+                    for c in word:
+                        cw = self._get_text_width(
+                            c, self.tab_width, self._label_cached
+                        )
+                        if split_width + cw > width:
+                            break
+                        split_width += cw
+                        split_pos += 1
+                    if split_width == split_pos == 0:
+                        # can't fit the word in, give up
+                        break
                     lines_append(word[:split_pos])
                     lines_flags_append(flags)
                     flags = FL_IS_WORDBREAK


Test patch:
Repository: kivy/kivy

Issue:
Remove and Re-add of Highest Widget in a Layout leaves the Widget Invisible
I have noticed that adding widgets to a Layout Manager does not seem to work correctly. I have tested with BoxLayout, GridLayout, and FloatLayout. I have tested with 3 widgets, and with 4 widgets. I am using Kivy 1.9.0 with Python 2.7 on Fedora 22.

I start by adding widgets to a Layout- it looks fine. Then I remove a widget- the "first" one, which is list index 3 in the list of children in my FloatLayout example (index 2 with the Grid example). See the attachments.
[app2-float.txt](https://github.com/kivy/kivy/files/388380/app2-float.txt)
[app2-grid.txt](https://github.com/kivy/kivy/files/388383/app2-grid.txt)

When I re-add the widget in a BoxLayout or GridLayout, space is used in but the widget is not displayed. Testing in my "real" app (code not given here) shows that the widget is indeed in place (I can perform actions on it) but it's just not displayed. This problem only seems to happen with the leftmost position.



Discussion:
Ok, this is not specific to Layouts actually, you can replace FloatLayout with Widget in your first example, and still get the issue, it also has to do with the canvas instruction order, if you change `canvas` to `canvas.before` in either example, then your examples work as intended. So your Button is actually displayed, it's just that your canvas blocks overdraw it. This only happens if you try to use the last possible index position, i.e, there are no other sibling widget drawn before it.

Incidentally, it seem we had a similar issue with canvas.before in the past (#1021).

The issue seems to be in `Widget.add_widget` when widget is insered last, using 0 as index is wrong in this case, trying to come up with a better one.


Resolving patch:
diff --git a/kivy/uix/widget.py b/kivy/uix/widget.py
--- a/kivy/uix/widget.py
+++ b/kivy/uix/widget.py
@@ -546,7 +546,7 @@ def add_widget(self, widget, index=0, canvas=None):
             children = self.children
             if index >= len(children):
                 index = len(children)
-                next_index = 0
+                next_index = canvas.indexof(children[-1].canvas)
             else:
                 next_child = children[index]
                 next_index = canvas.indexof(next_child.canvas)


Test patch:
Repository: kivy/kivy

Issue:
ToggleButton can get released with allow_no_selection=False
Ohai buddiez, I hope you're all doing goodie ^__^

I found a new bug probably due to "always_release" on ButtonBehavior having been changed recently:
`Changed in version 1.9.2: The default value is now False.`

Take the following example:
https://gist.github.com/42e02d13c31a6504b57d5cd3ac23a460

If you try to press a button, then release outside of it, its state will be "normal", even though it should remain "down".

I have made a small change to ButtonBehavior which adds an event "on_release_outside" and makes it set the state to normal by default, and overrode it in ToggleButtonBehavior to do nothing instead.

Incoming PR, so please give feedback! (EDIT: See #4594 )

Thanks for reading, see you around buddiez bliblibli ^__^



Discussion:

Resolving patch:
diff --git a/kivy/uix/behaviors/button.py b/kivy/uix/behaviors/button.py
--- a/kivy/uix/behaviors/button.py
+++ b/kivy/uix/behaviors/button.py
@@ -167,7 +167,7 @@ def on_touch_up(self, touch):
 
         if (not self.always_release
                 and not self.collide_point(*touch.pos)):
-            self.state = 'normal'
+            self._do_release()
             return
 
         touchtime = time() - self.__touch_time


Test patch:
Repository: kivy/kivy

Issue:
keycode typo in core/window/__init__.py
Line 96 of core/window/**init**.py appears to give the same code for ";" and ":"

```
--- core/window/__init__.py.bak 2016-06-22 14:45:15.678376652 +0100
+++ core/window/__init__.py     2016-06-22 14:45:24.466500576 +0100
@@ -93,7 +93,7 @@
         '(': 40, ')': 41,
         '[': 91, ']': 93,
         '{': 123, '}': 125,
-        ':': 59, ';': 59,
+        ':': 58, ';': 59,
         '=': 61, '+': 43,
         '-': 45, '_': 95,
         '/': 47, '*': 42,
```



Discussion:

Resolving patch:
diff --git a/kivy/core/window/__init__.py b/kivy/core/window/__init__.py
--- a/kivy/core/window/__init__.py
+++ b/kivy/core/window/__init__.py
@@ -93,7 +93,7 @@ class Keyboard(EventDispatcher):
         '(': 40, ')': 41,
         '[': 91, ']': 93,
         '{': 123, '}': 125,
-        ':': 59, ';': 59,
+        ':': 58, ';': 59,
         '=': 61, '+': 43,
         '-': 45, '_': 95,
         '/': 47, '*': 42,


Test patch:
Repository: kivy/kivy

Issue:
TextInput selection_text not cleared on backspace/delete or widget defocus
Select part of the text and press backspace or delete, then press the print button, the previously selected text will still be there. The same is the case when the widget is defocused after selection.

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

kv = """
BoxLayout:
    orientation: 'vertical'
    TextInput:
        id: input
        text: 'select me'
    Button:
        text: 'Print selected text'
        on_press: print(input.selection_text)
"""


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

if __name__ == '__main__':
    TestApp().run()
```



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
@@ -1187,6 +1187,7 @@ def cancel_selection(self):
         self._selection = False
         self._selection_finished = True
         self._selection_touch = None
+        self.selection_text = u''
         self._trigger_update_graphics()
 
     def delete_selection(self, from_undo=False):


Test patch:
Repository: kivy/kivy

Issue:
Touchtracer - delay when trying to draw
I don't even see it if I don't look close, but if I'm right, the thing that's mentioned in [this question](http://stackoverflow.com/q/37933920/5994041) is in fact a delay I see here. If not, there's a delay anyway. It's like there is an invisible(because bg isn't only single color) brush covering the touch - such thing you can see even in Paint as it shows you where the brush actually is.

Touchtracer seems to catch every touch, yet something slips and is displayed hm... after there's enough items in a list or something? E.g. it won't draw until there's at least 3-4+ touches in let's say `touches = []` so that a line could be drawn? Even if, you can construct a line with two points, but I see that more than two touches are not present when I drag the mouse until another part is drawn(see the red circle). This thing is present even with master and from each side(it's not an issue with misplaced touch coords).

![image](https://cloud.githubusercontent.com/assets/8825439/16315583/233d8a16-3983-11e6-9564-79acdd90d607.png)



Discussion:

Resolving patch:
diff --git a/examples/demo/touchtracer/main.py b/examples/demo/touchtracer/main.py
--- a/examples/demo/touchtracer/main.py
+++ b/examples/demo/touchtracer/main.py
@@ -8,6 +8,12 @@
 you drag, it leaves a trail. Additional information, like pressure,
 will be shown if they are in your device's touch.profile.
 
+.. note::
+
+   A function `calculate_points` handling the points which will be drawn
+   has by default implemented a delay of 5 steps. To get more precise visual
+   results lower the value of the optional keyword argument `steps`.
+
 This program specifies an icon, the file icon.png, in its App subclass.
 It also uses the particle.png file as the source for drawing the trails which
 are white on transparent. The file touchtracer.kv describes the application.


Test patch:
Repository: kivy/kivy

Issue:
RecycleBoxLayout NameError
``` python
from random import sample
from string import ascii_lowercase

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


kv = """
<Row@BoxLayout>:
    value: ''
    size_hint: None, None
    size: self.minimum_size
    Label:
        text: root.value
        size_hint: None, None
        size: self.texture_size

<Test>:
    rv: rv
    orientation: 'vertical'
    Button:
        text: 'Populate list'
        on_press: root.populate()
    RecycleView:
        id: rv
        viewclass: 'Row'
        RecycleBoxLayout:
            default_size: None, None
            size_hint_y: None
            height: self.minimum_height
            orientation: 'vertical'
"""

Builder.load_string(kv)


class Test(BoxLayout):

    def populate(self):
        self.rv.data = [{'value': ''.join(sample(ascii_lowercase, 6))}
                        for x in range(50)]


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

if __name__ == '__main__':
    TestApp().run()
```

``` python
 Traceback (most recent call last):
   File "E:\dev\prs\kivy\examples\widgets\recycleview\basic_data.py", line 49, in <module>
     TestApp().run()
   File "E:\dev\prs\kivy\kivy\app.py", line 828, in run
     runTouchApp()
   File "E:\dev\prs\kivy\kivy\base.py", line 487, in runTouchApp
     EventLoop.window.mainloop()
   File "E:\dev\prs\kivy\kivy\core\window\window_sdl2.py", line 633, in mainloop
     self._mainloop()
   File "E:\dev\prs\kivy\kivy\core\window\window_sdl2.py", line 388, in _mainloop
     EventLoop.idle()
   File "E:\dev\prs\kivy\kivy\base.py", line 336, in idle
     Clock.tick_draw()
   File "E:\dev\prs\kivy\kivy\clock.py", line 528, in tick_draw
     self._process_events_before_frame()
   File "E:\dev\prs\kivy\kivy\clock.py", line 678, in _process_events_before_frame
     event.tick(self._last_tick, remove)
   File "E:\dev\prs\kivy\kivy\clock.py", line 412, in tick
     ret = callback(self._dt)
   File "E:\dev\prs\kivy\kivy\uix\recycleview\__init__.py", line 109, in refresh_views
     lm.compute_layout(data, f)
   File "E:\dev\prs\kivy\kivy\uix\recycleboxlayout.py", line 88, in compute_layout
     changed and not self._update_sizes(changed)):
   File "E:\dev\prs\kivy\kivy\uix\recycleboxlayout.py", line 81, in _update_sizes
     return relayout
 NameError: name 'relayout' is not defined
```



Discussion:

Resolving patch:
diff --git a/kivy/uix/recycleboxlayout.py b/kivy/uix/recycleboxlayout.py
--- a/kivy/uix/recycleboxlayout.py
+++ b/kivy/uix/recycleboxlayout.py
@@ -91,7 +91,7 @@ def _update_sizes(self, changed):
                         xo = posx - (w / 2.)
                 opt['pos'] = [xo, yo]
 
-        return relayout
+        return False
 
     def compute_layout(self, data, flags):
         super(RecycleBoxLayout, self).compute_layout(data, flags)


Test patch:
Repository: kivy/kivy

Issue:
ActionGroup needs clicking twice
Is it only me, or does the `ActionGroup` requires clicking twice? It worked normally before, at least in the beginning of 2016, but recently when I worked with it for a while I noticed this thing. The first touch seems to be ignored, but _isn't_ (try `on_release`), yet the `DropDown` won't show. When clicked the second time, it works normally. Seems like there's some issue with initialising the widget or something.

Run just the basic example in `actionbar.py` and try to click on either "Group 1" or "Group 2". I ran the  `showcase` demo too, but there the `Spinner` that looks like `ActionGroup` behaves normally because it inherits directly from `Spinner` and `ActionItem` in kv file and isn't built as a casual `ActionGroup`. Any ideas what's going on?


Discussion:
I am getting the same result. First click results in a blink of the background. Second click is ignored entirely. Then everything works normally.

Found it! @tshirtman 's commit broke the clicking somehow 🌵 https://github.com/kivy/kivy/commit/7925e9db1e52a731333e1d1a435d9a9c3a59d91f

Resolving patch:
diff --git a/kivy/uix/dropdown.py b/kivy/uix/dropdown.py
--- a/kivy/uix/dropdown.py
+++ b/kivy/uix/dropdown.py
@@ -33,6 +33,7 @@
         # When adding widgets, we need to specify the height manually
         # (disabling the size_hint_y) so the dropdown can calculate
         # the area it needs.
+
         btn = Button(text='Value %d' % index, size_hint_y=None, height=44)
 
         # for each button, attach a callback that will call the select() method
@@ -223,7 +224,8 @@ def on_key_down(self, instance, key, scancode, codepoint, modifiers):
             return True
 
     def on_container(self, instance, value):
-        pass
+        if value is not None:
+            self.container.bind(minimum_size=self._reposition)
 
     def open(self, widget):
         '''Open the dropdown list and attach it to a specific widget.


Test patch: