prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Windows seg fault when defaultView set to Runner
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `psychopy/app/pavlovia_ui/menu.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 # -*- coding: utf-8 -*-
  3 
  4 # Part of the PsychoPy library
  5 # Copyright (C) 2002-2018 Jonathan Peirce (C) 2019-2021 Open Science Tools Ltd.
  6 # Distributed under the terms of the GNU General Public License (GPL).
  7 
  8 import wx
  9 import requests
  10 
  11 from psychopy import logging
  12 from .. import dialogs
  13 from .functions import logInPavlovia
  14 from psychopy.app.pavlovia_ui.project import syncProject
  15 from .search import SearchFrame
  16 from .project import ProjectEditor
  17 from psychopy.localization import _translate
  18 from psychopy.projects import pavlovia
  19 
  20 
  21 class PavloviaMenu(wx.Menu):
  22     app = None
  23     appData = None
  24     currentUser = None
  25     knownUsers = None
  26     searchDlg = None
  27 
  28     def __init__(self, parent):
  29         wx.Menu.__init__(self)
  30         self.parent = parent  # type: BuilderFrame
  31         PavloviaMenu.app = parent.app
  32         keys = self.app.keys
  33         # from prefs fetch info about prev usernames and projects
  34         PavloviaMenu.appData = self.app.prefs.appData['projects']
  35 
  36         # item = self.Append(wx.ID_ANY, _translate("Tell me more..."))
  37         # parent.Bind(wx.EVT_MENU, self.onAbout, id=item.GetId())
  38 
  39         PavloviaMenu.knownUsers = pavlovia.knownUsers
  40 
  41         # sub-menu for usernames and login
  42         self.userMenu = wx.Menu()
  43         # if a user was previously logged in then set them as current
  44         lastPavUser = PavloviaMenu.appData['pavloviaUser']
  45         if pavlovia.knownUsers and (lastPavUser not in pavlovia.knownUsers):
  46             lastPavUser = None
  47         # if lastPavUser and not PavloviaMenu.currentUser:
  48         #     self.setUser(PavloviaMenu.appData['pavloviaUser'])
  49         for name in self.knownUsers:
  50             self.addToSubMenu(name, self.userMenu, self.onSetUser)
  51         self.userMenu.AppendSeparator()
  52         self.loginBtn = self.userMenu.Append(wx.ID_ANY,
  53                                     _translate("Log in to Pavlovia...\t{}")
  54                                     .format(keys['pavlovia_logIn']))
  55         parent.Bind(wx.EVT_MENU, self.onLogInPavlovia, id=self.loginBtn.GetId())
  56         self.AppendSubMenu(self.userMenu, _translate("User"))
  57 
  58         # search
  59         self.searchBtn = self.Append(wx.ID_ANY,
  60                            _translate("Search Pavlovia\t{}")
  61                            .format(keys['projectsFind']))
  62         parent.Bind(wx.EVT_MENU, self.onSearch, id=self.searchBtn.GetId())
  63 
  64         # new
  65         self.newBtn = self.Append(wx.ID_ANY,
  66                            _translate("New...\t{}").format(keys['projectsNew']))
  67         parent.Bind(wx.EVT_MENU, self.onNew, id=self.newBtn.GetId())
  68 
  69         self.syncBtn = self.Append(wx.ID_ANY,
  70                            _translate("Sync\t{}").format(keys['projectsSync']))
  71         parent.Bind(wx.EVT_MENU, self.onSync, id=self.syncBtn.GetId())
  72 
  73     def addToSubMenu(self, name, menu, function):
  74         item = menu.Append(wx.ID_ANY, name)
  75         self.parent.Bind(wx.EVT_MENU, function, id=item.GetId())
  76 
  77     def onAbout(self, event):
  78         wx.GetApp().followLink(event)
  79 
  80     def onSetUser(self, event):
  81         user = self.userMenu.GetLabelText(event.GetId())
  82         self.setUser(user)
  83 
  84     def setUser(self, user=None):
  85 
  86         if user is None and PavloviaMenu.appData['pavloviaUser']:
  87             user = PavloviaMenu.appData['pavloviaUser']
  88 
  89         if user in [PavloviaMenu.currentUser, None]:
  90             return  # nothing to do here. Move along please.
  91 
  92         PavloviaMenu.currentUser = user
  93         PavloviaMenu.appData['pavloviaUser'] = user
  94         if user in pavlovia.knownUsers:
  95             token = pavlovia.knownUsers[user]['token']
  96             try:
  97                 pavlovia.getCurrentSession().setToken(token)
  98             except requests.exceptions.ConnectionError:
  99                 logging.warning("Tried to log in to Pavlovia but no network "
  100                                 "connection")
  101                 return
  102         else:
  103             if hasattr(self, 'onLogInPavlovia'):
  104                 self.onLogInPavlovia()
  105 
  106         if PavloviaMenu.searchDlg:
  107             PavloviaMenu.searchDlg.updateUserProjs()
  108 
  109     def onSync(self, event):
  110         retVal = syncProject(parent=self.parent, project=self.parent.project)
  111         if hasattr(self.parent, 'gitFeedback'):
  112             self.parent.gitFeedback(retVal)
  113 
  114     def onSearch(self, event):
  115         PavloviaMenu.searchDlg = SearchFrame(app=self.parent.app)
  116         PavloviaMenu.searchDlg.Show()
  117 
  118     def onLogInPavlovia(self, event=None):
  119         logInPavlovia(parent=self.parent)
  120 
  121     def onNew(self, event):
  122         """Create a new project
  123         """
  124         if pavlovia.getCurrentSession().user.username:
  125             projEditor = ProjectEditor()
  126             if projEditor.ShowModal() == wx.ID_OK:
  127                 self.parent.project = projEditor.project
  128                 # do a first sync as well
  129                 retVal = syncProject(parent=self.parent, project=projEditor.project)
  130                 self.parent.gitFeedback(retVal)
  131         else:
  132             infoDlg = dialogs.MessageDialog(parent=None, type='Info',
  133                                             message=_translate(
  134                                                     "You need to log in"
  135                                                     " to create a project"))
  136             infoDlg.Show()
  137
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/psychopy/app/pavlovia_ui/menu.py b/psychopy/app/pavlovia_ui/menu.py
  --- a/psychopy/app/pavlovia_ui/menu.py
  +++ b/psychopy/app/pavlovia_ui/menu.py
  @@ -82,9 +82,9 @@
           self.setUser(user)
   
       def setUser(self, user=None):
  -
  -        if user is None and PavloviaMenu.appData['pavloviaUser']:
  -            user = PavloviaMenu.appData['pavloviaUser']
  +        if PavloviaMenu.appData:
  +            if user is None and PavloviaMenu.appData['pavloviaUser']:
  +                user = PavloviaMenu.appData['pavloviaUser']
   
           if user in [PavloviaMenu.currentUser, None]:
               return  # nothing to do here. Move along please.
  
verification_info: {"golden_diff": "diff --git a/psychopy/app/pavlovia_ui/menu.py b/psychopy/app/pavlovia_ui/menu.py\n--- a/psychopy/app/pavlovia_ui/menu.py\n+++ b/psychopy/app/pavlovia_ui/menu.py\n@@ -82,9 +82,9 @@\n         self.setUser(user)\n \n     def setUser(self, user=None):\n-\n-        if user is None and PavloviaMenu.appData['pavloviaUser']:\n-            user = PavloviaMenu.appData['pavloviaUser']\n+        if PavloviaMenu.appData:\n+            if user is None and PavloviaMenu.appData['pavloviaUser']:\n+                user = PavloviaMenu.appData['pavloviaUser']\n \n         if user in [PavloviaMenu.currentUser, None]:\n             return  # nothing to do here. Move along please.\n", "issue": "Windows seg fault when defaultView set to Runner\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\n# Part of the PsychoPy library\n# Copyright (C) 2002-2018 Jonathan Peirce (C) 2019-2021 Open Science Tools Ltd.\n# Distributed under the terms of the GNU General Public License (GPL).\n\nimport wx\nimport requests\n\nfrom psychopy import logging\nfrom .. import dialogs\nfrom .functions import logInPavlovia\nfrom psychopy.app.pavlovia_ui.project import syncProject\nfrom .search import SearchFrame\nfrom .project import ProjectEditor\nfrom psychopy.localization import _translate\nfrom psychopy.projects import pavlovia\n\n\nclass PavloviaMenu(wx.Menu):\n    app = None\n    appData = None\n    currentUser = None\n    knownUsers = None\n    searchDlg = None\n\n    def __init__(self, parent):\n        wx.Menu.__init__(self)\n        self.parent = parent  # type: BuilderFrame\n        PavloviaMenu.app = parent.app\n        keys = self.app.keys\n        # from prefs fetch info about prev usernames and projects\n        PavloviaMenu.appData = self.app.prefs.appData['projects']\n\n        # item = self.Append(wx.ID_ANY, _translate(\"Tell me more...\"))\n        # parent.Bind(wx.EVT_MENU, self.onAbout, id=item.GetId())\n\n        PavloviaMenu.knownUsers = pavlovia.knownUsers\n\n        # sub-menu for usernames and login\n        self.userMenu = wx.Menu()\n        # if a user was previously logged in then set them as current\n        lastPavUser = PavloviaMenu.appData['pavloviaUser']\n        if pavlovia.knownUsers and (lastPavUser not in pavlovia.knownUsers):\n            lastPavUser = None\n        # if lastPavUser and not PavloviaMenu.currentUser:\n        #     self.setUser(PavloviaMenu.appData['pavloviaUser'])\n        for name in self.knownUsers:\n            self.addToSubMenu(name, self.userMenu, self.onSetUser)\n        self.userMenu.AppendSeparator()\n        self.loginBtn = self.userMenu.Append(wx.ID_ANY,\n                                    _translate(\"Log in to Pavlovia...\\t{}\")\n                                    .format(keys['pavlovia_logIn']))\n        parent.Bind(wx.EVT_MENU, self.onLogInPavlovia, id=self.loginBtn.GetId())\n        self.AppendSubMenu(self.userMenu, _translate(\"User\"))\n\n        # search\n        self.searchBtn = self.Append(wx.ID_ANY,\n                           _translate(\"Search Pavlovia\\t{}\")\n                           .format(keys['projectsFind']))\n        parent.Bind(wx.EVT_MENU, self.onSearch, id=self.searchBtn.GetId())\n\n        # new\n        self.newBtn = self.Append(wx.ID_ANY,\n                           _translate(\"New...\\t{}\").format(keys['projectsNew']))\n        parent.Bind(wx.EVT_MENU, self.onNew, id=self.newBtn.GetId())\n\n        self.syncBtn = self.Append(wx.ID_ANY,\n                           _translate(\"Sync\\t{}\").format(keys['projectsSync']))\n        parent.Bind(wx.EVT_MENU, self.onSync, id=self.syncBtn.GetId())\n\n    def addToSubMenu(self, name, menu, function):\n        item = menu.Append(wx.ID_ANY, name)\n        self.parent.Bind(wx.EVT_MENU, function, id=item.GetId())\n\n    def onAbout(self, event):\n        wx.GetApp().followLink(event)\n\n    def onSetUser(self, event):\n        user = self.userMenu.GetLabelText(event.GetId())\n        self.setUser(user)\n\n    def setUser(self, user=None):\n\n        if user is None and PavloviaMenu.appData['pavloviaUser']:\n            user = PavloviaMenu.appData['pavloviaUser']\n\n        if user in [PavloviaMenu.currentUser, None]:\n            return  # nothing to do here. Move along please.\n\n        PavloviaMenu.currentUser = user\n        PavloviaMenu.appData['pavloviaUser'] = user\n        if user in pavlovia.knownUsers:\n            token = pavlovia.knownUsers[user]['token']\n            try:\n                pavlovia.getCurrentSession().setToken(token)\n            except requests.exceptions.ConnectionError:\n                logging.warning(\"Tried to log in to Pavlovia but no network \"\n                                \"connection\")\n                return\n        else:\n            if hasattr(self, 'onLogInPavlovia'):\n                self.onLogInPavlovia()\n\n        if PavloviaMenu.searchDlg:\n            PavloviaMenu.searchDlg.updateUserProjs()\n\n    def onSync(self, event):\n        retVal = syncProject(parent=self.parent, project=self.parent.project)\n        if hasattr(self.parent, 'gitFeedback'):\n            self.parent.gitFeedback(retVal)\n\n    def onSearch(self, event):\n        PavloviaMenu.searchDlg = SearchFrame(app=self.parent.app)\n        PavloviaMenu.searchDlg.Show()\n\n    def onLogInPavlovia(self, event=None):\n        logInPavlovia(parent=self.parent)\n\n    def onNew(self, event):\n        \"\"\"Create a new project\n        \"\"\"\n        if pavlovia.getCurrentSession().user.username:\n            projEditor = ProjectEditor()\n            if projEditor.ShowModal() == wx.ID_OK:\n                self.parent.project = projEditor.project\n                # do a first sync as well\n                retVal = syncProject(parent=self.parent, project=projEditor.project)\n                self.parent.gitFeedback(retVal)\n        else:\n            infoDlg = dialogs.MessageDialog(parent=None, type='Info',\n                                            message=_translate(\n                                                    \"You need to log in\"\n                                                    \" to create a project\"))\n            infoDlg.Show()\n", "path": "psychopy/app/pavlovia_ui/menu.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\n# Part of the PsychoPy library\n# Copyright (C) 2002-2018 Jonathan Peirce (C) 2019-2021 Open Science Tools Ltd.\n# Distributed under the terms of the GNU General Public License (GPL).\n\nimport wx\nimport requests\n\nfrom psychopy import logging\nfrom .. import dialogs\nfrom .functions import logInPavlovia\nfrom psychopy.app.pavlovia_ui.project import syncProject\nfrom .search import SearchFrame\nfrom .project import ProjectEditor\nfrom psychopy.localization import _translate\nfrom psychopy.projects import pavlovia\n\n\nclass PavloviaMenu(wx.Menu):\n    app = None\n    appData = None\n    currentUser = None\n    knownUsers = None\n    searchDlg = None\n\n    def __init__(self, parent):\n        wx.Menu.__init__(self)\n        self.parent = parent  # type: BuilderFrame\n        PavloviaMenu.app = parent.app\n        keys = self.app.keys\n        # from prefs fetch info about prev usernames and projects\n        PavloviaMenu.appData = self.app.prefs.appData['projects']\n\n        # item = self.Append(wx.ID_ANY, _translate(\"Tell me more...\"))\n        # parent.Bind(wx.EVT_MENU, self.onAbout, id=item.GetId())\n\n        PavloviaMenu.knownUsers = pavlovia.knownUsers\n\n        # sub-menu for usernames and login\n        self.userMenu = wx.Menu()\n        # if a user was previously logged in then set them as current\n        lastPavUser = PavloviaMenu.appData['pavloviaUser']\n        if pavlovia.knownUsers and (lastPavUser not in pavlovia.knownUsers):\n            lastPavUser = None\n        # if lastPavUser and not PavloviaMenu.currentUser:\n        #     self.setUser(PavloviaMenu.appData['pavloviaUser'])\n        for name in self.knownUsers:\n            self.addToSubMenu(name, self.userMenu, self.onSetUser)\n        self.userMenu.AppendSeparator()\n        self.loginBtn = self.userMenu.Append(wx.ID_ANY,\n                                    _translate(\"Log in to Pavlovia...\\t{}\")\n                                    .format(keys['pavlovia_logIn']))\n        parent.Bind(wx.EVT_MENU, self.onLogInPavlovia, id=self.loginBtn.GetId())\n        self.AppendSubMenu(self.userMenu, _translate(\"User\"))\n\n        # search\n        self.searchBtn = self.Append(wx.ID_ANY,\n                           _translate(\"Search Pavlovia\\t{}\")\n                           .format(keys['projectsFind']))\n        parent.Bind(wx.EVT_MENU, self.onSearch, id=self.searchBtn.GetId())\n\n        # new\n        self.newBtn = self.Append(wx.ID_ANY,\n                           _translate(\"New...\\t{}\").format(keys['projectsNew']))\n        parent.Bind(wx.EVT_MENU, self.onNew, id=self.newBtn.GetId())\n\n        self.syncBtn = self.Append(wx.ID_ANY,\n                           _translate(\"Sync\\t{}\").format(keys['projectsSync']))\n        parent.Bind(wx.EVT_MENU, self.onSync, id=self.syncBtn.GetId())\n\n    def addToSubMenu(self, name, menu, function):\n        item = menu.Append(wx.ID_ANY, name)\n        self.parent.Bind(wx.EVT_MENU, function, id=item.GetId())\n\n    def onAbout(self, event):\n        wx.GetApp().followLink(event)\n\n    def onSetUser(self, event):\n        user = self.userMenu.GetLabelText(event.GetId())\n        self.setUser(user)\n\n    def setUser(self, user=None):\n        if PavloviaMenu.appData:\n            if user is None and PavloviaMenu.appData['pavloviaUser']:\n                user = PavloviaMenu.appData['pavloviaUser']\n\n        if user in [PavloviaMenu.currentUser, None]:\n            return  # nothing to do here. Move along please.\n\n        PavloviaMenu.currentUser = user\n        PavloviaMenu.appData['pavloviaUser'] = user\n        if user in pavlovia.knownUsers:\n            token = pavlovia.knownUsers[user]['token']\n            try:\n                pavlovia.getCurrentSession().setToken(token)\n            except requests.exceptions.ConnectionError:\n                logging.warning(\"Tried to log in to Pavlovia but no network \"\n                                \"connection\")\n                return\n        else:\n            if hasattr(self, 'onLogInPavlovia'):\n                self.onLogInPavlovia()\n\n        if PavloviaMenu.searchDlg:\n            PavloviaMenu.searchDlg.updateUserProjs()\n\n    def onSync(self, event):\n        retVal = syncProject(parent=self.parent, project=self.parent.project)\n        if hasattr(self.parent, 'gitFeedback'):\n            self.parent.gitFeedback(retVal)\n\n    def onSearch(self, event):\n        PavloviaMenu.searchDlg = SearchFrame(app=self.parent.app)\n        PavloviaMenu.searchDlg.Show()\n\n    def onLogInPavlovia(self, event=None):\n        logInPavlovia(parent=self.parent)\n\n    def onNew(self, event):\n        \"\"\"Create a new project\n        \"\"\"\n        if pavlovia.getCurrentSession().user.username:\n            projEditor = ProjectEditor()\n            if projEditor.ShowModal() == wx.ID_OK:\n                self.parent.project = projEditor.project\n                # do a first sync as well\n                retVal = syncProject(parent=self.parent, project=projEditor.project)\n                self.parent.gitFeedback(retVal)\n        else:\n            infoDlg = dialogs.MessageDialog(parent=None, type='Info',\n                                            message=_translate(\n                                                    \"You need to log in\"\n                                                    \" to create a project\"))\n            infoDlg.Show()\n", "path": "psychopy/app/pavlovia_ui/menu.py"}]}