📄 btmaketorrentgui.py
字号:
#!/usr/bin/env python# Written by Bram Cohen# modified for multitracker by John Hoffman# see LICENSE.txt for license information#import PSYCO#if PSYCO.psyco:# try:# import psyco# assert psyco.__version__ >= 0x010100f0# psyco.full()# except:# passfrom sys import argv, versionfrom btcompletedir import completedirfrom btmakemetafile import make_meta_filefrom threading import Event, Threadfrom BitTorrent.bencode import bdecodefrom os.path import join, isdirfrom os import getcwd, pathfrom wxPython.wx import *true = 1false = 0wxEVT_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 = kwargsclass AnnounceFile: def __init__(self, announceconf): self.announcelst = [] self.piece_size = 0 self.announcedefault = "" self.announceconf = announceconf def readConfig(self): f = open(self.announceconf, 'rb') while True: configline = f.readline() if configline == "" or configline == "\n": break else: configmap = configline.split("=") if configmap[0] == "piece_size": self.piece_size = int(configmap[1][0:-1]) elif configmap[0] == "announce": self.announcelst.append(configmap[1][0:-1]) elif configmap[0] == "announcedefault": self.announcelst.append(configmap[1][0:-1]) self.announcedefault = configmap[1][0:-1] f.close() return self.announcedefault, self.announcelst, self.piece_size def saveDefault(self, piece, url): numslot = -1 self.piece_size = piece print "piece_size = %d" % piece for i in range(0, len(self.announcelst)): if self.announcelst[i] == url: numslot = i break if numslot == -1: #current URL is bad if len(self.announcelst) != 0: self.announcedefault = self.announcelst[0] f = open(self.announceconf, 'wb') f.writelines("piece_size=" + str(piece) + "\n") for i in range(0, len(self.announcelst)): if self.announcelst[i] == self.announcedefault: f.writelines("announcedefault="+self.announcedefault+"\n") else: f.writelines("announce="+self.announcelst[i]+"\n") f.close() def addAnnounce(self, url): self.announcelst.append(url) self.announcedefault = url f = open(self.announceconf, 'wb') f.writelines("piece_size=" + str(self.piece_size) + "\n") for i in range(0, len(self.announcelst)): if self.announcelst[i] == self.announcedefault: f.writelines("announcedefault="+self.announcedefault+"\n") else: f.writelines("announce="+self.announcelst[i]+"\n") f.close() def removeAnnounce(self, url): numslot = -1 for i in range(0, len(self.announcelst)): if self.announcelst[i] == url: numslot = i break if numslot == -1: return else: del self.announcelst[i] if self.announcedefault == url: if len(self.announcelst) != 0: self.announcedefault = self.announcelst[0] else: self.announcedefault = '' f = open(self.announceconf, 'wb') f.writelines("piece_size=" + str(self.piece_size) + "\n") for i in range(0, len(self.announcelst)): if self.announcelst[i] == self.announcedefault: f.writelines("announcedefault="+self.announcedefault+"\n") else: f.writelines("announce="+self.announcelst[i]+"\n") f.close()class DownloadInfo: def __init__(self, parent, abcpath): self.parent = parent frame = wxFrame(self.parent, -1, 'BitTorrent Torrent File Maker', size = wxSize(550, 410)) self.frame = frame if (sys.platform == 'win32'): self.icon = wxIcon(path.join(abcpath, 'icon_abc.ico'), wxBITMAP_TYPE_ICO) self.frame.SetIcon(self.icon) self.announceconf = AnnounceFile(path.join(abcpath, "announce.lst")) # Read config file ######################### self.announcedefault, self.announcelst, self.piece_size = self.announceconf.readConfig() panel = wxPanel(frame, -1) gridSizer = wxFlexGridSizer(cols = 2, rows = 2, vgap = 0, hgap = 8) gridSizer.Add(wxStaticText(panel, -1, 'make torrent of:')) b = wxBoxSizer(wxHORIZONTAL) self.dirCtl = wxTextCtrl(panel, -1, '') b.Add(self.dirCtl, 1, wxEXPAND) b.Add(10, 10, 0, wxEXPAND) button = wxButton(panel, -1, 'dir', size = (30,20)) EVT_BUTTON(frame, button.GetId(), self.selectdir) b.Add(button, 0) button2 = wxButton(panel, -1, 'file', size = (30,20)) EVT_BUTTON(frame, button2.GetId(), self.selectfile) b.Add(button2, 0) gridSizer.Add(b, 0, wxEXPAND) gridSizer.Add(wxStaticText(panel, -1, '')) gridSizer.Add(wxStaticText(panel, -1, '')) gridSizer.Add(wxStaticText(panel, -1, 'announce url:')) b = wxBoxSizer(wxHORIZONTAL) #self.annCtl = wxTextCtrl(panel, -1, '') self.annCtl = wxComboBox(panel, -1, self.announcedefault,choices=self.announcelst, style=wxCB_DROPDOWN) b.Add(self.annCtl, 1, wxEXPAND) b.Add(10, 10, 0, wxEXPAND) button = wxButton(panel, -1, 'Add', size = (30,20)) EVT_BUTTON(frame, button.GetId(), self.addAnnounce) b.Add(button, 0) button2 = wxButton(panel, -1, 'Remove', size = (60,20)) EVT_BUTTON(frame, button2.GetId(), self.removeAnnounce) b.Add(button2, 0) # Change here to combobox gridSizer.Add(b, 0, wxEXPAND) gridSizer.Add(wxStaticText(panel, -1, '')) gridSizer.Add(wxStaticText(panel, -1, '')) a = wxFlexGridSizer(cols = 1) a.Add(wxStaticText(panel, -1, 'announce list:')) a.Add(wxStaticText(panel, -1, '')) abutton = wxButton(panel, -1, 'copy\nannounces\nfrom\ntorrent', size = (50,70)) EVT_BUTTON(frame, abutton.GetId(), self.announcecopy) a.Add(abutton, 0, wxEXPAND) gridSizer.Add(a, 0, wxEXPAND) self.annListCtl = wxTextCtrl(panel, -1, '\n\n\n\n\n', wxPoint(-1,-1), (400,120), wxTE_MULTILINE|wxHSCROLL|wxTE_DONTWRAP) gridSizer.Add(self.annListCtl, -1, wxEXPAND) gridSizer.Add(wxStaticText(panel, -1, '')) exptext = wxStaticText(panel, -1, "a list of announces separated by commas " + "or whitespace and on several lines -\n" + "trackers on the same line will be tried randomly," + "and all the trackers on one line\n" + "will be tried before the trackers on the next line.") exptext.SetFont(wxFont(6, wxDEFAULT, wxNORMAL, wxNORMAL, false)) gridSizer.Add(exptext) gridSizer.Add(wxStaticText(panel, -1, '')) gridSizer.Add(wxStaticText(panel, -1, '')) gridSizer.Add(wxStaticText(panel, -1, 'piece size:')) self.piece_length = wxChoice(panel, -1, choices = ['automatic', '2MiB', '1MiB', '512KiB', '256KiB', '128KiB', '64KiB', '32KiB']) self.piece_length_list = [0, 21, 20, 19, 18, 17, 16, 15] self.piece_length.SetSelection(self.piece_size) gridSizer.Add(self.piece_length) gridSizer.Add(wxStaticText(panel, -1, '')) gridSizer.Add(wxStaticText(panel, -1, '')) gridSizer.Add(wxStaticText(panel, -1, 'comment:')) self.commentCtl = wxTextCtrl(panel, -1, '') gridSizer.Add(self.commentCtl, 0, wxEXPAND) gridSizer.AddGrowableCol(1) border = wxBoxSizer(wxVERTICAL) border.Add(gridSizer, 0, wxEXPAND | wxNORTH | wxEAST | wxWEST, 25) btnbox = wxBoxSizer(wxHORIZONTAL) b3 = wxButton(panel, -1, 'Save as default config') btnbox.Add(b3, 1, wxEXPAND) btnbox.Add(10, 10, 0, wxEXPAND) b2 = wxButton(panel, -1, 'Make Torrent') btnbox.Add(b2, 1, wxEXPAND) btnbox.Add(10, 10, 0, wxEXPAND) b4 = wxButton(panel, -1, 'Close') btnbox.Add(b4, 1, wxEXPAND) btnbox.Add(10, 10, 0, wxEXPAND) border.Add(10, 10, 1, wxEXPAND) border.Add(btnbox, 0, wxALIGN_CENTER | wxSOUTH, 20) EVT_BUTTON(frame, b2.GetId(), self.complete) EVT_BUTTON(frame, b3.GetId(), self.saveconfig)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -