Skip to content

Remove .views & .color states, fix gradZ 3D GUI display#1432

Open
mrariden wants to merge 15 commits intomainfrom
gradz_fix
Open

Remove .views & .color states, fix gradZ 3D GUI display#1432
mrariden wants to merge 15 commits intomainfrom
gradz_fix

Conversation

@mrariden
Copy link
Copy Markdown
Collaborator

@mrariden mrariden commented Apr 9, 2026

Moved the main gui's .view and .color attributes to a stateless property that just looks at the actual drop down state. Setting the attribute/property is backwards compatible to use indexes or strings for convenience.

Also, using more intuitive variables for the update_plot function.

Also, removed duplicated code from 3d GUI keyPressEvent that is now delegated to MainW class.

Fix gradZ displaying in 3d GUI.

  • GUI testing protocol
  • passing CI tests

@mrariden mrariden requested a review from carsen-stringer April 9, 2026 22:29
@mrariden
Copy link
Copy Markdown
Collaborator Author

mrariden commented Apr 13, 2026

Tests passing on

  • Mac
  • Ubuntu

GUI manual testing:

Image loading

  • Drop image into GUI
  • Load from menu
  • Right/left arrow keys to load next image in folder

Network

  • 'run CPSAM' button works
  • Adjusting parameters & hit return to re-run dynamics
    • Diameter
    • Flow threshold
    • cell probability threshold
    • normalization percentiles
    • niter dynamics
  • User models work

GUI: display

  • Image colors work with drop down and arrow key up/down
  • Display data cycles through flows/cellprob/image/restored with drop down and pg up/down
  • Auto adjust saturation checkbox and sliders work

GUI: mouse/ROIs

  • Right click and draw cell
  • Command/ctrl and click to delete cell
  • Left click and drag to pan
  • Scroll to zoom
  • Number of ROIs updates correctly when add/delete cell
  • Masks/outline can be turned on/off with checkbox and (Z & X)
  • Delete multiple ROIs using region selection works

GUI: menus

  • All File > saving functions work
  • All Edit > functions work
  • Models >
    • Add model and remove model works
    • Train new model, adjusting training params/name works
  • Help menu items appear when clicked

Filtering

  • Sharpen and smooth radius appear correct and make a 'restored' viewer image
  • tile_norm blocksize normalizes images per block
  • Smoothing in 3D works

@mrariden
Copy link
Copy Markdown
Collaborator Author

Verified that update_plot() isn't called too frequently, only 1 or 2 times depending on the data update.

@mrariden mrariden changed the title Remove .views state, fix gradZ 3D GUI display Remove .views & .color states, fix gradZ 3D GUI display Apr 13, 2026
@mrariden
Copy link
Copy Markdown
Collaborator Author

Verified that update plot is only called once per interaction 👍

Good to merge

Comment thread cellpose/gui/gui.py
Comment on lines -331 to -332
self.view = 0 # 0=image, 1=flowsXY, 2=flowsZ, 3=cellprob
self.color = 0 # 0=RGB, 1=gray, 2=R, 3=G, 4=B
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removes the .view and .color state so we only reference the checkbox state. This way we can use qt signals from the checkbox easily

Comment thread cellpose/gui/gui.py
Comment on lines 335 to +344
self.RGBDropDown.addItems(
["RGB", "red=R", "green=G", "blue=B", "gray", "spectral"])
self.RGBDropDown.name_map = {
"rgb" : "rgb",
"red" : "red=r",
"green" : "green=g",
"blue" : "blue=b",
"gray" : "gray",
"spectral": "spectral",
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

convience maps to get the correct drop down setting. These can be extended

Comment thread cellpose/gui/gui.py
@@ -662,62 +673,75 @@ def level_change(self, r):
self.update_plot()

def keyPressEvent(self, event):
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

modified this method to use qt events and event propagation instead of updated flag

Comment thread cellpose/gui/gui.py
Comment on lines -731 to -732
if not updated:
self.update_plot()
Copy link
Copy Markdown
Collaborator Author

@mrariden mrariden Apr 15, 2026

Choose a reason for hiding this comment

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

removed unnecessary update. use the event accepted flag instead

Comment thread cellpose/gui/gui.py
Comment on lines -792 to -793

self.update_plot()
Copy link
Copy Markdown
Collaborator Author

@mrariden mrariden Apr 15, 2026

Choose a reason for hiding this comment

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

removed unnecessary update. only really matters at startup

Comment thread cellpose/gui/gui.py
self.draw_layer()
self.update_layer()
if self.loaded:
self.update_plot()
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed unnecessary update. Toggling the checkbox is wired to update_plot via a signal

Comment thread cellpose/gui/gui.py
Comment on lines +1115 to +1117
self.enable_restored_view(False)
if self.view == 'restored':
self.view = 'image'
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

a good example of the gained clarity when using the new properties

Comment thread cellpose/gui/gui.py
Comment on lines -1400 to -1403
self.sliders[r].setValue([
self.saturation[r][self.currentZ][0],
self.saturation[r][self.currentZ][1]
])
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

the sliders were wired to fire a signal that connected to update_plot() previously. Now, this signal is blocked

Comment thread cellpose/gui/gui.py
print("GUI_INFO: resizing flows to original image size")
for j in range(len(flows_new)):
flow0 = flows_new[j]
for flows0 in flows_new:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

just a simplification/clarification

Comment thread cellpose/gui/gui.py
Comment on lines +2121 to +2144

def go_next_previous_dropdown(self, dropdown, increment=1):
""" Go to the next dropdown element using `increment` """

# skip disabled views
num_items = dropdown.count()
enabled = []
for i in range(num_items):
enabled.append(dropdown.model().item(i).isEnabled())

if not any(enabled):
self.logger.error('No available dropdown items are enabled. Cannot adjust view.')
return

idx = dropdown.currentIndex() + increment

for _ in range(num_items):
idx %= num_items
if enabled[idx]:
dropdown.setCurrentIndex(idx)
return
idx += increment

self.logger.error('Could not find an emabled dropdown item.') No newline at end of file
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

allows indexing a dropdown by increment and skips disabled items

is used for RGB and views dropdowns

Comment thread cellpose/gui/gui3d.py
Comment on lines 624 to +631
if event.key() == QtCore.Qt.Key_Minus or event.key() == QtCore.Qt.Key_Equal:
self.p0.keyPressEvent(event)
event.accept()
return

# propagate unhandled events to MainW
if not event.isAccepted():
super().keyPressEvent(event)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

deduplicated key press logic in gui3d so 2d gui takes care of it

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.

1 participant