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

📄 abcdetailframe.py

📁 ABC-win32-v3.1 一个P2P软源代码
💻 PY
📖 第 1 页 / 共 3 页
字号:
        r = str(s)
        for i in range(len(r)-3, 0, -3):
            r = r[:i]+','+r[i:]
        return(r)



################################################################
#
# Class: FileInfoList
#
# Used by multi-file torrents to display information about
# each of the files.
#
################################################################
class FileInfoList(ManagedList):
    def __init__(self, parent):        
        style = wx.LC_REPORT
        
        prefix = 'fileinfo'
        minid = 0
        maxid = 7
        rightalign = [FILEINFO_SIZE, FILEINFO_PROGRESS]
        centeralign = []

        exclude = []

        ManagedList.__init__(self, parent, style, prefix, minid, maxid, exclude, rightalign, centeralign)
        
        self.torrent = parent.torrent

        self.priorityIDs = [wx.NewId(), wx.NewId(), wx.NewId(), wx.NewId()]
        self.prioritycolors = [ wx.Colour(160, 160, 160), 
                                wx.Colour(255, 64, 0), 
                                wx.Colour(0, 0, 0), 
                                wx.Colour(64, 64, 255) ]

        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onItemSelected)
        self.Bind(wx.EVT_LEFT_DCLICK, self.onOpenFileDest)
        self.Bind(wx.EVT_KEY_DOWN, self.onKeyDown)

    def onKeyDown(self, event):
        keycode = event.GetKeyCode()
        if event.CmdDown():
            if keycode == ord('a') or keycode == ord('A'):
                # Select all files (CTRL-A)
                self.selectAll()
            elif keycode == ord('x') or keycode == ord('X'):
                # Invert file selection (CTRL-X)
                self.invertSelection()
            elif keycode == ord('c') or keycode == ord('C'):
                self.onCopyFilename()
        elif keycode == 399:
            # Open right-click menu (windows menu key)
            self.onItemSelected()

        event.Skip()     

    def onOpenFileDest(self, event = None):
        for index in self.getSelected(firstitemonly = True):
            self.torrent.files.onOpenFileDest(index = index)
        
    def onOpenDest(self, event = None):
        for index in self.getSelected(firstitemonly = True):
            self.torrent.files.onOpenFileDest(index = index, pathonly = True)

    # Copy the filenames for one or more files
    def onCopyFilename(self, event = None, pathonly = False):
        # Get the filenames
        text = ""
        count = 0
        for index in self.getSelected():
            if count > 0:
                text += "\n"
            text += self.torrent.files.getSingleFileDest(index, pathonly, checkexists = False)
            count += 1
        
        # Copy the text to the clipboard
        if wx.TheClipboard.Open():
            data = wx.TextDataObject(text)
            wx.TheClipboard.SetData(data)
            wx.TheClipboard.Close()

    # Copy just the paths for files
    def onCopyPath(self, event = None):
        self.onCopyFilename(pathonly = True)

    def makePriorityMenu(self):
        s = self.getSelected()
        if not s:
            return None

        priorities = self.torrent.files.filepriorities
        oldstate = priorities[s[0]]
        kind = wx.ITEM_RADIO
        for i in s[1:]:
            if priorities[i] != oldstate:
                oldstate = None
                kind = wx.ITEM_NORMAL
                break
            
        menu = wx.Menu()
        menu.Append(self.priorityIDs[1], self.utility.lang.get('download_first'), kind=kind)
        menu.Append(self.priorityIDs[2], self.utility.lang.get('download_normal'), kind=kind)
        menu.Append(self.priorityIDs[3], self.utility.lang.get('download_later'), kind=kind)
        menu.Append(self.priorityIDs[0], self.utility.lang.get('download_never'), kind=kind)
        if oldstate is not None:
            menu.Check(self.priorityIDs[oldstate+1], True)

        def onSelection(event, self = self, s = s):
            p = event.GetId()
            priorities = self.torrent.files.filepriorities
            for i in xrange(len(self.priorityIDs)):
                if p == self.priorityIDs[i]:
                    for ss in s:
                        priorities[ss] = i-1
                        item = self.GetItem(ss)
                        item.SetTextColour(self.prioritycolors[i])
                        self.SetItem(item)

                    self.torrent.files.setFilePriorities(priorities)
                    self.Refresh()
                    break
            
        for index in self.priorityIDs:
            self.Bind(wx.EVT_MENU, onSelection, id = index)
        
        return menu

    def onItemSelected(self, event = None):
        s = self.getSelected()

        if not s:   # just in case
            return

        menu = wx.Menu()
        
        self.utility.makePopup(menu, self.onCopyFilename, 'rcopyfilename')
        self.utility.makePopup(menu, self.onCopyPath, 'rcopypath')
        self.utility.makePopup(menu, self.onOpenDest, 'ropendest')
        self.utility.makePopup(menu, self.onOpenFileDest, 'ropenfiledest')

        # Add the priority submenu if this is a multi-file torrent
        if not self.torrent.files.isFile():
            prioritymenu = self.makePriorityMenu()
            if prioritymenu is not None:
                menu.AppendMenu(-1, self.utility.lang.get('rpriosetting'), prioritymenu)

        # Popup the menu.  If an item is selected then its handler
        # will be called before PopupMenu returns.
        if event is None:
            # use the position of the first selected item (key event)
            position = self.GetItemPosition(s[0])
        else:
            # use the cursor position (mouse event)
            position = event.GetPoint()

        self.PopupMenu(menu, position)
 
        
################################################################
#
# Class: DetailPanel
#
# Displays network information related to how much has been
# downloaded/uploaded, along with a listing of peers
# (if connected).
#
################################################################
class DetailPanel(wx.Panel):
    def __init__(self, parent, dialog):
        wx.Panel.__init__(self, parent, -1)
    
        self.dialog = dialog
        self.utility = dialog.utility
        self.torrent = dialog.torrent
        
        colSizer = wx.BoxSizer(wx.VERTICAL)
       
        detailSizer = wx.FlexGridSizer(cols = 2, vgap = 6, hgap = 100)
        colSizer.Add (detailSizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
        leftdetailSizer  = wx.FlexGridSizer(cols = 2, vgap = 3, hgap = 5)
        rightdetailSizer = wx.FlexGridSizer(cols = 2, vgap = 3, hgap = 5)
        detailSizer.Add(leftdetailSizer)
        detailSizer.Add(rightdetailSizer)

        # # SEED
        ###################
        self.seedtitle = wx.StaticText(self, -1, "")
        self.numseed   = wx.StaticText(self, -1, "")
        leftdetailSizer.Add(self.seedtitle)
        leftdetailSizer.Add(self.numseed)
        
        # # Peers
        ###################
        self.numpeer   = wx.StaticText(self, -1, "")
        leftdetailSizer.Add(wx.StaticText(self, -1, self.utility.lang.get('dnumconnectedpeer')))
        leftdetailSizer.Add(self.numpeer)

        # # Seeing Copies
        ##################
        self.numcopy  = wx.StaticText(self, -1, "")
        rightdetailSizer.Add(wx.StaticText(self, -1, self.utility.lang.get('dseeingcopies')))
        rightdetailSizer.Add(self.numcopy)
        
        # Avg peer
        ##################
        self.avgprogress  = wx.StaticText(self, -1, "")
        rightdetailSizer.Add(wx.StaticText(self, -1, self.utility.lang.get('davgpeerprogress')))
        rightdetailSizer.Add(self.avgprogress)
                
        # Download Size
        ##################
        self.downsize  = wx.StaticText(self, -1, "")
        leftdetailSizer.Add(wx.StaticText(self, -1, self.utility.lang.get('ddownloadedsize')))
        leftdetailSizer.Add(self.downsize)
        
        # Upload Size
        ##################
        self.upsize = wx.StaticText(self, -1, "")
        rightdetailSizer.Add(wx.StaticText(self, -1, self.utility.lang.get('duploadedsize')))
        rightdetailSizer.Add(self.upsize)

        # Total Speed
        ##################
        self.totalspeed  = wx.StaticText(self, -1, "")
        leftdetailSizer.Add(wx.StaticText(self, -1, self.utility.lang.get('dtotalspeed')))
        leftdetailSizer.Add(self.totalspeed)

        # Port Used
        ##################
        self.portused = wx.StaticText(self, -1, "")
        rightdetailSizer.Add(wx.StaticText(self, -1, self.utility.lang.get('dportused')))
        rightdetailSizer.Add(self.portused)

        # Shad0w Advance display
        #####################
        def StaticText(text):
            return wx.StaticText(self, -1, text, style = wx.ALIGN_LEFT)

        self.spewList = SpewList(self)

        colSizer.Add(self.spewList, 1, wx.EXPAND|wx.ALL, 5)

        self.storagestats1 = StaticText('')
        self.storagestats2 = StaticText('')
        colSizer.Add(self.storagestats1, 0, wx.ALL, 5)
        colSizer.Add(self.storagestats2, 0, wx.ALL, 5)

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

        self.SetSizer(colSizer)
        self.SetAutoLayout(True)

    ######################################
    # Update on-the-fly
    ######################################
    def updateColumns(self, force = False):
        # Update display in column?
        pass

    def updateFromABCTorrent(self):
        if self.utility.abcquitting:
            return
        try:
            self.downsize.SetLabel(self.torrent.getColumnText(COL_DLSIZE))
            self.upsize.SetLabel(self.torrent.getColumnText(COL_ULSIZE))
            if not self.torrent.status.completed:
                self.seedtitle.SetLabel(self.utility.lang.get('dnumconnectedseed'))
            else:
                self.seedtitle.SetLabel(self.utility.lang.get('dseenseed'))
            self.totalspeed.SetLabel(self.torrent.getColumnText(COL_TOTALSPEED))
            self.avgprogress.SetLabel(self.torrent.getColumnText(COL_PEERPROGRESS))
            self.numseed.SetLabel(self.torrent.getColumnText(COL_SEEDS))
            self.numpeer.SetLabel(self.torrent.getColumnText(COL_PEERS))
            self.numcopy.SetLabel(self.torrent.getColumnText(COL_COPIES))
            if self.torrent.status.isActive():
                port = self.utility.controller.listen_port
                if port is not None:
                    self.portused.SetLabel(str(port))
        except wx.PyDeadObjectError:
            pass


################################################################
#
# Class: SpewList
#
# Displays a listing of peers (if connected).
#
################################################################
class SpewList(ManagedList):
    def __init__(self, parent):
        style = wx.LC_REPORT|wx.LC_HRULES|wx.LC_VRULES
        
        prefix = 'spew'
        minid = 0
        maxid = 14
        rightalign = [SPEW_UP, 
                      SPEW_DOWN, 
                      SPEW_DLSIZE, 
                      SPEW_ULSIZE, 
                      SPEW_PEERPROGRESS, 
                      SPEW_PEERSPEED]
        centeralign = [SPEW_UNCHOKE, 
                       SPEW_LR, 
                       SPEW_INTERESTED, 
                       SPEW_CHOKING, 
                       SPEW_INTERESTING, 
                       SPEW_CHOKED, 
                       SPEW_SNUBBED]

        exclude = []      

        ManagedList.__init__(self, parent, style, prefix, minid, maxid, exclude, rightalign, centeralign)
    

################################################################
#
# Class: MessageLogPanel
#
# Displays the errors that a torrent has encountered
#
################################################################
class MessageLogPanel(wx.Panel):
    def __init__(self, parent, dialog):
        wx.Panel.__init__(self, parent, -1)
    
        self.dialog = dialog
        self.utility = dialog.utility

⌨️ 快捷键说明

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