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

Issue:
ScrollView mousewheel inconsistent behavior
Mousewheeling over a scrollview behaves inconsistently. When it's possible to scroll, it scrolls as expected, but when all the content fits inside it acts like a tap.

To reproduce, 
1. Size window so that scrolling is possible. Scroll to top/bottom (this is expected)
2. Resize window so all content fits inside the ScrollView, and mousewheel over some option

Expected outcome would be that it is either ignored, or show a bounce effect as if it was drag-scrolled.

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

Builder.load_string('''
<Interface>:
    orientation: 'vertical'
    Button:
        text: 'open the settings!'
        font_size: 150
        on_release: app.open_settings()
''')

class Interface(BoxLayout):
    pass

class SettingsApp(App):
    def build(self):   
        return Interface()

SettingsApp().run()
```



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
@@ -598,7 +598,7 @@ def on_touch_down(self, touch):
                     e.velocity = 0
                 touch.ud[self._get_uid('svavoid')] = True
                 e.trigger_velocity_update()
-                return True
+            return True
 
         # no mouse scrolling, so the user is going to drag the scrollview with
         # this touch.
@@ -767,7 +767,6 @@ def convert_distance_to_scroll(self, dx, dy):
             sy = 1
         return sx, sy
 
-
     def update_from_scroll(self, *largs):
         '''Force the reposition of the content, according to current value of
         :attr:`scroll_x` and :attr:`scroll_y`.


Test patch:
Repository: kivy/kivy

Issue:
Screenshot doesn't work, glReadPixels can't be imported
As noted on [stackoverflow](https://stackoverflow.com/questions/22755619/screenshot-gives-importerror-cannot-import-name-glreadpixels-error-in-kivy/22772125#22772125), the Window.screenshot function is currently broken (at least, with the pygame provider), as it fails to import glReadPixels.



Discussion:
Still broken with last update (1.8.1)


Resolving patch:
diff --git a/kivy/core/window/window_pygame.py b/kivy/core/window/window_pygame.py
--- a/kivy/core/window/window_pygame.py
+++ b/kivy/core/window/window_pygame.py
@@ -243,7 +243,8 @@ def screenshot(self, *largs, **kwargs):
         if filename is None:
             return None
         if glReadPixels is None:
-            from kivy.core.gl import glReadPixels, GL_RGBA, GL_UNSIGNED_BYTE
+            from kivy.graphics.opengl import (glReadPixels, GL_RGBA,
+                                              GL_UNSIGNED_BYTE)
         width, height = self.system_size
         data = glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE)
         data = str(buffer(data))
diff --git a/kivy/core/window/window_sdl.py b/kivy/core/window/window_sdl.py
--- a/kivy/core/window/window_sdl.py
+++ b/kivy/core/window/window_sdl.py
@@ -99,7 +99,7 @@ def screenshot(self, *largs, **kwargs):
         filename = super(WindowPygame, self).screenshot(*largs, **kwargs)
         if filename is None:
             return None
-        from kivy.core.gl import glReadPixels, GL_RGB, GL_UNSIGNED_BYTE
+        from kivy.graphics.opengl import glReadPixels, GL_RGB, GL_UNSIGNED_BYTE
         width, height = self.size
         data = glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE)
         data = str(buffer(data))


Test patch:
Repository: kivy/kivy

Issue:
Scheduling a function that has a @mainthread decorator fails with Python 3.3
Normally `callback` is called directly from other threads too, but i left that out, this code fails for me:

``` python
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock, mainthread


class Test(BoxLayout):

    @mainthread
    def callback(self, *args):
        print(1)


class TestApp(App):
    def build(self):
        root = Test()
        Clock.schedule_interval(root.callback, 1)
        return root

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

Error:

```
Traceback (most recent call last):
  File "C:\Project\text.py", line 20, in <module>
    TestApp().run()
  File "C:\dev\python\lib\site-packages\kivy\app.py", line 800, in run
    runTouchApp()
  File "C:\dev\python\lib\site-packages\kivy\base.py", line 481, in runTouchApp
    EventLoop.window.mainloop()
  File "C:\dev\python\lib\site-packages\kivy\core\window\window_pygame.py", line 360, in mainloop
    self._mainloop()
  File "C:\dev\python\lib\site-packages\kivy\core\window\window_pygame.py", line 266, in _mainloop
    EventLoop.idle()
  File "C:\dev\python\lib\site-packages\kivy\base.py", line 321, in idle
    Clock.tick()
  File "C:\dev\python\lib\site-packages\kivy\clock.py", line 422, in tick
    self._process_events()
  File "C:\dev\python\lib\site-packages\kivy\clock.py", line 537, in _process_events
    if event.tick(self._last_tick) is False:
  File "C:\dev\python\lib\site-packages\kivy\clock.py", line 299, in tick
    callback = self.get_callback()
  File "C:\dev\python\lib\site-packages\kivy\clock.py", line 263, in get_callback
    return callback()
  File "C:\dev\python\lib\site-packages\kivy\weakmethod.py", line 46, in __call__
    return getattr(self.proxy, self.method_name)
AttributeError: 'Test' object has no attribute 'delayed_func'
```



Discussion:

Resolving patch:
diff --git a/kivy/clock.py b/kivy/clock.py
--- a/kivy/clock.py
+++ b/kivy/clock.py
@@ -208,6 +208,7 @@ def cb(self, *largs):
 
 from sys import platform
 from os import environ
+from functools import wraps
 from kivy.context import register_context
 from kivy.weakmethod import WeakMethod
 from kivy.config import Config
@@ -654,6 +655,7 @@ def callback(self, *args):
 
     .. versionadded:: 1.8.0
     '''
+    @wraps(func)
     def delayed_func(*args, **kwargs):
         def callback_func(dt):
             func(*args, **kwargs)


Test patch:
Repository: kivy/kivy

Issue:
TextInput middle handle does not follow the cursor position after window resize
Runt textinput.py to reproduce: click on the text at the position illustrated on the left image, grab the lower right corner and resize the window until it's similar to the left image, and release it. The left image shows the window right before the mouse is released and the window is redrawn.

![untitled-1](https://f.cloud.github.com/assets/5255957/2524476/c051637c-b4e2-11e3-80b6-3e2c4742f211.jpg)

TextInput cursor changes position on window resize
Runt textinput.py to reproduce: click on the text at the position illustrated on the left image, grab the lower right corner and resize the window until it's similar to the left image, and release it. The left image shows the window right before the mouse is released and the window is redrawn.

![untitled-1](https://f.cloud.github.com/assets/5255957/2524476/c051637c-b4e2-11e3-80b6-3e2c4742f211.jpg)



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
@@ -1499,7 +1499,9 @@ def _refresh_text(self, text, *largs):
         if len(largs) > 1:
             mode, start, finish, _lines, _lines_flags, len_lines = largs
             #start = max(0, start)
+            cursor = None
         else:
+            cursor = self.cursor_index()
             _lines, self._lines_flags = self._split_smart(text)
         _lines_labels = []
         _line_rects = []
@@ -1535,7 +1537,8 @@ def _refresh_text(self, text, *largs):
         # now, if the text change, maybe the cursor is not at the same place as
         # before. so, try to set the cursor on the good place
         row = self.cursor_row
-        self.cursor = self.get_cursor_from_index(self.cursor_index())
+        self.cursor = self.get_cursor_from_index(self.cursor_index()
+                                                 if cursor is None else cursor)
         # if we back to a new line, reset the scroll, otherwise, the effect is
         # ugly
         if self.cursor_row != row:


Test patch:
Repository: kivy/kivy

Issue:
Crash on `TextInput.select_text` if never focused
Calling `select_text` on a `TextInput` causes Kivy to crash if the `TextInput` has not previously been focused.



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
@@ -1121,6 +1121,9 @@ def _position_handles(self, *args, **kwargs):
         group = self.canvas.get_group('selection')
         if not group:
             return
+
+        if not self._win:
+            self._set_window()
         self._win.remove_widget(self._handle_middle)
 
         handle_left = self._handle_left


Test patch:
Repository: kivy/kivy

Issue:
TextInput _get_min_height() bug with padding indices
Source code of the _get_min_height() method:
def _get_min_height(self):
    return (len(self._lines) \* (self.line_height + self.line_spacing) + self.padding[0] + self.padding[2])

Corrected source code of the _get_min_height() method:
def _get_min_height(self):
    return (len(self._lines) \* (self.line_height + self.line_spacing) + self.padding[1] + self.padding[3])

Further Explanation:
https://groups.google.com/forum/#!topic/kivy-dev/2p2IpRHirMQ



Discussion:
Thanks for this, it seems like a good change. Are you interested in doing a pull request for the actual change, which we could merge straight into kivy? If not, someone else will do it soonish!


Resolving patch:
diff --git a/kivy/uix/textinput.py b/kivy/uix/textinput.py
--- a/kivy/uix/textinput.py
+++ b/kivy/uix/textinput.py
@@ -1,4 +1,4 @@
-# -*- encoding: utf8 -*-
+# -*- encoding: utf-8 -*-
 '''
 Text Input
 ==========
@@ -2561,7 +2561,7 @@ def _set_text(self, text):
 
     def _get_min_height(self):
         return (len(self._lines) * (self.line_height + self.line_spacing)
-                + self.padding[0] + self.padding[2])
+                + self.padding[1] + self.padding[3])
 
     minimum_height = AliasProperty(_get_min_height, None,
                                    bind=('_lines', 'line_spacing', 'padding',


Test patch:
Repository: kivy/kivy

Issue:
Popups not centered with softinput_mode 'resize'
While using softinput_mode 'resize', when the keyboard is opened popups are pushed off the top of the screen:

![screenshot_2014-08-05-11-45-01](https://cloud.githubusercontent.com/assets/1126441/3814963/04acae7e-1cc0-11e4-828c-ea56a913b504.png)

![screenshot_2014-08-05-11-45-08](https://cloud.githubusercontent.com/assets/1126441/3814964/0950412a-1cc0-11e4-8c4f-c2a78882a716.png)



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
@@ -345,9 +345,10 @@ def _get_width(self):
     def _get_height(self):
         '''Rotated window height'''
         r = self._rotation
+        kb = self.keyboard_height if self.softinput_mode == 'resize' else 0
         if r == 0 or r == 180:
-            return self._size[1]
-        return self._size[0]
+            return self._size[1] - kb
+        return self._size[0] - kb
 
     height = AliasProperty(_get_height, None, bind=('_rotation', '_size'))
     '''Rotated window height.


Test patch:
Repository: kivy/kivy

Issue:
DropDown defined as dynamic class in kv file does not work
Test file and kivy log are here: https://gist.github.com/PARC6502/7e47667cdea5cbd0e6a4

I'm using this branch of kivy, not sure if that's the issue: https://github.com/matham/kivy/tree/focus-text

If I define a custom DropDown widget in the kv file as a dynamic class, I get an error when I try to open it. If I have the exact same setup but the class is defined in python it works.



Discussion:

Resolving patch:
diff --git a/kivy/uix/dropdown.py b/kivy/uix/dropdown.py
--- a/kivy/uix/dropdown.py
+++ b/kivy/uix/dropdown.py
@@ -94,18 +94,12 @@ class CustomDropDown(DropDown):
 from kivy.core.window import Window
 from kivy.lang import Builder
 
-Builder.load_string('''
-<DropDown>:
-    container: container
-    do_scroll_x: False
-    size_hint: None, None
-
-    GridLayout:
-        id: container
-        size_hint_y: None
-        height: self.minimum_size[1]
-        cols: 1
-''')
+_grid_kv = '''
+GridLayout:
+    size_hint_y: None
+    height: self.minimum_size[1]
+    cols: 1
+'''
 
 
 class DropDownException(Exception):
@@ -179,7 +173,18 @@ class DropDown(ScrollView):
 
     def __init__(self, **kwargs):
         self._win = None
+        if 'container' not in kwargs:
+            c = self.container = Builder.load_string(_grid_kv)
+        else:
+            c = None
+        kwargs.setdefault('do_scroll_x', False)
+        if 'size_hint' not in kwargs:
+            kwargs.setdefault('size_hint_x', None)
+            kwargs.setdefault('size_hint_y', None)
         super(DropDown, self).__init__(**kwargs)
+        if c is not None:
+            super(DropDown, self).add_widget(c)
+            self.on_container(self, c)
         Window.bind(on_key_down=self.on_key_down)
         self.bind(size=self._reposition)
 
@@ -189,7 +194,8 @@ def on_key_down(self, instance, key, scancode, codepoint, modifiers):
             return True
 
     def on_container(self, instance, value):
-        self.container.bind(minimum_size=self._container_minimum_size)
+        if value is not None:
+            self.container.bind(minimum_size=self._container_minimum_size)
 
     def open(self, widget):
         '''Open the dropdown list and attach it to a specific widget.


Test patch:
Repository: kivy/kivy

Issue:
FileChooser Icon view is not scrolled to the top after opening a dir
When FileChooser Icon view is selected and the view is scolled down before opening a directory with many files and folders, ScrollView is not reset and scrolled to the top, as one would expect.



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
@@ -717,6 +717,13 @@ class FileChooserIconView(FileChooserController):
     '''
     _ENTRY_TEMPLATE = 'FileIconEntry'
 
+    def __init__(self, **kwargs):
+        super(FileChooserIconView, self).__init__(**kwargs)
+        self.bind(on_entries_cleared=self.scroll_to_top)
+    
+    def scroll_to_top(self, *args):
+        self.ids.scrollview.scroll_y = 1.0
+
 
 if __name__ == '__main__':
     from kivy.app import App


Test patch:
Repository: kivy/kivy

Issue:
Inspector property list scrolling selects an underlying widget
While scrolling with the mouse wheel through the property list of a selected widget, a different widget (one underneath the property list) is selected, when reaching the top or the bottom of the list.
The same happens while trying to drag the view with the scrollbar.



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
@@ -644,7 +644,7 @@ def on_scroll_start(self, touch, check_children=True):
             self._scroll_y_mouse = self.scroll_y
 
         if (ud.get('in_bar_x', False) or ud.get('in_bar_y', False)):
-            return
+            return True
         if scroll_type == ['bars']:
             # touch is in parent, but _change_touch_mode expects window coords
             touch.push()


Test patch:
Repository: kivy/kivy

Issue:
Allow changing the directory where config files get written.
When running on a read-only filesystem, with a separate partition for read/write access, it's really nice to allow Kivy to read the config file directory from a environment variable.



Discussion:
The location of config.ini is platform-specific, but it is always in the
user's home dir (if such a thing exists on the platform). Most desktop apps
expect the user's home dir to be writable. You might want to think about
moving the home dir to the read/write partition, if possible.
On Sep 25, 2014 1:18 PM, "Derek Willian Stavis" notifications@github.com
wrote:

> When running on a read-only filesystem, with a separate partition for
> read/write access, it's really nice to allow Kivy to read the config file
> directory from a environment variable.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/kivy/kivy/issues/2510.

In my case there's no home directory, as the application is owned by a non-root user, without home directory or even a shell.

@derekstavis as you can set config options in your code, you can choose to not write them to disk at all:
`os.environ['KIVY_NO_CONFIG'] = ''`

Due to a kivy bug, the `.kivy` folder will still be created if you write the logs to a file, even if you choose a different directory for them at runtime (with `Config.set`). For now, you will need to disable logging as well:
`os.environ['KIVY_NO_FILELOG'] = ''`

Details at http://kivy.org/docs/guide/environment.html.

The `.kivy` folder shouldn't be created after using these env vars.

This issue should be left open, the aim would be to let the user choose a custom `.kivy` directory path.


Resolving patch:
diff --git a/kivy/__init__.py b/kivy/__init__.py
--- a/kivy/__init__.py
+++ b/kivy/__init__.py
@@ -243,12 +243,15 @@ def kivy_usage():
 
 if not environ.get('KIVY_DOC_INCLUDE'):
     # Configuration management
-    user_home_dir = expanduser('~')
-    if platform == 'android':
-        user_home_dir = environ['ANDROID_APP_PATH']
-    elif platform == 'ios':
-        user_home_dir = join(expanduser('~'), 'Documents')
-    kivy_home_dir = join(user_home_dir, '.kivy')
+    if 'KIVY_HOME' in environ:
+        kivy_home_dir = expanduser(environ['KIVY_HOME'])
+    else:
+        user_home_dir = expanduser('~')
+        if platform == 'android':
+            user_home_dir = environ['ANDROID_APP_PATH']
+        elif platform == 'ios':
+            user_home_dir = join(expanduser('~'), 'Documents')
+        kivy_home_dir = join(user_home_dir, '.kivy')
     kivy_config_fn = join(kivy_home_dir, 'config.ini')
     kivy_usermodules_dir = join(kivy_home_dir, 'mods')
     kivy_userexts_dir = join(kivy_home_dir, 'extensions')


Test patch:
Repository: kivy/kivy

Issue:
[Documentation] Mainthread decorator
Hey guys,

I noticed that the `@mainthread` decorator always schedules the function call for some time in the future, even when called from another `@mainthread` function. This can lead to some unexpected results. Take the following code:

```
class CoolWidget(Widget):
    def __init__(*args):
        self.is_cool = True

    @mainthread
    def DoFoo():
        self.is_cool = False
        print "Foo 1", self.is_cool
        self.DoBar()
        print "Foo 2", self.is_cool
        self.is_cool = True

    @mainthread
    def DoBar():
        print "Bar 1", self.is_cool

CoolWidget().DoFoo()
```

The expected output in this case would be:
    "Foo 1, False"
    "Bar 1, False"
    "Foo 2, False"

Instead, we get:
    "Foo 1, False"
    "Foo 2, False"
    "Bar 1, True"

[The docs](http://kivy.org/docs/api-kivy.clock.html?highlight=mainthread#kivy.clock.mainthread) do mention scheduling, but imho it's currently not clear that this scheduling happens regardless, and will thus _always_ cause a delay.

I propose to change the first sentence there to something like:
`Decorator that will schedule the call of the function for the next available frame in the mainthread.`

Cheers,
Patrick



Discussion:

Resolving patch:
diff --git a/kivy/clock.py b/kivy/clock.py
--- a/kivy/clock.py
+++ b/kivy/clock.py
@@ -641,8 +641,8 @@ def _process_events_before_frame(self):
 
 
 def mainthread(func):
-    '''Decorator that will schedule the call of the function in the
-    mainthread.  It can be useful when you use
+    '''Decorator that will schedule the call of the function for the next
+    available frame in the mainthread. It can be useful when you use
     :class:`~kivy.network.urlrequest.UrlRequest` or when you do Thread
     programming: you cannot do any OpenGL-related work in a thread.
 
@@ -651,8 +651,8 @@ def mainthread(func):
 
         @mainthread
         def callback(self, *args):
-            print('The request succedded!'
-                  'This callback is call in the main thread')
+            print('The request succedded!',
+                  'This callback is called in the main thread.')
 
         self.req = UrlRequest(url='http://...', on_success=callback)
 


Test patch:
Repository: kivy/kivy

Issue:
Widget.export_to_png broken
Tested on debian jessie.

![bla](https://cloud.githubusercontent.com/assets/7513068/4968874/59a60dec-684e-11e4-815c-d03ca36110e2.png)

``` python
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.button import Button


class MyApp(App):

    def shoot(self, *args):
        self.root.export_to_png('bla.png')

    def build(self):
        Clock.schedule_once(self.shoot, 1)
        return Button(text='Test')

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

```



Discussion:
Works correctly with pygame.


Resolving patch:
diff --git a/kivy/uix/widget.py b/kivy/uix/widget.py
--- a/kivy/uix/widget.py
+++ b/kivy/uix/widget.py
@@ -172,7 +172,7 @@ def on_touch_down(self, touch, after=False):
 from kivy.properties import (NumericProperty, StringProperty, AliasProperty,
                              ReferenceListProperty, ObjectProperty,
                              ListProperty, DictProperty, BooleanProperty)
-from kivy.graphics import Canvas, Translate, Fbo, ClearColor, ClearBuffers
+from kivy.graphics import Canvas, Translate, Fbo, ClearColor, ClearBuffers, Scale
 from kivy.base import EventLoop
 from kivy.lang import Builder
 from kivy.context import get_current_context
@@ -555,11 +555,12 @@ def export_to_png(self, filename, *args):
         with fbo:
             ClearColor(0, 0, 0, 1)
             ClearBuffers()
-            Translate(-self.x, -self.y, 0)
+            Scale(1, -1, 1)
+            Translate(-self.x, -self.y - self.height, 0)
 
         fbo.add(self.canvas)
         fbo.draw()
-        fbo.texture.save(filename)
+        fbo.texture.save(filename, flipped=False)
         fbo.remove(self.canvas)
 
         if self.parent is not None:


Test patch: