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

📄 configreader.py

📁 ABC-win32-v3.1 一个P2P软源代码
💻 PY
📖 第 1 页 / 共 4 页
字号:
                    self.config['gui_displaystats']=int(self.gui_displaystats_checkbox.GetValue())
                    self.config['gui_displaymiscstats']=int(self.gui_displaymiscstats_checkbox.GetValue())
                    self.config['security']=int(self.security_checkbox.GetValue())
                    self.config['auto_kick']=int(self.autokick_checkbox.GetValue())
                    buffering=int(self.buffering_checkbox.GetValue())
                    self.config['buffer_reads']=buffering
                    if buffering:
                        self.config['write_buffer_size']=self.defaults['write_buffer_size']
                    else:
                        self.config['write_buffer_size']=0
                    self.config['breakup_seed_bitfield']=int(self.breakup_checkbox.GetValue())
                    if self.autoflush_checkbox.GetValue():
                        self.config['auto_flush']=5
                    else:
                        self.config['auto_flush']=0
                    if sys.version_info >= (2, 3) and socket.has_ipv6:
                        self.config['ipv6_enabled']=int(self.ipv6enabled_checkbox.GetValue())
                    self.config['gui_forcegreenonfirewall']=int(self.gui_forcegreenonfirewall_checkbox.GetValue())
                    self.config['minport']=self.minport_data.GetValue()
                    self.config['maxport']=self.maxport_data.GetValue()
                    self.config['random_port']=int(self.randomport_checkbox.GetValue())
                    self.config['gui_font']=self.gui_font_data.GetValue()
                    self.config['gui_ratesettingsdefault']=self.gui_ratesettingsdefault_data.GetStringSelection()
                    self.config['max_download_rate']=self.maxdownload_data.GetValue()
                    self.config['gui_ratesettingsmode']=self.gui_ratesettingsmode_data.GetStringSelection()
                    self.config['gui_default_savedir']=self.gui_default_savedir_ctrl.GetValue()
                    self.config['gui_saveas_ask']=1-self.gui_savemode_data.GetSelection()
                    self.config['gui_checkingcolor']=ColorToHex(self.checkingcolor)
                    self.config['gui_downloadcolor']=ColorToHex(self.downloadcolor)
                    self.config['gui_seedingcolor']=ColorToHex(self.seedingcolor)
                    
                    if (sys.platform == 'win32'):
                        self.config['win32_taskbar_icon']=int(self.win32_taskbar_icon_checkbox.GetValue())
        #                self.config['upnp_nat_access']=int(self.upnp_checkbox.GetValue())
                        self.config['upnp_nat_access']=self.upnp_data.GetSelection()
        
                    if self.advancedConfig:
                        for key, val in self.advancedConfig.items():
                            self.config[key] = val
        
                    self.writeConfigFile()
                    self._configReset = True
                    self.Close()
                except:
                    self.parent.exception()
    
            def cancelConfigs(evt, self = self):
                self.Close()
    
            def savepath_set(evt, self = self):
                try:
                    d = self.gui_default_savedir_ctrl.GetValue()
                    if d == '':
                        d = self.config['last_saved']
                    dl = wxDirDialog(self.panel, 'Choose a default directory to save to', 
                        d, style = wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON)
                    if dl.ShowModal() == wxID_OK:
                        self.gui_default_savedir_ctrl.SetValue(dl.GetPath())
                except:
                    self.parent.exception()
    
            def checkingcoloricon_set(evt, self = self):
                try:
                    newcolor = self.getColorFromUser(self.panel, self.checkingcolor)
                    self.setColorIcon(self.checkingcolor_icon, self.checkingcolor_iconptr, newcolor)
                    self.checkingcolor = newcolor
                except:
                    self.parent.exception()
    
            def downloadcoloricon_set(evt, self = self):
                try:
                    newcolor = self.getColorFromUser(self.panel, self.downloadcolor)
                    self.setColorIcon(self.downloadcolor_icon, self.downloadcolor_iconptr, newcolor)
                    self.downloadcolor = newcolor
                except:
                    self.parent.exception()
    
            def seedingcoloricon_set(evt, self = self):
                try:
                    newcolor = self.getColorFromUser(self.panel, self.seedingcolor)
                    self.setColorIcon(self.seedingcolor_icon, self.seedingcolor_iconptr, newcolor)
                    self.seedingcolor = newcolor
                except:
                    self.parent.exception()

            EVT_BUTTON(self.configMenuBox, saveButton.GetId(), saveConfigs)
            EVT_BUTTON(self.configMenuBox, cancelButton.GetId(), cancelConfigs)
            EVT_BUTTON(self.configMenuBox, defaultsButton.GetId(), setDefaults)
            EVT_BUTTON(self.configMenuBox, advancedButton.GetId(), self.advancedMenu)
            EVT_BUTTON(self.configMenuBox, savepathButton.GetId(), savepath_set)
            EVT_LEFT_DOWN(self.checkingcolor_iconptr, checkingcoloricon_set)
            EVT_LEFT_DOWN(self.downloadcolor_iconptr, downloadcoloricon_set)
            EVT_LEFT_DOWN(self.seedingcolor_iconptr, seedingcoloricon_set)
    
            self.configMenuBox.Show()
            border.Fit(panel)
            self.configMenuBox.Fit()
        except:
            self.parent.exception()


    def Close(self):
        self.CloseAdvanced()
        if self.configMenuBox is not None:
            try:
                self.configMenuBox.Close()
            except wxPyDeadObjectError, e:
                pass
            self.configMenuBox = None

    def advancedMenu(self, event = None):
        try:
            if not self.advancedConfig:
                for key in ['ip', 'bind', 'min_peers', 'max_initiate', 'display_interval', 
            'alloc_type', 'alloc_rate', 'max_files_open', 'max_connections', 'super_seeder', 
            'ipv6_binds_v4', 'double_check', 'triple_check', 'lock_files', 'lock_while_reading', 
            'expire_cache_data']:
                    self.advancedConfig[key] = self.config[key]
    
            if (self.advancedMenuBox is not None):
                try:
                    self.advancedMenuBox.Close()
                except wxPyDeadObjectError, e:
                    self.advancedMenuBox = None
    
            self.advancedMenuBox = wxFrame(None, -1, 'BitTorrent Advanced Preferences', size = (1, 1), 
                                style = wxDEFAULT_FRAME_STYLE|wxFULL_REPAINT_ON_RESIZE)
            if (sys.platform == 'win32'):
                self.advancedMenuBox.SetIcon(self.icon)
    
            panel = wxPanel(self.advancedMenuBox, -1)
    #        self.panel = panel
    
            def StaticText(text, font = self.FONT, underline = False, color = None, panel = panel):
                x = wxStaticText(panel, -1, text, style = wxALIGN_LEFT)
                x.SetFont(wxFont(font, wxDEFAULT, wxNORMAL, wxNORMAL, underline))
                if color is not None:
                    x.SetForegroundColour(color)
                return x
    
            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)
    
            self.ip_data = wxTextCtrl(parent = panel, id = -1, 
                        value = self.advancedConfig['ip'], 
                        size = (self.FONT*13, int(self.FONT*2.2)), style = wxTE_PROCESS_TAB)
            self.ip_data.SetFont(self.default_font)
            
            self.bind_data = wxTextCtrl(parent = panel, id = -1, 
                        value = self.advancedConfig['bind'], 
                        size = (self.FONT*13, int(self.FONT*2.2)), style = wxTE_PROCESS_TAB)
            self.bind_data.SetFont(self.default_font)
            
            if sys.version_info >= (2, 3) and socket.has_ipv6:
                self.ipv6bindsv4_data=wxChoice(panel, -1, 
                                 choices = ['separate sockets', 'single socket'])
                self.ipv6bindsv4_data.SetFont(self.default_font)
                self.ipv6bindsv4_data.SetSelection(self.advancedConfig['ipv6_binds_v4'])
    
            self.minpeers_data = wxSpinCtrl(panel, -1, '', (-1, -1), (self.FONT*7, -1))
            self.minpeers_data.SetFont(self.default_font)
            self.minpeers_data.SetRange(10, 100)
            self.minpeers_data.SetValue(self.advancedConfig['min_peers'])
            # max_initiate = 2*minpeers
    
            self.displayinterval_data = wxSpinCtrl(panel, -1, '', (-1, -1), (self.FONT*7, -1))
            self.displayinterval_data.SetFont(self.default_font)
            self.displayinterval_data.SetRange(100, 2000)
            self.displayinterval_data.SetValue(int(self.advancedConfig['display_interval']*1000))
    
            self.alloctype_data = wxChoice(panel, -1, 
                             choices = ['normal', 'background', 'pre-allocate', 'sparse'])
            self.alloctype_data.SetFont(self.default_font)
            self.alloctype_data.SetStringSelection(self.advancedConfig['alloc_type'])
    
            self.allocrate_data = wxSpinCtrl(panel, -1, '', (-1, -1), (self.FONT*7, -1))
            self.allocrate_data.SetFont(self.default_font)
            self.allocrate_data.SetRange(1, 100)
            self.allocrate_data.SetValue(int(self.advancedConfig['alloc_rate']))
    
            self.locking_data = wxChoice(panel, -1, 
                               choices = ['no locking', 'lock while writing', 'lock always'])
            self.locking_data.SetFont(self.default_font)
            if self.advancedConfig['lock_files']:
                if self.advancedConfig['lock_while_reading']:
                    self.locking_data.SetSelection(2)
                else:
                    self.locking_data.SetSelection(1)
            else:
                self.locking_data.SetSelection(0)
    
            self.doublecheck_data = wxChoice(panel, -1, 
                               choices = ['no extra checking', 'double-check', 'triple-check'])
            self.doublecheck_data.SetFont(self.default_font)
            if self.advancedConfig['double_check']:
                if self.advancedConfig['triple_check']:
                    self.doublecheck_data.SetSelection(2)
                else:
                    self.doublecheck_data.SetSelection(1)
            else:
                self.doublecheck_data.SetSelection(0)
    
            self.maxfilesopen_choices = ['50', '100', '200', 'no limit ']
            self.maxfilesopen_data = wxChoice(panel, -1, choices = self.maxfilesopen_choices)
            self.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 self.maxfilesopen_choices:
                setval = self.maxfilesopen_choices[0]
            self.maxfilesopen_data.SetStringSelection(setval)
    
            self.maxconnections_choices = ['no limit ', '20', '30', '40', '50', '60', '100', '200']
            self.maxconnections_data = wxChoice(panel, -1, choices = self.maxconnections_choices)
            self.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 self.maxconnections_choices:
                setval = self.maxconnections_choices[0]
            self.maxconnections_data.SetStringSelection(setval)
    
            self.superseeder_data = wxChoice(panel, -1, 
                             choices = ['normal', 'super-seed'])
            self.superseeder_data.SetFont(self.default_font)
            self.superseeder_data.SetSelection(self.advancedConfig['super_seeder'])
    
            self.expirecache_choices = ['never ', '3', '5', '7', '10', '15', '30', '60', '90']
            self.expirecache_data = wxChoice(panel, -1, choices = self.expirecache_choices)
            setval = self.advancedConfig['expire_cache_data']
            if setval == 0:
                setval = 'never '
            else:
                setval = str(setval)
            if not setval in self.expirecache_choices:
                setval = self.expirecache_choices[0]
            self.expirecache_data.SetFont(self.default_font)
            self.expirecache_data.SetStringSelection(setval)
           
    
            twocolsizer = wxFlexGridSizer(cols = 2, hgap = 20)
            datasizer = wxFlexGridSizer(cols = 2, vgap = 2)
            datasizer.Add(StaticText('Local IP: '), 1, wxALIGN_CENTER_VERTICAL)
            datasizer.Add(self.ip_data)
            datasizer.Add(StaticText('IP to bind to: '), 1, wxALIGN_CENTER_VERTICAL)
            datasizer.Add(self.bind_data)
            if sys.version_info >= (2, 3) and socket.has_ipv6:
                datasizer.Add(StaticText('IPv6 socket handling: '), 1, wxALIGN_CENTER_VERTICAL)
                datasizer.Add(self.ipv6bindsv4_data)
            datasizer.Add(StaticText('Minimum number of peers: '), 1, wxALIGN_CENTER_VERTICAL)
            datasizer.Add(self.minpeers_data)
            datasizer.Add(StaticText('Display interval (ms): '), 1, wxALIGN_CENTER_VERTICAL)
            datasizer.Add(self.displayinterval_data)
            datasizer.Add(StaticText('Disk allocation type:'), 1, wxALIGN_CENTER_VERTICAL)
            datasizer.Add(self.alloctype_data)
            datasizer.Add(StaticText('Allocation rate (MiB/s):'), 1, wxALIGN_CENTER_VERTICAL)
            datasizer.Add(self.allocrate_data)
            datasizer.Add(StaticText('File locking:'), 1, wxALIGN_CENTER_VERTICAL)
            datasizer.Add(self.locking_data)
            datasizer.Add(StaticText('Extra data checking:'), 1, wxALIGN_CENTER_VERTICAL)
            datasizer.Add(self.doublecheck_data)
            datasizer.Add(StaticText('Max files open:'), 1, wxALIGN_CENTER_VERTICAL)
            datasizer.Add(self.maxfilesopen_data)

⌨️ 快捷键说明

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