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

Unable to save workspace on Linux #7196

Closed
hiteshnitetc opened this issue May 24, 2018 · 28 comments · Fixed by #17790
Closed

Unable to save workspace on Linux #7196

hiteshnitetc opened this issue May 24, 2018 · 28 comments · Fixed by #17790

Comments

@hiteshnitetc
Copy link

Problem Description

Unable to save workspace
screenshot from 2018-05-24 17-15-10

What steps will reproduce the problem?

Just create a python list, and try to save using save data icon

Package Versions

  • Spyder version: 3.2.8
  • Python version: 3.6.3
  • Qt version: 5.6.2
  • PyQt5 version: 5.6
  • Operating system: Linux 4.13.0-43-generic

Dependencies

pyflakes >=0.6.0 :  1.5.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.20.1 (OK)
numpy >=1.7      :  1.13.3 (OK)
sphinx >=0.6.6   :  1.5.6 (OK)
rope >=0.9.4     :  0.9.4-1 (OK)
jedi >=0.9.0     :  0.10.2 (OK)
psutil >=0.3     :  5.2.2 (OK)
nbconvert >=4.0  :  5.1.1 (OK)
sympy >=0.7.3    :  1.0 (OK)
cython >=0.21    :  0.25.2 (OK)
qtconsole >=4.2.0:  4.3.0 (OK)
IPython >=4.0    :  5.3.0 (OK)
pylint >=0.25    :  1.6.4 (OK)
@hiteshnitetc
Copy link
Author

