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

Issue:
Window is always resizable, minimizable and closeable on windows
**Describe the bug**
Window seems to ignore `resizable`, `minimizable` and `closeable` args on OS Windows: if they're set to `False`, window still can be resized, minimized and closed.

**To Reproduce**
Steps to reproduce the behavior:
1. Pass `minimizable=False`, `resizable=False` and `closeable=False` to `Window.__init__`.
2. Resize it, minimize it, close it.

**Expected behavior**
Window should keep its size, and all of titlebar buttons should be hidden (minimize and close due to corresponding args, and fullscreen due to resizable).

**Simple example**
```python
import toga


class App(toga.App):
    def open_window(self, widget: toga.Widget):
        # resizable, minimizable and closeable are False
        window = toga.Window(
            "window id", "window title", size=(320, 240), resizeable=False, minimizable=False, closeable=False
        )
        window.content = toga.Box()
        self.windows += window
        window.show()

    def startup(self):
        # resizable and minimizable are False
        self.main_window = toga.MainWindow(
            title=self.formal_name, factory=self.factory, resizeable=False, minimizable=False
        )

        box = toga.Box()
        btn = toga.Button("Open second window", on_press=self.open_window)
        box.add(btn)
        self.main_window.content = box

        self.main_window.show()


def main():
    App("testing", "testing").main_loop()


if __name__ == "__main__":
    main()

```

**Screenshots**
![resizing](https://user-images.githubusercontent.com/2825638/152692206-4b1f3a1b-0945-4895-a71b-31c379e26fe6.gif)


**Environment:**
 - Operating System: Windows 10
 - Python version: 3.10.1
 - Software versions:
   - Toga: 0.3.0.dev30


Discussion:

Resolving patch:
diff --git a/src/winforms/toga_winforms/window.py b/src/winforms/toga_winforms/window.py
--- a/src/winforms/toga_winforms/window.py
+++ b/src/winforms/toga_winforms/window.py
@@ -48,6 +48,8 @@ def __init__(self, interface, title, position, size):
         self.native.interface = self.interface
         self.native.FormClosing += self.winforms_FormClosing
 
+        self.native.MinimizeBox = self.native.interface.minimizable
+
         self.set_title(title)
         self.set_size(size)
         self.set_position(position)


Test patch:
Repository: beeware/toga

Issue:
WHEN TYPING "-" IN THE NUMBERINPUT, WIDGET FAILS.
"""
TESTE
"""
import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW


class TESTE(toga.App):

    def startup(self):
        """
        Construct and show the Toga application.

        Usually, you would add your application to a main content box.
        We then create a main window (with a name matching the app), and
        show the main window.
        """

        # WIDGETS ###############################
        self.number = toga.NumberInput()
        self.pushButton = toga.Button('AHHHH')
        ########################################

        # BOX ####################################################
        main_box = toga.Box(style=Pack(direction=COLUMN))
        main_box.add(self.number, self.pushButton)
        #########################################################

        # EVENT #####################################################
        self.pushButton.on_press = self.printar
        ##############################################################

        # WINDOW #####################################################
        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()
        ##############################################################

    def printar(self, widget):
        brasil = float(self.number.value)
        print(brasil)

def main():
    return TESTE()

https://user-images.githubusercontent.com/75274707/195914116-84981cc4-62d4-423c-a51d-0b77b4f6948a.mp4




Discussion:
[briefcase.2022_10_14-15_07_40.run.log](https://github.com/beeware/toga/files/9789054/briefcase.2022_10_14-15_07_40.run.log)

Using: toga-android==0.3.0.dev35

Resolving patch:
diff --git a/src/android/toga_android/widgets/numberinput.py b/src/android/toga_android/widgets/numberinput.py
--- a/src/android/toga_android/widgets/numberinput.py
+++ b/src/android/toga_android/widgets/numberinput.py
@@ -1,4 +1,4 @@
-from decimal import Decimal
+from decimal import Decimal, InvalidOperation
 
 from travertino.size import at_least
 
@@ -10,11 +10,11 @@
 
 
 def decimal_from_string(s):
-    """If s is the empty string, return `None`. Otherwise, convert to a `Decimal`,
-    allowing any exceptions to bubble up."""
-    if not s:
+    """Convert s to a `Decimal`, returning `None` if it's not a valid number."""
+    try:
+        return Decimal(s)
+    except InvalidOperation:
         return None
-    return Decimal(s)
 
 
 def string_from_decimal(d):


Test patch:
Repository: beeware/toga

Issue:
Android: `paths.app` doesn't work in event handlers
**Describe the bug**

On Android, `paths.app` returns `/` when called outside of the `startup` method, e.g. in an event handler. This is because the `__main__` module has finished importing, and it no longer exists in `sys.modules` under that name.

This doesn't happen on Windows, because it runs the entire main loop within the top level of the `__main__` module. The other desktop platforms are probably the same.

But on Android, the main loop is already running and we have to integrate into it, so importing the `__main__` module does not block. From inspection of the code, it looks like iOS is similar, so it might have the same problem.

The fallback to `/` makes no sense on Android anyway, so it should be removed.

Reported by @kakos-k9 on Discord.

**Test app**
```python
import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW

class Hello(toga.App):

    def startup(self):
        button = toga.Button("Print", on_press=self.on_press)
        self.on_press(button)

        self.main_window = toga.MainWindow()
        self.main_window.content = toga.Box(
            style=Pack(direction=COLUMN),
            children=[button]
        )
        self.main_window.show()

    def on_press(self, button):
        import traceback
        for name in ["app", "data", "toga"]:
            print(f"{name}={getattr(self.paths, name)}")


def main():
    return Hello()
```

**Environment:**
 - Operating System: Android
 - Python version: 3.8
 - Software versions:
   - Toga: 9a292f8e26



Discussion:

Resolving patch:
diff --git a/src/android/toga_android/paths.py b/src/android/toga_android/paths.py
--- a/src/android/toga_android/paths.py
+++ b/src/android/toga_android/paths.py
@@ -13,18 +13,13 @@ class Paths:
     def __context(self):
         return App.app._impl.native.getApplicationContext()
 
+    def __init__(self):
+        # On Android, __main__ only exists during app startup, so cache its location now.
+        self._app = Path(sys.modules["__main__"].__file__).parent
+
     @property
     def app(self):
-        try:
-            return Path(sys.modules["__main__"].__file__).parent
-        except KeyError:
-            # If we're running in test conditions,
-            # there is no __main__ module.
-            return Path.cwd()
-        except AttributeError:
-            # If we're running at an interactive prompt,
-            # the __main__ module isn't file-based.
-            return Path.cwd()
+        return self._app
 
     @property
     def data(self):


Test patch:
Repository: beeware/toga

Issue:
Source installs no longer working
#1614 made some changes to the packaging of modules to support the release package workflow.

The wheels generated from this process appear to work fine; however, source installs don't appear to be working. I've had problems on both macOS and Android.

**To Reproduce**
Steps to reproduce the behavior:
1. `briefcase run` or `briefcase run android` on Tutorial 0.

**Expected behavior**

App should start.

**Environment:**
 - Operating System: macOS
 - Python version: 3.10
 - Software versions:
   - Briefcase: 0.3.11
   - Toga: 96881f093



Discussion:
> The wheels generated from this process appear to work fine

They do, but the `src` folder's contents are bundled in the main toga wheel as of 0.3.0.dev39 and get installed by pip as if they were packages.

At some point in the not too distant past setuptools was made to auto-discover packages under `src`, so the following line needs to be added to the toga `setup.cfg` under `[options]` to prevent it from bundling everything under `src` in the wheel:

```
packages =
```

cc @abravalheri in case he has a better suggestion.

Resolving patch:
diff --git a/src/web/setup.py b/src/web/setup.py
--- a/src/web/setup.py
+++ b/src/web/setup.py
@@ -20,10 +20,6 @@
 setup(
     version=version,
     install_requires=[
-        # TODO: Due to https://github.com/pyodide/pyodide/issues/2408, the name
-        # toga-core is ambigous when on the package hasn't been published to
-        # PyPI. As a workaround, don't specify the dependency, and manually
-        # ensure that toga-core is installed.
-        # 'toga-core==%s' % version,
+        'toga-core==%s' % version,
     ],
 )


Test patch:
Repository: beeware/toga

Issue:
App.paths property is not documented
So it's not surprising that people keep failing to use it (e.g. #1568).


Discussion:
Can't argue with that. Definitely need more docs, across the board.

Resolving patch:
diff --git a/core/src/toga/app.py b/core/src/toga/app.py
--- a/core/src/toga/app.py
+++ b/core/src/toga/app.py
@@ -19,7 +19,6 @@
     # Backwards compatibility - imporlib.metadata was added in Python 3.8
     import importlib_metadata
 
-
 # Make sure deprecation warnings are shown by default
 warnings.filterwarnings("default", category=DeprecationWarning)
 
@@ -321,7 +320,7 @@ def __init__(
 
         # Get a platform factory, and a paths instance from the factory.
         self.factory = get_platform_factory()
-        self.paths = self.factory.paths
+        self._paths = self.factory.paths
 
         # If an icon (or icon name) has been explicitly provided, use it;
         # otherwise, the icon will be based on the app name.
@@ -349,6 +348,42 @@ def __init__(
     def _create_impl(self):
         return self.factory.App(interface=self)
 
+    @property
+    def paths(self):
+        """
+        Paths for platform appropriate locations on the user's filesystem.
+
+        Some platforms do not allow arbitrary file access to any location on
+        disk; even when arbitrary filesystem access is allowed, there are
+        "preferred" locations for some types of content.
+
+        The ``paths`` object has a set of sub-properties that return
+        ``pathlib.Path`` instances of platform-appropriate paths on the
+        filesystem.
+
+        :PROPERTIES:
+            * **app** – The directory containing the app's ``__main__`` module.
+              This location should be considered read-only, and only used to
+              retrieve app-specific resources (e.g., resource files bundled with
+              the app).
+
+            * **data** – Platform-appropriate location for user data (e.g., user
+              settings)
+
+            * **cache** – Platform-appropriate location for temporary files. It
+              should be assumed that the operating system will purge the
+              contents of this directory without warning if it needs to recover
+              disk space.
+
+            * **logs** – Platform-appropriate location for log files for this
+              app.
+
+            * **toga** – The path of the ``toga`` core module. This location
+              should be considered read-only.
+
+        """
+        return self._paths
+
     @property
     def name(self):
         """The formal name of the app.


Test patch:
Repository: beeware/toga

Issue:
Hide webview black background when resizing
### Describe the bug

By default in Windows, a webview will render a black background behind it. When resizing the webview, this black background becomes visible for a couple of frames while the html rendered on top is still in the process of updating, resulting in black "bars" appearing at the side of the webview when resizing it.

This can look quite ugly

### Steps to reproduce

see: https://youtu.be/Xj1rW4L-Pqk

```py
"""
My first application
"""
import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW


class HelloWorld(toga.App):

    def startup(self):
        """
        Construct and show the Toga application.

        Usually, you would add your application to a main content box.
        We then create a main window (with a name matching the app), and
        show the main window.
        """
        web = toga.WebView(url='https://google.com')
        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = web
        self.main_window.show()




def main():
    helloWorld = HelloWorld("foobar",
                            "org.foo.bar")
    return helloWorld


main().main_loop()
```

### Environment

- Operating System:
- Windows 11, winforms
- Python version:
- 3.10
- Software versions:
  - Briefcase:
  - 0.3.12
  - Toga:
  - 0.3.0




Discussion:

Resolving patch:
diff --git a/winforms/src/toga_winforms/widgets/webview.py b/winforms/src/toga_winforms/widgets/webview.py
--- a/winforms/src/toga_winforms/widgets/webview.py
+++ b/winforms/src/toga_winforms/widgets/webview.py
@@ -8,6 +8,7 @@
 from toga_winforms.keys import toga_key
 from toga_winforms.libs import (
     Action,
+    Color,
     CoreWebView2CreationProperties,
     String,
     Task,
@@ -43,6 +44,7 @@ def create(self):
 
         # Trigger the configuration of the webview
         self.native.EnsureCoreWebView2Async(None)
+        self.native.DefaultBackgroundColor = Color.Transparent
 
     def winforms_initialization_completed(self, sender, args):
         # The WebView2 widget has an "internal" widget (CoreWebView2) that is


Test patch:
Repository: beeware/toga

Issue:
Window without `on_close` handler can't be closed with the window decoration
### Describe the bug

If a window is defined without an `on_close` handler, The close button (X or red button on the window frame) cannot be used to close the window

### Steps to reproduce

1. Run the `windows` example
2. Click on the "create windows" button
3. Try to close the window with "no on_close handler"

The window should, but will not close. There are no errors or log messages.

Programmatically invoking `window.close()` *does* work.

### Expected behavior

The window should close.

### Screenshots

_No response_

### Environment

- Operating System: Windows, macOS, Linux
- Python version: All
- Software versions:
  - Toga: 0.3.1


### Logs

_No response_

### Additional context

As a workaround, adding `on_close=lambda w: True` to the window will allow it to close.

This is likely caused by 0d9d43a from #1833.


Discussion:
Overlaps with #1714.
There may be some conceptual overlap, but this is a specific regression in the `on_close` handler; this functionality worked in 0.3.0. #1714 is new (albeit definitely required) functionality.

Resolving patch:
diff --git a/cocoa/src/toga_cocoa/window.py b/cocoa/src/toga_cocoa/window.py
--- a/cocoa/src/toga_cocoa/window.py
+++ b/cocoa/src/toga_cocoa/window.py
@@ -311,7 +311,7 @@ def set_full_screen(self, is_full_screen):
         self.interface.factory.not_implemented("Window.set_full_screen()")
 
     def cocoa_windowShouldClose(self):
-        if self.interface.on_close:
+        if self.interface.on_close._raw:
             # The on_close handler has a cleanup method that will enforce
             # the close if the on_close handler requests it; this initial
             # "should close" request can always return False.
diff --git a/gtk/src/toga_gtk/window.py b/gtk/src/toga_gtk/window.py
--- a/gtk/src/toga_gtk/window.py
+++ b/gtk/src/toga_gtk/window.py
@@ -106,7 +106,7 @@ def get_visible(self):
     def gtk_delete_event(self, widget, data):
         if self._is_closing:
             should_close = True
-        elif self.interface.on_close:
+        elif self.interface.on_close._raw:
             should_close = self.interface.on_close(self.interface.app)
         else:
             should_close = True
diff --git a/winforms/src/toga_winforms/window.py b/winforms/src/toga_winforms/window.py
--- a/winforms/src/toga_winforms/window.py
+++ b/winforms/src/toga_winforms/window.py
@@ -189,7 +189,7 @@ def winforms_FormClosing(self, sender, event):
             if not self.interface.closeable:
                 # Closeability is implemented by shortcutting the close handler.
                 event.Cancel = True
-            elif self.interface.on_close:
+            elif self.interface.on_close._raw:
                 # If there is an on_close event handler, process it;
                 # but then cancel the close event. If the result of
                 # on_close handling indicates the window should close,


Test patch:
Repository: beeware/toga

Issue:
Cycle between windows can't find icon resources/window
### Describe the bug

cd toga/examples/window
> python -m window

After selecting "Create Window" 3 toga windows are created
Moved the main display away from the windows and selected "Cycle between windows"
This resulted in the following traceback:

>python -m window
WARNING: Can't find icon resources/window; falling back to default icon
```
Error in async handler: 'Form' object has no attribute '_impl'
Traceback (most recent call last):
  File "C:\Users\eilee\beewareToga\toga\core\src\toga\handlers.py", line 28, in handler_with_cleanup
    result = await handler(interface, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\eilee\beewareToga\toga\examples\window\window\app.py", line 75, in do_current_window_cycling
    self.label.text = f"Current window is {self.current_window.id}"
                                           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\eilee\beewareToga\toga\core\src\toga\app.py", line 518, in current_window
    return self._impl.get_current_window().interface
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\eilee\beewareToga\toga\winforms\src\toga_winforms\app.py", line 293, in get_current_window
    return WinForms.Form.ActiveForm._impl
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Form' object has no attribute '_impl'
```

### Steps to reproduce

1. toga/examples/window
2. python -m window
3. Select "Create Window"
4. Move main window away from new windows
5. Select "Cycle between windows"

### Expected behavior

Traceback show above

### Screenshots

_No response_

### Environment

- Operating System: Windows
- Python version: 3.11.3
- Software versions:
  - Briefcase: 
  - Toga: 0.3.2.dev82+gbc44914a
  - ...


### Logs

```

```


### Additional context

_No response_


Discussion:
Thanks for the report. Looks like the Winforms implementation merged in #1887 was buggy. (Ping @proneon267) 

Resolving patch:
diff --git a/winforms/src/toga_winforms/app.py b/winforms/src/toga_winforms/app.py
--- a/winforms/src/toga_winforms/app.py
+++ b/winforms/src/toga_winforms/app.py
@@ -290,7 +290,9 @@ def set_main_window(self, window):
         self.app_context.MainForm = window._impl.native
 
     def get_current_window(self):
-        return WinForms.Form.ActiveForm._impl
+        for window in self.interface.windows:
+            if WinForms.Form.ActiveForm == window._impl.native:
+                return window._impl.native
 
     def set_current_window(self, window):
         window._impl.native.Activate()
diff --git a/winforms/src/toga_winforms/window.py b/winforms/src/toga_winforms/window.py
--- a/winforms/src/toga_winforms/window.py
+++ b/winforms/src/toga_winforms/window.py
@@ -47,6 +47,7 @@ def __init__(self, interface, title, position, size):
 
         self.native = WinForms.Form()
         self.native.interface = self.interface
+        self.native._impl = self
         self.native.FormClosing += self.winforms_FormClosing
 
         self.native.MinimizeBox = self.native.interface.minimizable


Test patch:
Repository: beeware/toga

Issue:
DetailedList showing empty rows
### Describe the bug

Using Toga for the first time, trying to add `DetailedListBox` to my window. *Something* shows up in the box that contains the `DetailedListBox`, but it just looks like a single empty list cell. `on_select` confirms that it's a list cell.

### Steps to reproduce

Run this code:

```python
import toga
from toga.style.pack import Pack

history_data = [
    {
        'icon': toga.Icon.DEFAULT_ICON,
        'title': 'Foo',
        'subtitle': 'Bar',
        'pk': 100,
    },
]


def build(app):
    history = toga.DetailedList(
        id='foo',
        data=history_data,
        on_select=selection_handler,
    )

    history_box = toga.Box()
    history_box.add(history)

    box = toga.Box(style=Pack(padding=(5, 5)))

    box.add(history_box)

    return box


def main():
    return toga.App('DetailedList test', 'foo.bar', startup=build)


def selection_handler(widget, row):
    print('Row {} of widget {} was selected'.format(row, widget))


if __name__ == '__main__':
    main().main_loop()
```

### Expected behavior

A populated listbox shows up

### Screenshots

![image](https://user-images.githubusercontent.com/4182659/235446971-06292534-f8c3-4292-9dec-540a19f54f3f.png)


### Environment

- Operating System: Manjaro Linux
- Python version: 3.10
- Software versions:
  - Briefcase:
  - Toga: 0.3.1
  - ...


### Logs

```

```


### Additional context

- If I add other stuff to `box`, that stuff renders fine
- No matter how many rows I add in list, always seems to render just one empty cell


Discussion:
Looking into this, and looks like a temporary fix is setting a width for the detailed list manually makes it show the items in the list.
Fantastic, thanks @LunaMeadows !

Resolving patch:
diff --git a/gtk/src/toga_gtk/widgets/detailedlist.py b/gtk/src/toga_gtk/widgets/detailedlist.py
--- a/gtk/src/toga_gtk/widgets/detailedlist.py
+++ b/gtk/src/toga_gtk/widgets/detailedlist.py
@@ -1,3 +1,5 @@
+from travertino.size import at_least
+
 from ..libs import Gdk, Gio, GLib, Gtk
 from .base import Widget
 from .internal.buttons.refresh import RefreshButton
@@ -213,3 +215,7 @@ def _list_items_changed(self):
         self.refresh_button.list_changed()
         self.scroll_button.list_changed()
         return True
+
+    def rehint(self):
+        self.interface.intrinsic.width = at_least(self.interface._MIN_WIDTH)
+        self.interface.intrinsic.height = at_least(self.interface._MIN_HEIGHT)


Test patch: