Isotropix Forums

Creating shelf toolbar

Clarisse Scripting related topics

Creating shelf toolbar

Unread postby jboissinot » Fri Apr 19, 2019 5:24 pm

Hi,

I'm having issues putting in place a new shelf toolbar. Basically, the idea is to keep the custom shelf toolbar for users preferences and to add a new one that could be shared by all users.

When I create a new shelf toolbar, it sets the shelf configuration in the default user shelf.cfg file, which does work fine after relaunching Clarisse as this new shelf does remain visible.

Code: Select all
/user_local_path/.isotropix/clarisse/4.0/shelf.cfg


But, I can't find a way to get this new shelf properly set up if I place its config file in a different location, even though I did follow the procedure for doing it in the Customizing shelf toolbar documentation page.

I removed the new shelf config file I created, so it was reset after relaunching Clarisse, and placed it in the following location in order to set a similar structure of the default one in the application directory:

Code: Select all
/user_local_path/.isotropix/clarisse/4.0/shelves/shelf.cfg


The goal behind this would be to copy those files into the user local folder when launching Clarisse with the startup script, that's the idea at least.

Then, I set the IX_SHELF_CONFIG_FILE variable in the clarisse.env file by adding the path of my new shelf config file so I get something like this:

Code: Select all
IX_SHELF_CONFIG_FILE=$CLARISSE_BIN_DIR/shelves/shelf.cfg;/user_local_path/.isotropix/clarisse/4.0/shelves/shelf.cfg


Actually, regarding this, the description of this variable in the documentation mentions "Defines which folders Clarisse should look for shelf configuration files". As such, I was wondering if we need to set the full path of the config file or just its directory?

Anyway, I tried setting the directory only as well and didn't work either:

Code: Select all
IX_SHELF_CONFIG_FILE=$CLARISSE_BIN_DIR/shelves/shelf.cfg;/user_local_path/.isotropix/clarisse/4.0/shelves


I also tried to use the ":" as separator but was still not successful, and by the way, I'm doing this on linux for info.

The other issue I was dealing with is that even when I place the shelf config file here:

Code: Select all
/user_local_path/.isotropix/clarisse/4.0/shelf.cfg


I can see the shelf toolbar in Clarisse but the script files that are set in the shelf items can't be found while I placed the scripts in the following location:

Code: Select all
/user_local_path/.isotropix/clarisse/4.0/shelves/scripts/my_script.py


And set the items script path like this:

Code: Select all
./shelves/scripts/my_script.py


So, I'm not quite sure if I'm missing something here but was hoping that you may help me on this.

Thanks,
Jeremy
jboissinot
 
Posts: 58
Joined: Tue Jan 29, 2019 10:36 pm

Re: Creating shelf toolbar

Unread postby bvaldes » Tue Apr 23, 2019 1:14 pm

Hi,

This is not possible to change the path of the shelf. You have to merge the shelf you want to add in the current one.
You can do it with a script by merging the 2 files. I wrote a script but you have to use it outside of Clarisse when it's not open. Else When clarisse will restart everything will be overwritten.

python code

import os, re

def get_block(content, kindof, name=None):
"""
Parse a file created from Clarisse parser (project, cfg...)
"""
lines = content.split("\n")
start = False
current_block = []
result = []
brackets_count = 0
for line in lines:
if kindof + " " in line:
start = True
if start is True:
current_block.append(line)
if "{" in line:
brackets_count += 1
if "}" in line:
brackets_count -= 1
if brackets_count == 0:
start = False
block = "\n".join(current_block)
result.append(block)
current_block = []
return result


def merge_shelf(custom_shelf_path, clarisse_shelf_path):
"""
Merge shelf_A in shelf_B
So you have to set in shelf_B the path of the current shelf that Clarisse's uses
"""
if not os.path.exists(custom_shelf_path) or not os.path.exists(clarisse_shelf_path):
ix.log_warning("Check the paths of the shelf you provide. One of them can't be found")
return False

with open(custom_shelf_path, "r") as f:
custom_shelf_content = f.read()
with open(clarisse_shelf_path, "r") as f:
clarisse_shelf_content = f.read()


custom_shelf = get_block(custom_shelf_content, "category")
clarisse_shelf = get_block(clarisse_shelf_content, "category")
if len(clarisse_shelf) > 0 :
for cat in custom_shelf:
cat_name = re.findall('category "[a-zA-Z0-9 ]+"', cat)[0]
if cat_name in clarisse_shelf_content:
# That mean tha the category already exists in shelf B so we have to replace it
# For that we need to find the id of the category in the clarisse shelf file
for ix_cat in clarisse_shelf:
ix_cat_name = re.findall('category "[a-zA-Z0-9 ]+"', ix_cat)[0]
if ix_cat_name == cat_name:
cat_id = clarisse_shelf.index(ix_cat)
break
clarisse_shelf[cat_id] = cat
else:
# The cat do not exists so we gonna append it to the end
clarisse_shelf.append(cat)

#print "\n".join(clarisse_shelf)
new_content = "\n".join(clarisse_shelf)


clarisse_slot_0 = get_block(clarisse_shelf_content, "slot")[0]
old_content = "\n".join(get_block(clarisse_slot_0, "category"))
clarisse_shelf_content = clarisse_shelf_content.replace(old_content, new_content)
else:
custom_shelf_slot_0 = get_block(custom_shelf_content, "slot")[0]
clarisse_shelf_content = clarisse_shelf_content.replace("}", custom_shelf_slot_0 + "\n}")
print clarisse_shelf_content


# This part is to bake current shelf to avoid issue if there is one
# os.rename(clarisse_shelf_path, clarisse_shelf_path+".old")

with open(clarisse_shelf_path, "w") as f:
f.write(clarisse_shelf_content)




merge_shelf(r"C:\Users\bvaldes\Desktop\shelf2.cfg", r"C:\Users\bvaldes\AppData\Roaming\Isotropix\Clarisse\4.0\shelf.cfg")

The last line is an example. Tell us if it not works.

Best regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Creating shelf toolbar

Unread postby jboissinot » Tue Apr 23, 2019 5:41 pm

Hi Benoit,

Thanks for the info and the merge script, which I tried and does work fine, but I'm still a bit confused and having a few questions regarding this though.

This is not possible to change the path of the shelf. You have to merge the shelf you want to add in the current one.


What do you mean by this? And what the IX_SHELF_CONFIG_FILE variable of the clarisse.env file is used for then?

As the description of the variable in the documentation says "Defines which folders Clarisse should look for shelf configuration files.", I was expecting that Clarisse will be able to load other config files. Also, the documentation does illustrate how to use multiple shelf config files, and this is what I was trying to achieve by following the procedures.

Do you mean that Clarisse can have only two config files? The main one in the application directory - $CLARISSE_BIN_DIR/shelves/shelf.cfg - and the one in the user local directory - /user_local_dir/.isotropix/clarisse/4.0/shelf.cfg - while the documentation does mentions "As Clarisse supports and appends multiple shelf.cfg file,...".

Even though I'm able to add my custom shelf by merging it, I'm still having the issue for executing the scripts. See my original comment for more info regarding the issue, as Clarisse is not able to run the scripts from the shelf. Let me know if you have any idea of what may cause the issue or if I'm missing something.

Thanks,
Jeremy
jboissinot
 
Posts: 58
Joined: Tue Jan 29, 2019 10:36 pm

Re: Creating shelf toolbar

Unread postby bvaldes » Wed Apr 24, 2019 10:41 am

Hi,

Sorry I didn't answer to all your questions. Indeed I didn't succeed to make work the documentation example about the shelf so I've create an entry in our bug database (#9633). So until the issue will be fixed, you can use the script I gave you in the previous post. Sorry for the inconvenience.

About your script execution this is quite simple: The reason why Clarisse's built-in shelf use "./the_path_of_the_script.py" is that it's a relative path (you can google it to have more information, this is a common usage). If your python scripts are not in the clarisse install dir, you will not be able to use relative path (except if you go up in the directory hierarchy) so you have to write the absolute path: C:/the/path/of/your/file.py
With that in mind you will be able to make your shelf work.

Tell me if this still not work.

Best regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Creating shelf toolbar

Unread postby jboissinot » Wed Apr 24, 2019 8:02 pm

Hi,

Seems like we did find an issue here then, so that's good if you're aware and I'll try to set it up with the merge script for the moment.

I am well familiar with the ./ relative syntax and the built-in tool shelf but could not understand why Clarisse was not able to find my scripts even though everything seemed to be properly set up.

When I check the settings of an item I add in my new shelf, it does use $CLARISSE_BIN_DIR/ as Config Directory while I was expecting it to get the actual directory of the config file from which the item is set, in this case, it should be using:
Code: Select all
/user_local_path/.isotropix/clarisse/4.0/

as the config file is here:
Code: Select all
/user_local_path/.isotropix/clarisse/4.0/shelf.cfg


But maybe this is part of the same issue we found with the example from the documentation.

This is why I was curious to know more about the IX_SHELF_CONFIG_FILE variable, I mean if we add the user local directory path to it, and it does find the config file of the shelf, it should be able to get and use the proper config directory of an item, and not the Clarisse bin directory.

And this is also why I tried to set the IX_SHELF_SCRIPT_PATH variable with the scripts directory so that I don't need to set the full path, but was not working either.

So my bet is that the shelf toolbar is either buggy or limited, as it simply doesn't work just like it is demonstrated in the documentation, or maybe I'm just missing something again.

I'll let you investigate on this, for now, I'll set it up with the shelf merge solution and the scripts full path, even though it's not ideal, but I think I could live with it for the moment until we can possibly use a better approach.

Thanks,
Jeremy
jboissinot
 
Posts: 58
Joined: Tue Jan 29, 2019 10:36 pm

Re: Creating shelf toolbar

Unread postby bvaldes » Thu Apr 25, 2019 8:28 am

Hi,

In the documentation, this is written that ./ pointing in the install_dir/shelves (you can find it on the line before the hierarchy example).
So when you use relative path, Clarisse do not try to resolve in the config folder but in the shelf directory in the install folder.

There is no way to add a variable in the path of a shelf item because the path is not interpreted so Clarisse will not resolve the variable. So you will have to use absolute path if the scripts are not located in the Clarisse's install directory.

Best regards.
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Creating shelf toolbar

Unread postby jboissinot » Thu Apr 25, 2019 3:17 pm

Hi Benoit,

This is what the documentation says:
When the script_filename doesn't specify any folder, Clarisse uses the content of the variable IX_SHELF_SCRIPT_PATH to locate the file. When the filename is relative such as "./path/to/my/file.py" then Clarisse resolves the path using the folder where it found the configuration file and which used eventually the IX_SHELF_CONFIG_FILE variable.


From my understanding reading this, that's why I was expecting Clarisse to be able to find the script file based on what it's set in the clarisse.env file, and therefore resolves its path from which location it found the corresponding config file.

As such, from my testing, the IX_SHELF_CONFIG_FILE and IX_SHELF_SCRIPT_PATH variables don't seem to be working as expected.

To me, it's not really clear that using the ./ relative path syntax would only resolve the path from the Clarisse bin directory based on how it's explained in the documentation.

There is no way to add a variable in the path of a shelf item because the path is not interpreted so Clarisse will not resolve the variable. So you will have to use absolute path if the scripts are not located in the Clarisse's install directory.


It's good that you mention this because I was thinking to set the scripts file path with the $CLARISSE_USER_CONFIG_DIR but this might not work then, and like you say, I would have to set them with their absolute path.

Thanks for the info,
Jeremy
jboissinot
 
Posts: 58
Joined: Tue Jan 29, 2019 10:36 pm

Re: Creating shelf toolbar

Unread postby jboissinot » Tue Apr 30, 2019 4:36 pm

Hi Benoit,

I just wanted to confirm this with you:
I wrote a script but you have to use it outside of Clarisse when it's not open. Else When clarisse will restart everything will be overwritten.


Do you mean that we can run a similar script from the Clarisse startup_script or does it need to be ran even before we launch Clarisse?

Thanks,
Jeremy
jboissinot
 
Posts: 58
Joined: Tue Jan 29, 2019 10:36 pm

Re: Creating shelf toolbar

Unread postby jboissinot » Wed May 01, 2019 12:03 am

Hi,

I actually tried this on my own to see how it'd go. There's an issue with setting up the custom startup_script path from the clarisse.env file, see the following topic:
https://forum.isotropix.com/viewtopic.php?f=21&t=5526

I was able to set my custom startup_script which is well executed at startup, all my python works fine as it does merge my custom shelf with the user shelf config file. The only this I noticed though is that the user shelf config file is being overwritten when quitting Clarisse. It seems that Clarisse caches the user shelf config file at startup which is then overwritten at exit if different than it was at startup.

Not sure if this is a bug or some kind of design or limitation, anyway that may explain why the merge process would have to be done even before startup. But, I just feel it's a bit sad not to be able to update the user shelf config file during the starting_script process.

Can you let me know a bit more about this.

Thanks,
Jeremy
jboissinot
 
Posts: 58
Joined: Tue Jan 29, 2019 10:36 pm

Re: Creating shelf toolbar

Unread postby bvaldes » Thu May 02, 2019 8:27 am

Hi,

This is what I wanted to say by: use it outside of Clarisse when it's not open. Else When clarisse will restart everything will be overwritten.
When Clarisse exit, the preferences are saved (or when you close the preferences panel within Clarisse). That mean that you have to execute the script before launching any Clarisse. Else the prefs will be overwritten.

Don't forget that this script is a workaround until we fix the issue with the env file to fit with the documentation explanations.
Every issue you encounter are related to the issue with the env file. The script is not perfect but allow you to work until the issue is fixed.

Sorry for the inconvenience.
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Next

Return to Scripting
cron