Compas_view2 get the button name

Hi,

This is a question related to compas_view2 method.
Is there any possibility to print the name of a currently clicked button in the compas_view2 method?
In the click method I would like to print this property: text=“Reset”.

@viewer.button(text="Reset")
def click():
    if viewer.confirm('This will reset the point to parameter t=0.'):
        pointobj._data = curve.point(0)
        pointobj.update()
        slide.value = 0
        viewer.view.update()

I am using this example:

Found a solution,

If I pass two variables in the click function I get what I want e.g. click(number0 = i, number1 = 1).
If I just pass one variable click(number0 = i,). this will always return boolean false.

the button decorator basically replaces the function by a UI object.
so, in this case, you can just do click.button.text() to get the text value of the button…

@viewer.button(text="Reset")
def click():
    if viewer.confirm('This will reset the point to parameter t=0.'):
        pointobj._data = curve.point(0)
        pointobj.update()
        slide.value = 0
        viewer.view.update()
        print(click.button.text())
1 Like

Thank you, did not know about this.

Dear @brgcode

I created a little bit more buttons than the viewer panel can store by default.
In this situation it is possible to expand the panel by hovering with the mouse on the bottom.

Is there any way to see all buttons at once without automatic collapsing?
Because once I move my mouse outside the panel collapse back again.

Instead of this I would like always to see the full interface with all buttons:

perhaps having so many buttons is not really the way to go about this. what is it that these buttons are supposed to do?

I also thought the same.
But I have a case when I am developing the library. And at one moment I need to test more than 40 data-sets, including bad user inputs, to know if it crashes and where are possible mistakes. So I test them all one by one via viewer.

sure, but this could still be some kind of selection menu with all possible options and a “load” button for the selected option, or something like that, no?

That would be great.

In the examples I see that there are radio buttons and slider. Is there any other options for a list selection ? What I mean is list selection:
examples_01~2

done

1 Like

Thank you,
I see the updated repository on github.

ha yes, sorry.
it is this example…

1 Like

Thank you.
For dev updates, which I imagine this is not on conda yet, is it enough to pip install like this in a current environment to update the current package?

pip install git+https://github.com/compas-dev/compas_view2.git#egg=compas_view2

in general, easiest is to install from conda in some environment to get all the dependencies right and then indeed do a pip install from local source or directly from github to get the latest stuff.

that said though, we are in the process of switching to qtpy (https://github.com/spyder-ide/qtpy) to maximize compatibility with multiple backends, and parts of the dev version of compas_view2 use unreleased components of compas. so you have to install qtpy in your environment and the latest dev version of compas. so with your env activated…

conda install qtpy
pip install git+ ... compas_view2
pip install git+ ... compas
1 Like