?? btdownloadgui.py
字號(hào):
#!D:\Python22\python.exe
# Written by Bram Cohen and Myers Carpenter
# see LICENSE.txt for license information
from sys import argv, version
assert version >= '2', "Install Python 2.0 or greater"
from BitTorrent import version
from BitTorrent.download import *
from BitTorrent.ConnChoice import *
from threading import Event, Thread
from os.path import join
from os import getcwd
from wxPython.wx import *
from time import strftime
from webbrowser import open_new
def hours(n):
if n == -1:
return '<unknown>'
if n == 0:
return 'complete!'
n = int(n)
h, r = divmod(n, 60 * 60)
m, sec = divmod(r, 60)
if h > 1000000:
return '<unknown>'
if h > 0:
return '%d hour %02d min %02d sec' % (h, m, sec)
else:
return '%d min %02d sec' % (m, sec)
wxEVT_INVOKE = wxNewEventType()
def EVT_INVOKE(win, func):
win.Connect(-1, -1, wxEVT_INVOKE, func)
class InvokeEvent(wxPyEvent):
def __init__(self, func, args, kwargs):
wxPyEvent.__init__(self)
self.SetEventType(wxEVT_INVOKE)
self.func = func
self.args = args
self.kwargs = kwargs
def pr(event):
print 'augh!'
class DownloadInfoFrame:
def __init__(self, flag):
frame = wxFrame(None, -1, 'BitTorrent ' + version + ' download', size = wxSize(450, 250))
self.frame = frame
self.flag = flag
self.fin = false
self.aboutBox = None
panel = wxPanel(frame, -1)
colSizer = wxFlexGridSizer(cols = 1, vgap = 3)
fnsizer = wxBoxSizer(wxHORIZONTAL)
self.fileNameText = wxStaticText(panel, -1, '', style = wxALIGN_LEFT)
self.fileNameText.SetFont(wxFont(12, wxNORMAL, wxNORMAL, wxNORMAL, false))
fnsizer.Add(self.fileNameText, 1, wxALIGN_BOTTOM)
self.aboutText = wxStaticText(panel, -1, 'about', style = wxALIGN_RIGHT)
self.aboutText.SetForegroundColour('Blue')
self.aboutText.SetFont(wxFont(12, wxNORMAL, wxNORMAL, wxNORMAL, true))
fnsizer.Add(self.aboutText, 0, wxEXPAND)
colSizer.Add(fnsizer, 0, wxEXPAND)
self.gauge = wxGauge(panel, -1, range = 1000, style = wxGA_SMOOTH)
colSizer.Add(self.gauge, 0, wxEXPAND)
gridSizer = wxFlexGridSizer(cols = 2, vgap = 3, hgap = 8)
gridSizer.Add(wxStaticText(panel, -1, 'Estimated time left:'))
self.timeEstText = wxStaticText(panel, -1, '')
gridSizer.Add(self.timeEstText, 0, wxEXPAND)
gridSizer.Add(wxStaticText(panel, -1, 'Download to:'))
self.fileDestText = wxStaticText(panel, -1, '')
gridSizer.Add(self.fileDestText, 0, wxEXPAND)
self.ratesSizer = wxFlexGridSizer(cols = 2, hgap = 0, vgap = 0)
self.infoSizer = wxFlexGridSizer(cols = 2, hgap = 0, vgap = 0)
self.ratesSizer.Add(wxStaticText(panel, -1, 'Download rate: '))
self.downRateText = wxStaticText(panel, -1, ' 0 KB/s')
self.ratesSizer.Add(self.downRateText, 0, wxEXPAND)
self.infoSizer.Add(wxStaticText(panel, -1, 'Downloaded: '))
self.downText = wxStaticText(panel, -1, ' 0.00 MiB')
self.infoSizer.Add(self.downText, 0, wxEXPAND)
self.ratesSizer.Add(wxStaticText(panel, -1, 'Upload rate: '))
self.upRateText = wxStaticText(panel, -1, ' 0 KB/s')
self.ratesSizer.Add(self.upRateText, 0, wxEXPAND)
self.infoSizer.Add(wxStaticText(panel, -1, 'Uploaded: '))
self.upText = wxStaticText(panel, -1, ' 0.00 MiB')
self.infoSizer.Add(self.upText, 0, wxEXPAND)
gridSizer.Add(self.ratesSizer)
gridSizer.Add(self.infoSizer)
gridSizer.AddGrowableCol(1)
colSizer.Add(gridSizer, 0, wxEXPAND)
self.errorText = wxStaticText(panel, -1, '', style = wxALIGN_LEFT)
self.errorText.SetForegroundColour('Red')
colSizer.Add(self.errorText, 0, wxEXPAND)
self.cancelButton = wxButton(panel, -1, 'Cancel')
colSizer.Add(self.cancelButton, 0, wxALIGN_CENTER)
# Setting options
slideSizer = wxFlexGridSizer(cols = 7, hgap = 0, vgap = 0)
# dropdown
slideSizer.Add (wxStaticText(panel, -1, 'Settings for '), 0, wxALIGN_LEFT)
self.connChoice = wxChoice (panel, -1, (-1, -1), (90, -1), choices = connChoiceList)
self.connChoice.SetSelection(0)
slideSizer.Add (self.connChoice, 0, wxALIGN_CENTER)
slideSizer.Add (wxStaticText(panel, -1, ' Upload rate (KB/s) '), 0, wxALIGN_RIGHT)
# max upload rate
self.rateSpinner = wxSpinCtrl (panel, -1, "", (-1,-1), (50, -1))
self.rateSpinner.SetRange(0,5000)
self.rateSpinner.SetValue(0)
slideSizer.Add (self.rateSpinner, 0, wxALIGN_CENTER)
self.rateLowerText = wxStaticText(panel, -1, ' %5d' % (0))
self.rateUpperText = wxStaticText(panel, -1, '%5d' % (5000))
self.rateslider = wxSlider(panel, -1, 0, 0, 100, (-1, -1), (80, -1))
slideSizer.Add(self.rateLowerText, 0, wxALIGN_RIGHT)
slideSizer.Add(self.rateslider, 0, wxALIGN_CENTER)
slideSizer.Add(self.rateUpperText, 0, wxALIGN_LEFT)
# Placeholders in Layout
slideSizer.Add(wxStaticText(panel, -1, ''), 0, wxALIGN_LEFT)
slideSizer.Add(wxStaticText(panel, -1, ''), 0, wxALIGN_LEFT)
# max uploads
slideSizer.Add(wxStaticText(panel, -1, ' Max uploads '), 0, wxALIGN_RIGHT)
self.connSpinner = wxSpinCtrl (panel, -1, "", (-1,-1), (50, -1))
self.connSpinner.SetRange(4,100)
self.connSpinner.SetValue(4)
slideSizer.Add (self.connSpinner, 0, wxALIGN_CENTER)
self.connLowerText = wxStaticText(panel, -1, ' %5d' % (4))
self.connUpperText = wxStaticText(panel, -1, '%5d' % (100))
self.connslider = wxSlider(panel, -1, 4, 4, 100, (-1, -1), (80, -1))
slideSizer.Add(self.connLowerText, 0, wxALIGN_RIGHT)
slideSizer.Add(self.connslider, 0, wxALIGN_CENTER)
slideSizer.Add(self.connUpperText, 0, wxALIGN_LEFT)
colSizer.Add(slideSizer, 1, wxALL|wxALIGN_CENTER|wxEXPAND, 0)
colSizer.Add(wxStaticText(panel, -1, '0 KB/s means unlimited. Tip: your download rate is proportional to your upload rate'), 0, wxALIGN_CENTER)
colSizer.AddGrowableCol(0)
colSizer.AddGrowableRow(3)
border = wxBoxSizer(wxHORIZONTAL)
border.Add(colSizer, 1, wxEXPAND | wxALL, 4)
panel.SetSizer(border)
panel.SetAutoLayout(true)
EVT_LEFT_DOWN(self.aboutText, self.about)
EVT_CLOSE(frame, self.done)
EVT_BUTTON(frame, self.cancelButton.GetId(), self.done)
EVT_INVOKE(frame, self.onInvoke)
EVT_SCROLL(self.rateslider, self.onRateScroll)
EVT_SCROLL(self.connslider, self.onConnScroll)
EVT_CHOICE(self.connChoice, -1, self.onConnChoice)
EVT_SPINCTRL(self.connSpinner, -1, self.onConnSpinner)
EVT_SPINCTRL(self.rateSpinner, -1, self.onRateSpinner)
self.frame.Show()
def onRateScroll(self, event):
newValue = self.rateslider.GetValue()
if self.connChoice.GetSelection() == 0:
newValue = self.rateslider.GetValue() * 50
self.rateSpinner.SetValue (newValue)
self.dow.setUploadRate (newValue)
def onConnScroll(self, event):
self.connSpinner.SetValue (self.connslider.GetValue ())
self.dow.setConns (self.connslider.GetValue ())
def onRateSpinner(self, event):
if self.connChoice.GetSelection() == 0:
newValue = self.rateSpinner.GetValue ()
if newValue != 0:
newValue /= 50
if self.rateSpinner.GetValue () % 10 != 9:
newValue += 1
self.rateslider.SetValue (newValue)
newValue *= 50
if (self.rateSpinner.GetValue () != newValue):
self.rateSpinner.SetValue (newValue)
self.dow.setUploadRate (self.rateSpinner.GetValue ())
else:
self.dow.setUploadRate (self.rateSpinner.GetValue ())
self.rateslider.SetValue (self.rateSpinner.GetValue ())
def onConnSpinner(self, event):
self.connslider.SetValue (self.connSpinner.GetValue())
self.dow.setConns (self.connSpinner.GetValue ())
def onConnChoice(self, event):
num = self.connChoice.GetSelection()
self.rateSpinner.SetValue (connChoices[num]['rate']['def'])
self.rateSpinner.SetRange (connChoices[num]['rate']['min'],
connChoices[num]['rate']['max'])
self.rateslider.SetRange (
connChoices[num]['rate']['min']/connChoices[num]['rate'].get('div',1),
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -