Skip to content

Commit

Permalink
MNT: adjust open_page_slot to return the widget for additional wiring…
Browse files Browse the repository at this point in the history
…, explicitly hint the slot signature
  • Loading branch information
tangkong committed Oct 22, 2024
1 parent 0db43da commit 73e0f3b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
9 changes: 8 additions & 1 deletion superscore/type_hints.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from typing import Dict, Protocol, Union
from typing import TYPE_CHECKING, Callable, Dict, Protocol, Union

if TYPE_CHECKING:
from superscore.model import Entry
from superscore.widgets.core import DataWidget

AnyEpicsType = Union[int, str, float, bool]

Expand All @@ -8,3 +12,6 @@ class AnyDataclass(Protocol):
Protocol stub shamelessly lifted from stackoverflow to hint at dataclass
"""
__dataclass_fields__: Dict


OpenPageSlot = Callable[["Entry"], "DataWidget"]
5 changes: 3 additions & 2 deletions superscore/widgets/page/collection_builder.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logging
from typing import Callable, Optional
from typing import Optional

from qtpy import QtCore, QtWidgets
from qtpy.QtGui import QCloseEvent

from superscore.client import Client
from superscore.model import Collection, Entry, Parameter
from superscore.type_hints import OpenPageSlot
from superscore.widgets.core import DataWidget, Display, NameDescTagsWidget
from superscore.widgets.enhanced import FilterComboBox
from superscore.widgets.manip_helpers import insert_widget
Expand Down Expand Up @@ -47,7 +48,7 @@ def __init__(
*args,
client: Client,
data: Optional[Collection] = None,
open_page_slot: Optional[Callable] = None,
open_page_slot: Optional[OpenPageSlot] = None,
**kwargs
):
if data is None:
Expand Down
7 changes: 4 additions & 3 deletions superscore/widgets/page/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
from enum import auto
from typing import Any, Callable, Dict, List, Optional
from typing import Any, Dict, List, Optional

import qtawesome as qta
from dateutil import tz
Expand All @@ -11,6 +11,7 @@
from superscore.backends.core import SearchTerm
from superscore.client import Client
from superscore.model import Collection, Entry, Readback, Setpoint, Snapshot
from superscore.type_hints import OpenPageSlot
from superscore.widgets import ICON_MAP
from superscore.widgets.core import Display
from superscore.widgets.views import (BaseTableEntryModel, ButtonDelegate,
Expand Down Expand Up @@ -56,7 +57,7 @@ def __init__(
self,
*args,
client: Client,
open_page_slot: Optional[Callable] = None,
open_page_slot: Optional[OpenPageSlot] = None,
**kwargs
) -> None:
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -234,7 +235,7 @@ class ResultFilterProxyModel(QtCore.QSortFilterProxyModel):
def __init__(
self,
*args,
open_page_slot: Optional[Callable] = None,
open_page_slot: Optional[OpenPageSlot] = None,
**kwargs
) -> None:
super().__init__(*args, **kwargs)
Expand Down
6 changes: 3 additions & 3 deletions superscore/widgets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import logging
import time
from enum import Enum, IntEnum, auto
from typing import (Any, Callable, ClassVar, Dict, Generator, List, Optional,
Union)
from typing import Any, ClassVar, Dict, Generator, List, Optional, Union
from uuid import UUID
from weakref import WeakValueDictionary

Expand All @@ -23,6 +22,7 @@
from superscore.model import (Collection, Entry, Nestable, Parameter, Readback,
Root, Setpoint, Severity, Snapshot, Status)
from superscore.qt_helpers import QDataclassBridge
from superscore.type_hints import OpenPageSlot
from superscore.widgets import ICON_MAP

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def __init__(
*args,
client: Optional[Client] = None,
data: Optional[Union[Entry, List[Entry]]] = None,
open_page_slot: Optional[Callable] = None,
open_page_slot: Optional[OpenPageSlot] = None,
**kwargs,
) -> None:
"""need to set open_column, close_column in subclass"""
Expand Down
11 changes: 9 additions & 2 deletions superscore/widgets/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from superscore.client import Client
from superscore.model import Entry
from superscore.widgets import ICON_MAP
from superscore.widgets.core import Display
from superscore.widgets.core import DataWidget, Display
from superscore.widgets.page import PAGE_MAP
from superscore.widgets.page.collection_builder import CollectionBuilderPage
from superscore.widgets.page.search import SearchPage
Expand Down Expand Up @@ -87,14 +87,19 @@ def open_collection_builder(self):
)
self._partial_slots.append(update_slot)

def open_page(self, entry: Entry) -> None:
def open_page(self, entry: Entry) -> DataWidget:
"""
Open a page for ``entry`` in a new tab.
Parameters
----------
entry : Entry
Entry subclass to open a new page for
Returns
-------
DataWidget
Created widget, for cross references
"""
logger.debug(f'attempting to open {entry}')
if not isinstance(entry, Entry):
Expand All @@ -119,6 +124,8 @@ def open_page(self, entry: Entry) -> None:
idx = self.tab_widget.addTab(page_widget, icon, tab_name)
self.tab_widget.setCurrentIndex(idx)

return page_widget

def open_search_page(self) -> None:
page = SearchPage(client=self.client, open_page_slot=self.open_page)
self.tab_widget.addTab(page, 'search')
Expand Down

0 comments on commit 73e0f3b

Please sign in to comment.