We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
On GTK, `App.current_window` returns the last active window even when all windows are hidden
### Describe the bug

On Cocoa and WinForms, it returns `None` in this situation, which I think makes more sense.

### Environment

- Software versions:
  - Toga: main (536a60f)

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `gtk/src/toga_gtk/app.py`
Content:
```
1 import asyncio
2 import signal
3 import sys
4 from pathlib import Path
5 
6 import gbulb
7 
8 import toga
9 from toga import App as toga_App
10 from toga.command import Command, Separator
11 
12 from .keys import gtk_accel
13 from .libs import TOGA_DEFAULT_STYLES, Gdk, Gio, GLib, Gtk
14 from .window import Window
15 
16 
17 class MainWindow(Window):
18     def create(self):
19         self.native = Gtk.ApplicationWindow()
20         self.native.set_role("MainWindow")
21         icon_impl = toga_App.app.icon._impl
22         self.native.set_icon(icon_impl.native_72)
23 
24     def gtk_delete_event(self, *args):
25         # Return value of the GTK on_close handler indicates
26         # whether the event has been fully handled. Returning
27         # False indicates the event handling is *not* complete,
28         # so further event processing (including actually
29         # closing the window) should be performed; so
30         # "should_exit == True" must be converted to a return
31         # value of False.
32         self.interface.app.on_exit()
33         return True
34 
35 
36 class App:
37     """
38     Todo:
39         * Creation of Menus is not working.
40         * Disabling of menu items is not working.
41         * App Icon is not showing up
42     """
43 
44     def __init__(self, interface):
45         self.interface = interface
46         self.interface._impl = self
47 
48         gbulb.install(gtk=True)
49         self.loop = asyncio.new_event_loop()
50 
51         self.create()
52 
53     def create(self):
54         # Stimulate the build of the app
55         self.native = Gtk.Application(
56             application_id=self.interface.app_id,
57             flags=Gio.ApplicationFlags.FLAGS_NONE,
58         )
59         self.native_about_dialog = None
60 
61         # Connect the GTK signal that will cause app startup to occur
62         self.native.connect("startup", self.gtk_startup)
63         self.native.connect("activate", self.gtk_activate)
64 
65         self.actions = None
66 
67     def gtk_startup(self, data=None):
68         # Set up the default commands for the interface.
69         self.interface.commands.add(
70             Command(
71                 self._menu_about,
72                 "About " + self.interface.formal_name,
73                 group=toga.Group.HELP,
74             ),
75             Command(None, "Preferences", group=toga.Group.APP),
76             # Quit should always be the last item, in a section on its own
77             Command(
78                 self._menu_quit,
79                 "Quit " + self.interface.formal_name,
80                 shortcut=toga.Key.MOD_1 + "q",
81                 group=toga.Group.APP,
82                 section=sys.maxsize,
83             ),
84         )
85         self._create_app_commands()
86 
87         self.interface._startup()
88 
89         # Create the lookup table of menu items,
90         # then force the creation of the menus.
91         self.create_menus()
92 
93         # Now that we have menus, make the app take responsibility for
94         # showing the menubar.
95         # This is required because of inconsistencies in how the Gnome
96         # shell operates on different windowing environments;
97         # see #872 for details.
98         settings = Gtk.Settings.get_default()
99         settings.set_property("gtk-shell-shows-menubar", False)
100 
101         # Set any custom styles
102         css_provider = Gtk.CssProvider()
103         css_provider.load_from_data(TOGA_DEFAULT_STYLES)
104 
105         context = Gtk.StyleContext()
106         context.add_provider_for_screen(
107             Gdk.Screen.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER
108         )
109 
110     def _create_app_commands(self):
111         # No extra menus
112         pass
113 
114     def gtk_activate(self, data=None):
115         pass
116 
117     def _menu_about(self, command, **kwargs):
118         self.interface.about()
119 
120     def _menu_quit(self, command, **kwargs):
121         self.interface.on_exit()
122 
123     def create_menus(self):
124         # Only create the menu if the menu item index has been created.
125         self._menu_items = {}
126         self._menu_groups = {}
127 
128         # Create the menu for the top level menubar.
129         menubar = Gio.Menu()
130         section = None
131         for cmd in self.interface.commands:
132             if isinstance(cmd, Separator):
133                 section = None
134             else:
135                 submenu, created = self._submenu(cmd.group, menubar)
136                 if created:
137                     section = None
138 
139                 if section is None:
140                     section = Gio.Menu()
141                     submenu.append_section(None, section)
142 
143                 cmd_id = "command-%s" % id(cmd)
144                 action = Gio.SimpleAction.new(cmd_id, None)
145                 action.connect("activate", cmd._impl.gtk_activate)
146 
147                 cmd._impl.native.append(action)
148                 cmd._impl.set_enabled(cmd.enabled)
149                 self._menu_items[action] = cmd
150                 self.native.add_action(action)
151 
152                 item = Gio.MenuItem.new(cmd.text, "app." + cmd_id)
153                 if cmd.shortcut:
154                     item.set_attribute_value(
155                         "accel", GLib.Variant("s", gtk_accel(cmd.shortcut))
156                     )
157 
158                 section.append_item(item)
159 
160         # Set the menu for the app.
161         self.native.set_menubar(menubar)
162 
163     def _submenu(self, group, menubar):
164         try:
165             return self._menu_groups[group], False
166         except KeyError:
167             if group is None:
168                 submenu = menubar
169             else:
170                 parent_menu, _ = self._submenu(group.parent, menubar)
171                 submenu = Gio.Menu()
172                 self._menu_groups[group] = submenu
173 
174                 text = group.text
175                 if text == "*":
176                     text = self.interface.formal_name
177                 parent_menu.append_submenu(text, submenu)
178 
179             # Install the item in the group cache.
180             self._menu_groups[group] = submenu
181 
182             return submenu, True
183 
184     def main_loop(self):
185         # Modify signal handlers to make sure Ctrl-C is caught and handled.
186         signal.signal(signal.SIGINT, signal.SIG_DFL)
187 
188         self.loop.run_forever(application=self.native)
189 
190     def set_main_window(self, window):
191         pass
192 
193     def show_about_dialog(self):
194         self.native_about_dialog = Gtk.AboutDialog()
195         self.native_about_dialog.set_modal(True)
196 
197         icon_impl = toga_App.app.icon._impl
198         self.native_about_dialog.set_logo(icon_impl.native_72)
199 
200         self.native_about_dialog.set_program_name(self.interface.formal_name)
201         if self.interface.version is not None:
202             self.native_about_dialog.set_version(self.interface.version)
203         if self.interface.author is not None:
204             self.native_about_dialog.set_authors([self.interface.author])
205         if self.interface.description is not None:
206             self.native_about_dialog.set_comments(self.interface.description)
207         if self.interface.home_page is not None:
208             self.native_about_dialog.set_website(self.interface.home_page)
209 
210         self.native_about_dialog.show()
211         self.native_about_dialog.connect("close", self._close_about)
212 
213     def _close_about(self, dialog):
214         self.native_about_dialog.destroy()
215         self.native_about_dialog = None
216 
217     def beep(self):
218         Gdk.beep()
219 
220     # We can't call this under test conditions, because it would kill the test harness
221     def exit(self):  # pragma: no cover
222         self.native.quit()
223 
224     def get_current_window(self):
225         return self.native.get_active_window()._impl
226 
227     def set_current_window(self, window):
228         window._impl.native.present()
229 
230     def enter_full_screen(self, windows):
231         for window in windows:
232             window._impl.set_full_screen(True)
233 
234     def exit_full_screen(self, windows):
235         for window in windows:
236             window._impl.set_full_screen(False)
237 
238     def show_cursor(self):
239         self.interface.factory.not_implemented("App.show_cursor()")
240 
241     def hide_cursor(self):
242         self.interface.factory.not_implemented("App.hide_cursor()")
243 
244 
245 class DocumentApp(App):  # pragma: no cover
246     def _create_app_commands(self):
247         self.interface.commands.add(
248             toga.Command(
249                 self.open_file,
250                 text="Open...",
251                 shortcut=toga.Key.MOD_1 + "o",
252                 group=toga.Group.FILE,
253                 section=0,
254             ),
255         )
256 
257     def gtk_startup(self, data=None):
258         super().gtk_startup(data=data)
259 
260         try:
261             # Look for a filename specified on the command line
262             self.interface._open(Path(sys.argv[1]))
263         except IndexError:
264             # Nothing on the command line; open a file dialog instead.
265             # Create a temporary window so we have context for the dialog
266             m = toga.Window()
267             m.open_file_dialog(
268                 self.interface.formal_name,
269                 file_types=self.interface.document_types.keys(),
270                 on_result=lambda dialog, path: self.interface._open(path)
271                 if path
272                 else self.exit(),
273             )
274 
275     def open_file(self, widget, **kwargs):
276         # Create a temporary window so we have context for the dialog
277         m = toga.Window()
278         m.open_file_dialog(
279             self.interface.formal_name,
280             file_types=self.interface.document_types.keys(),
281             on_result=lambda dialog, path: self.interface._open(path) if path else None,
282         )
283
```
--- 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/gtk/src/toga_gtk/app.py b/gtk/src/toga_gtk/app.py
--- a/gtk/src/toga_gtk/app.py
+++ b/gtk/src/toga_gtk/app.py
@@ -222,7 +222,8 @@
         self.native.quit()
 
     def get_current_window(self):
