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
using magicclass and popup boxes #2
Comments
Hi @pr4deepr, I'm happy to hear you enjoy coding with magic-class!
I'm sorry, I need more time to make it work because there would be a lot of options to open the magicgui widget (such as in a napari-like way, in the last position or right below the button as you mentioned). You can suppress popup with option
First, since you want to let fields like class Plot_Menu:
x = field(str)
y = field(str)
hue = field(str)
dodge = field(bool)
def Plot(self): ...
def Histogram(self): ... Every time seaborn's plot function is called, you have to refer to those fields. Since class Analyzer:
...
def _seaborn_plot(self, plot_function):
x = self.Tools.Plot_Menu.x.value or None
y = self.Tools.Plot_Menu.y.value or None
hue = self.Tools.Plot_Menu.hue.value or None
dodge = self.Tools.Plot_Menu.dodge.value
self.canvas.figure.clf()
df = self._current_df()
plot_function(data=df, ax=self.canvas.ax, x=x, y=y, hue=hue, dodge=dodge)
self.canvas.draw()
@Tools.Plot_Menu.wraps
def Box_Plot(self):
"""Show box plot"""
self._seaborn_plot(sns.boxplot) and the main window will look like this |
Hi @hanjinliu I am mainly using this in napari, but I thought I'd try your examples first to get an understanding. Also, another thing I noticed is that the pop up boxes don't dock onto napari. Why is that? Cheers |
Hi @pr4deepr, Yes, I was aware of the bug and it's fixed now. I've also added some popup options in the main branch. Can you clone it and give it a try? Instead of Currently implemented popup modes are: 'first' (top of the widget), 'last' (bottom of the widget), 'dock', 'above' (above the button), 'below' (below the button) and 'parentlast' (bottom of the most parent widget). I hope they'll be helpful. |
Thank you so much. So, when I run the code like this in napari:
I can click Open file from the napari window and it works fine. However, when using the napari plugin system generated by napari cookiecutter, followed by calling this from the napari plugin menu, I get an error: I'm assuming its with how I initialise or define the napari viewer, but I can't figure out where to define this appopriatelY?
Apologies if the questions are too basic. |
I'm not sure what's going on when def Open_File(self, path: Path):
print("Opening", path)
img = io.imread(path)
self.parent_viewer.add_image(img) |
Ok, that works really well. BTW, is there any link to documentation for magic-class? There is so much good stuff in here!! |
I've posted this on imagesc forum to get input from napari developers about accessing the viewer. |
I admit that's a high-priority task, so please wait for a while... It would be great if you'll visit the documentation and send some feedbacks to me.
Thank you very much! The discussion there are also helpful for me. I have not joined imagesc yet, but it seems that I should also sign up! |
Yea, I'd recommend you join imagesc. I think there was a question for you by Talley on the forum: BTW, I am having some more trouble now.
I get this in napari: However, when I move the blur function to be under the
|
Happy to provide feedback on documentation. Let me know if/when you have a link |
The compatibility of @magicclass(widget_type="scrollable")
class test_widget:
@magicclass(widget_type="list", popup_mode="last")
class File_Menu:
def Open_File(self, path:Path): ...
def blur(self,sigma:int): ...
@File_Menu.wraps
def Open_File(self,path:Path):
print("Opening", path)
img=io.imread(path)
self.parent_viewer.add_image(img)
@File_Menu.wraps
@magicgui
def blur(self,img_data:ImageData,sigma:int):
print("Blurring")
blurred_img=gaussian(img_data,sigma)
self.parent_viewer.add_image(blurred_img) If you predefined The predefinition/wraps strategy is needed only when you want to call parent method from its child widget. In your case, you don't have to use this strategy because the
That's great! Thanks for your help and interest in magic-class! |
Thanks. Eventually, I would like to design a sequence of widgets, where:
Is this the right approach? |
Ah yes, in that case you'll have to use |
Hi @hanjinliu
Thanks for this amazing tool. I've been enjoying playing around with it.
I was looking at this example using pandas and seaborn
When clicking each button, a popup window appears.
Instead of a popup window, how can I have the fields appear in the main window (in this case, above the Swarm Plot button)? Also, my aim is that once the user enters the values within the main window and clicks the Swarm Plot button it just plots it using the values without an additional box?
I can see you've used
field
ormagicgui
before, but where do I add that if I was following a similar workflow as your seaborn example?Cheers
Pradeep
The text was updated successfully, but these errors were encountered: