Skip to content

Commit

Permalink
Add folder argument to OpenFileDialog()
Browse files Browse the repository at this point in the history
  • Loading branch information
tritemio committed May 12, 2015
1 parent 40761fb commit da10924
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions fretbursts/utils/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,30 @@

from sys import executable
from subprocess import check_output
import contextlib
import os


def OpenFileDialog():
file = check_output([executable, __file__])
@contextlib.contextmanager
def chdir(dirname=None):
"""
Source: http://www.astropython.org/snippet/2009/10/chdir-context-manager
"""
curdir = os.getcwd()
try:
if dirname is not None:
os.chdir(dirname)
yield
finally:
os.chdir(curdir)


def OpenFileDialog(dirname=None):
with chdir(dirname):
file = check_output([executable, __file__])
return file.strip()


def gui_fname(dir=None):
"""
Select a file via a dialog and return the file name.
Expand Down

0 comments on commit da10924

Please sign in to comment.