Skip to content

Commit

Permalink
Merge pull request #83 from jpgill86/edit-metadata
Browse files Browse the repository at this point in the history
Add menu action for opening metadata in editor
  • Loading branch information
jpgill86 committed Jul 21, 2019
2 parents 4ae7bb0 + 262d8da commit 286f77a
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions neurotic/gui/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import os
import gc
import platform
import subprocess
import pkg_resources

import quantities as pq
Expand Down Expand Up @@ -55,7 +57,7 @@ def load(self):
try:
MetadataSelector.load(self)
except Exception as e:
print('Bad metadata file!', e)
print('Bad metadata file:', e)

if self.all_metadata is not None:

Expand Down Expand Up @@ -162,8 +164,8 @@ def __init__(self, file=None, initial_selection=None, lazy=True, theme='light',
if initial_selection is not None:
try:
self.metadata_selector.setCurrentRow(list(self.metadata_selector.all_metadata).index(initial_selection))
except (TypeError, ValueError):
print('Bad dataset key! Will ignore')
except (TypeError, ValueError) as e:
print('Bad dataset key, will ignore:', e)

def create_menus(self):
"""
Expand All @@ -176,6 +178,10 @@ def create_menus(self):
do_open_metadata.triggered.connect(self.open_metadata)
self.file_menu.addAction(do_open_metadata)

do_edit_metadata = QT.QAction('&Edit metadata', self, shortcut = 'Ctrl+E')
do_edit_metadata.triggered.connect(self.edit_metadata)
self.file_menu.addAction(do_edit_metadata)

do_reload_metadata = QT.QAction('&Reload metadata', self, shortcut = 'Ctrl+R')
do_reload_metadata.triggered.connect(self.metadata_selector.load)
self.file_menu.addAction(do_reload_metadata)
Expand Down Expand Up @@ -250,6 +256,27 @@ def open_metadata(self):
self.metadata_selector.file = file
self.metadata_selector.load()

def edit_metadata(self):
"""
Open the metadata file in an editor
"""

path = self.metadata_selector.file

try:

if platform.system() == "Windows":
os.startfile(path)
elif platform.system() == "Darwin":
subprocess.Popen(["open", path])
else:
subprocess.Popen(["xdg-open", path])

except FileNotFoundError as e:

print('The metadata file was not found:', e)
return

def download_files(self):
"""
Expand Down Expand Up @@ -299,9 +326,8 @@ def launch(self):

except FileNotFoundError as e:

print('Some files were not found locally and may need to be downloaded')
print(e)
return
print('Some files were not found locally and may need to be ' \
'downloaded:', e)

def show_about(self):
"""
Expand Down

0 comments on commit 286f77a

Please sign in to comment.