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
def addColumn(strkey, strtooltip): # strkey = key.replace("_", " ").capitalize() header = StaticText(self.panel, -1, strkey) _set_font(header, fontweight=wx.FONTWEIGHT_BOLD) self.gridSizer.Add(header) self.textdict[strkey] = StaticText(self.panel, -1, '') self.textdict[strkey].SetMinSize((200, -1)) self.gridSizer.Add(self.textdict[strkey]) if strtooltip: header.SetToolTipString(strtooltip) self.textdict[strkey].SetToolTipString(strtooltip)
def GetMidPanel(self, hSizer): hSizer.AddStretchSpacer() self.title = StaticText(self) hSizer.Add(self.title) self.scrollBar = hSizer.AddSpacer((0, 0)) self.scrollBar.sizer = hSizer
def AddHeader(self): sizer = wx.BoxSizer(wx.HORIZONTAL) self.header = StaticText(self.parent, -1, ' ') self.info_icon = wx.StaticBitmap(self.parent, -1, self.icons['info']) sizer.Add(self.header, 0, wx.RIGHT, 7) sizer.Add(self.info_icon, 0, wx.ALIGN_CENTER_VERTICAL) self.vsizer.Add(sizer, 0, wx.BOTTOM, 3)
def GetMidPanel(self, hSizer): self.message = StaticText(self) font = self.message.GetFont() font.SetPointSize(font.GetPointSize() + 2) font.SetWeight(wx.FONTWEIGHT_BOLD) self.message.SetFont(font) hSizer.Add(self.message, 0, wx.TOP | wx.BOTTOM | wx.ALIGN_BOTTOM, 3) hSizer.AddStretchSpacer() self.channelResults = wx.Button(self, -1, "Channel Results") hSizer.Add(self.channelResults, 0, wx.TOP | wx.BOTTOM, 3)
def _DoInit(self): try: disp = DispersyPanel(self) except: #Dispersy not ready, try again in 5s if self.createTimer is None: self.createTimer = wx.CallLater(5000, self._DoInit) else: self.createTimer.Restart(5000) print_exc() return self.SetBackgroundColour(DEFAULT_BACKGROUND) vSizer = wx.BoxSizer(wx.VERTICAL) self.dowserStatus = StaticText(self, -1, 'Dowser is not running') self.dowserButton = wx.Button(self, -1, 'Start dowser') self.dowserButton.Bind(wx.EVT_BUTTON, self.OnDowser) self.memdumpButton = wx.Button(self, -1, 'Dump memory') self.memdumpButton.Bind(wx.EVT_BUTTON, self.OnMemdump) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(self.dowserStatus, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 3) hSizer.Add(self.dowserButton) hSizer.Add(self.memdumpButton, 0, wx.RIGHT, 3) vSizer.Add(hSizer, 0, wx.ALIGN_RIGHT | wx.TOP | wx.BOTTOM, 3) vSizer.Add(disp, 1, wx.EXPAND | wx.BOTTOM, 3) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(NetworkPanel(self), 1, wx.EXPAND | wx.RIGHT, 7) self.activity = ActivityPanel(self) hSizer.Add(self.activity, 1, wx.EXPAND) vSizer.Add(hSizer, 0, wx.EXPAND) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(NewTorrentPanel(self), 1, wx.EXPAND | wx.RIGHT, 7) hSizer.Add(PopularTorrentPanel(self), 1, wx.EXPAND, 7) vSizer.Add(hSizer, 0, wx.EXPAND) self.SetSizer(vSizer) self.Layout() self.Bind(wx.EVT_KEY_UP, self.onKey) if sys.platform.startswith('win'): # on Windows, the panel doesn't respond to keypresses self.Bind(wx.EVT_MOUSE_EVENTS, self.onMouse) self.isReady = True
class ChannelResultFooter(ListFooter): def GetMidPanel(self, hSizer): self.message = StaticText(self) font = self.message.GetFont() font.SetPointSize(font.GetPointSize() + 2) font.SetWeight(wx.FONTWEIGHT_BOLD) self.message.SetFont(font) hSizer.Add(self.message, 0, wx.TOP | wx.BOTTOM | wx.ALIGN_BOTTOM, 3) hSizer.AddStretchSpacer() self.channelResults = wx.Button(self, -1, "Channel Results") hSizer.Add(self.channelResults, 0, wx.TOP | wx.BOTTOM, 3) def SetLabel(self, label, nr_channels): haveResults = True if nr_channels and nr_channels >= 1 else False if label != self.message.GetLabel(): self.message.SetLabel(label) if haveResults: self.HighLight() self.Layout() self.EnableResults(haveResults) def SetEvents(self, channel): #removing old, binding new eventhandler self.channelResults.Unbind(wx.EVT_BUTTON) self.channelResults.Bind(wx.EVT_BUTTON, channel) def EnableResults(self, state): self.channelResults.Enable(state) def Reset(self): self.EnableResults(False) self.message.SetLabel('')
def CreatePanel(self): panel = wx.Panel(self) panel.SetBackgroundColour(DEFAULT_BACKGROUND) vSizer = wx.BoxSizer(wx.VERTICAL) self.nrTorrents = StaticText(panel) self.nrFiles = StaticText(panel) self.totalSize = StaticText(panel) self.queueSize = StaticText(panel) self.queueSize.SetToolTipString('Number of torrents queued per prio') self.queueSuccess = StaticText(panel) self.queueBW = StaticText(panel) self.queueBW.SetToolTipString( 'Bandwidth spent on collecting .torrents') self.nrChannels = StaticText(panel) self.freeMem = None try: if wx.GetFreeMemory() != -1: self.freeMem = StaticText(panel) except: pass gridSizer = wx.FlexGridSizer(0, 2, 3, 10) gridSizer.AddGrowableCol(1) gridSizer.Add(StaticText(panel, -1, 'Number files')) gridSizer.Add(self.nrFiles, 0, wx.EXPAND) gridSizer.Add(StaticText(panel, -1, 'Total size')) gridSizer.Add(self.totalSize, 0, wx.EXPAND) gridSizer.Add(StaticText(panel, -1, 'Torrents collected')) gridSizer.Add(self.nrTorrents, 0, wx.EXPAND) gridSizer.Add(StaticText(panel, -1, 'Torrents in queue')) gridSizer.Add(self.queueSize, 0, wx.EXPAND) gridSizer.Add(StaticText(panel, -1, 'Torrent queue success')) gridSizer.Add(self.queueSuccess, 0, wx.EXPAND) gridSizer.Add(StaticText(panel, -1, 'Torrent queue bw')) gridSizer.Add(self.queueBW, 0, wx.EXPAND) gridSizer.Add(StaticText(panel, -1, 'Channels found')) gridSizer.Add(self.nrChannels, 0, wx.EXPAND) if self.freeMem: gridSizer.Add(StaticText(panel, -1, 'WX:Free memory')) gridSizer.Add(self.freeMem, 0, wx.EXPAND) vSizer.Add(gridSizer, 0, wx.EXPAND | wx.LEFT, 7) panel.SetSizer(vSizer) return panel
class TitleFooter(ListFooter): def GetMidPanel(self, hSizer): hSizer.AddStretchSpacer() self.title = StaticText(self) hSizer.Add(self.title) self.scrollBar = hSizer.AddSpacer((0, 0)) self.scrollBar.sizer = hSizer def SetTitle(self, title): self.Freeze() self.title.SetLabel(title) self.Layout() self.Thaw()
def _DoInit(self): self.SetBackgroundColour(DEFAULT_BACKGROUND) vSizer = wx.BoxSizer(wx.VERTICAL) self.dowserStatus = StaticText(self, -1, 'Dowser is not running') self.dowserButton = wx.Button(self, -1, 'Start dowser') self.dowserButton.Bind(wx.EVT_BUTTON, self.OnDowser) self.memdumpButton = wx.Button(self, -1, 'Dump memory') self.memdumpButton.Bind(wx.EVT_BUTTON, self.OnMemdump) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(self.dowserStatus, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 3) hSizer.Add(self.dowserButton) hSizer.Add(self.memdumpButton, 0, wx.RIGHT, 3) vSizer.Add(hSizer, 0, wx.ALIGN_RIGHT | wx.TOP | wx.BOTTOM, 3) hSizer = wx.BoxSizer(wx.HORIZONTAL) self.__dispersy_frame_btn = wx.Button(self, -1, "Open Dispersy Debug Frame") self.__dispersy_frame_btn.Bind(wx.EVT_BUTTON, self.OnOpenDispersyDebugButtonClicked) hSizer.Add(self.__dispersy_frame_btn, 0, wx.EXPAND, 3) vSizer.Add(hSizer, 0, wx.EXPAND | wx.BOTTOM, 3) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(NetworkPanel(self), 1, wx.EXPAND | wx.RIGHT, 7) self.activity = ActivityPanel(self) hSizer.Add(self.activity, 1, wx.EXPAND) vSizer.Add(hSizer, 1, wx.EXPAND) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(NewTorrentPanel(self), 1, wx.EXPAND | wx.RIGHT, 7) hSizer.Add(PopularTorrentPanel(self), 1, wx.EXPAND, 7) vSizer.Add(hSizer, 1, wx.EXPAND) self.SetSizer(vSizer) self.Layout() self.Bind(wx.EVT_KEY_UP, self.onKey) if sys.platform.startswith('win'): # on Windows, the panel doesn't respond to keypresses self.Bind(wx.EVT_MOUSE_EVENTS, self.onMouse) self.isReady = True
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)
class NetworkPanel(HomePanel): def __init__(self, parent): HomePanel.__init__(self, parent, 'Network info', SEPARATOR_GREY, (0, 1)) self.torrentdb = parent.guiutility.utility.session.open_dbhandler( NTFY_TORRENTS) self.channelcastdb = parent.guiutility.utility.session.open_dbhandler( NTFY_CHANNELCAST) self.remotetorrenthandler = parent.guiutility.utility.session.lm.rtorrent_handler self.timer = None session = Session.get_instance() session.add_observer(self.OnNotify, NTFY_TORRENTS, [NTFY_INSERT]) self.UpdateStats() def CreatePanel(self): panel = wx.Panel(self) panel.SetBackgroundColour(DEFAULT_BACKGROUND) vSizer = wx.BoxSizer(wx.VERTICAL) self.nrTorrents = StaticText(panel) self.nrFiles = StaticText(panel) self.totalSize = StaticText(panel) self.queueSize = StaticText(panel) self.queueSize.SetToolTipString('Number of torrents queued per prio') self.queueSuccess = StaticText(panel) self.queueBW = StaticText(panel) self.queueBW.SetToolTipString( 'Bandwidth spent on collecting .torrents') self.nrChannels = StaticText(panel) self.freeMem = None try: if wx.GetFreeMemory() != -1: self.freeMem = StaticText(panel) except: pass gridSizer = wx.FlexGridSizer(0, 2, 3, 10) gridSizer.AddGrowableCol(1) gridSizer.Add(StaticText(panel, -1, 'Number files')) gridSizer.Add(self.nrFiles, 0, wx.EXPAND) gridSizer.Add(StaticText(panel, -1, 'Total size')) gridSizer.Add(self.totalSize, 0, wx.EXPAND) gridSizer.Add(StaticText(panel, -1, 'Torrents collected')) gridSizer.Add(self.nrTorrents, 0, wx.EXPAND) gridSizer.Add(StaticText(panel, -1, 'Torrents in queue')) gridSizer.Add(self.queueSize, 0, wx.EXPAND) gridSizer.Add(StaticText(panel, -1, 'Torrent queue success')) gridSizer.Add(self.queueSuccess, 0, wx.EXPAND) gridSizer.Add(StaticText(panel, -1, 'Torrent queue bw')) gridSizer.Add(self.queueBW, 0, wx.EXPAND) gridSizer.Add(StaticText(panel, -1, 'Channels found')) gridSizer.Add(self.nrChannels, 0, wx.EXPAND) if self.freeMem: gridSizer.Add(StaticText(panel, -1, 'WX:Free memory')) gridSizer.Add(self.freeMem, 0, wx.EXPAND) vSizer.Add(gridSizer, 0, wx.EXPAND | wx.LEFT, 7) panel.SetSizer(vSizer) return panel def OnNotify(self, subject, type, infohash): try: if self.IsShownOnScreen(): self.UpdateStats() except wx.PyDeadObjectError: pass def UpdateStats(self): def db_callback(): stats = self.torrentdb.getTorrentsStats() nr_channels = self.channelcastdb.getNrChannels() self._UpdateStats(stats, nr_channels) startWorker(None, db_callback, uId=u"NetworkPanel_UpdateStats", priority=GUI_PRI_DISPERSY) @forceWxThread def _UpdateStats(self, stats, nr_channels): self.nrTorrents.SetLabel(str(stats[0])) if stats[1] is None: self.totalSize.SetLabel(str(stats[1])) else: self.totalSize.SetLabel(size_format(stats[1])) self.nrFiles.SetLabel(str(stats[2])) self.queueSize.SetLabel(self.remotetorrenthandler.getQueueSize()) self.queueBW.SetLabel(self.remotetorrenthandler.getBandwidthSpent()) qsuccess = self.remotetorrenthandler.getQueueSuccess() qlabel = ", ".join(label for label, tooltip in qsuccess) qtooltip = ", ".join(tooltip for label, tooltip in qsuccess) self.queueSuccess.SetLabel(qlabel) self.queueSuccess.SetToolTipString(qtooltip) self.nrChannels.SetLabel(str(nr_channels)) if self.freeMem: self.freeMem.SetLabel(size_format(wx.GetFreeMemory())) if self.timer: self.timer.Restart(10000) else: self.timer = wx.CallLater(10000, self.UpdateStats)
class Stats(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent) self._logger = logging.getLogger(self.__class__.__name__) self.guiutility = GUIUtility.getInstance() self.createTimer = None self.isReady = False def _DoInit(self): self.SetBackgroundColour(DEFAULT_BACKGROUND) vSizer = wx.BoxSizer(wx.VERTICAL) self.dowserStatus = StaticText(self, -1, 'Dowser is not running') self.dowserButton = wx.Button(self, -1, 'Start dowser') self.dowserButton.Bind(wx.EVT_BUTTON, self.OnDowser) self.memdumpButton = wx.Button(self, -1, 'Dump memory') self.memdumpButton.Bind(wx.EVT_BUTTON, self.OnMemdump) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(self.dowserStatus, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 3) hSizer.Add(self.dowserButton) hSizer.Add(self.memdumpButton, 0, wx.RIGHT, 3) vSizer.Add(hSizer, 0, wx.ALIGN_RIGHT | wx.TOP | wx.BOTTOM, 3) hSizer = wx.BoxSizer(wx.HORIZONTAL) self.__dispersy_frame_btn = wx.Button(self, -1, "Open Dispersy Debug Frame") self.__dispersy_frame_btn.Bind(wx.EVT_BUTTON, self.OnOpenDispersyDebugButtonClicked) hSizer.Add(self.__dispersy_frame_btn, 0, wx.EXPAND, 3) vSizer.Add(hSizer, 0, wx.EXPAND | wx.BOTTOM, 3) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(NetworkPanel(self), 1, wx.EXPAND | wx.RIGHT, 7) self.activity = ActivityPanel(self) hSizer.Add(self.activity, 1, wx.EXPAND) vSizer.Add(hSizer, 1, wx.EXPAND) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(NewTorrentPanel(self), 1, wx.EXPAND | wx.RIGHT, 7) hSizer.Add(PopularTorrentPanel(self), 1, wx.EXPAND, 7) vSizer.Add(hSizer, 1, wx.EXPAND) self.SetSizer(vSizer) self.Layout() self.Bind(wx.EVT_KEY_UP, self.onKey) if sys.platform.startswith('win'): # on Windows, the panel doesn't respond to keypresses self.Bind(wx.EVT_MOUSE_EVENTS, self.onMouse) self.isReady = True def OnOpenDispersyDebugButtonClicked(self, event): self.guiutility.frame.OnOpenDebugFrame(None) def onActivity(self, msg): if self.isReady: self.activity.onActivity(msg) def onKey(self, event): if event.ControlDown() and (event.GetKeyCode() == 73 or event.GetKeyCode() == 105): # ctrl + i self._showInspectionTool() elif event.ControlDown() and (event.GetKeyCode() == 68 or event.GetKeyCode() == 100): # ctrl + d self._printDBStats() else: event.Skip() def onMouse(self, event): if all([ event.RightUp(), event.ControlDown(), event.AltDown(), event.ShiftDown() ]): self._showInspectionTool() elif all([ event.LeftUp(), event.ControlDown(), event.AltDown(), event.ShiftDown() ]): self._printDBStats() else: event.Skip() def OnDowser(self, event): if self.dowserStatus.GetLabel() == 'Dowser is running': self._stopDowser() else: if not self._startDowser(): dlg = wx.DirDialog( None, "Please select your dowser installation directory", style=wx.wx.DD_DIR_MUST_EXIST) if dlg.ShowModal() == wx.ID_OK and os.path.isdir( dlg.GetPath()): sys.path.append(dlg.GetPath()) self._startDowser() dlg.Destroy() def OnMemdump(self, event): from meliae import scanner scanner.dump_all_objects("memory-dump.out") def _startDowser(self): try: import cherrypy import dowser cherrypy.config.update({'server.socket_port': 8080}) cherrypy.tree.mount(dowser.Root()) cherrypy.engine.start() self.dowserButton.SetLabel('Stop dowser') self.dowserStatus.SetLabel('Dowser is running') return True except: print_exc() return False def _stopDowser(self): try: import cherrypy cherrypy.engine.stop() self.dowserButton.SetLabel('Start dowser') self.dowserStatus.SetLabel('Dowser is not running') return True except: print_exc() return False def _showInspectionTool(self): import wx.lib.inspection itool = wx.lib.inspection.InspectionTool() itool.Show() try: frame = itool._frame import Tribler frame.locals['Tribler'] = Tribler session = Session.get_instance() frame.locals['session'] = session frame.locals['dispersy'] = session.lm.dispersy except Exception: import traceback traceback.print_exc() def _printDBStats(self): sqlite_db = self.guiutility.utility.session.sqlite_db tables = sqlite_db.fetchall( "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name") for table, in tables: self._logger.info( "%s %s", table, sqlite_db.fetchone("SELECT COUNT(*) FROM %s" % table)) def Show(self, show=True): if show: if not self.isReady: self._DoInit() wx.Panel.Show(self, show)
class CreateTorrentDialog(wx.Dialog): def __init__(self, parent, recent_creation_config_file, recent_trackers_config_file, suggested_trackers, to_channel=False): wx.Dialog.__init__(self, parent, -1, 'Create a .torrent', size=(600, 200), name="CreateTorrentDialog") self.to_channel = to_channel # setup layout vSizer = wx.BoxSizer(wx.VERTICAL) header = wx.StaticText(self, -1, 'Browse for a file or files') _set_font(header, fontweight=wx.FONTWEIGHT_BOLD) vSizer.Add(header, 0, wx.EXPAND | wx.BOTTOM, 3) self.locationText = StaticText(self, -1, '') vSizer.Add(self.locationText, 0, wx.EXPAND | wx.BOTTOM, 3) browseButton = wx.Button(self, -1, 'Browse') browseButton.Bind(wx.EVT_BUTTON, self.OnBrowse) browseDirButton = wx.Button(self, -1, 'Browse for a Directory') browseDirButton.Bind(wx.EVT_BUTTON, self.OnBrowseDir) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(browseButton) hSizer.Add(browseDirButton) vSizer.Add(hSizer, 0, wx.ALIGN_RIGHT | wx.BOTTOM, 3) vSizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10) header = wx.StaticText(self, -1, '.Torrent details') _set_font(header, fontweight=wx.FONTWEIGHT_BOLD) vSizer.Add(header, 0, wx.EXPAND | wx.BOTTOM, 3) self.foundFilesText = StaticText( self, -1, 'Please select a file or files first') vSizer.Add(self.foundFilesText, 0, wx.EXPAND | wx.BOTTOM, 3) self.combineRadio = wx.RadioButton( self, -1, 'Combine files into a single .torrent', style=wx.RB_GROUP) self.combineRadio.Bind(wx.EVT_RADIOBUTTON, self.OnCombine) self.combineRadio.Enable(False) self.sepRadio = wx.RadioButton( self, -1, 'Create separate .torrent for every file') self.sepRadio.Bind(wx.EVT_RADIOBUTTON, self.OnCombine) self.sepRadio.Enable(False) vSizer.Add(self.combineRadio, 0, wx.EXPAND | wx.BOTTOM, 3) vSizer.Add(self.sepRadio, 0, wx.EXPAND | wx.BOTTOM, 3) self.specifiedName = wx.TextCtrl(self, -1, '') self.specifiedName.Enable(False) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(wx.StaticText(self, -1, 'Specify a name'), 0, wx.ALIGN_CENTER_VERTICAL) hSizer.Add(self.specifiedName, 1, wx.EXPAND) vSizer.Add(hSizer, 0, wx.EXPAND | wx.BOTTOM, 3) vSizer.Add(StaticText(self, -1, 'Trackers')) self.trackerList = wx.TextCtrl(self, -1, '', style=wx.TE_MULTILINE) self.trackerList.SetMinSize((500, -1)) self.trackerHistory = wx.FileHistory(10) self.config = wx.FileConfig(appName="Tribler", localFilename=recent_creation_config_file) self.trackerHistory.Load(self.config) if self.trackerHistory.GetCount() > 0: trackers = [ self.trackerHistory.GetHistoryFile(i) for i in range(self.trackerHistory.GetCount()) ] if len(trackers) < len(suggested_trackers): trackers.extend(suggested_trackers[:len(suggested_trackers) - len(trackers)]) else: trackers = suggested_trackers for tracker in trackers: self.trackerList.AppendText(tracker + os.linesep) vSizer.Add(self.trackerList, 0, wx.EXPAND | wx.BOTTOM, 3) vSizer.Add(StaticText(self, -1, 'Comment')) self.commentList = wx.TextCtrl(self, -1, '', style=wx.TE_MULTILINE) vSizer.Add(self.commentList, 0, wx.EXPAND, 3) vSizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10) header = wx.StaticText(self, -1, 'Advanced options') _set_font(header, fontweight=wx.FONTWEIGHT_BOLD) vSizer.Add(header, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 3) abbrev_mb = " MB" abbrev_kb = " KB" piece_choices = [ 'Automatic', '4' + abbrev_mb, '2' + abbrev_mb, '1' + abbrev_mb, '512' + abbrev_kb, '256' + abbrev_kb, '128' + abbrev_kb, '64' + abbrev_kb, '32' + abbrev_kb ] self.pieceChoice = wx.Choice(self, -1, choices=piece_choices) self.pieceChoice.SetSelection(0) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(StaticText(self, -1, 'Piecesize'), 1) hSizer.Add(self.pieceChoice) vSizer.Add(hSizer, 0, wx.EXPAND | wx.BOTTOM, 3) vSizer.Add(StaticText(self, -1, 'Webseed')) self.webSeed = wx.TextCtrl(self, -1, 'Please select a file or files first') self.webSeed.Enable(False) vSizer.Add(self.webSeed, 0, wx.EXPAND | wx.BOTTOM, 3) cancel = wx.Button(self, wx.ID_CANCEL) cancel.Bind(wx.EVT_BUTTON, self.OnCancel) create = wx.Button(self, wx.ID_OK, 'Create .torrent(s)') create.Bind(wx.EVT_BUTTON, self.OnOk) bSizer = wx.StdDialogButtonSizer() bSizer.AddButton(cancel) bSizer.AddButton(create) bSizer.Realize() vSizer.Add(bSizer, 0, wx.EXPAND) sizer = wx.BoxSizer() sizer.Add(vSizer, 1, wx.EXPAND | wx.ALL, 10) self.SetSizerAndFit(sizer) self.selectedPaths = [] self.createdTorrents = [] self.cancelEvent = Event() self.filehistory = wx.FileHistory(1) self.fileconfig = wx.FileConfig( appName="Tribler", localFilename=recent_trackers_config_file) self.filehistory.Load(self.fileconfig) if self.filehistory.GetCount() > 0: self.latestFile = self.filehistory.GetHistoryFile(0) else: self.latestFile = '' self.paths = None def OnBrowse(self, event): dlg = wx.FileDialog(None, "Please select the file(s).", style=wx.FD_OPEN | wx.FD_MULTIPLE, defaultDir=self.latestFile) if dlg.ShowModal() == wx.ID_OK: filenames = dlg.GetPaths() dlg.Destroy() self._browsePaths(filenames) else: dlg.Destroy() def OnBrowseDir(self, event): dlg = wx.DirDialog(None, "Please a directory.", style=wx.DD_DIR_MUST_EXIST, defaultPath=self.latestFile) if dlg.ShowModal() == wx.ID_OK: filenames = [dlg.GetPath()] dlg.Destroy() self._browsePaths(filenames) else: dlg.Destroy() def OnCombine(self, event=None): combine = self.combineRadio.GetValue() self.specifiedName.Enable(False) if combine: path = '' nrFiles = len( [file for file in self.selectedPaths if os.path.isfile(file)]) if nrFiles > 1: self.specifiedName.Enable(True) path = os.path.abspath(os.path.commonprefix( self.selectedPaths)) elif nrFiles > 0: path = self.selectedPaths[0] _, name = os.path.split(path) self.specifiedName.SetValue(name) def OnOk(self, event): max = 1 if self.combineRadio.GetValue() else len(self.selectedPaths) if self.to_channel: dlg = wx.MessageDialog( self, "This will add %d new .torrents to this Channel.\nDo you want to continue?" % max, "Are you sure?", style=wx.YES_NO | wx.ICON_QUESTION) else: dlg = wx.MessageDialog( self, "This will create %d new .torrents.\nDo you want to continue?" % max, "Are you sure?", style=wx.YES_NO | wx.ICON_QUESTION) if dlg.ShowModal() == wx.ID_YES: dlg.Destroy() params = {} params['comment'] = self.commentList.GetValue().encode('utf-8') params['created by'] = '%s version: %s' % ('Tribler', version_id) trackers = self.trackerList.GetValue() trackers = [ tracker for tracker in trackers.split(os.linesep) if tracker ] for tracker in trackers: self.trackerHistory.AddFileToHistory(tracker) self.trackerHistory.Save(self.config) self.config.Flush() self.filehistory.Save(self.fileconfig) self.fileconfig.Flush() if trackers: params['announce'] = trackers[0] params['announce-list'] = trackers if self.webSeed.GetValue(): params['urllist'] = [self.webSeed.GetValue()] params['nodes'] = False params['httpseeds'] = False params['encoding'] = False piece_length_list = [ 0, 2**22, 2**21, 2**20, 2**19, 2**18, 2**17, 2**16, 2**15 ] if self.pieceChoice.GetSelection() != wx.NOT_FOUND: params['piece length'] = piece_length_list[ self.pieceChoice.GetSelection()] else: params['piece length'] = 0 def do_gui(): if self.cancelEvent.isSet(): self.OnCancel(event) else: self.EndModal(wx.ID_OK) def create_torrents(): try: if self.combineRadio.GetValue(): params['name'] = self.specifiedName.GetValue() result = create_torrent_file(self.selectedPaths, params) self._torrentCreated(result) else: for path in self.selectedPaths: if os.path.isfile(path): result = create_torrent_file([path], params) self._torrentCreated(result) except: print_exc() wx.CallAfter(do_gui) def start(): if self.combineRadio.GetValue(): self.progressDlg = wx.ProgressDialog( "Creating new .torrents", "Please wait while Tribler is creating your .torrents.\n" "This could take a while due to creating the required hashes.", maximum=max, parent=self, style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE) else: self.progressDlg = wx.ProgressDialog( "Creating new .torrents", "Please wait while Tribler is creating your .torrents.\n" "This could take a while due to creating the required hashes.", maximum=max, parent=self, style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_AUTO_HIDE) self.progressDlg.Pulse() self.progressDlg.cur = 0 reactor.callInThread(create_torrents) if params['piece length']: total_size = 0 if self.combineRadio.GetValue(): for path in self.selectedPaths: total_size += os.path.getsize(path) else: for path in self.selectedPaths: total_size = max(total_size, os.path.getsize(path)) nrPieces = total_size / params['piece length'] if nrPieces > 2500: dlg2 = wx.MessageDialog( self, "The selected piecesize will cause a torrent to have %d pieces.\n" "This is more than the recommended max 2500 pieces.\nDo you want to continue?" % nrPieces, "Are you sure?", style=wx.YES_NO | wx.ICON_QUESTION) if dlg2.ShowModal() == wx.ID_YES: start() dlg2.Destroy() else: start() else: start() else: dlg.Destroy() def OnCancel(self, event): self.EndModal(wx.ID_CANCEL) def _browsePaths(self, paths=None): if paths: self.paths = paths else: paths = self.paths if paths: label = ";".join(paths) self.locationText.SetLabel(label) if os.path.isdir(paths[0]): def addDir(path, recursive=False): paths = [path] for file in os.listdir(path): absfile = os.path.join(path, file) if os.path.isfile(absfile): if file.lower().endswith('.torrent') or file.lower( ).endswith('thumbs.db'): continue paths.append(absfile) elif os.path.isdir(absfile) and recursive: paths.extend(addDir(absfile, recursive)) return paths paths = addDir(paths[0], False) # self.recursive.GetValue()) self.selectedPaths = paths nrFiles = len([file for file in paths if os.path.isfile(file)]) self.foundFilesText.SetLabel('Selected %d files' % nrFiles) if nrFiles == 1: self.webSeed.Enable(True) self.webSeed.SetValue('') else: self.webSeed.SetValue( 'Webseed will only work for a single file.') self.webSeed.Enable(False) self.combineRadio.Enable(nrFiles > 0) self.sepRadio.Enable(nrFiles > 1) self.combineRadio.SetValue(nrFiles == 1) self.sepRadio.SetValue(nrFiles > 1) self.OnCombine() self.Layout() @forceWxThread def _torrentCreated(self, result): if not result['success']: self.cancelEvent.set() path = result['base_path'] torrentfilename = result['torrent_file_path'] self.progressDlg.cur += 1 keepGoing, _ = self.progressDlg.Update(self.progressDlg.cur) if not keepGoing: self.cancelEvent.set() self.createdTorrents.append((path, torrentfilename))
def __init__(self, parent, recent_creation_config_file, recent_trackers_config_file, suggested_trackers, to_channel=False): wx.Dialog.__init__(self, parent, -1, 'Create a .torrent', size=(600, 200), name="CreateTorrentDialog") self.to_channel = to_channel # setup layout vSizer = wx.BoxSizer(wx.VERTICAL) header = wx.StaticText(self, -1, 'Browse for a file or files') _set_font(header, fontweight=wx.FONTWEIGHT_BOLD) vSizer.Add(header, 0, wx.EXPAND | wx.BOTTOM, 3) self.locationText = StaticText(self, -1, '') vSizer.Add(self.locationText, 0, wx.EXPAND | wx.BOTTOM, 3) browseButton = wx.Button(self, -1, 'Browse') browseButton.Bind(wx.EVT_BUTTON, self.OnBrowse) browseDirButton = wx.Button(self, -1, 'Browse for a Directory') browseDirButton.Bind(wx.EVT_BUTTON, self.OnBrowseDir) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(browseButton) hSizer.Add(browseDirButton) vSizer.Add(hSizer, 0, wx.ALIGN_RIGHT | wx.BOTTOM, 3) vSizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10) header = wx.StaticText(self, -1, '.Torrent details') _set_font(header, fontweight=wx.FONTWEIGHT_BOLD) vSizer.Add(header, 0, wx.EXPAND | wx.BOTTOM, 3) self.foundFilesText = StaticText( self, -1, 'Please select a file or files first') vSizer.Add(self.foundFilesText, 0, wx.EXPAND | wx.BOTTOM, 3) self.combineRadio = wx.RadioButton( self, -1, 'Combine files into a single .torrent', style=wx.RB_GROUP) self.combineRadio.Bind(wx.EVT_RADIOBUTTON, self.OnCombine) self.combineRadio.Enable(False) self.sepRadio = wx.RadioButton( self, -1, 'Create separate .torrent for every file') self.sepRadio.Bind(wx.EVT_RADIOBUTTON, self.OnCombine) self.sepRadio.Enable(False) vSizer.Add(self.combineRadio, 0, wx.EXPAND | wx.BOTTOM, 3) vSizer.Add(self.sepRadio, 0, wx.EXPAND | wx.BOTTOM, 3) self.specifiedName = wx.TextCtrl(self, -1, '') self.specifiedName.Enable(False) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(wx.StaticText(self, -1, 'Specify a name'), 0, wx.ALIGN_CENTER_VERTICAL) hSizer.Add(self.specifiedName, 1, wx.EXPAND) vSizer.Add(hSizer, 0, wx.EXPAND | wx.BOTTOM, 3) vSizer.Add(StaticText(self, -1, 'Trackers')) self.trackerList = wx.TextCtrl(self, -1, '', style=wx.TE_MULTILINE) self.trackerList.SetMinSize((500, -1)) self.trackerHistory = wx.FileHistory(10) self.config = wx.FileConfig(appName="Tribler", localFilename=recent_creation_config_file) self.trackerHistory.Load(self.config) if self.trackerHistory.GetCount() > 0: trackers = [ self.trackerHistory.GetHistoryFile(i) for i in range(self.trackerHistory.GetCount()) ] if len(trackers) < len(suggested_trackers): trackers.extend(suggested_trackers[:len(suggested_trackers) - len(trackers)]) else: trackers = suggested_trackers for tracker in trackers: self.trackerList.AppendText(tracker + os.linesep) vSizer.Add(self.trackerList, 0, wx.EXPAND | wx.BOTTOM, 3) vSizer.Add(StaticText(self, -1, 'Comment')) self.commentList = wx.TextCtrl(self, -1, '', style=wx.TE_MULTILINE) vSizer.Add(self.commentList, 0, wx.EXPAND, 3) vSizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10) header = wx.StaticText(self, -1, 'Advanced options') _set_font(header, fontweight=wx.FONTWEIGHT_BOLD) vSizer.Add(header, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 3) abbrev_mb = " MB" abbrev_kb = " KB" piece_choices = [ 'Automatic', '4' + abbrev_mb, '2' + abbrev_mb, '1' + abbrev_mb, '512' + abbrev_kb, '256' + abbrev_kb, '128' + abbrev_kb, '64' + abbrev_kb, '32' + abbrev_kb ] self.pieceChoice = wx.Choice(self, -1, choices=piece_choices) self.pieceChoice.SetSelection(0) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(StaticText(self, -1, 'Piecesize'), 1) hSizer.Add(self.pieceChoice) vSizer.Add(hSizer, 0, wx.EXPAND | wx.BOTTOM, 3) vSizer.Add(StaticText(self, -1, 'Webseed')) self.webSeed = wx.TextCtrl(self, -1, 'Please select a file or files first') self.webSeed.Enable(False) vSizer.Add(self.webSeed, 0, wx.EXPAND | wx.BOTTOM, 3) cancel = wx.Button(self, wx.ID_CANCEL) cancel.Bind(wx.EVT_BUTTON, self.OnCancel) create = wx.Button(self, wx.ID_OK, 'Create .torrent(s)') create.Bind(wx.EVT_BUTTON, self.OnOk) bSizer = wx.StdDialogButtonSizer() bSizer.AddButton(cancel) bSizer.AddButton(create) bSizer.Realize() vSizer.Add(bSizer, 0, wx.EXPAND) sizer = wx.BoxSizer() sizer.Add(vSizer, 1, wx.EXPAND | wx.ALL, 10) self.SetSizerAndFit(sizer) self.selectedPaths = [] self.createdTorrents = [] self.cancelEvent = Event() self.filehistory = wx.FileHistory(1) self.fileconfig = wx.FileConfig( appName="Tribler", localFilename=recent_trackers_config_file) self.filehistory.Load(self.fileconfig) if self.filehistory.GetCount() > 0: self.latestFile = self.filehistory.GetHistoryFile(0) else: self.latestFile = '' self.paths = None
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')
class BundlePanel(wx.BoxSizer): COLLAPSED, PARTIAL, FULL = range(3) icons = None @classmethod def load_icons(cls): if not cls.icons: icons = cls.icons = {} guiUtility = GUIUtility.getInstance() utility = guiUtility.utility base_path = os.path.join(utility.getPath(), LIBRARYNAME, "Main", "vwxGUI", "images") icons['info'] = wx.Bitmap(os.path.join(base_path, "info.png"), wx.BITMAP_TYPE_ANY) def __init__(self, parent, parent_list, hits, general_description=None, description=None, font_increment=0): wx.BoxSizer.__init__(self, wx.HORIZONTAL) # preload icons self.load_icons() self.parent = parent self.parent_listitem = parent self.parent_list = parent_list listbody_width = parent_list.GetSize()[0] if listbody_width < BUNDLE_GRID_COLLAPSE: self.num_cols = 1 else: self.num_cols = BUNDLE_NUM_COLS # logging self.guiutility = GUIUtility.getInstance() self.uelog = UserEventLogDBHandler.getInstance() self.state = BundlePanel.COLLAPSED self.nrhits = -1 self.bundlelist = None self.font_increment = font_increment self.vsizer = wx.BoxSizer(wx.VERTICAL) self.SetBackgroundColour(DEFAULT_BACKGROUND) self.indent = 3 + 3 + self.parent_list.leftSpacer # width of 3px left spacer + 3px right spacer self.AddHeader() self.AddGrid() self.SetHits(hits, noChange=True) self.UpdateHeader(general_description, description) self.AddSpacer((self.indent, -1)) self.Add(self.vsizer, 1, wx.EXPAND | wx.BOTTOM, 7) def AddHeader(self): sizer = wx.BoxSizer(wx.HORIZONTAL) self.header = StaticText(self.parent, -1, ' ') self.info_icon = wx.StaticBitmap(self.parent, -1, self.icons['info']) sizer.Add(self.header, 0, wx.RIGHT, 7) sizer.Add(self.info_icon, 0, wx.ALIGN_CENTER_VERTICAL) self.vsizer.Add(sizer, 0, wx.BOTTOM, 3) def UpdateHeader(self, general_description, description): self.SetGeneralDescription(general_description) self.SetDescription(description) def AddGrid(self): self.grid = wx.FlexGridSizer(0, self.num_cols, 3, 7) self.grid.SetFlexibleDirection(wx.HORIZONTAL) self.grid.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_NONE) self.grid.SetMinSize((1, -1)) for i in xrange(BUNDLE_NUM_ROWS): self.grid.AddGrowableRow(i, 1) for j in xrange(self.num_cols): self.grid.AddGrowableCol(j, 1) self.vsizer.Add(self.grid, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 14 + self.indent) def RebuildGrid(self, new_cols): if self.num_cols != new_cols: self.num_cols = new_cols children = self.grid.GetChildren() children_controls = [] for child in children: children_controls.append(child.GetWindow() or child.GetSizer()) for child in children_controls: self.grid.Detach(child) self.vsizer.Detach(self.grid) self.grid.Destroy() self.grid = wx.FlexGridSizer(0, self.num_cols, 3, 7) for child in children_controls: self.grid.Add(child, 0, wx.EXPAND) for j in xrange(self.num_cols): self.grid.AddGrowableCol(j, 1) self.vsizer.Add(self.grid, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 14 + self.indent) self.Layout() self.parent_listitem.Layout() return True return False def UpdateGrid(self, hits, noChange=False): N = BUNDLE_NUM_ROWS * BUNDLE_NUM_COLS items_to_add = min(N, self.nrhits) if self.nrhits > N: items_to_add -= 1 self.parent.Freeze() children = self.grid.GetChildren() didChange = len(children) < min(N, self.nrhits) if not didChange: if DEBUG: print >> sys.stderr, "*** BundlePanel.UpdateGrid: total nr items did not change, updating labels only" # total nr items did not change for i in range(items_to_add): link_static_text = children[i].GetWindow( ) or children[i].GetSizer() if link_static_text and getattr(link_static_text, 'SetLabel', False): link_static_text.SetLabel(hits[i].name) link_static_text.action = hits[i] else: didChange = True break if self.nrhits > N: more_caption = '(%s more...)' % (self.nrhits - N + 1) link_static_text = children[i + 1].GetWindow() or children[ i + 1].GetSizer() if link_static_text and getattr(link_static_text, 'SetLabel', False): link_static_text.SetLabel(more_caption) link_static_text.Unbind(wx.EVT_LEFT_UP) link_static_text.Bind(wx.EVT_LEFT_UP, self.OnMoreClick) else: didChange = True if didChange: if DEBUG: print >> sys.stderr, "*** BundlePanel.UpdateGrid: something did change rebuilding grid", len( children), min(N, self.nrhits) curRows = len(children) / BUNDLE_NUM_COLS newRows = min(self.nrhits / BUNDLE_NUM_COLS, BUNDLE_NUM_ROWS) rowsChanged = curRows != newRows self.grid.ShowItems(False) self.grid.Clear(deleteWindows=True) for i in range(items_to_add): hit = hits[i] new_text = LinkStaticText(self.parent, hit.name, icon=False, icon_align=wx.ALIGN_LEFT, font_increment=self.font_increment, font_colour=BUNDLE_FONT_COLOR) new_text.Bind(wx.EVT_LEFT_UP, self.OnBundleLinkClick) new_text.SetMinSize((1, -1)) new_text.action = hit self.grid.Add(new_text, 0, wx.EXPAND) if self.nrhits > N: caption = '(%s more...)' % (self.nrhits - N + 1) more_label = LinkStaticText(self.parent, caption, icon=False, icon_align=wx.ALIGN_LEFT, font_increment=self.font_increment, font_colour=BUNDLE_FONT_COLOR) more_label.Bind(wx.EVT_LEFT_UP, self.OnMoreClick) self.grid.Add(more_label, 0, wx.EXPAND) self.parent_listitem.AddEvents(self.grid) if self.state != self.COLLAPSED: self.ShowGrid(False) if rowsChanged and not noChange: self.parent_listitem.OnChange() self.parent.Thaw() return didChange def OnEventSize(self, width): if width < BUNDLE_GRID_COLLAPSE: return self.RebuildGrid(1) return self.RebuildGrid(BUNDLE_NUM_COLS) def ShowGrid(self, show): if show: self.grid.ShowItems(True) else: self.grid.ShowItems(False) def UpdateList(self, hits): self.hits = hits if self.bundlelist: self.bundlelist.SetData(hits) if self.state == BundlePanel.FULL: self.bundlelist.OnLoadAll() def ShowList(self, show): if self.bundlelist is None and show: max_list = BUNDLE_NUM_ROWS * BUNDLE_NUM_COLS if len(self.hits) != BUNDLE_NUM_ROWS * BUNDLE_NUM_COLS: max_list -= 1 self.bundlelist = BundleListView(parent=self.parent, list_item_max=max_list) self.vsizer.Add(self.bundlelist, 0, wx.EXPAND | wx.BOTTOM, self.indent - 7) #a 7px spacer is already present # SetData does wx.Yield, which could cause a collapse event to be processed within the setdata # method. Thus we have to do this after the add to the sizer self.bundlelist.SetData(self.hits) elif self.bundlelist is not None and not show: self.vsizer.Detach(self.bundlelist) self.bundlelist.Show(False) self.bundlelist.Destroy() self.bundlelist = None def CollapseExpandedItem(self): if self.state != BundlePanel.COLLAPSED: self.bundlelist.list.OnCollapse() def RefreshDataBundleList(self, key, data): if self.bundlelist is not None: self.bundlelist.RefreshData(key, data) def SetDescription(self, description): self.header.SetToolTipString(description) self.info_icon.SetToolTipString(description) def SetGeneralDescription(self, general_description): if general_description: general_description = unicode(general_description) else: general_description = u'Similar' self.header.SetLabel(u'%s items (%s):' % (general_description, self.nrhits)) def SetHits(self, hits, noChange=False): self.nrhits = len(hits) gridChanged = self.UpdateGrid(hits, noChange) self.UpdateList(hits) self.Layout() return gridChanged def ChangeState(self, new_state, doLayout=True): if self.state != new_state: old_state = self.state self.state = new_state if new_state == BundlePanel.COLLAPSED: self.ShowList(False) self.ShowGrid(True) else: if new_state == BundlePanel.PARTIAL or new_state == BundlePanel.FULL: self.ShowGrid(False) if old_state == BundlePanel.COLLAPSED: self.ShowList(True) if new_state == BundlePanel.FULL and self.bundlelist: self.bundlelist.OnLoadAll() if DEBUG: statestr = lambda st: ['COLLAPSED', 'PARTIAL', 'FULL'][st] print >> sys.stderr, '*** BundlePanel.ChangeState: %s --> %s' % ( statestr(old_state), statestr(new_state)) def ExpandHit(self, hit): id = hit.infohash self.bundlelist.ExpandItem(id) self.parent_listitem.ShowSelected() def OnBundleLinkClick(self, event): # do expand # self.ExpandAndHideParent() staticText = event.GetEventObject() action = getattr(staticText, 'action', None) if action is not None: # Reason for non-persistence (for now) is least-surprise. # If the user collapses a bundled listitem, the previously # clicked item is still at the same location. if action in self.hits: self.hits.remove(action) self.hits.insert(0, action) # self.ChangeState(BundlePanel.PARTIAL) # self.ExpandHit(action) self.SetBackgroundColour(self.parent.GetBackgroundColour()) from __init__ import TRIBLER_RED, LIST_HIGHTLIGHT event.GetEventObject().SetBackgroundColour(LIST_HIGHTLIGHT) for item in self.parent_listitem.bundle: if action.infohash == item.infohash: td = TorrentDetails( self.guiutility.frame.splitter_bottom_window, item) item.expandedPanel = td self.guiutility.SetBottomSplitterWindow(td) def db_callback(): self.uelog.addEvent( message="Bundler GUI: BundleLink click; %s; %s;" % (self.nrhits, self.parent_listitem.general_description), type=3) self.guiutility.frame.guiserver.add_task(db_callback) def OnMoreClick(self, event): return # do expand self.ExpandAndHideParent() self.ChangeState(BundlePanel.FULL) def db_callback(): self.uelog.addEvent( message="Bundler GUI: More click; %s; %s;" % (self.nrhits, self.parent_listitem.general_description), type=3) self.guiutility.frame.guiserver.add_task(db_callback) def ExpandAndHideParent(self): self.parent.Freeze() if not self.parent_listitem.expanded: # Make sure the listitem is marked as expanded self.parent_listitem.OnClick() # but hide the panel self.parent_listitem.ShowExpandedPanel(False) self.parent.Thaw() # Called from GUI to get expanded torrentdetails panel def GetExpandedPanel(self): if self.bundlelist: item = self.bundlelist.GetExpandedItem() if item: return item.GetExpandedPanel() def SetBackgroundColour(self, colour): self.parent.Freeze() if getattr(self, 'grid', False): for sizeritem in self.grid.GetChildren(): child = sizeritem.GetWindow() or sizeritem.GetSizer() if child and getattr(child, 'SetBackgroundColour', False): child.SetBackgroundColour(colour) self.parent.Thaw()
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): wx.Panel.__init__(self, parent) self.guiutility = GUIUtility.getInstance() self.SetBackgroundColour(DEFAULT_BACKGROUND) vSizer = wx.BoxSizer(wx.VERTICAL) vSizer.AddStretchSpacer() text = StaticText(self, -1, "Tribler") font = text.GetFont() font.SetPointSize(font.GetPointSize() * 3) font.SetWeight(wx.FONTWEIGHT_BOLD) text.SetForegroundColour((255, 51, 0)) text.SetFont(font) textSizer = wx.FlexGridSizer(2, 2, 3, 7) if sys.platform == 'darwin': # mac self.searchBox = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER) else: self.searchBox = TextCtrlAutoComplete( self, entrycallback=parent.top_bg.complete) font = self.searchBox.GetFont() font.SetPointSize(font.GetPointSize() * 2) self.searchBox.SetFont(font) self.searchBox.Bind(wx.EVT_TEXT_ENTER, self.OnSearchKeyDown) if sys.platform == 'darwin': # mac self.searchBox.SetMinSize( (450, self.searchBox.GetTextExtent('T')[1] + 5)) else: self.searchBox.SetMinSize((450, -1)) self.searchBox.SetFocus() textSizer.Add(text, 0, wx.EXPAND | wx.RIGHT, 7) scalingSizer = wx.BoxSizer(wx.HORIZONTAL) scalingSizer.Add(self.searchBox) if sys.platform == 'darwin': # mac searchButton = wx.Button(self, -1, '\n') searchButton.SetLabel('Search') else: searchButton = wx.Button(self, -1, 'Search') searchButton.Bind(wx.EVT_BUTTON, self.OnClick) scalingSizer.Add(searchButton, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 3) textSizer.Add(scalingSizer, 0, wx.ALIGN_CENTER_VERTICAL) textSizer.AddSpacer((1, 1)) hSizer = wx.BoxSizer(wx.HORIZONTAL) hSizer.Add(StaticText(self, -1, "Take me to ")) channelLink = LinkStaticText(self, "channels", icon=None) channelLink.Bind(wx.EVT_LEFT_UP, self.OnChannels) hSizer.Add(channelLink) hSizer.Add(StaticText(self, -1, " to see what others are sharing")) textSizer.Add(hSizer) vSizer.Add(textSizer, 0, wx.ALIGN_CENTER) vSizer.AddStretchSpacer() self.aw_panel = ArtworkPanel(self) self.aw_panel.SetMinSize((-1, 275)) # TODO(lipu): enable this when metadata PR is merged #self.aw_panel.Show(self.guiutility.ReadGuiSetting('show_artwork', True)) self.aw_panel.Show(False) vSizer.Add(self.aw_panel, 0, wx.EXPAND) self.SetSizer(vSizer) self.Layout() self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick) self.SearchFocus()
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()