⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svnservice.py

📁 wxPython的基本示例程序
💻 PY
📖 第 1 页 / 共 4 页
字号:
                    view.AddLines("%s\n" % str(e))                    wx.MessageBox(str(e), _("SVN Add"), wx.OK | wx.ICON_EXCLAMATION)                except:                    extype, ex, tb = sys.exc_info()                    view.AddLines("Add failed: (%s) %s\n" % (extype, str(ex)))                    for line in traceback.format_tb(tb):                        view.AddLines(line)                    wx.MessageBox(_("Add failed."), _("SVN Add"), wx.OK | wx.ICON_EXCLAMATION)                    wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))                return True                elif id == SVNService.SVN_DELETE_ID:                wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))                    filenames = self.GetCurrentDocuments()                    messageService = wx.GetApp().GetService(MessageService.MessageService)                messageService.ShowWindow()                    view = messageService.GetView()                view.ClearLines()                view.AddLines(_("SVN Delete:\n"))                for filename in filenames:                    view.AddLines("%s\n" % filename)                    try:                    self._client.remove(filenames)                    view.AddLines(_("Delete completed.\n"))                except pysvn.ClientError, e:                    view.AddLines("%s\n" % str(e))                    wx.MessageBox(str(e), _("SVN Delete"), wx.OK | wx.ICON_EXCLAMATION)                except:                    extype, ex, tb = sys.exc_info()                    view.AddLines("Delete failed: (%s) %s\n" % (extype, str(ex)))                    for line in traceback.format_tb(tb):                        view.AddLines(line)                    wx.MessageBox(_("Delete failed."), _("SVN Delete"), wx.OK | wx.ICON_EXCLAMATION)                    wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))                return True                return False        finally:            wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))    def ProcessUpdateUIEvent(self, event):        id = event.GetId()        if id in [SVNService.SVN_CHECKIN_ID,                  SVNService.SVN_REVERT_ID,                  SVNService.SVN_ADD_ID,                  SVNService.SVN_DELETE_ID]:            if self.GetCurrentDocuments():                event.Enable(True)            else:                event.Enable(False)            return True        elif id == SVNService.SVN_UPDATE_ID:            if self.GetCurrentDocuments() or self.GetCurrentFolder():                event.Enable(True)            else:                event.Enable(False)            return True        elif id == SVNService.SVN_CHECKOUT_ID:            event.Enable(True)            return True        elif (id == SVNService.SVN_UPDATE_ALL_ID        or id == SVNService.SVN_CHECKIN_ALL_ID):            if self.GetCurrentProject():                event.Enable(True)            else:                event.Enable(False)            return True        return False    def GetCurrentProject(self):        projectService = wx.GetApp().GetService(ProjectEditor.ProjectService)        if projectService:            projView = projectService.GetView()            return projView.GetSelectedProject()        return None    def GetCurrentDocuments(self):        projectService = wx.GetApp().GetService(ProjectEditor.ProjectService)        if projectService:            projView = projectService.GetView()            if projView.FilesHasFocus():                filenames = projView.GetSelectedFiles()                if len(filenames):                    return filenames                else:                    return None        doc = wx.GetApp().GetTopWindow().GetDocumentManager().GetCurrentDocument()        if doc:            filenames = [doc.GetFilename()]        else:            filenames = None        return filenames    def GetCurrentFolder(self):        projectService = wx.GetApp().GetService(ProjectEditor.ProjectService)        if projectService:            projView = projectService.GetView()            if projView.FilesHasFocus():                folderPath = projView.GetSelectedPhysicalFolder()                if folderPath:                    return folderPath        return None    def BasenameCaseInsensitiveCompare(self, s1, s2):        s1L = os.path.basename(s1).lower()        s2L = os.path.basename(s2).lower()        if s1L == s2L:            return 0        elif s1L < s2L:            return -1        else:            return 1class SVNOptionsPanel(wx.Panel):    def __init__(self, parent, id):        wx.Panel.__init__(self, parent, id)        config = wx.ConfigBase_Get()        configDir = config.Read(SVN_CONFIG_DIR, "")        borderSizer = wx.BoxSizer(wx.VERTICAL)        sizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5)        sizer.AddGrowableCol(1, 1)        sizer.Add(wx.StaticText(self, -1, _("SVN Config Dir:")), 0, wx.ALIGN_CENTER_VERTICAL)        self._svnConfigDir = wx.TextCtrl(self, -1, configDir, size = (200, -1))        if configDir == "":            self._svnConfigDir.SetToolTipString(_("Path Subversion configuration directory."))        else:            self._svnConfigDir.SetToolTipString(configDir)                findDirButton = wx.Button(self, -1, _("Browse..."))        def OnBrowseButton(event):            dirDlg = wx.DirDialog(self, _("Choose a directory:"), style=wx.DD_DEFAULT_STYLE)            dir = self._svnConfigDir.GetValue()            if len(dir):                dirDlg.SetPath(dir)            dirDlg.CenterOnParent()            if dirDlg.ShowModal() == wx.ID_OK:                self._svnConfigDir.SetValue(dirDlg.GetPath())                self._svnConfigDir.SetToolTipString(self._svnConfigDir.GetValue())                self._svnConfigDir.SetInsertionPointEnd()            dirDlg.Destroy()        wx.EVT_BUTTON(findDirButton, -1, OnBrowseButton)        hsizer = wx.BoxSizer(wx.HORIZONTAL)        hsizer.Add(self._svnConfigDir, 1, wx.EXPAND)        hsizer.Add(findDirButton, 0, wx.LEFT, HALF_SPACE)        sizer.Add(hsizer, 0, wx.EXPAND)        svnUrlList = ReadSvnUrlList()        sizer.Add(wx.StaticText(self, -1, _("SVN URL:")), 0, wx.ALIGN_CENTER_VERTICAL)        self._svnURLCombobox = wx.ComboBox(self, -1, size=(200, -1), choices=svnUrlList, style=wx.CB_DROPDOWN)        if len(svnUrlList):            self._svnURLCombobox.SetToolTipString(svnUrlList[0])            self._svnURLCombobox.SetStringSelection(svnUrlList[0])        else:            self._svnURLCombobox.SetToolTipString(_("Set Repository URL"))        sizer.Add(self._svnURLCombobox, 0, wx.EXPAND)        sizer.Add(wx.StaticText(self, -1, _("SVN_SSH:")), 0, wx.ALIGN_CENTER_VERTICAL)        svnSSH = os.getenv("SVN_SSH")        if not svnSSH or svnSSH == "":            self._svnSSH = wx.TextCtrl(self, -1, size = (200, -1))        else:            self._svnSSH = wx.TextCtrl(self, -1, svnSSH, size = (200, -1))        self._svnSSH.SetToolTipString(_("Override SVN_SSH environment variable temporarily."))                findSSHButton = wx.Button(self, -1, _("Browse..."))        def OnBrowseFileButton(event):            dirDlg = wx.FileDialog(self, _("Choose a file:"), style=wx.OPEN|wx.CHANGE_DIR)            # dirDlg.CenterOnParent()  # wxBug: caused crash with wx.FileDialog            if dirDlg.ShowModal() == wx.ID_OK:                self._svnSSH.SetValue(dirDlg.GetPath())                self._svnSSH.SetToolTipString(self._svnSSH.GetValue())                self._svnSSH.SetInsertionPointEnd()            dirDlg.Destroy()        wx.EVT_BUTTON(findSSHButton, -1, OnBrowseFileButton)        hsizer = wx.BoxSizer(wx.HORIZONTAL)        hsizer.Add(self._svnSSH, 1, wx.EXPAND)        hsizer.Add(findSSHButton, 0, wx.LEFT, HALF_SPACE)        sizer.Add(hsizer, 0, wx.EXPAND)        borderSizer.Add(sizer, 0, wx.ALL|wx.EXPAND, SPACE)        self.SetSizer(borderSizer)        self.Layout()        parent.AddPage(self, _("SVN"))    def GetIcon(self):        return wx.NullIcon    def OnOK(self, optionsDialog):        config = wx.ConfigBase_Get()                config.Write(SVN_CONFIG_DIR, self._svnConfigDir.GetValue())                WriteSvnUrlList(self._svnURLCombobox)                os.environ["SVN_SSH"] = self._svnSSH.GetValue()        def ReadSvnUrlList():    """ Read in list of SNV repository URLs.  First in list is the last one path used. """    config = wx.ConfigBase_Get()    urlStringList = config.Read(SVN_REPOSITORY_URL)    if len(urlStringList):        urlList = eval(urlStringList)    else:        urlList = []    if len(urlList) == 0:        svnService = wx.GetApp().GetService(SVNService)        if svnService and hasattr(svnService, "_defaultURL"):            urlList.append(svnService._defaultURL)    return urlListdef WriteSvnUrlList(comboBox):    """ Save out list of SVN repository URLs from combobox.  Put on top the current selection.  Only save out first 10 from the list """    urlList = []        url = comboBox.GetValue()    if len(url):        urlList.append(url)            for i in range(min(comboBox.GetCount(), 10)):        url = comboBox.GetString(i)        if url not in urlList:            urlList.append(url)    config = wx.ConfigBase_Get()    config.Write(SVN_REPOSITORY_URL, urlList.__repr__())

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -