Skip to content

PlotItem.autoBtnClicked to emit PlotItem.sigRangeChangedManually#3049

Merged
j9ac9k merged 4 commits intopyqtgraph:masterfrom
tikuma-lsuhsc:add-PlotItem-autoBtnClicked-emit-sigRangeChangedManually
Oct 13, 2024
Merged

PlotItem.autoBtnClicked to emit PlotItem.sigRangeChangedManually#3049
j9ac9k merged 4 commits intopyqtgraph:masterfrom
tikuma-lsuhsc:add-PlotItem-autoBtnClicked-emit-sigRangeChangedManually

Conversation

@tikuma-lsuhsc
Copy link
Copy Markdown
Contributor

As all the mouse interactions in ViewBox emits ViewBox.sigRangeChangedManually, it seems logical for pressing the "auto" button on PlotItem to also emit this signal.

@tikuma-lsuhsc
Copy link
Copy Markdown
Contributor Author

tikuma-lsuhsc commented Jun 6, 2024

Here is a script to test the added feature.

import numpy as np
from PyQt6.QtCore import pyqtSlot
import pyqtgraph as pg

app = pg.mkQApp("Plotting Example")
win = pg.GraphicsLayoutWidget(show=True, title="Basic plotting examples")
p1 = win.addPlot(y=np.random.normal(size=100))
p1.vb.setMouseEnabled(True, True)

@pyqtSlot(object)
def rangeChangedManually(mask):
    print(f'sigRangeChangedManually emitted ({mask})')

p1.sigRangeChangedManually.connect(rangeChangedManually)

if __name__ == "__main__":
    pg.exec()

edited 7/3: updated the signal connection to the PlotItem instead of ViewBox

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jul 2, 2024

Hi @tikuma-lsuhsc

Thanks for the PR, sorry for the long wait to reply, I recently had a large move.

My first question is why emit the signal inside the PlotItem instance, but not have it emitted as part of ViewBox.enableAutoRange instead?

@tikuma-lsuhsc
Copy link
Copy Markdown
Contributor Author

@j9ac9k - I'm glad you got around to my PRs. Thanks for reviewing them.

why emit the signal inside the PlotItem instance, but not have it emitted as part of ViewBox.enableAutoRange instead

Because it was the path of the least resistance although I agree with you on its awkwardness. I didn't think it would be appropriate for ViewBox.enableAutoRange to emit the sigRangeChangedManually signal as the signal name suggests that it ought to be triggered by user (UI). Its emission by enableAutoRange introduces a potential emission by a non-user command (at least not directly). For example, I can see myself using enableAutoRange to reset the view when I load a new data. (There was a specific reason I needed this signal emitted in my app, but it has escaped me at the moment.)

Hope this makes sense. I'm 100% open to your suggestions/decisions and will be happy to modify the PR accordingly.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jul 3, 2024

Actually you can chain signals together so we can just tie this signal to the signal that is emitted when the button is pressed. I'm on mobile right now so I can't look it up but maybe that signal makes more sense there?

@tikuma-lsuhsc tikuma-lsuhsc force-pushed the add-PlotItem-autoBtnClicked-emit-sigRangeChangedManually branch from 2d783b1 to a4f54ec Compare July 3, 2024 14:17
- chained to ViewBox.sigRangeChangedManually
changed to emit this signal instead of the viewbox one
@tikuma-lsuhsc
Copy link
Copy Markdown
Contributor Author

Yes, I was thinking that just after I posted last night. I checked PlotItem this morning and indeed, you're already chaining the other range-related signals. I've added sigRangeChangedManually to it and switched to it. I've updated the example in the second comment above.

@tikuma-lsuhsc tikuma-lsuhsc changed the title PlotItem.autoBtnClicked to emit ViewBox.sigRangeChangedManually PlotItem.autoBtnClicked to emit PlotItem.sigRangeChangedManually Jul 15, 2024
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 13, 2024

Sorry for the long wait on merging this @tikuma-lsuhsc

This PR LGTM, merging. Thanks for the contribution to the library!

@j9ac9k j9ac9k merged commit 5c8ecb5 into pyqtgraph:master Oct 13, 2024
j9ac9k pushed a commit to j9ac9k/pyqtgraph that referenced this pull request Mar 25, 2025
…tgraph#3049)

* PlotItem.autoBtnClicked changes range via user interface - emit ViewBox.sigRangeChangedManually

* fixed error

* added PlotItem.sigRangeChangedManually
- chained to ViewBox.sigRangeChangedManually
changed to emit this signal instead of the viewbox one

* updated doc

---------

Co-authored-by: Takeshi Ikuma <tikuma@gmail.com>
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.

3 participants