Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to add a function to a common button. #288

Open
chj93 opened this issue Sep 7, 2022 · 5 comments
Open

I want to add a function to a common button. #288

chj93 opened this issue Sep 7, 2022 · 5 comments

Comments

@chj93
Copy link

chj93 commented Sep 7, 2022

@partridgejiang First off, I am huge fan of the project. Thanks for all the work :)

I am using Kekule.Editor.Composer.

  1. I want to set the default value of the 'save data' button to smi.
  2. I want to add smi to the selectable field of the 'Load data' button.

I searched the documentation for a day and couldn't find a way.
Is there any easy way to solve it? thank you!

@partridgejiang
Copy link
Owner

Hi @chj93, it's a pity that some hacks are needed to accomplish the default input/output format before. So some new commits are submitted today. With these new dist files, you may use the following codes:

composer.getEditor().setDefaultInputFormatId(Kekule.IO.DataFormat.SMILES);
composer.getEditor().setDefaultOutputFormatId(Kekule.IO.DataFormat.SMILES);

By the way, the loading SMILES depends on the extra OpenBabel.wasm module, so you need to enable that module first:

Kekule.OpenBabel.enable(function(error){
  if (!error)
  {
    composer.getEditor().setDefaultInputFormatId(Kekule.IO.DataFormat.SMILES);
  }
});

@chj93
Copy link
Author

chj93 commented Sep 8, 2022

Hi @partridgejiang, Thanks for your kind reply!
I'm using 'Kekule' by installing it as an npm package. The latest release (v.0.9.7) cannot be used because the new commit history is not reflected.
Can I request a new release that reflects the new commits?

@partridgejiang
Copy link
Owner

partridgejiang commented Sep 8, 2022

Just getting the files in /dist directory of this repo and replacing the ones downloaded with npm should work, :).

@chj93
Copy link
Author

chj93 commented Sep 8, 2022

With help, in case 1, it works normally. However, in case 2, it does not work because 'Smi' does not exist in the 'Load data' button in the first place.
Can you help me with this?? thank you :)

Kekule.OpenBabel.enable(function(error) {
  if (!error) {
    composer.getEditor().setDefaultInputFormatId(Kekule.IO.DataFormat.SMILES);
  }
});
// composer.getEditor().setDefaultInputFormatId(Kekule.IO.DataFormat.SMILES);
composer.getEditor().setDefaultOutputFormatId(Kekule.IO.DataFormat.SMILES);

@partridgejiang
Copy link
Owner

Hi @chj93, please check if there are errors in the browser console and whether openbabel.wasm is properly loaded when running the following code:

Kekule.OpenBabel.enable(function(error) {
  if (!error) {
    composer.getEditor().setDefaultInputFormatId(Kekule.IO.DataFormat.SMILES);
  }
});

Since the OpenBabel is a web assembly module, the whole page should be launched in a web server with http(s) protocal, and the mime type of .wasm file may also need to be correctly configurated in the web server.

By the way, a small demo page is attached below, you may run it in your own web server, :)

defInOutFormat.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants