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

📄 abcdetailframe.py

📁 ABC-win32-v3.1 一个P2P软源代码
💻 PY
📖 第 1 页 / 共 3 页
字号:
        self.torrent = dialog.torrent
        
        colSizer = wx.BoxSizer(wx.VERTICAL)

        self.msgtext = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP|wx.TE_RICH)
        
        colSizer.Add(self.msgtext, 1, wx.EXPAND|wx.ALL, 5)
        
        logButtons = wx.BoxSizer(wx.HORIZONTAL)
        
        clearlog = wx.Button(self, -1, self.utility.lang.get('clearlog'))
        self.Bind(wx.EVT_BUTTON, self.clearLog, clearlog)
        logButtons.Add(clearlog, 0, wx.LEFT|wx.RIGHT, 5)

        savelog = wx.Button(self, -1, self.utility.lang.get('savelog'))
        self.Bind(wx.EVT_BUTTON, self.saveLog, savelog)
        logButtons.Add(savelog, 0, wx.LEFT|wx.RIGHT, 5)
        
        colSizer.Add(logButtons, 0, wx.ALIGN_RIGHT|wx.ALL, 5)

        # Grab initial values from ABCTorrent:
        self.updateMessageLog()

        self.SetSizer(colSizer)
        self.SetAutoLayout(True)
        
    def clearLog(self, event = None):
        self.torrent.messages["log"] = []
        self.updateMessageLog()
        
    def saveLog(self, event = None):
        # Ask where to save the file to
        defaultdir = self.utility.getLastDir("log")
        
        dlg = wx.FileDialog(self.dialog, 
                            message = self.utility.lang.get('savelogas'), 
                            defaultDir = defaultdir, 
                            defaultFile = self.torrent.files.filename + ".log", 
                            wildcard = self.utility.lang.get('logfileswildcard') + ' (*.log)|*.log', 
                            style = wx.SAVE)
        dlg.Raise()
        result = dlg.ShowModal()
        dlg.Destroy()
        
        if result != wx.ID_OK:
            return
        
        dest = dlg.GetPath()
            
        self.utility.lastdir['log'] = os.path.dirname(dest)

        # Generate the combined log text
        logtext = ""
        for entry in self.torrent.messages["log"]:
            msgdate = strftime('%x', localtime(entry[0]))
            msgtime = strftime('%X', localtime(entry[0]))
            message = entry[1]
            msgtype = entry[2]
            
            combined = msgdate + " " + msgtime + " - " + message
            
            logtext += combined + "\n"
            
        # Write the file
        try:
            logfile = open(dest, "w")
            logfile.write(logtext)
            logfile.close()
        except:
            data = StringIO()
            print_exc(file = data)

            dialog = wx.MessageDialog(self.dialog, 
                                      self.utility.lang.get('error_savelog') + "\n" + data.getvalue(), 
                                      self.utility.lang.get('error'), 
                                      wx.ICON_ERROR)
            dialog.ShowModal()
            dialog.Destroy()
        
    def updateMessageLog(self):
        if self.utility.abcquitting:
            return

        try:
            self.msgtext.Clear()
            for entry in self.torrent.messages["log"]:
                msgdate = strftime('%x', localtime(entry[0]))
                msgtime = strftime('%X', localtime(entry[0]))
                message = entry[1]
                msgtype = entry[2]
                
                combined = msgdate + " " + msgtime + " - " + message
                
                if msgtype == "error":
                    color = wx.Colour(200, 0, 0)
                else:
                    color = wx.Colour(0, 0, 0)
    
                self.msgtext.SetInsertionPointEnd()
                before = self.msgtext.GetInsertionPoint()
                
                self.msgtext.AppendText(combined + "\n")
                
                self.msgtext.SetInsertionPointEnd()
                after = self.msgtext.GetInsertionPoint()
                
                self.msgtext.SetStyle(before, after, wx.TextAttr(color))
        except wx.PyDeadObjectError:
            pass


