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

Issue:
Voice Input in TextInput enters text twice.
Words get intered into the text input twice when using voice input.  Galaxy Tab II 7.0 running some 4.1.1 Android.



Discussion:
Got the same issue, very annoying.

Would be great if we could get a list of devices this is a issue on, per the discussion on irc with Knappador it seems to work fine with other devices. @tito tested with nexus7, 10 on 4.3.

I might have misinterpreted my communicae with knappador, seems he only has access to one device for testing. I'll retest on my device and report back.

kovak confirmed issue on droid4, 4.1.2

I can confirm on my nexus7 2013, with official keyboard, not with my usual non-standard keyboard though.


Resolving patch:
diff --git a/kivy/uix/textinput.py b/kivy/uix/textinput.py
--- a/kivy/uix/textinput.py
+++ b/kivy/uix/textinput.py
@@ -309,6 +309,8 @@ def __init__(self, **kwargs):
         self._line_options = None
         self._keyboard = None
         self._keyboard_mode = Config.get('kivy', 'keyboard_mode')
+        self._command_mode = False
+        self._command = ''
         self.reset_undo()
         self._touch_count = 0
         self.interesting_keys = {
@@ -454,10 +456,42 @@ def insert_text(self, substring, from_undo=False):
         '''Insert new text at the current cursor position. Override this
         function in order to pre-process text for input validation.
         '''
-        if self.readonly:
+        if self.readonly or not substring:
             return
+
         self._hide_handles(self._win)
 
+        # check for command modes
+        if ord(substring) == 1:
+            self._command_mode = True
+            self._command = ''
+        if ord(substring) == 2:
+            self._command_mode = False
+            self._command = self._command[1:]
+
+        if self._command_mode:
+            self._command += substring
+            return
+
+        _command = self._command
+        if _command and ord(substring) == 2:
+            from_undo = True
+            _command, data = _command.split(':')
+            self._command = ''
+            if _command == 'DEL':
+                count = int(data)
+                end = self.cursor_index()
+                self._selection_from = max(end - count, 0)
+                self._selection_to = end
+                self._selection = True
+                self.delete_selection(from_undo=True)
+                return
+            elif _command == 'INSERT':
+                substring = data
+            elif _command == 'INSERTN':
+                from_undo = False
+                substring = data
+
         if not from_undo and self.multiline and self.auto_indent \
                 and substring == u'\n':
             substring = self._auto_indent(substring)


Test patch:
Repository: kivy/kivy

Issue:
interactive.py illegally lists instance methods in __slots__
Trying to compile the docs with Python 3 sphinx, I get:

```
 Traceback (most recent call last):
   File "autobuild.py", line 58, in <module>
     import kivy.interactive
   File "/Users/valrus/.envs/kivy/lib/python3.3/site-packages/kivy/interactive.py", line 177, in <module>
     class SafeMembrane(object):
 ValueError: 'safeIn' in __slots__ conflicts with class variable
```

It appears this is just because `__slots__` should not list any methods in Python 3. I will have a trivial pull request to fix this shortly.



Discussion:

Resolving patch:
diff --git a/doc/autobuild.py b/doc/autobuild.py
--- a/doc/autobuild.py
+++ b/doc/autobuild.py
@@ -160,7 +160,7 @@ def writefile(filename, data):
 
 def extract_summary_line(doc):
     if doc is None:
-        return
+        return ""
     for line in doc.split('\n'):
         line = line.strip()
         # don't take empty line
diff --git a/kivy/interactive.py b/kivy/interactive.py
--- a/kivy/interactive.py
+++ b/kivy/interactive.py
@@ -185,7 +185,7 @@ class SafeMembrane(object):
     from leaking into the user's environment.
     '''
 
-    __slots__ = ('_ref', 'safe', 'confirmed', 'safeIn', 'safeOut')
+    __slots__ = ('_ref', 'safe', 'confirmed')
 
     def __init__(self, ob, *args, **kwargs):
         self.confirmed = EventLoop.confirmed


Test patch:
Repository: kivy/kivy

Issue:
SoundLoader can't determine file types for URL's with URL parameters in them.
Kivy currently can't load audio files from URL's that have URL parameters in them (For example `https://audio.example.com/get/test.wav?dl=true&token=9a8s76f9a876`).



Discussion:

Resolving patch:
diff --git a/kivy/core/audio/__init__.py b/kivy/core/audio/__init__.py
--- a/kivy/core/audio/__init__.py
+++ b/kivy/core/audio/__init__.py
@@ -59,6 +59,8 @@ def load(filename):
         if rfn is not None:
             filename = rfn
         ext = filename.split('.')[-1].lower()
+        if '?' in ext:
+            ext = ext.split('?')[0]
         for classobj in SoundLoader._classes:
             if ext in classobj.extensions():
                 return classobj(source=filename)


Test patch:
Repository: kivy/kivy

Issue:
log_level isn't honored from the config
setting log_level in config.ini doesn't change anything.by default logs are displayed at debug level.



Discussion:

Resolving patch:
diff --git a/kivy/__init__.py b/kivy/__init__.py
--- a/kivy/__init__.py
+++ b/kivy/__init__.py
@@ -179,14 +179,6 @@ def kivy_usage():
     print(kivy_usage.__doc__ % (basename(sys.argv[0])))
 
 
-# Start !
-if 'vim' in globals():
-    Logger.setLevel(level=LOG_LEVELS.get('critical'))
-else:
-    Logger.setLevel(level=LOG_LEVELS.get('info'))
-    Logger.info('Kivy v%s' % (__version__))
-    Logger.info('Python: v{}'.format(sys.version))
-
 #: Global settings options for kivy
 kivy_options = {
     'window': ('egl_rpi', 'pygame', 'sdl', 'x11'),
@@ -280,7 +272,6 @@ def kivy_usage():
     # Set level of logger
     level = LOG_LEVELS.get(Config.get('kivy', 'log_level'))
     Logger.setLevel(level=level)
-    Logger.setLevel(level=LOG_LEVELS.get('debug'))
 
     # Can be overrided in command line
     if 'KIVY_UNITTEST' not in environ and 'KIVY_PACKAGING' not in environ:
@@ -388,3 +379,7 @@ def kivy_usage():
 
     if platform == 'android':
         Config.set('input', 'androidtouch', 'android')
+
+Logger.info('Kivy v%s' % (__version__))
+Logger.info('Python: v{}'.format(sys.version))
+


Test patch:
Repository: kivy/kivy

Issue:
Permanent black pixel at the cursor's base in TextInput
It will appear only if hint_text is set, and it disappears, if there is some text. Tested on Windows 8.1.
https://gist.github.com/voen/dbb2b4e249833a9f87e9
![untitled-2](https://f.cloud.github.com/assets/5255957/2242064/6ca8d25c-9cf3-11e3-8241-21ef371d1d82.gif)



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
@@ -154,6 +154,7 @@ def insert_text(self, substring, from_undo=False):
 
 from kivy.core.text import Label
 from kivy.graphics import Color, Rectangle
+from kivy.graphics.texture import Texture
 
 from kivy.uix.widget import Widget
 from kivy.uix.bubble import Bubble
@@ -1765,6 +1766,13 @@ def _create_line_label(self, text, hint=False):
             label = None
             label_len = len(ntext)
             ld = None
+
+            # check for blank line
+            if not ntext:
+                texture  = Texture.create(size=(1, 1))
+                Cache_append('textinput.label', cid, texture)
+                return texture
+
             while True:
                 try:
                     label = Label(text=ntext[:label_len], **kw)


Test patch:
Repository: kivy/kivy

Issue:
Properties mentioned in .kv #comments become an event dependency
I found this bug by accident while trying to solve my [Problem with event resolution order](https://github.com/kivy/kivy/issues/2092)

> I made this very simple example: it's supposed to display some text in the top left of the window, and the font size should adapt to the window height.
> 
> But there is a problem: `top` seems to be updated before `font_size`, so the text's top position is counted according to the previous font size, which is very apparent when the window is maximized/restored: the text can even go outside the window, and it's also outside the window on application start.

And here is the weird thing: adding this comment to the code makes it work as expected!

```
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.base import runTouchApp

class ExampleWidget(Widget):
    pass
Builder.load_string('''
<ExampleWidget>:
    Label:
        font_size: 0.05*root.height
        size: self.texture_size
        text: "test"
        top: root.height-5 # self.texture_size
''')

runTouchApp(ExampleWidget())
```



Discussion:
This happens because comments are not stripped out from the kv code for when declared on the same line as the code.


Resolving patch:
diff --git a/kivy/lang.py b/kivy/lang.py
--- a/kivy/lang.py
+++ b/kivy/lang.py
@@ -919,6 +919,9 @@ def precompile(self):
         # now, detect obj.prop
         # first, remove all the string from the value
         tmp = sub(lang_str, '', value)
+        idx = tmp.find('#')
+        if idx != -1:
+            tmp = tmp[:idx]
         # detect key.value inside value, and split them
         wk = list(set(findall(lang_keyvalue, tmp)))
         if len(wk):


Test patch:
Repository: kivy/kivy

Issue:
EffectWidget can have artifacts over the time
After manipulating a lot the effects in the first example, i got artifacts.

 It's like the background is not cleared at some points. If i resize the window, everything is back to normal. I've been able to get it twice, but dunno all the things i've tested, cannot reproduce now.

The first time, the background of the right image in the first example was blue. After resize, it was back to black.
On the second time, some artifacts where appearing around the circle. Same, after resize, nothing.



Discussion:

Resolving patch:
diff --git a/kivy/uix/effectwidget.py b/kivy/uix/effectwidget.py
--- a/kivy/uix/effectwidget.py
+++ b/kivy/uix/effectwidget.py
@@ -113,7 +113,7 @@
 from kivy.properties import (StringProperty, ObjectProperty, ListProperty,
                              NumericProperty, DictProperty)
 from kivy.graphics import (RenderContext, Fbo, Color, Rectangle,
-                           Translate, PushMatrix, PopMatrix)
+                           Translate, PushMatrix, PopMatrix, ClearColor, ClearBuffers)
 from kivy.event import EventDispatcher
 from kivy.base import EventLoop
 from kivy.resources import resource_find
@@ -644,7 +644,9 @@ def __init__(self, **kwargs):
             PushMatrix()
             self.fbo_translation = Translate(-self.x, -self.y, 0)
         with self.fbo:
+            ClearColor(1, 1, 1, 1)
             Color(*self.background_color)
+            ClearBuffers()
             self.fbo_rectangle = Rectangle(size=self.size)
         with self.fbo.after:
             PopMatrix()
@@ -687,9 +689,10 @@ def refresh_fbo_setup(self, *args):
             with self.canvas:
                 new_fbo = EffectFbo(size=self.size)
             with new_fbo:
+                ClearColor(1, 1, 1, 1)
                 Color(*self.background_color)
-                new_fbo.texture_rectangle = Rectangle(
-                    size=self.size)
+                ClearBuffers()
+                new_fbo.texture_rectangle = Rectangle(size=self.size)
 
                 new_fbo.texture_rectangle.size = self.size
             self.fbo_list.append(new_fbo)


Test patch:
Repository: kivy/kivy

Issue:
[examples] installation of latest kivy-examples package fails
Looks like there is a simple syntax problem in an example...
Beleave it is not py3 compatible :/

Package: kivy-examples (1.8.1-daily0+201405040547-2023-testing42~ubuntu14.04.1)

```
  File "/usr/share/kivy-examples/widgets/compound_selection.py", line 17
    print [x.text for x in self.selected_nodes]
                    ^
SyntaxError: invalid syntax
```



Discussion:

Resolving patch:
diff --git a/examples/widgets/compound_selection.py b/examples/widgets/compound_selection.py
--- a/examples/widgets/compound_selection.py
+++ b/examples/widgets/compound_selection.py
@@ -14,7 +14,7 @@ def __init__(self, **kwargs):
                       on_key_up=self.select_with_key_up)
 
         def print_selection(*l):
-            print [x.text for x in self.selected_nodes]
+            print(x.text for x in self.selected_nodes)
         self.bind(selected_nodes=print_selection)
 
     def goto_node(self, key, last_node, last_node_idx):


Test patch:
Repository: kivy/kivy

Issue:
Logger ignores custom log_dir
The new value is set but logs are created in the default log directory, tested on Windows.

```
import os
from kivy.config import Config
Config.set('kivy', 'log_dir', os.path.dirname(os.path.abspath(__file__)))
print(Config.get('kivy', 'log_dir'))

from kivy.app import App
from kivy.core.window import Window

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



Discussion:
Good one, snake head and tail issue. The logfile is opened during import of Config, based on the file recommendation. Changing it after = need to close the previous and reopen in the new place.


Resolving patch:
diff --git a/kivy/logger.py b/kivy/logger.py
--- a/kivy/logger.py
+++ b/kivy/logger.py
@@ -140,7 +140,7 @@ def purge_logs(self, directory):
 
         print('Purge finished !')
 
-    def _configure(self):
+    def _configure(self, *largs, **kwargs):
         from time import strftime
         from kivy.config import Config
         log_dir = Config.get('kivy', 'log_dir')
@@ -167,7 +167,11 @@ def _configure(self):
             if n > 10000:  # prevent maybe flooding ?
                 raise Exception('Too many logfile, remove them')
 
+        if FileHandler.filename == filename and FileHandler.fd is not None:
+            return
         FileHandler.filename = filename
+        if FileHandler.fd is not None:
+            FileHandler.fd.close()
         FileHandler.fd = open(filename, 'w')
 
         Logger.info('Logger: Record log in %s' % filename)
@@ -199,6 +203,9 @@ def emit(self, message):
         if FileHandler.fd is None:
             try:
                 self._configure()
+                from kivy.config import Config
+                Config.add_callback(self._configure, 'kivy', 'log_dir')
+                Config.add_callback(self._configure, 'kivy', 'log_name')
             except Exception:
                 # deactivate filehandler...
                 FileHandler.fd = False


Test patch:
Repository: kivy/kivy

Issue:
[examples] installation of latest kivy-examples package fails
Looks like there is a simple syntax problem in an example...
Beleave it is not py3 compatible :/

Package: kivy-examples (1.8.1-daily0+201405040547-2023-testing42~ubuntu14.04.1)

```
  File "/usr/share/kivy-examples/widgets/compound_selection.py", line 17
    print [x.text for x in self.selected_nodes]
                    ^
SyntaxError: invalid syntax
```



Discussion:

Resolving patch:
diff --git a/examples/widgets/compound_selection.py b/examples/widgets/compound_selection.py
--- a/examples/widgets/compound_selection.py
+++ b/examples/widgets/compound_selection.py
@@ -14,7 +14,7 @@ def __init__(self, **kwargs):
                       on_key_up=self.select_with_key_up)
 
         def print_selection(*l):
-            print(x.text for x in self.selected_nodes)
+            print([x.text for x in self.selected_nodes])
         self.bind(selected_nodes=print_selection)
 
     def goto_node(self, key, last_node, last_node_idx):


Test patch:
Repository: kivy/kivy

Issue:
TypeError in image.read_pixel (Python3.4)
In my code I call `image.read_pixel(x, y)` and I get the following exception:

``` python
...
     color = tuple(image.read_pixel(x, y))
   File "/usr/local/lib/python3.4/dist-packages/kivy/core/image/__init__.py", line 778, in read_pixel
     color = [ord(c) / 255.0 for c in raw]
   File "/usr/local/lib/python3.4/dist-packages/kivy/core/image/__init__.py", line 778, in <listcomp>
     color = [ord(c) / 255.0 for c in raw]
 TypeError: ord() expected string of length 1, but int found
```



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
@@ -776,8 +776,8 @@ def read_pixel(self, x, y):
         assert data.fmt in ImageData._supported_fmts
         size = 3 if data.fmt in ('rgb', 'bgr') else 4
         index = y * data.width * size + x * size
-        raw = data.data[index:index + size]
-        color = [ord(c) / 255.0 for c in raw]
+        raw = bytearray(data.data[index:index + size])
+        color = [c / 255.0 for c in raw]
 
         # conversion for BGR->RGB, BGR->RGBA format
         if data.fmt in ('bgr', 'bgra'):


Test patch:
Repository: kivy/kivy

Issue:
Color markup lost on window resize
I'm using kivy 1.8.0 and I have some labels with color markup in the label text. The colors show up on initialization of the program, but if I resize the window, all color markup is lost and all the text labels are white.



Discussion:
Here is some sample code that is showing the issue for me: http://pastebin.com/7aXam3Bv

The two labels at the bottom right start off blue, then change to white if window is resized.

Some more testing: it looks like the color is cleared when it is set with the `color` property, but not if it's done with markup.

```
from kivy.app import App
from kivy.lang import Builder

kv = """
GridLayout:
    cols: 1
    Label:
        color: 0.7, 0, 0, 1
        font_size: 100
        markup: True
        text: 'SAMPLE'
    Label:
        font_size: 100
        markup: True
        text: '[color=3333ff]SAMPLE[/color]'
"""


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

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

Using markup=False is a possible workaround if you don't need it. Cannot reproduce with 1.8.0 on linux, but Windows and MacOS is affected using same version


Resolving patch:
diff --git a/kivy/uix/label.py b/kivy/uix/label.py
--- a/kivy/uix/label.py
+++ b/kivy/uix/label.py
@@ -202,7 +202,6 @@ def texture_update(self, *largs):
                 # force the rendering to get the references
                 if self._label.texture:
                     self._label.texture.bind()
-                self._label.text = text
                 self.refs = self._label.refs
                 self.anchors = self._label.anchors
             else:


Test patch:
Repository: kivy/kivy

Issue:
Phantom reference links remain after Label text cleared.
Repo:
1. Run this program:

```
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout

class TestApp(App):
    def build(self):
        layout = FloatLayout()
        b = Button(text='Clear',
                   pos_hint={'x': 0.0, 'y':0.0},
                   size_hint=(1.0, 0.5))
        b.bind(on_press=self.clear_it)
        layout.add_widget(b)

        self.l = Label(text='[ref=test]test[/ref]', markup=True,
                       font_size=50,
                   pos_hint={'x': 0.0, 'y':0.5},
                   size_hint=(1.0, 0.5))

        self.l.bind(on_ref_press=self.print_it)
        layout.add_widget(self.l)
        return layout

    def print_it(self, instance, value):
        print('User clicked on', value)

    def clear_it(self, instance):
        self.l.text = ''

TestApp().run()
```
1. Click on the "test" text to verify that it prints.
2. Click the clear button.
3. Click the bottom half and right side of where the word "test" used to be. (The clickable area appears to move down and to the right while shrinking somewhat.)
4. Observe that the print statement still fires.

The problem appears to be that the when the text is set to an empty string it fails to clear the references and anchors.

Changing the texture_update method of the Label class to the following seems to fix it (I'm not 100% sure this is exactly the appropriate way to fix it but it seems to work):

```
if self._label.text.strip() == '':
            self.texture_size = (0, 0)
            mrkup = self._label.__class__ is CoreMarkupLabel
            if mrkup:
                self.refs = {}
                self.anchors = {}
        else:
...
```



Discussion:

Resolving patch:
diff --git a/kivy/uix/label.py b/kivy/uix/label.py
--- a/kivy/uix/label.py
+++ b/kivy/uix/label.py
@@ -182,12 +182,16 @@ def texture_update(self, *largs):
         After this function call, the :attr:`texture` and :attr:`texture_size`
         will be updated in this order.
         '''
+        mrkup = self._label.__class__ is CoreMarkupLabel
         self.texture = None
+
         if (not self._label.text or (self.halign[-1] == 'y' or self.strip) and
             not self._label.text.strip()):
             self.texture_size = (0, 0)
+            if mrkup:
+                self.refs, self._label._refs = {}, {}
+                self.anchors, self._label._anchors = {}, {}
         else:
-            mrkup = self._label.__class__ is CoreMarkupLabel
             if mrkup:
                 text = self._label.text
                 # we must strip here, otherwise, if the last line is empty,


Test patch:
Repository: kivy/kivy

Issue:
touch grab doesn't work for weakproxy
If you pass a weakproxy to `MotionEvent.grab()`, a `TypeError` is raised as you cannot create a weakref to a weakproxy. This can be worked around by changing the following line in `MotionEvent.grab()`:

```
class_instance = weakref.ref(class_instance)
```

to this:

```
try:
    class_instance = weakref.ref(class_instance)
except TypeError:
    ci = class_instance
    class_instance = lambda: ci
```

This works, however weakproxy does not support comparison using the `is` operator, so all lines like `if touch.grab_current is widget` must change to `if touch.grab_current.__eq__(widget)`. So I'm not sure if this is a good approach or not. Have I mentioned that I hate weakproxy yet?



Discussion:

Resolving patch:
diff --git a/kivy/input/motionevent.py b/kivy/input/motionevent.py
--- a/kivy/input/motionevent.py
+++ b/kivy/input/motionevent.py
@@ -320,7 +320,11 @@ def on_touch_up(self, touch):
             raise Exception('Grab works only for Touch MotionEvents.')
         if self.grab_exclusive_class is not None:
             raise Exception('Cannot grab the touch, touch is exclusive')
-        class_instance = weakref.ref(class_instance)
+        try:
+            class_instance = weakref.ref(class_instance)
+        except TypeError:
+            # handle weakproxy objects which cannot be weakref'd
+            class_instance = weakref.ref(class_instance.__self__)
         if exclusive:
             self.grab_exclusive_class = class_instance
         self.grab_list.append(class_instance)


Test patch: