diff --git a/app.py b/app.py index 9049972..795684f 100644 --- a/app.py +++ b/app.py @@ -65,21 +65,9 @@ import invesalius.i18n as i18n import invesalius.session as ses import invesalius.utils as utils -FS_ENCODE = sys.getfilesystemencoding() - -if sys.platform == 'win32': - from invesalius.expanduser import expand_user - try: - USER_DIR = expand_user() - except: - USER_DIR = utils.decode(os.path.expanduser('~'), FS_ENCODE) -else: - USER_DIR = utils.decode(os.path.expanduser('~'),FS_ENCODE) +from invesalius import inv_paths -USER_INV_DIR = os.path.join(USER_DIR, u'.invesalius') -USER_PRESET_DIR = os.path.join(USER_INV_DIR, u'presets') -USER_RAYCASTING_PRESETS_DIRECTORY = os.path.join(USER_PRESET_DIR, u'raycasting') -USER_LOG_DIR = os.path.join(USER_INV_DIR, u'logs') +FS_ENCODE = sys.getfilesystemencoding() # ------------------------------------------------------------------ @@ -510,17 +498,14 @@ if __name__ == '__main__': os.chdir(path) - # Create raycasting presets' folder, if it doens't exist - if not os.path.isdir(USER_RAYCASTING_PRESETS_DIRECTORY): - os.makedirs(USER_RAYCASTING_PRESETS_DIRECTORY) - - # Create logs' folder, if it doesn't exist - if not os.path.isdir(USER_LOG_DIR): - os.makedirs(USER_LOG_DIR) + if not inv_paths.USER_INV_DIR.exists(): + inv_paths.create_conf_folders() + if inv_paths.OLD_USER_INV_DIR.exists(): + inv_paths.copy_old_files() if hasattr(sys,"frozen") and sys.frozen == "windows_exe": # Set system standard error output to file - path = os.path.join(USER_LOG_DIR, u"stderr.log") + path = inv_paths.USER_LOG_DIR.join("stderr.log") sys.stderr = open(path, "w") # Add current directory to PYTHONPATH, so other classes can diff --git a/invesalius/constants.py b/invesalius/constants.py index 575130b..36fa3ac 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -24,6 +24,7 @@ import wx import itertools from invesalius import utils +from invesalius import inv_paths #from invesalius.project import Project INVESALIUS_VERSION = "3.1.1" @@ -335,59 +336,13 @@ REDUCE_IMAGEDATA_QUALITY = 0 # PATHS FS_ENCODE = sys.getfilesystemencoding() -if sys.platform == 'win32': - from invesalius.expanduser import expand_user - try: - USER_DIR = expand_user() - except: - USER_DIR = utils.decode(os.path.expanduser('~'), FS_ENCODE) -else: - USER_DIR = utils.decode(os.path.expanduser('~'), FS_ENCODE) - -USER_INV_DIR = os.path.join(USER_DIR, u'.invesalius') -USER_PRESET_DIR = os.path.join(USER_INV_DIR, u'presets') -USER_LOG_DIR = os.path.join(USER_INV_DIR, u'logs') - -FILE_PATH = utils.decode(os.path.split(__file__)[0], FS_ENCODE) - -if hasattr(sys,"frozen") and (sys.frozen == "windows_exe"\ - or sys.frozen == "console_exe"): - abs_path = os.path.abspath(FILE_PATH, u'..', u'..', u'..') - ICON_DIR = os.path.join(abs_path, u"icons") - SAMPLE_DIR = os.path.join(FILE_PATH, u'samples') - DOC_DIR = os.path.join(FILE_PATH, u'docs') - folder=RAYCASTING_PRESETS_DIRECTORY= os.path.join(abs_path, u"presets", u"raycasting") - RAYCASTING_PRESETS_COLOR_DIRECTORY = os.path.join(abs_path, u"presets", u"raycasting", u"color_list") - -else: - ICON_DIR = os.path.abspath(os.path.join(FILE_PATH, u'..', u'icons')) - SAMPLE_DIR = os.path.abspath(os.path.join(FILE_PATH, u'..', u'samples')) - DOC_DIR = os.path.abspath(os.path.join(FILE_PATH, u'..', u'docs')) - - folder=RAYCASTING_PRESETS_DIRECTORY= os.path.abspath(os.path.join(u".", - u"presets", - u"raycasting")) - - RAYCASTING_PRESETS_COLOR_DIRECTORY = os.path.abspath(os.path.join(u".", - u"presets", - u"raycasting", - u"color_list")) - - -# MAC App -if not os.path.exists(ICON_DIR): - ICON_DIR = os.path.abspath(os.path.join(FILE_PATH, u'..', u'..', u'..', u'..', u'icons')) - SAMPLE_DIR = os.path.abspath(os.path.join(FILE_PATH, u'..', u'..', u'..', u'..', u'samples')) - DOC_DIR = os.path.abspath(os.path.join(FILE_PATH, u'..', u'..', u'..', u'..', u'docs')) - - -ID_TO_BMP = {VOL_FRONT: [_("Front"), os.path.join(ICON_DIR, u"view_front.png")], - VOL_BACK: [_("Back"), os.path.join(ICON_DIR, u"view_back.png")], - VOL_TOP: [_("Top"), os.path.join(ICON_DIR, u"view_top.png")], - VOL_BOTTOM: [_("Bottom"), os.path.join(ICON_DIR, u"view_bottom.png")], - VOL_RIGHT: [_("Right"), os.path.join(ICON_DIR, u"view_right.png")], - VOL_LEFT: [_("Left"), os.path.join(ICON_DIR, u"view_left.png")], - VOL_ISO:[_("Isometric"), os.path.join(ICON_DIR, u"view_isometric.png")] +ID_TO_BMP = {VOL_FRONT: [_("Front"), str(inv_paths.ICON_DIR.joinpath("view_front.png"))], + VOL_BACK: [_("Back"), str(inv_paths.ICON_DIR.joinpath("view_back.png"))], + VOL_TOP: [_("Top"), str(inv_paths.ICON_DIR.joinpath("view_top.png"))], + VOL_BOTTOM: [_("Bottom"), str(inv_paths.ICON_DIR.joinpath("view_bottom.png"))], + VOL_RIGHT: [_("Right"), str(inv_paths.ICON_DIR.joinpath("view_right.png"))], + VOL_LEFT: [_("Left"), str(inv_paths.ICON_DIR.joinpath("view_left.png"))], + VOL_ISO:[_("Isometric"), str(inv_paths.ICON_DIR.joinpath("view_isometric.png"))] } # if 1, use vtkVolumeRaycastMapper, if 0, use vtkFixedPointVolumeRayCastMapper @@ -433,10 +388,9 @@ RAYCASTING_FILES = {_("Airways"): "Airways.plist", # os.path.isfile(os.path.join(folder,filename))] -USER_RAYCASTING_PRESETS_DIRECTORY = os.path.join(USER_PRESET_DIR, u'raycasting') -RAYCASTING_TYPES = [_(filename.split(".")[0]) for filename in - os.listdir(USER_RAYCASTING_PRESETS_DIRECTORY) if - os.path.isfile(os.path.join(USER_RAYCASTING_PRESETS_DIRECTORY, filename))] +RAYCASTING_TYPES = [_(filename.name.split(".")[0]) for filename in + inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY.glob('*') if + filename.is_file()] RAYCASTING_TYPES += RAYCASTING_FILES.keys() RAYCASTING_TYPES.append(_(' Off')) RAYCASTING_TYPES.sort() @@ -446,8 +400,8 @@ RAYCASTING_TOOLS = [_("Cut plane")] # If 0 dont't blur, 1 blur RAYCASTING_WWWL_BLUR = 0 -RAYCASTING_PRESETS_FOLDERS = (RAYCASTING_PRESETS_DIRECTORY, - USER_RAYCASTING_PRESETS_DIRECTORY) +RAYCASTING_PRESETS_FOLDERS = (inv_paths.RAYCASTING_PRESETS_DIRECTORY, + inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY) #### @@ -761,14 +715,11 @@ TIPS_OBJ = [_("Select left object fiducial"), _("Select object center"), _("Attach sensor to object")] -CAL_DIR = os.path.abspath(os.path.join(FILE_PATH, '..', 'navigation', 'mtc_files', 'CalibrationFiles')) -MAR_DIR = os.path.abspath(os.path.join(FILE_PATH, '..', 'navigation', 'mtc_files', 'Markers')) PROBE_NAME = "1Probe" REF_NAME = "2Ref" OBJ_NAME = "3Coil" #OBJECT TRACKING -OBJ_DIR = os.path.abspath(os.path.join(FILE_PATH, '..', 'navigation', 'objects')) ARROW_SCALE = 3 ARROW_UPPER_LIMIT = 30 #COIL_ANGLES_THRESHOLD = 3 * ARROW_SCALE diff --git a/invesalius/control.py b/invesalius/control.py index ef641ca..f437fa2 100644 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -42,6 +42,8 @@ import invesalius.gui.dialogs as dialogs import subprocess import sys +from invesalius import inv_paths + DEFAULT_THRESH_MODE = 0 class Controller(): @@ -920,13 +922,13 @@ class Controller(): def LoadRaycastingPreset(self, preset_name): if preset_name != const.RAYCASTING_OFF_LABEL: if preset_name in const.RAYCASTING_FILES.keys(): - path = os.path.join(const.RAYCASTING_PRESETS_DIRECTORY, + path = os.path.join(inv_paths.RAYCASTING_PRESETS_DIRECTORY, const.RAYCASTING_FILES[preset_name]) else: - path = os.path.join(const.RAYCASTING_PRESETS_DIRECTORY, + path = os.path.join(inv_paths.RAYCASTING_PRESETS_DIRECTORY, preset_name+".plist") if not os.path.isfile(path): - path = os.path.join(const.USER_RAYCASTING_PRESETS_DIRECTORY, + path = os.path.join(inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY, preset_name+".plist") preset = plistlib.readPlist(path) prj.Project().raycasting_preset = preset @@ -940,7 +942,7 @@ class Controller(): def SaveRaycastingPreset(self, preset_name): preset = prj.Project().raycasting_preset preset['name'] = preset_name - preset_dir = os.path.join(const.USER_RAYCASTING_PRESETS_DIRECTORY, + preset_dir = os.path.join(inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY, preset_name + '.plist') plistlib.writePlist(preset, preset_dir) diff --git a/invesalius/data/imagedata_utils.py b/invesalius/data/imagedata_utils.py index 2a65379..75fa77c 100644 --- a/invesalius/data/imagedata_utils.py +++ b/invesalius/data/imagedata_utils.py @@ -37,6 +37,8 @@ import invesalius.reader.bitmap_reader as bitmap_reader import invesalius.utils as utils import invesalius.data.converters as converters +from invesalius import inv_paths + if sys.platform == 'win32': try: import win32api @@ -335,7 +337,7 @@ def CreateImageData(filelist, zspacing, xyspacing,size, message = _("Generating multiplanar visualization...") if not const.VTK_WARNING: - log_path = os.path.join(const.USER_LOG_DIR, 'vtkoutput.txt') + log_path = os.path.join(inv_paths.USER_LOG_DIR, 'vtkoutput.txt') fow = vtk.vtkFileOutputWindow() fow.SetFileName(log_path) ow = vtk.vtkOutputWindow() @@ -440,7 +442,7 @@ class ImageCreator: message = _("Generating multiplanar visualization...") if not const.VTK_WARNING: - log_path = os.path.join(const.USER_LOG_DIR, 'vtkoutput.txt') + log_path = os.path.join(inv_paths.USER_LOG_DIR, 'vtkoutput.txt') fow = vtk.vtkFileOutputWindow() fow.SetFileName(log_path) ow = vtk.vtkOutputWindow() diff --git a/invesalius/data/trackers.py b/invesalius/data/trackers.py index a161cb8..aec84d6 100644 --- a/invesalius/data/trackers.py +++ b/invesalius/data/trackers.py @@ -61,6 +61,7 @@ def DefaultTracker(tracker_id): def ClaronTracker(tracker_id): import invesalius.constants as const + from invesalius import inv_paths trck_init = None try: @@ -68,8 +69,8 @@ def ClaronTracker(tracker_id): lib_mode = 'wrapper' trck_init = pyclaron.pyclaron() - trck_init.CalibrationDir = const.CAL_DIR.encode(const.FS_ENCODE) - trck_init.MarkerDir = const.MAR_DIR.encode(const.FS_ENCODE) + trck_init.CalibrationDir = inv_paths.CAL_DIR.encode(const.FS_ENCODE) + trck_init.MarkerDir = inv_paths.MAR_DIR.encode(const.FS_ENCODE) trck_init.NumberFramesProcessed = 1 trck_init.FramesExtrapolated = 0 trck_init.PROBE_NAME = const.PROBE_NAME.encode(const.FS_ENCODE) diff --git a/invesalius/data/viewer_volume.py b/invesalius/data/viewer_volume.py index 8adfe0a..b49fdaf 100644 --- a/invesalius/data/viewer_volume.py +++ b/invesalius/data/viewer_volume.py @@ -42,6 +42,8 @@ import invesalius.project as prj import invesalius.style as st import invesalius.utils as utils +from invesalius import inv_paths + if sys.platform == 'win32': try: import win32api @@ -873,7 +875,7 @@ class Viewer(wx.Panel): self.m_img_vtk = m_img_vtk - filename = os.path.join(const.OBJ_DIR, "aim.stl") + filename = os.path.join(inv_paths.OBJ_DIR, "aim.stl") reader = vtk.vtkSTLReader() reader.SetFileName(filename) @@ -898,7 +900,7 @@ class Viewer(wx.Panel): self.aim_actor = aim_actor self.ren.AddActor(aim_actor) - obj_polydata = self.CreateObjectPolyData(os.path.join(const.OBJ_DIR, "magstim_fig8_coil_no_handle.stl")) + obj_polydata = self.CreateObjectPolyData(os.path.join(inv_paths.OBJ_DIR, "magstim_fig8_coil_no_handle.stl")) transform = vtk.vtkTransform() transform.RotateZ(90) @@ -1148,7 +1150,7 @@ class Viewer(wx.Panel): wx.MessageBox(_("File format not reconized by InVesalius"), _("Import surface error")) return else: - filename = os.path.join(const.OBJ_DIR, "magstim_fig8_coil.stl") + filename = os.path.join(inv_paths.OBJ_DIR, "magstim_fig8_coil.stl") reader = vtk.vtkSTLReader() if _has_win32api: diff --git a/invesalius/data/volume.py b/invesalius/data/volume.py index 4bd4efd..9da5254 100644 --- a/invesalius/data/volume.py +++ b/invesalius/data/volume.py @@ -33,6 +33,8 @@ import invesalius.data.vtk_utils as vtk_utils from vtk.util import numpy_support import invesalius.session as ses +from invesalius import inv_paths + Kernels = { "Basic Smooth 5x5" : [1.0, 1.0, 1.0, 1.0, 1.0, @@ -352,7 +354,7 @@ class Volume(): color_preset = self.config['CLUT'] if color_preset != "No CLUT": p = plistlib.readPlist( - os.path.join(const.RAYCASTING_PRESETS_DIRECTORY, + os.path.join(inv_paths.RAYCASTING_PRESETS_DIRECTORY, 'color_list', color_preset + '.plist')) r = p['Red'] g = p['Green'] diff --git a/invesalius/gui/data_notebook.py b/invesalius/gui/data_notebook.py index 1bc1140..8396805 100644 --- a/invesalius/gui/data_notebook.py +++ b/invesalius/gui/data_notebook.py @@ -43,6 +43,8 @@ import invesalius.gui.dialogs as dlg import wx.lib.mixins.listctrl as listmix import invesalius.utils as ul +from invesalius import inv_paths + BTN_NEW, BTN_REMOVE, BTN_DUPLICATE, BTN_OPEN = [wx.NewId() for i in range(4)] @@ -155,11 +157,11 @@ class MeasureButtonControlPanel(wx.Panel): def __init_gui(self): # Bitmaps to be used in plate buttons - BMP_NEW = wx.Bitmap(os.path.join(const.ICON_DIR, "data_new.png"), + BMP_NEW = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "data_new.png"), wx.BITMAP_TYPE_PNG) - BMP_REMOVE = wx.Bitmap(os.path.join(const.ICON_DIR, "data_remove.png"), + BMP_REMOVE = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "data_remove.png"), wx.BITMAP_TYPE_PNG) - BMP_DUPLICATE = wx.Bitmap(os.path.join(const.ICON_DIR, "data_duplicate.png"), + BMP_DUPLICATE = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "data_duplicate.png"), wx.BITMAP_TYPE_PNG) # Plate buttons based on previous bitmaps @@ -273,11 +275,11 @@ class ButtonControlPanel(wx.Panel): def __init_gui(self): # Bitmaps to be used in plate buttons - BMP_NEW = wx.Bitmap(os.path.join(const.ICON_DIR, "data_new.png"), + BMP_NEW = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "data_new.png"), wx.BITMAP_TYPE_PNG) - BMP_REMOVE = wx.Bitmap(os.path.join(const.ICON_DIR, "data_remove.png"), + BMP_REMOVE = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "data_remove.png"), wx.BITMAP_TYPE_PNG) - BMP_DUPLICATE = wx.Bitmap(os.path.join(const.ICON_DIR, "data_duplicate.png"), + BMP_DUPLICATE = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "data_duplicate.png"), wx.BITMAP_TYPE_PNG) # Plate buttons based on previous bitmaps @@ -473,13 +475,13 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckListCt def __init_image_list(self): self.imagelist = wx.ImageList(16, 16) - image = wx.Image(os.path.join(const.ICON_DIR, "object_invisible.jpg")) + image = wx.Image(os.path.join(inv_paths.ICON_DIR, "object_invisible.jpg")) bitmap = wx.Bitmap(image.Scale(16, 16)) bitmap.SetWidth(16) bitmap.SetHeight(16) img_null = self.imagelist.Add(bitmap) - image = wx.Image(os.path.join(const.ICON_DIR, "object_visible.jpg")) + image = wx.Image(os.path.join(inv_paths.ICON_DIR, "object_visible.jpg")) bitmap = wx.Bitmap(image.Scale(16, 16)) bitmap.SetWidth(16) bitmap.SetHeight(16) @@ -487,7 +489,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckListCt self.SetImageList(self.imagelist,wx.IMAGE_LIST_SMALL) - self.image_gray = Image.open(os.path.join(const.ICON_DIR, "object_colour.jpg")) + self.image_gray = Image.open(os.path.join(inv_paths.ICON_DIR, "object_colour.jpg")) def OnBeginLabelEdit(self, evt): if evt.GetColumn() == 1: @@ -616,13 +618,13 @@ class SurfaceButtonControlPanel(wx.Panel): def __init_gui(self): # Bitmaps to be used in plate buttons - BMP_NEW = wx.Bitmap(os.path.join(const.ICON_DIR, "data_new.png"), + BMP_NEW = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "data_new.png"), wx.BITMAP_TYPE_PNG) - BMP_REMOVE = wx.Bitmap(os.path.join(const.ICON_DIR, "data_remove.png"), + BMP_REMOVE = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "data_remove.png"), wx.BITMAP_TYPE_PNG) - BMP_DUPLICATE = wx.Bitmap(os.path.join(const.ICON_DIR, "data_duplicate.png"), + BMP_DUPLICATE = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "data_duplicate.png"), wx.BITMAP_TYPE_PNG) - BMP_OPEN = wx.Bitmap(os.path.join(const.ICON_DIR, "load_mesh.png"), + BMP_OPEN = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "load_mesh.png"), wx.BITMAP_TYPE_PNG) # Plate buttons based on previous bitmaps @@ -839,13 +841,13 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckLis def __init_image_list(self): self.imagelist = wx.ImageList(16, 16) - image = wx.Image(os.path.join(const.ICON_DIR, "object_invisible.jpg")) + image = wx.Image(os.path.join(inv_paths.ICON_DIR, "object_invisible.jpg")) bitmap = wx.Bitmap(image.Scale(16, 16)) bitmap.SetWidth(16) bitmap.SetHeight(16) img_null = self.imagelist.Add(bitmap) - image = wx.Image(os.path.join(const.ICON_DIR, "object_visible.jpg")) + image = wx.Image(os.path.join(inv_paths.ICON_DIR, "object_visible.jpg")) bitmap = wx.Bitmap(image.Scale(16, 16)) bitmap.SetWidth(16) bitmap.SetHeight(16) @@ -853,7 +855,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckLis self.SetImageList(self.imagelist,wx.IMAGE_LIST_SMALL) - self.image_gray = Image.open(os.path.join(const.ICON_DIR, "object_colour.jpg")) + self.image_gray = Image.open(os.path.join(inv_paths.ICON_DIR, "object_colour.jpg")) def OnBeginLabelEdit(self, evt): if evt.GetColumn() == 1: @@ -1114,13 +1116,13 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckLis def __init_image_list(self): self.imagelist = wx.ImageList(16, 16) - image = wx.Image(os.path.join(const.ICON_DIR, "object_invisible.jpg")) + image = wx.Image(os.path.join(inv_paths.ICON_DIR, "object_invisible.jpg")) bitmap = wx.Bitmap(image.Scale(16, 16)) bitmap.SetWidth(16) bitmap.SetHeight(16) img_null = self.imagelist.Add(bitmap) - image = wx.Image(os.path.join(const.ICON_DIR, "object_visible.jpg")) + image = wx.Image(os.path.join(inv_paths.ICON_DIR, "object_visible.jpg")) bitmap = wx.Bitmap(image.Scale(16, 16)) bitmap.SetWidth(16) bitmap.SetHeight(16) @@ -1128,7 +1130,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckLis self.SetImageList(self.imagelist,wx.IMAGE_LIST_SMALL) - self.image_gray = Image.open(os.path.join(const.ICON_DIR, "object_colour.jpg")) + self.image_gray = Image.open(os.path.join(inv_paths.ICON_DIR, "object_colour.jpg")) def OnBeginLabelEdit(self, evt): if evt.GetColumn() == 1: @@ -1309,19 +1311,19 @@ class AnnotationsListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.Check def __init_image_list(self): self.imagelist = wx.ImageList(16, 16) - image = wx.Image(os.path.join(const.ICON_DIR, "object_visible.jpg")) + image = wx.Image(os.path.join(inv_paths.ICON_DIR, "object_visible.jpg")) bitmap = wx.Bitmap(image.Scale(16, 16)) bitmap.SetWidth(16) bitmap.SetHeight(16) img_check = self.imagelist.Add(bitmap) - image = wx.Image(os.path.join(const.ICON_DIR, "object_invisible.jpg")) + image = wx.Image(os.path.join(inv_paths.ICON_DIR, "object_invisible.jpg")) bitmap = wx.Bitmap(image.Scale(16, 16)) bitmap.SetWidth(16) bitmap.SetHeight(16) img_null = self.imagelist.Add(bitmap) - image = wx.Image(os.path.join(const.ICON_DIR, "object_colour.jpg")) + image = wx.Image(os.path.join(inv_paths.ICON_DIR, "object_colour.jpg")) bitmap = wx.Bitmap(image.Scale(16, 16)) bitmap.SetWidth(16) bitmap.SetHeight(16) diff --git a/invesalius/gui/default_viewers.py b/invesalius/gui/default_viewers.py index 2105cae..f10e3de 100644 --- a/invesalius/gui/default_viewers.py +++ b/invesalius/gui/default_viewers.py @@ -34,6 +34,7 @@ from invesalius.gui.widgets.clut_raycasting import CLUTRaycastingWidget, \ EVT_CLUT_CURVE_WL_CHANGE from invesalius.constants import ID_TO_BMP +from invesalius import inv_paths import invesalius.session as ses import invesalius.constants as const @@ -348,17 +349,17 @@ class VolumeToolPanel(wx.Panel): wx.Panel.__init__(self, parent) # VOLUME RAYCASTING BUTTON - BMP_RAYCASTING = wx.Bitmap(os.path.join(const.ICON_DIR, "volume_raycasting.png"), + BMP_RAYCASTING = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "volume_raycasting.png"), wx.BITMAP_TYPE_PNG) - BMP_SLICE_PLANE = wx.Bitmap(os.path.join(const.ICON_DIR, "slice_plane.png"), + BMP_SLICE_PLANE = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "slice_plane.png"), wx.BITMAP_TYPE_PNG) - BMP_3D_STEREO = wx.Bitmap(os.path.join(const.ICON_DIR, "3D_glasses.png"), + BMP_3D_STEREO = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "3D_glasses.png"), wx.BITMAP_TYPE_PNG) - BMP_TARGET = wx.Bitmap(os.path.join(const.ICON_DIR, "target.png"), + BMP_TARGET = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "target.png"), wx.BITMAP_TYPE_PNG) diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 48d7c24..eb3e815 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -64,6 +64,8 @@ from invesalius.gui.widgets import clut_imagedata from invesalius.gui.widgets.clut_imagedata import CLUTImageDataWidget, EVT_CLUT_NODE_CHANGED import numpy as np +from invesalius import inv_paths + try: from agw import floatspin as FS except ImportError: # if it's not there locally, try the wxPython lib. @@ -3443,10 +3445,10 @@ class ObjectCalibrationDialog(wx.Dialog): wx.MessageBox(_("File format not reconized by InVesalius"), _("Import surface error")) return else: - filename = os.path.join(const.OBJ_DIR, "magstim_fig8_coil.stl") + filename = os.path.join(inv_paths.OBJ_DIR, "magstim_fig8_coil.stl") reader = vtk.vtkSTLReader() else: - filename = os.path.join(const.OBJ_DIR, "magstim_fig8_coil.stl") + filename = os.path.join(inv_paths.OBJ_DIR, "magstim_fig8_coil.stl") reader = vtk.vtkSTLReader() if _has_win32api: diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index 5159267..87f194c 100644 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -23,31 +23,31 @@ import platform import sys import webbrowser -import wx - -try: - from wx.adv import TaskBarIcon as wx_TaskBarIcon -except ImportError: - from wx import TaskBarIcon as wx_TaskBarIcon - -import wx.aui -from wx.lib.pubsub import pub as Publisher -import wx.lib.agw.toasterbox as TB -import wx.lib.popupctl as pc - -from wx.lib.agw.aui.auibar import AuiToolBar, AUI_TB_PLAIN_BACKGROUND - import invesalius.constants as const import invesalius.gui.default_tasks as tasks import invesalius.gui.default_viewers as viewers import invesalius.gui.dialogs as dlg -import invesalius.gui.import_panel as imp import invesalius.gui.import_bitmap_panel as imp_bmp +import invesalius.gui.import_panel as imp +import invesalius.gui.preferences as preferences # import invesalius.gui.import_network_panel as imp_net import invesalius.project as prj import invesalius.session as ses import invesalius.utils as utils -import invesalius.gui.preferences as preferences +import wx +import wx.aui +import wx.lib.agw.toasterbox as TB +import wx.lib.popupctl as pc +from invesalius import inv_paths +from wx.lib.agw.aui.auibar import AUI_TB_PLAIN_BACKGROUND, AuiToolBar +from wx.lib.pubsub import pub as Publisher + +try: + from wx.adv import TaskBarIcon as wx_TaskBarIcon +except ImportError: + from wx import TaskBarIcon as wx_TaskBarIcon + + # Layout tools' IDs - this is used only locally, therefore doesn't # need to be defined in constants.py VIEW_TOOLS = [ID_LAYOUT, ID_TEXT] =\ @@ -94,8 +94,8 @@ class Frame(wx.Frame): size=wx.Size(1024, 748), #size = wx.DisplaySize(), style=wx.DEFAULT_FRAME_STYLE, title='InVesalius 3') self.Center(wx.BOTH) - icon_path = os.path.join(const.ICON_DIR, "invesalius.ico") - self.SetIcon(wx.Icon(icon_path, wx.BITMAP_TYPE_ICO)) + icon_path = inv_paths.ICON_DIR.joinpath("invesalius.ico") + self.SetIcon(wx.Icon(str(icon_path), wx.BITMAP_TYPE_ICO)) self.mw = None self._last_viewer_orientation_focus = const.AXIAL_STR @@ -621,7 +621,7 @@ class Frame(wx.Frame): else: user_guide = "user_guide_en.pdf" - path = os.path.join(const.DOC_DIR, + path = os.path.join(inv_paths.DOC_DIR, user_guide) if sys.platform == 'darwin': path = r'file://' + path @@ -846,7 +846,7 @@ class MenuBar(wx.MenuBar): app(const.ID_EXIT, _("Exit\tCtrl+Q")) file_edit = wx.Menu() - d = const.ICON_DIR + d = inv_paths.ICON_DIR if not(sys.platform == 'darwin'): # Bitmaps for show/hide task panel item p = os.path.join(d, "undo_menu.png") @@ -1284,43 +1284,43 @@ class ProjectToolBar(AuiToolBar): Add tools into toolbar. """ # Load bitmaps - d = const.ICON_DIR + d = inv_paths.ICON_DIR if sys.platform == 'darwin': - path = os.path.join(d,"file_from_internet_original.png") - BMP_NET = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = d.joinpath("file_from_internet_original.png") + BMP_NET = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) - path = os.path.join(d, "file_import_original.png") - BMP_IMPORT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = d.joinpath("file_import_original.png") + BMP_IMPORT = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) - path = os.path.join(d, "file_open_original.png") - BMP_OPEN = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = d.joinpath("file_open_original.png") + BMP_OPEN = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) - path = os.path.join(d, "file_save_original.png") - BMP_SAVE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = d.joinpath("file_save_original.png") + BMP_SAVE = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) - path = os.path.join(d, "print_original.png") - BMP_PRINT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = d.joinpath("print_original.png") + BMP_PRINT = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) - path = os.path.join(d, "tool_photo_original.png") - BMP_PHOTO = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = d.joinpath("tool_photo_original.png") + BMP_PHOTO = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) else: - path = os.path.join(d, "file_from_internet.png") - BMP_NET = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = d.joinpath("file_from_internet.png") + BMP_NET = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) - path = os.path.join(d, "file_import.png") - BMP_IMPORT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = d.joinpath("file_import.png") + BMP_IMPORT = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) - path = os.path.join(d, "file_open.png") - BMP_OPEN = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = d.joinpath("file_open.png") + BMP_OPEN = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) - path = os.path.join(d, "file_save.png") - BMP_SAVE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = d.joinpath("file_save.png") + BMP_SAVE = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) - path = os.path.join(d, "print.png") - BMP_PRINT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = d.joinpath("print.png") + BMP_PRINT = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) - path = os.path.join(d, "tool_photo.png") - BMP_PHOTO = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = d.joinpath("tool_photo.png") + BMP_PHOTO = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) # Create tool items based on bitmaps self.AddTool(const.ID_DICOM_IMPORT, @@ -1436,65 +1436,65 @@ class ObjectToolBar(AuiToolBar): """ Add tools into toolbar. """ - d = const.ICON_DIR + d = inv_paths.ICON_DIR if sys.platform == 'darwin': path = os.path.join(d, "tool_rotate_original.png") - BMP_ROTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_ROTATE = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "tool_translate_original.png") - BMP_MOVE =wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_MOVE =wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "tool_zoom_original.png") - BMP_ZOOM = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_ZOOM = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "tool_zoom_select_original.png") - BMP_ZOOM_SELECT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_ZOOM_SELECT = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "tool_contrast_original.png") - BMP_CONTRAST = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_CONTRAST = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "measure_line_original.png") - BMP_DISTANCE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_DISTANCE = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "measure_angle_original.png") - BMP_ANGLE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_ANGLE = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "measure_density_ellipse32px.png") - BMP_ELLIPSE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_ELLIPSE = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "measure_density_polygon32px.png") - BMP_POLYGON = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_POLYGON = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) #path = os.path.join(d, "tool_annotation_original.png") #BMP_ANNOTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) else: path = os.path.join(d, "tool_rotate.png") - BMP_ROTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_ROTATE = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "tool_translate.png") - BMP_MOVE =wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_MOVE =wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "tool_zoom.png") - BMP_ZOOM = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_ZOOM = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "tool_zoom_select.png") - BMP_ZOOM_SELECT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_ZOOM_SELECT = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "tool_contrast.png") - BMP_CONTRAST = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_CONTRAST = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "measure_line.png") - BMP_DISTANCE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_DISTANCE = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "measure_angle.png") - BMP_ANGLE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_ANGLE = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "measure_density_ellipse28px.png") - BMP_ELLIPSE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_ELLIPSE = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d, "measure_density_polygon28px.png") - BMP_POLYGON = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_POLYGON = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) #path = os.path.join(d, "tool_annotation.png") #BMP_ANNOTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) @@ -1686,19 +1686,19 @@ class SliceToolBar(AuiToolBar): """ Add tools into toolbar. """ - d = const.ICON_DIR + d = inv_paths.ICON_DIR if sys.platform == 'darwin': path = os.path.join(d, "slice_original.png") - BMP_SLICE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_SLICE = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d,"cross_original.png") - BMP_CROSS = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_CROSS = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) else: path = os.path.join(d, "slice.png") - BMP_SLICE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_SLICE = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) path = os.path.join(d,"cross.png") - BMP_CROSS = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + BMP_CROSS = wx.Bitmap(str(path), wx.BITMAP_TYPE_PNG) self.sst = self.AddToggleTool(const.SLICE_STATE_SCROLL, BMP_SLICE,#, kind=wx.ITEM_CHECK) @@ -1853,36 +1853,36 @@ class LayoutToolBar(AuiToolBar): """ Add tools into toolbar. """ - d = const.ICON_DIR + d = inv_paths.ICON_DIR if sys.platform == 'darwin': # Bitmaps for show/hide task panel item p = os.path.join(d, "layout_data_only_original.gif") - self.BMP_WITH_MENU = wx.Bitmap(p, wx.BITMAP_TYPE_GIF) + self.BMP_WITH_MENU = wx.Bitmap(str(p), wx.BITMAP_TYPE_GIF) p = os.path.join(d, "layout_full_original.gif") - self.BMP_WITHOUT_MENU = wx.Bitmap(p, wx.BITMAP_TYPE_GIF) + self.BMP_WITHOUT_MENU = wx.Bitmap(str(p), wx.BITMAP_TYPE_GIF) # Bitmaps for show/hide task item p = os.path.join(d, "text_inverted_original.png") - self.BMP_WITHOUT_TEXT = wx.Bitmap(p, wx.BITMAP_TYPE_PNG) + self.BMP_WITHOUT_TEXT = wx.Bitmap(str(p), wx.BITMAP_TYPE_PNG) p = os.path.join(d, "text_original.png") - self.BMP_WITH_TEXT = wx.Bitmap(p, wx.BITMAP_TYPE_PNG) + self.BMP_WITH_TEXT = wx.Bitmap(str(p), wx.BITMAP_TYPE_PNG) else: # Bitmaps for show/hide task panel item p = os.path.join(d, "layout_data_only.gif") - self.BMP_WITH_MENU = wx.Bitmap(p, wx.BITMAP_TYPE_GIF) + self.BMP_WITH_MENU = wx.Bitmap(str(p), wx.BITMAP_TYPE_GIF) p = os.path.join(d, "layout_full.gif") - self.BMP_WITHOUT_MENU = wx.Bitmap(p, wx.BITMAP_TYPE_GIF) + self.BMP_WITHOUT_MENU = wx.Bitmap(str(p), wx.BITMAP_TYPE_GIF) # Bitmaps for show/hide task item p = os.path.join(d, "text_inverted.png") - self.BMP_WITHOUT_TEXT = wx.Bitmap(p, wx.BITMAP_TYPE_PNG) + self.BMP_WITHOUT_TEXT = wx.Bitmap(str(p), wx.BITMAP_TYPE_PNG) p = os.path.join(d, "text.png") - self.BMP_WITH_TEXT = wx.Bitmap(p, wx.BITMAP_TYPE_PNG) + self.BMP_WITH_TEXT = wx.Bitmap(str(p), wx.BITMAP_TYPE_PNG) self.AddTool(ID_LAYOUT, "", @@ -2035,22 +2035,22 @@ class HistoryToolBar(AuiToolBar): """ Add tools into toolbar. """ - d = const.ICON_DIR + d = inv_paths.ICON_DIR if sys.platform == 'darwin': # Bitmaps for show/hide task panel item p = os.path.join(d, "undo_original.png") - self.BMP_UNDO = wx.Bitmap(p, wx.BITMAP_TYPE_PNG) + self.BMP_UNDO = wx.Bitmap(str(p), wx.BITMAP_TYPE_PNG) p = os.path.join(d, "redo_original.png") - self.BMP_REDO = wx.Bitmap(p, wx.BITMAP_TYPE_PNG) + self.BMP_REDO = wx.Bitmap(str(p), wx.BITMAP_TYPE_PNG) else: # Bitmaps for show/hide task panel item p = os.path.join(d, "undo_small.png") - self.BMP_UNDO = wx.Bitmap(p, wx.BITMAP_TYPE_PNG) + self.BMP_UNDO = wx.Bitmap(str(p), wx.BITMAP_TYPE_PNG) p = os.path.join(d, "redo_small.png") - self.BMP_REDO = wx.Bitmap(p, wx.BITMAP_TYPE_PNG) + self.BMP_REDO = wx.Bitmap(str(p), wx.BITMAP_TYPE_PNG) self.AddTool(wx.ID_UNDO, "", diff --git a/invesalius/gui/task_exporter.py b/invesalius/gui/task_exporter.py index b87966f..0fe48b9 100644 --- a/invesalius/gui/task_exporter.py +++ b/invesalius/gui/task_exporter.py @@ -35,6 +35,8 @@ import invesalius.gui.dialogs as dlg import invesalius.project as proj import invesalius.session as ses +from invesalius import inv_paths + BTN_MASK = wx.NewId() BTN_PICTURE = wx.NewId() BTN_SURFACE = wx.NewId() @@ -170,22 +172,22 @@ class InnerTaskPanel(wx.Panel): # Image(s) for buttons if sys.platform == 'darwin': BMP_EXPORT_SURFACE = wx.Bitmap(\ - os.path.join(const.ICON_DIR, "surface_export_original.png"), + os.path.join(inv_paths.ICON_DIR, "surface_export_original.png"), wx.BITMAP_TYPE_PNG).ConvertToImage()\ .Rescale(25, 25).ConvertToBitmap() BMP_TAKE_PICTURE = wx.Bitmap(\ - os.path.join(const.ICON_DIR, "tool_photo_original.png"), + os.path.join(inv_paths.ICON_DIR, "tool_photo_original.png"), wx.BITMAP_TYPE_PNG).ConvertToImage()\ .Rescale(25, 25).ConvertToBitmap() #BMP_EXPORT_MASK = wx.Bitmap("../icons/mask.png", # wx.BITMAP_TYPE_PNG) else: - BMP_EXPORT_SURFACE = wx.Bitmap(os.path.join(const.ICON_DIR, "surface_export.png"), + BMP_EXPORT_SURFACE = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "surface_export.png"), wx.BITMAP_TYPE_PNG).ConvertToImage()\ .Rescale(25, 25).ConvertToBitmap() - BMP_TAKE_PICTURE = wx.Bitmap(os.path.join(const.ICON_DIR, "tool_photo.png"), + BMP_TAKE_PICTURE = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "tool_photo.png"), wx.BITMAP_TYPE_PNG).ConvertToImage()\ .Rescale(25, 25).ConvertToBitmap() diff --git a/invesalius/gui/task_importer.py b/invesalius/gui/task_importer.py index 7f6850d..f1648d6 100644 --- a/invesalius/gui/task_importer.py +++ b/invesalius/gui/task_importer.py @@ -31,6 +31,8 @@ from wx.lib.pubsub import pub as Publisher import invesalius.constants as const import invesalius.gui.dialogs as dlg +from invesalius import inv_paths + BTN_IMPORT_LOCAL = wx.NewId() BTN_IMPORT_PACS = wx.NewId() BTN_OPEN_PROJECT = wx.NewId() @@ -100,9 +102,9 @@ class InnerTaskPanel(wx.Panel): link_open_proj.Bind(hl.EVT_HYPERLINK_LEFT, self.OnLinkOpenProject) # Image(s) for buttons - BMP_IMPORT = wx.Bitmap(os.path.join(const.ICON_DIR, "file_import.png"), wx.BITMAP_TYPE_PNG) - BMP_NET = wx.Bitmap(os.path.join(const.ICON_DIR, "file_from_internet.png"), wx.BITMAP_TYPE_PNG) - BMP_OPEN_PROJECT = wx.Bitmap(os.path.join(const.ICON_DIR, "file_open.png"), wx.BITMAP_TYPE_PNG) + BMP_IMPORT = wx.Bitmap(str(inv_paths.ICON_DIR.joinpath("file_import.png")), wx.BITMAP_TYPE_PNG) + BMP_NET = wx.Bitmap(str(inv_paths.ICON_DIR.joinpath("file_from_internet.png")), wx.BITMAP_TYPE_PNG) + BMP_OPEN_PROJECT = wx.Bitmap(str(inv_paths.ICON_DIR.joinpath("file_open.png")), wx.BITMAP_TYPE_PNG) bmp_list = [BMP_IMPORT, BMP_NET, BMP_OPEN_PROJECT] #for bmp in bmp_list: diff --git a/invesalius/gui/task_slice.py b/invesalius/gui/task_slice.py index 80fd062..90bfe68 100644 --- a/invesalius/gui/task_slice.py +++ b/invesalius/gui/task_slice.py @@ -40,6 +40,8 @@ import invesalius.gui.dialogs as dlg import invesalius.gui.widgets.gradient as grad from invesalius.gui.widgets.inv_spinctrl import InvSpinCtrl +from invesalius import inv_paths + from invesalius.project import Project import invesalius.session as ses @@ -78,7 +80,7 @@ class InnerTaskPanel(wx.Panel): self.SetAutoLayout(1) # Image(s) for buttons - BMP_ADD = wx.Bitmap(os.path.join(const.ICON_DIR, "object_add.png"), wx.BITMAP_TYPE_PNG) + BMP_ADD = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "object_add.png"), wx.BITMAP_TYPE_PNG) #BMP_ADD.SetWidth(25) #BMP_ADD.SetHeight(25) @@ -686,11 +688,11 @@ class EditionTools(wx.Panel): ## LINE 2 menu = wx.Menu() - CIRCLE_BMP = wx.Bitmap(os.path.join(const.ICON_DIR, "brush_circle.jpg"), wx.BITMAP_TYPE_JPEG) + CIRCLE_BMP = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "brush_circle.jpg"), wx.BITMAP_TYPE_JPEG) item = wx.MenuItem(menu, MENU_BRUSH_CIRCLE, _("Circle")) item.SetBitmap(CIRCLE_BMP) - SQUARE_BMP = wx.Bitmap(os.path.join(const.ICON_DIR, "brush_square.jpg"), wx.BITMAP_TYPE_JPEG) + SQUARE_BMP = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "brush_square.jpg"), wx.BITMAP_TYPE_JPEG) item2 = wx.MenuItem(menu, MENU_BRUSH_SQUARE, _("Square")) item2.SetBitmap(SQUARE_BMP) @@ -800,8 +802,8 @@ class EditionTools(wx.Panel): threshold_range=(thresh_min, thresh_max)) def OnMenu(self, evt): - SQUARE_BMP = wx.Bitmap(os.path.join(const.ICON_DIR, "brush_square.jpg"), wx.BITMAP_TYPE_JPEG) - CIRCLE_BMP = wx.Bitmap(os.path.join(const.ICON_DIR, "brush_circle.jpg"), wx.BITMAP_TYPE_JPEG) + SQUARE_BMP = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "brush_square.jpg"), wx.BITMAP_TYPE_JPEG) + CIRCLE_BMP = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "brush_circle.jpg"), wx.BITMAP_TYPE_JPEG) brush = {MENU_BRUSH_CIRCLE: const.BRUSH_CIRCLE, MENU_BRUSH_SQUARE: const.BRUSH_SQUARE} @@ -849,11 +851,11 @@ class WatershedTool(EditionTools): ## LINE 2 menu = wx.Menu() - CIRCLE_BMP = wx.Bitmap(os.path.join(const.ICON_DIR, "brush_circle.jpg"), wx.BITMAP_TYPE_JPEG) + CIRCLE_BMP = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "brush_circle.jpg"), wx.BITMAP_TYPE_JPEG) item = wx.MenuItem(menu, MENU_BRUSH_CIRCLE, _("Circle")) item.SetBitmap(CIRCLE_BMP) - SQUARE_BMP = wx.Bitmap(os.path.join(const.ICON_DIR, "brush_square.jpg"), wx.BITMAP_TYPE_JPEG) + SQUARE_BMP = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "brush_square.jpg"), wx.BITMAP_TYPE_JPEG) item2 = wx.MenuItem(menu, MENU_BRUSH_SQUARE, _("Square")) item2.SetBitmap(SQUARE_BMP) @@ -903,7 +905,7 @@ class WatershedTool(EditionTools): self.ww_wl_cbox = ww_wl_cbox # Line 6 - bmp = wx.Bitmap(os.path.join(const.ICON_DIR, "configuration.png"), wx.BITMAP_TYPE_PNG) + bmp = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "configuration.png"), wx.BITMAP_TYPE_PNG) self.btn_wconfig = wx.BitmapButton(self, -1, bitmap=bmp, size=(bmp.GetWidth()+10, bmp.GetHeight()+10)) self.btn_exp_watershed = wx.Button(self, -1, _('Expand watershed to 3D')) @@ -970,8 +972,8 @@ class WatershedTool(EditionTools): self.gradient_thresh.SetMaxValue(thresh_max) def OnMenu(self, evt): - SQUARE_BMP = wx.Bitmap(os.path.join(const.ICON_DIR, "brush_square.jpg"), wx.BITMAP_TYPE_JPEG) - CIRCLE_BMP = wx.Bitmap(os.path.join(const.ICON_DIR, "brush_circle.jpg"), wx.BITMAP_TYPE_JPEG) + SQUARE_BMP = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "brush_square.jpg"), wx.BITMAP_TYPE_JPEG) + CIRCLE_BMP = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "brush_circle.jpg"), wx.BITMAP_TYPE_JPEG) brush = {MENU_BRUSH_CIRCLE: const.BRUSH_CIRCLE, MENU_BRUSH_SQUARE: const.BRUSH_SQUARE} diff --git a/invesalius/gui/task_surface.py b/invesalius/gui/task_surface.py index 6ab4754..e3bb409 100644 --- a/invesalius/gui/task_surface.py +++ b/invesalius/gui/task_surface.py @@ -38,6 +38,7 @@ import wx.lib.platebtn as pbtn import invesalius.project as prj import invesalius.utils as utl +from invesalius import inv_paths from invesalius.gui.widgets.inv_spinctrl import InvSpinCtrl, InvFloatSpinCtrl #INTERPOLATION_MODE_LIST = ["Cubic", "Linear", "NearestNeighbor"] @@ -82,7 +83,7 @@ class InnerTaskPanel(wx.Panel): self.SetAutoLayout(1) - BMP_ADD = wx.Bitmap(os.path.join(const.ICON_DIR, "object_add.png"), wx.BITMAP_TYPE_PNG) + BMP_ADD = wx.Bitmap(os.path.join(inv_paths.ICON_DIR, "object_add.png"), wx.BITMAP_TYPE_PNG) #BMP_ADD.SetWidth(25) #BMP_ADD.SetHeight(25) @@ -330,17 +331,17 @@ class SurfaceTools(wx.Panel): link_seeds.Bind(hl.EVT_HYPERLINK_LEFT, self.OnLinkSeed) # Image(s) for buttons - img_largest = wx.Image(os.path.join(const.ICON_DIR, "connectivity_largest.png"), + img_largest = wx.Image(os.path.join(inv_paths.ICON_DIR, "connectivity_largest.png"), wx.BITMAP_TYPE_PNG) img_largest.Rescale(25, 25) bmp_largest = img_largest.ConvertToBitmap() - img_split_all = wx.Image(os.path.join(const.ICON_DIR, "connectivity_split_all.png"), + img_split_all = wx.Image(os.path.join(inv_paths.ICON_DIR, "connectivity_split_all.png"), wx.BITMAP_TYPE_PNG) img_split_all.Rescale(25, 25) bmp_split_all = img_split_all.ConvertToBitmap() - img_seeds = wx.Image(os.path.join(const.ICON_DIR, "connectivity_manual.png"), + img_seeds = wx.Image(os.path.join(inv_paths.ICON_DIR, "connectivity_manual.png"), wx.BITMAP_TYPE_PNG) img_seeds.Rescale(25, 25) bmp_seeds = img_seeds.ConvertToBitmap() diff --git a/invesalius/gui/widgets/clut_raycasting.py b/invesalius/gui/widgets/clut_raycasting.py index 56134dd..142be55 100644 --- a/invesalius/gui/widgets/clut_raycasting.py +++ b/invesalius/gui/widgets/clut_raycasting.py @@ -29,6 +29,8 @@ from wx.lib.pubsub import pub as Publisher import invesalius.gui.dialogs as dialog import invesalius.constants as const +from invesalius import inv_paths + FONT_COLOUR = (1, 1, 1) LINE_COLOUR = (128, 128, 128) LINE_WIDTH = 2 @@ -634,7 +636,7 @@ class CLUTRaycastingWidget(wx.Panel): self.Histogram.points.append((x, y)) def _build_buttons(self): - img = wx.Image(os.path.join(const.ICON_DIR, 'Floppy.png')) + img = wx.Image(os.path.join(inv_paths.ICON_DIR, 'Floppy.png')) width = img.GetWidth() height = img.GetHeight() self.save_button = Button() diff --git a/invesalius/inv_paths.py b/invesalius/inv_paths.py new file mode 100644 index 0000000..dd7d523 --- /dev/null +++ b/invesalius/inv_paths.py @@ -0,0 +1,79 @@ +import os +import pathlib +import shutil +import sys + +USER_DIR = pathlib.Path().home() +CONF_DIR = pathlib.Path(os.environ.get("XDG_CONFIG_HOME", USER_DIR.joinpath(".config"))) +USER_INV_DIR = CONF_DIR.joinpath("invesalius") +USER_PRESET_DIR = USER_INV_DIR.joinpath("presets") +USER_LOG_DIR = USER_INV_DIR.joinpath("logs") +USER_RAYCASTING_PRESETS_DIRECTORY = USER_PRESET_DIR.joinpath("raycasting") + +OLD_USER_INV_DIR = USER_DIR.joinpath(".invesalius") +OLD_USER_PRESET_DIR = OLD_USER_INV_DIR.joinpath("presets") +OLD_USER_LOG_DIR = OLD_USER_INV_DIR.joinpath("logs") + +INV_TOP_DIR = pathlib.Path(__file__).parent.parent.resolve() + +ICON_DIR = INV_TOP_DIR.joinpath("icons") +SAMPLE_DIR = INV_TOP_DIR.joinpath("samples") +DOC_DIR = INV_TOP_DIR.joinpath("docs") +RAYCASTING_PRESETS_DIRECTORY = INV_TOP_DIR.joinpath("presets", "raycasting") +RAYCASTING_PRESETS_COLOR_DIRECTORY = INV_TOP_DIR.joinpath( + "presets", "raycasting", "color_list" +) + +# Inside the windows executable +if hasattr(sys, "frozen") and ( + sys.frozen == "windows_exe" or sys.frozen == "console_exe" +): + abs_path = INV_TOP_DIR.parent.resolve() + ICON_DIR = abs_path.joinpath("icons") + SAMPLE_DIR = INV_TOP_DIR.joinpath("samples") + DOC_DIR = INV_TOP_DIR.joinpath("docs") + RAYCASTING_PRESETS_DIRECTORY = abs_path.joinpath("presets", "raycasting") + RAYCASTING_PRESETS_COLOR_DIRECTORY = abs_path.joinpath( + "presets", "raycasting", "color_list" + ) +else: + + ICON_DIR = pathlib.Path(os.environ.get("INV_ICON_DIR", ICON_DIR)) + SAMPLE_DIR = pathlib.Path(os.environ.get("INV_SAMPLE_DIR", SAMPLE_DIR)) + DOC_DIR = pathlib.Path(os.environ.get("INV_DOC_DIR", DOC_DIR)) + RAYCASTING_PRESETS_DIRECTORY = pathlib.Path( + os.environ.get("INV_RAYCASTING_PRESETS_DIR", RAYCASTING_PRESETS_DIRECTORY) + ) + RAYCASTING_PRESETS_COLOR_DIRECTORY = pathlib.Path( + os.environ.get("INV_RAYCASTING_COLOR_DIR", RAYCASTING_PRESETS_COLOR_DIRECTORY) + ) + +# Navigation paths +CAL_DIR = INV_TOP_DIR.joinpath("navigation", "mtc_files", "CalibrationFiles") +MAR_DIR = INV_TOP_DIR.joinpath("navigation", "mtc_files", "Markers") +OBJ_DIR = INV_TOP_DIR.joinpath("navigation", "objects") + +# MAC App +if not os.path.exists(ICON_DIR): + ICON_DIR = INV_TOP_DIR.parent.parent.joinpath("icons").resolve() + SAMPLE_DIR = INV_TOP_DIR.parent.parent.joinpath("samples").resolve() + DOC_DIR = INV_TOP_DIR.parent.parent.joinpath("docs").resolve() + + +def create_conf_folders(): + USER_INV_DIR.mkdir(parents=True, exist_ok=True) + USER_PRESET_DIR.mkdir(parents=True, exist_ok=True) + USER_LOG_DIR.mkdir(parents=True, exist_ok=True) + + +def copy_old_files(): + for f in OLD_USER_INV_DIR.glob("*"): + if f.is_file(): + print( + shutil.copy( + f, + USER_INV_DIR.joinpath( + str(f).replace(str(OLD_USER_INV_DIR) + "/", "") + ), + ) + ) diff --git a/invesalius/presets.py b/invesalius/presets.py index 7a39760..408e543 100644 --- a/invesalius/presets.py +++ b/invesalius/presets.py @@ -24,7 +24,10 @@ import invesalius.constants as const from wx.lib.pubsub import pub as Publisher +from invesalius import inv_paths from invesalius.utils import TwoWaysDictionary + + class Presets(): def __init__(self): @@ -169,7 +172,7 @@ class Presets(): def get_wwwl_presets(): - files = glob.glob(os.path.join(const.RAYCASTING_PRESETS_COLOR_DIRECTORY, '*.plist')) + files = glob.glob(os.path.join(inv_paths.RAYCASTING_PRESETS_COLOR_DIRECTORY, '*.plist')) presets = {} for f in files: p = os.path.splitext(os.path.basename(f))[0] diff --git a/invesalius/project.py b/invesalius/project.py index 0dead02..478db42 100644 --- a/invesalius/project.py +++ b/invesalius/project.py @@ -39,6 +39,8 @@ from invesalius.presets import Presets from invesalius.utils import Singleton, debug, touch, decode import invesalius.version as version +from invesalius import inv_paths + if sys.platform == 'win32': try: import win32api @@ -280,7 +282,7 @@ class Project(with_metaclass(Singleton, object)): import invesalius.data.surface as srf if not const.VTK_WARNING: - log_path = os.path.join(const.USER_LOG_DIR, 'vtkoutput.txt') + log_path = os.path.join(inv_paths.USER_LOG_DIR, 'vtkoutput.txt') fow = vtk.vtkFileOutputWindow() fow.SetFileName(log_path.encode(const.FS_ENCODE)) ow = vtk.vtkOutputWindow() diff --git a/invesalius/reader/bitmap_reader.py b/invesalius/reader/bitmap_reader.py index e496f40..0f532ad 100644 --- a/invesalius/reader/bitmap_reader.py +++ b/invesalius/reader/bitmap_reader.py @@ -35,6 +35,9 @@ import imghdr import invesalius.utils as utils import invesalius.data.converters as converters +from invesalius import inv_paths + + #flag to control vtk error in read files no_error = True vtk_error = False @@ -299,7 +302,7 @@ def ScipyRead(filepath): def VtkRead(filepath, t): if not const.VTK_WARNING: - log_path = os.path.join(const.USER_LOG_DIR, 'vtkoutput.txt') + log_path = os.path.join(inv_paths.USER_LOG_DIR, 'vtkoutput.txt') fow = vtk.vtkFileOutputWindow() fow.SetFileName(log_path.encode(const.FS_ENCODE)) ow = vtk.vtkOutputWindow() diff --git a/invesalius/reader/dicom_reader.py b/invesalius/reader/dicom_reader.py index d3f587b..9208c69 100644 --- a/invesalius/reader/dicom_reader.py +++ b/invesalius/reader/dicom_reader.py @@ -35,6 +35,7 @@ import invesalius.session as session import glob import invesalius.utils as utils +from invesalius import inv_paths from invesalius.data import imagedata_utils import plistlib @@ -334,7 +335,7 @@ class ProgressDicomReader: def GetDicomGroups(self, path, recursive): if not const.VTK_WARNING: - log_path = utils.encode(os.path.join(const.USER_LOG_DIR, 'vtkoutput.txt'), const.FS_ENCODE) + log_path = utils.encode(str(inv_paths.USER_LOG_DIR.joinpath('vtkoutput.txt')), const.FS_ENCODE) fow = vtk.vtkFileOutputWindow() fow.SetFileName(log_path) ow = vtk.vtkOutputWindow() diff --git a/invesalius/reader/others_reader.py b/invesalius/reader/others_reader.py index 2cb4e3f..7ab2c41 100644 --- a/invesalius/reader/others_reader.py +++ b/invesalius/reader/others_reader.py @@ -23,6 +23,7 @@ import vtk import nibabel as nib import invesalius.constants as const +from invesalius import inv_paths def ReadOthers(dir_): @@ -38,7 +39,7 @@ def ReadOthers(dir_): """ if not const.VTK_WARNING: - log_path = os.path.join(const.USER_LOG_DIR, 'vtkoutput.txt') + log_path = os.path.join(inv_paths.USER_LOG_DIR, 'vtkoutput.txt') fow = vtk.vtkFileOutputWindow() fow.SetFileName(log_path.encode(const.FS_ENCODE)) ow = vtk.vtkOutputWindow() diff --git a/invesalius/session.py b/invesalius/session.py index b6e08c7..f30e5a8 100644 --- a/invesalius/session.py +++ b/invesalius/session.py @@ -40,22 +40,12 @@ import wx from invesalius.utils import Singleton, debug, decode from random import randint +from invesalius import inv_paths + FS_ENCODE = sys.getfilesystemencoding() -if sys.platform == 'win32': - from invesalius.expanduser import expand_user - try: - USER_DIR = expand_user() - except: - USER_DIR = decode(os.path.expanduser('~'), FS_ENCODE) -else: - USER_DIR = decode(os.path.expanduser('~'), FS_ENCODE) - -USER_INV_DIR = os.path.join(USER_DIR, u'.invesalius') -USER_PRESET_DIR = os.path.join(USER_INV_DIR, u'presets') -USER_LOG_DIR = os.path.join(USER_INV_DIR, u'logs') -USER_INV_CFG_PATH = os.path.join(USER_INV_DIR, 'config.json') -OLD_USER_INV_CFG_PATH = os.path.join(USER_INV_DIR, 'config.cfg') +USER_INV_CFG_PATH = os.path.join(inv_paths.USER_INV_DIR, 'config.json') +OLD_USER_INV_CFG_PATH = os.path.join(inv_paths.USER_INV_DIR, 'config.cfg') SESSION_ENCODING = 'utf8' @@ -98,8 +88,8 @@ class Session(with_metaclass(Singleton, object)): def CreateItens(self): import invesalius.constants as const - homedir = USER_DIR - tempdir = os.path.join(USER_DIR, u".invesalius", u"temp") + homedir = inv_paths.USER_DIR + tempdir = os.path.join(inv_paths.USER_DIR, u".invesalius", u"temp") if not os.path.isdir(tempdir): os.makedirs(tempdir) @@ -116,11 +106,11 @@ class Session(with_metaclass(Singleton, object)): }, 'project': { - 'recent_projects': [(const.SAMPLE_DIR, u"Cranium.inv3"), ], + 'recent_projects': [(inv_paths.SAMPLE_DIR, u"Cranium.inv3"), ], }, 'paths': { - 'homedir': USER_DIR, + 'homedir': inv_paths.USER_DIR, 'tempdir': os.path.join(homedir, u".invesalius", u"temp"), 'last_dicom_folder': '', }, -- libgit2 0.21.2