📄 configreader.py
字号:
#written by John Hoffmanfrom ConnChoice import *from wxPython.wx import *from types import IntType, FloatType, StringTypefrom download_bt1 import defaultsfrom ConfigDir import ConfigDirimport sys,osimport socketfrom parseargs import defaultargstry: Trueexcept: True = 1 False = 0 try: wxFULL_REPAINT_ON_RESIZEexcept: wxFULL_REPAINT_ON_RESIZE = 0 # fix for wx pre-2.5if (sys.platform == 'win32'): _FONT = 9else: _FONT = 10def HexToColor(s): r,g,b = s.split(' ') return wxColour(red=int(r,16), green=int(g,16), blue=int(b,16)) def hex2(c): h = hex(c)[2:] if len(h) == 1: h = '0'+h return hdef ColorToHex(c): return hex2(c.Red()) + ' ' + hex2(c.Green()) + ' ' + hex2(c.Blue())ratesettingslist = []for x in connChoices: if not x.has_key('super-seed'): ratesettingslist.append(x['name'])configFileDefaults = [ #args only available for the gui client ('win32_taskbar_icon', 1, "whether to iconize do system try or not on win32"), ('gui_stretchwindow', 0, "whether to stretch the download status window to fit the torrent name"), ('gui_displaystats', 1, "whether to display statistics on peers and seeds"), ('gui_displaymiscstats', 1, "whether to display miscellaneous other statistics"), ('gui_ratesettingsdefault', ratesettingslist[0], "the default setting for maximum upload rate and users"), ('gui_ratesettingsmode', 'full', "what rate setting controls to display; options are 'none', 'basic', and 'full'"), ('gui_forcegreenonfirewall', 0, "forces the status icon to be green even if the client seems to be firewalled"), ('gui_default_savedir', '', "default save directory"), ('last_saved', '', # hidden; not set in config "where the last torrent was saved"), ('gui_font', _FONT, "the font size to use"), ('gui_saveas_ask', -1, "whether to ask where to download to (0 = never, 1 = always, -1 = automatic resume"),]def setwxconfigfiledefaults(): CHECKINGCOLOR = ColorToHex(wxSystemSettings_GetColour(wxSYS_COLOUR_3DSHADOW)) DOWNLOADCOLOR = ColorToHex(wxSystemSettings_GetColour(wxSYS_COLOUR_ACTIVECAPTION)) configFileDefaults.extend([ ('gui_checkingcolor', CHECKINGCOLOR, "progress bar checking color"), ('gui_downloadcolor', DOWNLOADCOLOR, "progress bar downloading color"), ('gui_seedingcolor', '00 FF 00', "progress bar seeding color"), ])defaultsToIgnore = ['responsefile', 'url', 'priority']class configReader: def __init__(self): self.configfile = wxConfig("BitTorrent",style=wxCONFIG_USE_LOCAL_FILE) self.configMenuBox = None self.advancedMenuBox = None self._configReset = True # run reset for the first time setwxconfigfiledefaults() defaults.extend(configFileDefaults) self.defaults = defaultargs(defaults) self.configDir = ConfigDir('gui') self.configDir.setDefaults(defaults,defaultsToIgnore) if self.configDir.checkConfig(): self.config = self.configDir.loadConfig() else: self.config = self.configDir.getConfig() self.importOldGUIConfig() self.configDir.saveConfig() updated = False # make all config default changes here if self.config['gui_ratesettingsdefault'] not in ratesettingslist: self.config['gui_ratesettingsdefault'] = ( self.defaults['gui_ratesettingsdefault'] ) updated = True if self.config['ipv6_enabled'] and ( sys.version_info < (2,3) or not socket.has_ipv6 ): self.config['ipv6_enabled'] = 0 updated = True for c in ['gui_checkingcolor','gui_downloadcolor','gui_seedingcolor']: try: HexToColor(self.config[c]) except: self.config[c] = self.defaults[c] updated = True if updated: self.configDir.saveConfig() self.configDir.deleteOldCacheData(self.config['expire_cache_data']) def importOldGUIConfig(self): oldconfig = wxConfig("BitTorrent",style=wxCONFIG_USE_LOCAL_FILE) cont, s, i = oldconfig.GetFirstEntry() if not cont: oldconfig.DeleteAll() return False while cont: # import old config data if self.config.has_key(s): t = oldconfig.GetEntryType(s) try: if t == 1: assert type(self.config[s]) == type('') self.config[s] = oldconfig.Read(s) elif t == 2 or t == 3: assert type(self.config[s]) == type(1) self.config[s] = int(oldconfig.ReadInt(s)) elif t == 4: assert type(self.config[s]) == type(1.0) self.config[s] = oldconfig.ReadFloat(s) except: pass cont, s, i = oldconfig.GetNextEntry(i)# oldconfig.DeleteAll() return True def resetConfigDefaults(self): for p,v in self.defaults.items(): if not p in defaultsToIgnore: self.config[p] = v self.configDir.saveConfig() def writeConfigFile(self): self.configDir.saveConfig() def WriteLastSaved(self, l): self.config['last_saved'] = l self.configDir.saveConfig() def getcheckingcolor(self): return HexToColor(self.config['gui_checkingcolor']) def getdownloadcolor(self): return HexToColor(self.config['gui_downloadcolor']) def getseedingcolor(self): return HexToColor(self.config['gui_seedingcolor']) def configReset(self): r = self._configReset self._configReset = False return r def getConfigDir(self): return self.configDir def getIconDir(self): return self.configDir.getIconDir() def getTorrentData(self,t): return self.configDir.getTorrentData(t) def setColorIcon(self, xxicon, xxiconptr, xxcolor): idata = wxMemoryDC() idata.SelectObject(xxicon) idata.SetBrush(wxBrush(xxcolor,wxSOLID)) idata.DrawRectangle(0,0,16,16) idata.SelectObject(wxNullBitmap) xxiconptr.Refresh() def getColorFromUser(self, parent, colInit): data = wxColourData() if colInit.Ok(): data.SetColour(colInit) data.SetCustomColour(0, self.checkingcolor) data.SetCustomColour(1, self.downloadcolor) data.SetCustomColour(2, self.seedingcolor) dlg = wxColourDialog(parent,data) if not dlg.ShowModal(): return colInit return dlg.GetColourData().GetColour() def configMenu(self, parent): self.parent = parent try: self.FONT = self.config['gui_font'] self.default_font = wxFont(self.FONT, wxDEFAULT, wxNORMAL, wxNORMAL, False) self.checkingcolor = HexToColor(self.config['gui_checkingcolor']) self.downloadcolor = HexToColor(self.config['gui_downloadcolor']) self.seedingcolor = HexToColor(self.config['gui_seedingcolor']) if (self.configMenuBox is not None): try: self.configMenuBox.Close() except wxPyDeadObjectError, e: self.configMenuBox = None self.configMenuBox = wxFrame(None, -1, 'BitTorrent Preferences', size = (1,1), style = wxDEFAULT_FRAME_STYLE|wxFULL_REPAINT_ON_RESIZE) if (sys.platform == 'win32'): self.icon = self.parent.icon self.configMenuBox.SetIcon(self.icon) panel = wxPanel(self.configMenuBox, -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, vgap = 8) self.gui_stretchwindow_checkbox = wxCheckBox(panel, -1, "Stretch window to fit torrent name *") self.gui_stretchwindow_checkbox.SetFont(self.default_font) self.gui_stretchwindow_checkbox.SetValue(self.config['gui_stretchwindow']) self.gui_displaystats_checkbox = wxCheckBox(panel, -1, "Display peer and seed statistics") self.gui_displaystats_checkbox.SetFont(self.default_font) self.gui_displaystats_checkbox.SetValue(self.config['gui_displaystats']) self.gui_displaymiscstats_checkbox = wxCheckBox(panel, -1, "Display miscellaneous other statistics") self.gui_displaymiscstats_checkbox.SetFont(self.default_font) self.gui_displaymiscstats_checkbox.SetValue(self.config['gui_displaymiscstats']) self.security_checkbox = wxCheckBox(panel, -1, "Don't allow multiple connections from the same IP") self.security_checkbox.SetFont(self.default_font) self.security_checkbox.SetValue(self.config['security']) self.autokick_checkbox = wxCheckBox(panel, -1, "Kick/ban clients that send you bad data *") self.autokick_checkbox.SetFont(self.default_font) self.autokick_checkbox.SetValue(self.config['auto_kick'])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -