@@ -180,6 +180,7 @@ class Session(ABC):
180
180
output : Outputs
181
181
clientdata : ClientData
182
182
current_output_id : str | None
183
+ "ID for the currently rendering output."
183
184
184
185
# Could be done with a weak ref dict from root to all children. Then we could just
185
186
# iterate over all modules and check the `.bookmark_exclude` list of each proxy
@@ -1556,7 +1557,7 @@ def pixelratio(self) -> float:
1556
1557
"""
1557
1558
return cast (int , self ._read_input ("pixelratio" ))
1558
1559
1559
- def output_height (self , id : str ) -> float | None :
1560
+ def output_height (self , id : Optional [ str ] = None ) -> float | None :
1560
1561
"""
1561
1562
Reactively read the height of an output.
1562
1563
@@ -1573,7 +1574,7 @@ def output_height(self, id: str) -> float | None:
1573
1574
"""
1574
1575
return cast (float , self ._read_output (id , "height" ))
1575
1576
1576
- def output_width (self , id : str ) -> float | None :
1577
+ def output_width (self , id : Optional [ str ] = None ) -> float | None :
1577
1578
"""
1578
1579
Reactively read the width of an output.
1579
1580
@@ -1590,7 +1591,7 @@ def output_width(self, id: str) -> float | None:
1590
1591
"""
1591
1592
return cast (float , self ._read_output (id , "width" ))
1592
1593
1593
- def output_hidden (self , id : str ) -> bool | None :
1594
+ def output_hidden (self , id : Optional [ str ] = None ) -> bool | None :
1594
1595
"""
1595
1596
Reactively read whether an output is hidden.
1596
1597
@@ -1606,7 +1607,7 @@ def output_hidden(self, id: str) -> bool | None:
1606
1607
"""
1607
1608
return cast (bool , self ._read_output (id , "hidden" ))
1608
1609
1609
- def output_bg_color (self , id : str ) -> str | None :
1610
+ def output_bg_color (self , id : Optional [ str ] = None ) -> str | None :
1610
1611
"""
1611
1612
Reactively read the background color of an output.
1612
1613
@@ -1623,7 +1624,7 @@ def output_bg_color(self, id: str) -> str | None:
1623
1624
"""
1624
1625
return cast (str , self ._read_output (id , "bg" ))
1625
1626
1626
- def output_fg_color (self , id : str ) -> str | None :
1627
+ def output_fg_color (self , id : Optional [ str ] = None ) -> str | None :
1627
1628
"""
1628
1629
Reactively read the foreground color of an output.
1629
1630
@@ -1640,7 +1641,7 @@ def output_fg_color(self, id: str) -> str | None:
1640
1641
"""
1641
1642
return cast (str , self ._read_output (id , "fg" ))
1642
1643
1643
- def output_accent_color (self , id : str ) -> str | None :
1644
+ def output_accent_color (self , id : Optional [ str ] = None ) -> str | None :
1644
1645
"""
1645
1646
Reactively read the accent color of an output.
1646
1647
@@ -1657,7 +1658,7 @@ def output_accent_color(self, id: str) -> str | None:
1657
1658
"""
1658
1659
return cast (str , self ._read_output (id , "accent" ))
1659
1660
1660
- def output_font (self , id : str ) -> str | None :
1661
+ def output_font (self , id : Optional [ str ] = None ) -> str | None :
1661
1662
"""
1662
1663
Reactively read the font(s) of an output.
1663
1664
@@ -1685,9 +1686,18 @@ def _read_input(self, key: str) -> str:
1685
1686
1686
1687
return self ._session .input [id ]()
1687
1688
1688
- def _read_output (self , id : str , key : str ) -> str | None :
1689
+ def _read_output (self , id : str | None , key : str ) -> str | None :
1689
1690
self ._check_current_context (f"output_{ key } " )
1690
1691
1692
+ if id is None :
1693
+ id = self ._session .current_output_id
1694
+
1695
+ if id is None :
1696
+ raise ValueError (
1697
+ "session.clientdata.output_*() must be either be supplied with an id "
1698
+ "or called from within an output renderer."
1699
+ )
1700
+
1691
1701
input_id = ResolvedId (f".clientdata_output_{ id } _{ key } " )
1692
1702
if input_id in self ._session .input :
1693
1703
return self ._session .input [input_id ]()
0 commit comments