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

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

Here are images for reference for other readers

image

image

image

image

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.

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

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.

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

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.

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 , but without creating the *.mrml file first. Funnily enough, Python didn’t show any error when I ran that.

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]

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):

# 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. :slight_smile:

***

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