📄 abcoptiondlg.py
字号:
from wxPython.wx import *
from wxPython import *
from webbrowser import open_new
from threading import Thread
from filemanager import *
from os import path
from os.path import join
class ABCOptionDialog(wxDialog):
def __init__(self, parent, ID, title,
pos=wxDefaultPosition, size=wxDefaultSize,
style=wxDEFAULT_DIALOG_STYLE):
pre = wxPreDialog()
pre.Create(parent, ID, title, pos, size, style)
self.this = pre.this
self.parent = parent
self.numsim = 0
self.advancedConfig = {}
self.advancedMenuBox = None
# Port Setting
#####################
ID_MINPORT = wxNewId()
ID_MAXPORT = wxNewId()
wxStaticBox(self, -1, "Port Setting", wxPoint(10,5), wxSize(270,70))
wxStaticText(self, -1, "Minimum port number : ", wxPoint(25,25))
wxStaticText(self, -1, "Maximum port number :" , wxPoint(25,50))
self.minport = wxTextCtrl(self, ID_MINPORT, self.parent.abcparams['minport'], wxPoint(140,20),wxSize(60, -1))
self.maxport = wxTextCtrl(self, ID_MAXPORT, self.parent.abcparams['maxport'], wxPoint(140,45),wxSize(60, -1))
# Queue Setting
##########################
ID_NUMSIM = wxNewId()
ID_NUMSIMSPIN = wxNewId()
ID_COMBOBOX_HTIME = wxNewId()
ID_COMBOBOX_MTIME = wxNewId()
ID_COMBOBOX_RATIO = wxNewId()
ID_APPLY_BUTTON = wxNewId()
wxStaticBox(self, -1, "Queue Setting", wxPoint(10,85), wxSize(270,60))
wxStaticText(self, -1, "Maximum number of", wxPoint(25,105))
wxStaticText(self, -1, "simultaneous downloads", wxPoint(25, 120))
self.numsimtext = wxTextCtrl(self, ID_NUMSIM, self.parent.abcparams['numsimdownload'], wxPoint(150,110),wxSize(60, -1),wxTE_READONLY|wxTE_RIGHT)
h = self.numsimtext.GetSize().height
self.numsimspin = wxSpinButton(self, ID_NUMSIMSPIN, wxPoint(210, 110), wxSize(h,h), wxSP_VERTICAL)
self.numsimspin.SetRange(0, 1024)
self.numsimspin.SetValue(int(self.parent.abcparams['numsimdownload']))
# Misc Setting
#############################
ID_TORRENTBACKUP = wxNewId()
ID_DEFAULTDIR = wxNewId()
ID_DIR = wxNewId()
ID_BROWSEDIR = wxNewId()
ID_MINIMIZETRAY = wxNewId()
wxStaticBox(self, -1, "Misc Setting", wxPoint(10, 155), wxSize(270, 90))
self.torrentbackup = wxCheckBox(self, ID_TORRENTBACKUP,
"Remove .torrent backup file when using remove",
wxPoint(25, 175), style=wxNO_BORDER)
if self.parent.abcparams['removetorrent'] == "1":
self.torrentbackup.SetValue(true)
else:
self.torrentbackup.SetValue(false)
self.mintray = wxCheckBox(self, ID_MINIMIZETRAY,
"Minimize ABC client to tray",
wxPoint(25, 195), style=wxNO_BORDER)
if self.parent.abcparams['mintray'] == "1":
self.mintray.SetValue(true)
else:
self.mintray.SetValue(false)
self.defaultdir = wxCheckBox(self, ID_DEFAULTDIR, "Set default download folder",
wxPoint(25, 215), style=wxNO_BORDER)
if self.parent.abcparams['setdefaultfolder'] == "1":
self.defaultdir.SetValue(true)
else:
self.defaultdir.SetValue(false)
self.dir = wxTextCtrl(self, ID_DIR, self.parent.abcparams['defaultfolder'], wxPoint(175,211),wxSize(82, -1))
self.browsebtn = wxButton(self, ID_BROWSEDIR, "...", wxPoint(255,210), wxSize(20,-1))
ID_ADV_BUTTON = wxNewId()
ID_CANCEL_BUTTON = wxNewId()
advbtn = wxButton(self, ID_ADV_BUTTON, " Advanced setting ", wxPoint(10, 255))
applybtn = wxButton(self, ID_APPLY_BUTTON, " Apply ", wxPoint(125, 255))
cancelbtn = wxButton(self, ID_CANCEL_BUTTON, " Cancel ", wxPoint(205, 255))
# Add events
###########################
EVT_SPIN(self, ID_NUMSIMSPIN, self.onNumSimSpin)
EVT_BUTTON(self, ID_APPLY_BUTTON, self.onApply)
EVT_BUTTON(self, ID_ADV_BUTTON, self.onAdvSetting)
EVT_BUTTON(self, ID_BROWSEDIR, self.onBrowseDir)
EVT_BUTTON(self, ID_CANCEL_BUTTON, self.onCloseGlobalPref)
EVT_CLOSE(self, self.onCloseGlobalPref)
def onCloseGlobalPref(self, event):
if (self.advancedMenuBox is not None):
try:
self.advancedMenuBox.Close ()
except wxPyDeadObjectError, e:
self.advancedMenuBox = None
self.Destroy()
def onAdvSetting(self, event):
self.FONT=12
if len(self.advancedConfig) == 0:
for key in ['ip', 'bind', 'min_peers', 'max_initiate', 'alloc_type', 'alloc_rate', 'max_files_open', 'max_connections']:
self.advancedConfig[key] = self.parent.abcparams[key]
if (self.advancedMenuBox is not None):
try:
self.advancedMenuBox.Close ()
except wxPyDeadObjectError, e:
self.advancedMenuBox = None
self.advancedMenuBox = wxFrame(None, -1, 'ABC Advanced Preferences', size = (1,1))
if (sys.platform == 'win32'):
self.advancedMenuBox.SetIcon(self.parent.icon)
panel = wxPanel(self.advancedMenuBox, -1)
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)
ip_data = wxTextCtrl(parent = panel, id = -1,
value = self.advancedConfig['ip'],
size = (self.FONT*13, int(self.FONT*2.2)), style = wxTE_PROCESS_TAB)
bind_data = wxTextCtrl(parent = panel, id = -1,
value = self.advancedConfig['bind'],
size = (self.FONT*7, int(self.FONT*2.2)), style = wxTE_PROCESS_TAB)
minpeers_data = wxSpinCtrl(panel, -1, '', (-1,-1), (self.FONT*7, -1))
minpeers_data.SetRange(10,100)
minpeers_data.SetValue(int(self.advancedConfig['min_peers']))
# max_initiate = 2*minpeers
alloctype_data=wxChoice(panel, -1,
choices = ['normal', 'background', 'pre-allocate', 'sparse'])
alloctype_data.SetStringSelection(self.advancedConfig['alloc_type'])
allocrate_data = wxSpinCtrl(panel, -1, '', (-1,-1), (self.FONT*7,-1))
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)
setval = int(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)
setval = int(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)
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('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)
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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -