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

📄 abc.py

📁 BitTorrentABC-Linux-V.2.4.3源码
💻 PY
📖 第 1 页 / 共 3 页
字号:
    
    def OnLeftDown(self, event):
        self.x = event.GetX()
        self.y = event.GetY()
        item, flags = self.list.HitTest((self.x, self.y))
        if flags & wxLIST_HITTEST_ONITEM:
            self.selectedROW = item
            if item != -1:
                self.list.Select(item)
        event.Skip()
    
    def OnLeftDClick(self, event):
        self.x = event.GetX()
        self.y = event.GetY()
        item, flags = self.list.HitTest((self.x, self.y))
        if flags & wxLIST_HITTEST_ONITEM:
            self.selectedROW = item
            if item != -1:
                self.list.Select(item)
                self.onDetailsNoEvent()
        event.Skip()

        
    def ClearLink(self, event):
        self.TextCtrlBTLink.SetValue("")
        
    def OnRightDown(self, event):
        self.x = event.GetX()
        self.y = event.GetY()
        item, flags = self.list.HitTest((self.x, self.y))
        if flags & wxLIST_HITTEST_ONITEM:
            self.selectedROW = item
            if item != -1 :
                self.list.Select(item)
        event.Skip()

    def OnItemSelected(self, event):
        self.selectedROW = event.m_itemIndex
      
        if not hasattr(self, "popupID1"):    
            self.popupID1 = wxNewId()
            self.popupID2 = wxNewId()
            self.popupID3 = wxNewId()
            self.popupID4 = wxNewId()
            self.popupID5 = wxNewId()
            self.popupID6 = wxNewId()
            self.popupID7 = wxNewId()
            self.popupID8 = wxNewId()
            #self.popupID9  = wxNewId()
            #self.popupID10 = wxNewId()
            self.popupID11 = wxNewId()
            self.popupID12 = wxNewId()
            # Fix ID for Priority menu
            self.prioID1  = 666
            self.prioID2  = 667
            self.prioID3  = 668
            self.prioID4  = 669
            self.prioID5  = 670



            EVT_MENU(self, self.popupID1, self.onResume)
            EVT_MENU(self, self.popupID2, self.onPause)
            EVT_MENU(self, self.popupID3, self.onQueue)
            EVT_MENU(self, self.popupID4, self.onRemove)
            EVT_MENU(self, self.popupID6, self.onLocalSetting)
            EVT_MENU(self, self.popupID7, self.onSuperSeed)
            EVT_MENU(self, self.popupID8, self.onDetails)
            EVT_MENU(self, self.popupID11, self.onOpenDest)
            EVT_MENU(self, self.popupID12, self.onChangeDownloadDest)

            
            EVT_MENU(self, self.prioID1, self.onChangePrio)
            EVT_MENU(self, self.prioID2, self.onChangePrio)
            EVT_MENU(self, self.prioID3, self.onChangePrio)
            EVT_MENU(self, self.prioID4, self.onChangePrio)
            EVT_MENU(self, self.prioID5, self.onChangePrio)

        # Make a right-click menu
        ################################
        menu = wxMenu()
        menu.Append(self.popupID1, "Resume")
        menu.Append(self.popupID2, "Pause")
        menu.Append(self.popupID3, "Queue")
        menu.Append(self.popupID4, "Remove")
        menu.AppendSeparator()        


        submenu = wxMenu()
        submenu.Append(self.prioID1, "Highest", "Highest", wxITEM_RADIO)
        submenu.Append(self.prioID2, "High", "High",wxITEM_RADIO)
        submenu.Append(self.prioID3, "Normal","Normal", wxITEM_RADIO)
        submenu.Append(self.prioID4, "Low", "Low",wxITEM_RADIO)
        submenu.Append(self.prioID5, "Lowest", "Lowest",wxITEM_RADIO)
        oldprio = self.queue.getPriority(self.selectedROW)
        submenu.Check(oldprio+666, True)
        menu.Append(self.popupID6, "Local Upload Setting ...")
        menu.AppendMenu(self.popupID5, "Priority Setting", submenu)

        
        menu.AppendSeparator()
        menu.Append(self.popupID7, "Use Super-seed Mode")

        
        menu.AppendSeparator()
        menu.Append(self.popupID11, "Open Destination ...")
        menu.Append(self.popupID12, "Change Download Destination...")

        menu.AppendSeparator()                    
        menu.Append(self.popupID8, "Torrent Details ...")

        # Popup the menu.  If an item is selected then its handler
        # will be called before PopupMenu returns.
        self.PopupMenu(menu, wxPoint(self.x, self.y+40))
        #menu.Destroy() #??????


    def onOpenDest(self, event):
        relative_row = self.selectedROW
        if self.queue.isProcComplete(relative_row):
            Thread(target = open_new(self.queue.getProcDest(relative_row))).start()
        else:   #Display Warning file is not complete yet
            dlg = wxMessageDialog(self, "Your file is not complete yet\nDo you really want to open?",
                                  "Warning!!", wxYES_NO|wxICON_EXCLAMATION)
            if dlg.ShowModal() == wxID_YES:
                Thread(target = open_new(self.queue.getProcDest(relative_row))).start()            
            dlg.Destroy()
            
    def onChangeDownloadDest(self, event):
        relative_row = self.selectedROW
        if self.queue.isProcActive(relative_row): #torrent is active, error!
            dlg = wxMessageDialog(self, "Torrent is active, you have to inactivate it before change destination.",
                                  "Error!!", wxICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
        else:
            #pop-up file dialog or dir dialog for new destination
            isfile, defaultname = self.queue.isFile(relative_row)
            if isfile: #Torrent is a file open file dialog
                dl = wxFileDialog(self, 'Choose new location for this torrent', '', defaultname, '*.*', wxSAVE)                
            else :  # Torrent is a folder, open folder dialog
                dl = wxDirDialog(self, 'Choose new directory for this torrent', path.join(getcwd(), defaultname), style = wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON)
            if dl.ShowModal() == wxID_OK:
                self.queue.changeProcDest(relative_row, dl.GetPath())
        
    def onItemMoveUp(self, event):
        relative_row = self.selectedROW
        if relative_row == -1:
            return
        
        if self.queue.MoveItemUp(relative_row):
            self.list.Select(relative_row - 1)
            self.selectedROW = self.selectedROW - 1
        
    def onItemMoveDown(self, event):
        relative_row = self.selectedROW
        if relative_row == -1:
            return
        
        if self.queue.MoveItemDown(relative_row):
            self.list.Select(relative_row + 1)
            self.selectedROW = self.selectedROW + 1

    def onClearAllCompleted(self, event):
        relative_row = self.selectedROW
        # Deselect List
        self.list.SetItemState(relative_row, 0, wxLIST_STATE_SELECTED)
        # Clear all completed torrent
        self.queue.clearAllCompleted()
        self.selectedROW = -1

    def onSuperSeed(self, event):
        relative_row = self.selectedROW
        self.queue.procSUPERSEED(relative_row)

    def onResume(self, event):
        relative_row = self.selectedROW
        self.queue.procRESUME(relative_row)
        
    def onPause(self, event):
        relative_row = self.selectedROW
        self.queue.procPAUSE(relative_row)
        # change display status in list control
        ###############################################
        # 0:Title, 3:Priority, 12:%U/D 18:downsize, 19:upsize-> don't have to change
        ###############################################
        for rank in range (0, self.guiman.getNumCol()):
            colid = self.guiman.getIDfromRank(rank)            
            if colid != 4 and colid != 7 and colid != 12 and colid != 18 and colid != 19:   
                if colid == 6:              # change bt status to pause
                    self.list.SetStringItem(relative_row, rank, "pause")
                else:
                    self.list.SetStringItem(relative_row, rank, "")

    def onQueue(self, event):
        relative_row = self.selectedROW
        self.queue.procQUEUE(relative_row, 0)
        # change display status in list control
        ###############################################
        # 0:Title, 3:Priority, 12:%U/D 18:downsize, 19:upsize-> don't have to change
        ###############################################
        for rank in range (0, self.guiman.getNumCol()):
            colid = self.guiman.getIDfromRank(rank)
            
            if colid != 4 and colid != 7 and colid != 12 and colid != 18 and colid != 19:   
                if colid == 6:              # change bt status to pause
                    self.list.SetStringItem(relative_row, rank, "queue")
                else:
                    self.list.SetStringItem(relative_row, rank, "")

    def onRemove(self, event):
        relative_row = self.selectedROW
        self.list.DeleteItem(relative_row)
        self.queue.procREMOVE(relative_row)
        self.selectedROW = -1

        
    def onChangePrio(self, event):
        prio = (event.GetId()) - 666
        relative_row = self.selectedROW
        self.queue.changePriority(relative_row, prio)

        rank = self.guiman.getRankfromID(7) #priority id = 7
        if rank != -1:
            self.list.SetStringItem(relative_row, rank, self.queue.priotext[prio])            
        #self.list.SetStringItem(relative_row, 3, self.queue.priotext[prio])            
        
    def onLocalSetting(self, event):
        relative_row = self.selectedROW
        localsettingdlg = LocalSettingDialog(self, -1, "Local Setting", size=wxSize(275, 300),
                          style = wxDEFAULT_DIALOG_STYLE, index=relative_row)
        localsettingdlg.ShowModal()

    def onDetailsNoEvent(self):
        relative_row = self.selectedROW
        if (self.queue.hasDetailWin(relative_row)):
            self.queue.proctab[relative_row][14].killAdv()

        self.queue.proctab[relative_row][14] = ABCDetailFrame(self, -1, "Torrent Details", self.abcpath, self.queue.proctab[relative_row][2], relative_row, wxSize(self.guiman.getValue(2), self.guiman.getValue(3)))
        if self.queue.proctab[relative_row][1] is not None:
            self.queue.proctab[relative_row][1].detailwin = self.queue.proctab[relative_row][14]
        
    def onDetails(self, event):
        self.onDetailsNoEvent()
            

    def AddTorrentLink(self, event):
        self.btlink = str(self.TextCtrlBTLink.GetValue())
        if self.btlink[:7] != "http://":
            dlg = wxMessageDialog(self, "Please enter URL started with http://",
                                  "Error!!", wxICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
        else:
            # Copy file from web and call addnewproc
            #########################################
            try:
                h = urlopen(self.btlink)
                btmetafile = h.read()
                h.close()
            except IOError, e:
                #display error can't connect to server
                dlg = wxMessageDialog(self, "Can't get torrent from this URL",
                                  "Error!!", wxICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
                return

            # Backup metainfo from URL to local directory
            filename = path.split(self.btlink)[1]
            torrentsrc = path.join(self.abcpath, "torrent", filename)
            try:
                f = open(torrentsrc, "r")
                f.close()
                # There is a duplicate .torrent file in /torrent
                dlg = wxMessageDialog(self, "This torrent is duplicate!\nAre you sure to replace it?" , "Duplicate Torrent!", wxYES_NO|wxICON_EXCLAMATION)
                if(dlg.ShowModal() == wxID_NO):
                    dlg.Destroy()
                    return
            except:
                # No duplicate file
                pass
            f = open(torrentsrc, "wb")
            f.write(btmetafile)
            f.close()
            self.queue.addNewProc(torrentsrc, False)
            

    def AddTorrentFile(self, event):
        dl = wxFileDialog(self, 'Choose a torrent file', '', '', '*.torrent', wxOPEN|wxMULTIPLE)
        if dl.ShowModal() != wxID_OK:
            dl.Destroy()
            return
        
        filelocation = dl.GetPaths()
        for i in range (0, len(filelocation)):            
            filename     = path.split(filelocation[i])[1]
            torrentsrc   = path.join(self.abcpath, "torrent", filename)
            try:
                f = open(torrentsrc, "r")
                f.close()
                # There is a duplicate .torrent file in /torrent
                dlg = wxMessageDialog(self, "This torrent is duplicate!\nAre you sure to replace it?" , "Duplicate Torrent!", wxYES_NO|wxICON_EXCLAMATION)
                if(dlg.ShowModal() == wxID_NO):
                    dlg.Destroy()
                    continue
            except:
                # No duplicate file
                pass
            copyfile(filelocation[i], torrentsrc)
            self.queue.addNewProc(torrentsrc, False)
        
    def AddTorrentNoneDefault(self, event):
        dl = wxFileDialog(self, 'Choose a torrent file', '', '', '*.torrent', wxOPEN|wxMULTIPLE)
        if dl.ShowModal() != wxID_OK:
            dl.Destroy()
            return
        
        filelocation = dl.GetPaths()
        for i in range (0, len(filelocation)):            
            filename     = path.split(filelocation[i])[1]
            torrentsrc   = path.join(self.abcpath, "torrent", filename)
            try:
                f = open(torrentsrc, "r")

⌨️ 快捷键说明

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