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

📄 abcoption.py

📁 ABC-win32-v3.1 一个P2P软源代码
💻 PY
📖 第 1 页 / 共 5 页
字号:

        self.buffer_read_enable = wx.CheckBox(self, -1, self.utility.lang.get('buffer_read'))
                   
        self.buffer_write = wx.SpinCtrl(self, size = wx.Size(60, -1))
        self.buffer_write.SetRange(0, 999)
        
        self.buffer_write_enable = wx.CheckBox(self, -1, self.utility.lang.get('buffer_write'))

        buffer_write_box = wx.BoxSizer(wx.HORIZONTAL)
        buffer_write_box.Add(self.buffer_write_enable, 0, wx.ALIGN_CENTER_VERTICAL)
        buffer_write_box.Add(self.buffer_write, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 5)
        buffer_write_box.Add(wx.StaticText(self, -1, self.utility.lang.get('mb')), 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 5)
       
        buffer.Add(self.buffer_read_enable, 0, wx.ALL, 5)
        buffer.Add(buffer_write_box, 0, wx.ALL, 5)

        sizer.Add(buffer, 0, wx.EXPAND|wx.ALL, 5)

        self.alloctype_data.SetToolTipString(self.utility.lang.get('alloctypehint'))
        self.allocrate_data.SetToolTipString(self.utility.lang.get('allocratehint'))
        self.locking_data.SetToolTipString(self.utility.lang.get('lockinghint'))
        self.doublecheck_data.SetToolTipString(self.utility.lang.get('doublecheckhint'))
        self.maxfilesopen_data.SetToolTipString(self.utility.lang.get('maxfileopenhint'))
        
        self.initTasks()

    def loadValues(self, Read = None):
        if Read is None:
            Read = self.utility.config.Read
        
        try:
            alloc_selection = self.alloc_strings[Read('alloc_type')]
        except:
            alloc_selection = 0
        self.alloctype_data.SetSelection(alloc_selection)
        
        self.allocrate_data.SetValue(Read('alloc_rate', "int"))
        
        if Read('lock_files', "int"):
            if Read('lock_while_reading', "int"):
                self.locking_data.SetSelection(2)
            else:
                self.locking_data.SetSelection(1)
        else:
            self.locking_data.SetSelection(0)
        
        if Read('double_check', "int"):
            if Read('triple_check', "int"):
                self.doublecheck_data.SetSelection(2)
            else:
                self.doublecheck_data.SetSelection(1)
        else:
            self.doublecheck_data.SetSelection(0)
        
        setval = Read('max_files_open', "int")
        if setval == 0:
            setval = self.utility.lang.get('nolimit')
        else:
            setval = str(setval)
        if not setval in self.maxfilesopen_choices:
            setval = self.maxfilesopen_choices[0]
        self.maxfilesopen_data.SetStringSelection(setval)
        
        self.buffer_read_enable.SetValue(Read('buffer_read', "boolean"))
        
        try:
            flushval = Read('auto_flush', "int")
        except:
            flushval = 0
        self.flush_data.SetValue(flushval)
        self.flush_data_enable.SetValue(flushval > 0)
        
        try:
            writeval = Read('buffer_write', "int")
        except:
            writeval = 0
        self.buffer_write.SetValue(writeval)
        self.buffer_write_enable.SetValue(writeval > 0)
                            
    def apply(self):
        truth = { True: "1", False: "0" }
        
        alloc_strings = ["normal", "background", "pre-allocate", "sparse"]
        
        self.utility.config.Write('alloc_type', alloc_strings[self.alloctype_data.GetSelection()])
        self.utility.config.Write('alloc_rate', int(self.allocrate_data.GetValue()))

        try:
            maxopen = int(self.maxfilesopen_data.GetStringSelection())
        except:       # if it ain't a number, it must be "no limit"
            maxopen = 0
        self.utility.config.Write('max_files_open', maxopen)

        self.utility.config.Write('lock_files', self.locking_data.GetSelection() >= 1, "boolean")
        self.utility.config.Write('lock_while_reading', self.locking_data.GetSelection() > 1, "boolean")

        self.utility.config.Write('double_check', self.doublecheck_data.GetSelection() >= 1, "boolean")
        self.utility.config.Write('triple_check', self.doublecheck_data.GetSelection() > 1, "boolean")
        
        self.utility.config.Write('buffer_read', self.buffer_read_enable.GetValue(), "boolean")
        
        if not self.buffer_write_enable.GetValue():
            writeval = 0
        else:
            writeval = self.buffer_write.GetValue()
        self.utility.config.Write('buffer_write', writeval)
        
        if not self.flush_data_enable.GetValue():
            flushval = 0
        else:
            flushval = self.flush_data.GetValue()
        self.utility.config.Write('auto_flush', flushval)


################################################################
#
# Class: ABCTree
#
# A collapsable listing of all the options panels
#
################################################################
class ABCTree(wx.TreeCtrl):
    def __init__(self, parent, dialog):
        style = wx.TR_DEFAULT_STYLE | wx.TR_HIDE_ROOT
        wx.TreeCtrl.__init__(self, parent, -1, style = style)

        self.dialog = dialog
        self.utility = dialog.utility
       
        self.root = self.AddRoot("Preferences")
        
        self.ratelimits = self.AppendItem(self.root, self.utility.lang.get('ratelimits'))
        self.seedingoptions = self.AppendItem(self.root, self.utility.lang.get('seedoptions'))
        self.queuesetting = self.AppendItem(self.root, self.utility.lang.get('queuesetting'))
        self.timeout = self.AppendItem(self.root, self.utility.lang.get('timeout'))
        
        self.network = self.AppendItem(self.root, self.utility.lang.get('networksetting'))
        
        self.advancednetwork = self.AppendItem(self.network, self.utility.lang.get('advanced'))
        
        self.disk = self.AppendItem(self.root, self.utility.lang.get('disksettings'))
        self.advanceddisk = self.AppendItem(self.disk, self.utility.lang.get('advanced'))

        self.display = self.AppendItem(self.root, self.utility.lang.get('displaysetting'))

        self.colors = self.AppendItem(self.display, self.utility.lang.get('torrentcolors'))
                
        self.misc = self.AppendItem(self.root, self.utility.lang.get('miscsetting'))

        self.treeMap = {self.ratelimits : self.dialog.rateLimitPanel, 
                        self.seedingoptions : self.dialog.seedingOptionsPanel, 
                        self.queuesetting : self.dialog.queuePanel, 
                        self.timeout : self.dialog.schedulerRulePanel, 
                        self.network : self.dialog.networkPanel, 
                        self.misc : self.dialog.miscPanel, 
                        self.display : self.dialog.displayPanel, 
                        self.colors : self.dialog.colorPanel, 
                        self.disk : self.dialog.diskPanel }

        self.treeMap[self.advancednetwork] = self.dialog.advancedNetworkPanel
        self.treeMap[self.advanceddisk] = self.dialog.advancedDiskPanel
        
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.onSwitchPage)

        self.SetAutoLayout(True)
        self.Fit()

    def onSwitchPage(self, event = None):       
        if self.dialog.closing or event is None:
            return

        newitem = event.GetItem()
        newpanel = None
        foundnew = False
        for key in self.treeMap:
            if key == newitem:
                newpanel = self.treeMap[key]
                foundnew = True
            if foundnew:
                break

        if newpanel is not None:
            # Trying to switch to the current window
            try:
                oldpanel = self.dialog.splitter.GetWindow2()
                if oldpanel != newpanel:
                    oldpanel.Show(False)
                    self.dialog.splitter.ReplaceWindow(oldpanel, newpanel)
                    newpanel.Show(True)
                    newpanel.changed = True
            except:
                pass
                # TODO: for some reason this is sometimes failing
                # (splitter.GetWindow2() sometimes appears to
                #  return an Object rather than wx.Window)


