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

📄 globaluploaddlg.py

📁 BitTorrentABC-Linux-V.2.4.3源码
💻 PY
字号:
from wxPython.wx import *
from wxPython import *
from webbrowser import open_new
from threading import Thread
from filemanager import *
from os import path
from os.path import join

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


        #Add GUI maxupload, maxupload_rate, uploadoption
        # Upload Setting
        #####################
        loc_maxupload       = self.parent.abcparams['maxupload']
        loc_maxuploadrate   = self.parent.abcparams['maxuploadrate']
        loc_uploadopt       = self.parent.abcparams['uploadoption']
        loc_uploadtimeh     = self.parent.abcparams['uploadtimeh']
        loc_uploadtimem     = self.parent.abcparams['uploadtimem']
        loc_uploadratio     = self.parent.abcparams['uploadratio']

        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))

        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):
        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

        # Set new value to abcparams
        ##############################
        self.parent.abcparams['maxupload']     = self.maxupload.GetValue()
        self.parent.abcparams['maxuploadrate'] = self.uploadrate.GetValue()
        self.parent.abcparams['uploadoption'] = str(self.rb.GetSelection())
        self.parent.abcparams['uploadtimeh'] = self.cbhtime.GetValue()
        self.parent.abcparams['uploadtimem'] = self.cbmtime.GetValue()
        self.parent.abcparams['uploadratio'] = self.cbratio.GetValue()


        # Saving Value to abc.conf
        ##############################
        abcconfig = TorrentConfigFileManager()
        abcconfig.open(path.join(self.parent.abcpath,"abc.conf"), "w")
        abcconfig.writeConfig("minport",         self.parent.abcparams['minport'])
        abcconfig.writeConfig("maxport",         self.parent.abcparams['maxport'])
        abcconfig.writeConfig("maxupload",       self.parent.abcparams['maxupload'])
        abcconfig.writeConfig("maxuploadrate",   self.parent.abcparams['maxuploadrate'])
        abcconfig.writeConfig("numsimdownload",  self.parent.abcparams['numsimdownload'])
        abcconfig.writeConfig("uploadoption",    self.parent.abcparams['uploadoption'])
        abcconfig.writeConfig("uploadtimeh",     self.parent.abcparams['uploadtimeh'])
        abcconfig.writeConfig("uploadtimem",     self.parent.abcparams['uploadtimem'])
        abcconfig.writeConfig("uploadratio",     self.parent.abcparams['uploadratio'])
        abcconfig.writeConfig("removetorrent",   self.parent.abcparams['removetorrent'])
        abcconfig.writeConfig("setdefaultfolder",self.parent.abcparams['setdefaultfolder'])
        abcconfig.writeConfig("defaultfolder",   self.parent.abcparams['defaultfolder'])
        abcconfig.writeConfig("mintray",         self.parent.abcparams['mintray'])
        abcconfig.writeConfig("ip",              self.parent.abcparams['ip'])
        abcconfig.writeConfig("bind",            self.parent.abcparams['bind'])
        abcconfig.writeConfig("min_peers",       self.parent.abcparams['min_peers'])
        abcconfig.writeConfig("max_initiate",    self.parent.abcparams['max_initiate'])
        abcconfig.writeConfig("alloc_type",      self.parent.abcparams['alloc_type'])
        abcconfig.writeConfig("alloc_rate",      self.parent.abcparams['alloc_rate'])
        abcconfig.writeConfig("max_files_open",  self.parent.abcparams['max_files_open'])
        abcconfig.writeConfig("max_connections", self.parent.abcparams['max_connections'])
        abcconfig.close()
        self.parent.window.changeABCParams(self.parent.abcparams)

        self.Destroy()

⌨️ 快捷键说明

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