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

📄 abc.py

📁 BitTorrentABC-Linux-V.2.4.3源码
💻 PY
📖 第 1 页 / 共 3 页
字号:
from sys import argv
from wxPython.wx import *
from wxPython import *
#from wxPython.lib.mixins.listctrl import wxListCtrlAutoWidthMixin
from BitTorrent import version
from BitTorrent.download import download
from threading import Event, Thread, Timer
from os.path import join
from os import getcwd, path, chdir
from BitTorrent.zurllib import urlopen
from interconn import ServerListener, ClientPassParam
from filemanager import TorrentConfigFileManager, TorrentListFileManager
from scheduler import ABCScheduler
from abcdetailframe import ABCDetailFrame
from webbrowser import open_new
from shutil import copyfile
from guimanager import GUIManager
from abc_tweak import ABCTweakFrame
from btmaketorrentgui import DownloadInfo
from aboutmedlg import AboutMeDialog
from abcoptiondlg import ABCOptionDialog
from globaluploaddlg import GlobalUploadDialog


#class ABCListCtrl(wxListCtrl, wxListCtrlAutoWidthMixin):
#    def __init__(self, parent, ID, pos=wxDefaultPosition,
#                 size=wxDefaultSize, style=0):
#        wxListCtrl.__init__(self, parent, ID, pos, size, style)
#        wxListCtrlAutoWidthMixin.__init__(self)

# Define File Drop Target class 
class FileDropTarget(wxFileDropTarget): 
   def __init__(self, obj): 
      # Initialize the wsFileDropTarget Object 
      wxFileDropTarget.__init__(self) 
      # Store the Object Reference for dropped files 
      self.obj = obj 
 
   def OnDropFiles(self, x, y, filenames): 
      for file in filenames:
            filename     = path.split(file)[1]
            torrentsrc   = path.join(self.obj.abcpath, "torrent", filename)
            try:
                f = open(torrentsrc, "r")
                f.close()
                # There is a duplicate .torrent file in /torrent
                dlg = wxMessageDialog(self.obj, "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(file, torrentsrc)
            self.obj.queue.addNewProc(torrentsrc, False)


    
class LocalSettingDialog(wxDialog):
    def __init__(self, parent, ID, title,
                 pos=wxDefaultPosition, size=wxDefaultSize,
                 style=wxDEFAULT_DIALOG_STYLE, index=0):
        
        pre = wxPreDialog()
        pre.Create(parent, ID, title, pos, size, style)
        self.this = pre.this
        
        self.parent = parent
        self.index  = index

        #Add GUI maxupload, maxupload_rate, uploadoption
        # Upload Setting
        #####################
        localinfo = parent.queue.getLocalInfo(self.index)
        loc_maxupload       = localinfo[0]
        loc_maxuploadrate   = localinfo[1]
        loc_uploadopt       = localinfo[2]
        loc_uploadtimeh     = localinfo[3]
        loc_uploadtimem     = localinfo[4]
        loc_uploadratio     = localinfo[5]

        ID_UPLOADRATE    = wxNewId()
        ID_MAXUPLOAD     = wxNewId()
        ID_MAXUPLOADSPIN = wxNewId()
        
        wxStaticBox(self,  -1,  "Upload Setting", wxPoint(10,20), wxSize(245,85))
        wxStaticText(self, -1,  "Maximum uploads:" , wxPoint(25,40))
        wxStaticText(self, -1,  "Maximum upload rate:" , wxPoint(25,65))
        wxStaticText(self, -1,  "(0 = Unlimited)" , wxPoint(135,85))
        wxStaticText(self, -1,  "KB/s" , wxPoint(182,65))

        self.maxupload   = wxTextCtrl(self, ID_MAXUPLOAD,  loc_maxupload, wxPoint(135,35),wxSize(30, -1),wxTE_READONLY|wxTE_RIGHT)
        self.uploadrate  = wxTextCtrl(self, ID_UPLOADRATE, loc_maxuploadrate, wxPoint(135,60),wxSize(40, -1))
        h = self.maxupload.GetSize().height
        self.maxuploadspin = wxSpinButton(self, ID_MAXUPLOADSPIN, wxPoint(165, 35), wxSize(h,h), wxSP_VERTICAL)
        self.maxuploadspin.SetRange(2, 100)
        self.maxuploadspin.SetValue(int(loc_maxupload))

        uploadlist = ['Unlimited upload', 'Continue upload for', 'Upload until UL/DL ratio']
        RBOX1 = wxNewId()        
        self.rb = wxRadioBox(self, RBOX1, "Upload option for completed file",
                        wxPoint(10, 115), wxSize(245, 85),
                        uploadlist, 1, wxRA_SPECIFY_COLS)
        self.rb.SetSelection(int(loc_uploadopt))

        wxStaticText(self, -1, "H", wxPoint(188,155)) # 270-155 = 115
        wxStaticText(self, -1, "M", wxPoint(236,155))
        mtimeval = ['30', '45', '60', '75']
        htimeval = []
        for i in range(0, 24):
            htimeval.append(str(i))
            
        ID_COMBOBOX_HTIME = wxNewId()
        ID_COMBOBOX_MTIME = wxNewId()
        ID_COMBOBOX_RATIO = wxNewId()

        self.cbhtime = wxComboBox(self, ID_COMBOBOX_HTIME, loc_uploadtimeh, wxPoint(150, 149),                                  
                                  wxSize(37, -1), htimeval, wxCB_DROPDOWN|wxCB_READONLY)
        self.cbmtime = wxComboBox(self, ID_COMBOBOX_MTIME, loc_uploadtimem, wxPoint(198, 149),
                                  wxSize(37, -1), mtimeval, wxCB_DROPDOWN|wxCB_READONLY)
        self.cbhtime.SetValue(loc_uploadtimeh)
        self.cbmtime.SetValue(loc_uploadtimem)

        ratioval = ['50', '75', '100', '125', '150','175','200']
        self.cbratio = wxComboBox(self, ID_COMBOBOX_RATIO, loc_uploadratio,
                                  wxPoint(150, 173), wxSize(45, -1), ratioval, wxCB_DROPDOWN|wxCB_READONLY)
        self.cbratio.SetValue(loc_uploadratio)
        wxStaticText(self, -1, "%", wxPoint(195,178))

#        self.cbsuper_seed = wxCheckBox(self, -1, "Use Super-Seed Mode (Only!! For first seed)",
#                                       wxPoint(15, 210))
        ID_APPLY_BUTTON = wxNewId()
        applybtn  = wxButton(self, ID_APPLY_BUTTON, " Apply ",  wxPoint(88, 215))
        cancelbtn = wxButton(self, wxID_CANCEL,     " Cancel ", wxPoint(178,215))

        # Add events
        ###########################
        EVT_SPIN(self, ID_MAXUPLOADSPIN, self.onMaxUploadSpin)
        EVT_BUTTON(self, ID_APPLY_BUTTON, self.onApply)

    def onMaxUploadSpin(self, event):
        self.maxupload.SetValue(str(event.GetPosition()))
            
    def onApply(self, event):
        loc_info = []
        loc_info.append(self.maxupload.GetValue())      #maxupload
        loc_info.append(self.uploadrate.GetValue())     #maxuploadrate
        loc_info.append(str(self.rb.GetSelection()))    #uploadopt     
        loc_info.append(self.cbhtime.GetValue())        #uploadtimeh   
        loc_info.append(self.cbmtime.GetValue())        #uploadtimem   
        loc_info.append(self.cbratio.GetValue())        #uploadratio

        try:
            upload_rate = int(self.uploadrate.GetValue())
        except: #not integer
            dlg = wxMessageDialog(self, "Only integer allows in Maximum upload rate setting"  , "Error!!", wxICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return

        if upload_rate < 3 and upload_rate != 0:
            #display warning
            dlg = wxMessageDialog(self, "Minimum upload rate is 3kB/s or 0 for unlimited upload rate"  , "Error!!", wxICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return

        self.parent.queue.changeLocalInfo(self.index, loc_info)
        # Sent new parameter to process
        #################################
        # must change now
        # - maxupload, maxuploadrate, numsimdownload
        # - uploadoption, uploadtimeh, uploadtimem,
        # - uploadratio, removetorrent
        ##########################################
        # - minport, maxport, setdefaultfolder, defaultfolder will
        #   automatically activate with new torrent
        ##########################################
        self.Destroy()


##############################################################
# Class : ABCPanel
#
# Main ABC Panel class
############################################################## 
class ABCPanel(wxPanel):

    def __init__(self, parent, params, abcparams, abcpath, guiman):
        wxPanel.__init__(self, parent, -1, style=wxWANTS_CHARS)
        
        self.parent     = parent        
        self.params     = params
        self.abcparams  = abcparams
        self.dldlgsem   = 0
        self.abcpath    = abcpath
        self.guiman     = guiman
        
        #Manual Bittorrent Adding UI
        ##############################
        colSizer = wxFlexGridSizer(cols = 1, vgap = 4)

        spacetext = wxStaticText(self, -1, "")
        spacetext.SetFont(wxFont(1, wxDEFAULT, wxNORMAL, wxNORMAL, false))
        colSizer.Add(spacetext, -1, wxEXPAND)
        
        firstlineSizer = wxFlexGridSizer(cols=6, vgap = 3,hgap = 3)
        colSizer.Add(firstlineSizer, -1, wxLEFT)

        firstlineSizer.Add(wxStaticText(self, -1, "  "))
        firstlineSizer.Add(wxStaticText(self, -1, "Bittorent link : "), -1, wxALIGN_CENTER)
        
        ID_BTLINK   = wxNewId()
        ID_ADDLINK  = wxNewId()
        ID_CLEARLINK=  wxNewId()

        self.TextCtrlBTLink = wxTextCtrl(self, ID_BTLINK, "", size=(260, -1))

        firstlineSizer.Add(self.TextCtrlBTLink, -1, wxALIGN_CENTER)
        firstlineSizer.Add(wxButton(self, ID_ADDLINK, "Add Link"), -1, wxALIGN_CENTER)        
        firstlineSizer.Add(wxButton(self, ID_CLEARLINK, "Clear"), -1, wxALIGN_CENTER)
        firstlineSizer.Add(wxStaticText(self, -1, ""), -1, wxALIGN_CENTER)
        firstlineSizer.AddGrowableCol(5)

        secondlineSizer = wxFlexGridSizer(cols=5, vgap = 3, hgap = 3)
        secondlineSizer.Add(wxStaticText(self, -1, "  "))        
        colSizer.Add(secondlineSizer, -1, wxLEFT)
        secondlineSizer.Add(wxStaticText(self, -1, "Bittorent file : "), -1, wxALIGN_CENTER)
        
        ID_ADDTORFROMFILE=wxNewId()
        ID_ADDNONEDEFAULT=wxNewId()
        secondlineSizer.Add(wxButton(self, ID_ADDTORFROMFILE, "Add Torrent File"))
        secondlineSizer.Add(wxButton(self, ID_ADDNONEDEFAULT, "Add Torrent File to non-default location"))
        secondlineSizer.Add(wxStaticText(self, -1, ""), -1, wxALIGN_CENTER)
        secondlineSizer.AddGrowableCol(4)

        # List Control Display UI
        ###############################
        ID_LISTCTRL = wxNewId()
        self.list = wxListCtrl(self, ID_LISTCTRL , style=wxLC_REPORT|wxLC_SINGLE_SEL)
        dragdroplist = FileDropTarget(self)
        self.list.SetDropTarget(dragdroplist)
        colSizer.Add(self.list, -1, wxEXPAND)

        # New option buttons
        ##################################
        bottomline = wxFlexGridSizer(cols=5, vgap=3, hgap=3)
        colSizer.Add(bottomline, -1, wxLEFT)

        ID_CLEARTORRENT = wxNewId()
        ID_MOVELISTUP   = wxNewId()
        ID_MOVELISTDOWN = wxNewId()
        bottomline.Add(wxStaticText(self, -1, "  "))
        bottomline.Add(wxButton(self, ID_MOVELISTUP, "Move Up"), -1, wxALIGN_CENTER)
        bottomline.Add(wxButton(self, ID_MOVELISTDOWN, "Move Down"), -1, wxALIGN_CENTER)
        bottomline.Add(wxButton(self, ID_CLEARTORRENT, "Clear all completed torrents"), -1, wxALIGN_CENTER)
        bottomline.Add(wxStaticText(self, -1, ""), -1, wxALIGN_CENTER)
        bottomline.AddGrowableCol(4)

        
        colSizer.AddGrowableRow(3)
        colSizer.AddGrowableCol(0)
        self.SetSizer(colSizer)
        self.SetAutoLayout(true)
        
        # Read abc.ini for status display
        ####################################
        for rank in range(0, self.guiman.getNumCol()):
            self.list.InsertColumn(rank, self.guiman.getTextfromRank(rank))
            self.list.SetColumnWidth(rank, self.guiman.getValuefromRank(rank))
        
        self.queue  = ABCScheduler(self, self.abcparams, self.guiman)

        # Read old list from torrent.lst
        ####################################
        torrentlistfile = TorrentListFileManager()
        torrentlistfile.open("torrent.lst")
        oldproc_array = []
        while True:
            config = torrentlistfile.readList()
            if config != ["", "", "", "", "", "", ""]: #filename, src, dest, status, prio, downsize, upsize
                oldproc_array.append([config[0], config[1], config[2], config[3], config[4], config[5], config[6]])
            else:
                if len(oldproc_array) != 0:
                    self.queue.addOldProc(oldproc_array)
                break
        # Start single instance server listenner
        ############################################
        self.serverlistener = ServerListener()
        self.serverthread   = Thread(target = self.serverlistener.start, args = [self])
        self.serverthread.setDaemon(false)
        self.serverthread.start()

        #if server start with params run it
        #####################################
        if self.params[0] != "":
            ClientPassParam(self.params[0], self.abcpath)

        # Event
        #############
        EVT_TEXT_ENTER(self, ID_BTLINK, self.AddTorrentLink)
        EVT_BUTTON(self, ID_ADDLINK, self.AddTorrentLink)
        EVT_BUTTON(self, ID_CLEARLINK, self.ClearLink) 
        EVT_BUTTON(self, ID_ADDTORFROMFILE, self.AddTorrentFile)
        EVT_BUTTON(self, ID_ADDNONEDEFAULT , self.AddTorrentNoneDefault)

        EVT_BUTTON(self, ID_CLEARTORRENT, self.onClearAllCompleted)
        EVT_BUTTON(self, ID_MOVELISTUP, self.onItemMoveUp)
        EVT_BUTTON(self, ID_MOVELISTDOWN, self.onItemMoveDown)


        EVT_LIST_ITEM_RIGHT_CLICK(self, ID_LISTCTRL, self.OnItemSelected)
        EVT_KEY_DOWN(self.list, self.IgnoreEvent)
        EVT_KEY_UP(self.list, self.IgnoreEvent)
        EVT_CHAR(self.list, self.IgnoreEvent)
        EVT_LEFT_DOWN(self.list, self.OnLeftDown)
        EVT_RIGHT_DOWN(self.list, self.OnRightDown)
        EVT_LEFT_DCLICK(self.list, self.OnLeftDClick)
        self.x = 0
        self.y = 0
        self.selectedROW = -1

    def IgnoreEvent(self, event):
        pass

⌨️ 快捷键说明

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