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

Add a widget for settings like Camera that can be saved with names #294

Merged
merged 9 commits into from
Apr 29, 2024

Conversation

mwcraig
Copy link
Contributor

@mwcraig mwcraig commented Apr 26, 2024

This PR has a few things:

  1. Adds a couple of custom widgets to support saving settings like camera that have names.
  2. Tests for those widgets.
  3. A notebook to use for testing out the widget, integrated into the jupyterlab launcher.

In addition to the code review please try going through the notebook. Once you have done a pip install -e . with this branch in your environment, you should see the button in the launcher:

JupyterLab

@JuanCab -- if you could review by early next week that would be great.

@codecov-commenter
Copy link

codecov-commenter commented Apr 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.70%. Comparing base (f927559) to head (f960057).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #294      +/-   ##
==========================================
+ Coverage   71.86%   73.70%   +1.83%     
==========================================
  Files          26       27       +1     
  Lines        3220     3388     +168     
==========================================
+ Hits         2314     2497     +183     
+ Misses        906      891      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mwcraig mwcraig force-pushed the add-jup-app-launcher branch 2 times, most recently from 8e220c0 to af067b8 Compare April 27, 2024 16:16
@mwcraig
Copy link
Contributor Author

mwcraig commented Apr 27, 2024

@JuanCab -- it may be easiest to review these changes in commit order now. The first few commits are small, and made to lay the groundwork for the new custom widgets.

The commit to add the custom widget and the commit to add its tests are pretty chunky...

@mwcraig
Copy link
Contributor Author

mwcraig commented Apr 27, 2024

Instructions for student testers

  1. make a new environment, for example: mamba create -n test-294 python=3.11 astroscrappy
  2. activate the new environment: mamba activate test-294
  3. install the version of stellarphot in this PR: pip install git+https://github.com/mwcraig/stellarphot.git@add-jup-app-launcher
  4. Start jupyter lab: jupyter lab
  5. Open the testing notebook in the "Stellarphot" section of the launcher
  6. Email feedback to @mwcraig or open a new issue in this repo with your feedback.
  7. Once you quit jupyter lab, deactivate the environment: mamba deactivate
  8. Delete the test environment: mamba remove --all --yes test-294

@mwcraig
Copy link
Contributor Author

mwcraig commented Apr 27, 2024

A few things that @Tanner728 found:

  • You can type stuff in nullable fields (e.g. AAVSO code for observatory) even if the "switch" is off if you have hit the "Edit" button
  • "Edit" button appears if there are no items in a group (e.g. no observatories) and it shouldn't.
  • Might be possible to enter an invalid name (e.g. trailing space) in the form.
  • The edit button doesn't appear after making a new item.

There were a couple other things I'm opening issues for.

@mwcraig mwcraig changed the title Add a widget for settings linke Camera that can be saved with names Add a widget for settings like Camera that can be saved with names Apr 27, 2024
Copy link
Contributor

@JuanCab JuanCab left a comment

Choose a reason for hiding this comment

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

Changes for deleting items code makes sense AND the tests seem to cover all the possibilities I can think of.

Copy link
Contributor

@JuanCab JuanCab left a comment

Choose a reason for hiding this comment

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

See notes about the documentation, the actual code seems sound.

stellarphot/settings/models.py Show resolved Hide resolved
@JuanCab
Copy link
Contributor

JuanCab commented Apr 28, 2024

@JuanCab -- it may be easiest to review these changes in commit order now. The first few commits are small, and made to lay the groundwork for the new custom widgets.

The commit to add the custom widget and the commit to add its tests are pretty chunky...

I didn't know I could go commit by commit, doing that now. It is easier!

Copy link
Contributor

@JuanCab JuanCab left a comment

Choose a reason for hiding this comment

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

Documentation tweaks requested... looks like a very challenging customization, you did a lot here!

Name of the item type to be displayed in the widget. Must be one of
"camera", "observatory", "passband_map", "Camera", "Observatory"
or "PassbandMap".
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Documentation is missing the keyword _testing_path... is that meant to eventually go away?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure how to handle this...the intent is that users don't use it, it is just there for testing. I could hide it more, I suppose, by putting it into **kwargs and popping it from there. That way it wouldn't show up in code completion.

Copy link
Contributor

@JuanCab JuanCab Apr 28, 2024

Choose a reason for hiding this comment

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

I suppose parameters can't be flagged as private (correction, private doesn't exist really in Python, I was thinking of name mangling via double underscore, but that won't help here). But it makes sense that it is for testing purposes.

# but does no harm in the other cases (true of both lines below)
# (and yes, both lines below are needed...this is a bug in ipyautoui,
# I think, because open_nested=True isn't respected when we _init_ui.
# Forcing a *change* in the value triggers the behavior we want.)
Copy link
Contributor

Choose a reason for hiding this comment

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

Cute fix for the bug.

# but does no harm in the other cases (true of both lines below)
# (and yes, both lines below are needed...this is a bug in ipyautoui,
# I think, because open_nested=True isn't respected when we _init_ui.
# Forcing a *change* in the value triggers the behavior we want.)
Copy link
Contributor

Choose a reason for hiding this comment

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

Given you have the same comment and fix twice, makes me wonder if you should just create a function called _jiggle_open_nested_for_ipyautoui. :)


# Use a closure here to capture the current state of the widget
def save_confirm_handler(change):
# value of None means the widget has been reset to not answered
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to clarify this is that the "confirmation" has not been addressed or the "confirmation widget" has been reset to behave as if not answered? I was confused by this at first and only realized what you meant by reading the behavior below. Better yet, maybe place a comment in the function 'docstring' above explaining what the desired behavior is as a whole.

Copy link
Contributor

@JuanCab JuanCab left a comment

Choose a reason for hiding this comment

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

Looks good, I didn't know how you could check UI features, now I know. Made sense, although I had to concentrate at a few points to follow it.

'ignore:Using extra keyword arguments on `Field` is deprecated:'
'ignore:Using extra keyword arguments on `Field` is deprecated:',
# ipywidgets is using something deprecated in traitlets
'ignore:Deprecated in traitlets 4.1, use the instance:DeprecationWarning',
Copy link
Contributor

Choose a reason for hiding this comment

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

So we have to wait for an ipywidgets update to address this...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah

JuanCab
JuanCab previously approved these changes Apr 28, 2024
Copy link
Contributor

@JuanCab JuanCab left a comment

Choose a reason for hiding this comment

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

I tweaked my stellardev.yml file for the stellarphot development environment to include the Jupyter app launcher.

@JuanCab
Copy link
Contributor

JuanCab commented Apr 28, 2024

All looks good code wise, I had a few documentation issues, but they were minor. I did also try out the notebooks, using the instructions to students above (after editing them to replace a test-394 with test-294).

For the camera, it keeps displaying "(red X) Invalid" at the top, same with Passband Map (but not Observatory). I can't set a Camera name, which may be the problem.... it's greyed out. The Passband Map name is not filled out but I can't seem to get it to be editable. Rebuilt the widget from scratch by re-running the cell that has widgets = [ChooseOrMakeNew(item) for item in to_make] tp create the widgets.. then understood a few issues.

Some testing reveals if I forget to fill out the Bandpass Map NAME before trying to actually add a mapping, the Name becomes uneditable, which condemns me to an invalid Bandpass Map.

For the Camera, I was not able to replicate the problem in some limited testing, the second time, choosing the values that were default did work.

@JuanCab
Copy link
Contributor

JuanCab commented Apr 28, 2024

I do not get the sparkly waffle icon BTW, I just get this:
CleanShot 2024-04-28 at 14 21 10@2x

@mwcraig
Copy link
Contributor Author

mwcraig commented Apr 29, 2024

I'm going merge this -- I addressed the documentation comments, I think, and have opened issues for the rest.

@mwcraig mwcraig merged commit a111b68 into feder-observatory:main Apr 29, 2024
9 checks passed
@mwcraig mwcraig deleted the add-jup-app-launcher branch April 29, 2024 15:38
@mwcraig mwcraig restored the add-jup-app-launcher branch April 29, 2024 15:38
@mwcraig mwcraig deleted the add-jup-app-launcher branch May 5, 2024 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants