# Compas\_view2 get the button name

**URL:** <https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555>\
**Category:** Uncategorized\
**Created:** [January 26, 2022, 1:21pm UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555 "2022-01-26T13:21:47Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![petrasvestartas](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/petrasvestartas/32/305_2.png) [@petrasvestartas](https://forum.compas-framework.org/u/petrasvestartas)\
**Post date:** [January 26, 2022, 1:21pm UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/1 "2022-01-26T13:21:48Z")

</div>

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”.

```auto
@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:

> <https://github.com/compas-dev/compas_view2/blob/main/scripts/v120_ui_elements.py>

---

<div class="post-metadata">

**Author:** ![petrasvestartas](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/petrasvestartas/32/305_2.png) [@petrasvestartas](https://forum.compas-framework.org/u/petrasvestartas)\
**Post date:** [January 26, 2022, 2:01pm UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/2 "2022-01-26T14:01:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [January 26, 2022, 10:38pm UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/3 "2022-01-26T22:38:43Z")

</div>

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…

```python
@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())

```

---

<div class="post-metadata">

**Author:** ![petrasvestartas](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/petrasvestartas/32/305_2.png) [@petrasvestartas](https://forum.compas-framework.org/u/petrasvestartas)\
**Post date:** [January 27, 2022, 9:48am UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/4 "2022-01-27T09:48:15Z")

</div>

Thank you, did not know about this.

---

<div class="post-metadata">

**Author:** ![petrasvestartas](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/petrasvestartas/32/305_2.png) [@petrasvestartas](https://forum.compas-framework.org/u/petrasvestartas)\
**Post date:** [January 27, 2022, 7:15pm UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/5 "2022-01-27T19:15:05Z")

</div>

Dear @tomvanmele

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.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/compas_framework1/original/1X/5e4332c43e28edac098cc4a4e390526972b3938f.png)

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/compas_framework1/original/1X/7f6675788ea720704c28c6502a9b622d1f32d00f.png)

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [January 31, 2022, 4:38pm UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/6 "2022-01-31T16:38:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![petrasvestartas](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/petrasvestartas/32/305_2.png) [@petrasvestartas](https://forum.compas-framework.org/u/petrasvestartas)\
**Post date:** [January 31, 2022, 6:50pm UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/7 "2022-01-31T18:50:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [January 31, 2022, 8:42pm UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/8 "2022-01-31T20:42:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![petrasvestartas](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/petrasvestartas/32/305_2.png) [@petrasvestartas](https://forum.compas-framework.org/u/petrasvestartas)\
**Post date:** [January 31, 2022, 9:21pm UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/9 "2022-01-31T21:21:36Z")

</div>

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](https://us1.discourse-cdn.com/flex015/uploads/compas_framework1/original/1X/a5861a07cdfdce84accafc5351b75f398ef10dbd.png)

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [February 2, 2022, 9:38pm UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/10 "2022-02-02T21:38:53Z")

</div>

done

 ![Screenshot 2022-02-02 at 22.34.39](https://us1.discourse-cdn.com/flex015/uploads/compas_framework1/original/1X/d277b09ad4f7b9a867aa6fb4185bf35bace112e8.jpeg)

---

<div class="post-metadata">

**Author:** ![petrasvestartas](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/petrasvestartas/32/305_2.png) [@petrasvestartas](https://forum.compas-framework.org/u/petrasvestartas)\
**Post date:** [February 3, 2022, 7:29am UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/11 "2022-02-03T07:29:56Z")

</div>

Thank you,  
I see the updated repository on github.

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [February 3, 2022, 7:35am UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/12 "2022-02-03T07:35:06Z")

</div>

ha yes, sorry.  
it is this example…

> <https://github.com/compas-dev/compas_view2/blob/main/scripts/v120_ui_elements.py>

---

<div class="post-metadata">

**Author:** ![petrasvestartas](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/petrasvestartas/32/305_2.png) [@petrasvestartas](https://forum.compas-framework.org/u/petrasvestartas)\
**Post date:** [February 3, 2022, 7:49am UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/13 "2022-02-03T07:49:48Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [February 3, 2022, 8:11am UTC](https://forum.compas-framework.org/t/compas-view2-get-the-button-name/555/14 "2022-02-03T08:11:52Z")

</div>

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](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…

```bash
conda install qtpy
pip install git+ ... compas_view2
pip install git+ ... compas

```
