'Close client tab from index or widget (or close current tab)'

def close_client(self, index=None, client=None, force=False):

    if (not self.tabwidget.count()):
        return
    if (client is not None):
        index = self.tabwidget.indexOf(client)
    if ((index is None) and (client is None)):
        index = self.tabwidget.currentIndex()
    if (index is not None):
        client = self.tabwidget.widget(index)
    if ((not self.mainwindow_close) and (not force)):
        close_all = True
        if self.get_option('ask_before_closing'):
            close = QMessageBox.question(self, self.get_plugin_title(), _('Do    you    want    to    close    this    console?'), (QMessageBox.Yes | QMessageBox.No))
            if (close == QMessageBox.No):
                return
        if (len(self.get_related_clients(client)) > 0):
            close_all = QMessageBox.question(self, self.get_plugin_title(), _('Do    you    want    to    close    all    other    consoles    connected    to    the    same    kernel    as    this    one?'), (QMessageBox.Yes | QMessageBox.No))
        client.shutdown()
        if (close_all == QMessageBox.Yes):
            self.close_related_clients(client)
    client.close()
    self.tabwidget.removeTab(self.tabwidget.indexOf(client))
    self.clients.remove(client)
    self.filenames.pop(index)
    if ((not self.tabwidget.count()) and self.create_new_client_if_empty):
        self.create_new_client()
    self.update_tabs_text()
    self.sig_update_plugin_title.emit()
