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

Store script settings on import #677

Closed
Maboroshy opened this Issue Aug 16, 2017 · 35 comments

Comments

Projects
None yet
3 participants
@Maboroshy
Contributor

Maboroshy commented Aug 16, 2017

As I use Python to write most of scripts, which require direct file access, I need to make sure that QML script can run Python 3 Interpreter. The command for these can vary even between Linux distros.

I've implemented a function that tests different commands and uses successful one for a script setting's default. But it does so every time the script loads. More such scripts load, more resources wasted.

I think there's a need for a special procedure for that kind of "adapting", which will run only on script import. Maybe a special function, which runs only on import and saves some variables as a stored script settings.

@pbek pbek added the enhancement label Aug 16, 2017

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

Please define "script import" and why it is so special to you.

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Aug 16, 2017

Script import is the moment script is added to the QON script list, as a local or from repo. It can even be disabled then, no matter. When the script is added it will adapt itself to the system. If the system radically changes after some update, user is able to manually correct stored settings or reimport the script.

I want to adapt the script to use correct command to run Python 3, which is:
python3 or python - for "unstable" Linux distros;
python3 - for "stable" Linux distros and OSX, they have python for Python 2;
python or py - for Windows, there's no python3 by default there;
"I don't know, help me" - if all the above won't work.

Also, pandoc changed some important markdown setting keys lately, so there should be different commands for markdown conversion for different versions. I've already had to implement that to my nsx2md thing, which is not QON script, there are already 3 versions.

Yes, the script can check that every run, but that's a waste or cpu time. And yes the user can do it manually, but why should he.

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

The script engine is reloaded if QOwnNotes starts or if settings change in the settings dialog. I still fail to see what use something that is only called when a script is added to QON is implemented. And I'm not even sure if that is what you need, because the headline of this feature request is "Store script settings on import".

Don't you just need a way to persist data at runtime inside the script?

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Aug 16, 2017

Maybe. I want to store a setting before the script will be ran by user. Then use that setting in all the following script runs.

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

You can't do something in a script unless it is run by the scripting engine...
Although if you want to create a "run-once-function" that would be possible with that "persisted data".

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

And you can use registerSettingsVariables to alter default values, like in https://github.com/pbek/QOwnNotes/blob/develop/doc/scripting/variables.qml.

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

17.08.5

  • you can now use the new scripting functions script.setPersistentVariable() and
    script.getPersistentVariable() to store and load persistent variables in scripts

@pbek pbek added this to the 17.08.5 milestone Aug 16, 2017

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Aug 16, 2017

I've tried. registerSettingsVariables runs every time the script runs, even when defaults are already overridden by saved settings. So registerSettingsVariables = {'default': function(),} as I see it.

I'll try the new functions.

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

I've tried. registerSettingsVariables runs every time the script runs, even when defaults are already overridden by saved settings. So registerSettingsVariables = {'default': function(),} as I see it.

yes, they are meant to work that way

I'll try the new functions.

you'll be able to do so shortly

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

There now is a new release, could you please test it and report if it works for you?

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Aug 16, 2017

By the way, the shared namespace for persistent var is great! Since my scripts mostly use the same external programs, the first script can prepare settings for all the following.

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Aug 16, 2017

... And then this goes into bus to exchange data between scripts. New goodies to play with!

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

Thank you for testing!

By the way, the shared namespace for persistent var is great!

I couldn't even do it "per script", because QON doesn't know which script called the function. :(

And then this goes into bus

which bus? did you invent something? :)

@pbek pbek closed this Aug 16, 2017

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Aug 16, 2017

which bus? did you invent something? :)

One script can save some data to persistent var, and the other script can get and use it.

I haven't tried sockets, haven't even read about them. Do they do the same thing?

To my shame I still consider QML as the necessary evil to get to Python. Since, after trying QtQuick, I found out that QON has quite striped up Qt libs bundled, I'm not sure what's available for the scripts and what's not.

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

I haven't tried sockets, haven't even read about them. Do they do the same thing?

see: https://en.wikipedia.org/wiki/WebSocket

Since, after trying QtQuick, I found out that QON has quite striped up Qt libs bundled, I'm not sure what's available for the scripts and what's not.

I think that depends on what libraries are installed on the system...

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Aug 16, 2017

I know, as a KDE user I have all of them. But I want the script to be available on every OS QON is.

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

We would end up by bundling the whole Qt library... (but bundling unused libraries didn't even work when I last tried)

If you want to remote control QOwnNotes with sockets you can use WebSocketServer in a script. I prepared examples at http://docs.qownnotes.org/en/develop/scripting/README.html#working-with-websockets

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

This might also be of interest to @siriux.

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Aug 16, 2017

Looks like a very powerful stuff. Maybe it will allow me to overcome #524. That would be an overkill, but can work out.

I'll think some more what can I get out of it with a current set of scripting functions.

@pbek

This comment has been minimized.

Owner

pbek commented Aug 16, 2017

You tell you script in QOwnNotes to do stuff from your python scripts if you open a socket connection to the socket server in your QOwnNotes script. Pretty amazing.

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Aug 16, 2017

What about Windows guys? Would they get the goods with QON bundle?

@pbek

This comment has been minimized.

Owner

pbek commented Aug 17, 2017

Which bundle do you mean? Websockets? It should work there too... if the Qt library for websockets is installed...

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Aug 17, 2017

The chances Windows users has some Qt library explicitly installed are close to 0.
Is websockets library included into QON installation package?

@pbek

This comment has been minimized.

Owner

pbek commented Aug 17, 2017

The chances Windows users has some Qt library explicitly installed are close to 0.

Who is using websockets to talk to their software and isn't a developer that can build QON him/herself anyway? :)

Is websockets library included into QON installation package?

No, Qt's deployment script would throw it out I guess...

@siriux

This comment has been minimized.

siriux commented Aug 17, 2017

Wow, that's pretty interesting.

The QT5Websockets library is just a few hundred KB, maybe it could be included by default in the windows and macosx builds.

This could open the door to browser extensions that let you save notes directly from the browser. To save some extracts from web pages, bookmarks, ...

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Aug 17, 2017

Who is using websockets to talk to their software and isn't a developer that can build QON him/herself anyway? :)

It's the user who want to install the script from repo. That very script the smart developer made.
If the script info says "Windows users should rebuild QON with websocket library", the script will loose a big part of users right away.

@pbek

This comment has been minimized.

Owner

pbek commented Aug 17, 2017

Last time I tried to include a library that wasn't used it got thrown out by Qt's deployment scripts...

@pbek

This comment has been minimized.

Owner

pbek commented Aug 17, 2017

If anyone can tell me what the name of the file on Windows (or Mac) is and ideally where to find it on AppVeyor/Travis (it might take some time to find that out) I could try to copy it manually in the build scripts.

@pbek

This comment has been minimized.

Owner

pbek commented Aug 17, 2017

And of course it first would need to be tested if just placing the file into a folder in the ZIP (for Windows) and APP-dmg (for macOS) is enough for the script to work.

@pbek

This comment has been minimized.

Owner

pbek commented Aug 17, 2017

For example working with AppVeyor (building for Windows) is pretty easy, just fork the QOwnNotes repository on GitHub and create a free account on https://www.appveyor.com/. If you build the project (the configuration is in https://github.com/pbek/QOwnNotes/blob/develop/appveyor.yml) you always get a zip to download and test, like in https://ci.appveyor.com/project/pbek/qownnotes/build/windows-b3173/artifacts. You could add some code to your forked appveyor.yml to list the files the Qt library paths to find the needed websockets-library. You could even alter the deployment to add that library to the zip file... @Maboroshy, @siriux, are you up to the challenge? 😸

@siriux

This comment has been minimized.

siriux commented Aug 17, 2017

I don't have a windows machine to test available right now, but I have an "old" Macosx 10.9 and I can try there. I see that for macosx you just install qt5 from homebrew, so I'll try that first to see if I can get it to work locally.

@pbek

This comment has been minimized.

Owner

pbek commented Aug 17, 2017

@siriux

This comment has been minimized.

siriux commented Aug 17, 2017

Well, it seems that QT5 needs macosx 10.10 or greater, so I cannot test it right now. Current QOwnNotes crashes too, but I don't have time right now to upgrade it.

I'll work on a plugin + extension on linux for the time being and when I have something working I'll update my macosx installation.

@pbek

This comment has been minimized.

Owner

pbek commented Aug 17, 2017

Too bad, thank you for trying, @siriux!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment