py4dstem / py4DSTEM

GNU General Public License v3.0
201 stars 137 forks source link

GUI File selector for read and save #419

Open alex-rakowski opened 1 year ago

alex-rakowski commented 1 year ago

Is your feature request related to a problem? Please describe. Loading/saving files could be easier for some users if they had a GUI to handle paths Describe the solution you'd like

Pop up window that allows file navigation through system menu

Additional context Basic code is something like

from tkinter import Tk
from tkinter.filedialog import askopenfilename, askopenfilenames, asksaveasfile

Tk().withdraw()
filename = askopenfilename()

I think the py4DSTEM.read() and py4DSTEM.save() functions should be altered so if called with no file path arguments it defaults to this method, rather than having an additional methods like ~ py4DSTEM.read_gui()

alex-rakowski commented 1 year ago

save func alterations:

def write(
    filepath,
    data,
    mode = 'w',
    emdpath = None,
    tree = True,
    ):

would need to be rewritten as:

def write(
    data,
    filepath = None,
    mode = 'w',
    emdpath = None,
    tree = True,
    ):

        ...

    if filepath is None:
      Tk().withdraw()
      filepath = asksavefilename()
   ... 

read func alterations:

    filepath: Union[str,Path],
    datapath: Optional[str] = None,
    tree: Optional[Union[bool,str]] = True,
    verbose: Optional[bool] = False,
    **kwargs,
    ):

would need to be rewritten as:

    filepath: Union[str,Path] = None, 
    datapath: Optional[str] = None,
    tree: Optional[Union[bool,str]] = True,
    verbose: Optional[bool] = False,
    **kwargs,
    ):

    ...

    if filepath is None:
      Tk().withdraw()
      filepath = askopenfilename()
   ... 

@bsavitzky do you this would have any weird knock on effects? Particularly on the emdfile side.

bsavitzky commented 1 year ago

Summarizing dev team discussion:

The main concern folks have it adding tkinter as a dependency, and whether this will cause distribution issues. Some additional clarification about possible issues here would help.

This feature likely would not work under some configurations - e.g. running py4DSTEM through an ssh tunnel. If we move forward with this, let's make sure to use a try/except statement and throw a sensible error in cases where this fails.