Dialog that allows user to choose a working directory
197875
def get_DIR(self):
        
        dlg = wx.DirDialog(self, "Choose a directory:", defaultPath=self.currentDirectory,
                           style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON | wx.DD_CHANGE_DIR)
        ok = self.show_dlg(dlg)
        if ok == wx.ID_OK:
            new_WD = dlg.GetPath()
            dlg.Destroy()
        else:
            new_WD = os.getcwd()
            dlg.Destroy()
        return new_WD
1280840
def set_dir(self, dir_):
        """"""

        self.__lock_set_dir(dir_)
        self.__lock_auto_load()
        self.__lock_update_table()
        self.__update_info()
        self.__update_window_title()
1359275
def _interact_with_folder(self, output_folder, action):
        
        if not action in ('r', 'w'):
            raise ValueError("action must be either 'r' or 'w'.")
        for key, item in self.__dict__.items():
            if isinstance(item, dict):
                for side in ("left", "right"):
                    filename = os.path.join(output_folder,
                                            "{}_{}.npy".format(key, side))
                    if action == 'w':
                        np.save(filename, self.__dict__[key][side])
                    else:
                        self.__dict__[key][side] = np.load(filename)
            else:
                filename = os.path.join(output_folder, "{}.npy".format(key))
                if action == 'w':
                    np.save(filename, self.__dict__[key])
                else:
                    self.__dict__[key] = np.load(filename)
1152996
def mkdir(dir_path):
        # type: (AnyStr) -> None
        """"""
        if not os.path.isdir(dir_path) or not os.path.exists(dir_path):
            os.makedirs(dir_path)
116684
def prompt_gui(path):
    """"""

    import subprocess

    filepath, extension = os.path.splitext(path)
    basename = os.path.basename(filepath)
    dirname = os.path.dirname(filepath)

    retry_text = 'Sorry, please try again...'
    icon = 'video-x-generic'

    # detect and configure dialog program
    if have('yad'):
        args = ['yad',
                '--borders=5',
                '--entry',
                '--entry-label=Filename:',
                '--entry-text=' + basename,
                '--title=Batch Tool',
                '--window-icon=' + icon]
        retry_args = args + ['--text=<b>' + retry_text + '</b>',
                             '--text-align=center']

    elif have('zenity'):
        base = ['zenity',
                '--entry',
                '--entry-text=' + basename,
                '--title=Batch Tool',
                '--window-icon=info']
        args = base + ['--text=Filename:']
        retry_args = base + ['--text=' + retry_text]

    else:
        fatal('Please install yad (or zenity)')

    # display filename prompt
    try:
        new_basename = subprocess.check_output(
            args, universal_newlines=True).strip()
    except subprocess.CalledProcessError:
        sys.exit(1)

    # retry prompt if new filename already exists
    while os.path.exists(os.path.join(dirname, new_basename + extension)) and \
            new_basename != basename:
        try:
            new_basename = subprocess.check_output(
                retry_args, universal_newlines=True).strip()
        except subprocess.CalledProcessError:
            sys.exit(1)

    if new_basename == '':
        new_basename = basename

    return os.path.join(dirname, new_basename + extension)
78868
def popup(self, title, callfn, initialdir=None):
        """"""
        super(DirectorySelection, self).popup(title, callfn, initialdir)
319470
def select_multi_directory_dialog():
    
    import wx.lib.agw.multidirdialog as MDD

    app = wx.App(0)
    dlg = MDD.MultiDirDialog(None, title="Select directories", defaultPath=os.getcwd(),
                             agwStyle=MDD.DD_MULTIPLE | MDD.DD_DIR_MUST_EXIST)

    if dlg.ShowModal() != wx.ID_OK:
        dlg.Destroy()
        return

    paths = dlg.GetPaths()

    dlg.Destroy()
    app.MainLoop()

    return paths
360638
def action_import_folder(location):
    """"""

    if os.path.isdir(location):
        onlyfiles = [
            f for f in os.listdir(location)
            if os.path.isfile(os.path.join(location, f))
        ]
        for file in onlyfiles:
            if not file.startswith("."):
                filepath = os.path.join(location, file)
                # print(Fore.RED + "\n---------\n" + filepath + "\n---------" + Style.RESET_ALL)
                click.secho(
                    "\n---------\n" + filepath + "\n---------", fg='red')
                return action_import(filepath)
    else:
        printDebug("Not a valid directory", "important")
        return None
1154992
def pwd(editor, location):
    "  "
    try:
        os.chdir(location)
    except OSError as e:
        editor.show_message('{}'.format(e))
306428
def edit_tree_item(self):
        

        def open_path_dialog(path):
            """
            opens a file dialog to get the path to a file and
            """
            dialog = QtWidgets.QFileDialog()
            dialog.setFileMode(QtWidgets.QFileDialog.Directory)
            dialog.setOption(QtWidgets.QFileDialog.ShowDirsOnly, True)
            path = dialog.getExistingDirectory(self, 'Select a folder:', path)

            return path

        tree = self.sender()

        if tree == self.tree_gui_settings:

            index = tree.selectedIndexes()[0]
            model = index.model()

            if index.column() == 1:
                path = model.itemFromIndex(index).text()
                path = str(open_path_dialog(path))

                key = str(model.itemFromIndex(model.index(index.row(), 0)).text())

                if path != "":
                    self.gui_settings.update({key : str(path)})
                    self.fill_treeview(tree, self.gui_settings)
110871
def goToDirectory(alias):
	""""""
	if not settings.platformCompatible():
		return False
	data = pickle.load(open(settings.getDataFile(), "rb"))
	try:
		data[alias]
	except KeyError:
		speech.fail("Sorry, it doesn't look like you have saved " + alias + " yet.")
		speech.fail("Go to the directory you'd like to save and type 'hallie save as " + alias + "\'")
		return
	try:
		(output, error) = subprocess.Popen(["osascript", "-e", CHANGE_DIR % (data[alias])], stdout=subprocess.PIPE).communicate()
	except:
		speech.fail("Something seems to have gone wrong. Please report this error to michaelmelchione@gmail.com.")
		return
	speech.success("Successfully navigating to " + data[alias])
1001732
def mkdir(dir, enter):
    

    if not os.path.exists(dir):
        os.makedirs(dir)
1229639
def browse_clicked(self, widget, data=None):
        
        text = self.gui_helper.create_file_chooser_dialog("Please select directory", self.path_window)
        if text is not None:
            data.set_text(text)
752739
def on_change_dir_button(self, event=None):
        
        currentDirectory = self.WD #os.getcwd()
        change_dir_dialog = wx.DirDialog(self.panel,
                                         "Choose your working directory to create or edit a MagIC contribution:",
                                         defaultPath=currentDirectory,
                                         style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON | wx.DD_CHANGE_DIR)
        result = change_dir_dialog.ShowModal()
        if result == wx.ID_CANCEL:
            return
        if result == wx.ID_OK:
            self.WD = change_dir_dialog.GetPath()
            self.dir_path.SetValue(self.WD)
        change_dir_dialog.Destroy()
        self.get_wd_data()
787508
def work_dir(path):
    '''
    

    '''
    starting_directory = os.getcwd()
    try:
        os.chdir(path)
        yield
    finally:
        os.chdir(starting_directory)
529670
@Override
    public File showDialog(WindowBasedTextGUI textGUI) {
        selectedFile = null;
        super.showDialog(textGUI);
        return selectedFile;
    }
1067789
def set_working_directory(self, path):
        
        """
        _complain_ifclosed(self.closed)
        return self.fs.set_working_directory(path)