Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions imagepy/core/util/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def add_recent(path):
idx = recent.index(path)
recent.insert(0, recent.pop(idx))
rlist.insert(0, rlist.pop(idx))
else:
else:
recent.insert(0, path)
rlist.insert(0, f(path))
if len(recent)>=5:
Expand All @@ -40,11 +40,18 @@ def add_recent(path):
ConfigManager.set('recent', recent)
IPy.curapp.reload_plugins()

def make_wildcard(file_pattern):
if isinstance(file_pattern, str):
return '%s files (*.%s)|*.%s'%(file_pattern.upper(), file_pattern, file_pattern)
else:
extensions = ";".join(["*." + x for x in file_pattern[1]])
return '%s files (*.%s)|*.%s'%(file_pattern[0].upper(), extensions, extensions)

class Reader(Free):
para = {'path':''}

def show(self):
filt = '|'.join(['%s files (*.%s)|*.%s'%(i.upper(),i,i) for i in self.filt])
filt = '|'.join([make_wildcard(i) for i in self.filt])
return IPy.getpath('Open..', filt, 'open', self.para)

#process
Expand All @@ -58,7 +65,7 @@ def run(self, para = None):
a, b = os.path.splitext(fn)
fn, fe = a, b+fe
read = ReaderManager.get(fe[1:], None)
if read is None:
if read is None:
return IPy.alert('No reader found for %s'%fe[1:])
view = ViewerManager.get(fe[1:])

Expand All @@ -72,7 +79,7 @@ class Writer(Simple):
para={'path':root_dir}

def show(self):
filt = '|'.join(['%s files (*.%s)|*.%s'%(i.upper(),i,i) for i in self.filt])
filt = '|'.join([make_wildcard(i) for i in self.filt])
return IPy.getpath('Save..', filt, 'save', self.para)

#process
Expand All @@ -82,4 +89,4 @@ def run(self, ips, imgs, para = None):
write = WriterManager.get(fe[1:], 'img')
write2 = write or WriterManager.get(fe[1:], 'imgs')
print(write2, write)
write2(para['path'], imgs if write is None else ips.img)
write2(para['path'], imgs if write is None else ips.img)
8 changes: 4 additions & 4 deletions imagepy/menus/File/TIF/tif3d_plgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Save(fileio.Writer):
title = 'TIF 3D Save'
filt = ['TIF']
filt = [('TIF', ('TIF','TIFF', 'tif', 'tiff'))]
note = ['all', 'stack3d']

#process
Expand All @@ -14,13 +14,13 @@ def run(self, ips, imgs, para = None):

class Open(fileio.Reader):
title = 'TIF 3D Open'
filt = ['TIF']
filt = [('TIF', ('TIF','TIFF', 'tif', 'tiff'))]

#process
def run(self, para = None):
imgs = imread(para['path']).transpose(2,0,1)
fp, fn = os.path.split(para['path'])
fn, fe = os.path.splitext(fn)
fn, fe = os.path.splitext(fn)
IPy.show_img(imgs, fn)

plgs = [Open, Save]
plgs = [Open, Save]
6 changes: 3 additions & 3 deletions imagepy/menus/File/TIF/tif_plgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

class OpenFile(fileio.Reader):
title = 'TIF Open'
filt = ['TIF']
filt = [('TIF', ('TIF','TIFF', 'tif', 'tiff'))]

class SaveFile(fileio.Writer):
title = 'TIF Save'
filt = ['TIF']
filt = [('TIF', ('TIF','TIFF', 'tif', 'tiff'))]

plgs = [OpenFile, SaveFile]
plgs = [OpenFile, SaveFile]