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

📄 btmaketorrentgui.py

📁 ABC-win32-v3.1 一个P2P软源代码
💻 PY
📖 第 1 页 / 共 2 页
字号:
#!/usr/bin/env python# Written by Bram Cohen# modified for multitracker by John Hoffman# see LICENSE.txt for license informationimport sysimport wximport osfrom os.path import join, isdir, exists, normpath, splitfrom threading import Event, Threadfrom shutil import copy2from traceback import print_excfrom TorrentMaker.btmakemetafile import make_meta_file, completedirfrom Utility.helpers import unionfrom Utility.constants import * #IGNORE:W0611wxEVT_INVOKE = wx.NewEventType()def EVT_INVOKE(win, func):    win.Connect(-1, -1, wxEVT_INVOKE, func)class InvokeEvent(wx.PyEvent):    def __init__(self, func, args, kwargs):        wx.PyEvent.__init__(self)        self.SetEventType(wxEVT_INVOKE)        self.func = func        self.args = args        self.kwargs = kwargs################################################################## Class: MiscInfoPanel## Panel for defining miscellaneous settings for a torrent#################################################################class MiscInfoPanel(wx.Panel):    def __init__(self, parent, dialog):        wx.Panel.__init__(self, parent, -1)                self.dialog = dialog        self.utility = dialog.utility        outerbox = wx.BoxSizer(wx.VERTICAL)        # Created by:        outerbox.Add(wx.StaticText(self, -1, self.utility.lang.get('createdby')), 0, wx.EXPAND|wx.ALL, 5)        self.createdBy = wx.TextCtrl(self, -1)        outerbox.Add(self.createdBy, 0, wx.EXPAND|wx.ALL, 5)        # Comment:                outerbox.Add(wx.StaticText(self, -1, self.utility.lang.get('comment')), 0, wx.EXPAND|wx.ALL, 5)        self.commentCtl = wx.TextCtrl(self, -1, size = (-1, 75), style = wx.TE_MULTILINE|wx.HSCROLL|wx.TE_DONTWRAP)                outerbox.Add(self.commentCtl, 0, wx.EXPAND|wx.ALL, 5)              self.SetSizerAndFit(outerbox)                self.loadValues()    def loadValues(self, Read = None):        if Read is None:            Read = self.utility.makerconfig.Read                self.createdBy.SetValue(Read('created_by'))        self.commentCtl.SetValue(Read('comment'))    def saveConfig(self, event = None):        self.utility.makerconfig.Write('created_by', self.createdBy.GetValue())        self.utility.makerconfig.Write('comment', self.commentCtl.GetValue())            def getParams(self):        params = {}                comment = self.commentCtl.GetValue()        if comment != '':            params['comment'] = comment        createdby = self.createdBy.GetValue()        if comment != '':            params['created by'] = createdby                    return params################################################################## Class: TrackerInfoPanel## Panel for defining tracker settings for a torrent#################################################################class TrackerInfoPanel(wx.Panel):    def __init__(self, parent, dialog):        wx.Panel.__init__(self, parent, -1)                self.dialog = dialog        self.utility = dialog.utility        outerbox = wx.BoxSizer(wx.VERTICAL)        announcesection_title = wx.StaticBox(self, -1, self.utility.lang.get('announce'))        announcesection = wx.StaticBoxSizer(announcesection_title, wx.VERTICAL)        self.announcehistory = []        # Copy announce from torrent        abutton = wx.Button(self, -1, self.utility.lang.get('copyannouncefromtorrent'))        wx.EVT_BUTTON(self, abutton.GetId(), self.announceCopy)        announcesection.Add(abutton, 0, wx.ALL, 5)        # Announce url:        announcesection.Add(wx.StaticText(self, -1, self.utility.lang.get('announceurl')), 0, wx.ALL, 5)        announceurl_box = wx.BoxSizer(wx.HORIZONTAL)               self.annCtl = wx.ComboBox(self, -1, "", choices = self.announcehistory, style=wx.CB_DROPDOWN)        announceurl_box.Add(self.annCtl, 1, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 5)                button = wx.Button(self, -1, "+", size = (30, -1))        button.SetToolTipString(self.utility.lang.get('add'))        wx.EVT_BUTTON(self, button.GetId(), self.addAnnounce)        announceurl_box.Add(button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 3)        button2 = wx.Button(self, -1, "-", size = (30, -1))        button2.SetToolTipString(self.utility.lang.get('remove'))        wx.EVT_BUTTON(self, button2.GetId(), self.removeAnnounce)        announceurl_box.Add(button2, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 3)        announcesection.Add(announceurl_box, 0, wx.EXPAND)        # Announce List:                announcesection.Add(wx.StaticText(self, -1, self.utility.lang.get('announcelist')), 0, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)               self.annListCtl = wx.TextCtrl(self, -1, size = (-1, 75), style = wx.TE_MULTILINE|wx.HSCROLL|wx.TE_DONTWRAP)        self.annListCtl.SetToolTipString(self.utility.lang.get('multiannouncehelp'))        announcesection.Add(self.annListCtl, 1, wx.EXPAND|wx.TOP, 5)                outerbox.Add(announcesection, 0, wx.EXPAND|wx.ALL, 3)              # HTTP Seeds:        outerbox.Add(wx.StaticText(self, -1, self.utility.lang.get('httpseeds')), 0, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)               self.httpSeeds = wx.TextCtrl(self, -1, size = (-1, 75), style = wx.TE_MULTILINE|wx.HSCROLL|wx.TE_DONTWRAP)        self.httpSeeds.SetToolTipString(self.utility.lang.get('httpseedshelp'))        outerbox.Add(self.httpSeeds, 1, wx.EXPAND|wx.ALL, 5)              self.SetSizerAndFit(outerbox)                self.loadValues()    def loadValues(self, Read = None):        if Read is None:            Read = self.utility.makerconfig.Read                self.annCtl.Clear()        self.annCtl.SetValue(Read('announcedefault'))        self.announcehistory = Read('announcehistory', "bencode-list")        for announceurl in self.announcehistory:            self.annCtl.Append(announceurl)        self.annListCtl.SetValue(Read('announce-list'))        self.httpSeeds.SetValue(Read('httpseeds'))    def saveConfig(self, event = None):        index = self.annCtl.GetSelection()        if index != -1:            self.utility.makerconfig.Write('announcedefault', self.annCtl.GetValue())        self.utility.makerconfig.Write('announcehistory', self.announcehistory, "bencode-list")        self.utility.makerconfig.Write('announce-list', self.annListCtl.GetValue())        self.utility.makerconfig.Write('httpseeds', self.httpSeeds.GetValue())    def addAnnounce(self, event = None):        announceurl = self.annCtl.GetValue()        # Don't add to the list if it's already present or the string is empty        announceurl = announceurl.strip()        if not announceurl or announceurl in self.announcehistory:            return               self.announcehistory.append(announceurl)        self.annCtl.Append(announceurl)            def removeAnnounce(self, event = None):        index = self.annCtl.GetSelection()        if index != -1:            announceurl = self.annCtl.GetValue()            self.annCtl.Delete(index)            try:                self.announcehistory.remove(announceurl)            except:                pass    def announceCopy(self, event = None):        dl = wx.FileDialog(self.dialog,                            self.utility.lang.get('choosedottorrentfiletouse'),                            '',                            '',                            self.utility.lang.get('torrentfileswildcard') + ' (*.torrent)|*.torrent',                            wx.OPEN)        if dl.ShowModal() == wx.ID_OK:            try:                metainfo = self.utility.getMetainfo(dl.GetPath())                if (metainfo is None):                    return                self.annCtl.SetValue(metainfo['announce'])                if 'announce-list' in metainfo:                    list = []                    for tier in metainfo['announce-list']:                        for tracker in tier:                            list += [tracker, ', ']                        del list[-1]                        list += ['\n']                    liststring = ''                    for i in list:                        liststring += i                    self.annListCtl.SetValue(liststring+'\n\n')                else:                    self.annListCtl.SetValue('')            except:                return                    def getAnnounceList(self):        text = self.annListCtl.GetValue()        list = []        for tier in text.split('\n'):            sublist = []            tier.replace(',', ' ')            for tracker in tier.split(' '):                if tracker != '':                    sublist += [tracker]            if sublist:                list.append(sublist)        return list            def getHTTPSeedList(self):        text = self.httpSeeds.GetValue()        list = []        for tier in text.split('\n'):            tier.replace(',', ' ')            for tracker in tier.split(' '):                if tracker != '':                    list.append(tracker)        return list    def getParams(self):        params = {}                # Announce list        annlist = self.getAnnounceList()        if annlist:            params['real_announce_list'] = annlist                # Announce URL        announceurl = None        index = self.annCtl.GetSelection()        if annlist and index == -1:            # If we don't have an announce url specified,            # try using the first value in announce-list            tier1 = annlist[0]            if tier1:                announceurl = tier1[0]        else:            announceurl = self.annCtl.GetValue()                        if announceurl is None:            # What should we do here?            announceurl = ""                    params['announce'] = announceurl                           # HTTP Seeds        httpseedlist = self.getHTTPSeedList()        if httpseedlist:            params['real_httpseeds'] = httpseedlist                return params################################################################## Class: FileInfoPanel## Class for choosing a file when creating a torrent#################################################################        class FileInfoPanel(wx.Panel):    def __init__(self, parent, dialog):        wx.Panel.__init__(self, parent, -1)                self.dialog = dialog        self.utility = dialog.utility        outerbox = wx.BoxSizer(wx.VERTICAL)        # Make torrent of:        maketorrent_box = wx.BoxSizer(wx.HORIZONTAL)        maketorrent_box.Add(wx.StaticText(self, -1, self.utility.lang.get('maketorrentof')), 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)        self.dirCtl = wx.TextCtrl(self, -1, '')        maketorrent_box.Add(self.dirCtl, 1, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND|wx.ALL, 5)        button = wx.Button(self, -1, self.utility.lang.get('dir'), style = wx.BU_EXACTFIT)        wx.EVT_BUTTON(self, button.GetId(), self.selectDir)        maketorrent_box.Add(button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)        button2 = wx.Button(self, -1, self.utility.lang.get('file'), style = wx.BU_EXACTFIT)        wx.EVT_BUTTON(self, button2.GetId(), self.selectFile)        maketorrent_box.Add(button2, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)        outerbox.Add(maketorrent_box, 0, wx.EXPAND)                # Piece size:        piecesize_box = wx.BoxSizer(wx.HORIZONTAL)                piecesize_box.Add(wx.StaticText(self, -1, self.utility.lang.get('piecesize')), 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)                abbrev_mb = " " + self.utility.lang.get('MB')        abbrev_kb = " " + self.utility.lang.get('KB')                piece_choices = [self.utility.lang.get('automatic'),                          '2' + abbrev_mb,                          '1' + abbrev_mb,                          '512' + abbrev_kb,                          '256' + abbrev_kb,                          '128' + abbrev_kb,                          '64' + abbrev_kb,                          '32' + abbrev_kb]        self.piece_length = wx.Choice(self, -1, choices = piece_choices)        self.piece_length_list = [0, 21, 20, 19, 18, 17, 16, 15]        piecesize_box.Add(self.piece_length, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)                outerbox.Add(piecesize_box, 0, wx.EXPAND)        #        panel.DragAcceptFiles(True)#        wx.EVT_DROP_FILES(panel, self.selectdrop)        # Save torrent :        savetorrentbox = wx.StaticBoxSizer(wx.StaticBox(self, -1, self.utility.lang.get('savetor')), wx.VERTICAL)        self.savetorrb1 = wx.RadioButton(self, -1, self.utility.lang.get('savetordefault'), (-1, -1), (-1, -1), wx.RB_GROUP)        savetorrb2 = wx.RadioButton(self, -1, self.utility.lang.get('savetorsource'), (-1, -1), (-1, -1))        savetorrb3 = wx.RadioButton(self, -1, self.utility.lang.get('savetorask'), (-1, -1), (-1, -1))        self.savetor = [self.savetorrb1, savetorrb2, savetorrb3]        savetordefbox = wx.BoxSizer(wx.HORIZONTAL)        savetordefbox.Add(self.savetorrb1, 0, wx.ALIGN_CENTER_VERTICAL)        self.savetordeftext = wx.TextCtrl(self, -1, "")        browsebtn = wx.Button(self, -1, "...", style = wx.BU_EXACTFIT)        browsebtn.Bind(wx.EVT_BUTTON, self.onBrowseDir)        savetordefbox.Add(self.savetordeftext, 1, wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 5)        savetordefbox.Add(browsebtn, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 3)        savetorrentbox.Add(savetordefbox, 0, wx.EXPAND)                savetorrentbox.Add(savetorrb2, 0)        savetorrentbox.Add(savetorrb3, 0, wx.TOP, 4)        outerbox.Add(savetorrentbox, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)        optionalhash_title = wx.StaticBox(self, -1, self.utility.lang.get('makehash_optional'))        optionalhash = wx.StaticBoxSizer(optionalhash_title, wx.VERTICAL)        self.makehash_md5 = wx.CheckBox(self, -1, self.utility.lang.get('makehash_md5'))        optionalhash.Add(self.makehash_md5, 0)        self.makehash_crc32 = wx.CheckBox(self, -1, self.utility.lang.get('makehash_crc32'))        optionalhash.Add(self.makehash_crc32, 0, wx.TOP, 4)        self.makehash_sha1 = wx.CheckBox(self, -1, self.utility.lang.get('makehash_sha1'))        optionalhash.Add(self.makehash_sha1, 0, wx.TOP, 4)                outerbox.Add(optionalhash, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)        self.startnow = wx.CheckBox(self, -1, self.utility.lang.get('startnow'))        outerbox.Add(self.startnow, 0, wx.ALIGN_LEFT|wx.ALL, 5)        self.SetSizerAndFit(outerbox)                self.loadValues()#        panel.DragAcceptFiles(True)#        wx.EVT_DROP_FILES(panel, self.selectdrop)    def loadValues(self, Read = None):

⌨️ 快捷键说明

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