################################################################
#
# Class: ABCOptionDialog
#
# Creates a dialog that allows users to set various preferences
#
################################################################        
class ABCOptionDialog(wx.Dialog):
    def __init__(self, parent):
        self.utility = parent.utility

        style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
#        size = wx.Size(530, 420)
        
        size, split = self.getWindowSettings()
        
        wx.Dialog.__init__(self, parent, -1, self.utility.lang.get('abcpreference'), size = size, style = style)
                     
        self.splitter = wx.SplitterWindow(self, -1, style = wx.SP_NOBORDER | wx.SP_LIVE_UPDATE)

        self.rateLimitPanel = RateLimitPanel(self.splitter, self)
        self.seedingOptionsPanel = SeedingOptionsPanel(self.splitter, self)
        self.queuePanel = QueuePanel(self.splitter, self)

        self.schedulerRulePanel = SchedulerRulePanel(self.splitter, self)
        self.networkPanel = NetworkPanel(self.splitter, self)
        self.miscPanel = MiscPanel(self.splitter, self)
        self.displayPanel = DisplayPanel(self.splitter, self)
        self.colorPanel = ColorPanel(self.splitter, self)
        self.diskPanel = DiskPanel(self.splitter, self)
        
        self.advancedNetworkPanel = AdvancedNetworkPanel(self.splitter, self)
        self.advancedDiskPanel = AdvancedDiskPanel(self.splitter, self)
        
        self.tree = ABCTree(self.splitter, self)

        # TODO: Try wx.Listbook instead of splitterwindow

        self.splitter.SetAutoLayout(True)
        self.splitter.Fit()
      
        applybtn       = wx.Button(self, -1, " "+self.utility.lang.get('apply')+" ", size = (60, -1))
        okbtn          = wx.Button(self, -1, " "+self.utility.lang.get('ok')+" ", size = (60, -1))
        cancelbtn      = wx.Button(self, -1, " "+self.utility.lang.get('cancel')+" ", size = (60, -1))
        
        buttonbox = wx.BoxSizer(wx.HORIZONTAL)
        buttonbox.Add(applybtn, 0, wx.ALL, 5)
        buttonbox.Add(okbtn, 0, wx.ALL, 5)
        buttonbox.Add(cancelbtn, 0, wx.ALL, 5)
       
        outerbox = wx.BoxSizer(wx.VERTICAL)
        outerbox.Add(self.splitter , 1, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5)
        
        outerbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)
        
        outerbox.Add(buttonbox, 0, wx.ALIGN_RIGHT)

        # Add events
        ###########################
        self.Bind(wx.EVT_BUTTON, self.onOK, okbtn)
        self.Bind(wx.EVT_BUTTON, self.onApply, applybtn)
        self.Bind(wx.EVT_BUTTON, self.onCloseGlobalPref, cancelbtn)
        self.Bind(wx.EVT_CLOSE, self.onCloseGlobalPref)

        self.splitter.SplitVertically(self.tree, self.rateLimitPanel, split)
        self.rateLimitPanel.changed = True
        self.splitter.SetMinimumPaneSize(50)

        for key in self.tree.treeMap:
            panel = self.tree.treeMap[key]
            panel.Show(False)
        
        self.rateLimitPanel.Show(True)
        self.rateLimitPanel.Fit()
        
        self.SetSizer(outerbox)
#        self.Fit()
        
        self.closing = False
        
    def getWindowSettings(self):
        width = self.utility.config.Read("prefwindow_width", "int")
        height = self.utility.config.Read("prefwindow_height", "int")
        split = self.utility.config.Read("prefwindow_split", "int")
                  
        return wx.Size(width, height), split
        
    def saveWindowSettings(self):       
        width, height = self.GetSizeTuple()
        self.utility.config.Write("prefwindow_width", width)
        self.utility.config.Write("prefwindow_height", height)
        self.utility.config.Write("prefwindow_split", self.splitter.GetSashPosition())
        self.utility.config.Flush()
              
    def onCloseGlobalPref(sel

⌨️ 快捷键说明

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