From 7c19b6bdb82e50c2ea87fec593d74ed17371f6ee Mon Sep 17 00:00:00 2001 From: "Rob.Young" Date: Sun, 27 Jun 2021 14:46:54 +0930 Subject: [PATCH 1/4] Added context menu to List View column headers to show and hide headers. --- lisp/plugins/list_layout/list_view.py | 34 +++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/lisp/plugins/list_layout/list_view.py b/lisp/plugins/list_layout/list_view.py index 4025c8d7a..ed287c2d6 100644 --- a/lisp/plugins/list_layout/list_view.py +++ b/lisp/plugins/list_layout/list_view.py @@ -24,7 +24,7 @@ QTimer, ) from PyQt5.QtGui import QKeyEvent, QContextMenuEvent, QBrush, QColor -from PyQt5.QtWidgets import QTreeWidget, QHeaderView, QTreeWidgetItem +from PyQt5.QtWidgets import QTreeWidget, QHeaderView, QTreeWidgetItem, QMenu from lisp.application import Application from lisp.backend import get_backend @@ -50,6 +50,7 @@ def __init__(self, name, widget, resize=None, width=None, visible=True): self.resize = resize self.width = width self.visible = visible + self.action = None @property def name(self): @@ -109,6 +110,10 @@ def __init__(self, listModel, parent=None): self._model.item_removed.connect(self.__cueRemoved) self._model.model_reset.connect(self.__modelReset) + self.__columnMenu = QMenu() + self.__hideMenu = self.__columnMenu.addAction("Hide") + self.__showMenu = self.__columnMenu.addMenu("Show") + # Setup the columns headers self.setHeaderLabels((c.name for c in CueListView.COLUMNS)) for i, column in enumerate(CueListView.COLUMNS): @@ -116,9 +121,20 @@ def __init__(self, listModel, parent=None): self.header().setSectionResizeMode(i, column.resize) if column.width is not None: self.setColumnWidth(i, column.width) + # Create popup menu + column.action = self.__showMenu.addAction(column.name) + column.action.triggered.connect( + lambda chk, item=i: self.showColumn(item)) + - self.header().setDragEnabled(False) + self.header().setDragEnabled(True) self.header().setStretchLastSection(False) + + # Connect local context menu for headers + self.header().setContextMenuPolicy(Qt.CustomContextMenu) + self.header().customContextMenuRequested.connect(self.__openHeaderMenu) + + self.setDragDropMode(self.InternalMove) @@ -323,3 +339,17 @@ def __updateScrollRange(self, min_, max_): self.__scrollRangeGuard = True self.verticalScrollBar().setMaximum(max_ + 1) self.__scrollRangeGuard = False + + def __openHeaderMenu(self, position): + index = self.indexAt(position) + showShowMenu = False + for i, column in enumerate(CueListView.COLUMNS): + column.action.setVisible(self.isColumnHidden(i)) + showShowMenu |= self.isColumnHidden(i) + self.__showMenu.menuAction().setVisible(showShowMenu) + action = self.__columnMenu.exec_(self.mapToGlobal(position)) + if action == self.__hideMenu: + self.hideColumn(index.column()) + + + From 349a80f54c94c74db4b9d5bd0a0c363a885aeb8a Mon Sep 17 00:00:00 2001 From: "Rob.Young" Date: Sun, 27 Jun 2021 15:19:01 +0930 Subject: [PATCH 2/4] Added i18n lookup for menu strings. --- lisp/plugins/list_layout/list_view.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/plugins/list_layout/list_view.py b/lisp/plugins/list_layout/list_view.py index ed287c2d6..839e80693 100644 --- a/lisp/plugins/list_layout/list_view.py +++ b/lisp/plugins/list_layout/list_view.py @@ -111,8 +111,8 @@ def __init__(self, listModel, parent=None): self._model.model_reset.connect(self.__modelReset) self.__columnMenu = QMenu() - self.__hideMenu = self.__columnMenu.addAction("Hide") - self.__showMenu = self.__columnMenu.addMenu("Show") + self.__hideMenu = self.__columnMenu.addAction(QT_TRANSLATE_NOOP("ListLayoutHeaderMenu", "Hide")) + self.__showMenu = self.__columnMenu.addMenu(QT_TRANSLATE_NOOP("ListLayoutHeaderMenu","Show")) # Setup the columns headers self.setHeaderLabels((c.name for c in CueListView.COLUMNS)) From c0d3f7c57c3d1dc4983416a30cfcf598752bf426 Mon Sep 17 00:00:00 2001 From: Rob7000 Date: Mon, 28 Jun 2021 08:10:15 -0400 Subject: [PATCH 3/4] Added comments --- lisp/plugins/list_layout/list_view.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lisp/plugins/list_layout/list_view.py b/lisp/plugins/list_layout/list_view.py index 839e80693..938df3a89 100644 --- a/lisp/plugins/list_layout/list_view.py +++ b/lisp/plugins/list_layout/list_view.py @@ -110,6 +110,7 @@ def __init__(self, listModel, parent=None): self._model.item_removed.connect(self.__cueRemoved) self._model.model_reset.connect(self.__modelReset) + # Create context menu for column headers self.__columnMenu = QMenu() self.__hideMenu = self.__columnMenu.addAction(QT_TRANSLATE_NOOP("ListLayoutHeaderMenu", "Hide")) self.__showMenu = self.__columnMenu.addMenu(QT_TRANSLATE_NOOP("ListLayoutHeaderMenu","Show")) @@ -121,21 +122,19 @@ def __init__(self, listModel, parent=None): self.header().setSectionResizeMode(i, column.resize) if column.width is not None: self.setColumnWidth(i, column.width) - # Create popup menu + # Create context menu to show the column column.action = self.__showMenu.addAction(column.name) column.action.triggered.connect( lambda chk, item=i: self.showColumn(item)) - self.header().setDragEnabled(True) + self.header().setDragEnabled(True) self.header().setStretchLastSection(False) # Connect local context menu for headers self.header().setContextMenuPolicy(Qt.CustomContextMenu) self.header().customContextMenuRequested.connect(self.__openHeaderMenu) - - self.setDragDropMode(self.InternalMove) # Set some visual options @@ -341,9 +340,11 @@ def __updateScrollRange(self, min_, max_): self.__scrollRangeGuard = False def __openHeaderMenu(self, position): + # Prepare and open context menu index = self.indexAt(position) showShowMenu = False for i, column in enumerate(CueListView.COLUMNS): + # show column name in menu if column is hidden column.action.setVisible(self.isColumnHidden(i)) showShowMenu |= self.isColumnHidden(i) self.__showMenu.menuAction().setVisible(showShowMenu) From afd0dff7df66566c7fc578978dec021911d9bd6c Mon Sep 17 00:00:00 2001 From: Rob7000 Date: Thu, 1 Jul 2021 09:09:25 -0400 Subject: [PATCH 4/4] Improved header menu for columns that have no name in header. --- lisp/plugins/list_layout/list_view.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lisp/plugins/list_layout/list_view.py b/lisp/plugins/list_layout/list_view.py index 938df3a89..188044b71 100644 --- a/lisp/plugins/list_layout/list_view.py +++ b/lisp/plugins/list_layout/list_view.py @@ -44,12 +44,12 @@ class ListColumn: - def __init__(self, name, widget, resize=None, width=None, visible=True): + def __init__(self, name, widget, resize=None, width=None, displayName=True): self.baseName = name self.widget = widget self.resize = resize self.width = width - self.visible = visible + self.displayName = displayName self.action = None @property @@ -73,7 +73,7 @@ class CueListView(QTreeWidget): # TODO: add ability to show/hide # TODO: implement columns (cue-type / target / etc..) COLUMNS = [ - ListColumn("", CueStatusIcons, QHeaderView.Fixed, width=45), + ListColumn(QT_TRANSLATE_NOOP("ListLayoutHeader", "Cue Status"), CueStatusIcons, QHeaderView.Fixed, width=45, displayName=False), ListColumn("#", IndexWidget, QHeaderView.ResizeToContents), ListColumn( QT_TRANSLATE_NOOP("ListLayoutHeader", "Cue"), @@ -89,7 +89,7 @@ class CueListView(QTreeWidget): ListColumn( QT_TRANSLATE_NOOP("ListLayoutHeader", "Post wait"), PostWaitWidget ), - ListColumn("", NextActionIcon, QHeaderView.Fixed, width=18), + ListColumn(QT_TRANSLATE_NOOP("ListLayoutHeader", "Next Action"), NextActionIcon, QHeaderView.Fixed, width=18, displayName=False), ] ITEM_DEFAULT_BG = QBrush(Qt.transparent) @@ -116,7 +116,7 @@ def __init__(self, listModel, parent=None): self.__showMenu = self.__columnMenu.addMenu(QT_TRANSLATE_NOOP("ListLayoutHeaderMenu","Show")) # Setup the columns headers - self.setHeaderLabels((c.name for c in CueListView.COLUMNS)) + self.setHeaderLabels((c.name if c.displayName else "" for c in CueListView.COLUMNS)) for i, column in enumerate(CueListView.COLUMNS): if column.resize is not None: self.header().setSectionResizeMode(i, column.resize)