################################################################
#
# Class: ABCDetailFrame
#
# Window that displays detailed information about the status
# of a torrent and its files
#
################################################################
class ABCDetailFrame(wx.Frame):
    def __init__(self, torrent):
        self.torrent = torrent
        self.utility = torrent.utility
        
        size = self.getWindowSettings()
        
        wx.Frame.__init__(self, None, -1, "", size = size)

        self.update = False

        try:
            self.SetIcon(self.utility.icon)
        except:
            pass

        self.metainfo = self.torrent.getResponse()
        if self.metainfo is None:
            self.killAdv()
            return
                   
        panel = wx.Panel(self, -1, size = size)
                   
        sizer = wx.BoxSizer(wx.VERTICAL)

#        self.aboutTitle = wx.StaticText(panel, -1, self.torrent.getColumnText(COL_TITLE))
        self.aboutTitle = wx.TextCtrl(panel, -1, "", style = wx.TE_CENTRE)
        
        self.aboutTitle.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
        sizer.Add(self.aboutTitle, 0, wx.EXPAND|wx.ALIGN_CENTER|wx.ALL, 5)

        self.notebook = wx.Notebook(panel, -1)

        self.detailPanel = DetailPanel(self.notebook, self)
        self.notebook.AddPage(self.detailPanel, self.utility.lang.get('networkinfo'))
        
        self.fileInfoPanel = FileInfoPanel(self.notebook, self)
        self.notebook.AddPage(self.fileInfoPanel, self.utility.lang.get('fileinfo'))
        
        self.torrentInfoPanel = TorrentInfoPanel(self.notebook, self)
        self.notebook.AddPage(self.torrentInfoPanel, self.utility.lang.get('torrentinfo'))
        
        self.messageLogPanel = MessageLogPanel(self.notebook, self)
        self.notebook.AddPage(self.messageLogPanel, self.utility.lang.get('messagelog'))
        
        sizer.Add(self.notebook, 1, wx.EXPAND|wx.ALL, 5)
        
        try:
            self.notebook.SetSelection(self.utility.lasttab['advanced'])
        except:
            pass
                
        # Add buttons
        #########################
        buttonSizer = wx.BoxSizer(wx.HORIZONTAL)

        scrapeButton = wx.Button(panel, -1, self.utility.lang.get('updateseedpeer'))
        self.Bind(wx.EVT_BUTTON, self.getScrape, scrapeButton)
        buttonSizer.Add(scrapeButton, 0, wx.RIGHT, 5)
        
        reannounceButton = wx.Button(panel, -1, self.utility.lang.get('manualannounce'))
        self.Bind(wx.EVT_BUTTON, self.torrent.connection.reannounce, reannounceButton)
        buttonSizer.Add(reannounceButton, 0, wx.LEFT|wx.RIGHT, 5)
        
        extannounceButton = wx.Button(panel, -1, self.utility.lang.get('externalannounce'))
        self.Bind(wx.EVT_BUTTON, self.reannounce_external, extannounceButton)
        buttonSizer.Add(extannounceButton, 0, wx.LEFT|wx.RIGHT, 5)

        bgallocButton = wx.Button(panel, -1, self.utility.lang.get('finishallocation'))
        self.Bind(wx.EVT_BUTTON, self.bgalloc, bgallocButton)
        buttonSizer.Add(bgallocButton, 0, wx.LEFT|wx.RIGHT, 5)

        okButton = wx.Button(panel, -1, self.utility.lang.get('ok'))
        self.Bind(wx.EVT_BUTTON, self.killAdv, okButton)
        buttonSizer.Add(okButton, 0, wx.LEFT, 5)

        sizer.Add(buttonSizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
        
        panel.SetSizer(sizer)
        
        self.Bind(wx.EVT_CLOSE, self.killAdv)
       
        # Set the spew flag
        if self.torrent.status.isActive():
            self.torrent.connection.engine.dow.spewflag.set()

        self.aboutTitle.Bind(wx.EVT_RIGHT_DOWN, self.onTitleMenu)
        self.aboutTitle.Bind(wx.EVT_TEXT, self.onChangeTitle)

        self.updateTorrentName()

        self.update = True

        self.Show()
            
    def reannounce_external(self, event = None):
        self.torrent.connection.reannounce_external(event, self)
        
    def getScrape(self, event = None):
        self.torrent.actions.scrape(manualscrape = True)
               
    def killAdv(self, event = None):       
        self.update = False
        
        # Remove lists from the index kept in utility:
        try:
            self.utility.lists[self.detailPanel.spewList] = False
            del self.utility.lists[self.detailPanel.spewList]
        except:
            pass
        try:
            self.utility.lists[self.fileInfoPanel.fileList] = False
            del self.utility.lists[self.fileInfoPanel.fileList]
        except:
            pass

        self.torrent.dialogs.details = None

        # Clear the spew flag
        if self.torrent.status.isActive():
            # TODO: Workaround for multiport not reporting
            #       external_connection_made properly
            if self.torrent.connection.engine.workarounds['hasexternal']:
                self.torrent.connection.engine.dow.spewflag.clear()
        
        try:
            self.saveWindowSettings()
            self.Destroy()
        except wx.PyDeadObjectError:
            pass
        
    def onStop(self):
        self.detailPanel.updateFromABCTorrent()

        self.detailPanel.spewList.DeleteAllItems()
        self.detailPanel.storagestats1.SetLabel('')
        self.detailPanel.storagestats2.SetLabel('')
        
    def onChangeTitle(self, event = None):
        self.torrent.changeTitle(self.aboutTitle.GetValue())
        self.updateTitle()
        
    #
    # Give options for changing the torrent's title
    # (hide options that are the same)
    #
    def onTitleMenu(self, event):
        menu = wx.Menu()

        original = self.torrent.getTitle("original")
        dest = self.torrent.getTitle("dest")
        torrent = self.torrent.getTitle("torrent")
        
        titlemenu = wx.Menu()
        self.utility.makePopup(titlemenu, self.changeTitleOriginal, 'originalname', bindto = menu)
        self.utility.makePopup(titlemenu, self.changeTitleOriginal, extralabel = self.torrent.getTitle("original"), bindto = menu)
        if original != dest:
            titlemenu.AppendSeparator()
            self.utility.makePopup(titlemenu, self.changeTitleDest, 'destname', bindto = menu)
            self.utility.makePopup(titlemenu, self.changeTitleDest, extralabel = self.torrent.getTitle("dest"), bindto = menu)
        if original != torrent:
            titlemenu.AppendSeparator()
            self.utility.makePopup(titlemenu, self.changeTitleTorrent, 'torrentfilename', bindto = menu)
            self.utility.makePopup(titlemenu, self.changeTitleTorrent, extralabel = self.torrent.getTitle("torrent"), bindto = menu)
        
        menu.AppendMenu(-1, self.utility.lang.get('changetitle'), titlemenu)
        
        self.PopupMenu(menu, event.GetPosition() + self.aboutTitle.GetPosition())
                
    def changeTitleOriginal(self, event = None):
        self.aboutTitle.SetValue(self.torrent.getTitle("original"))
        
    def changeTitleTorrent(self, event = None):
        self.aboutTitle.SetValue(self.torrent.getTitle("torrent"))
        
    def changeTitleDest(self, event = None):
        self.aboutTitle.SetValue(self.torrent.getTitle("dest"))

    def getWindowSettings(self):
        width = self.utility.config.Read("detailwindow_width", "int")
        height = self.utility.config.Read("detailwindow_height", "int")
                  
        return wx.Size(width, height)
        
    def saveWindowSettings(self):
        self.utility.lasttab['advanced'] = self.notebook.GetSelection()
        
        width, height = self.GetSizeTuple()
        self.utility.config.Write("detailwindow_width", str(width))
        self.utility.config.Write("detailwindow_height", str(height))
        self.utility.config.Flush()
        
    def bgalloc(self, event = None):
        if self.torrent.status.isActive():
            if self.torrent.connection.engine.dow.storagewrapper is not None:
                self.torrent.connection.engine.dow.storagewrapper.bgalloc()
                
    def updateTitle(self):
        self.SetTitle(self.utility.lang.get('torrentdetail') + " - " + self.torrent.getColumnText(COL_TITLE))
        
    def updateTorrentName(self):
        try:
            self.updateTitle()
            self.aboutTitle.SetLabel(self.torrent.getColumnText(COL_TITLE))
        except:
            pass
        info = self.metainfo['info']
        if 'length' in info:
            self.fileInfoPanel.fileList.updateColumns()

⌨️ 快捷键说明

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