This tutorial is designed as a "flipped classroom" where completion of the prerequisites is required before the lab. The exercises are designed to be completed with active in-person guidance, but there will not be time to set up individual environments or go fully in depth on underlying concepts. 

Prerequisites

  1. Join #srf_pydm_tutorial on Slack for any questions about the setup or exercises
  2. Complete a Local PyDM/Simulacrum Setup
  3. Run through the GitHub quick start tutorial
  4. Run through the GitHub tutorial on contributing to projects
    1. Note that I recommend using the ssh approach as it leverages what we did in step 2
  5. Read through the Microsoft OOP training and really try to get a conceptual handle on objects
  6. Read through the description of Qt signals and slots
  7. Join the slaclab tutorial team
  8. Download and install PyCharm. 
    1. Other IDEs are available, but we will be leveraging PyCharm specific features such as refactoring on save
  9. Fork the tutorial repository and clone it to your machine (see step 3)
    1. navigate to the solutions subdirectory and follow the instructions in solutions.txt


Unless otherwise specified, everything hereafter will be done in the PyDM conda environment set up in prerequisites step 2

Simple GUI

Explore

  1. Navigate to the simple subdirectory in your personal subdirectory and run pydm simple.py. This will launch a simple GUI:
  2. Play with it. Note that the "selected options" output doesn't change until you click the "update status" button. It's meant to reflect the state of the checkboxes at the point the button is pressed
  3. Launch designer and open simple.ui
    1. Note the Object Names in the Object Inspector:
      1. The checkboxes, push button, and output label all have custom names that reflect what they are (the standard names are typically not helpful and make connecting to them in python much harder)
    2. Note the different layouts; they allow for window resizing and snapping to grid
      1. Window resizing happens by right clicking the background of your widget and clicking Lay out to select the kind you want
    3. Note that we changed the window title in the Property Editor
  4. Open the tutorial repo with PyCharm and navigate to simple.py. Read through it and try to understand how the connections are happening (clicking through the provided links as necessary)

Exercises

Layouts in Designer

  1. Create and checkout a new branch called layouts 
  2. Right click the background of the widget and select Lay out > Break Layout
  3. Notice that the GUI will no longer resize or snap to grid; try to get it back to where it was
  4. Run git status and observe your changes
  5. Git add, git commit, and git push your changes to your fork

Renaming Widgets in Designer

  1. Create and checkout a new branch called rename_widgets
  2. Rename a widget in designer without changing the python file
  3. Note the error message and try to edit the python file to make it work again
  4. Run git status and observe your changes
  5. Git add, git commit, and git push your changes to your fork

Introducing New Functionality

  1. Create and checkout a new branch called auto_update
  2. Disable or delete the button in designer
  3. Use signals and slots to make the status label update whenever either of the checkboxes is toggled
  4. Run git status and observe your changes
  5. Git add, git commit, and git push your changes to your fork

PV Readout

This section will need the simulacrum sc_rf_service running. Please refer to prerequisites step 2

Here you've been provide the skeleton of a non-resizing GUI whose purpose is to take a PV string and connect a readout to it. If you run pydm pv_readout.py as is, it will launch an example GUI that has a spin box for CM01 cavity 1's ADES.

  1. Navigate to the pv_readout directory in your personal subdirectory and open pv_readout.ui in designer and pv_readout.py in PyCharm
  2. Make the widget resizable and make it so that the elements are aligned nicely horizontally
  3. Rename the widgets to have helpful names
  4. Edit the python file so that it uses pv_readout.ui
  5. Connect the returnPressed signal from the line edit to a custom slot that updates the pydm label's channel to the line edit's text 
  6. Git add, git commit, and git push your changes to your fork

Merging into production

Once all your work is complete and pushed to your fork, navigate to your fork's page on GitHub and open a pull request. Please request the slaclab/srf_tutorial team as a reviewer and await feedback.