I also reported this issue 7 months back (#5647), till now not getting solution. This is creating big trouble for me. Please help.

@hiteshnitetc
Copy link
Author

And save option of spyder works for windows, but not working on ubuntu.

@CAM-Gerlach
Copy link
Member

CAM-Gerlach commented May 24, 2018

Yup, I can reproduce this running the latest 3.x on Fedora 28 LXQt, while it works just fine on my Windows 8.1 machine. Thanks for posting a minimal example to help isolate it.

@CAM-Gerlach
Copy link
Member

CAM-Gerlach commented May 24, 2018

@ccordoba12 I successfully isolated the problem. It simply appears to be that the file extension .spydata is not getting added to the filename on Linux, since if I manually add it to the filename in the save file dialog, (test_data.spydata) then everything saves and loads perfectly. We can just check in namespacebrowser if filename doesn't have an extension, and if not, then we add it before trying to save. @ccordoba12 that sound like a good plan or is there a better way?

@CAM-Gerlach CAM-Gerlach added this to the v3.3 milestone May 24, 2018
@CAM-Gerlach CAM-Gerlach self-assigned this May 24, 2018
@ccordoba12
Copy link
Member

Yeah, it sounds good. Please proceed with it.

@hiteshnitetc
Copy link
Author

hiteshnitetc commented May 25, 2018 via email

@CAM-Gerlach
Copy link
Member

CAM-Gerlach commented May 25, 2018

@hiteshnitetc As I mentioned,

if [you] manually add it to the filename in the save file dialog, (test_data.spydata) then everything saves and loads perfectly.

so just type .spydata after the filename (whatever you want to name it; I used test_data above) when saving and that'll fix it for now. We'll have a permanent fix in hopefully in the next version; its a very easy solution, I just need to get to it.

@hiteshnitetc
Copy link
Author

@CAM-Gerlach Very thnx. You saved my lot of time. Otherwise i was saving all variable using pickle. I am wondering, why this simple solution i didn't try.

@CAM-Gerlach
Copy link
Member

Glad to hear it! Sometimes the simplest solutions are the easiest to miss; I know that all too well myself.

@ccordoba12 ccordoba12 changed the title Unable to save workspace Unable to save workspace on Linux May 28, 2018
@ccordoba12 ccordoba12 modified the milestones: v3.3, v3.3.1 Jun 3, 2018
@ccordoba12 ccordoba12 modified the milestones: v3.3.1, v3.3.2 Jul 15, 2018
@ccordoba12 ccordoba12 modified the milestones: v3.3.2, v3.3.3 Oct 20, 2018
@ccordoba12 ccordoba12 modified the milestones: v3.3.3, v4.0beta2 Jan 7, 2019
@ccordoba12 ccordoba12 modified the milestones: v4.0beta2, important Feb 24, 2019
@bcolsen
Copy link
Member

bcolsen commented Feb 25, 2019

@CAM-Gerlach I don't know if you have worked on this one yet but I did some research and might have a fix. You can assign me this one if you don't want it.

@CAM-Gerlach
Copy link
Member

@bcolsen It should be a pretty simple fix (see my comment above outlining the solution) and I've been pretty busy working on a big grant proposal lately, so you're welcome to go for it.

@bcolsen bcolsen self-assigned this Feb 25, 2019
@bcolsen
Copy link
Member

bcolsen commented Feb 25, 2019

It's not too bad, but do need a pop up so it doesn't silently overwrite files.

@hiteshnitetc
Copy link
Author

@CAM-Gerlach Now i am unable save data from variable explorer after adding .spydata to file name.

@CAM-Gerlach
Copy link
Member

What version of Spyder, Spyder-Kernels and Python are you using? What changed since it worked? What specific error messages/behavior are you getting? Have you upgraded to the latest version of Spyder and Spyder-Kernels (3.3.3 and 0.4.2)? We've implemented some significant improvements in saving and loading .spydata files.

Now

After what, specifically? What did you change/update that resulted in it not working

after adding .spydata to file name.

Did you try not adding .spydata?

@hiteshnitetc
Copy link
Author

@CAM-Gerlach previously i was using spyder 3.3 , now i updated to 3.3 , it's working , thnx.

@CAM-Gerlach
Copy link
Member

previously i was using spyder 3.3 now i updated to 3.3

@hiteshnitetc ?

@hiteshnitetc
Copy link
Author

@CAM-Gerlach ooh really sorry for typo. i was using 3.2 now upgraded to 3.3

@CAM-Gerlach
Copy link
Member

@hiteshnitetc Those still aren't real versions, sorry. Do you mean 3.3.2 to 3.3.3? Or 3.2.x to 3.3.x?

@hiteshnitetc
Copy link
Author

hiteshnitetc commented Mar 27, 2019 via email

@arteagac
Copy link
Contributor

Hi @bcolsen and @ccordoba12,
I could give this one a try if you guys agree.

@CAM-Gerlach
Copy link
Member

@arteagac We're always happy for some help! Feel free to go ahead with a PR, and let us know if you have questions. Thanks!

@arteagac
Copy link
Contributor

Awesome! I'll work on it.

@bcolsen
Copy link
Member

bcolsen commented Jul 23, 2020

@arteagac This is a Spyder wide problem that will happen with every save dialogue on linux not just with the data explorer. The qt file picker(only used in linux) doesn't support adding extensions to files based on the extension.

To fix it we could:

  1. Contribute the feature upstream to qt https://bugreports.qt.io/plugins/servlet/mobile#issue/QTBUG-27186

  2. Write a wrapper around the save file dialogue function to add the extension from filterSelected and check for over writes. I couldn't get this to check the name with the file dialogue still open. It would be annoying to click no to the overwrite and then be left without a saved file of a dilague to change it.

  3. Figure out how to get native(at least gnome and kde) file selection dialogues on Linux through anaconda and not use the silly qtfiledialogue that rarely actually ever gets used.(I would absolutely love this)

  4. Do something else that I didn't think of :-)

This is why I haven't fixed this yet. I hope this helps you find a few directions to look.

@arteagac
Copy link
Contributor

Hi @bcolsen, Thank you for such a detailed description of potential fixes for the bug. I think I will start exploring the options 2 and 3 you mentioned and I will let you know how it goes. Thanks again.

@arteagac
Copy link
Contributor

arteagac commented Aug 6, 2020

Hi @bcolsen,
I did some research and I can see why the issue is tricky.
Here are some thoughts about the potential fixes you mentioned:

  1. A related Qt bug report says the issue was fixed on Qt v5.2.0 https://bugreports.qt.io/browse/QTBUG-33156. However, perhaps it does not apply to Linux as we are clearly still facing this issue.
  2. This seems like a feasible solution. However, you are right about the undesirable overwrite behavior. To address this, after the user selects the file and the FileDialog closes, we could show a dialog asking the user if they really want to overwrite the existing file. See the code at the end of this comment. However, this does not seem like an elegant solution. 
  3. I did some research but I could not find a solution for a native KDE/GNOME file dialog. We would need to involve some GTK libraries, which does not seem convenient.

I am not really sure how to proceed. Do you have any suggestions? My short experience suggests that perhaps option 2 is better than nothing but I am not really convinced.

#################################################################
###### CODE FOR OPTION #2 (Wrapper that appends extension) ######
#################################################################
import sys
import os.path
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog, QMessageBox

class App(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
    
    def initUI(self):
        self.setWindowTitle('File dialogs')
        self.setGeometry(10, 10, 640, 480)
        fileName, selFilter = QFileDialog.getSaveFileName(self,"Save","","Text Files (*.txt)")
        fileName += ".txt"
        if os.path.exists(fileName):
            reply = QMessageBox.question(self, 'Message',"Are you sure you want to overwrite "+fileName+"?", QMessageBox.Yes, QMessageBox.No)
            print("File overwritten" if reply == QMessageBox.Yes else "File NOT overwritten")
        print(fileName)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

@bcolsen
Copy link
Member

bcolsen commented Aug 10, 2020

I played around with native Gtk save dialogs and they don't add the file extensions either.

I think option 2 is the best way to go currently, and your simple method outlined above is the way to go. I have 3 suggestions:

  1. You should only add an extension if the user doesn't have one. I think this is how it works on windows. If the extension is "wrong" and that matters (for saving in the variable explorer it does matter), give an error that the extension must be one of....
  2. If the user doesn't have an extension then use the extension returned by the selfilter
  3. If there is an error in saving and the user says "no" to the suggested overwrite open the save dialogue again with their previous filename to allow the user to make a change to the name to remove the name overlap.

@arteagac
Copy link
Contributor

Thanks @bcolsen,
I will go ahead and implement it considering your suggestions.
One quick additional question, the extension that selfilter returns is in a text format like "Spyder data files (*.spydata)". I can extract the extension from this string using a regular expression or somethig similar; however, I am not sure if this is the right approach. Is there a better way to do this or I need to use text manipulation to extract such extension?

@bcolsen
Copy link
Member

bcolsen commented Aug 11, 2020

One quick additional question, the extension that selfilter returns is in a text format like "Spyder data files (*.spydata)". I can extract the extension from this string using a regular expression or something similar; however, I am not sure if this is the right approach. Is there a better way to do this or I need to use text manipulation to extract such extension?

Those strings are produced from a dictionary in iofunctions so it should be fine extract the extension from the string. I would just use rfind and some string indexing to get the extension. It should always be of the form "(*.XXXXXX)" at the end of the sting.

maurerle added a commit to maurerle/spyder that referenced this issue Jul 14, 2022
- rename ext variable to more explicit extension
- rename ext in iimport_data to extension too for consistency
- add comment for related issue spyder-ide#7196
maurerle added a commit to maurerle/spyder that referenced this issue Jul 14, 2022
- rename ext variable to more explicit extension
- rename ext in iimport_data to extension too for consistency
- add comment for related issue spyder-ide#7196
@ccordoba12 ccordoba12 modified the milestones: important, v5.3.3 Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants