📄 abcoption.py
字号:
import sys
import wx
import os
from random import shuffle
from traceback import print_exc
from cStringIO import StringIO
from wx.lib import masked, colourselect
from ABC.GUI.menu import MenuDialog
from Utility.configreader import ConfigReader
from Utility.constants import * #IGNORE:W0611
################################################################
#
# Class: ABCOptionPanel
#
# Basic structure for options window panels
#
# Adds a button for "Restore Defaults"
# at the bottom of each panel
#
################################################################
class ABCOptionPanel(wx.Panel):
def __init__(self, parent, dialog):
wx.Panel.__init__(self, parent, -1)
self.dialog = dialog
self.utility = dialog.utility
self.changed = False
self.outersizer = wx.BoxSizer(wx.VERTICAL)
self.sizer = wx.BoxSizer(wx.VERTICAL)
# Things to do after the subclass has finished its init stage
def initTasks(self):
self.loadValues()
self.outersizer.Add(self.sizer, 1, wx.EXPAND)
defaultsButton = wx.Button(self, -1, self.utility.lang.get('reverttodefault'))
wx.EVT_BUTTON(self, defaultsButton.GetId(), self.setDefaults)
self.outersizer.Add(defaultsButton, 0, wx.ALIGN_RIGHT|wx.TOP|wx.BOTTOM, 10)
self.SetSizerAndFit(self.outersizer)
def loadValues(self, Read = None):
# Dummy function that class members should override
pass
def setDefaults(self, event = None):
self.loadValues(self.utility.config.ReadDefault)
def apply(self):
# Dummy function that class members should override
pass
################################################################
#
# Class: NetworkPanel
#
# Contains network settings
#
################################################################
class NetworkPanel(ABCOptionPanel):
def __init__(self, parent, dialog):
ABCOptionPanel.__init__(self, parent, dialog)
sizer = self.sizer
self.minport = self.utility.makeNumCtrl(self, 1, min = 1, max = 65536)
port_box = wx.BoxSizer(wx.HORIZONTAL)
port_box.Add(wx.StaticText(self, -1, self.utility.lang.get('portnumber')), 0, wx.ALIGN_CENTER_VERTICAL)
port_box.Add(self.minport, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 5)
port_box.Add(wx.StaticText(self, -1, self.utility.lang.get('restartabc')), 0, wx.ALIGN_CENTER_VERTICAL)
sizer.Add(port_box, 0, wx.EXPAND|wx.ALL, 5)
self.kickban = wx.CheckBox(self, -1, self.utility.lang.get('kickban'))
sizer.Add(self.kickban, 0, wx.ALIGN_LEFT|wx.ALL, 5)
self.notsameip = wx.CheckBox(self, -1, self.utility.lang.get('security'))
sizer.Add(self.notsameip, 0, wx.ALIGN_LEFT|wx.ALL, 5)
# Do or don't get scrape data
###################################################################
self.scrape = wx.CheckBox(self, -1, self.utility.lang.get('scrape'))
sizer.Add(self.scrape, 0, wx.ALIGN_LEFT|wx.ALL, 5)
self.scrape.SetToolTipString(self.utility.lang.get('scrape_hint'))
###################################################################
#self.ipv6 = wx.CheckBox(self, -1, "Initiate and receive connections via IPv6")
#if self.utility.config.Read('ipv6') == "1":
# self.ipv6.SetValue(True)
#else:
# self.ipv6.SetValue(False)
####################################################################
self.initTasks()
def loadValues(self, Read = None):
if Read is None:
Read = self.utility.config.Read
self.minport.SetValue(Read('minport', 'int'))
self.kickban.SetValue(Read('kickban', "boolean"))
self.notsameip.SetValue(Read('notsameip', "boolean"))
self.scrape.SetValue(Read('scrape', "boolean"))
def apply(self):
minport = int(self.minport.GetValue())
if minport > 65535:
minport = 65535
minchanged = self.utility.config.Write('minport', minport)
self.utility.config.Write('kickban', self.kickban.GetValue(), "boolean")
self.utility.config.Write('notsameip', self.notsameip.GetValue(), "boolean")
self.utility.config.Write('scrape', self.scrape.GetValue(), "boolean")
################################################################
#
# Class: QueuePanel
#
# Contains settings that control how many torrents to start
# at once and when to start them
#
################################################################
class QueuePanel(ABCOptionPanel):
def __init__(self, parent, dialog):
ABCOptionPanel.__init__(self, parent, dialog)
sizer = self.sizer
#
# Number of simultaneous active torrents
#
activesection_title = wx.StaticBox(self, -1, self.utility.lang.get('activetorrents'))
activesection = wx.StaticBoxSizer(activesection_title, wx.VERTICAL)
self.numsimtext = wx.SpinCtrl(self, size = wx.Size(60, -1))
self.numsimtext.SetRange(0, 1000)
numsim = wx.BoxSizer(wx.HORIZONTAL)
numsim.Add(wx.StaticText(self, -1, self.utility.lang.get('maxnumsimul')), 0, wx.ALIGN_CENTER_VERTICAL)
numsim.Add(self.numsimtext, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 5)
activesection.Add(numsim, 0, wx.ALL, 5)
self.trig_finish_values = [ self.utility.lang.get('after_downloading') , self.utility.lang.get('after_seeding') ]
self.trig_finish_seed = wx.ComboBox(self, -1, "", wx.Point(-1, -1), wx.Size(-1, -1), self.trig_finish_values, wx.CB_DROPDOWN|wx.CB_READONLY)
trigger_box = wx.BoxSizer(wx.HORIZONTAL)
trigger_box.Add(wx.StaticText(self, -1, self.utility.lang.get('trignexttorrent')), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 5)
trigger_box.Add(self.trig_finish_seed, 0, wx.ALIGN_CENTER_VERTICAL)
activesection.Add(trigger_box, 0, wx.ALL, 5)
sizer.Add(activesection, 0, wx.EXPAND|wx.ALL, 5)
#
# Autostart torrents
#
autostartsection_title = wx.StaticBox(self, -1, self.utility.lang.get('autostart'))
autostartsection = wx.StaticBoxSizer(autostartsection_title, wx.VERTICAL)
self.autostart = wx.CheckBox(self, -1, self.utility.lang.get('autostart_threshold'))
self.autostartthreshold = self.utility.makeNumCtrl(self, 0, integerWidth = 4)
autostart_line1box = wx.BoxSizer(wx.HORIZONTAL)
autostart_line1box.Add(self.autostart, 0, wx.ALIGN_CENTER_VERTICAL)
autostart_line1box.Add(self.autostartthreshold, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 5)
autostart_line1box.Add(wx.StaticText(self, -1, self.utility.lang.get('KB') + "/" + self.utility.lang.get('l_second')), 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 3)
self.autostartdelay = self.utility.makeNumCtrl(self, 0, integerWidth = 4, min = 1)
autostart_line2box = wx.BoxSizer(wx.HORIZONTAL)
autostart_line2box.Add(wx.StaticText(self, -1, self.utility.lang.get('autostart_delay')), 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 20)
autostart_line2box.Add(self.autostartdelay, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 5)
autostart_line2box.Add(wx.StaticText(self, -1, self.utility.lang.get('l_second')), 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 3)
autostartsection.Add(autostart_line1box, 0, wx.ALL, 3)
autostartsection.Add(autostart_line2box, 0, wx.ALL, 3)
sizer.Add(autostartsection, 0, wx.EXPAND|wx.ALL, 5)
#
# Default priority for new torrents
#
self.priorities = [ self.utility.lang.get('highest'),
self.utility.lang.get('high'),
self.utility.lang.get('normal'),
self.utility.lang.get('low'),
self.utility.lang.get('lowest') ]
self.defaultpriority = wx.ComboBox(self, -1, "", wx.Point(-1, -1), wx.Size(-1, -1), self.priorities, wx.CB_DROPDOWN|wx.CB_READONLY)
prio_box = wx.BoxSizer(wx.HORIZONTAL)
prio_box.Add(wx.StaticText(self, -1, self.utility.lang.get('defaultpriority')), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 5)
prio_box.Add(self.defaultpriority, 0, wx.ALIGN_CENTER_VERTICAL)
sizer.Add(prio_box, 0, wx.ALL, 5)
self.failbehaviors = [ self.utility.lang.get('stop'), self.utility.lang.get('queue') ]
self.failbehavior = wx.ComboBox(self, -1, "", wx.Point(-1, -1), wx.Size(-1, -1), self.failbehaviors, wx.CB_DROPDOWN|wx.CB_READONLY)
fail_box = wx.BoxSizer(wx.HORIZONTAL)
fail_box.Add(wx.StaticText(self, -1, self.utility.lang.get('failbehavior1')), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 5)
fail_box.Add(self.failbehavior, 0, wx.ALIGN_CENTER_VERTICAL)
fail_box.Add(wx.StaticText(self, -1, self.utility.lang.get('failbehavior2')), 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 5)
sizer.Add(fail_box, 0, wx.ALL, 5)
self.fastresume = wx.CheckBox(self, -1, self.utility.lang.get('fastresume'))
self.fastresume.SetToolTipString(self.utility.lang.get('fastresume_hint'))
sizer.Add(self.fastresume, 0, wx.ALL, 5)
# self.skipcheck = wx.CheckBox(self, -1, self.utility.lang.get('skipcheck'))
# self.skipcheck.SetToolTipString(self.utility.lang.get('skipcheck_hint'))
# sizer.Add(self.skipcheck, 0, wx.ALL, 5)
self.initTasks()
def loadValues(self, Read = None):
if Read is None:
Read = self.utility.config.Read
if Read('trigwhenfinishseed', "boolean"):
trig_default_value = self.utility.lang.get('after_seeding')
else:
trig_default_value = self.utility.lang.get('after_downloading')
self.trig_finish_seed.SetStringSelection(trig_default_value)
currentprio = Read('defaultpriority', "int")
if currentprio >= len(self.priorities):
currentprio = len(self.priorities) - 1
defaultprio = self.priorities[currentprio]
self.defaultpriority.SetStringSelection(defaultprio)
defaultfail = self.failbehaviors[Read('failbehavior', "int")]
self.failbehavior.SetStringSelection(defaultfail)
self.numsimtext.SetValue(Read('numsimdownload', "int"))
self.fastresume.SetValue(Read('fastresume', "boolean"))
# self.skipcheck.SetValue(Read('skipcheck', "boolean"))
self.autostart.SetValue(Read('urm', "boolean"))
self.autostartthreshold.SetValue(Read('urmupthreshold', "int"))
self.autostartdelay.SetValue(Read('urmdelay', "int"))
def apply(self):
self.utility.config.Write('fastresume', self.fastresume.GetValue(), "boolean")
# self.utility.config.Write('skipcheck', self.skipcheck.GetValue(), "boolean")
selected = self.priorities.index(self.defaultpriority.GetValue())
self.utility.config.Write('defaultpriority', selected)
self.utility.config.Write('failbehavior', self.failbehaviors.index(self.failbehavior.GetValue()))
self.utility.config.Write('numsimdownload', self.numsimtext.GetValue())
trigwhenfinished = (self.trig_finish_seed.GetValue() == self.utility.lang.get('after_seeding'))
self.utility.config.Write('trigwhenfinishseed', trigwhenfinished, "boolean")
self.utility.config.Write('urm', self.autostart.GetValue(), "boolean")
self.utility.config.Write('urmupthreshold', self.autostartthreshold.GetValue())
self.utility.config.Write('urmdelay', self.autostartdelay.GetValue())
self.utility.queue.UpdateRunningTorrentCounters()
################################################################
#
# Class: DisplayPanel
#
# Contains settings for how ABC looks
#
################################################################
class DisplayPanel(ABCOptionPanel):
def __init__(self, parent, dialog):
ABCOptionPanel.__init__(self, parent, dialog)
sizer = self.sizer
listfont_box = wx.BoxSizer(wx.HORIZONTAL)
listfont_box.Add(wx.StaticText(self, -1, self.utility.lang.get('listfont')), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 5)
self.fontexample = wx.TextCtrl(self, -1, self.utility.lang.get('sampletext'))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -