def __init__(self, parent): wx.Menu.__init__(self) self.parent = parent ProjectsMenu.app = parent.app keys = self.app.keys # from prefs fetch info about prev usernames and projects ProjectsMenu.appData = self.app.prefs.appData['projects'] global projHistory self.projHistory = projHistory # so we can treat as local from here global usersList self.userList = usersList item = self.Append(wx.ID_ANY, _translate("Tell me more...")) parent.Bind(wx.EVT_MENU, self.onAbout, id=item.GetId()) if not havePyosf: self.Append(wx.ID_ANY, _translate("Requires pyosf (not installed)")) ProjectsMenu.knownUsers = {} else: if self.app.osf_session is None: # create a default (anonymous) session with osf self.app.osf_session = pyosf.Session() ProjectsMenu.knownUsers = pyosf.TokenStorage() # a dict name:token # sub-menu to open previous or new projects self.projsSubMenu = wx.Menu() item = self.projsSubMenu.Append( wx.ID_ANY, _translate("From file...\t{}").format(keys['projectsOpen'])) parent.Bind(wx.EVT_MENU, self.onOpenFile, id=item.GetId()) self.projsSubMenu.AppendSeparator() self.projHistory.UseMenu(self.projsSubMenu) try: self.projHistory.AddFilesToMenu(self.projsSubMenu) except: self.projHistory.AddFilesToThisMenu(self.projsSubMenu) parent.Bind(wx.EVT_MENU_RANGE, self.onProjFromHistory, id=self.projHistory.idBase, id2=self.projHistory.idBase + 9) self.AppendSubMenu(self.projsSubMenu, _translate("Open")) # sub-menu for usernames and login self.userMenu = wx.Menu() # if a user was previously logged in then set them as current if ProjectsMenu.appData['user'] and \ ProjectsMenu.appData['user'] in self.knownUsers: self.setUser(ProjectsMenu.appData['user']) for name in self.knownUsers: self.addToSubMenu(name, self.userMenu, self.onSetUser) self.userMenu.AppendSeparator() item = self.userMenu.Append( wx.ID_ANY, _translate("Log in...\t{}").format(keys['projectsLogIn'])) parent.Bind(wx.EVT_MENU, self.onLogIn, id=item.GetId()) self.AppendSubMenu(self.userMenu, _translate("User")) # search item = self.Append( wx.ID_ANY, _translate("Search OSF\t{}").format(keys['projectsFind'])) parent.Bind(wx.EVT_MENU, self.onSearch, id=item.GetId()) # new item = self.Append( wx.ID_ANY, _translate("New...\t{}").format(keys['projectsNew'])) parent.Bind(wx.EVT_MENU, self.onNew, id=item.GetId())
def __init__(self, parent): wx.Menu.__init__(self) self.parent = parent ProjectsMenu.app = parent.app keys = self.app.keys ProjectsMenu.appData = self.app.prefs.appData['projects'] global projHistory self.projHistory = projHistory # so we can treat as local from here global usersList self.userList = usersList if self.app.osf_session is None: # create a default (anonymous) session with osf self.app.osf_session = pyosf.Session() self.Append(wxIDs.projsAbout, "Tell me more...") wx.EVT_MENU(parent, wxIDs.projsAbout, self.onAbout) if not havePyosf: self.Append(wx.NewId(), "Requires pyosf (not installed)") ProjectsMenu.knownUsers = {} else: ProjectsMenu.knownUsers = pyosf.TokenStorage() # a dict name:token # sub-menu to open previous or new projects self.projsSubMenu = wx.Menu() self.projsSubMenu.Append(wxIDs.projsOpen, "From file...\t{}" .format(keys['projectsOpen'])) wx.EVT_MENU(parent, wxIDs.projsOpen, self.onOpenFile) self.projsSubMenu.AppendSeparator() self.projHistory.UseMenu(self.projsSubMenu) try: self.projHistory.AddFilesToMenu(self.projsSubMenu) except: self.projHistory.AddFilesToThisMenu(self.projsSubMenu) parent.Bind(wx.EVT_MENU_RANGE, self.onProjFromHistory, id=self.projHistory.idBase, id2=self.projHistory.idBase+9) self.AppendSubMenu(self.projsSubMenu, "Open") # sub-menu for usernames and login self.userMenu = wx.Menu() # if a user was previously logged in then set them as current if ProjectsMenu.appData['user'] and \ ProjectsMenu.appData['user'] in self.knownUsers: self.setUser(ProjectsMenu.appData['user']) for name in self.knownUsers: self.addToSubMenu(name, self.userMenu, self.onSetUser) self.userMenu.AppendSeparator() self.userMenu.Append(wxIDs.projsNewUser, "Log in...\t{}".format(keys['projectsLogIn'])) wx.EVT_MENU(parent, wxIDs.projsNewUser, self.onLogIn) self.AppendSubMenu(self.userMenu, "User") # search self.Append(wxIDs.projsSearch, "Search OSF\t{}".format(keys['projectFind'])) wx.EVT_MENU(parent, wxIDs.projsSearch, self.onSearch) self.Append(wxIDs.projsSync, "Sync\t{}".format(keys['projectsSync'])) wx.EVT_MENU(parent, wxIDs.projsSync, self.onSync)