Restore default_shortcuts.json and embedded scripts support

Bug #1299092 reported by Gabriele Pacaccio
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Stellarium
Incomplete
Undecided
Guillaume Chereau

Bug Description

This bug report is related to question #245630.

After trying the new 0.13 version I found out that there is no more support to embedded scripts and default_shortcuts.json file like the 0.12 version. I'd like to have these features restored because are very useful to me.

Changed in stellarium:
assignee: nobody → Guillaume Chereau (guillaume-chereau)
milestone: none → 0.13.0
Revision history for this message
Gabriele Pacaccio (gabrielepacaccio01) wrote :

Any news about this issue?

Revision history for this message
Gabriele Pacaccio (gabrielepacaccio01) wrote :

Please, let me know if you are working on this problem. I've downloaded the latest 0.13 dev3 release and I can't find the default_shortcuts.json file.

I need informations because if you can't do that I have to find an alternative in time for 0.13 release.

Thanks.

Revision history for this message
Guillaume Chereau (guillaume-chereau) wrote : Re: [Bug 1299092] Re: Restore default_shortcuts.json and embedded scripts support

Gabriele: I removed the default_shortcuts.json file in the 0.13 branch.
Instead you can define shortcuts in the global config file.

If you want to create a script and assign it a shortcut, you have to add
the script in the scripts directory, and then in config.ini add a line
in the shortcuts section. The shortucts action names for scripts are of
the from "actionScript/<file.ssc>" For example, if you created a script
called "my_script.ssc", you would add:

    [shortcuts]
    actionScript/my_script.ssc = Ctrl+U,2

Let me know if this does not cover all the cases you need.

Revision history for this message
Guillaume Chereau (guillaume-chereau) wrote :

Also, I realize there is a bug when you use the shortcuts editor from within the application,
it adds spaces in the config file that shouldn't be there. I am going to fix that.

Revision history for this message
Alexander Wolf (alexwolf) wrote :

Guillaume, I think you are meant the bug #1294169. Current bug report related to support of embedded scripts in shortcuts.

Revision history for this message
Guillaume Chereau (guillaume-chereau) wrote :

You're right, though those two bugs are related. Maybe we should merge
them into the same issue?

Revision history for this message
Gabriele Pacaccio (gabrielepacaccio01) wrote :

The embedded script was a great functionality to add a lot of scripts, all in the same file. So now I have to create a file for all the scripts I have in the default_shortcuts.json file and then I have to add shortcuts in another file, when this was done in a single file in the past.

Why did you do that? Is it a way to enhance stellarium?
So, can you restore this function or not? I think it is so useful and fast.

Revision history for this message
Guillaume Chereau (guillaume-chereau) wrote :

There were some technical problems with the default_shortcuts.json
approach in my opinion. I changed it so that the default shortcuts are
defined in the C++ code at the same time we create the actions, it
avoided some redundancies and made the code smaller. Also I thought it
was nicer to save only the redefined shortcuts directly in the config
file instead of the somehow complicated json format that was used.

One thing that annoyed me what that in the json file you had for
example:

  "actionShow_Constellation_Lines": {
    "text": "Constellation lines",
    "primaryKey": "C",
    "checkable": "1",
    "autorepeat": "0",
    "global": "1"
  }

Here the only real information is the primaryKey attribute. All the
other attributes are already known by the code implementing the action,
so it does not make sense to make them configurable. What would it mean
for example to change the checkable value to "0"?

Those changes were not related to the embedded scripts functionality, I
just happened to remove that as well since it was part of the json file,
at the time I thought it was acceptable to just let people create
shortcuts in the usual way.

So, it would be possible to reintroduce some support for embedded scripts,
but at the cost of having a special file to parse only for this reason,
which I somehow find annoying.

An intermediary solution could be to allow to specify a default shortcut
directly in the script files. Then you would still need to create one
file per script, but at least you wouldn't have to change the config.ini
to add the shortcuts. Do you think that solution would be good enough?

Revision history for this message
Gabriele Pacaccio (gabrielepacaccio01) wrote :

Understood. So, can you add the embedded scripts functionality with this new configuration?
Otherwise, is there a way to add the script and a shortcut to it directly in the stellarium source code? I mean with a sintax similar to the script sintax.

Revision history for this message
Guillaume Chereau (guillaume-chereau) wrote :

On Tue, Apr 08, 2014 at 07:42:55AM -0000, Gabriele Pacaccio wrote:
> Otherwise, is there a way to add the script and a shortcut to it
> directly in the stellarium source code? I mean with a sintax similar
> to the script sintax.
Yes that would be possible, but it defeats the advantage of using
scripts (that is, not having to recompile the source for every change in
the script code).

I am going to start working on a branch to add the possibility to
specify script shortcuts directly in the script files, and eventually
also reintroducing some sort of support for having several scripts in
one file.

Revision history for this message
Gabriele Pacaccio (gabrielepacaccio01) wrote :

Thanks. Can you make a solution in time for the 0.13 release?
Let me know. I appreciate your work.

Revision history for this message
Bogdan Marinov (daggerstab) wrote :