-        return self.native.get_active_window()._impl
+        current_window = self.native.get_active_window()._impl
+        return current_window if current_window.interface.visible else None
 
     def set_current_window(self, window):
         window._impl.native.present()

{"golden_diff": "diff --git a/gtk/src/toga_gtk/app.py b/gtk/src/toga_gtk/app.py\n--- a/gtk/src/toga_gtk/app.py\n+++ b/gtk/src/toga_gtk/app.py\n@@ -222,7 +222,8 @@\n         self.native.quit()\n \n     def get_current_window(self):\n-        return self.native.get_active_window()._impl\n+        current_window = self.native.get_active_window()._impl\n+        return current_window if current_window.interface.visible else None\n \n     def set_current_window(self, window):\n         window._impl.native.present()\n", "issue": "On GTK, `App.current_window` returns the last active window even when all windows are hidden\n### Describe the bug\r\n\r\nOn Cocoa and WinForms, it returns `None` in this situation, which I think makes more sense.\r\n\r\n### Environment\r\n\r\n- Software versions:\r\n  - Toga: main (536a60f)\n", "before_files": [{"content": "import asyncio\nimport signal\nimport sys\nfrom pathlib import Path\n\nimport gbulb\n\nimport toga\nfrom toga import App as toga_App\nfrom toga.command import Command, Separator\n\nfrom .keys import gtk_accel\nfrom .libs import TOGA_DEFAULT_STYLES, Gdk, Gio, GLib, Gtk\nfrom .window import Window\n\n\nclass MainWindow(Window):\n    def create(self):\n        self.native = Gtk.ApplicationWindow()\n        self.native.set_role(\"MainWindow\")\n        icon_impl = toga_App.app.icon._impl\n        self.native.set_icon(icon_impl.native_72)\n\n    def gtk_delete_event(self, *args):\n        # Return value of the GTK on_close handler indicates\n        # whether the event has been fully handled. Returning\n        # False indicates the event handling is *not* complete,\n        # so further event processing (including actually\n        # closing the window) should be performed; so\n        # \"should_exit == True\" must be converted to a return\n        # value of False.\n        self.interface.app.on_exit()\n        return True\n\n\nclass App:\n    \"\"\"\n    Todo:\n        * Creation of Menus is not working.\n        * Disabling of menu items is not working.\n        * App Icon is not showing up\n    \"\"\"\n\n    def __init__(self, interface):\n        self.interface = interface\n        self.interface._impl = self\n\n        gbulb.install(gtk=True)\n        self.loop = asyncio.new_event_loop()\n\n        self.create()\n\n    def create(self):\n        # Stimulate the build of the app\n        self.native = Gtk.Application(\n            application_id=self.interface.app_id,\n            flags=Gio.ApplicationFlags.FLAGS_NONE,\n        )\n        self.native_about_dialog = None\n\n        # Connect the GTK signal that will cause app startup to occur\n        self.native.connect(\"startup\", self.gtk_startup)\n        self.native.connect(\"activate\", self.gtk_activate)\n\n        self.actions = None\n\n    def gtk_startup(self, data=None):\n        # Set up the default commands for the interface.\n        self.interface.commands.add(\n            Command(\n                self._menu_about,\n                \"About \" + self.interface.formal_name,\n                group=toga.Group.HELP,\n            ),\n            Command(None, \"Preferences\", group=toga.Group.APP),\n            # Quit should always be the last item, in a section on its own\n            Command(\n                self._menu_quit,\n                \"Quit \" + self.interface.formal_name,\n                shortcut=toga.Key.MOD_1 + \"q\",\n                group=toga.Group.APP,\n                section=sys.maxsize,\n            ),\n        )\n        self._create_app_commands()\n\n        self.interface._startup()\n\n        # Create the lookup table of menu items,\n        # then force the creation of the menus.\n        self.create_menus()\n\n        # Now that we have menus, make the app take responsibility for\n        # showing the menubar.\n        # This is required because of inconsistencies in how the Gnome\n        # shell operates on different windowing environments;\n        # see #872 for details.\n        settings = Gtk.Settings.get_default()\n        settings.set_property(\"gtk-shell-shows-menubar\", False)\n\n        # Set any custom styles\n        css_provider = Gtk.CssProvider()\n        css_provider.load_from_data(TOGA_DEFAULT_STYLES)\n\n        context = Gtk.StyleContext()\n        context.add_provider_for_screen(\n            Gdk.Screen.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER\n        )\n\n    def _create_app_commands(self):\n        # No extra menus\n        pass\n\n    def gtk_activate(self, data=None):\n        pass\n\n    def _menu_about(self, command, **kwargs):\n        self.interface.about()\n\n    def _menu_quit(self, command, **kwargs):\n        self.interface.on_exit()\n\n    def create_menus(self):\n        # Only create the menu if the menu item index has been created.\n        self._menu_items = {}\n        self._menu_groups = {}\n\n        # Create the menu for the top level menubar.\n        menubar = Gio.Menu()\n        section = None\n        for cmd in self.interface.commands:\n            if isinstance(cmd, Separator):\n                section = None\n            else:\n                submenu, created = self._submenu(cmd.group, menubar)\n                if created:\n                    section = None\n\n                if section is None:\n                    section = Gio.Menu()\n                    submenu.append_section(None, section)\n\n                cmd_id = \"command-%s\" % id(cmd)\n                action = Gio.SimpleAction.new(cmd_id, None)\n                action.connect(\"activate\", cmd._impl.gtk_activate)\n\n                cmd._impl.native.append(action)\n                cmd._impl.set_enabled(cmd.enabled)\n                self._menu_items[action] = cmd\n                self.native.add_action(action)\n\n                item = Gio.MenuItem.new(cmd.text, \"app.\" + cmd_id)\n                if cmd.shortcut:\n                    item.set_attribute_value(\n                        \"accel\", GLib.Variant(\"s\", gtk_accel(cmd.shortcut))\n                    )\n\n                section.append_item(item)\n\n        # Set the menu for the app.\n        self.native.set_menubar(menubar)\n\n    def _submenu(self, group, menubar):\n        try:\n            return self._menu_groups[group], False\n        except KeyError:\n            if group is None:\n                submenu = menubar\n            else:\n                parent_menu, _ = self._submenu(group.parent, menubar)\n                submenu = Gio.Menu()\n                self._menu_groups[group] = submenu\n\n                text = group.text\n                if text == \"*\":\n                    text = self.interface.formal_name\n                parent_menu.append_submenu(text, submenu)\n\n            # Install the item in the group cache.\n            self._menu_groups[group] = submenu\n\n            return submenu, True\n\n    def main_loop(self):\n        # Modify signal handlers to make sure Ctrl-C is caught and handled.\n        signal.signal(signal.SIGINT, signal.SIG_DFL)\n\n        self.loop.run_forever(application=self.native)\n\n    def set_main_window(self, window):\n        pass\n\n    def show_about_dialog(self):\n        self.native_about_dialog = Gtk.AboutDialog()\n        self.native_about_dialog.set_modal(True)\n\n        icon_impl = toga_App.app.icon._impl\n        self.native_about_dialog.set_logo(icon_impl.native_72)\n\n        self.native_about_dialog.set_program_name(self.interface.formal_name)\n        if self.interface.version is not None:\n            self.native_about_dialog.set_version(self.interface.version)\n        if self.interface.author is not None:\n            self.native_about_dialog.set_authors([self.interface.author])\n        if self.interface.description is not None:\n            self.native_about_dialog.set_comments(self.interface.description)\n        if self.interface.home_page is not None:\n            self.native_about_dialog.set_website(self.interface.home_page)\n\n        self.native_about_dialog.show()\n        self.native_about_dialog.connect(\"close\", self._close_about)\n\n    def _close_about(self, dialog):\n        self.native_about_dialog.destroy()\n        self.native_about_dialog = None\n\n    def beep(self):\n        Gdk.beep()\n\n    # We can't call this under test conditions, because it would kill the test harness\n    def exit(self):  # pragma: no cover\n        self.native.quit()\n\n    def get_current_window(self):\n        return self.native.get_active_window()._impl\n\n    def set_current_window(self, window):\n        window._impl.native.present()\n\n    def enter_full_screen(self, windows):\n        for window in windows:\n            window._impl.set_full_screen(True)\n\n    def exit_full_screen(self, windows):\n        for window in windows:\n            window._impl.set_full_screen(False)\n\n    def show_cursor(self):\n        self.interface.factory.not_implemented(\"App.show_cursor()\")\n\n    def hide_cursor(self):\n        self.interface.factory.not_implemented(\"App.hide_cursor()\")\n\n\nclass DocumentApp(App):  # pragma: no cover\n    def _create_app_commands(self):\n        self.interface.commands.add(\n            toga.Command(\n                self.open_file,\n                text=\"Open...\",\n                shortcut=toga.Key.MOD_1 + \"o\",\n                group=toga.Group.FILE,\n                section=0,\n            ),\n        )\n\n    def gtk_startup(self, data=None):\n        super().gtk_startup(data=data)\n\n        try:\n            # Look for a filename specified on the command line\n            self.interface._open(Path(sys.argv[1]))\n        except IndexError:\n            # Nothing on the command line; open a file dialog instead.\n            # Create a temporary window so we have context for the dialog\n            m = toga.Window()\n            m.open_file_dialog(\n                self.interface.formal_name,\n                file_types=self.interface.document_types.keys(),\n                on_result=lambda dialog, path: self.interface._open(path)\n                if path\n                else self.exit(),\n            )\n\n    def open_file(self, widget, **kwargs):\n        # Create a temporary window so we have context for the dialog\n        m = toga.Window()\n        m.open_file_dialog(\n            self.interface.formal_name,\n            file_types=self.interface.document_types.keys(),\n            on_result=lambda dialog, path: self.interface._open(path) if path else None,\n        )\n", "path": "gtk/src/toga_gtk/app.py"}], "after_files": [{"content": "import asyncio\nimport signal\nimport sys\nfrom pathlib import Path\n\nimport gbulb\n\nimport toga\nfrom toga import App as toga_App\nfrom toga.command import Command, Separator\n\nfrom .keys import gtk_accel\nfrom .libs import TOGA_DEFAULT_STYLES, Gdk, Gio, GLib, Gtk\nfrom .window import Window\n\n\nclass MainWindow(Window):\n    def create(self):\n        self.native = Gtk.ApplicationWindow()\n        self.native.set_role(\"MainWindow\")\n        icon_impl = toga_App.app.icon._impl\n        self.native.set_icon(icon_impl.native_72)\n\n    def gtk_delete_event(self, *args):\n        # Return value of the GTK on_close handler indicates\n        # whether the event has been fully handled. Returning\n        # False indicates the event handling is *not* complete,\n        # so further event processing (including actually\n        # closing the window) should be performed; so\n        # \"should_exit == True\" must be converted to a return\n        # value of False.\n        self.interface.app.on_exit()\n        return True\n\n\nclass App:\n    \"\"\"\n    Todo:\n        * Creation of Menus is not working.\n        * Disabling of menu items is not working.\n        * App Icon is not showing up\n    \"\"\"\n\n    def __init__(self, interface):\n        self.interface = interface\n        self.interface._impl = self\n\n        gbulb.install(gtk=True)\n        self.loop = asyncio.new_event_loop()\n\n        self.create()\n\n    def create(self):\n        # Stimulate the build of the app\n        self.native = Gtk.Application(\n            application_id=self.interface.app_id,\n            flags=Gio.ApplicationFlags.FLAGS_NONE,\n        )\n        self.native_about_dialog = None\n\n        # Connect the GTK signal that will cause app startup to occur\n        self.native.connect(\"startup\", self.gtk_startup)\n        self.native.connect(\"activate\", self.gtk_activate)\n\n        self.actions = None\n\n    def gtk_startup(self, data=None):\n        # Set up the default commands for the interface.\n        self.interface.commands.add(\n            Command(\n                self._menu_about,\n                \"About \" + self.interface.formal_name,\n                group=toga.Group.HELP,\n            ),\n            Command(None, \"Preferences\", group=toga.Group.APP),\n            # Quit should always be the last item, in a section on its own\n            Command(\n                self._menu_quit,\n                \"Quit \" + self.interface.formal_name,\n                shortcut=toga.Key.MOD_1 + \"q\",\n                group=toga.Group.APP,\n                section=sys.maxsize,\n            ),\n        )\n        self._create_app_commands()\n\n        self.interface._startup()\n\n        # Create the lookup table of menu items,\n        # then force the creation of the menus.\n        self.create_menus()\n\n        # Now that we have menus, make the app take responsibility for\n        # showing the menubar.\n        # This is required because of inconsistencies in how the Gnome\n        # shell operates on different windowing environments;\n        # see #872 for details.\n        settings = Gtk.Settings.get_default()\n        settings.set_property(\"gtk-shell-shows-menubar\", False)\n\n        # Set any custom styles\n        css_provider = Gtk.CssProvider()\n        css_provider.load_from_data(TOGA_DEFAULT_STYLES)\n\n        context = Gtk.StyleContext()\n        context.add_provider_for_screen(\n            Gdk.Screen.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER\n        )\n\n    def _create_app_commands(self):\n        # No extra menus\n        pass\n\n    def gtk_activate(self, data=None):\n        pass\n\n    def _menu_about(self, command, **kwargs):\n        self.interface.about()\n\n    def _menu_quit(self, command, **kwargs):\n        self.interface.on_exit()\n\n    def create_menus(self):\n        # Only create the menu if the menu item index has been created.\n        self._menu_items = {}\n        self._menu_groups = {}\n\n        # Create the menu for the top level menubar.\n        menubar = Gio.Menu()\n        section = None\n        for cmd in self.interface.commands:\n            if isinstance(cmd, Separator):\n                section = None\n            else:\n                submenu, created = self._submenu(cmd.group, menubar)\n                if created:\n                    section = None\n\n                if section is None:\n                    section = Gio.Menu()\n                    submenu.append_section(None, section)\n\n                cmd_id = \"command-%s\" % id(cmd)\n                action = Gio.SimpleAction.new(cmd_id, None)\n                action.connect(\"activate\", cmd._impl.gtk_activate)\n\n                cmd._impl.native.append(action)\n                cmd._impl.set_enabled(cmd.enabled)\n                self._menu_items[action] = cmd\n                self.native.add_action(action)\n\n                item = Gio.MenuItem.new(cmd.text, \"app.\" + cmd_id)\n                if cmd.shortcut:\n                    item.set_attribute_value(\n                        \"accel\", GLib.Variant(\"s\", gtk_accel(cmd.shortcut))\n                    )\n\n                section.append_item(item)\n\n        # Set the menu for the app.\n        self.native.set_menubar(menubar)\n\n    def _submenu(self, group, menubar):\n        try:\n            return self._menu_groups[group], False\n        except KeyError:\n            if group is None:\n                submenu = menubar\n            else:\n                parent_menu, _ = self._submenu(group.parent, menubar)\n                submenu = Gio.Menu()\n                self._menu_groups[group] = submenu\n\n                text = group.text\n                if text == \"*\":\n                    text = self.interface.formal_name\n                parent_menu.append_submenu(text, submenu)\n\n            # Install the item in the group cache.\n            self._menu_groups[group] = submenu\n\n            return submenu, True\n\n    def main_loop(self):\n        # Modify signal handlers to make sure Ctrl-C is caught and handled.\n        signal.signal(signal.SIGINT, signal.SIG_DFL)\n\n        self.loop.run_forever(application=self.native)\n\n    def set_main_window(self, window):\n        pass\n\n    def show_about_dialog(self):\n        self.native_about_dialog = Gtk.AboutDialog()\n        self.native_about_dialog.set_modal(True)\n\n        icon_impl = toga_App.app.icon._impl\n        self.native_about_dialog.set_logo(icon_impl.native_72)\n\n        self.native_about_dialog.set_program_name(self.interface.formal_name)\n        if self.interface.version is not None:\n            self.native_about_dialog.set_version(self.interface.version)\n        if self.interface.author is not None:\n            self.native_about_dialog.set_authors([self.interface.author])\n        if self.interface.description is not None:\n            self.native_about_dialog.set_comments(self.interface.description)\n        if self.interface.home_page is not None:\n            self.native_about_dialog.set_website(self.interface.home_page)\n\n        self.native_about_dialog.show()\n        self.native_about_dialog.connect(\"close\", self._close_about)\n\n    def _close_about(self, dialog):\n        self.native_about_dialog.destroy()\n        self.native_about_dialog = None\n\n    def beep(self):\n        Gdk.beep()\n\n    # We can't call this under test conditions, because it would kill the test harness\n    def exit(self):  # pragma: no cover\n        self.native.quit()\n\n    def get_current_window(self):\n        current_window = self.native.get_active_window()._impl\n        return current_window if current_window.interface.visible else None\n\n    def set_current_window(self, window):\n        window._impl.native.present()\n\n    def enter_full_screen(self, windows):\n        for window in windows:\n            window._impl.set_full_screen(True)\n\n    def exit_full_screen(self, windows):\n        for window in windows:\n            window._impl.set_full_screen(False)\n\n    def show_cursor(self):\n        self.interface.factory.not_implemented(\"App.show_cursor()\")\n\n    def hide_cursor(self):\n        self.interface.factory.not_implemented(\"App.hide_cursor()\")\n\n\nclass DocumentApp(App):  # pragma: no cover\n    def _create_app_commands(self):\n        self.interface.commands.add(\n            toga.Command(\n                self.open_file,\n                text=\"Open...\",\n                shortcut=toga.Key.MOD_1 + \"o\",\n                group=toga.Group.FILE,\n                section=0,\n            ),\n        )\n\n    def gtk_startup(self, data=None):\n        super().gtk_startup(data=data)\n\n        try:\n            # Look for a filename specified on the command line\n            self.interface._open(Path(sys.argv[1]))\n        except IndexError:\n            # Nothing on the command line; open a file dialog instead.\n            # Create a temporary window so we have context for the dialog\n            m = toga.Window()\n            m.open_file_dialog(\n                self.interface.formal_name,\n                file_types=self.interface.document_types.keys(),\n                on_result=lambda dialog, path: self.interface._open(path)\n                if path\n                else self.exit(),\n            )\n\n    def open_file(self, widget, **kwargs):\n        # Create a temporary window so we have context for the dialog\n        m = toga.Window()\n        m.open_file_dialog(\n            self.interface.formal_name,\n            file_types=self.interface.document_types.keys(),\n            on_result=lambda dialog, path: self.interface._open(path) if path else None,\n        )\n", "path": "gtk/src/toga_gtk/app.py"}]}