def GetMidPanel(self, hSizer): self.totals = [] for i in xrange(len(self.columns)): if self.columns[i]['width'] == wx.LIST_AUTOSIZE: option = 1 size = wx.DefaultSize else: option = 0 size = (self.columns[i]['width'], -1) label = StaticText(self, i, '', style=self.columns[i].get('footer_style', 0) | wx.ST_NO_AUTORESIZE, size=size) hSizer.Add(label, option, wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.TOP | wx.BOTTOM, 3) if self.columns[i]['width'] == wx.LIST_AUTOSIZE: label.SetMinSize((1, -1)) self.totals.append(label) self.scrollBar = hSizer.AddSpacer((3, 0)) self.scrollBar.sizer = hSizer
class ChannelFooter(ListFooter): def GetMidPanel(self, hSizer): self.hSizer = hSizer self.message = StaticText(self) self.message.SetMinSize((1, -1)) font = self.message.GetFont() font.SetPointSize(font.GetPointSize() + 2) font.SetWeight(wx.FONTWEIGHT_BOLD) self.message.SetFont(font) self.subtitle = wx.StaticText(self) self.subtitle.SetMinSize((1, -1)) self.manage = wx.Button(self, -1, 'Edit this Channel') self.spam = wx.Button(self, -1, 'Mark as Spam') self.favorite = wx.Button(self, -1, 'Mark as Favorite') self.ortext = None self.subtitle.Show(False) self.favorite.Show(False) self.spam.Show(False) self.manage.Show(False) def SetEvents(self, spam, favorite, remove, manage): self.spam_eventhandler = spam self.favorite_eventhandler = favorite self.remove_eventhandler = remove self.manage.Bind(wx.EVT_BUTTON, manage) def SetStates(self, vote, channelstate, iamModerator): self.Freeze() self.hSizer.Clear() explicit_vote = vote != 0 preview = not explicit_vote and not iamModerator open2edit = channelstate == ChannelCommunity.CHANNEL_CLOSED and iamModerator allow2edit = vote == 2 and channelstate == ChannelCommunity.CHANNEL_OPEN self.favorite.Show(False) self.spam.Show(False) self.manage.Show(False) #clean up old ortext statictext if self.ortext: self.ortext.Destroy() self.ortext = None header = '' msg = '' buttonSizer = None if preview: header = "You are looking at a preview of this Channel." msg = "If you want to see more of it, press the 'Mark as Favorite' button.\nTribler will then more aggressively download updates making sure you always have access to the newest content." self.spam.SetLabel('Mark as Spam') self.spam.Bind(wx.EVT_BUTTON, self.spam_eventhandler) self.spam.Show(True) self.ortext = wx.StaticText(self, -1, 'or') self.favorite.SetLabel('Mark as Favorite') self.favorite.Bind(wx.EVT_BUTTON, self.favorite_eventhandler) self.favorite.Show(True) buttonSizer = wx.BoxSizer(wx.HORIZONTAL) buttonSizer.Add(self.spam) buttonSizer.Add(self.ortext, 0, wx.LEFT | wx.RIGHT | wx.ALIGN_CENTRE_VERTICAL, 3) buttonSizer.Add(self.favorite) else: if open2edit: header = "You can now enable community-features for this Channel." msg = "Allowing other users to comment, modify and improve meta-data will increase the overall community feel. Try it now.\nEdit your channel settings to get started." self.manage.Show(True) buttonSizer = self.manage elif allow2edit: header = "This is an open community. You can modify, comment and add new content. Feel free to do so." self.manage.Show(True) buttonSizer = self.manage if vote == -1: header = '' msg = "You have marked this Channel as Spam." self.spam.SetLabel('This is not Spam') self.spam.Bind(wx.EVT_BUTTON, self.remove_eventhandler) self.spam.Show(True) buttonSizer = self.spam elif vote == 2: if msg == '': msg = "Thank you for marking this Channel as your Favorite." self.favorite.SetLabel('Remove Favorite') self.favorite.Bind(wx.EVT_BUTTON, self.remove_eventhandler) self.favorite.Show(True) if buttonSizer: sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(buttonSizer) sizer.Add(self.favorite) buttonSizer = sizer else: buttonSizer = self.favorite else: if msg == '': msg = "You can edit this channel" self.manage.Show(True) buttonSizer = self.manage if header != '': self.message.SetLabel(header) self.subtitle.SetLabel(msg) self.subtitle.Show(True) vSizer = wx.BoxSizer(wx.VERTICAL) vSizer.Add(self.message, 0, wx.EXPAND) if buttonSizer: if preview: vSizer.Add(self.subtitle, 0, wx.EXPAND) vSizer.Add(buttonSizer, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10) else: sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.subtitle, 1, wx.EXPAND) sizer.Add(buttonSizer, 0, wx.TOP | wx.BOTTOM | wx.RIGHT, 3) vSizer.Add(sizer, 0, wx.EXPAND) else: vSizer.Add(self.subtitle, 0, wx.EXPAND) self.hSizer.Add(vSizer, 1, wx.EXPAND | wx.TOP | wx.BOTTOM, 7) else: self.message.SetLabel(msg) self.subtitle.Show(False) self.hSizer.Add(self.message, 1, wx.TOP | wx.BOTTOM | wx.ALIGN_BOTTOM | wx.LEFT, 7) self.hSizer.Add(buttonSizer, 0, wx.TOP | wx.BOTTOM | wx.RIGHT, 7) self.hSizer.Layout() self.Layout() self.Thaw() def Reset(self): ListFooter.Reset(self) self.Freeze() self.hSizer.Clear() self.subtitle.Show(False) self.favorite.Show(False) self.spam.Show(False) self.manage.Show(False) self.message.SetLabel('') self.Thaw() def GetStates(self): return (self.spam.GetLabel() == 'This is not Spam', self.favorite.GetLabel() == 'Remove Favorite')
def __init__(self, parent, torrents): canEdit = False single = len(torrents) == 1 if single and torrents[0].hasChannel(): state = torrents[0].channel.getState() canEdit = state >= ChannelCommunity.CHANNEL_OPEN wx.Dialog.__init__( self, parent, -1, 'Are you sure you want to remove the selected torrent%s?' % ('' if single else 's'), size=(600, -1), name="RemoveTorrent") bitmap = wx.ArtProvider.GetBitmap(wx.ART_QUESTION, wx.ART_MESSAGE_BOX) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(wx.StaticBitmap(self, -1, bitmap), 0, wx.RIGHT, 10) vSizer = wx.BoxSizer(wx.VERTICAL) firstLine = StaticText(self, -1, '') _set_font(firstLine, fontweight=wx.FONTWEIGHT_BOLD) if single: firstLineMsg = "Delete '%s' from disk, or just remove it from your downloads?" % torrents[ 0].name else: firstLineMsg = "Delete %s torrents from disk, or just remove them from your downloads?" % len( torrents) cdc = wx.ClientDC(firstLine) cdc.SetFont(firstLine.GetFont()) firstLineMsg = wordwrap(firstLineMsg, self.GetSize()[0] - bitmap.GetSize()[0] - 30, cdc, breakLongWords=True, margin=0) firstLine.SetLabel(firstLineMsg) firstLine.SetMinSize((1, -1)) vSizer.Add(firstLine, 0, wx.EXPAND | wx.BOTTOM, 3) vSizer.Add( StaticText( self, -1, "Removing from disk will move the selected item%s to your trash." % ('' if single else 's')), 0, wx.EXPAND) vSizer.AddStretchSpacer() self.newName = None if single and canEdit: vSizer.Add( StaticText( self, -1, "While we're at it, can you improve the name of this torrent?" ), 0, wx.EXPAND | wx.BOTTOM, 3) self.newName = EditText(self, torrents[0].name) vSizer.Add(self.newName, 0, wx.EXPAND) vSizer.AddStretchSpacer() bSizer = wx.BoxSizer(wx.HORIZONTAL) bSizer.AddStretchSpacer() bSizer.Add(wx.Button(self, wx.ID_CANCEL), 0, wx.RIGHT, 3) bSizer.Add( wx.Button(self, wx.ID_DEFAULT, 'Only delete from downloads'), 0, wx.RIGHT, 3) bSizer.Add(wx.Button(self, wx.ID_DELETE, 'Also delete from disk')) vSizer.Add(bSizer, 0, wx.ALIGN_RIGHT | wx.TOP, 7) hSizer.Add(vSizer, 1, wx.EXPAND) border = wx.BoxSizer() border.Add(hSizer, 1, wx.ALL | wx.EXPAND, 10) self.Bind(wx.EVT_BUTTON, lambda event: self.EndModal(event.GetId())) self.SetSizer(border) self.SetSize((-1, self.GetBestSize()[1])) self.Layout() self.CenterOnParent()
def __init__(self, parent, torrent): canEdit = canComment = False if torrent.hasChannel(): state, iamModerator = torrent.channel.getState() canEdit = state >= ChannelCommunity.CHANNEL_OPEN height = 125 if canEdit: height = 200 wx.Dialog.__init__(self, parent, -1, 'Are you sure you want to remove this torrent?', size=(600, height)) bitmap = wx.ArtProvider.GetBitmap(wx.ART_QUESTION, wx.ART_MESSAGE_BOX) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(wx.StaticBitmap(self, -1, bitmap), 0, wx.RIGHT, 10) vSizer = wx.BoxSizer(wx.VERTICAL) firstLine = StaticText( self, -1, "Delete '%s' from disk, or just remove them from your downloads?" % torrent.name) _set_font(firstLine, fontweight=wx.FONTWEIGHT_BOLD) firstLine.Wrap(self.GetSize()[0] - bitmap.GetSize()[0] - 10) firstLine.SetMinSize((1, -1)) vSizer.Add(firstLine, 0, wx.EXPAND | wx.BOTTOM, 3) vSizer.Add( StaticText( self, -1, "Removing from disk will move the selected item to your trash." ), 0, wx.EXPAND) vSizer.AddStretchSpacer() self.newName = None if canEdit: vSizer.Add( StaticText( self, -1, "While we're at it, can you improve the name of this torrent?" ), 0, wx.EXPAND | wx.BOTTOM, 3) self.newName = EditText(self, torrent.name) vSizer.Add(self.newName, 0, wx.EXPAND) vSizer.AddStretchSpacer() bSizer = wx.BoxSizer(wx.HORIZONTAL) bSizer.AddStretchSpacer() bSizer.Add(wx.Button(self, wx.ID_CANCEL), 0, wx.RIGHT, 3) bSizer.Add( wx.Button(self, wx.ID_DEFAULT, 'Only delete from downloads'), 0, wx.RIGHT, 3) bSizer.Add(wx.Button(self, wx.ID_DELETE, 'Also delete from disk')) vSizer.Add(bSizer, 0, wx.ALIGN_RIGHT | wx.TOP, 7) hSizer.Add(vSizer, 1, wx.EXPAND) border = wx.BoxSizer() border.Add(hSizer, 1, wx.ALL | wx.EXPAND, 10) self.Bind(wx.EVT_BUTTON, lambda event: self.EndModal(event.GetId())) self.SetSizer(border) self.Layout() self.CenterOnParent()