Esempio n. 1
0
 def copy_system_colormaps(self):
     """Verify system colormaps are copied to user's folder"""
     colormaps_folder = os.path.join(pathfinder.app_path(), 'colormaps')
     colormaps = os.listdir(colormaps_folder)
     self.remove_system_files(colormaps, pathfinder.colormaps_path())
     self.model.copy_system_colormaps()
     for cmap in colormaps:
         installed_cmap = os.path.join(pathfinder.colormaps_path(), cmap)
         self.assertTrue(os.path.exists(installed_cmap))
Esempio n. 2
0
 def copy_system_colormaps(cls):
     """Copies matplotlib colormaps that ship with the application to the user's colormaps folder."""
     colormaps_folder = os.path.join(pathfinder.app_path(), 'colormaps')
     colormaps = os.listdir(colormaps_folder)
     for colormap_file in colormaps:
         shutil.copy(os.path.join(colormaps_folder, colormap_file),
                     pathfinder.colormaps_path())
Esempio n. 3
0
 def check_user_path(self):
     """Verify user data folders were created"""
     data_folders = [pathfinder.user_path(), pathfinder.data_path(),
                     pathfinder.thumbnails_path(), pathfinder.gates_path(),
                     pathfinder.plugins_path(), pathfinder.podmodels_path(),
                     pathfinder.colormaps_path(), pathfinder.batchoutput_path()]
     self.model.check_user_path()
     for folder in data_folders:
         self.assertTrue(os.path.exists(folder))
Esempio n. 4
0
 def check_user_path(self):
     """Verify user data folders were created"""
     data_folders = [pathfinder.user_path(), pathfinder.data_path(),
                     pathfinder.thumbnails_path(), pathfinder.gates_path(),
                     pathfinder.plugins_path(), pathfinder.podmodels_path(),
                     pathfinder.adamodels_path(), pathfinder.colormaps_path(),
                     pathfinder.batchoutput_path()]
     self.model.check_user_path()
     for folder in data_folders:
         self.assertTrue(os.path.exists(folder))
Esempio n. 5
0
 def get_user_colormaps(self, cmap_fldr=pathfinder.colormaps_path()):
     """Returns a list of user-defined colormaps in the specified folder (defaults to
     standard colormaps folder if not specified)."""
     user_colormaps = []
     for root, dirs, files in os.walk(cmap_fldr):
         for name in files:
             with open(os.path.join(root, name), "r") as fidin:
                 cmap_dict = json.load(fidin)
                 user_colormaps.append(cmap_dict.get('name', name))
     return user_colormaps
Esempio n. 6
0
 def get_user_colormaps(self, cmap_fldr=pathfinder.colormaps_path()):
     """Returns a list of user-defined colormaps in the specified folder (defaults to
     standard colormaps folder if not specified)."""
     user_colormaps = []
     for root, dirs, files in os.walk(cmap_fldr):
         for name in files:
             with open(os.path.join(root, name), "r") as fidin:
                 cmap_dict = json.load(fidin)
                 user_colormaps.append(cmap_dict.get('name', name))
     return user_colormaps
 def test_save_colormap(self):
     """Verify saving a colormap"""
     shipped_colormaps_folder = os.path.join(pathfinder.app_path(), 'colormaps')
     shipped_colormaps = os.listdir(shipped_colormaps_folder)
     for shipped_colormap in shipped_colormaps:
         shipped_colormap_file = os.path.join(shipped_colormaps_folder, shipped_colormap)
         with open(shipped_colormap_file, "r") as fidin:
             cmap_dict = json.load(fidin)
             self.model.save_colormap(cmap_dict)
             cmap_file = os.path.join(pathfinder.colormaps_path(), cmap_dict['name'])
             self.assertTrue(os.path.exists(cmap_file))
Esempio n. 8
0
 def get_cmap(self, cmap_name, cmap_folder=pathfinder.colormaps_path()):
     """Returns the matplotlib colormap of the specified name - if not found in the predefined
     colormaps, searches for the colormap in the specified folder (defaults to standard colormaps
     folder if not specified)."""
     user_colormaps = self.get_user_colormaps(cmap_folder)
     system_colormaps = self.get_system_colormaps()
     if cmap_name in system_colormaps:
         return cm.get_cmap(cmap_name)
     elif cmap_name in user_colormaps:
         cmap_file = os.path.join(cmap_folder, cmap_name)
         cmap = self.load_colormap(cmap_file)
         return cmap
 def get_cmap(self, cmap_name, usercmaps_folder=pathfinder.colormaps_path()):
     """Returns a matplotlib colormap of specified name cmap_name, searching the predefined
     matplotlib colormaps first.  If not found, attempts to search for JSON file cmap_name in
     specified folder (defaults to app's colormaps folder) for valid colormap.  Returns None
     if no valid colormap could be found."""
     system_colormaps = [m for m in cm.datad]
     if cmap_name in system_colormaps:
         return cm.get_cmap(cmap_name)
     for root, dirs, files in os.walk(usercmaps_folder):
         if cmap_name in files:
             return self.create_cmap(self.get_cmap_dict(os.path.join(root, cmap_name)))
     return None
Esempio n. 10
0
 def get_cmap(self, cmap_name, cmap_folder=pathfinder.colormaps_path()):
     """Returns the matplotlib colormap of the specified name - if not found in the predefined
     colormaps, searches for the colormap in the specified folder (defaults to standard colormaps
     folder if not specified)."""
     user_colormaps = self.get_user_colormaps(cmap_folder)
     system_colormaps = self.get_system_colormaps()
     if cmap_name in system_colormaps:
         return cm.get_cmap(cmap_name)
     elif cmap_name in user_colormaps:
         cmap_file = os.path.join(cmap_folder, cmap_name)
         cmap = self.load_colormap(cmap_file)
         return cmap
Esempio n. 11
0
    def save_colormap(self, cmap_dict):
        """Saves a properly-formatted colormap dict as a new user-defined colormap.

        keys:values
        'name': name of the new colormap (str)
        'type': one of 'linear' or 'list'.  A linear colormap creates a gradient by linearly interpolating between
        colors; a list colormap uses the supplied colors as the colormap without interpolation.
        'colors': a list of tuples that define the colors.  Each color tuple is a three-element RGB (R,G,B) where
        each element is between 0 and 1.
        """
        cmap_fname = os.path.join(pathfinder.colormaps_path(), cmap_dict['name'])
        with open(cmap_fname, "w") as fidout:
            json.dump(cmap_dict, fidout)
Esempio n. 12
0
    def save_colormap(self, cmap_dict):
        """Saves a properly-formatted colormap dict as a new user-defined colormap.

        keys:values
        'name': name of the new colormap (str)
        'type': one of 'linear' or 'list'.  A linear colormap creates a gradient by linearly interpolating between
        colors; a list colormap uses the supplied colors as the colormap without interpolation.
        'colors': a list of tuples that define the colors.  Each color tuple is a three-element RGB (R,G,B) where
        each element is between 0 and 1.
        """
        cmap_fname = os.path.join(pathfinder.colormaps_path(),
                                  cmap_dict['name'])
        with open(cmap_fname, "w") as fidout:
            json.dump(cmap_dict, fidout)
Esempio n. 13
0
 def test_save_colormap(self):
     """Verify saving a colormap"""
     shipped_colormaps_folder = os.path.join(pathfinder.app_path(),
                                             'colormaps')
     shipped_colormaps = os.listdir(shipped_colormaps_folder)
     for shipped_colormap in shipped_colormaps:
         shipped_colormap_file = os.path.join(shipped_colormaps_folder,
                                              shipped_colormap)
         with open(shipped_colormap_file, "r") as fidin:
             cmap_dict = json.load(fidin)
             self.model.save_colormap(cmap_dict)
             cmap_file = os.path.join(pathfinder.colormaps_path(),
                                      cmap_dict['name'])
             self.assertTrue(os.path.exists(cmap_file))
Esempio n. 14
0
 def check_user_path(cls):
     """Verify that user data folders exist.  Creates
     any missing folders."""
     user_folder = pathfinder.user_path()
     data_folder = pathfinder.data_path()
     thumbnail_folder = pathfinder.thumbnails_path()
     plugins_folder = pathfinder.plugins_path()
     podmodels_folder = pathfinder.podmodels_path()
     adamodels_folder = pathfinder.adamodels_path()
     gates_folder = pathfinder.gates_path()
     colormaps_folder = pathfinder.colormaps_path()
     batch_folder = pathfinder.batchoutput_path()
     for fldr in (user_folder, data_folder, thumbnail_folder, plugins_folder, podmodels_folder, gates_folder,
         adamodels_folder, colormaps_folder, batch_folder):
         if not os.path.exists(fldr):
             os.makedirs(fldr)
Esempio n. 15
0
 def check_user_path(cls):
     """Verify that user data folders exist.  Creates
     any missing folders."""
     user_folder = pathfinder.user_path()
     data_folder = pathfinder.data_path()
     thumbnail_folder = pathfinder.thumbnails_path()
     plugins_folder = pathfinder.plugins_path()
     podmodels_folder = pathfinder.podmodels_path()
     gates_folder = pathfinder.gates_path()
     colormaps_folder = pathfinder.colormaps_path()
     batch_folder = pathfinder.batchoutput_path()
     for fldr in (user_folder, data_folder, thumbnail_folder,
                  plugins_folder, podmodels_folder, gates_folder,
                  colormaps_folder, batch_folder):
         if not os.path.exists(fldr):
             os.makedirs(fldr)
Esempio n. 16
0
def deleted_user_path():
    """Utility function to delete empty folders in the user data folders,
    used to verify that MainModel will recreate missing folders as required.
    Returns a list of folders successfully deleted or None if no folders
    were deleted."""
    data_folders = [pathfinder.user_path(), pathfinder.data_path(), pathfinder.thumbnails_path(),
                    pathfinder.plugins_path(), pathfinder.colormaps_path()]
    deleted_folders = []
    for folder in data_folders:
        exists_and_empty = os.path.exists(folder) and os.listdir(folder) == []
        if exists_and_empty:
            try:
                os.rmdir(folder)
                deleted_folders.append(folder)
            except WindowsError: # folder in use (Explorer, cmd, etc.)
                pass
    if deleted_folders:
        return deleted_folders
    return None
Esempio n. 17
0
def deleted_user_path():
    """Utility function to delete empty folders in the user data folders,
    used to verify that MainModel will recreate missing folders as required.
    Returns a list of folders successfully deleted or None if no folders
    were deleted."""
    data_folders = [pathfinder.user_path(), pathfinder.data_path(), pathfinder.thumbnails_path(),
                    pathfinder.plugins_path(), pathfinder.podmodels_path(), pathfinder.adamodels_path(),
                    pathfinder.colormaps_path()]
    deleted_folders = []
    for folder in data_folders:
        exists_and_empty = os.path.exists(folder) and os.listdir(folder) == []
        if exists_and_empty:
            try:
                os.rmdir(folder)
                deleted_folders.append(folder)
            except WindowsError: # folder in use (Explorer, cmd, etc.)
                pass
    if deleted_folders:
        return deleted_folders
    return None
Esempio n. 18
0
 def test_colormaps_path(self):
     """Verify returning correct path to colormaps"""
     colormaps_path = os.path.join(self.user_path, "colormaps")
     self.assertEqual(colormaps_path, pathfinder.colormaps_path())
Esempio n. 19
0
 def test_colormaps_path(self):
     """Verify returning correct path to colormaps"""
     colormaps_path = os.path.join(self.user_path, "colormaps")
     self.assertEqual(colormaps_path, pathfinder.colormaps_path())
Esempio n. 20
0
 def copy_system_colormaps(cls):
     """Copies matplotlib colormaps that ship with the application to the user's colormaps folder."""
     colormaps_folder = os.path.join(pathfinder.app_path(), 'colormaps')
     colormaps = os.listdir(colormaps_folder)
     for colormap_file in colormaps:
         shutil.copy(os.path.join(colormaps_folder, colormap_file), pathfinder.colormaps_path())