Commits

iorodeo committed 2816486 Draft

Modified so that program will run if h5py library is not present.

  • Participants
  • Parent commits 7b04643

Comments (0)

Files changed (2)

File mct_json_converter/main_window.py

 import sys
 import os
 import time
+import mct_json_converter
 from PyQt4 import QtCore
 from PyQt4 import QtGui
 from converter_ui import Ui_MainWindow
-from mct_json_converter import JSON_Converter 
 
 USER_HOME = os.getenv('USERPROFILE')
 if USER_HOME is None:
         else:
             self.directory = USER_HOME
         self.disableWidgetsOnEmpty()
+        if not mct_json_converter.haveh5py:
+            self.hdf5RadioButton.setEnabled(False)
 
     def connectActions(self):
         self.selectPushButton.clicked.connect(self.selectClicked)
 
     def selectClicked(self):
         if not os.path.isdir(self.directory):
-            self.directory = USER_HOME
-
+            self.directory = USER_HOME 
         fileNameList = QtGui.QFileDialog.getOpenFileNames(
                 self,
                 'Select JSON files for conversion',
         self.selectPushButton.setEnabled(True)
         self.clearPushButton.setEnabled(True)
         self.matRadioButton.setEnabled(True)
-        self.hdf5RadioButton.setEnabled(True)
+        if mct_json_converter.haveh5py:
+            self.hdf5RadioButton.setEnabled(True)
         self.fileListWidget.setEnabled(True)
         self.convertPushButton.setEnabled(True)
 
             self.statusbar.showMessage(statusMessage)
             self.repaint()
             try:
-                converter = JSON_Converter(filePath)
+                converter = mct_json_converter.JSON_Converter(filePath)
             except Exception, e:
                 message = 'Unable to convert file: {0}\n\n{1}'.format(fileName,str(e))
                 QtGui.QMessageBox.critical(self,'Error',message)

File mct_json_converter/mct_json_converter.py

 from __future__ import print_function
 import simplejson as json
-import h5py
 import numpy
 import scipy
 import scipy.io
 import os
+try:
+    import h5py
+    haveh5py = True
+except ImportError:
+    haveh5py = False
 
 class JSON_Converter(object):
 
         scipy.io.savemat(matFileName, {'data': dataDict}, oned_as='row')
             
     def writeH5File(self,h5FileName=None):
+        assert haveh5py, 'h5py library is not installed'
         assert self.dictOfArrays is not None, 'dictOfArrays is None'
         if h5FileName is None:
             h5FileName = self.getAutoFileName(ext='hdf5')