# Segment Editor: reduce the number of mouse clicks to set basic colour for segment

**URL:** https://discourse.slicer.org/t/segment-editor-reduce-the-number-of-mouse-clicks-to-set-basic-colour-for-segment/20236
**Category:** Feature requests
**Tags:** segmentation, color, gui
**Created:** [October 19, 2021, 11:50am UTC](https://discourse.slicer.org/t/segment-editor-reduce-the-number-of-mouse-clicks-to-set-basic-colour-for-segment/20236 "2021-10-19T11:50:54Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![DIV](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/div/32/12816_2.png) [@DIV](https://discourse.slicer.org/u/DIV)
#### Post date: [October 19, 2021, 11:50am UTC](https://discourse.slicer.org/t/segment-editor-reduce-the-number-of-mouse-clicks-to-set-basic-colour-for-segment/20236/1 "2021-10-19T11:50:54Z")

</div>

If I wish to set a Basic Color for a segment I need _seven_ mouse clicks (or _six_ operations):

- double-click the relevant swatch for **Segment color** ;
- click **Color** in the (badly named) _Slicer_ dialogue box;
- click **Basic** tab in the _Select Color_ dialogue box;
- click a swatch under **Basic colors** ;
- click **OK** in the _Select Color_ dialogue box;
- click **Select** in the _Slicer_ dialogue box.  
That is too many mouse clicks for a basic operation that I regularly perform.

I often have multiple segments representing the same category of anatomy (e.g. multiple bones; or multiple arteries). I don’t want them all to be the same colour, because I want to able to distinguish them at a glance.

The best suggestion I have off the top of my head is to integrate the current _two_ dialogue boxes identified above into a unified dialogue box with three tabs. The first tab would contain the content of the current (badly named) _Slicer_ dialogue box, and could perhaps be named **Properties** ; the remaining two tabs would be identical to the existing **Basic** and **Labels** tabs in the _Select Color_ dialogue box.

If I wish to set a Basic Color for a segment the new workflow would then be:

- double-click the relevant swatch for **Segment color** ;
- click **Basic** tab in the new (unified) dialogue box;
- click a swatch under **Basic colors** ;
- click **OK** in the new (unified) dialogue box.  
I would thus need _five_ mouse clicks (or _four_ operations).

It may be subtle, but I believe this would improve the user experience.

—DIV

---

<div class="post-metadata">

### Author: ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)
#### Post date: [October 20, 2021, 2:58am UTC](https://discourse.slicer.org/t/segment-editor-reduce-the-number-of-mouse-clicks-to-set-basic-colour-for-segment/20236/2 "2021-10-20T02:58:51Z")

</div>

Here are images for reference for other readers

> [@DIV](#):
>
> double-click the relevant swatch for **Segment color** ;

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/2/e2a0539ad9b429dd233291f457bb41ae6532ff2a.png)

> [@DIV](#):
>
> click **Color** in the (badly named) _Slicer_ dialogue box;

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/0/4026c683aebdbca272d7d8f944941a05f6602cf5.png)

> [@DIV](#):
>
> - click **Basic** tab in the _Select Color_ dialogue box;
> - click a swatch under **Basic colors** ;

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/d/6db7602383a06d99f725cc01d5f47c0f75bee084.png)

> [@DIV](#):
>
> click **Select** in the _Slicer_ dialogue box.

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/8/d895f3215784109d869a95cd55db34f4b8902b65.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [October 20, 2021, 4:19am UTC](https://discourse.slicer.org/t/segment-editor-reduce-the-number-of-mouse-clicks-to-set-basic-colour-for-segment/20236/3 "2021-10-20T04:19:19Z")

</div>

You actually don’t need to switch to Basic tab, so it “just” takes 5 clicks to change color. Of course 5 would be still more than the usual 3 clicks, but you can reduce the required number of clicks to 3 by creating a json file that contains all the segment names and colors that you use frequently, or further reduce it to 0 clicks by creating a segmentation node with empty segments that you can use as a template for each new segmentation.

If you just want to always use the “Basic” color picker then you can change that in Application settings → Application startup script → add `ctk.ctkColorDialog().setDefaultTab(0)` to the end of the displayed startup script file.

> [@DIV](#):
>
> click **Color** in the (badly named) _Slicer_ dialogue box;

> [@DIV](#):
>
> content of the current (badly named) _Slicer_ dialogue box

Windows uses the application name as title in all dialog boxes that have no specific title - not just in Slicer, but in all other applications, too.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/6/566a7e73a7b2961698721aa0a8f1e8b4f2198954.png)

Maybe adding a bit more specific title (“Terminology”?) could be useful, but the current behavior is not faulty. Therefore I don’t feel that it is justified bringing it up twice like it was some serious mistake and doing so somewhat dulls the edge of your other comments.

---

<div class="post-metadata">

### Author: ![DIV](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/div/32/12816_2.png) [@DIV](https://discourse.slicer.org/u/DIV)
#### Post date: [October 20, 2021, 7:07am UTC](https://discourse.slicer.org/t/segment-editor-reduce-the-number-of-mouse-clicks-to-set-basic-colour-for-segment/20236/4 "2021-10-20T07:07:19Z")

</div>

Hello, Andras.  
Thanks for your response.

I’m not sure why, but for me it _is_ definitely necessary to click the **Basic** tab in the workflow I described, because when I click click **Color** in the (Windows-default-named) _Slicer_ dialogue box (to be more precise, I’m clicking on the field next to that label, which contains a coloured square), the **Labels** tabs always comes up in the _Select Color_ dialogue box.  
That is for the two most recent versions of Slicer on Windows (4.11.20210226 & 4.11.20200930).

Or did you mean that it’s not necessary to select the Basic tab if I add the relevant line of code you described to the end of the displayed startup script file?  
I have tried to do this, by adding the command “ctk.ctkColorDialog().setDefaultTab(0)” on a new line in the file “C:/Users/[username]/.slicerrc.py”, but it seems to have no effect. (Unless I have to restart the application or computer or something first? I merely opened a new instance of Slicer, without closing all old instances.)

By the by, in the _Settings_ dialogue box there’s a button with a folder icon beside the **Application startup script** text field. I guess that clicking on this “opens” the file in whatever the default OS application is, because I was expecting the file to be opened for editing as a text file, but instead I think that Windows tried to run it as a Python file (because of the \*.py extension), which wasn’t what I was expecting, and probably isn’t a very useful action for the button to invoke. Not sure if it might be better for this button to get the OS to open this \*.py file as if it were a text file?

OK, OK, it may have seemed unnecessary to repeat the point about the naming of the _Slicer_ dialogue box twice. I could say it was repeated for consistency, but you could also interpret the repetition as lazy copy-and-paste.  
Certainly I didn’t mean to imply that it was a major issue. I was just feeling irritated that the dialogue box didn’t have a distinctive name that I could use to clearly refer to it. In the meanwhile James has greatly helped out in that department by adding little screen captures of the relevant steps.

—DIV

---

<div class="post-metadata">

### Author: ![DIV](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/div/32/12816_2.png) [@DIV](https://discourse.slicer.org/u/DIV)
#### Post date: [October 20, 2021, 7:44am UTC](https://discourse.slicer.org/t/segment-editor-reduce-the-number-of-mouse-clicks-to-set-basic-colour-for-segment/20236/5 "2021-10-20T07:44:46Z")

</div>

Further on the topic of modifying the start-up script file, I clicked the toolbar button to show the Python Interactor window just after launching a new instance of Slicer, and it shows the following error message.

```auto
Python 3.6.7 (default, Feb 27 2021, 00:03:56) [MSC v.1924 64 bit (AMD64)] on win32
>>> 
Loading Slicer RC file [C:/Users/[username]/.slicerrc.py]
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 131, in loadSlicerRCFile
  File "E:/Program Files/Slicer 4.11.20210226/bin/../lib/Python/Lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 370: character maps to <undefined>

```

I’m not too sure what’s producing the error. Maybe it’s been there all along, as it came up again even when I removed (commented out) the newly added command from the start-up script file.  
Before now I haven’t generally opened the Python Interactor window.

—DIV

P.S. One recent thing I tried quickly was running the code at [Script repository — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#register-custom-volume-rendering-presets) , but without creating the \*.mrml file first. Funnily enough, Python didn’t show any error when I ran that.

---

<div class="post-metadata">

### Author: ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)
#### Post date: [October 20, 2021, 7:51pm UTC](https://discourse.slicer.org/t/segment-editor-reduce-the-number-of-mouse-clicks-to-set-basic-colour-for-segment/20236/6 "2021-10-20T19:51:41Z")

</div>

> [@DIV](#):
>
> `Loading Slicer RC file [C:/Users/[username]/.slicerrc.py]`

What is the actual location of your .slicerrc.py file? Do you have special characters in your username?

This is what it displays for me in the python interactor window.

> Loading Slicer RC file [C:/Users/james/.slicerrc.py]

---

<div class="post-metadata">

### Author: ![DIV](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/div/32/12816_2.png) [@DIV](https://discourse.slicer.org/u/DIV)
#### Post date: [October 22, 2021, 5:01am UTC](https://discourse.slicer.org/t/segment-editor-reduce-the-number-of-mouse-clicks-to-set-basic-colour-for-segment/20236/7 "2021-10-22T05:01:38Z")

</div>

Hello, James.  
My username is purely alphanumeric; besides that, the file is exactly where I said: `C:/Users/[username]/.slicerrc.py`.  
_thinking_…  
_working_…  
OK, I have found the cause of the error message.  
I had inserted the following into the start-up script file (on the last three lines):

```auto
# Always use the “Basic” color picker
# https://discourse.slicer.org/t/segment-editor-reduce-the-number-of-mouse-clicks-to-set-basic-colour-for-segment/20236/3
ctk.ctkColorDialog().setDefaultTab(0)

```

If you inspect the comment “`Always use the ` **“** `Basic` **”** ` color picker`” [_copied from this thread_] carefully you’ll see that proper quotation marks are used. This is causing the error.  
When I change the comment to “`Always use the "Basic" color picker`” the error goes away.

I don’t think the curved quotation marks are especially exotic symbols, and most of all I didn’t expect any issue to be caused because they are in a comment, not a command.  
Nevertheless I leave it to your judgement as to whether this is a bug or whether it is expected/intended behaviour.

I can also confirm that the command is run at start-up, as the **Basic** tab is indeed now shown as the default tab in the _Select Color_ dialogue box.  
Every little bit helps. 🙂

`***`

Personally I would prefer that after clicking **OK** in the _Select Color_ dialogue box I didn’t have to then also click **Select** in the _Slicer_ dialogue box, but I think that the current structure of having two dialogue boxes makes the twofold confirmation unavoidable. That was part of the rationale behind my proposal to unify the current two dialogue boxes (with 1 + 2 tabs) into a single dialogue box (with 3 tabs): just a single “OK” would be needed.  
I realise that may not be a huge priority, but the idea is there to be considered anyway.

—DIV
