Adjust feed status fields/display-pane to new actor-ID
That is to use the new `tractor.msg.types.Aid` struct to pull the
`brokerd` info from the `tractor.Channel.aid: Aid` attr as well as more
generally handling the new `Channel.raddr.proto_key: str` and no longer
assuming a TCP IPC transport; this per the recent `tractor.ipc`
subsys which adds multi-IPC-transports!
Downstream tweaks to match,
- use an "opt-in" field set to display in the `brokerd` info pane in
  `.ui._feedstatus.mk_feed_label()`.
 |_ also add some todos and drop some seemingly unneeded form sizing
    calcs?
- tweak `.ui._label` to allow not using markdown, though ended up not
  doing that since it looked too plain..
			
			
				port_to_latest_tractor
			
			
		
							parent
							
								
									f50202a6af
								
							
						
					
					
						commit
						28ba1392bb
					
				|  | @ -39,6 +39,7 @@ from typing import ( | ||||||
|     AsyncContextManager, |     AsyncContextManager, | ||||||
|     Awaitable, |     Awaitable, | ||||||
|     Sequence, |     Sequence, | ||||||
|  |     TYPE_CHECKING, | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| import trio | import trio | ||||||
|  | @ -75,6 +76,10 @@ from ._sampling import ( | ||||||
|     uniform_rate_send, |     uniform_rate_send, | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | if TYPE_CHECKING: | ||||||
|  |     from tractor._addr import Address | ||||||
|  |     from tractor.msg.types import Aid | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class Sub(Struct, frozen=True): | class Sub(Struct, frozen=True): | ||||||
|     ''' |     ''' | ||||||
|  | @ -899,19 +904,19 @@ async def open_feed( | ||||||
|             feed.portals[brokermod] = portal |             feed.portals[brokermod] = portal | ||||||
| 
 | 
 | ||||||
|             # fill out "status info" that the UI can show |             # fill out "status info" that the UI can show | ||||||
|             host, port = portal.channel.raddr |             chan: tractor.Channel = portal.chan | ||||||
|             if host == '127.0.0.1': |             raddr: Address = chan.raddr | ||||||
|                 host = 'localhost' |             aid: Aid = chan.aid | ||||||
| 
 |             # TAG_feed_status_update | ||||||
|             feed.status.update({ |             feed.status.update({ | ||||||
|                 'actor_name': portal.channel.uid[0], |                 'actor_id': aid, | ||||||
|                 'host': host, |                 'actor_short_id': f'{aid.name}@{aid.pid}', | ||||||
|                 'port': port, |                 'ipc': chan.raddr.proto_key, | ||||||
|  |                 'ipc_addr': raddr, | ||||||
|                 'hist_shm': 'NA', |                 'hist_shm': 'NA', | ||||||
|                 'rt_shm': 'NA', |                 'rt_shm': 'NA', | ||||||
|                 'throttle_rate': tick_throttle, |                 'throttle_hz': tick_throttle, | ||||||
|             }) |             }) | ||||||
|             # feed.status.update(init_msg.pop('status', {})) |  | ||||||
| 
 | 
 | ||||||
|             # (allocate and) connect to any feed bus for this broker |             # (allocate and) connect to any feed bus for this broker | ||||||
|             bus_ctxs.append( |             bus_ctxs.append( | ||||||
|  |  | ||||||
|  | @ -18,10 +18,11 @@ | ||||||
| Feed status and controls widget(s) for embedding in a UI-pane. | Feed status and controls widget(s) for embedding in a UI-pane. | ||||||
| 
 | 
 | ||||||
| """ | """ | ||||||
| 
 |  | ||||||
| from __future__ import annotations | from __future__ import annotations | ||||||
| from textwrap import dedent | from typing import ( | ||||||
| from typing import TYPE_CHECKING |     Any, | ||||||
|  |     TYPE_CHECKING, | ||||||
|  | ) | ||||||
| 
 | 
 | ||||||
| # from PyQt5.QtCore import Qt | # from PyQt5.QtCore import Qt | ||||||
| 
 | 
 | ||||||
|  | @ -49,35 +50,55 @@ def mk_feed_label( | ||||||
|     a feed control protocol. |     a feed control protocol. | ||||||
| 
 | 
 | ||||||
|     ''' |     ''' | ||||||
|     status = feed.status |     status: dict[str, Any] = feed.status | ||||||
|     assert status |     assert status | ||||||
| 
 | 
 | ||||||
|     msg = dedent(""" |     # SO tips on ws/nls, | ||||||
|         actor: **{actor_name}**\n |     # https://stackoverflow.com/a/15721400 | ||||||
|         |_ @**{host}:{port}**\n |     ws: str = ' ' | ||||||
|     """) |     # nl: str = '<br>'  # dun work? | ||||||
|  |     actor_info_repr: str = ( | ||||||
|  |         f')> **{status["actor_short_id"]}**\n' | ||||||
|  |         '\n'  # bc md? | ||||||
|  |     ) | ||||||
| 
 | 
 | ||||||
|     for key, val in status.items(): |     # fields to select *IN* for display | ||||||
|         if key in ('host', 'port', 'actor_name'): |     # (see `.data.feed.open_feed()` status | ||||||
|             continue |     #  update -> TAG_feed_status_update) | ||||||
|         msg += f'\n|_ {key}: **{{{key}}}**\n' |     for key in [ | ||||||
|  |         'ipc', | ||||||
|  |         'hist_shm', | ||||||
|  |         'rt_shm', | ||||||
|  |         'throttle_hz', | ||||||
|  |     ]: | ||||||
|  |         # NOTE, the 2nd key is filled via `.format()` updates. | ||||||
|  |         actor_info_repr += ( | ||||||
|  |             f'\n'  # bc md? | ||||||
|  |             f'{ws}|_{key}: **{{{key}}}**\n' | ||||||
|  |         ) | ||||||
|  |         # ^TODO? formatting and content.. | ||||||
|  |         # -[ ] showing which fqme is "forward" on the | ||||||
|  |         #    chart/fsp/order-mode? | ||||||
|  |         #  '|_ flows: **{symbols}**\n' | ||||||
|  |         # | ||||||
|  |         # -[x] why isn't the indent working? | ||||||
|  |         #  => markdown, now solved.. | ||||||
| 
 | 
 | ||||||
|     feed_label = FormatLabel( |     feed_label = FormatLabel( | ||||||
|         fmt_str=msg, |         fmt_str=actor_info_repr, | ||||||
|         # |_ streams: **{symbols}**\n |  | ||||||
|         font=_font.font, |         font=_font.font, | ||||||
|         font_size=_font_small.px_size, |         font_size=_font_small.px_size, | ||||||
|         font_color='default_lightest', |         font_color='default_lightest', | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|  |     # ?TODO, remove this? | ||||||
|     # form.vbox.setAlignment(feed_label, Qt.AlignBottom) |     # form.vbox.setAlignment(feed_label, Qt.AlignBottom) | ||||||
|     # form.vbox.setAlignment(Qt.AlignBottom) |     # form.vbox.setAlignment(Qt.AlignBottom) | ||||||
|     _ = chart.height() - ( |     # _ = chart.height() - ( | ||||||
|         form.height() + |     #     form.height() + | ||||||
|         form.fill_bar.height() |     #     form.fill_bar.height() | ||||||
|         # feed_label.height() |     #     # feed_label.height() | ||||||
|     ) |     # ) | ||||||
| 
 | 
 | ||||||
|     feed_label.format(**feed.status) |     feed_label.format(**feed.status) | ||||||
| 
 |  | ||||||
|     return feed_label |     return feed_label | ||||||
|  |  | ||||||
|  | @ -285,18 +285,20 @@ class FormatLabel(QLabel): | ||||||
|         font_size: int, |         font_size: int, | ||||||
|         font_color: str, |         font_color: str, | ||||||
| 
 | 
 | ||||||
|  |         use_md: bool = True, | ||||||
|  | 
 | ||||||
|         parent=None, |         parent=None, | ||||||
| 
 | 
 | ||||||
|     ) -> None: |     ) -> None: | ||||||
| 
 | 
 | ||||||
|         super().__init__(parent) |         super().__init__(parent) | ||||||
| 
 | 
 | ||||||
|         # by default set the format string verbatim and expect user to |         # by default set the format string verbatim and expect user | ||||||
|         # call ``.format()`` later (presumably they'll notice the |         # to call ``.format()`` later (presumably they'll notice the | ||||||
|         # unformatted content if ``fmt_str`` isn't meant to be |         # unformatted content if ``fmt_str`` isn't meant to be | ||||||
|         # unformatted). |         # unformatted). | ||||||
|         self.fmt_str = fmt_str |         self.fmt_str = fmt_str | ||||||
|         self.setText(fmt_str) |         # self.setText(fmt_str)  # ?TODO, why here? | ||||||
| 
 | 
 | ||||||
|         self.setStyleSheet( |         self.setStyleSheet( | ||||||
|             f"""QLabel {{ |             f"""QLabel {{ | ||||||
|  | @ -306,9 +308,10 @@ class FormatLabel(QLabel): | ||||||
|             """ |             """ | ||||||
|         ) |         ) | ||||||
|         self.setFont(_font.font) |         self.setFont(_font.font) | ||||||
|         self.setTextFormat( |         if use_md: | ||||||
|             Qt.TextFormat.MarkdownText |             self.setTextFormat( | ||||||
|         ) |                 Qt.TextFormat.MarkdownText | ||||||
|  |             ) | ||||||
|         self.setMargin(0) |         self.setMargin(0) | ||||||
| 
 | 
 | ||||||
|         self.setSizePolicy( |         self.setSizePolicy( | ||||||
|  | @ -316,7 +319,10 @@ class FormatLabel(QLabel): | ||||||
|             size_policy.Expanding, |             size_policy.Expanding, | ||||||
|         ) |         ) | ||||||
|         self.setAlignment( |         self.setAlignment( | ||||||
|             Qt.AlignVCenter | Qt.AlignLeft |             Qt.AlignLeft | ||||||
|  |             | | ||||||
|  |             Qt.AlignBottom | ||||||
|  |             # Qt.AlignVCenter | ||||||
|         ) |         ) | ||||||
|         self.setText(self.fmt_str) |         self.setText(self.fmt_str) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue