# Buggy code
def __init__(self):
    QMainWindow.__init__(self)

    self.navigation_stack = []
    self.feedback_dialog_is_open = False
    self.tribler_started = False
    self.tribler_settings = None
    self.debug_window = None
    self.core_manager = CoreManager()
    self.pending_requests = {}
    self.pending_uri_requests = []
    self.download_uri = None
    self.dialog = None
    self.start_download_dialog_active = False
    self.request_mgr = None
    self.search_request_mgr = None
    self.search_suggestion_mgr = None
    self.selected_torrent_files = []
    self.vlc_available = True
    self.has_search_results = False
    self.start_time = time.time()

    sys.excepthook = self.on_exception

    uic.loadUi(get_ui_file_path("mainwindow.ui"), self)
    TriblerRequestManager.window = self
    self.tribler_status_bar.hide()

    self.magnet_handler = MagnetHandler(self.window)
    QDesktopServices.setUrlHandler("magnet", self.magnet_handler, "on_open_magnet_link")

    QCoreApplication.setOrganizationDomain("nl")
    QCoreApplication.setOrganizationName("TUDelft")
    QCoreApplication.setApplicationName("Tribler")
    QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

    self.read_settings()

    # Remove the focus rect on OS X
    for widget in (
        self.findChildren(QLineEdit)
        + self.findChildren(QListWidget)
        + self.findChildren(QTreeWidget)
    ):
        widget.setAttribute(Qt.WA_MacShowFocusRect, 0)

    self.menu_buttons = [
        self.left_menu_button_home,
        self.left_menu_button_search,
        self.left_menu_button_my_channel,
        self.left_menu_button_subscriptions,
        self.left_menu_button_video_player,
        self.left_menu_button_downloads,
        self.left_menu_button_discovered,
    ]

    self.video_player_page.initialize_player()
    self.search_results_page.initialize_search_results_page()
    self.settings_page.initialize_settings_page()
    self.subscribed_channels_page.initialize()
    self.edit_channel_page.initialize_edit_channel_page()
    self.downloads_page.initialize_downloads_page()
    self.home_page.initialize_home_page()
    self.loading_page.initialize_loading_page()
    self.discovering_page.initialize_discovering_page()
    self.discovered_page.initialize_discovered_page()
    self.trust_page.initialize_trust_page()

    self.stackedWidget.setCurrentIndex(PAGE_LOADING)

    # Create the system tray icon
    if QSystemTrayIcon.isSystemTrayAvailable():
        self.tray_icon = QSystemTrayIcon()
        use_monochrome_icon = get_gui_setting(
            self.gui_settings, "use_monochrome_icon", False, is_bool=True
        )
        self.update_tray_icon(use_monochrome_icon)

    self.hide_left_menu_playlist()
    self.left_menu_button_debug.setHidden(True)
    self.top_menu_button.setHidden(True)
    self.left_menu.setHidden(True)
    self.trust_button.setHidden(True)
    self.settings_button.setHidden(True)
    self.add_torrent_button.setHidden(True)
    self.top_search_bar.setHidden(True)

    # Set various icons
    self.top_menu_button.setIcon(QIcon(get_image_path("menu.png")))

    self.search_completion_model = QStringListModel()
    completer = QCompleter()
    completer.setModel(self.search_completion_model)
    completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
    self.item_delegate = QStyledItemDelegate()
    completer.popup().setItemDelegate(self.item_delegate)
    completer.popup().setStyleSheet("""
        QListView {
            background-color: #404040;
        }

        QListView::item {
            color: #D0D0D0;
            padding-top: 5px;
            padding-bottom: 5px;
        }

        QListView::item:hover {
            background-color: #707070;
        }
        """)
    self.top_search_bar.setCompleter(completer)

    # Toggle debug if developer mode is enabled
    self.window().left_menu_button_debug.setHidden(
        not get_gui_setting(self.gui_settings, "debug", False, is_bool=True)
    )

    self.core_manager.start()

    self.core_manager.events_manager.received_search_result_channel.connect(
        self.search_results_page.received_search_result_channel
    )
    self.core_manager.events_manager.received_search_result_torrent.connect(
        self.search_results_page.received_search_result_torrent
    )
    self.core_manager.events_manager.torrent_finished.connect(self.on_torrent_finished)
    self.core_manager.events_manager.new_version_available.connect(
        self.on_new_version_available
    )
    self.core_manager.events_manager.tribler_started.connect(self.on_tribler_started)

    # Install signal handler for ctrl+c events
    def sigint_handler(*_):
        self.close_tribler()

    signal.signal(signal.SIGINT, sigint_handler)

    self.installEventFilter(self.video_player_page)

    self.show()


# Traceback (AssertionError)
Tuples differ: (2, ('127.0.0.1', [5, 4, 3, 2,... != (2, ('127.0.0.1', [5, 4, 3, 2,...

First differing element 2:
u'None'
''

- (2, ('127.0.0.1', [5, 4, 3, 2, 1]), u'None')
?                                     - ----

+ (2, ('127.0.0.1', [5, 4, 3, 2, 1]), '')
Stacktrace

Traceback (most recent call last):
File "c:\python27\lib\unittest\case.py", line 329, in run
testMethod()
File "C:\workspace\jenkins\workspace\GH_Tribler_PR_tests_win64\tribler\Tribler\Test\test_as_server.py", line 58, in check
result = fun(*argv, **kwargs)
File "C:\workspace\jenkins\workspace\GH_Tribler_PR_tests_win64\tribler\Tribler\Test\Core\Upgrade\test_config_upgrade_70_71.py", line 33, in test_read_test_libtribler_conf
self.assertEqual(result_config.get_anon_proxy_settings(), (2, ("127.0.0.1", [5, 4, 3, 2, 1]), ''))
File "c:\python27\lib\unittest\case.py", line 513, in assertEqual
assertion_func(first, second, msg=msg)
File "c:\python27\lib\unittest\case.py", line 753, in assertTupleEqual
self.assertSequenceEqual(tuple1, tuple2, msg, seq_type=tuple)
File "c:\python27\lib\unittest\case.py", line 724, in assertSequenceEqual
self.fail(msg)
File "c:\python27\lib\unittest\case.py", line 410, in fail
raise self.failureException(msg)
AssertionError: Tuples differ: (2, ('127.0.0.1', [5, 4, 3, 2,... != (2, ('127.0.0.1', [5, 4, 3, 2,...

First differing element 2:
u'None'
''

- (2, ('127.0.0.1', [5, 4, 3, 2, 1]), u'None')
?                                     - ----

+ (2, ('127.0.0.1', [5, 4, 3, 2, 1]), '')

# Fixed code
def __init__(self):
    QMainWindow.__init__(self)

    self.navigation_stack = []
    self.feedback_dialog_is_open = False
    self.tribler_started = False
    self.tribler_settings = None
    self.debug_window = None
    self.core_manager = CoreManager()
    self.pending_requests = {}
    self.pending_uri_requests = []
    self.download_uri = None
    self.dialog = None
    self.start_download_dialog_active = False
    self.request_mgr = None
    self.search_request_mgr = None
    self.search_suggestion_mgr = None
    self.selected_torrent_files = []
    self.vlc_available = True
    self.has_search_results = False
    self.start_time = time.time()

    sys.excepthook = self.on_exception

    uic.loadUi(get_ui_file_path("mainwindow.ui"), self)
    TriblerRequestManager.window = self
    self.tribler_status_bar.hide()

    self.magnet_handler = MagnetHandler(self.window)
    QDesktopServices.setUrlHandler("magnet", self.magnet_handler, "on_open_magnet_link")

    QCoreApplication.setOrganizationDomain("nl")
    QCoreApplication.setOrganizationName("TUDelft")
    QCoreApplication.setApplicationName("Tribler")
    QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

    self.read_settings()

    # Remove the focus rect on OS X
    for widget in (
        self.findChildren(QLineEdit)
        + self.findChildren(QListWidget)
        + self.findChildren(QTreeWidget)
    ):
        widget.setAttribute(Qt.WA_MacShowFocusRect, 0)

    self.menu_buttons = [
        self.left_menu_button_home,
        self.left_menu_button_search,
        self.left_menu_button_my_channel,
        self.left_menu_button_subscriptions,
        self.left_menu_button_video_player,
        self.left_menu_button_downloads,
        self.left_menu_button_discovered,
    ]

    self.video_player_page.initialize_player()
    self.search_results_page.initialize_search_results_page()
    self.settings_page.initialize_settings_page()
    self.subscribed_channels_page.initialize()
    self.edit_channel_page.initialize_edit_channel_page()
    self.downloads_page.initialize_downloads_page()
    self.home_page.initialize_home_page()
    self.loading_page.initialize_loading_page()
    self.discovering_page.initialize_discovering_page()
    self.discovered_page.initialize_discovered_page()
    self.trust_page.initialize_trust_page()

    self.stackedWidget.setCurrentIndex(PAGE_LOADING)

    # Create the system tray icon
    if QSystemTrayIcon.isSystemTrayAvailable():
        self.tray_icon = QSystemTrayIcon()
        use_monochrome_icon = get_gui_setting(
            self.gui_settings, "use_monochrome_icon", False, is_bool=True
        )
        self.update_tray_icon(use_monochrome_icon)
    else:
        self.tray_icon = None

    self.hide_left_menu_playlist()
    self.left_menu_button_debug.setHidden(True)
    self.top_menu_button.setHidden(True)
    self.left_menu.setHidden(True)
    self.trust_button.setHidden(True)
    self.settings_button.setHidden(True)
    self.add_torrent_button.setHidden(True)
    self.top_search_bar.setHidden(True)

    # Set various icons
    self.top_menu_button.setIcon(QIcon(get_image_path("menu.png")))

    self.search_completion_model = QStringListModel()
    completer = QCompleter()
    completer.setModel(self.search_completion_model)
    completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
    self.item_delegate = QStyledItemDelegate()
    completer.popup().setItemDelegate(self.item_delegate)
    completer.popup().setStyleSheet("""
        QListView {
            background-color: #404040;
        }

        QListView::item {
            color: #D0D0D0;
            padding-top: 5px;
            padding-bottom: 5px;
        }

        QListView::item:hover {
            background-color: #707070;
        }
        """)
    self.top_search_bar.setCompleter(completer)

    # Toggle debug if developer mode is enabled
    self.window().left_menu_button_debug.setHidden(
        not get_gui_setting(self.gui_settings, "debug", False, is_bool=True)
    )

    self.core_manager.start()

    self.core_manager.events_manager.received_search_result_channel.connect(
        self.search_results_page.received_search_result_channel
    )
    self.core_manager.events_manager.received_search_result_torrent.connect(
        self.search_results_page.received_search_result_torrent
    )
    self.core_manager.events_manager.torrent_finished.connect(self.on_torrent_finished)
    self.core_manager.events_manager.new_version_available.connect(
        self.on_new_version_available
    )
    self.core_manager.events_manager.tribler_started.connect(self.on_tribler_started)

    # Install signal handler for ctrl+c events
    def sigint_handler(*_):
        self.close_tribler()

    signal.signal(signal.SIGINT, sigint_handler)

    self.installEventFilter(self.video_player_page)

    self.show()