Skip to content

Commit

Permalink
ENH: add root tree view to main window, add context menu for opening …
Browse files Browse the repository at this point in the history
…page
  • Loading branch information
tangkong committed Jul 26, 2024
1 parent d2b2e30 commit a75211a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions superscore/widgets/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from superscore.widgets.core import Display
from superscore.widgets.page import PAGE_MAP
from superscore.widgets.page.search import SearchPage
from superscore.widgets.tree import RootTree

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -44,6 +45,13 @@ def setup_ui(self) -> None:
tab_bar.setElideMode(QtCore.Qt.ElideNone)
self.tab_widget.tabCloseRequested.connect(self.tab_widget.removeTab)

# setup tree view
self.tree_model = RootTree(base_entry=self.client.backend.root,
client=self.client)
self.tree_view.setModel(self.tree_model)
self.tree_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.tree_view.customContextMenuRequested.connect(self._tree_context_menu)

def open_page(self, entry: Entry) -> None:
"""
Open a page for ``entry`` in a new tab.
Expand Down Expand Up @@ -78,3 +86,20 @@ def open_page(self, entry: Entry) -> None:
def open_search_page(self) -> None:
page = SearchPage(client=self.client, open_page_slot=self.open_page)
self.tab_widget.addTab(page, 'search')

def _tree_context_menu(self, pos: QtCore.QPoint) -> None:
self.menu = QtWidgets.QMenu(self)
index: QtCore.QModelIndex = self.tree_view.indexAt(pos)
entry: Entry = index.internalPointer()._data

if index is not None and index.data() is not None:
# WeakPartialMethodSlot may not be needed, menus are transient
def open(*_, **__):
self.open_page(entry)

open_action = self.menu.addAction(
f'&Open Detailed {type(entry).__name__} page'
)
open_action.triggered.connect(open)

self.menu.exec_(self.tree_view.mapToGlobal(pos))

0 comments on commit a75211a

Please sign in to comment.