📄 configreader.py
字号:
colsizer = wxFlexGridSizer(cols = 1, hgap = 13, vgap = 13) warningtext = StaticText('CHANGE THESE SETTINGS AT YOUR OWN RISK', self.FONT+4, true, 'Red') colsizer.Add(warningtext, 1, wxALIGN_CENTER) ip_data = wxTextCtrl(parent = panel, id = -1, value = self.advancedConfig['ip'], size = (self.FONT*13, int(self.FONT*2.2)), style = wxTE_PROCESS_TAB) ip_data.SetFont(self.default_font) bind_data = wxTextCtrl(parent = panel, id = -1, value = self.advancedConfig['bind'], size = (self.FONT*7, int(self.FONT*2.2)), style = wxTE_PROCESS_TAB) bind_data.SetFont(self.default_font) minpeers_data = wxSpinCtrl(panel, -1, '', (-1,-1), (self.FONT*7, -1)) minpeers_data.SetFont(self.default_font) minpeers_data.SetRange(10,100) minpeers_data.SetValue(self.advancedConfig['min_peers']) # max_initiate = 2*minpeers displayinterval_data = wxSpinCtrl(panel, -1, '', (-1,-1), (self.FONT*7, -1)) displayinterval_data.SetFont(self.default_font) displayinterval_data.SetRange(100,2000) displayinterval_data.SetValue(int(self.advancedConfig['display_interval']*1000)) alloctype_data=wxChoice(panel, -1, choices = ['normal', 'background', 'pre-allocate', 'sparse']) alloctype_data.SetFont(self.default_font) alloctype_data.SetStringSelection(self.advancedConfig['alloc_type']) allocrate_data = wxSpinCtrl(panel, -1, '', (-1,-1), (self.FONT*7,-1)) allocrate_data.SetFont(self.default_font) allocrate_data.SetRange(1,10) allocrate_data.SetValue(int(self.advancedConfig['alloc_rate'])) maxfilesopen_choices = ['50', '100', '200', 'no limit '] maxfilesopen_data=wxChoice(panel, -1, choices = maxfilesopen_choices) maxfilesopen_data.SetFont(self.default_font) setval = self.advancedConfig['max_files_open'] if setval == 0: setval = 'no limit ' else: setval = str(setval) if not setval in maxfilesopen_choices: setval = maxfilesopen_choices[0] maxfilesopen_data.SetStringSelection(setval)
maxconnections_choices = ['no limit ', '20', '30', '40', '60', '100', '200'] maxconnections_data=wxChoice(panel, -1, choices = maxconnections_choices) maxconnections_data.SetFont(self.default_font) setval = self.advancedConfig['max_connections'] if setval == 0: setval = 'no limit ' else: setval = str(setval) if not setval in maxconnections_choices: setval = maxconnections_choices[0] maxconnections_data.SetStringSelection(setval)
superseeder_data=wxChoice(panel, -1, choices = ['normal', 'super-seed']) superseeder_data.SetFont(self.default_font) superseeder_data.SetSelection(self.advancedConfig['super_seeder']) twocolsizer = wxFlexGridSizer(cols = 2, hgap = 20) datasizer = wxFlexGridSizer(cols = 2, vgap = 2) datasizer.Add(StaticText('Local IP: '), 1, wxALIGN_CENTER_VERTICAL) datasizer.Add(ip_data) datasizer.Add(StaticText('IP to bind to: '), 1, wxALIGN_CENTER_VERTICAL) datasizer.Add(bind_data) datasizer.Add(StaticText('Minimum number of peers: '), 1, wxALIGN_CENTER_VERTICAL) datasizer.Add(minpeers_data) datasizer.Add(StaticText('Display interval (ms): '), 1, wxALIGN_CENTER_VERTICAL) datasizer.Add(displayinterval_data) datasizer.Add(StaticText('Disk allocation type:'), 1, wxALIGN_CENTER_VERTICAL) datasizer.Add(alloctype_data) datasizer.Add(StaticText('Allocation rate (MiB/s):'), 1, wxALIGN_CENTER_VERTICAL) datasizer.Add(allocrate_data) datasizer.Add(StaticText('Max files open:'), 1, wxALIGN_CENTER_VERTICAL) datasizer.Add(maxfilesopen_data) datasizer.Add(StaticText('Max peer connections:'), 1, wxALIGN_CENTER_VERTICAL) datasizer.Add(maxconnections_data) datasizer.Add(StaticText('Default seeding mode:'), 1, wxALIGN_CENTER_VERTICAL) datasizer.Add(superseeder_data) twocolsizer.Add(datasizer) infosizer = wxFlexGridSizer(cols = 1) self.hinttext = StaticText('', self.FONT, false, 'Blue') infosizer.Add(self.hinttext, 1, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL) infosizer.SetMinSize((180,100)) twocolsizer.Add(infosizer, 1, wxEXPAND) colsizer.Add(twocolsizer) savesizer = wxGridSizer(cols = 3, hgap = 20) okButton = wxButton(panel, -1, 'OK')# okButton.SetFont(self.default_font) savesizer.Add(okButton, 0, wxALIGN_CENTER) cancelButton = wxButton(panel, -1, 'Cancel')# cancelButton.SetFont(self.default_font) savesizer.Add(cancelButton, 0, wxALIGN_CENTER) defaultsButton = wxButton(panel, -1, 'Revert to Defaults')# defaultsButton.SetFont(self.default_font) savesizer.Add(defaultsButton, 0, wxALIGN_CENTER) colsizer.Add(savesizer, 1, wxALIGN_CENTER) resizewarningtext=StaticText('None of these settings will take effect until the next time you start BitTorrent', self.FONT-2) colsizer.Add(resizewarningtext, 1, wxALIGN_CENTER) border = wxBoxSizer(wxHORIZONTAL) border.Add(colsizer, 1, wxEXPAND | wxALL, 4) panel.SetSizer(border) panel.SetAutoLayout(true) def setDefaults(self, ref = self): try: ip_data.SetValue(ref.defaults.get('ip')) bind_data.SetValue(ref.defaults.get('bind')) minpeers_data.SetValue(ref.defaults.get('min_peers')) displayinterval_data.SetValue(int(ref.defaults.get('display_interval')*1000)) alloctype_data.SetStringSelection(ref.defaults.get('alloc_type')) allocrate_data.SetValue(int(ref.defaults.get('alloc_rate'))) setval = ref.defaults.get('max_files_open') if setval == 0: setval = 'no limit ' else: setval = str(setval) if not setval in maxfilesopen_choices: setval = maxfilesopen_choices[0] maxfilesopen_data.SetStringSelection(setval) setval = ref.defaults.get('max_connections') if setval == 0: setval = 'no limit ' else: setval = str(setval) if not setval in maxconnections_choices: setval = maxconnections_choices[0] maxconnections_data.SetStringSelection(setval) superseeder_data.SetSelection(int(ref.defaults.get('super_seeder'))) except: ref.parent.exception() def saveConfigs(self, ref = self): try: ref.advancedConfig['ip'] = ip_data.GetValue() ref.advancedConfig['bind'] = bind_data.GetValue() ref.advancedConfig['min_peers'] = minpeers_data.GetValue() ref.advancedConfig['display_interval'] = float(displayinterval_data.GetValue())/1000 ref.advancedConfig['alloc_type'] = alloctype_data.GetStringSelection() ref.advancedConfig['alloc_rate'] = float(allocrate_data.GetValue()) try: ref.advancedConfig['max_files_open'] = int(maxfilesopen_data.GetStringSelection()) except: # if it ain't a number, it must be "no limit" ref.advancedConfig['max_files_open'] = 0 try: ref.advancedConfig['max_connections'] = int(maxconnections_data.GetStringSelection()) ref.advancedConfig['max_initiate'] = min(
2*ref.advancedConfig['min_peers'], ref.advancedConfig['max_connections'])
except: # if it ain't a number, it must be "no limit" ref.advancedConfig['max_connections'] = 0
ref.advancedConfig['max_initiate'] = 2*ref.advancedConfig['min_peers']
ref.advancedConfig['super_seeder']=int(superseeder_data.GetSelection()) ref.advancedMenuBox.Close() except: ref.parent.exception() def cancelConfigs(self, ref = self): ref.advancedMenuBox.Close() def ip_hint(self, ref = self): ref.hinttext.SetLabel('\n\n\nThe IP reported to the tracker.\n' + 'unless the tracker is on the\n' + 'same intranet as this client,\n' + 'the tracker will autodetect the\n' + "client's IP and ignore this\n" + "value.") def bind_hint(self, ref = self): ref.hinttext.SetLabel('\n\n\nThe IP the client will bind to.\n' + 'Only useful if your machine is\n' + 'directly handling multiple IPs.\n' + "If you don't know what this is,\n" + "leave it blank.") def minpeers_hint(self, ref = self): ref.hinttext.SetLabel('\n\n\nThe minimum number of peers the\n' + 'client tries to stay connected\n' + 'with. Do not set this higher\n' + 'unless you have a very fast\n' + "connection and a lot of system\n" + "resources.") def displayinterval_hint(self, ref = self): ref.hinttext.SetLabel('\n\n\nHow often to update the\n' + 'graphical display, in 1/1000s\n' + 'of a second. Setting this too low\n' + "will strain your computer's\n" + "processor and video access.") def alloctype_hint(self, ref = self): ref.hinttext.SetLabel('\n\nHow to allocate disk space.\n' + 'normal allocates space as data is\n' + 'received, background also adds\n' + "space in the background, pre-\n" + "allocate reserves up front, and\n" + 'sparse is only for filesystems\n' + 'that support it by default.') def allocrate_hint(self, ref = self): ref.hinttext.SetLabel('\n\n\nAt what rate to allocate disk\n' + 'space when allocating in the\n' + 'background. Set this too high on a\n' + "slow filesystem and your download\n" + "will slow to a crawl.") def maxfilesopen_hint(self, ref = self): ref.hinttext.SetLabel('\n\n\nThe maximum number of files to\n' + 'keep open at the same time. Zero\n' + 'means no limit. Please note that\n' + "if this option is in effect,\n" + "files are not guaranteed to be\n" + "locked.") def maxconnections_hint(self, ref = self): ref.hinttext.SetLabel('\n\nSome operating systems, most\n' + 'notably Windows 9x/ME combined\n' + 'with certain network drivers,\n' + "cannot handle more than a certain\n" + "number of open ports. If the\n" + "client freezes, try setting this\n" + "to 60 or below.") def superseeder_hint(self, ref = self): ref.hinttext.SetLabel('\n\nThe "super-seed" method allows\n' + 'a single source to more efficiently\n' + 'seed a large torrent, but is not\n' + "necessary in a well-seeded torrent,\n" + "and causes problems with statistics.\n" + "Unless you routinely seed torrents\n" + "you can enable this by selecting\n" + '"SUPER-SEED" for connection type.\n' + '(once enabled it does not turn off.)') EVT_BUTTON(self.advancedMenuBox, okButton.GetId(), saveConfigs) EVT_BUTTON(self.advancedMenuBox, cancelButton.GetId(), cancelConfigs) EVT_BUTTON(self.advancedMenuBox, defaultsButton.GetId(), setDefaults) EVT_ENTER_WINDOW(ip_data, ip_hint) EVT_ENTER_WINDOW(bind_data, bind_hint) EVT_ENTER_WINDOW(minpeers_data, minpeers_hint) EVT_ENTER_WINDOW(displayinterval_data, displayinterval_hint) EVT_ENTER_WINDOW(alloctype_data, alloctype_hint) EVT_ENTER_WINDOW(allocrate_data, allocrate_hint) EVT_ENTER_WINDOW(maxfilesopen_data, maxfilesopen_hint) EVT_ENTER_WINDOW(maxconnections_data, maxconnections_hint) EVT_ENTER_WINDOW(superseeder_data, superseeder_hint) self.advancedMenuBox.Show () border.Fit(panel) self.advancedMenuBox.Fit() except: self.parent.exception() def CloseAdvanced(self): if self.advancedMenuBox is not None: try: self.advancedMenuBox.Close () except wxPyDeadObjectError, e: self.advancedMenuBox = None def Close(self): self.CloseAdvanced() if self.configMenuBox is not None: try: self.configMenuBox.Close () except wxPyDeadObjectError, e: self.configMenuBox = None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -