We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Asking how to use "file_types" in open_file_dialog
When I bookmark a list like the example below
`    def action_open_file_dialog(self, multi_var, widget=None):
            filenames = self.main_window.open_file_dialog(
                title="Open file with Toga",
                multiselect=multi_var,
                file_types=['gif', 'tiff', 'jpeg', 'bmp', 'png', 'webp']
            )`
The result is a column list, which will prevent the window from displaying all images in the correct format in the list.
How does the window show all the listed formats, instead of having to select files one by one or All files. Similar to the example in HTML.
input type="file"
       id="avatar" name="avatar"
       accept="image/png, image/jpeg"
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/winforms/toga_winforms/window.py`
Content:
```
1 from toga import GROUP_BREAK, SECTION_BREAK
2 
3 from .libs import Size, WinForms
4 
5 
6 class WinFormsViewport:
7     def __init__(self, native, frame):
8         self.native = native
9         self.frame = frame
10         self.baseline_dpi = 96
11 
12     @property
13     def width(self):
14         # Treat `native=None` as a 0x0 viewport
15         if self.native is None:
16             return 0
17         return self.native.ClientSize.Width
18 
19     @property
20     def height(self):
21         if self.native is None:
22             return 0
23         # Subtract any vertical shift of the frame. This is to allow
24         # for toolbars, or any other viewport-level decoration.
25         return self.native.ClientSize.Height - self.frame.vertical_shift
26 
27     @property
28     def dpi(self):
29         if self.native is None:
30             return self.baseline_dpi
31         return self.native.CreateGraphics().DpiX
32 
33 
34 class Window:
35     def __init__(self, interface):
36         self.interface = interface
37         self.interface._impl = self
38         self.create()
39 
40     def create(self):
41         self.native = WinForms.Form(self)
42         self.native.ClientSize = Size(*self.interface._size)
43         self.native.interface = self.interface
44         self.native.Resize += self.winforms_resize
45         self.toolbar_native = None
46         self.toolbar_items = None
47 
48     def create_toolbar(self):
49         self.toolbar_native = WinForms.ToolStrip()
50         for cmd in self.interface.toolbar:
51             if cmd == GROUP_BREAK:
52                 item = WinForms.ToolStripSeparator()
53             elif cmd == SECTION_BREAK:
54                 item = WinForms.ToolStripSeparator()
55             else:
56                 if cmd.icon is not None:
57                     native_icon = cmd.icon._impl.native
58                     item = WinForms.ToolStripMenuItem(cmd.label, native_icon.ToBitmap())
59                 else:
60                     item = WinForms.ToolStripMenuItem(cmd.label)
61                 item.Click += cmd._impl.as_handler()
62                 cmd._impl.native.append(item)
63             self.toolbar_native.Items.Add(item)
64 
65     def set_position(self, position):
66         pass
67 
68     def set_size(self, size):
69         self.native.ClientSize = Size(*self.interface._size)
70 
71     def set_app(self, app):
72         if app is None:
73             return
74         icon_impl = app.interface.icon._impl
75         if icon_impl is None:
76             return
77         self.native.Icon = icon_impl.native
78 
79     @property
80     def vertical_shift(self):
81         # vertical shift is the toolbar height or 0
82         result = 0
83         try:
84             result += self.native.interface._impl.toolbar_native.Height
85         except AttributeError:
86             pass
87         try:
88             result += self.native.interface._impl.native.MainMenuStrip.Height
89         except AttributeError:
90             pass
91         return result
92 
93     def set_content(self, widget):
94         if self.toolbar_native:
95             self.native.Controls.Add(self.toolbar_native)
96             # Create the lookup table of menu items,
97             # then force the creation of the menus.
98         self.native.Controls.Add(widget.native)
99 
100         # Set the widget's viewport to be based on the window's content.
101         widget.viewport = WinFormsViewport(native=self.native, frame=self)
102         widget.frame = self
103 
104         # Add all children to the content widget.
105         for child in widget.interface.children:
106             child._impl.container = widget
107 
108     def set_title(self, title):
109         self.native.Text = title
110 
111     def show(self):
112         # The first render of the content will establish the
113         # minimum possible content size; use that to enforce
114         # a minimum window size.
115         TITLEBAR_HEIGHT = WinForms.SystemInformation.CaptionHeight
116         # Now that the content is visible, we can do our initial hinting,
117         # and use that as the basis for setting the minimum window size.
118         self.interface.content._impl.rehint()
119         self.interface.content.style.layout(
120             self.interface.content,
121             WinFormsViewport(native=None, frame=None),
122         )
123         self.native.MinimumSize = Size(
124             int(self.interface.content.layout.width),
125             int(self.interface.content.layout.height) + TITLEBAR_HEIGHT
126         )
127         self.interface.content.refresh()
128 
129         self.native.Show()
130 
131     def winforms_FormClosing(self, event, handler):
132         if self.interface.app.on_exit:
133             self.interface.app.on_exit(self.interface.app)
134 
135     def set_full_screen(self, is_full_screen):
136         self.interface.factory.not_implemented('Window.set_full_screen()')
137 
138     def on_close(self):
139         pass
140 
141     def close(self):
142         self.native.Close()
143 
144     def winforms_resize(self, sender, args):
145         if self.interface.content:
146             # Re-layout the content
147             self.interface.content.refresh()
148 
149     def info_dialog(self, title, message):
150         return WinForms.MessageBox.Show(message, title, WinForms.MessageBoxButtons.OK)
151 
152     def question_dialog(self, title, message):
153         result = WinForms.MessageBox.Show(message, title, WinForms.MessageBoxButtons.YesNo)
154         return result
155 
156     def confirm_dialog(self, title, message):
157         result = WinForms.MessageBox.Show(message, title, WinForms.MessageBoxButtons.OKCancel)
158         # this returns 1 (DialogResult.OK enum) for OK and 2 for Cancel
159         return True if result == WinForms.DialogResult.OK else False
160 
161     def error_dialog(self, title, message):
162         return WinForms.MessageBox.Show(message, title, WinForms.MessageBoxButtons.OK,
163                                         WinForms.MessageBoxIcon.Error)
164 
165     def stack_trace_dialog(self, title, message, content, retry=False):
166         pass
167 
168     def save_file_dialog(self, title, suggested_filename, file_types):
169         dialog = WinForms.SaveFileDialog()
170         dialog.Title = title
171         if suggested_filename is not None:
172             dialog.FileName = suggested_filename
173         if file_types is not None:
174             dialog.Filter = self.build_filter(file_types)
175         if dialog.ShowDialog() == WinForms.DialogResult.OK:
176             return dialog.FileName
177         else:
178             raise ValueError("No filename provided in the save file dialog")
179 
180     def open_file_dialog(self, title, initial_directory, file_types, multiselect):
181         dialog = WinForms.OpenFileDialog()
182         dialog.Title = title
183         if initial_directory is not None:
184             dialog.InitialDirectory = initial_directory
185         if file_types is not None:
186             dialog.Filter = self.build_filter(file_types)
187         if multiselect:
188             dialog.Multiselect = True
189         if dialog.ShowDialog() == WinForms.DialogResult.OK:
190             return dialog.FileNames if multiselect else dialog.FileName
191         else:
192             raise ValueError("No filename provided in the open file dialog")
193 
194     def select_folder_dialog(self, title, initial_directory, multiselect):
195         dialog = WinForms.FolderBrowserDialog()
196         dialog.Title = title
197         if initial_directory is not None:
198             dialog.InitialDirectory = initial_directory
199 
200         if dialog.ShowDialog() == WinForms.DialogResult.OK:
201             return [dialog.SelectedPath]
202         else:
203             raise ValueError("No folder provided in the select folder dialog")
204 
205     def build_filter(self, file_types):
206         file_string = "{0} files (*.{0})|*.{0}"
207         return '|'.join([file_string.format(ext) for ext in file_types]) + \
208             "|All files (*.*)|*.*"
209
```

Path: `examples/dialogs/dialogs/app.py`
Content:
```
1 import toga
2 from toga.constants import COLUMN
3 from toga.style import Pack
4 
5 
6 class ExampledialogsApp(toga.App):
7     # Button callback functions
8     def do_clear(self, widget, **kwargs):
9         self.label.text = "Ready."
10 
11     def action_info_dialog(self, widget):
12         self.main_window.info_dialog('Toga', 'THIS! IS! TOGA!!')
13         self.label.text = 'Information was provided.'
14 
15     def action_question_dialog(self, widget):
16         if self.main_window.question_dialog('Toga', 'Is this cool or what?'):
17             self.label.text = 'User said yes!'
18             self.main_window.info_dialog('Happiness', 'I know, right! :-)')
19         else:
20             self.label.text = 'User says no...'
21             self.main_window.info_dialog('Shucks...', "Well aren't you a spoilsport... :-(")
22 
23     def action_confirm_dialog(self, widget):
24         if self.main_window.question_dialog('Toga', 'Are you sure you want to?'):
25             self.label.text = 'Lets do it!'
26         else:
27             self.label.text = "Left it as it was."
28 
29     def action_error_dialog(self, widget):
30         self.main_window.error_dialog('Toga', "Well that didn't work... or did it?")
31         self.label.text = 'Oh noes...'
32 
33     def action_open_file_dialog(self, widget):
34         try:
35             fname = self.main_window.open_file_dialog(
36                 title="Open file with Toga",
37                 multiselect=False
38             )
39             if fname is not None:
40                 self.label.text = "File to open:" + fname
41             else:
42                 self.label.text = "No file selected!"
43         except ValueError:
44             self.label.text = "Open file dialog was canceled"
45 
46     def action_open_file_dialog_multi(self, widget):
47         try:
48             filenames = self.main_window.open_file_dialog(
49                 title="Open file with Toga",
50                 multiselect=True
51             )
52             if filenames is not None:
53                 msg = "Files to open: {}".format(', '.join(filenames))
54                 self.label.text = msg
55             else:
56                 self.label.text = "No files selected!"
57 
58         except ValueError:
59             self.label.text = "Open file dialog was canceled"
60 
61     def action_select_folder_dialog(self, widget):
62         try:
63             path_names = self.main_window.select_folder_dialog(
64                 title="Select folder with Toga"
65             )
66             self.label.text = "Folder selected:" + ','.join([path for path in path_names])
67         except ValueError:
68             self.label.text = "Folder select dialog was canceled"
69 
70     def action_select_folder_dialog_multi(self, widget):
71         try:
72             path_names = self.main_window.select_folder_dialog(
73                 title="Select multiple folders with Toga",
74                 multiselect=True
75             )
76             self.label.text = "Folders selected:" + ','.join([path for path in path_names])
77         except ValueError:
78             self.label.text = "Folders select dialog was canceled"
79 
80     def action_save_file_dialog(self, widget):
81         fname = 'Toga_file.txt'
82         try:
83             save_path = self.main_window.save_file_dialog(
84                 "Save file with Toga",
85                 suggested_filename=fname)
86             if save_path is not None:
87                 self.label.text = "File saved with Toga:" + save_path
88             else:
89                 self.label.text = "Save file dialog was canceled"
90         except ValueError:
91             self.label.text = "Save file dialog was canceled"
92 
93     def startup(self):
94         # Set up main window
95         self.main_window = toga.MainWindow(title=self.name)
96 
97         # Label to show responses.
98         self.label = toga.Label('Ready.', style=Pack(padding_top=20))
99 
100         # Buttons
101         btn_style = Pack(flex=1)
102         btn_info = toga.Button('Info', on_press=self.action_info_dialog, style=btn_style)
103         btn_question = toga.Button('Question', on_press=self.action_question_dialog, style=btn_style)
104         btn_confirm = toga.Button('Confirm', on_press=self.action_confirm_dialog, style=btn_style)
105         btn_error = toga.Button('Error', on_press=self.action_error_dialog, style=btn_style)
106         btn_open = toga.Button('Open File', on_press=self.action_open_file_dialog, style=btn_style)
107         btn_open_multi = toga.Button(
108             'Open File (Multiple)',
109             on_press=self.action_open_file_dialog_multi,
110             style=btn_style
111         )
112         btn_save = toga.Button('Save File', on_press=self.action_save_file_dialog, style=btn_style)
113         btn_select = toga.Button('Select Folder', on_press=self.action_select_folder_dialog, style=btn_style)
114         btn_select_multi = toga.Button(
115             'Select Folders',
116             on_press=self.action_select_folder_dialog_multi,
117             style=btn_style
118         )
119 
120         btn_clear = toga.Button('Clear', on_press=self.do_clear, style=btn_style)
121 
122         # Outermost box
123         box = toga.Box(
124             children=[
125                 btn_info,
126                 btn_question,
127                 btn_confirm,
128                 btn_error,
129                 btn_open,
130                 btn_save,
131                 btn_select,
132                 btn_select_multi,
133                 btn_open_multi,
134                 btn_clear,
135                 self.label
136             ],
137             style=Pack(
138                 flex=1,
139                 direction=COLUMN,
140                 padding=10
141             )
142         )
143 
144         # Add the content on the main window
145         self.main_window.content = box
146 
147         # Show the main window
148         self.main_window.show()
149 
150 
151 def main():
152     return ExampledialogsApp('Dialogs', 'org.beeware.widgets.dialogs')
153 
154 
155 if __name__ == '__main__':
156     app = main()
157     app.main_loop()
158
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/examples/dialogs/dialogs/app.py b/examples/dialogs/dialogs/app.py
--- a/examples/dialogs/dialogs/app.py
+++ b/examples/dialogs/dialogs/app.py
@@ -43,6 +43,20 @@
         except ValueError:
             self.label.text = "Open file dialog was canceled"
 
+    def action_open_file_filtered_dialog(self, widget):
+        try:
+            fname = self.main_window.open_file_dialog(
+                title="Open file with Toga",
+                multiselect=False,
+                file_types=['doc', 'txt'],
+            )
+            if fname is not None:
+                self.label.text = "File to open:" + fname
+            else:
+                self.label.text = "No file selected!"
+        except ValueError:
+            self.label.text = "Open file dialog was canceled"
+
     def action_open_file_dialog_multi(self, widget):
         try:
             filenames = self.main_window.open_file_dialog(
@@ -104,6 +118,11 @@
         btn_confirm = toga.Button('Confirm', on_press=self.action_confirm_dialog, style=btn_style)
         btn_error = toga.Button('Error', on_press=self.action_error_dialog, style=btn_style)
         btn_open = toga.Button('Open File', on_press=self.action_open_file_dialog, style=btn_style)
+        btn_open_filtered = toga.Button(
+            'Open File (Filtered)',
+            on_press=self.action_open_file_filtered_dialog,
+            style=btn_style
+        )
         btn_open_multi = toga.Button(
             'Open File (Multiple)',
             on_press=self.action_open_file_dialog_multi,
@@ -127,6 +146,7 @@
                 btn_confirm,
                 btn_error,
                 btn_open,
+                btn_open_filtered,
                 btn_save,
                 btn_select,
                 btn_select_multi,
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
@@ -203,6 +203,18 @@
             raise ValueError("No folder provided in the select folder dialog")
 
     def build_filter(self, file_types):
-        file_string = "{0} files (*.{0})|*.{0}"
-        return '|'.join([file_string.format(ext) for ext in file_types]) + \
-            "|All files (*.*)|*.*"
+        filters = [
+            "{0} files (*.{0})|*.{0}".format(ext)
+            for ext in file_types
+        ] + [
+            "All files (*.*)|*.*"
+        ]
+
+        if len(file_types) > 1:
+            filters.insert(0, "All matching files ({0})|{0}".format(
+                ';'.join([
+                    '*.{0}'.format(ext)
+                    for ext in file_types
+                ])
+            ))
+        return '|'.join(filters)

{"golden_diff": "diff --git a/examples/dialogs/dialogs/app.py b/examples/dialogs/dialogs/app.py\n--- a/examples/dialogs/dialogs/app.py\n+++ b/examples/dialogs/dialogs/app.py\n@@ -43,6 +43,20 @@\n         except ValueError:\n             self.label.text = \"Open file dialog was canceled\"\n \n+    def action_open_file_filtered_dialog(self, widget):\n+        try:\n+            fname = self.main_window.open_file_dialog(\n+                title=\"Open file with Toga\",\n+                multiselect=False,\n+                file_types=['doc', 'txt'],\n+            )\n+            if fname is not None:\n+                self.label.text = \"File to open:\" + fname\n+            else:\n+                self.label.text = \"No file selected!\"\n+        except ValueError:\n+            self.label.text = \"Open file dialog was canceled\"\n+\n     def action_open_file_dialog_multi(self, widget):\n         try:\n             filenames = self.main_window.open_file_dialog(\n@@ -104,6 +118,11 @@\n         btn_confirm = toga.Button('Confirm', on_press=self.action_confirm_dialog, style=btn_style)\n         btn_error = toga.Button('Error', on_press=self.action_error_dialog, style=btn_style)\n         btn_open = toga.Button('Open File', on_press=self.action_open_file_dialog, style=btn_style)\n+        btn_open_filtered = toga.Button(\n+            'Open File (Filtered)',\n+            on_press=self.action_open_file_filtered_dialog,\n+            style=btn_style\n+        )\n         btn_open_multi = toga.Button(\n             'Open File (Multiple)',\n             on_press=self.action_open_file_dialog_multi,\n@@ -127,6 +146,7 @@\n                 btn_confirm,\n                 btn_error,\n                 btn_open,\n+                btn_open_filtered,\n                 btn_save,\n                 btn_select,\n                 btn_select_multi,\ndiff --git a/src/winforms/toga_winforms/window.py b/src/winforms/toga_winforms/window.py\n--- a/src/winforms/toga_winforms/window.py\n+++ b/src/winforms/toga_winforms/window.py\n@@ -203,6 +203,18 @@\n             raise ValueError(\"No folder provided in the select folder dialog\")\n \n     def build_filter(self, file_types):\n-        file_string = \"{0} files (*.{0})|*.{0}\"\n-        return '|'.join([file_string.format(ext) for ext in file_types]) + \\\n-            \"|All files (*.*)|*.*\"\n+        filters = [\n+            \"{0} files (*.{0})|*.{0}\".format(ext)\n+            for ext in file_types\n+        ] + [\n+            \"All files (*.*)|*.*\"\n+        ]\n+\n+        if len(file_types) > 1:\n+            filters.insert(0, \"All matching files ({0})|{0}\".format(\n+                ';'.join([\n+                    '*.{0}'.format(ext)\n+                    for ext in file_types\n+                ])\n+            ))\n+        return '|'.join(filters)\n", "issue": "Asking how to use \"file_types\" in open_file_dialog\nWhen I bookmark a list like the example below\r\n`    def action_open_file_dialog(self, multi_var, widget=None):\r\n            filenames = self.main_window.open_file_dialog(\r\n                title=\"Open file with Toga\",\r\n                multiselect=multi_var,\r\n                file_types=['gif', 'tiff', 'jpeg', 'bmp', 'png', 'webp']\r\n            )`\r\nThe result is a column list, which will prevent the window from displaying all images in the correct format in the list.\r\nHow does the window show all the listed formats, instead of having to select files one by one or All files. Similar to the example in HTML.\r\ninput type=\"file\"\r\n       id=\"avatar\" name=\"avatar\"\r\n       accept=\"image/png, image/jpeg\"\r\nhttps://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file\n", "before_files": [{"content": "from toga import GROUP_BREAK, SECTION_BREAK\n\nfrom .libs import Size, WinForms\n\n\nclass WinFormsViewport:\n    def __init__(self, native, frame):\n        self.native = native\n        self.frame = frame\n        self.baseline_dpi = 96\n\n    @property\n    def width(self):\n        # Treat `native=None` as a 0x0 viewport\n        if self.native is None:\n            return 0\n        return self.native.ClientSize.Width\n\n    @property\n    def height(self):\n        if self.native is None:\n            return 0\n        # Subtract any vertical shift of the frame. This is to allow\n        # for toolbars, or any other viewport-level decoration.\n        return self.native.ClientSize.Height - self.frame.vertical_shift\n\n    @property\n    def dpi(self):\n        if self.native is None:\n            return self.baseline_dpi\n        return self.native.CreateGraphics().DpiX\n\n\nclass Window:\n    def __init__(self, interface):\n        self.interface = interface\n        self.interface._impl = self\n        self.create()\n\n    def create(self):\n        self.native = WinForms.Form(self)\n        self.native.ClientSize = Size(*self.interface._size)\n        self.native.interface = self.interface\n        self.native.Resize += self.winforms_resize\n        self.toolbar_native = None\n        self.toolbar_items = None\n\n    def create_toolbar(self):\n        self.toolbar_native = WinForms.ToolStrip()\n        for cmd in self.interface.toolbar:\n            if cmd == GROUP_BREAK:\n                item = WinForms.ToolStripSeparator()\n            elif cmd == SECTION_BREAK:\n                item = WinForms.ToolStripSeparator()\n            else:\n                if cmd.icon is not None:\n                    native_icon = cmd.icon._impl.native\n                    item = WinForms.ToolStripMenuItem(cmd.label, native_icon.ToBitmap())\n                else:\n                    item = WinForms.ToolStripMenuItem(cmd.label)\n                item.Click += cmd._impl.as_handler()\n                cmd._impl.native.append(item)\n            self.toolbar_native.Items.Add(item)\n\n    def set_position(self, position):\n        pass\n\n    def set_size(self, size):\n        self.native.ClientSize = Size(*self.interface._size)\n\n    def set_app(self, app):\n        if app is None:\n            return\n        icon_impl = app.interface.icon._impl\n        if icon_impl is None:\n            return\n        self.native.Icon = icon_impl.native\n\n    @property\n    def vertical_shift(self):\n        # vertical shift is the toolbar height or 0\n        result = 0\n        try:\n            result += self.native.interface._impl.toolbar_native.Height\n        except AttributeError:\n            pass\n        try:\n            result += self.native.interface._impl.native.MainMenuStrip.Height\n        except AttributeError:\n            pass\n        return result\n\n    def set_content(self, widget):\n        if self.toolbar_native:\n            self.native.Controls.Add(self.toolbar_native)\n            # Create the lookup table of menu items,\n            # then force the creation of the menus.\n        self.native.Controls.Add(widget.native)\n\n        # Set the widget's viewport to be based on the window's content.\n        widget.viewport = WinFormsViewport(native=self.native, frame=self)\n        widget.frame = self\n\n        # Add all children to the content widget.\n        for child in widget.interface.children:\n            child._impl.container = widget\n\n    def set_title(self, title):\n        self.native.Text = title\n\n    def show(self):\n        # The first render of the content will establish the\n        # minimum possible content size; use that to enforce\n        # a minimum window size.\n        TITLEBAR_HEIGHT = WinForms.SystemInformation.CaptionHeight\n        # Now that the content is visible, we can do our initial hinting,\n        # and use that as the basis for setting the minimum window size.\n        self.interface.content._impl.rehint()\n        self.interface.content.style.layout(\n            self.interface.content,\n            WinFormsViewport(native=None, frame=None),\n        )\n        self.native.MinimumSize = Size(\n            int(self.interface.content.layout.width),\n            int(self.interface.content.layout.height) + TITLEBAR_HEIGHT\n        )\n        self.interface.content.refresh()\n\n        self.native.Show()\n\n    def winforms_FormClosing(self, event, handler):\n        if self.interface.app.on_exit:\n            self.interface.app.on_exit(self.interface.app)\n\n    def set_full_screen(self, is_full_screen):\n        self.interface.factory.not_implemented('Window.set_full_screen()')\n\n    def on_close(self):\n        pass\n\n    def close(self):\n        self.native.Close()\n\n    def winforms_resize(self, sender, args):\n        if self.interface.content:\n            # Re-layout the content\n            self.interface.content.refresh()\n\n    def info_dialog(self, title, message):\n        return WinForms.MessageBox.Show(message, title, WinForms.MessageBoxButtons.OK)\n\n    def question_dialog(self, title, message):\n        result = WinForms.MessageBox.Show(message, title, WinForms.MessageBoxButtons.YesNo)\n        return result\n\n    def confirm_dialog(self, title, message):\n        result = WinForms.MessageBox.Show(message, title, WinForms.MessageBoxButtons.OKCancel)\n        # this returns 1 (DialogResult.OK enum) for OK and 2 for Cancel\n        return True if result == WinForms.DialogResult.OK else False\n\n    def error_dialog(self, title, message):\n        return WinForms.MessageBox.Show(message, title, WinForms.MessageBoxButtons.OK,\n                                        WinForms.MessageBoxIcon.Error)\n\n    def stack_trace_dialog(self, title, message, content, retry=False):\n        pass\n\n    def save_file_dialog(self, title, suggested_filename, file_types):\n        dialog = WinForms.SaveFileDialog()\n        dialog.Title = title\n        if suggested_filename is not None:\n            dialog.FileName = suggested_filename\n        if file_types is not None:\n            dialog.Filter = self.build_filter(file_types)\n        if dialog.ShowDialog() == WinForms.DialogResult.OK:\n            return dialog.FileName\n        else:\n            raise ValueError(\"No filename provided in the save file dialog\")\n\n    def open_file_dialog(self, title, initial_directory, file_types, multiselect):\n        dialog = WinForms.OpenFileDialog()\n        dialog.Title = title\n        if initial_directory is not None:\n            dialog.InitialDirectory = initial_directory\n        if file_types is not None:\n            dialog.Filter = self.build_filter(file_types)\n        if multiselect:\n            dialog.Multiselect = True\n        if dialog.ShowDialog() == WinForms.DialogResult.OK:\n            return dialog.FileNames if multiselect else dialog.FileName\n        else:\n            raise ValueError(\"No filename provided in the open file dialog\")\n\n    def select_folder_dialog(self, title, initial_directory, multiselect):\n        dialog = WinForms.FolderBrowserDialog()\n        dialog.Title = title\n        if initial_directory is not None:\n            dialog.InitialDirectory = initial_directory\n\n        if dialog.ShowDialog() == WinForms.DialogResult.OK:\n            return [dialog.SelectedPath]\n        else:\n            raise ValueError(\"No folder provided in the select folder dialog\")\n\n    def build_filter(self, file_types):\n        file_string = \"{0} files (*.{0})|*.{0}\"\n        return '|'.join([file_string.format(ext) for ext in file_types]) + \\\n            \"|All files (*.*)|*.*\"\n", "path": "src/winforms/toga_winforms/window.py"}, {"content": "import toga\nfrom toga.constants import COLUMN\nfrom toga.style import Pack\n\n\nclass ExampledialogsApp(toga.App):\n    # Button callback functions\n    def do_clear(self, widget, **kwargs):\n        self.label.text = \"Ready.\"\n\n    def action_info_dialog(self, widget):\n        self.main_window.info_dialog('Toga', 'THIS! IS! TOGA!!')\n        self.label.text = 'Information was provided.'\n\n    def action_question_dialog(self, widget):\n        if self.main_window.question_dialog('Toga', 'Is this cool or what?'):\n            self.label.text = 'User said yes!'\n            self.main_window.info_dialog('Happiness', 'I know, right! :-)')\n        else:\n            self.label.text = 'User says no...'\n            self.main_window.info_dialog('Shucks...', \"Well aren't you a spoilsport... :-(\")\n\n    def action_confirm_dialog(self, widget):\n        if self.main_window.question_dialog('Toga', 'Are you sure you want to?'):\n            self.label.text = 'Lets do it!'\n        else:\n            self.label.text = \"Left it as it was.\"\n\n    def action_error_dialog(self, widget):\n        self.main_window.error_dialog('Toga', \"Well that didn't work... or did it?\")\n        self.label.text = 'Oh noes...'\n\n    def action_open_file_dialog(self, widget):\n        try:\n            fname = self.main_window.open_file_dialog(\n                title=\"Open file with Toga\",\n                multiselect=False\n            )\n            if fname is not None:\n                self.label.text = \"File to open:\" + fname\n            else:\n                self.label.text = \"No file selected!\"\n        except ValueError:\n            self.label.text = \"Open file dialog was canceled\"\n\n    def action_open_file_dialog_multi(self, widget):\n        try:\n            filenames = self.main_window.open_file_dialog(\n                title=\"Open file with Toga\",\n                multiselect=True\n            )\n            if filenames is not None:\n                msg = \"Files to open: {}\".format(', '.join(filenames))\n                self.label.text = msg\n            else:\n                self.label.text = \"No files selected!\"\n\n        except ValueError:\n            self.label.text = \"Open file dialog was canceled\"\n\n    def action_select_folder_dialog(self, widget):\n        try:\n            path_names = self.main_window.select_folder_dialog(\n                title=\"Select folder with Toga\"\n            )\n            self.label.text = \"Folder selected:\" + ','.join([path for path in path_names])\n        except ValueError:\n            self.label.text = \"Folder select dialog was canceled\"\n\n    def action_select_folder_dialog_multi(self, widget):\n        try:\n            path_names = self.main_window.select_folder_dialog(\n                title=\"Select multiple folders with Toga\",\n                multiselect=True\n            )\n            self.label.text = \"Folders selected:\" + ','.join([path for path in path_names])\n        except ValueError:\n            self.label.text = \"Folders select dialog was canceled\"\n\n    def action_save_file_dialog(self, widget):\n        fname = 'Toga_file.txt'\n        try:\n            save_path = self.main_window.save_file_dialog(\n                \"Save file with Toga\",\n                suggested_filename=fname)\n            if save_path is not None:\n                self.label.text = \"File saved with Toga:\" + save_path\n            else:\n                self.label.text = \"Save file dialog was canceled\"\n        except ValueError:\n            self.label.text = \"Save file dialog was canceled\"\n\n    def startup(self):\n        # Set up main window\n        self.main_window = toga.MainWindow(title=self.name)\n\n        # Label to show responses.\n        self.label = toga.Label('Ready.', style=Pack(padding_top=20))\n\n        # Buttons\n        btn_style = Pack(flex=1)\n        btn_info = toga.Button('Info', on_press=self.action_info_dialog, style=btn_style)\n        btn_question = toga.Button('Question', on_press=self.action_question_dialog, style=btn_style)\n        btn_confirm = toga.Button('Confirm', on_press=self.action_confirm_dialog, style=btn_style)\n        btn_error = toga.Button('Error', on_press=self.action_error_dialog, style=btn_style)\n        btn_open = toga.Button('Open File', on_press=self.action_open_file_dialog, style=btn_style)\n        btn_open_multi = toga.Button(\n            'Open File (Multiple)',\n            on_press=self.action_open_file_dialog_multi,\n            style=btn_style\n        )\n        btn_save = toga.Button('Save File', on_press=self.action_save_file_dialog, style=btn_style)\n        btn_select = toga.Button('Select Folder', on_press=self.action_select_folder_dialog, style=btn_style)\n        btn_select_multi = toga.Button(\n            'Select Folders',\n            on_press=self.action_select_folder_dialog_multi,\n            style=btn_style\n        )\n\n        btn_clear = toga.Button('Clear', on_press=self.do_clear, style=btn_style)\n\n        # Outermost box\n        box = toga.Box(\n            children=[\n                btn_info,\n                btn_question,\n                btn_confirm,\n                btn_error,\n                btn_open,\n                btn_save,\n                btn_select,\n                btn_select_multi,\n                btn_open_multi,\n                btn_clear,\n                self.label\n            ],\n            style=Pack(\n                flex=1,\n                direction=COLUMN,\n                padding=10\n            )\n        )\n\n        # Add the content on the main window\n        self.main_window.content = box\n\n        # Show the main window\n        self.main_window.show()\n\n\ndef main():\n    return ExampledialogsApp('Dialogs', 'org.beeware.widgets.dialogs')\n\n\nif __name__ == '__main__':\n    app = main()\n    app.main_loop()\n", "path": "examples/dialogs/dialogs/app.py"}], "after_files": [{"content": "from toga import GROUP_BREAK, SECTION_BREAK\n\nfrom .libs import Size, WinForms\n\n\nclass WinFormsViewport:\n    def __init__(self, native, frame):\n        self.native = native\n        self.frame = frame\n        self.baseline_dpi = 96\n\n    @property\n    def width(self):\n        # Treat `native=None` as a 0x0 viewport\n        if self.native is None:\n            return 0\n        return self.native.ClientSize.Width\n\n    @property\n    def height(self):\n        if self.native is None:\n            return 0\n        # Subtract any vertical shift of the frame. This is to allow\n        # for toolbars, or any other viewport-level decoration.\n        return self.native.ClientSize.Height - self.frame.vertical_shift\n\n    @property\n    def dpi(self):\n        if self.native is None:\n            return self.baseline_dpi\n        return self.native.CreateGraphics().DpiX\n\n\nclass Window:\n    def __init__(self, interface):\n        self.interface = interface\n        self.interface._impl = self\n        self.create()\n\n    def create(self):\n        self.native = WinForms.Form(self)\n        self.native.ClientSize = Size(*self.interface._size)\n        self.native.interface = self.interface\n        self.native.Resize += self.winforms_resize\n        self.toolbar_native = None\n        self.toolbar_items = None\n\n    def create_toolbar(self):\n        self.toolbar_native = WinForms.ToolStrip()\n        for cmd in self.interface.toolbar:\n            if cmd == GROUP_BREAK:\n                item = WinForms.ToolStripSeparator()\n            elif cmd == SECTION_BREAK:\n                item = WinForms.ToolStripSeparator()\n            else:\n                if cmd.icon is not None:\n                    native_icon = cmd.icon._impl.native\n                    item = WinForms.ToolStripMenuItem(cmd.label, native_icon.ToBitmap())\n                else:\n                    item = WinForms.ToolStripMenuItem(cmd.label)\n                item.Click += cmd._impl.as_handler()\n                cmd._impl.native.append(item)\n            self.toolbar_native.Items.Add(item)\n\n    def set_position(self, position):\n        pass\n\n    def set_size(self, size):\n        self.native.ClientSize = Size(*self.interface._size)\n\n    def set_app(self, app):\n        if app is None:\n            return\n        icon_impl = app.interface.icon._impl\n        if icon_impl is None:\n            return\n        self.native.Icon = icon_impl.native\n\n    @property\n    def vertical_shift(self):\n        # vertical shift is the toolbar height or 0\n        result = 0\n        try:\n            result += self.native.interface._impl.toolbar_native.Height\n        except AttributeError:\n            pass\n        try:\n            result += self.native.interface._impl.native.MainMenuStrip.Height\n        except AttributeError:\n            pass\n        return result\n\n    def set_content(self, widget):\n        if self.toolbar_native:\n            self.native.Controls.Add(self.toolbar_native)\n            # Create the lookup table of menu items,\n            # then force the creation of the menus.\n        self.native.Controls.Add(widget.native)\n\n        # Set the widget's viewport to be based on the window's content.\n        widget.viewport = WinFormsViewport(native=self.native, frame=self)\n        widget.frame = self\n\n        # Add all children to the content widget.\n        for child in widget.interface.children:\n            child._impl.container = widget\n\n    def set_title(self, title):\n        self.native.Text = title\n\n    def show(self):\n        # The first render of the content will establish the\n        # minimum possible content size; use that to enforce\n        # a minimum window size.\n        TITLEBAR_HEIGHT = WinForms.SystemInformation.CaptionHeight\n        # Now that the content is visible, we can do our initial hinting,\n        # and use that as the basis for setting the minimum window size.\n        self.interface.content._impl.rehint()\n        self.interface.content.style.layout(\n            self.interface.content,\n            WinFormsViewport(native=None, frame=None),\n        )\n        self.native.MinimumSize = Size(\n            int(self.interface.content.layout.width),\n            int(self.interface.content.layout.height) + TITLEBAR_HEIGHT\n        )\n        self.interface.content.refresh()\n\n        self.native.Show()\n\n    def winforms_FormClosing(self, event, handler):\n        if self.interface.app.on_exit:\n            self.interface.app.on_exit(self.interface.app)\n\n    def set_full_screen(self, is_full_screen):\n        self.interface.factory.not_implemented('Window.set_full_screen()')\n\n    def on_close(self):\n        pass\n\n    def close(self):\n        self.native.Close()\n\n    def winforms_resize(self, sender, args):\n        if self.interface.content:\n            # Re-layout the content\n            self.interface.content.refresh()\n\n    def info_dialog(self, title, message):\n        return WinForms.MessageBox.Show(message, title, WinForms.MessageBoxButtons.OK)\n\n    def question_dialog(self, title, message):\n        result = WinForms.MessageBox.Show(message, title, WinForms.MessageBoxButtons.YesNo)\n        return result\n\n    def confirm_dialog(self, title, message):\n        result = WinForms.MessageBox.Show(message, title, WinForms.MessageBoxButtons.OKCancel)\n        # this returns 1 (DialogResult.OK enum) for OK and 2 for Cancel\n        return True if result == WinForms.DialogResult.OK else False\n\n    def error_dialog(self, title, message):\n        return WinForms.MessageBox.Show(message, title, WinForms.MessageBoxButtons.OK,\n                                        WinForms.MessageBoxIcon.Error)\n\n    def stack_trace_dialog(self, title, message, content, retry=False):\n        pass\n\n    def save_file_dialog(self, title, suggested_filename, file_types):\n        dialog = WinForms.SaveFileDialog()\n        dialog.Title = title\n        if suggested_filename is not None:\n            dialog.FileName = suggested_filename\n        if file_types is not None:\n            dialog.Filter = self.build_filter(file_types)\n        if dialog.ShowDialog() == WinForms.DialogResult.OK:\n            return dialog.FileName\n        else:\n            raise ValueError(\"No filename provided in the save file dialog\")\n\n    def open_file_dialog(self, title, initial_directory, file_types, multiselect):\n        dialog = WinForms.OpenFileDialog()\n        dialog.Title = title\n        if initial_directory is not None:\n            dialog.InitialDirectory = initial_directory\n        if file_types is not None:\n            dialog.Filter = self.build_filter(file_types)\n        if multiselect:\n            dialog.Multiselect = True\n        if dialog.ShowDialog() == WinForms.DialogResult.OK:\n            return dialog.FileNames if multiselect else dialog.FileName\n        else:\n            raise ValueError(\"No filename provided in the open file dialog\")\n\n    def select_folder_dialog(self, title, initial_directory, multiselect):\n        dialog = WinForms.FolderBrowserDialog()\n        dialog.Title = title\n        if initial_directory is not None:\n            dialog.InitialDirectory = initial_directory\n\n        if dialog.ShowDialog() == WinForms.DialogResult.OK:\n            return [dialog.SelectedPath]\n        else:\n            raise ValueError(\"No folder provided in the select folder dialog\")\n\n    def build_filter(self, file_types):\n        filters = [\n            \"{0} files (*.{0})|*.{0}\".format(ext)\n            for ext in file_types\n        ] + [\n            \"All files (*.*)|*.*\"\n        ]\n\n        if len(file_types) > 1:\n            filters.insert(0, \"All matching files ({0})|{0}\".format(\n                ';'.join([\n                    '*.{0}'.format(ext)\n                    for ext in file_types\n                ])\n            ))\n        return '|'.join(filters)\n", "path": "src/winforms/toga_winforms/window.py"}, {"content": "import toga\nfrom toga.constants import COLUMN\nfrom toga.style import Pack\n\n\nclass ExampledialogsApp(toga.App):\n    # Button callback functions\n    def do_clear(self, widget, **kwargs):\n        self.label.text = \"Ready.\"\n\n    def action_info_dialog(self, widget):\n        self.main_window.info_dialog('Toga', 'THIS! IS! TOGA!!')\n        self.label.text = 'Information was provided.'\n\n    def action_question_dialog(self, widget):\n        if self.main_window.question_dialog('Toga', 'Is this cool or what?'):\n            self.label.text = 'User said yes!'\n            self.main_window.info_dialog('Happiness', 'I know, right! :-)')\n        else:\n            self.label.text = 'User says no...'\n            self.main_window.info_dialog('Shucks...', \"Well aren't you a spoilsport... :-(\")\n\n    def action_confirm_dialog(self, widget):\n        if self.main_window.question_dialog('Toga', 'Are you sure you want to?'):\n            self.label.text = 'Lets do it!'\n        else:\n            self.label.text = \"Left it as it was.\"\n\n    def action_error_dialog(self, widget):\n        self.main_window.error_dialog('Toga', \"Well that didn't work... or did it?\")\n        self.label.text = 'Oh noes...'\n\n    def action_open_file_dialog(self, widget):\n        try:\n            fname = self.main_window.open_file_dialog(\n                title=\"Open file with Toga\",\n                multiselect=False\n            )\n            if fname is not None:\n                self.label.text = \"File to open:\" + fname\n            else:\n                self.label.text = \"No file selected!\"\n        except ValueError:\n            self.label.text = \"Open file dialog was canceled\"\n\n    def action_open_file_filtered_dialog(self, widget):\n        try:\n            fname = self.main_window.open_file_dialog(\n                title=\"Open file with Toga\",\n                multiselect=False,\n                file_types=['doc', 'txt'],\n            )\n            if fname is not None:\n                self.label.text = \"File to open:\" + fname\n            else:\n                self.label.text = \"No file selected!\"\n        except ValueError:\n            self.label.text = \"Open file dialog was canceled\"\n\n    def action_open_file_dialog_multi(self, widget):\n        try:\n            filenames = self.main_window.open_file_dialog(\n                title=\"Open file with Toga\",\n                multiselect=True\n            )\n            if filenames is not None:\n                msg = \"Files to open: {}\".format(', '.join(filenames))\n                self.label.text = msg\n            else:\n                self.label.text = \"No files selected!\"\n\n        except ValueError:\n            self.label.text = \"Open file dialog was canceled\"\n\n    def action_select_folder_dialog(self, widget):\n        try:\n            path_names = self.main_window.select_folder_dialog(\n                title=\"Select folder with Toga\"\n            )\n            self.label.text = \"Folder selected:\" + ','.join([path for path in path_names])\n        except ValueError:\n            self.label.text = \"Folder select dialog was canceled\"\n\n    def action_select_folder_dialog_multi(self, widget):\n        try:\n            path_names = self.main_window.select_folder_dialog(\n                title=\"Select multiple folders with Toga\",\n                multiselect=True\n            )\n            self.label.text = \"Folders selected:\" + ','.join([path for path in path_names])\n        except ValueError:\n            self.label.text = \"Folders select dialog was canceled\"\n\n    def action_save_file_dialog(self, widget):\n        fname = 'Toga_file.txt'\n        try:\n            save_path = self.main_window.save_file_dialog(\n                \"Save file with Toga\",\n                suggested_filename=fname)\n            if save_path is not None:\n                self.label.text = \"File saved with Toga:\" + save_path\n            else:\n                self.label.text = \"Save file dialog was canceled\"\n        except ValueError:\n            self.label.text = \"Save file dialog was canceled\"\n\n    def startup(self):\n        # Set up main window\n        self.main_window = toga.MainWindow(title=self.name)\n\n        # Label to show responses.\n        self.label = toga.Label('Ready.', style=Pack(padding_top=20))\n\n        # Buttons\n        btn_style = Pack(flex=1)\n        btn_info = toga.Button('Info', on_press=self.action_info_dialog, style=btn_style)\n        btn_question = toga.Button('Question', on_press=self.action_question_dialog, style=btn_style)\n        btn_confirm = toga.Button('Confirm', on_press=self.action_confirm_dialog, style=btn_style)\n        btn_error = toga.Button('Error', on_press=self.action_error_dialog, style=btn_style)\n        btn_open = toga.Button('Open File', on_press=self.action_open_file_dialog, style=btn_style)\n        btn_open_filtered = toga.Button(\n            'Open File (Filtered)',\n            on_press=self.action_open_file_filtered_dialog,\n            style=btn_style\n        )\n        btn_open_multi = toga.Button(\n            'Open File (Multiple)',\n            on_press=self.action_open_file_dialog_multi,\n            style=btn_style\n        )\n        btn_save = toga.Button('Save File', on_press=self.action_save_file_dialog, style=btn_style)\n        btn_select = toga.Button('Select Folder', on_press=self.action_select_folder_dialog, style=btn_style)\n        btn_select_multi = toga.Button(\n            'Select Folders',\n            on_press=self.action_select_folder_dialog_multi,\n            style=btn_style\n        )\n\n        btn_clear = toga.Button('Clear', on_press=self.do_clear, style=btn_style)\n\n        # Outermost box\n        box = toga.Box(\n            children=[\n                btn_info,\n                btn_question,\n                btn_confirm,\n                btn_error,\n                btn_open,\n                btn_open_filtered,\n                btn_save,\n                btn_select,\n                btn_select_multi,\n                btn_open_multi,\n                btn_clear,\n                self.label\n            ],\n            style=Pack(\n                flex=1,\n                direction=COLUMN,\n                padding=10\n            )\n        )\n\n        # Add the content on the main window\n        self.main_window.content = box\n\n        # Show the main window\n        self.main_window.show()\n\n\ndef main():\n    return ExampledialogsApp('Dialogs', 'org.beeware.widgets.dialogs')\n\n\nif __name__ == '__main__':\n    app = main()\n    app.main_loop()\n", "path": "examples/dialogs/dialogs/app.py"}]}