Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: add snapshot view / compare / restore page (only view functional) #94

Merged
merged 18 commits into from
Nov 8, 2024

Conversation

shilorigins
Copy link
Collaborator

@shilorigins shilorigins commented Oct 15, 2024

Description

Add restore page template and logic
Add ability to open restore page from root tree QTreeView
Increase default size of the main window
Fix bug where closing a LivePVTableModel sometimes causes an error trying to access deleted data

Motivation and Context

This page can currently show all leaf Entrys in a snapshot and can compare stored values to live values. The same page is intended to be able to compare values from two snapshots and to restore saved values, but both of those capabilities are postponed for later PRs.

The AD control system has a convention where middle clicking on a UI element shows the underlying PV and copies it to the clipboard, so I added middle-click-to-copy as a partial implementation and convenience feature. We can fill out the PV-display-and-copy later if desired.

Double-clicking an entry on the tree view opens the entry page and no longer expands the tree item because I found that use case intuitive, and items can still be expanded by clicking on the items' arrows. Happy to alter this functionality if doing so would be more usable.
Since the Snapshot entry page is now associated with the tree view's double-click, I added an action to open the restore page to the tree view's context menu.

I increased the size of the main window to better show the data-dense tables without having to manually expand the window every time. I didn't optimize the new size, but it works well enough on my dev monitor and laptop.

How Has This Been Tested?

Interactively.

Where Has This Been Documented?

Screenshots:

Page when a snapshot is opened:
Screenshot 2024-10-23 at 15 56 24

Page when Compare to Live button is clicked:
Screenshot 2024-10-23 at 15 56 36

Pre-merge checklist

  • Code works interactively
  • Code follows the style guide
  • Code contains descriptive docstrings, including context and API
  • New/changed functions and methods are covered in the test suite where possible
  • Test suite passes locally
  • Test suite passes on GitHub Actions
  • Ran docs/pre-release-notes.sh and created a pre-release documentation page
  • Pre-release docs include context, functional descriptions, and contributors as appropriate

@shilorigins shilorigins self-assigned this Oct 15, 2024
@shilorigins shilorigins added this to the Minimum Viable Product milestone Oct 15, 2024
@shilorigins shilorigins added enhancement New feature or request GUI Graphical User Interface related issue Core Client Core functionality (Python Client) related issues labels Oct 15, 2024
@shilorigins shilorigins marked this pull request as ready for review October 23, 2024 22:51
@tangkong
Copy link
Contributor

I grabbed the changes and they look pretty good. No major bugs, though there are a limited number of interaction points thus far. From interactive testing:

  • the open button is not wired, since there was no open_page_slot provided. If the intent is for this to not be supported, we should also hide the open column

I'll go through the code in a bit more detail now

@shilorigins
Copy link
Collaborator Author

I was just adding some (any) tests before requesting review. Is there a setpoint / readback page to connect to open_page_slot yet?

superscore/widgets/page/restore.py Outdated Show resolved Hide resolved
superscore/widgets/page/restore.py Outdated Show resolved Hide resolved
superscore/widgets/page/restore.py Outdated Show resolved Hide resolved
superscore/widgets/page/restore.py Outdated Show resolved Hide resolved
superscore/widgets/page/restore.py Outdated Show resolved Hide resolved
superscore/widgets/views.py Show resolved Hide resolved
superscore/widgets/window.py Outdated Show resolved Hide resolved
superscore/widgets/window.py Outdated Show resolved Hide resolved
@tangkong
Copy link
Contributor

I was just adding some (any) tests before requesting review. Is there a setpoint / readback page to connect to open_page_slot yet?

whoops sorry I jumped the gun a bit. I have pages in #95, and have been adding tests there as well (though I haven't managed to finish and push them yet 💀 )

@shilorigins shilorigins force-pushed the devagr/restore-page branch 3 times, most recently from 5bc6afe to f871071 Compare October 24, 2024 22:45
The existing code would occassionally cause this error when closing
a tab containing a LivePVTableModel:

Traceback (most recent call last):
  File "/afs/slac.stanford.edu/u/cd/devagr/src/superscore/superscore/widgets/views.py", line 1021, in run
    self._update_data(pv_name)
  File "/afs/slac.stanford.edu/u/cd/devagr/src/superscore/superscore/widgets/views.py", line 1008, in _update_data
    if not isinstance(val, Exception) and self.data[pv_name] != val:
KeyError: 'VAC:GUNB:TEST1'

This error appears to be caused by LivePVTableModel.stop_polling
clearing _PVPollThread's data before calling its stop method, causing
the thread to be able to run for another cycle and try to access its
now-empty data. Calling stop() and then waiting before clearing the
data seems to prevent the error.
@shilorigins
Copy link
Collaborator Author

Since a branch merged into master replaced the default Snapshot page, I added a context menu action to open the restore page. We can link the pages better in the future, but I think we should discuss the intended page flow first.

@shilorigins shilorigins requested a review from tangkong November 6, 2024 19:34
@shilorigins shilorigins changed the title ENH: add snapshot view / compare / restore page ENH: add snapshot view / compare / restore page (only view functional) Nov 6, 2024
Copy link
Contributor

@tangkong tangkong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks pretty great code-wise, you've come up to speed on qt pretty quickly I think!

I'm holding off on approving until I can take it for a spin. I'm hoping to get to that tomorrow

@@ -10,6 +10,9 @@
from superscore.client import Client
from superscore.widgets.window import Window

DEFAULT_WIDTH = 1400
DEFAULT_HEIGHT = 800
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I'm always wary of setting raw defaults for things like sizes, since peoples' display setups vary so much. There's probably a way to set this relative to a user's total screen real estate 🤔 .

I also won't argue that superscore needs more space than qt was originally providing it. So I don't object strongly to this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I don't know how to manage screen details without researching it a bit. Like how your setup reports one combined screen while mine reports two screens. I suppose we could do percent of primary screen with a maximum absolute size?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, there's a few ideas but we can address these in more detail later

@@ -311,6 +311,8 @@ def linac_data():
pv_name=lasr_gunb_pv1.pv_name,
description=lasr_gunb_pv1.description,
data="Off",
status=Status.NO_ALARM,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A shame you had to specify all these, but I do think our defaults still make sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I couldn't come up with a nice way to generate test snapshots without taking too much time thinking about it, but we might want to revisit if we need to generate more. The best idea I had was mocking uuid4() and ControlLayer.get with consistent, pre-selected data and then using Client.snap.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related but not directly applicable: I think if we can set up some way of selecting a client/backend-data combination using our fixtures, that would be ideal. We already have a variety of datasets, but our sample_client only used the filestore json.

You could also take a snapshot of your controls system and save it in a filestore-backend, then we could add that as a backend to test with?

superscore/tests/test_page.py Outdated Show resolved Hide resolved
superscore/widgets/page/restore.py Show resolved Hide resolved
superscore/widgets/page/restore.py Outdated Show resolved Hide resolved
superscore/widgets/page/restore.py Show resolved Hide resolved
The existing code to resize and recenter the main window
had a bug where multiple monitors were apparently being
reported as one large screen, causing the window to appear
in between two monitors.  This commit centers the window
on the primary screen specifically.
Copy link
Contributor

@tangkong tangkong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I took this for a quick spin and things worked as advertised. The only additional thing I noticed was the context menu option that opened the restore page was named "inspect", but we need to clear up the page flow anyway

@shilorigins shilorigins merged commit 35c3a36 into pcdshub:master Nov 8, 2024
11 checks passed
@shilorigins shilorigins deleted the devagr/restore-page branch November 8, 2024 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Client Core functionality (Python Client) related issues enhancement New feature or request GUI Graphical User Interface related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants