PlotPyStack / PlotPy

Curve and image plotting tools for Python/Qt applications
BSD 3-Clause "New" or "Revised" License
28 stars 2 forks source link

register_all_curve_tools duplicate menu #14

Closed ivan2033 closed 4 months ago

ivan2033 commented 4 months ago

Hi,

I was using guiqwt and now I am moving to plotpy. I have an issue related to the curvewidget menu because it duplicates the right botton menu. It did not happen to me before with guiqwt.

I am doing the following call: curvewidget.manager.register_all_curve_tools()

Is there a way to "clean" the menu before adding the curves? Why does it happen now?

Kind regards, Iván

plotpy_duplicate_issue

PierreRaybaut commented 4 months ago

Hi,

Thanks for taking the time to submit this Issue.

I am doing the following call: curvewidget.manager.register_all_curve_tools()

In PlotPy, curve widgets and image widgets have been merged in a unique class handling plots (PlotWidget). This class may be specialized to handle curves or images by passing the type argument:

# Using the builder:
from plotpy.builder import make
plot_widget = make.widget(wintitle="Title", type="curve")

# Using the class, if you need to customize it:
from plotpy.plot import PlotWidget, PlotOptions
plot_widget = PlotWidget(options=PlotOptions(title="Example", type="image"))

So basically, you shouldn't have to call directly register_all_curve_tools because it is called automatically by PlotWidget when "curve" has been chosen as a type of plot.

Does it help?

ivan2033 commented 4 months ago

Thank you for answering so fast.

I have an UI made in QtDesigner for creating the plot (it should not mather, I just have changed the automa

tic code for adding the new parameters). If I have understand you well now I do the following when creating the plot:

self.curvewidgetAnalog = PlotWidget(parent=self.splitter, options=PlotOptions(title="Analog", type="curve"))

I can see the title (so the changes are applied), but the tools are still not created in the toolbar if I do not call the function I mentioned before. The ones that are shown are some specific created by myself.

plotpy_duplicate_issue_2

PierreRaybaut commented 4 months ago

Ok, maybe you are customizing the widget's toolbar after creating it.

In that case, you may do the folllowing (add the auto_tools=False option, then called later register_tools):

self.curvewidgetAnalog = PlotWidget(parent=self.splitter, options=PlotOptions(title="Analog", type="curve"), auto_tools=False)
# [...] your code [...]
self.curvewidgetAnalog.register_tools()
ivan2033 commented 4 months ago

Yes! That solves the problem, now it just appears once.

Thank you very much for your help and congratulations for your work!

PierreRaybaut commented 4 months ago

Glad that it solved your issue. All the best!