Stellarium / stellarium

Stellarium is a free GPL software which renders realistic skies in real time with OpenGL. It is available for Linux/Unix, Windows and macOS. With Stellarium, you really see what you can see with your eyes, binoculars or a small telescope.
https://stellarium.org
GNU General Public License v2.0
7.56k stars 815 forks source link

Report save errors writing scripts #741

Closed NotSoRandomOne closed 5 years ago

NotSoRandomOne commented 5 years ago

Is your feature request related to a problem? Please describe. Placed my used scripts in C:\Program Files\Graphic\Stellarium19\scripts, so I wouldn't always have to navigate to the User directory to find and use them. I was making changes to the scripts, and saving them. But the next time I opened a script, the changes weren't there. Evidently, the save is failing because the folder required elevation to save to. But Stellarium never reported the error, so I thought they saved OK and lost my work.

Describe the solution you'd like Add a messagebox on failure to save a script file, so the user knows of the failure.

Describe alternatives you've considered Nothing.

Additional context None.

gzotti commented 5 years ago

Again, no user should ever store stuff into c:\Program files.

I cannot confirm the issue on Win10. When I really try to store a script into c:\program files\Stellarium\scripts with Stellarium 0.19.1, a system panel informs me I cannot save there and offers to go to my home folder instead.

I had a similar problem years ago while editing a plugin for Sketchup 8. Sorry, I cannot remember the name of that extra folder where Windows 7 stored the files instead. It was offered in the menu of the file explorer when inside the plugins folder, so maybe, if you are using Win7, the same applies to you.

NotSoRandomOne commented 5 years ago

Then please make it so the user can set the subdirectory that opens when they open a script from the script window. And make that subdirectory stick between sessions. Right now it defaults to the subdirectory you say should not be saved to, which is annoying.

Thank you.

alex-w commented 5 years ago

@NotSoRandomOne Are you want to see configurable extra catalog for scripts?

NotSoRandomOne commented 5 years ago

I'm not certain what you mean. Right now, on my Win10 computer, the default scripts are at C:\Program Files\Graphic\Stellarium19\scripts, which I mentioned in my first post. (I moved the scripts in there to another subdirectory, so I didn't have to go through so many to find the ones I use.) Reading the docs, I came to the impression that scripts should be placed at C:\Users\David\AppData\Roaming\Stellarium\scripts, which I did. But every time I opened up Stellarium and went to open a script from the F12 window, it defaulted back to C:\Program Files\Graphic\Stellarium19\scripts, and it was a pain to navigate back to the AppData folder.

All I'm asking for is to make it so the user can somehow specify the default folder to open to when a script is opened and closed, so I don't have to navigate to it each time. (I originally asked for notification that the save didn't work, but if you make the default open/save location user-selectable, that would overcome the problem in a better way.

If you already have this, I'm sorry for overlooking it and taking your time, and please let me know where it is. Now that I have semi-mastered scripting with Stellarium, you have my full acknowledgment that it is the best archaeoastronomy program for general use. Your efforts are mind-bogglingly good.

If you want to ship future versions of Stellarium with the following script, feel free to do so. It allows researchers to easily jump to any sun depression they desire, and more easily see what our ancestors witnessed day-by-day.

Also, as seen by the script, your script window doesn't seem to handle the Unicode(?) ° sign correctly, and changes it to a question mark when copy/pasting from Notepad++.

David

(edit - didn't take the time to figure out why the '<' and '>' were causing the below code to drop case 4, and screw up some other cases. The attached zip should not have the problem.)

(edit 3? 4? - fixed < and > so script displays correctly)

// ******************************************************************************************
// Stellarium script to go to specified sun depression, either morning or evening,
// depending upon variable setting.
//
// Created by David O'Neil, Aug, 2019. Released to the public domain, for anyone interested.
// Just leave this 'created by' (or 'originally created by') verbage in the derived work.
//
// To use:
//   * Set the date via Stellarium's user interface
//   * Set 'gotoMorning' = true for morning viewing, false for evening
//   * You might want to change the 'core.wait(0.03);' line to another number, so
//     Stellarium has enough time to process and update before checking new positions.
//     This is dependent upon your computer's capabilities, since Stellarium does not
//     do things asynchronously for scripting.
//   * Run the script.
//   * You can change the year/month/day and Stellarium will automatically update
//     the time to the selected sun depression. Once it is finished getting to the time,
//     the selected object will be re-selected (the cross-hairs will reappear).
// ******************************************************************************************

objectToSelect = "Mars";   //SET THIS ONE (to "" if you want nothing selected)
gotoMorning = true;        //SET THIS ONE!
desiredDepression = 9.5;  //AND SET THIS ONE! The next chart is useful:

//These are the arcus visionis values for the planets, and an estimation for Sirius:
//The planetary values were taken from the Planetary, Lunar, and Stellar Visibility computer
//program, version 3.1.0, 2006, by Rainer Lange and Noel M. Swerdlow. The newest version
//should be at http://www.alcyone.de/planetary_lunar_and_stellar_visibility.html.
//
// Inner Planets   Morning First       Morning Last       Evening First       Evening Last
//  Mercury            13.0°               9.5°               10.5°              11.0°
//  Venus               5.7°               6.0°                6.0°               5.2°
//
//                Heliacal Rising    Heliacal Setting   Acronychal Rising   Cosmical Setting
// Object            (Morning)          (Evening)           (Evening)          (Morning)
//  Mars               14.5°              13.2°                6.0°               6.0°
//  Jupiter             9.3°               7.4°                6.0°               6.0°
//  Saturn             13.0°              10.0°                8.0°               8.0°
//  Sirius              7.8°               6.5°                4.0°               4.0°
//
// In addition, Civil Dusk = 0 - 6°, Nautical = 6 - 12°, Astronomic = 12 - 18°

desiredDepression = -desiredDepression;   //Enter it positively, and switch to negative here.
sunAzimuth = core.getObjectInfo("Sun").azimuth;
sunAlt = core.getObjectInfo("Sun").altitude;
//A 'catch up' time for Stellarium to do its work before re-querying attributes
waitTime = 0.03;

if (sunAzimuth >= 180 && sunAzimuth <= 360 && gotoMorning) {   //180 - 360 = western sun
   //We need to shift by half day.
   core.setDate("-12 hours");
   }
else if (sunAzimuth >= 0 && sunAzimuth <= 180 && !gotoMorning) {  //eastern sun
   core.setDate("+12 hours");
   }

core.wait(waitTime);  //Let computer catch up.
sunAzimuth = core.getObjectInfo("Sun").azimuth;
sunAlt = core.getObjectInfo("Sun").altitude;

// We now have 4 conditions:
// 1 - looking for morning, sun above desired condition
// 2 - looking for morning, sun below desired condition
// 3 - looking for evening, sun above desired condition
// 4 - looking for evening, sun below desired condition.

// For 1 and 4, the sun needs to go backward with respect to its normal forward movement.
// But each case stands on its own, because one coming from below, the other from above.

//So we can loop the entire chain, so the user can change the date and Stellarium
//will automatically update when change is made

lastDate = "dummy start date";
core.wait(waitTime);
justFinishedProcessing = false;

while (true) {
   specifiedDate = core.getDate();
   if (justFinishedProcessing) {
      lastDate = specifiedDate;
      justFinishedProcessing = false;
      //Set the crosshairs again, to tell it is done processing:
      core.selectObjectByName(objectToSelect, true);
      core.wait(0.3);
      core.setTimeRate(0); //Lock the sky in place, so we can see it unmoving!
      }
   if (specifiedDate != lastDate) {
      //Clear the crosshairs, so you can tell it is processing:
      core.selectObjectByName("", true);
      sunAlt = core.getObjectInfo("Sun").altitude;
      // Case 1:
      if (gotoMorning && sunAlt>desiredDepression) {
         //Go backward first:
         while (sunAlt>desiredDepression) {
            gotoTime("-10 minutes");
            }
         //Then forward:
         while (sunAlt<desiredDepression) {
            gotoTime("+1 minutes");
            }
         //You get the picture...
         while (sunAlt>desiredDepression) {
            gotoTime("-10 seconds");
            }
         while (sunAlt<desiredDepression) {
            gotoTime("+1 seconds");
            }
         while (sunAlt>desiredDepression) {
            gotoTime("-1 seconds");
            }
         sunAlt = desiredDepression;   //It has been done, so quit jimmying with it.
        }

      //Case 2, start at morning below
      else if (gotoMorning && sunAlt<desiredDepression) {
         //Go forward first:
         while (sunAlt<desiredDepression) {
            gotoTime("+10 minutes");
            }
         //Then backward:
         while (sunAlt>desiredDepression) {
            gotoTime("-1 minutes");
            }
         //You get the picture...
         while (sunAlt<desiredDepression) {
            gotoTime("+10 seconds");
            }
         while (sunAlt>desiredDepression) {
            gotoTime("-1 seconds");
            }
         sunAlt = desiredDepression;   //It has been done, so quit jimmying with it.
         }

      //Case 3, start at evening above
      else if (!gotoMorning && sunAlt>desiredDepression) {
         //Go forward first:
         while (sunAlt>desiredDepression) {
            gotoTime("+10 minutes");
            }
         //Then backward:
         while (sunAlt<desiredDepression) {
            gotoTime("-1 minutes");
            }
         //You get the picture...
         while (sunAlt>desiredDepression) {
            gotoTime("+10 seconds");
            }
         while (sunAlt<desiredDepression) {
            gotoTime("-1 seconds");
            }
          sunAlt = desiredDepression;   //It has been done, so quit jimmying with it.
        }

      //Case 4, start at evening below
      else if (!gotoMorning && sunAlt<desiredDepression) {
         //Go backward first:
         while (sunAlt<desiredDepression) {
            gotoTime("-10 minutes");
            }
         //Then forward:
         while (sunAlt>desiredDepression) {
            gotoTime("+1 minutes");
            }
         //You get the picture...
         while (sunAlt<desiredDepression) {
            gotoTime("-10 seconds");
            }
         while (sunAlt>desiredDepression) {
            gotoTime("+1 seconds");
            }
         sunAlt = desiredDepression;   //It has been done, so quit jimmying with it.
         }
      justFinishedProcessing = true;
      lastDate = specifiedDate;
      core.debug(sunAlt);

      //If you want to add a marker, for showing trajectory day-by-day:
      //alt = core.getObjectInfo(objectToSelect).altitude;
      //azi = core.getObjectInfo(objectToSelect).azimuth;
      //HighlightMgr.addPointAltAzi(alt, azi);
      //HighlightMgr.update(1440);
      //And later, to unhighlight it:
      //HighlightMgr.cleanHighlightList();
      // Unfortunately, highlights move with background, not stay at alt/azi!
      // To overcome this, you will need to store a list of alt/azi values, then
      // plot them at the end of a sequence.
      }
   }

function gotoTime(time) {
   core.setDate(time);
   core.wait(waitTime);
   sunAlt = core.getObjectInfo("Sun").altitude;
   }
gzotti commented 5 years ago

@alex-w Maybe just add a "load script from system scripts" button to the F12 script editor that always opens from the program folder, and have the "open" button look into %USERDATA%/scripts? The store button should default to %USERDATA%/scripts, but should remember the directory of the last "store" action. @NotSoRandomOne I still don't see how you lost that script, but thanks for this one, I will have a try soon. The issue around degree and question mark lies between Windows encoding and Unicode, I assume.

NotSoRandomOne commented 5 years ago

@gzotti : Hope you enjoy it! I'll open a proper bug report for the degree sign, so you can track it or close it, whatever you wish. I suspect it is a QT quirk.

NotSoRandomOne commented 5 years ago

Thank you, Alex! I look forward to playing with 19.2 when it is out! If you like playing with MIDI stuff, you are welcome to a copy of my editor: https://www.randommonkeyworks.com/medit_midi_sequencer/. Just let me know the email to send a code to. Have a great night!

NotSoRandomOne commented 5 years ago

PS - I updated the code for the sun depression script, just in case you picked it up earlier.

alex-w commented 5 years ago

Please check our weekly build - https://github.com/Stellarium/stellarium-data/releases/tag/beta

NotSoRandomOne commented 5 years ago

Playing with the build, it opens C:\Program Files\Graphic\Stellarium19\scripts whenever I go to open a script. It doesn't keep the last directory opened from. That is when using the upper left "Load Script From File" button.

alex-w commented 5 years ago

Please check Settings tab in Script Console

NotSoRandomOne commented 5 years ago

That will work! And the degree signs are fixed! Yay!

Have a great night!

NotSoRandomOne commented 5 years ago

One quick comment - each time I open Stellarium, including with this new build, I have to unselect "Show Meteor Showers." The setting doesn't stick when I do 'Configuration -> Save View' and 'Configuration -> Save Settings.' Is this on purpose?

alex-w commented 5 years ago

This is plugin, so, please use plugin’s tool for configuration and saving data

NotSoRandomOne commented 5 years ago

OK. Thanks. It isn't very intuitive, but if that's the best that can easily be done...

Again, have a great night!