import logging
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QKeySequence, QCursor
from PyQt5.QtWidgets import QApplication, QTableWidget, QMenu, \
  QTabWidget, QTabBar, QCheckBox, QFrame, QVBoxLayout, QHBoxLayout


class TableWidget(QTableWidget):
  def __init__(self):
    super().__init__()
    self.menu = QMenu()
    self.menu.addAction('&Copy selected', self.copySelected, QKeySequence('Ctrl+C'))

  def keyPressEvent(self, ev):
    if ev.matches(QKeySequence.Copy):
      self.copySelected()
      return

    super().keyPressEvent(ev)

  def contextMenuEvent(self, ev):
    self.menu.exec_(ev.globalPos())

  def copySelected(self):
    rows = []
    row = None
    curRow = None
    for cell in self.selectedIndexes():
      if cell.row() != curRow:
        row = []
        rows.append(row)
        curRow = cell.row()
      row.append(str(cell.data()).strip())
    QApplication.clipboard().setText('\n'.join(['\t'.join(r) for r in rows]))


class TabWidgetWithCheckBox(QTabWidget):
  selectionChanged = pyqtSignal(name='selectionChanged')

  def __init__(self):
    super().__init__()

    self.menu = QMenu()
    self.menu.addAction('Select all', self.selectAll)
    self.menu.addAction('Unselect all except this', self.unselectAllExceptThis)

    tabbar = self.tabBar()
    tabbar.setContextMenuPolicy(Qt.CustomContextMenu)
    tabbar.customContextMenuRequested.connect(self.showTabMenu)

  def isChecked(self, idx):
    return self.tabBar().tabData(idx)[0].isChecked()

  def setChecked(self, idx, checked):
    self.tabBar().tabData(idx)[0].setChecked(checked)

  def selectAll(self, func = None):
    for i in range(self.count()):
      if func is None or func(i):
        self.setChecked(i, True)
    self.selectionChanged.emit()

  def unselectAll(self, func = None):
    for i in range(self.count()):
      if func is None or func(i):
        self.setChecked(i, False)
    self.selectionChanged.emit()

  def selectAllExceptThis(self):
    self.selectAll(lambda i: i != self.currentIndex())

  def unselectAllExceptThis(self):
    self.unselectAll(lambda i: i != self.currentIndex())

  def selectRightTabs(self):
    self.selectAll(lambda i: i > self.currentIndex())

  def unselectRightTabs(self):
    self.unselectAll(lambda i: i > self.currentIndex())

  def selectLeftTabs(self):
    self.selectAll(lambda i: i < self.currentIndex())

  def unselectLeftTabs(self):
    self.unselectAll(lambda i: i < self.currentIndex())

  def showTabMenu(self, point):
    tabbar = self.tabBar()
    idx = tabbar.tabAt(point)
    self.setCurrentIndex(idx)
    self.menu.exec_(QCursor.pos())

  def addTab(self, widget, name, checked):
    idx = super().addTab(widget, name)

    check = QCheckBox()
    check.setChecked(checked)
    check.clicked.connect(self.selectionChanged)

    bar = self.tabBar()
    bar.setTabButton(idx, QTabBar.LeftSide, check)
    bar.setTabData(idx, (check,))

  def getAllWidgets(self):
    return [self.widget(i) for i in range(self.count())]



class HSeparator(QFrame):
  def __init__(self):
    super().__init__()
    self.setFrameShape(QFrame.HLine)
    self.setFrameShadow(QFrame.Sunken)



class HBoxLayout(QHBoxLayout):
  def __init__(self):
    super().__init__()
    self.setContentsMargins(0, 0, 0, 0)
    self.setSpacing(4)



class VBoxLayout(QVBoxLayout):
  def __init__(self):
    super().__init__()
    self.setContentsMargins(0, 0, 0, 0)
    self.setSpacing(4)

@@ -968,2040 +968,8 @@
 )%0A%0A%0A
-class TabWidgetWithCheckBox(QTabWidget):%0A  selectionChanged = pyqtSignal(name='selectionChanged')%0A%0A  def __init__(self):%0A    super().__init__()%0A%0A    self.menu = QMenu()%0A    self.menu.addAction('Select all', self.selectAll)%0A    self.menu.addAction('Unselect all except this', self.unselectAllExceptThis)%0A%0A    tabbar = self.tabBar()%0A    tabbar.setContextMenuPolicy(Qt.CustomContextMenu)%0A    tabbar.customContextMenuRequested.connect(self.showTabMenu)%0A%0A  def isChecked(self, idx):%0A    return self.tabBar().tabData(idx)%5B0%5D.isChecked()%0A%0A  def setChecked(self, idx, checked):%0A    self.tabBar().tabData(idx)%5B0%5D.setChecked(checked)%0A%0A  def selectAll(self, func = None):%0A    for i in range(self.count()):%0A      if func is None or func(i):%0A        self.setChecked(i, True)%0A    self.selectionChanged.emit()%0A%0A  def unselectAll(self, func = None):%0A    for i in range(self.count()):%0A      if func is None or func(i):%0A        self.setChecked(i, False)%0A    self.selectionChanged.emit()%0A%0A  def selectAllExceptThis(self):%0A    self.selectAll(lambda i: i != self.currentIndex())%0A%0A  def unselectAllExceptThis(self):%0A    self.unselectAll(lambda i: i != self.currentIndex())%0A%0A  def selectRightTabs(self):%0A    self.selectAll(lambda i: i %3E self.currentIndex())%0A%0A  def unselectRightTabs(self):%0A    self.unselectAll(lambda i: i %3E self.currentIndex())%0A%0A  def selectLeftTabs(self):%0A    self.selectAll(lambda i: i %3C self.currentIndex())%0A%0A  def unselectLeftTabs(self):%0A    self.unselectAll(lambda i: i %3C self.currentIndex())%0A%0A  def showTabMenu(self, point):%0A    tabbar = self.tabBar()%0A    idx = tabbar.tabAt(point)%0A    self.setCurrentIndex(idx)%0A    self.menu.exec_(QCursor.pos())%0A%0A  def addTab(self, widget, name, checked):%0A    idx = super().addTab(widget, name)%0A%0A    check = QCheckBox()%0A    check.setChecked(checked)%0A    check.clicked.connect(self.selectionChanged)%0A%0A    bar = self.tabBar()%0A    bar.setTabButton(idx, QTabBar.LeftSide, check)%0A    bar.setTabData(idx, (check,))%0A%0A  def getAllWidgets(self):%0A    return %5Bself.widget(i) for i in range(self.count())%5D%0A%0A%0A
 %0Acla

Remove unused class