Пример #1
0
    def __init__(self, abc, parent, internalvideo):
        self.abc = abc
        self._logger = logging.getLogger(self.__class__.__name__)

        self._logger.info('GUI started')

        # Do all init here
        self.ready = False
        self.guiUtility = GUIUtility.getInstance()
        self.guiUtility.frame = self
        self.utility = self.guiUtility.utility
        self.params = self.guiUtility.params
        self.utility.frame = self
        self.videoframe = None
        self.category = self.utility.session.lm.category
        self.shutdown_and_upgrade_notes = None

        title = "Tribler %s" % version_id

        # Get window size and (sash) position from config file
        size, position, sashpos = self.getWindowSettings()
        style = wx.DEFAULT_DIALOG_STYLE | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER | wx.NO_FULL_REPAINT_ON_RESIZE | wx.CLIP_CHILDREN

        wx.Frame.__init__(self, parent, wx.ID_ANY, title, position, size,
                          style)
        if sys.platform == 'linux2':
            font = self.GetFont()
            if font.GetPointSize() > 9:
                font.SetPointSize(9)
                self.SetFont(font)

        self.Freeze()
        self.SetDoubleBuffered(True)
        self.SetBackgroundColour(DEFAULT_BACKGROUND)

        themeColour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
        r, g, b = themeColour.Get(False)
        if r > 190 or g > 190 or b > 190:  # Grey == 190,190,190
            self.SetForegroundColour(wx.BLACK)

        if internalvideo:
            self.videoparentpanel = wx.Panel(self)
            self.videoparentpanel.Hide()
        else:
            self.videoparentpanel = None

        # Create all components
        self.utility.session.notifier.notify(NTFY_STARTUP_TICK, NTFY_INSERT,
                                             None, 'Creating panels')

        self.actlist = ActivitiesList(self)
        self.top_bg = TopSearchPanel(self)
        self.home = Home(self)

        self.splitter = wx.SplitterWindow(self, style=wx.SP_NOBORDER)
        self.splitter.SetMinimumPaneSize(1)
        self.splitter.SetForegroundColour(self.GetForegroundColour())
        self.splitter_top_window = wx.Panel(self.splitter, style=wx.NO_BORDER)
        self.splitter_top_window.SetForegroundColour(
            self.GetForegroundColour())
        self.splitter_top = wx.BoxSizer(wx.HORIZONTAL)
        self.splitter_top_window.SetSizer(self.splitter_top)
        self.splitter_bottom_window = wx.Panel(self.splitter)
        self.splitter_bottom_window.SetMinSize((-1, 25))
        self.splitter_bottom_window.SetForegroundColour(
            self.GetForegroundColour())
        self.splitter_bottom_window.OnChange = lambda: self.splitter_bottom.Layout(
        )
        self.splitter_bottom_window.parent_list = self.splitter_bottom_window

        self.networkgraph = NetworkGraphPanel(self)
        self.networkgraph.Show(False)
        self.searchlist = SearchList(self.splitter_top_window)
        self.searchlist.Show(False)
        self.librarylist = LibraryList(self.splitter_top_window)
        self.librarylist.Show(False)
        self.channellist = ChannelList(self.splitter_top_window)
        self.channellist.Show(False)
        self.selectedchannellist = SelectedChannelList(
            self.splitter_top_window)
        self.selectedchannellist.Show(False)
        self.playlist = Playlist(self.splitter_top_window)
        self.playlist.Show(False)

        self.creditminingpanel = CreditMiningPanel(self)
        self.creditminingpanel.Show(False)

        # Populate the bottom window
        self.splitter_bottom = wx.BoxSizer(wx.HORIZONTAL)
        self.torrentdetailspanel = TorrentDetails(self.splitter_bottom_window)
        self.torrentdetailspanel.Show(False)
        self.librarydetailspanel = LibraryDetails(self.splitter_bottom_window)
        self.librarydetailspanel.Show(False)
        self.channeldetailspanel = ChannelDetails(self.splitter_bottom_window)
        self.channeldetailspanel.Show(False)
        self.playlistdetailspanel = PlaylistDetails(
            self.splitter_bottom_window)
        self.playlistdetailspanel.Show(False)
        self.searchinfopanel = SearchInfoPanel(self.splitter_bottom_window)
        self.searchinfopanel.Show(False)
        self.channelinfopanel = ChannelInfoPanel(self.splitter_bottom_window)
        self.channelinfopanel.Show(False)
        self.libraryinfopanel = LibraryInfoPanel(self.splitter_bottom_window)
        self.libraryinfopanel.Show(False)
        self.playlistinfopanel = PlaylistInfoPanel(self.splitter_bottom_window)
        self.playlistinfopanel.Show(False)
        self.selectedchannelinfopanel = SelectedchannelInfoPanel(
            self.splitter_bottom_window)
        self.selectedchannelinfopanel.Show(False)
        self.splitter_bottom.Add(self.torrentdetailspanel, 1, wx.EXPAND)
        self.splitter_bottom.Add(self.librarydetailspanel, 1, wx.EXPAND)
        self.splitter_bottom.Add(self.channeldetailspanel, 1, wx.EXPAND)
        self.splitter_bottom.Add(self.playlistdetailspanel, 1, wx.EXPAND)
        self.splitter_bottom.Add(self.searchinfopanel, 1, wx.EXPAND)
        self.splitter_bottom.Add(self.channelinfopanel, 1, wx.EXPAND)
        self.splitter_bottom.Add(self.libraryinfopanel, 1, wx.EXPAND)
        self.splitter_bottom.Add(self.playlistinfopanel, 1, wx.EXPAND)
        self.splitter_bottom.Add(self.selectedchannelinfopanel, 1, wx.EXPAND)
        self.splitter_bottom_window.SetSizer(self.splitter_bottom)

        self.splitter.SetSashGravity(0.8)
        self.splitter.SplitHorizontally(self.splitter_top_window,
                                        self.splitter_bottom_window, sashpos)
        self.splitter.Show(False)

        # Reset the sash position after the splitter has been made visible
        def OnShowSplitter(event):
            wx.CallAfter(self.splitter.SetSashPosition, sashpos)
            self.splitter.Unbind(wx.EVT_SHOW)
            event.Skip()

        self.splitter.Bind(wx.EVT_SHOW, OnShowSplitter)

        self.stats = Stats(self)
        self.stats.Show(False)
        self.managechannel = ManageChannel(self)
        self.managechannel.Show(False)

        self.utility.session.notifier.notify(NTFY_STARTUP_TICK, NTFY_INSERT,
                                             None, 'Positioning')

        # position all elements
        vSizer = wx.BoxSizer(wx.VERTICAL)

        vSizer.Add(self.top_bg, 0, wx.EXPAND)

        hSizer = wx.BoxSizer(wx.HORIZONTAL)
        vSizer.Add(hSizer, 1, wx.EXPAND)

        hSizer.Add(self.actlist, 0, wx.EXPAND)
        separator = wx.Panel(self, size=(1, -1))
        separator.SetBackgroundColour(SEPARATOR_GREY)
        hSizer.Add(separator, 0, wx.EXPAND)
        hSizer.Add(self.home, 1, wx.EXPAND)
        hSizer.Add(self.stats, 1, wx.EXPAND)
        hSizer.Add(self.networkgraph, 1, wx.EXPAND)
        hSizer.Add(self.splitter, 1, wx.EXPAND)

        hSizer.Add(self.managechannel, 1, wx.EXPAND)

        if self.videoparentpanel:
            hSizer.Add(self.videoparentpanel, 1, wx.EXPAND)

        hSizer.Add(self.creditminingpanel, 1, wx.EXPAND)

        self.SetSizer(vSizer)

        # set sizes
        self.top_bg.SetMinSize((-1, 45))
        self.actlist.SetMinSize((200, -1))

        self.SRstatusbar = SRstatusbar(self)
        self.SetStatusBar(self.SRstatusbar)

        def preload_data():
            self.guiUtility.showChannelCategory('All', False)
            self.guiUtility.showLibrary(False)

        startWorker(None, preload_data, delay=1.5, workerType="ThreadPool")

        if sys.platform != 'darwin':
            dragdroplist = FileDropTarget(self)
            self.SetDropTarget(dragdroplist)
        try:
            self.SetIcon(
                wx.Icon(
                    os.path.join(self.utility.getPath(), 'Tribler', 'Main',
                                 'vwxGUI', 'images', 'tribler.ico'),
                    wx.BITMAP_TYPE_ICO))
        except:
            pass

        self.tbicon = None
        try:
            self.tbicon = ABCTaskBarIcon(self)
        except:
            print_exc()

        # Don't update GUI as often when iconized
        self.GUIupdate = True
        self.window = self.GetChildren()[0]
        self.window.utility = self.utility

        self.utility.session.notifier.notify(NTFY_STARTUP_TICK, NTFY_INSERT,
                                             None, 'Binding events')
        # Menu Events
        #
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        # leaving here for the time being:
        # wxMSW apparently sends the event to the App object rather than
        # the top-level Frame, but there seemed to be some possibility of
        # change
        self.Bind(wx.EVT_QUERY_END_SESSION, self.OnCloseWindow)
        self.Bind(wx.EVT_END_SESSION, self.OnCloseWindow)
        self.Bind(wx.EVT_ICONIZE, self.onIconify)
        self.Bind(wx.EVT_SIZE, self.onSize)
        self.Bind(wx.EVT_MAXIMIZE, self.onSize)

        findId = wx.NewId()
        quitId = wx.NewId()
        nextId = wx.NewId()
        prevId = wx.NewId()
        dispId = wx.NewId()
        wxId = wx.NewId()
        anonId = wx.NewId()
        DISPERSY_DEBUG_FRAME_ID = wx.NewId()
        self.Bind(wx.EVT_MENU, self.OnFind, id=findId)
        self.Bind(wx.EVT_MENU, lambda event: self.Close(), id=quitId)
        self.Bind(wx.EVT_MENU, self.OnNext, id=nextId)
        self.Bind(wx.EVT_MENU, self.OnPrev, id=prevId)
        self.Bind(wx.EVT_MENU,
                  lambda evt: self.guiUtility.ShowPage('stats'),
                  id=dispId)
        self.Bind(wx.EVT_MENU, lambda evt: self.OpenInspectionTool(), id=wxId)
        self.Bind(wx.EVT_MENU,
                  lambda evt: self.guiUtility.ShowPage('networkgraph'),
                  id=anonId)
        self.Bind(wx.EVT_MENU,
                  self.OnOpenDebugFrame,
                  id=DISPERSY_DEBUG_FRAME_ID)

        accelerators = [(wx.ACCEL_CTRL, ord('f'), findId)]
        accelerators.append((wx.ACCEL_CTRL, ord('d'), dispId))
        accelerators.append((wx.ACCEL_CTRL, ord('i'), wxId))
        accelerators.append((wx.ACCEL_CTRL, ord('n'), anonId))
        accelerators.append((wx.ACCEL_CTRL, wx.WXK_TAB, nextId))
        accelerators.append(
            (wx.ACCEL_CTRL | wx.ACCEL_SHIFT, wx.WXK_TAB, prevId))
        accelerators.append(
            (wx.ACCEL_CTRL | wx.ACCEL_ALT, ord('d'), DISPERSY_DEBUG_FRAME_ID))

        if sys.platform == 'linux2':
            accelerators.append((wx.ACCEL_CTRL, ord('q'), quitId))
            accelerators.append((wx.ACCEL_CTRL, ord('/'), findId))
        self.SetAcceleratorTable(wx.AcceleratorTable(accelerators))

        # Init video player
        self.utility.session.notifier.notify(NTFY_STARTUP_TICK, NTFY_INSERT,
                                             None, 'GUI complete')

        self.Thaw()
        self.ready = True

        self.SetMinSize((800, 600))

        def post():
            self.startCMDLineTorrent()

        # If the user passed a torrentfile on the cmdline, load it.
        wx.CallAfter(post)