I was another one annoyed by the previous implementation of the shortcuts.json file because it saved too much that should have been in the code. (Another problem caused by that was that shortcut descriptions had to be kept in synch across two files to enable translations.) The file should have held only action ID + shortcuts, and only for those shortcuts that have been redefined by the user. Such an arrangement would also allow embedded scripts.

AFAIK, the feature got implemented that way because it was mentored by Timothy Reaves - as far as I can recall, in previous discussions about key configuration, he had insisted on keeping all keys in a single file to prevent conflicts.

Unfortunately, I kept postponing raising the issue or doing something about, as usual. :(

Revision history for this message
Gabriele Pacaccio (gabrielepacaccio01) wrote :

Bogdan, you are right, but I think the embedded script functionality is very powerful.

Another thing I want to explain is that I'll set all the scripts once and I'll never change them anymore, so it's not a problem for me to add the scripts manually in the code and recompile stellarium. I just need someone to tell me how I can do that. For example in which file I have to add the code and the syntax I have to use.

Revision history for this message
Gabriele Pacaccio (gabrielepacaccio01) wrote :

After thinking a bit and taking a look at the source code I decided to add my custom scripts directly into the code and recompile Stellarium.

For me this should be a great alternative way to do what I want, because I don't need to change the scripts once added the first time. In addition, this can be a more powerful way to make custom functions because I can make changes directly in the source code.

I think that I can make a custom function for each script and add a shortcut to them with the addAction() method.

I need only a couple of informations:
- how can I correctly add a .cpp and .hpp file to the source code? (I will add the functions in these new files just to make easy to find them)

- how can I make a function for a script? I mean, is the syntax the same of the scripts?

for example, how can I make a function to replace for an embedded script like this:

"scriptgoto_Sun":
{
 "text" : "GotoSun",
 "primaryKey" : "Ctrl+P, 1, 2, 0",
 "script" : "core.selectObjectByName(\"Sun\", false);
                    StelMovementMgr.setFlagTracking(true);",
 "checkable" : "0",
 "autorepeat" : "0",
 "global" : "0"
}

Do I need to #include some files?

Please, let me know these informations and then you can go ahead with your ideas and forget the problem of the default_shortcuts.json file

Revision history for this message
Gabriele Pacaccio (gabrielepacaccio01) wrote :

So I made a MyFunctions.hpp file with these lines of code

#ifndef _MYFUNCTIONS_HPP_
#define _MYFUNCTIONS_HPP_

#include "StelModule.hpp"
#include "StelProjector.hpp"
#include "StelObjectType.hpp"
#include "StelObjectModule.hpp"

class MyFunctions
{
public:
    MyFunctions();
    virtual ~MyFunctions();

    virtual void init();

public slots:
    void customShortcut();
};

#endif // _MYFUNCTIONS_HPP_

and another called MyFunctions.cpp with these lines

#include "MyFunctions.hpp"
#include "StelActionMgr.hpp"
#include "StelMainScriptAPI.hpp"
#include "StelMovementMgr.hpp"
#include "StelModuleMgr.hpp"
#include "StelTranslator.hpp"
#include "StelApp.hpp"
#include "StelCore.hpp"

#include <QString>
#include <QTextStream>
#include <QSettings>
#include <QKeyEvent>
#include <QDebug>

MyFunctions::MyFunctions()
{

}

MyFunctions::~MyFunctions()
{

}

void MyFunctions::init()
{
    StelCore* core = new StelCore;
    StelActionMgr* actionsMgr = StelApp::getInstance().getStelActionManager();
    actionsMgr->addAction("actionCustom_Shortcut", N_("Miscellaneous"), N_("Custom shortcut"), core,
    "customShortcut()", "Shift+X");
}

void MyFunctions::customShortcut()
{
    StelMainScriptAPI* core = GETSTELMODULE(StelMainScriptAPI);
    StelMovementMgr* stelMovementMgr = GETSTELMODULE(StelMovementMgr);
    core->selectObjectByName("Sun", false);
    stelMovementMgr->setFlagTracking(true);
}

I've also added the file names in the CMakeLists file

The compilation goes well but when I can't see the shortcut in the Stellarium's shortcuts list and when I press the keys nothing appends. Why? What is wrong? Please, let me know what I have to change

Revision history for this message
Guillaume Chereau (guillaume-chereau) wrote :

Hi Gabriel,

Sorry I won't have time to check your code today. Just a quick note:
in order to use Qt slots mechanism, your class should inherit from
QObject, and have the Q_OBJECT macro added into it.

Something like:

    class MyFunctions : public QObject
    {
        Q_OBJECT
    public:
        MyFunctions();
        virtual ~MyFunctions();

        virtual void init();

    public slots:
        void customShortcut();
    };

Hum... maybe we should move this discussion to the mailing list and keep
this thread to the original bug.

Changed in stellarium:
milestone: 0.13.0 → none
Revision history for this message
gzotti (georg-zotti) wrote :

What's the point with this? As of V0.16 you write an .ssc script and declare its shortcut in the script header or reassign it later. Could hardly be made simpler.

Can we close this item?

Changed in stellarium:
status: New → Incomplete
Revision history for this message
Alexander Wolf (alexwolf) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.