コード例 #1
0
    def __init__(self, parent, config):
        BTFrameWithSizer.__init__(self, parent,
                         style=wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX|wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX|wx.CLIP_CHILDREN |wx.RESIZE_BORDER)  # HERE HACK.  I added RESIZE_BORDER because the window doesn't resize properly when Advanced button is pressed. --Dave
	self.parent = parent
        self.SetTitle(_("%s Publisher")%(app_name))
        self.config = config
        self.tracker_list = []
        if self.config['tracker_list']:
            self.tracker_list = self.config['tracker_list'].split(',')

        ## widgets

        # file widgets
        self.top_text = wx.StaticText(self.panel,
                                      label=_("Publish this file/directory:"))

        self.dir_text = wx.StaticText(self.panel,
                                      label= _("(Directories will become batch torrents)"))

        # title widgets
        self.title_label = wx.StaticText(self.panel, label=_("Title"))
        self.title = wx.TextCtrl(self.panel)
        self.title.SetValue(self.config['title'])

        # Comment widgets
        self.comment_label = wx.StaticText(self.panel, label=_("Comments:"))
        self.comment_text = wx.TextCtrl(self.panel, style=wx.TE_MULTILINE, size=(-1,50))
        self.comment_text.SetValue(self.config['comment'])

        # horizontal line
        self.simple_advanced_line = wx.StaticLine(self.panel, style=wx.LI_HORIZONTAL)

        # piece size widgets
        self.piece_size_label = wx.StaticText(self.panel, label=_("Piece size:"))
        self.piece_size = wx.Choice(self.panel)
        self.piece_size.Append(_("Auto"))
        self.piece_size.offset = 15
        for i in range(7):
            self.piece_size.Append(str(Size(2**(i+self.piece_size.offset))))
        self.piece_size.SetSelection(0)

        # Announce URL / Tracker widgets
        self.tracker_radio = wx.RadioButton(self.panel, label=_("Use &tracker:"), style=wx.RB_GROUP)
        self.tracker_radio.group = [self.tracker_radio, ]
        self.tracker_radio.value = True

        self.announce_entry = wx.ComboBox(self.panel, style=wx.CB_DROPDOWN,
                                          choices=self.tracker_list)

        self.tracker_radio.entry = self.announce_entry
        if self.tracker_radio.GetValue():
            self.announce_entry.Enable(True)
        else:
            self.announce_entry.Enable(False)

        if self.config['tracker_name']:
            self.announce_entry.SetValue(self.config['tracker_name'])
        elif len(self.tracker_list):
            self.announce_entry.SetValue(self.tracker_list[0])
        else:
            self.announce_entry.SetValue('http://my.tracker:6969/announce')

        # DHT / Trackerless widgets
        self.dht_radio = wx.RadioButton(self.panel, label=_("Use &DHT:"))
        self.tracker_radio.group.append(self.dht_radio)
        self.dht_radio.value = False

        self.dht_nodes_box = wx.StaticBox(self.panel, label=_("Nodes (optional):"))
        self.dht_nodes = NodeList(self.panel, 'router.bittorrent.com:6881')

        self.dht_radio.entry = self.dht_nodes

        for w in self.tracker_radio.group:
            w.Bind(wx.EVT_RADIOBUTTON, self.toggle_tracker_dht)

        for w in self.tracker_radio.group:
            if w.value == bool(self.config['use_tracker']):
                w.SetValue(True)
            else:
                w.SetValue(False)

        if self.config['use_tracker']:
            self.dht_nodes.Disable()
        else:
            self.announce_entry.Disable()

        # Button widgets
        self.quitbutton = wx.Button(self.panel, label=_("&Close"))
        self.quitbutton.Bind(wx.EVT_BUTTON, self.quit)
        self.makebutton = wx.Button(self.panel, label=_("&Publish"))
        self.makebutton.Bind(wx.EVT_BUTTON, self.make)
        self.makebutton.Enable(False)

        self.advancedbutton = wx.Button(self.panel, label=_("&Advanced"))
        self.advancedbutton.Bind(wx.EVT_BUTTON, self.toggle_advanced)
        self.simplebutton = wx.Button(self.panel, label=_("&Simple"))
        self.simplebutton.Bind(wx.EVT_BUTTON, self.toggle_advanced)

        ## sizers
        # file sizers
        def setfunc(path):
            self.config['torrent_dir'] = path
        path = ''
        if self.config.has_key('torrent_dir') and self.config['torrent_dir']:
            path = self.config['torrent_dir']
        elif self.config.has_key('open_from') and self.config['open_from']:
            path = self.config['open_from']
        elif self.config.has_key('save_in') and self.config['save_in']:
            path = self.config['save_in']
        self.choose_file_sizer = ChooseFileOrDirectorySizer(self.panel, path,
                                                            setfunc=setfunc)

        self.choose_file_sizer.pathbox.Bind(wx.EVT_TEXT, self.check_buttons)

        self.box = self.panel.sizer
        self.box.AddFirst(self.top_text, flag=wx.ALIGN_LEFT)
        self.box.Add(self.choose_file_sizer, flag=wx.GROW)
        self.box.Add(self.dir_text, flag=wx.ALIGN_LEFT)
        self.box.Add(wx.StaticLine(self.panel, style=wx.LI_HORIZONTAL), flag=wx.GROW)

        # Ye Olde Flexe Gryde Syzer
        self.table = wx.FlexGridSizer(5,2,SPACING,SPACING)

        # Title
        self.table.Add(self.title_label, flag=wx.ALIGN_CENTER_VERTICAL)
        self.table.Add(self.title, flag=wx.GROW)

        # Comments
        self.table.Add(self.comment_label, flag=wx.ALIGN_CENTER_VERTICAL)
        self.table.Add(self.comment_text, flag=wx.GROW)

        # separator
        self.table.Add((0,0),0)
        self.table.Add(self.simple_advanced_line, flag=wx.GROW)

        # Piece size sizers
        self.table.Add(self.piece_size_label, flag=wx.ALIGN_CENTER_VERTICAL)
        self.table.Add(self.piece_size, flag=wx.GROW)

        # Announce URL / Tracker sizers
        self.table.Add(self.tracker_radio, flag=wx.ALIGN_CENTER_VERTICAL)
        self.table.Add(self.announce_entry,flag=wx.GROW)

        # DHT / Trackerless sizers
        self.table.Add(self.dht_radio, flag=wx.ALIGN_CENTER_VERTICAL)

        self.dht_nodes_sizer = wx.StaticBoxSizer(self.dht_nodes_box, wx.VERTICAL)
        self.dht_nodes_sizer.Add(self.dht_nodes, flag=wx.ALL, border=SPACING)

        self.table.Add(self.dht_nodes_sizer, flag=wx.GROW)

        # add table
        self.table.AddGrowableCol(1)
        self.box.Add(self.table, flag=wx.GROW)

        self.box.Add(wx.StaticLine(self.panel, style=wx.LI_HORIZONTAL), flag=wx.GROW)

        # Button sizers
        self.buttonbox = HSizer()

        self.buttonbox.AddFirst(self.advancedbutton)
        self.buttonbox.Add(self.simplebutton)
        self.buttonbox.Add(self.quitbutton)
        self.buttonbox.Add(self.makebutton)

        self.box.Add(self.buttonbox, flag=wx.ALIGN_RIGHT, border=0)

        # bind a bunch of things to check_buttons
        self.announce_entry.Bind(wx.EVT_TEXT, self.check_buttons)
        self.choose_file_sizer.pathbox.Bind(wx.EVT_TEXT, self.check_buttons)
        # radio buttons are checked in toggle_tracker_dht

        minwidth = self.GetBestSize()[0]
        self.SetMinSize(wx.Size(minwidth, -1))

        # Flip advanced once because toggle_advanced flips it back
        self.advanced = True
        self.toggle_advanced(None)
        if self.config['verbose']:
            self.toggle_advanced(None)

        self.check_buttons()

        self.Show()

        self.Bind(wx.EVT_CLOSE, self.quit)
コード例 #2
0
 def __init__(self, *a, **k):
     BTFrameWithSizer.__init__(self, *a, **k)
     self.Fit()