# Buggy code
def init(self):
    """
    Custom initialization for ReceiveMode.
    """
    # Threads start out as None
    self.compress_thread = None

    # Create the Web object
    self.web = Web(self.common, True, "share")

    # File selection
    self.file_selection = FileSelection(self.common, self)
    if self.filenames:
        for filename in self.filenames:
            self.file_selection.file_list.add_file(filename)

    # Server status
    self.server_status.set_mode("share", self.file_selection)
    self.server_status.server_started.connect(self.file_selection.server_started)
    self.server_status.server_stopped.connect(self.file_selection.server_stopped)
    self.server_status.server_stopped.connect(self.update_primary_action)
    self.server_status.server_canceled.connect(self.file_selection.server_stopped)
    self.server_status.server_canceled.connect(self.update_primary_action)
    self.file_selection.file_list.files_updated.connect(self.server_status.update)
    self.file_selection.file_list.files_updated.connect(self.update_primary_action)
    # Tell server_status about web, then update
    self.server_status.web = self.web
    self.server_status.update()

    # Filesize warning
    self.filesize_warning = QtWidgets.QLabel()
    self.filesize_warning.setWordWrap(True)
    self.filesize_warning.setStyleSheet(self.common.css["share_filesize_warning"])
    self.filesize_warning.hide()

    # Download history
    self.history = History(
        self.common,
        QtGui.QPixmap.fromImage(
            QtGui.QImage(
                self.common.get_resource_path("images/share_icon_transparent.png")
            )
        ),
        strings._("gui_share_mode_no_files"),
        strings._("gui_all_modes_history"),
    )
    self.history.hide()

    # Info label
    self.info_label = QtWidgets.QLabel()
    self.info_label.hide()

    # Toggle history
    self.toggle_history = ToggleHistory(
        self.common,
        self,
        self.history,
        QtGui.QIcon(self.common.get_resource_path("images/share_icon_toggle.png")),
        QtGui.QIcon(
            self.common.get_resource_path("images/share_icon_toggle_selected.png")
        ),
    )

    # Top bar
    top_bar_layout = QtWidgets.QHBoxLayout()
    top_bar_layout.addWidget(self.info_label)
    top_bar_layout.addStretch()
    top_bar_layout.addWidget(self.toggle_history)

    # Primary action layout
    self.primary_action_layout.addWidget(self.filesize_warning)
    self.primary_action.hide()
    self.update_primary_action()

    # Status bar, zip progress bar
    self._zip_progress_bar = None

    # Main layout
    self.main_layout = QtWidgets.QVBoxLayout()
    self.main_layout.addLayout(top_bar_layout)
    self.main_layout.addLayout(self.file_selection)
    self.main_layout.addWidget(self.primary_action)
    self.main_layout.addWidget(self.min_width_widget)

    # Wrapper layout
    self.wrapper_layout = QtWidgets.QHBoxLayout()
    self.wrapper_layout.addLayout(self.main_layout)
    self.wrapper_layout.addWidget(self.history)
    self.setLayout(self.wrapper_layout)

    # Always start with focus on file selection
    self.file_selection.setFocus()


# Traceback (KeyError)
[Jan 07 2019 20:58:37] Onion.cleanup: trying to remove onion 5yym6w3kg4tof56umfy6a632nvtoc5dkkpkhj4zd2slqzp5wuiwml7yd
=> 2.4 MiB         video 1.mov[Jan 07 2019 20:58:37] ReceiveMode.update_primary_action
Traceback (most recent call last):
File "onionshare_gui/onionshare_gui.py", line 382, in timer_callback
mode.handle_request_progress(event)
File "onionshare_gui/mode/receive_mode/__init__.py", line 159, in handle_request_progress
'progress': event["data"]["progress"]
File "onionshare_gui/mode/history.py", line 451, in update
self.item_list.update(id, data)
File "onionshare_gui/mode/history.py", line 347, in update
self.items[id].update(data)
KeyError: 0
=> 2.4 MiB         video 1.movAbort trap: 6

# Fixed code
def init(self):
    """
    Custom initialization for ReceiveMode.
    """
    # Threads start out as None
    self.compress_thread = None

    # Create the Web object
    self.web = Web(self.common, True, "share")

    # File selection
    self.file_selection = FileSelection(self.common, self)
    if self.filenames:
        for filename in self.filenames:
            self.file_selection.file_list.add_file(filename)

    # Server status
    self.server_status.set_mode("share", self.file_selection)
    self.server_status.server_started.connect(self.file_selection.server_started)
    self.server_status.server_stopped.connect(self.file_selection.server_stopped)
    self.server_status.server_stopped.connect(self.update_primary_action)
    self.server_status.server_canceled.connect(self.file_selection.server_stopped)
    self.server_status.server_canceled.connect(self.update_primary_action)
    self.file_selection.file_list.files_updated.connect(self.server_status.update)
    self.file_selection.file_list.files_updated.connect(self.update_primary_action)
    # Tell server_status about web, then update
    self.server_status.web = self.web
    self.server_status.update()

    # Filesize warning
    self.filesize_warning = QtWidgets.QLabel()
    self.filesize_warning.setWordWrap(True)
    self.filesize_warning.setStyleSheet(self.common.css["share_filesize_warning"])
    self.filesize_warning.hide()

    # Download history
    self.history = History(
        self.common,
        QtGui.QPixmap.fromImage(
            QtGui.QImage(
                self.common.get_resource_path("images/share_icon_transparent.png")
            )
        ),
        strings._("gui_share_mode_no_files"),
        strings._("gui_all_modes_history"),
    )
    self.history.hide()

    # Info label
    self.info_label = QtWidgets.QLabel()
    self.info_label.hide()

    # Toggle history
    self.toggle_history = ToggleHistory(
        self.common,
        self,
        self.history,
        QtGui.QIcon(self.common.get_resource_path("images/share_icon_toggle.png")),
        QtGui.QIcon(
            self.common.get_resource_path("images/share_icon_toggle_selected.png")
        ),
    )

    # Top bar
    top_bar_layout = QtWidgets.QHBoxLayout()
    top_bar_layout.addWidget(self.info_label)
    top_bar_layout.addStretch()
    top_bar_layout.addWidget(self.toggle_history)

    # Primary action layout
    self.primary_action_layout.addWidget(self.filesize_warning)
    self.primary_action.hide()
    self.update_primary_action()

    # Status bar, zip progress bar
    self._zip_progress_bar = None

    # Main layout
    self.main_layout = QtWidgets.QVBoxLayout()
    self.main_layout.addLayout(top_bar_layout)
    self.main_layout.addLayout(self.file_selection)
    self.main_layout.addWidget(self.primary_action)
    self.main_layout.addWidget(self.min_width_widget)

    # Wrapper layout
    self.wrapper_layout = QtWidgets.QHBoxLayout()
    self.wrapper_layout.addLayout(self.main_layout)
    self.wrapper_layout.addWidget(self.history, stretch=1)
    self.setLayout(self.wrapper_layout)

    # Always start with focus on file selection
    self.file_selection.setFocus()