Commit 696200d161b10c21efdaac01612fc15df181f7ed
Committed by
GitHub
1 parent
a573cf37
Exists in
master
Python3 and wxPython4 support (also run in Python2 and wxPython3) (#135)
* Starting to port to python3 * String decode error with python3 * More string decode and print * More errors with wxpython modules * More errors with wxpython modules and prints * More errors with wxpython modules, prints and xrange * wx hyperlink import errors * print, xrange and wx import errors on tasks * more print and xrange errors * more print and xrange errors in dicom reader * taskbaricon error * print and xrange errors in surface code parts * print and xrange errors * metaclass in python3 using six * StringIO to BytesIO * Hyperlinkctrl errors * SystemSettings errors * AddSizer -> Add * More hyperlink errors * AddSpacer -> Add * Temporary fixes * Temporary fixes * Creating preferences dialog * Update checking working * presets and other errors * Opening inv3 proj * Measures and gradiente widget (from manual segmentation) working * Task thresholding, manual segmentation and watershed working * Changed a bunch of xrange to range * Opening dicom from command line * Opening dicom by the gui * Showing raycasting * clut raycasting working * Changing viewer volume colour working again * Saving inv3 files * Surface creation dialog and mask and surface colour setting * Region growing gui working again * Crop mask working again * Reorient image working again * New mask gui dialog working again * Mask boolean operations working again * Fill holes manually working again * Fill holes automatically working again * Fill holes automatically radiobox set default values * Select parts working again * Handling all exceptions when verifying update * Entering in navigate mode and the navigate debug device * Custom pseudocolor gui working again * Opening bitmap folder working again * Expanding watershed working again * Resize dicom dialog gui working again * Converted the rest of the dialogs * Exporting mesh files * Exporting mesh files * Datanotebook (surface and measures) working again * Fixed crash when closing project (because of checking an unused menu in slice viewer) * UnIniting auimanager when closing invesalius gui * Fill holes manually working in both wxpython 3 and 4 * Fill holes automatically working in both wxpython 3 and 4 * Crop working in both wxpython 3 and 4 * Opening bmp files working in both wxpython 3 and 4 * Colors of measures * Changes in Neuronavigation to work with wxpython4 and python3 * Forcing surface and mask colour to always be a triple (r, g, b) * Workaround to make InVesalius run in wxPython in Ubuntu 18.04
Showing
54 changed files
with
908 additions
and
571 deletions
Show diff stats
app.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # detalhes. |
| 19 | 19 | #------------------------------------------------------------------------- |
| 20 | 20 | |
| 21 | +from __future__ import print_function | |
| 21 | 22 | |
| 22 | 23 | import multiprocessing |
| 23 | 24 | import optparse as op |
| ... | ... | @@ -30,14 +31,18 @@ import re |
| 30 | 31 | |
| 31 | 32 | if sys.platform == 'win32': |
| 32 | 33 | import _winreg |
| 33 | -else: | |
| 34 | - if sys.platform != 'darwin': | |
| 35 | - import wxversion | |
| 36 | - #wxversion.ensureMinimal('2.8-unicode', optionsRequired=True) | |
| 37 | - #wxversion.select('2.8-unicode', optionsRequired=True) | |
| 38 | - wxversion.ensureMinimal('3.0') | |
| 34 | +# else: | |
| 35 | + # if sys.platform != 'darwin': | |
| 36 | + # import wxversion | |
| 37 | + # #wxversion.ensureMinimal('2.8-unicode', optionsRequired=True) | |
| 38 | + # #wxversion.select('2.8-unicode', optionsRequired=True) | |
| 39 | + # # wxversion.ensureMinimal('4.0') | |
| 39 | 40 | |
| 40 | 41 | import wx |
| 42 | +try: | |
| 43 | + from wx.adv import SplashScreen | |
| 44 | +except ImportError: | |
| 45 | + from wx import SplashScreen | |
| 41 | 46 | #from wx.lib.pubsub import setupv1 #new wx |
| 42 | 47 | from wx.lib.pubsub import setuparg1# as psv1 |
| 43 | 48 | #from wx.lib.pubsub import Publisher |
| ... | ... | @@ -64,9 +69,9 @@ if sys.platform == 'win32': |
| 64 | 69 | try: |
| 65 | 70 | USER_DIR = expand_user() |
| 66 | 71 | except: |
| 67 | - USER_DIR = os.path.expanduser('~').decode(FS_ENCODE) | |
| 72 | + USER_DIR = utils.decode(os.path.expanduser('~'), FS_ENCODE) | |
| 68 | 73 | else: |
| 69 | - USER_DIR = os.path.expanduser('~').decode(FS_ENCODE) | |
| 74 | + USER_DIR = utils.decode(os.path.expanduser('~'),FS_ENCODE) | |
| 70 | 75 | |
| 71 | 76 | USER_INV_DIR = os.path.join(USER_DIR, u'.invesalius') |
| 72 | 77 | USER_PRESET_DIR = os.path.join(USER_INV_DIR, u'presets') |
| ... | ... | @@ -75,6 +80,15 @@ USER_LOG_DIR = os.path.join(USER_INV_DIR, u'logs') |
| 75 | 80 | |
| 76 | 81 | # ------------------------------------------------------------------ |
| 77 | 82 | |
| 83 | +if sys.platform == 'linux2': | |
| 84 | + try: | |
| 85 | + tmp_var = wx.GetXDisplay | |
| 86 | + except AttributeError: | |
| 87 | + # A workaround to make InVesalius run with wxPython4 from Ubuntu 18.04 | |
| 88 | + wx.GetXDisplay = lambda: None | |
| 89 | + else: | |
| 90 | + del tmp_var | |
| 91 | + | |
| 78 | 92 | |
| 79 | 93 | class InVesalius(wx.App): |
| 80 | 94 | """ |
| ... | ... | @@ -89,7 +103,7 @@ class InVesalius(wx.App): |
| 89 | 103 | freeze_support() |
| 90 | 104 | |
| 91 | 105 | self.SetAppName("InVesalius 3") |
| 92 | - self.splash = SplashScreen() | |
| 106 | + self.splash = Inv3SplashScreen() | |
| 93 | 107 | self.splash.Show() |
| 94 | 108 | wx.CallLater(1000,self.Startup2) |
| 95 | 109 | |
| ... | ... | @@ -111,7 +125,7 @@ class InVesalius(wx.App): |
| 111 | 125 | |
| 112 | 126 | # ------------------------------------------------------------------ |
| 113 | 127 | |
| 114 | -class SplashScreen(wx.SplashScreen): | |
| 128 | +class Inv3SplashScreen(SplashScreen): | |
| 115 | 129 | """ |
| 116 | 130 | Splash screen to be shown in InVesalius initialization. |
| 117 | 131 | """ |
| ... | ... | @@ -202,16 +216,20 @@ class SplashScreen(wx.SplashScreen): |
| 202 | 216 | |
| 203 | 217 | bmp = wx.Image(path).ConvertToBitmap() |
| 204 | 218 | |
| 205 | - style = wx.SPLASH_TIMEOUT | wx.SPLASH_CENTRE_ON_SCREEN | |
| 206 | - wx.SplashScreen.__init__(self, | |
| 207 | - bitmap=bmp, | |
| 208 | - splashStyle=style, | |
| 209 | - milliseconds=1500, | |
| 210 | - id=-1, | |
| 211 | - parent=None) | |
| 219 | + try: | |
| 220 | + style = wx.adv.SPLASH_TIMEOUT | wx.adv.SPLASH_CENTRE_ON_SCREEN | |
| 221 | + except AttributeError: | |
| 222 | + style = wx.SPLASH_TIMEOUT | wx.SPLASH_CENTRE_ON_SCREEN | |
| 223 | + | |
| 224 | + SplashScreen.__init__(self, | |
| 225 | + bitmap=bmp, | |
| 226 | + splashStyle=style, | |
| 227 | + milliseconds=1500, | |
| 228 | + id=-1, | |
| 229 | + parent=None) | |
| 212 | 230 | self.Bind(wx.EVT_CLOSE, self.OnClose) |
| 213 | 231 | wx.Yield() |
| 214 | - wx.CallLater(200,self.Startup) | |
| 232 | + wx.CallLater(200, self.Startup) | |
| 215 | 233 | |
| 216 | 234 | def Startup(self): |
| 217 | 235 | # Importing takes sometime, therefore it will be done |
| ... | ... | @@ -349,14 +367,14 @@ def use_cmd_optargs(options, args): |
| 349 | 367 | else: |
| 350 | 368 | for arg in reversed(args): |
| 351 | 369 | |
| 352 | - file = arg.decode(FS_ENCODE) | |
| 370 | + file = utils.decode(arg, FS_ENCODE) | |
| 353 | 371 | if os.path.isfile(file): |
| 354 | 372 | path = os.path.abspath(file) |
| 355 | 373 | Publisher.sendMessage('Open project', path) |
| 356 | 374 | check_for_export(options) |
| 357 | 375 | return True |
| 358 | 376 | |
| 359 | - file = arg.decode(sys.stdin.encoding) | |
| 377 | + file = utils.decode(arg, sys.stdin.encoding) | |
| 360 | 378 | if os.path.isfile(file): |
| 361 | 379 | path = os.path.abspath(file) |
| 362 | 380 | Publisher.sendMessage('Open project', path) | ... | ... |
docs/devel/example_singleton_pubsub.py
invesalius/constants.py
| ... | ... | @@ -23,6 +23,8 @@ import sys |
| 23 | 23 | import wx |
| 24 | 24 | import itertools |
| 25 | 25 | |
| 26 | +from invesalius import utils | |
| 27 | + | |
| 26 | 28 | #from invesalius.project import Project |
| 27 | 29 | INVESALIUS_VERSION = "3.1.1" |
| 28 | 30 | |
| ... | ... | @@ -332,15 +334,15 @@ if sys.platform == 'win32': |
| 332 | 334 | try: |
| 333 | 335 | USER_DIR = expand_user() |
| 334 | 336 | except: |
| 335 | - USER_DIR = os.path.expanduser('~').decode(FS_ENCODE) | |
| 337 | + USER_DIR = utils.decode(os.path.expanduser('~'), FS_ENCODE) | |
| 336 | 338 | else: |
| 337 | - USER_DIR = os.path.expanduser('~').decode(FS_ENCODE) | |
| 339 | + USER_DIR = utils.decode(os.path.expanduser('~'), FS_ENCODE) | |
| 338 | 340 | |
| 339 | 341 | USER_INV_DIR = os.path.join(USER_DIR, u'.invesalius') |
| 340 | 342 | USER_PRESET_DIR = os.path.join(USER_INV_DIR, u'presets') |
| 341 | 343 | USER_LOG_DIR = os.path.join(USER_INV_DIR, u'logs') |
| 342 | 344 | |
| 343 | -FILE_PATH = os.path.split(__file__)[0].decode(FS_ENCODE) | |
| 345 | +FILE_PATH = utils.decode(os.path.split(__file__)[0], FS_ENCODE) | |
| 344 | 346 | |
| 345 | 347 | if hasattr(sys,"frozen") and (sys.frozen == "windows_exe"\ |
| 346 | 348 | or sys.frozen == "console_exe"): | ... | ... |
invesalius/control.py
| ... | ... | @@ -347,7 +347,7 @@ class Controller(): |
| 347 | 347 | dirpath, filename = session.project_path |
| 348 | 348 | |
| 349 | 349 | if isinstance(filename, str): |
| 350 | - filename = filename.decode(const.FS_ENCODE) | |
| 350 | + filename = utils.decode(filename, const.FS_ENCODE) | |
| 351 | 351 | |
| 352 | 352 | proj = prj.Project() |
| 353 | 353 | prj.Project().SavePlistProject(dirpath, filename, compress) |
| ... | ... | @@ -458,7 +458,7 @@ class Controller(): |
| 458 | 458 | def ImportMedicalImages(self, directory, gui=True): |
| 459 | 459 | patients_groups = dcm.GetDicomGroups(directory) |
| 460 | 460 | name = directory.rpartition('\\')[-1].split('.') |
| 461 | - print "patients: ", patients_groups | |
| 461 | + print("patients: ", patients_groups) | |
| 462 | 462 | |
| 463 | 463 | if len(patients_groups): |
| 464 | 464 | # OPTION 1: DICOM |
| ... | ... | @@ -760,7 +760,7 @@ class Controller(): |
| 760 | 760 | Publisher.sendMessage("Enable state project", True) |
| 761 | 761 | |
| 762 | 762 | def OnOpenOtherFiles(self, pubsub_evt): |
| 763 | - filepath = pubsub_evt.data | |
| 763 | + filepath = utils.decode(pubsub_evt.data, const.FS_ENCODE) | |
| 764 | 764 | if not(filepath) == None: |
| 765 | 765 | name = filepath.rpartition('\\')[-1].split('.') |
| 766 | 766 | |
| ... | ... | @@ -785,7 +785,7 @@ class Controller(): |
| 785 | 785 | utils.debug("Not used the IPPSorter") |
| 786 | 786 | filelist = [i.image.file for i in dicom_group.GetHandSortedList()[::interval]] |
| 787 | 787 | |
| 788 | - if file_range != None and file_range[1] > file_range[0]: | |
| 788 | + if file_range is not None and file_range[0] is not None and file_range[1] > file_range[0]: | |
| 789 | 789 | filelist = filelist[file_range[0]:file_range[1] + 1] |
| 790 | 790 | |
| 791 | 791 | zspacing = dicom_group.zspacing * interval |
| ... | ... | @@ -828,7 +828,7 @@ class Controller(): |
| 828 | 828 | self.matrix, scalar_range, self.filename = image_utils.dcm2memmap(filelist, size, |
| 829 | 829 | orientation, resolution_percentage) |
| 830 | 830 | |
| 831 | - print xyspacing, zspacing | |
| 831 | + print(xyspacing, zspacing) | |
| 832 | 832 | if orientation == 'AXIAL': |
| 833 | 833 | spacing = xyspacing[0], xyspacing[1], zspacing |
| 834 | 834 | elif orientation == 'CORONAL': |
| ... | ... | @@ -893,7 +893,7 @@ class Controller(): |
| 893 | 893 | proj = prj.Project() |
| 894 | 894 | |
| 895 | 895 | thresh_modes = proj.threshold_modes.keys() |
| 896 | - thresh_modes.sort() | |
| 896 | + thresh_modes = sorted(thresh_modes) | |
| 897 | 897 | default_threshold = const.THRESHOLD_PRESETS_INDEX |
| 898 | 898 | if proj.mask_dict: |
| 899 | 899 | keys = proj.mask_dict.keys() | ... | ... |
invesalius/data/coordinates.py
| ... | ... | @@ -47,7 +47,7 @@ def GetCoordinates(trck_init, trck_id, ref_mode): |
| 47 | 47 | 5: DebugCoord} |
| 48 | 48 | coord = getcoord[trck_id](trck_init, trck_id, ref_mode) |
| 49 | 49 | else: |
| 50 | - print "Select Tracker" | |
| 50 | + print("Select Tracker") | |
| 51 | 51 | |
| 52 | 52 | return coord |
| 53 | 53 | |
| ... | ... | @@ -70,7 +70,7 @@ def ClaronCoord(trck_init, trck_id, ref_mode): |
| 70 | 70 | k = 30 |
| 71 | 71 | except AttributeError: |
| 72 | 72 | k += 1 |
| 73 | - print "wait, collecting coordinates ..." | |
| 73 | + print("wait, collecting coordinates ...") | |
| 74 | 74 | if k == 30: |
| 75 | 75 | coord = dynamic_reference(probe, reference) |
| 76 | 76 | coord = (coord[0] * scale[0], coord[1] * scale[1], coord[2] * scale[2], coord[3], coord[4], coord[5]) |
| ... | ... | @@ -84,7 +84,7 @@ def ClaronCoord(trck_init, trck_id, ref_mode): |
| 84 | 84 | k = 30 |
| 85 | 85 | except AttributeError: |
| 86 | 86 | k += 1 |
| 87 | - print "wait, collecting coordinates ..." | |
| 87 | + print("wait, collecting coordinates ...") | |
| 88 | 88 | |
| 89 | 89 | Publisher.sendMessage('Sensors ID', [trck.probeID, trck.refID]) |
| 90 | 90 | |
| ... | ... | @@ -180,7 +180,7 @@ def PolhemusSerialCoord(trck_init, trck_id, ref_mode): |
| 180 | 180 | coord = None |
| 181 | 181 | |
| 182 | 182 | if lines[0][0] != '0': |
| 183 | - print "The Polhemus is not connected!" | |
| 183 | + print("The Polhemus is not connected!") | |
| 184 | 184 | else: |
| 185 | 185 | for s in lines: |
| 186 | 186 | if s[1] == '1': |
| ... | ... | @@ -198,7 +198,7 @@ def PolhemusSerialCoord(trck_init, trck_id, ref_mode): |
| 198 | 198 | plh1 = [float(s) for s in data[1:len(data)]] |
| 199 | 199 | j = 1 |
| 200 | 200 | except: |
| 201 | - print "error!!" | |
| 201 | + print("error!!") | |
| 202 | 202 | |
| 203 | 203 | coord = data[0:6] |
| 204 | 204 | return coord | ... | ... |
invesalius/data/cursor_actors.py
| ... | ... | @@ -205,7 +205,7 @@ class CursorBase(object): |
| 205 | 205 | |
| 206 | 206 | def _set_colour(self, imagedata, colour): |
| 207 | 207 | scalar_range = int(imagedata.GetScalarRange()[1]) |
| 208 | - r, g, b = colour | |
| 208 | + r, g, b = colour[:3] | |
| 209 | 209 | |
| 210 | 210 | # map scalar values into colors |
| 211 | 211 | lut_mask = vtk.vtkLookupTable() |
| ... | ... | @@ -319,7 +319,7 @@ class CursorRectangle(CursorBase): |
| 319 | 319 | """ |
| 320 | 320 | Function to plot the Retangle |
| 321 | 321 | """ |
| 322 | - print "Building rectangle cursor", self.orientation | |
| 322 | + print("Building rectangle cursor", self.orientation) | |
| 323 | 323 | r = self.radius |
| 324 | 324 | sx, sy, sz = self.spacing |
| 325 | 325 | if self.orientation == 'AXIAL': | ... | ... |
invesalius/data/geometry.py
| ... | ... | @@ -18,6 +18,8 @@ |
| 18 | 18 | # detalhes. |
| 19 | 19 | #-------------------------------------------------------------------------- |
| 20 | 20 | |
| 21 | +from six import with_metaclass | |
| 22 | + | |
| 21 | 23 | import numpy as np |
| 22 | 24 | import math |
| 23 | 25 | import vtk |
| ... | ... | @@ -27,14 +29,12 @@ import invesalius.utils as utils |
| 27 | 29 | import invesalius.constants as const |
| 28 | 30 | |
| 29 | 31 | |
| 30 | -class Box(object): | |
| 32 | +class Box(with_metaclass(utils.Singleton, object)): | |
| 31 | 33 | """ |
| 32 | - This class is a data structure for storing the | |
| 34 | + This class is a data structure for storing the | |
| 33 | 35 | coordinates (min and max) of box used in crop-mask. |
| 34 | 36 | """ |
| 35 | 37 | |
| 36 | - __metaclass__= utils.Singleton | |
| 37 | - | |
| 38 | 38 | def __init__(self): |
| 39 | 39 | self.xi = None |
| 40 | 40 | self.xf = None |
| ... | ... | @@ -356,7 +356,7 @@ class DrawCrop2DRetangle(): |
| 356 | 356 | x_pos_sl = x_pos_sl_ * xs |
| 357 | 357 | y_pos_sl = y_pos_sl_ * ys |
| 358 | 358 | |
| 359 | - for k, p in self.box.axial.iteritems(): | |
| 359 | + for k, p in self.box.axial.items(): | |
| 360 | 360 | p0 = p[0] |
| 361 | 361 | p1 = p[1] |
| 362 | 362 | |
| ... | ... | @@ -386,7 +386,7 @@ class DrawCrop2DRetangle(): |
| 386 | 386 | x_pos_sl = x_pos_sl_ * xs |
| 387 | 387 | y_pos_sl = y_pos_sl_ * zs |
| 388 | 388 | |
| 389 | - for k, p in self.box.coronal.iteritems(): | |
| 389 | + for k, p in self.box.coronal.items(): | |
| 390 | 390 | p0 = p[0] |
| 391 | 391 | p1 = p[1] |
| 392 | 392 | |
| ... | ... | @@ -415,7 +415,7 @@ class DrawCrop2DRetangle(): |
| 415 | 415 | x_pos_sl = x_pos_sl_ * ys |
| 416 | 416 | y_pos_sl = y_pos_sl_ * zs |
| 417 | 417 | |
| 418 | - for k, p in self.box.sagital.iteritems(): | |
| 418 | + for k, p in self.box.sagital.items(): | |
| 419 | 419 | p0 = p[0] |
| 420 | 420 | p1 = p[1] |
| 421 | 421 | ... | ... |
invesalius/data/imagedata_utils.py
| ... | ... | @@ -265,7 +265,7 @@ def ExtractVOI(imagedata,xi,xf,yi,yf,zi,zf): |
| 265 | 265 | |
| 266 | 266 | def create_dicom_thumbnails(filename, window=None, level=None): |
| 267 | 267 | rvtk = vtkgdcm.vtkGDCMImageReader() |
| 268 | - rvtk.SetFileName(filename) | |
| 268 | + rvtk.SetFileName(utils.encode(filename, const.FS_ENCODE)) | |
| 269 | 269 | rvtk.Update() |
| 270 | 270 | |
| 271 | 271 | img = rvtk.GetOutput() |
| ... | ... | @@ -278,7 +278,7 @@ def create_dicom_thumbnails(filename, window=None, level=None): |
| 278 | 278 | |
| 279 | 279 | if dz > 1: |
| 280 | 280 | thumbnail_paths = [] |
| 281 | - for i in xrange(dz): | |
| 281 | + for i in range(dz): | |
| 282 | 282 | img_slice = ExtractVOI(img, 0, dx-1, 0, dy-1, i, i+1) |
| 283 | 283 | |
| 284 | 284 | colorer = vtk.vtkImageMapToWindowLevelColors() |
| ... | ... | @@ -355,7 +355,7 @@ def CreateImageData(filelist, zspacing, xyspacing,size, |
| 355 | 355 | update_progress= vtk_utils.ShowProgress(1, dialog_type = "ProgressDialog") |
| 356 | 356 | |
| 357 | 357 | array = vtk.vtkStringArray() |
| 358 | - for x in xrange(len(filelist)): | |
| 358 | + for x in range(len(filelist)): | |
| 359 | 359 | array.InsertValue(x,filelist[x]) |
| 360 | 360 | |
| 361 | 361 | reader = vtkgdcm.vtkGDCMImageReader() |
| ... | ... | @@ -385,7 +385,7 @@ def CreateImageData(filelist, zspacing, xyspacing,size, |
| 385 | 385 | |
| 386 | 386 | |
| 387 | 387 | # Reformat each slice |
| 388 | - for x in xrange(len(filelist)): | |
| 388 | + for x in range(len(filelist)): | |
| 389 | 389 | # TODO: We need to check this automatically according |
| 390 | 390 | # to each computer's architecture |
| 391 | 391 | # If the resolution of the matrix is too large |
| ... | ... | @@ -459,7 +459,7 @@ class ImageCreator: |
| 459 | 459 | update_progress= vtk_utils.ShowProgress(1, dialog_type = "ProgressDialog") |
| 460 | 460 | |
| 461 | 461 | array = vtk.vtkStringArray() |
| 462 | - for x in xrange(len(filelist)): | |
| 462 | + for x in range(len(filelist)): | |
| 463 | 463 | if not self.running: |
| 464 | 464 | return False |
| 465 | 465 | array.InsertValue(x,filelist[x]) |
| ... | ... | @@ -491,7 +491,7 @@ class ImageCreator: |
| 491 | 491 | |
| 492 | 492 | |
| 493 | 493 | # Reformat each slice |
| 494 | - for x in xrange(len(filelist)): | |
| 494 | + for x in range(len(filelist)): | |
| 495 | 495 | # TODO: We need to check this automatically according |
| 496 | 496 | # to each computer's architecture |
| 497 | 497 | # If the resolution of the matrix is too large |
| ... | ... | @@ -683,11 +683,11 @@ def dcmmf2memmap(dcm_file, orientation): |
| 683 | 683 | d.shape = z, y, x |
| 684 | 684 | if orientation == 'CORONAL': |
| 685 | 685 | matrix.shape = y, z, x |
| 686 | - for n in xrange(z): | |
| 686 | + for n in range(z): | |
| 687 | 687 | matrix[:, n, :] = d[n] |
| 688 | 688 | elif orientation == 'SAGITTAL': |
| 689 | 689 | matrix.shape = x, z, y |
| 690 | - for n in xrange(z): | |
| 690 | + for n in range(z): | |
| 691 | 691 | matrix[:, :, n] = d[n] |
| 692 | 692 | else: |
| 693 | 693 | matrix[:] = d |
| ... | ... | @@ -695,7 +695,7 @@ def dcmmf2memmap(dcm_file, orientation): |
| 695 | 695 | matrix.flush() |
| 696 | 696 | scalar_range = matrix.min(), matrix.max() |
| 697 | 697 | |
| 698 | - print "ORIENTATION", orientation | |
| 698 | + print("ORIENTATION", orientation) | |
| 699 | 699 | |
| 700 | 700 | return matrix, spacing, scalar_range, temp_file |
| 701 | 701 | ... | ... |
invesalius/data/mask.py
| ... | ... | @@ -46,7 +46,7 @@ class EditionHistoryNode(object): |
| 46 | 46 | |
| 47 | 47 | def _save_array(self, array): |
| 48 | 48 | np.save(self.filename, array) |
| 49 | - print "Saving history", self.index, self.orientation, self.filename, self.clean | |
| 49 | + print("Saving history", self.index, self.orientation, self.filename, self.clean) | |
| 50 | 50 | |
| 51 | 51 | def commit_history(self, mvolume): |
| 52 | 52 | array = np.load(self.filename) |
| ... | ... | @@ -65,10 +65,10 @@ class EditionHistoryNode(object): |
| 65 | 65 | elif self.orientation == 'VOLUME': |
| 66 | 66 | mvolume[:] = array |
| 67 | 67 | |
| 68 | - print "applying to", self.orientation, "at slice", self.index | |
| 68 | + print("applying to", self.orientation, "at slice", self.index) | |
| 69 | 69 | |
| 70 | 70 | def __del__(self): |
| 71 | - print "Removing", self.filename | |
| 71 | + print("Removing", self.filename) | |
| 72 | 72 | os.remove(self.filename) |
| 73 | 73 | |
| 74 | 74 | |
| ... | ... | @@ -99,7 +99,7 @@ class EditionHistory(object): |
| 99 | 99 | self.history.append(node) |
| 100 | 100 | self.index += 1 |
| 101 | 101 | |
| 102 | - print "INDEX", self.index, len(self.history), self.history | |
| 102 | + print("INDEX", self.index, len(self.history), self.history) | |
| 103 | 103 | Publisher.sendMessage("Enable undo", True) |
| 104 | 104 | Publisher.sendMessage("Enable redo", False) |
| 105 | 105 | |
| ... | ... | @@ -128,7 +128,7 @@ class EditionHistory(object): |
| 128 | 128 | |
| 129 | 129 | if self.index == 0: |
| 130 | 130 | Publisher.sendMessage("Enable undo", False) |
| 131 | - print "AT", self.index, len(self.history), self.history[self.index].filename | |
| 131 | + print("AT", self.index, len(self.history), self.history[self.index].filename) | |
| 132 | 132 | |
| 133 | 133 | def redo(self, mvolume, actual_slices=None): |
| 134 | 134 | h = self.history |
| ... | ... | @@ -156,7 +156,7 @@ class EditionHistory(object): |
| 156 | 156 | |
| 157 | 157 | if self.index == len(h) - 1: |
| 158 | 158 | Publisher.sendMessage("Enable redo", False) |
| 159 | - print "AT", self.index, len(h), h[self.index].filename | |
| 159 | + print("AT", self.index, len(h), h[self.index].filename) | |
| 160 | 160 | |
| 161 | 161 | def _reload_slice(self, index): |
| 162 | 162 | Publisher.sendMessage(('Set scroll position', self.history[index].orientation), |
| ... | ... | @@ -236,7 +236,7 @@ class Mask(): |
| 236 | 236 | |
| 237 | 237 | mask['index'] = self.index |
| 238 | 238 | mask['name'] = self.name |
| 239 | - mask['colour'] = self.colour | |
| 239 | + mask['colour'] = self.colour[:3] | |
| 240 | 240 | mask['opacity'] = self.opacity |
| 241 | 241 | mask['threshold_range'] = self.threshold_range |
| 242 | 242 | mask['edition_threshold_range'] = self.edition_threshold_range |
| ... | ... | @@ -289,13 +289,12 @@ class Mask(): |
| 289 | 289 | def OnSwapVolumeAxes(self, pubsub_evt): |
| 290 | 290 | axis0, axis1 = pubsub_evt.data |
| 291 | 291 | self.matrix = self.matrix.swapaxes(axis0, axis1) |
| 292 | - print type(self.matrix) | |
| 293 | 292 | |
| 294 | 293 | def _save_mask(self, filename): |
| 295 | 294 | shutil.copyfile(self.temp_file, filename) |
| 296 | 295 | |
| 297 | 296 | def _open_mask(self, filename, shape, dtype='uint8'): |
| 298 | - print ">>", filename, shape | |
| 297 | + print(">>", filename, shape) | |
| 299 | 298 | self.temp_file = filename |
| 300 | 299 | self.matrix = np.memmap(filename, shape=shape, dtype=dtype, mode="r+") |
| 301 | 300 | ... | ... |
invesalius/data/measures.py
| 1 | 1 | #!/usr/bin/env python |
| 2 | 2 | # -*- coding: UTF-8 -*- |
| 3 | 3 | |
| 4 | +from six import with_metaclass | |
| 5 | + | |
| 4 | 6 | import math |
| 5 | 7 | import random |
| 6 | 8 | import sys |
| ... | ... | @@ -46,11 +48,10 @@ else: |
| 46 | 48 | MEASURE_TEXT_COLOUR = (0, 0, 0) |
| 47 | 49 | MEASURE_TEXTBOX_COLOUR = (255, 255, 165, 255) |
| 48 | 50 | |
| 49 | -class MeasureData: | |
| 51 | +class MeasureData(with_metaclass(utils.Singleton)): | |
| 50 | 52 | """ |
| 51 | 53 | Responsible to keep measures data. |
| 52 | 54 | """ |
| 53 | - __metaclass__= utils.Singleton | |
| 54 | 55 | def __init__(self): |
| 55 | 56 | self.measures = {const.SURFACE: {}, |
| 56 | 57 | const.AXIAL: {}, |
| ... | ... | @@ -358,7 +359,7 @@ class Measurement(): |
| 358 | 359 | Measurement.general_index += 1 |
| 359 | 360 | self.index = Measurement.general_index |
| 360 | 361 | self.name = const.MEASURE_NAME_PATTERN %(self.index+1) |
| 361 | - self.colour = const.MEASURE_COLOUR.next() | |
| 362 | + self.colour = next(const.MEASURE_COLOUR) | |
| 362 | 363 | self.value = 0 |
| 363 | 364 | self.location = const.SURFACE # AXIAL, CORONAL, SAGITTAL |
| 364 | 365 | self.type = const.LINEAR # ANGULAR |
| ... | ... | @@ -832,7 +833,7 @@ class AngularMeasure(object): |
| 832 | 833 | for p in self.points: |
| 833 | 834 | coord.SetValue(p) |
| 834 | 835 | cx, cy = coord.GetComputedDoubleDisplayValue(canvas.evt_renderer) |
| 835 | - print cx, cy | |
| 836 | + print(cx, cy) | |
| 836 | 837 | # canvas.draw_circle((cx, cy), 2.5) |
| 837 | 838 | points.append((cx, cy)) |
| 838 | 839 | ... | ... |
invesalius/data/polydata_utils.py
| ... | ... | @@ -78,7 +78,7 @@ def FillSurfaceHole(polydata): |
| 78 | 78 | Fill holes in the given polydata. |
| 79 | 79 | """ |
| 80 | 80 | # Filter used to detect and fill holes. Only fill |
| 81 | - print "Filling polydata" | |
| 81 | + print("Filling polydata") | |
| 82 | 82 | filled_polydata = vtk.vtkFillHolesFilter() |
| 83 | 83 | filled_polydata.SetInputData(polydata) |
| 84 | 84 | filled_polydata.SetHoleSize(500) |
| ... | ... | @@ -133,9 +133,9 @@ def Export(polydata, filename, bin=False): |
| 133 | 133 | |
| 134 | 134 | def Import(filename): |
| 135 | 135 | reader = vtk.vtkXMLPolyDataReader() |
| 136 | - if isinstance(filename, unicode): | |
| 136 | + try: | |
| 137 | 137 | reader.SetFileName(filename.encode(wx.GetDefaultPyEncoding())) |
| 138 | - else: | |
| 138 | + except AttributeError: | |
| 139 | 139 | reader.SetFileName(filename) |
| 140 | 140 | reader.Update() |
| 141 | 141 | return reader.GetOutput() |
| ... | ... | @@ -198,7 +198,7 @@ def SplitDisconectedParts(polydata): |
| 198 | 198 | if progress: |
| 199 | 199 | UpdateProgress = vu.ShowProgress(progress) |
| 200 | 200 | |
| 201 | - for region in xrange(nregions): | |
| 201 | + for region in range(nregions): | |
| 202 | 202 | conn.InitializeSpecifiedRegionList() |
| 203 | 203 | conn.AddSpecifiedRegion(region) |
| 204 | 204 | conn.Update() | ... | ... |
invesalius/data/slice_.py
| ... | ... | @@ -16,6 +16,8 @@ |
| 16 | 16 | # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais |
| 17 | 17 | # detalhes. |
| 18 | 18 | #-------------------------------------------------------------------------- |
| 19 | +from six import with_metaclass | |
| 20 | + | |
| 19 | 21 | import os |
| 20 | 22 | import tempfile |
| 21 | 23 | |
| ... | ... | @@ -72,12 +74,10 @@ class SliceBuffer(object): |
| 72 | 74 | self.vtk_mask = None |
| 73 | 75 | |
| 74 | 76 | |
| 75 | -class Slice(object): | |
| 76 | - __metaclass__= utils.Singleton | |
| 77 | - # Only one slice will be initialized per time (despite several viewers | |
| 78 | - # show it from distinct perspectives). | |
| 79 | - # Therefore, we use Singleton design pattern for implementing it. | |
| 80 | - | |
| 77 | +# Only one slice will be initialized per time (despite several viewers | |
| 78 | +# show it from distinct perspectives). | |
| 79 | +# Therefore, we use Singleton design pattern for implementing it. | |
| 80 | +class Slice(with_metaclass(utils.Singleton, object)): | |
| 81 | 81 | def __init__(self): |
| 82 | 82 | self.current_mask = None |
| 83 | 83 | self.blend_filter = None |
| ... | ... | @@ -841,7 +841,7 @@ class Slice(object): |
| 841 | 841 | proj = Project() |
| 842 | 842 | proj.mask_dict[index].colour = colour |
| 843 | 843 | |
| 844 | - (r,g,b) = colour | |
| 844 | + (r,g,b) = colour[:3] | |
| 845 | 845 | colour_wx = [r*255, g*255, b*255] |
| 846 | 846 | Publisher.sendMessage('Change mask colour in notebook', |
| 847 | 847 | (index, (r,g,b))) |
| ... | ... | @@ -1230,7 +1230,7 @@ class Slice(object): |
| 1230 | 1230 | """ |
| 1231 | 1231 | if mask is None: |
| 1232 | 1232 | mask = self.current_mask |
| 1233 | - for n in xrange(1, mask.matrix.shape[0]): | |
| 1233 | + for n in range(1, mask.matrix.shape[0]): | |
| 1234 | 1234 | if mask.matrix[n, 0, 0] == 0: |
| 1235 | 1235 | m = mask.matrix[n, 1:, 1:] |
| 1236 | 1236 | mask.matrix[n, 1:, 1:] = self.do_threshold_to_a_slice(self.matrix[n-1], m, mask.threshold_range) |
| ... | ... | @@ -1260,7 +1260,7 @@ class Slice(object): |
| 1260 | 1260 | |
| 1261 | 1261 | def do_colour_mask(self, imagedata, opacity): |
| 1262 | 1262 | scalar_range = int(imagedata.GetScalarRange()[1]) |
| 1263 | - r, g, b = self.current_mask.colour | |
| 1263 | + r, g, b = self.current_mask.colour[:3] | |
| 1264 | 1264 | |
| 1265 | 1265 | # map scalar values into colors |
| 1266 | 1266 | lut_mask = vtk.vtkLookupTable() | ... | ... |
invesalius/data/styles.py
| ... | ... | @@ -17,6 +17,8 @@ |
| 17 | 17 | # detalhes. |
| 18 | 18 | #-------------------------------------------------------------------------- |
| 19 | 19 | |
| 20 | +from six import with_metaclass | |
| 21 | + | |
| 20 | 22 | import os |
| 21 | 23 | import multiprocessing |
| 22 | 24 | import tempfile |
| ... | ... | @@ -226,7 +228,7 @@ class CrossInteractorStyle(DefaultInteractorStyle): |
| 226 | 228 | def OnCrossMove(self, obj, evt): |
| 227 | 229 | # The user moved the mouse with left button pressed |
| 228 | 230 | if self.left_pressed: |
| 229 | - print "OnCrossMove interactor style" | |
| 231 | + print("OnCrossMove interactor style") | |
| 230 | 232 | iren = obj.GetInteractor() |
| 231 | 233 | self.ChangeCrossPosition(iren) |
| 232 | 234 | |
| ... | ... | @@ -716,8 +718,7 @@ class ChangeSliceInteractorStyle(DefaultInteractorStyle): |
| 716 | 718 | self.last_position = position[1] |
| 717 | 719 | |
| 718 | 720 | |
| 719 | -class EditorConfig(object): | |
| 720 | - __metaclass__= utils.Singleton | |
| 721 | +class EditorConfig(with_metaclass(utils.Singleton, object)): | |
| 721 | 722 | def __init__(self): |
| 722 | 723 | self.operation = const.BRUSH_THRESH |
| 723 | 724 | self.cursor_type = const.BRUSH_CIRCLE |
| ... | ... | @@ -759,7 +760,7 @@ class EditorInteractorStyle(DefaultInteractorStyle): |
| 759 | 760 | def SetUp(self): |
| 760 | 761 | |
| 761 | 762 | x, y = self.viewer.interactor.ScreenToClient(wx.GetMousePosition()) |
| 762 | - if self.viewer.interactor.HitTestXY(x, y) == wx.HT_WINDOW_INSIDE: | |
| 763 | + if self.viewer.interactor.HitTest((x, y)) == wx.HT_WINDOW_INSIDE: | |
| 763 | 764 | self.viewer.slice_data.cursor.Show() |
| 764 | 765 | |
| 765 | 766 | y = self.viewer.interactor.GetSize()[1] - y |
| ... | ... | @@ -985,8 +986,7 @@ class WatershedProgressWindow(object): |
| 985 | 986 | self.dlg.Destroy() |
| 986 | 987 | |
| 987 | 988 | |
| 988 | -class WatershedConfig(object): | |
| 989 | - __metaclass__= utils.Singleton | |
| 989 | +class WatershedConfig(with_metaclass(utils.Singleton, object)): | |
| 990 | 990 | def __init__(self): |
| 991 | 991 | self.algorithm = "Watershed" |
| 992 | 992 | self.con_2d = 4 |
| ... | ... | @@ -1069,7 +1069,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): |
| 1069 | 1069 | self.viewer.OnScrollBar() |
| 1070 | 1070 | |
| 1071 | 1071 | x, y = self.viewer.interactor.ScreenToClient(wx.GetMousePosition()) |
| 1072 | - if self.viewer.interactor.HitTestXY(x, y) == wx.HT_WINDOW_INSIDE: | |
| 1072 | + if self.viewer.interactor.HitTest((x, y)) == wx.HT_WINDOW_INSIDE: | |
| 1073 | 1073 | self.viewer.slice_data.cursor.Show() |
| 1074 | 1074 | |
| 1075 | 1075 | y = self.viewer.interactor.GetSize()[1] - y |
| ... | ... | @@ -1104,7 +1104,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): |
| 1104 | 1104 | if self.matrix is not None: |
| 1105 | 1105 | self.matrix = None |
| 1106 | 1106 | os.remove(self.temp_file) |
| 1107 | - print "deleting", self.temp_file | |
| 1107 | + print("deleting", self.temp_file) | |
| 1108 | 1108 | |
| 1109 | 1109 | def _set_cursor(self): |
| 1110 | 1110 | if self.config.cursor_type == const.BRUSH_SQUARE: |
| ... | ... | @@ -1249,7 +1249,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): |
| 1249 | 1249 | position = self.viewer.get_slice_pixel_coord_by_world_pos(*coord) |
| 1250 | 1250 | radius = cursor.radius |
| 1251 | 1251 | |
| 1252 | - if position < 0: | |
| 1252 | + if isinstance(position, int) and position < 0: | |
| 1253 | 1253 | position = viewer.calculate_matrix_position(coord) |
| 1254 | 1254 | |
| 1255 | 1255 | operation = self.config.operation |
| ... | ... | @@ -1455,7 +1455,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): |
| 1455 | 1455 | del wp |
| 1456 | 1456 | |
| 1457 | 1457 | w_x, w_y = wx.GetMousePosition() |
| 1458 | - x, y = self.viewer.ScreenToClientXY(w_x, w_y) | |
| 1458 | + x, y = self.viewer.ScreenToClient((w_x, w_y)) | |
| 1459 | 1459 | flag = self.viewer.interactor.HitTest((x, y)) |
| 1460 | 1460 | |
| 1461 | 1461 | if flag == wx.HT_WINDOW_INSIDE: |
| ... | ... | @@ -1767,8 +1767,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): |
| 1767 | 1767 | buffer_.discard_image() |
| 1768 | 1768 | |
| 1769 | 1769 | |
| 1770 | -class FFillConfig(object): | |
| 1771 | - __metaclass__= utils.Singleton | |
| 1770 | +class FFillConfig(with_metaclass(utils.Singleton, object)): | |
| 1772 | 1771 | def __init__(self): |
| 1773 | 1772 | self.dlg_visible = False |
| 1774 | 1773 | self.target = "2D" |
| ... | ... | @@ -1904,8 +1903,7 @@ class RemoveMaskPartsInteractorStyle(FloodFillMaskInteractorStyle): |
| 1904 | 1903 | self._progr_title = _(u"Remove part") |
| 1905 | 1904 | self._progr_msg = _(u"Removing part ...") |
| 1906 | 1905 | |
| 1907 | -class CropMaskConfig(object): | |
| 1908 | - __metaclass__= utils.Singleton | |
| 1906 | +class CropMaskConfig(with_metaclass(utils.Singleton, object)): | |
| 1909 | 1907 | def __init__(self): |
| 1910 | 1908 | self.dlg_visible = False |
| 1911 | 1909 | |
| ... | ... | @@ -2007,8 +2005,7 @@ class CropMaskInteractorStyle(DefaultInteractorStyle): |
| 2007 | 2005 | Publisher.sendMessage('Reload actual slice') |
| 2008 | 2006 | |
| 2009 | 2007 | |
| 2010 | -class SelectPartConfig(object): | |
| 2011 | - __metaclass__= utils.Singleton | |
| 2008 | +class SelectPartConfig(with_metaclass(utils.Singleton, object)): | |
| 2012 | 2009 | def __init__(self): |
| 2013 | 2010 | self.mask = None |
| 2014 | 2011 | self.con_3d = 6 |
| ... | ... | @@ -2114,8 +2111,7 @@ class SelectMaskPartsInteractorStyle(DefaultInteractorStyle): |
| 2114 | 2111 | self.config.mask = mask |
| 2115 | 2112 | |
| 2116 | 2113 | |
| 2117 | -class FFillSegmentationConfig(object): | |
| 2118 | - __metaclass__= utils.Singleton | |
| 2114 | +class FFillSegmentationConfig(with_metaclass(utils.Singleton, object)): | |
| 2119 | 2115 | def __init__(self): |
| 2120 | 2116 | self.dlg_visible = False |
| 2121 | 2117 | self.target = "2D" |
| ... | ... | @@ -2225,7 +2221,7 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): |
| 2225 | 2221 | |
| 2226 | 2222 | elif self.config.method == 'dynamic': |
| 2227 | 2223 | if self.config.use_ww_wl: |
| 2228 | - print "Using WW&WL" | |
| 2224 | + print("Using WW&WL") | |
| 2229 | 2225 | ww = self.viewer.slice_.window_width |
| 2230 | 2226 | wl = self.viewer.slice_.window_level |
| 2231 | 2227 | image = get_LUT_value_255(image, ww, wl) |
| ... | ... | @@ -2282,7 +2278,7 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): |
| 2282 | 2278 | |
| 2283 | 2279 | elif self.config.method == 'dynamic': |
| 2284 | 2280 | if self.config.use_ww_wl: |
| 2285 | - print "Using WW&WL" | |
| 2281 | + print("Using WW&WL") | |
| 2286 | 2282 | ww = self.viewer.slice_.window_width |
| 2287 | 2283 | wl = self.viewer.slice_.window_level |
| 2288 | 2284 | image = get_LUT_value_255(image, ww, wl) |
| ... | ... | @@ -2335,18 +2331,18 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): |
| 2335 | 2331 | bool_mask = np.zeros_like(mask, dtype='bool') |
| 2336 | 2332 | out_mask = np.zeros_like(mask) |
| 2337 | 2333 | |
| 2338 | - for k in xrange(int(z-1), int(z+2)): | |
| 2334 | + for k in range(int(z-1), int(z+2)): | |
| 2339 | 2335 | if k < 0 or k >= bool_mask.shape[0]: |
| 2340 | 2336 | continue |
| 2341 | - for j in xrange(int(y-1), int(y+2)): | |
| 2337 | + for j in range(int(y-1), int(y+2)): | |
| 2342 | 2338 | if j < 0 or j >= bool_mask.shape[1]: |
| 2343 | 2339 | continue |
| 2344 | - for i in xrange(int(x-1), int(x+2)): | |
| 2340 | + for i in range(int(x-1), int(x+2)): | |
| 2345 | 2341 | if i < 0 or i >= bool_mask.shape[2]: |
| 2346 | 2342 | continue |
| 2347 | 2343 | bool_mask[k, j, i] = True |
| 2348 | 2344 | |
| 2349 | - for i in xrange(self.config.confid_iters): | |
| 2345 | + for i in range(self.config.confid_iters): | |
| 2350 | 2346 | var = np.std(image[bool_mask]) |
| 2351 | 2347 | mean = np.mean(image[bool_mask]) |
| 2352 | 2348 | ... | ... |
invesalius/data/surface.py
| ... | ... | @@ -90,7 +90,7 @@ class Surface(): |
| 90 | 90 | |
| 91 | 91 | filelist[vtp_filepath] = vtp_filename |
| 92 | 92 | |
| 93 | - surface = {'colour': self.colour, | |
| 93 | + surface = {'colour': self.colour[:3], | |
| 94 | 94 | 'index': self.index, |
| 95 | 95 | 'name': self.name, |
| 96 | 96 | 'polydata': vtp_filename, |
| ... | ... | @@ -361,7 +361,7 @@ class SurfaceManager(): |
| 361 | 361 | area = measured_polydata.GetSurfaceArea() |
| 362 | 362 | surface.volume = volume |
| 363 | 363 | surface.area = area |
| 364 | - print ">>>>", surface.volume | |
| 364 | + print(">>>>", surface.volume) | |
| 365 | 365 | else: |
| 366 | 366 | surface.volume = volume |
| 367 | 367 | surface.area = area |
| ... | ... | @@ -430,7 +430,7 @@ class SurfaceManager(): |
| 430 | 430 | actor.SetMapper(mapper) |
| 431 | 431 | |
| 432 | 432 | # Set actor colour and transparency |
| 433 | - actor.GetProperty().SetColor(surface.colour) | |
| 433 | + actor.GetProperty().SetColor(surface.colour[:3]) | |
| 434 | 434 | actor.GetProperty().SetOpacity(1-surface.transparency) |
| 435 | 435 | |
| 436 | 436 | self.actors_dict[surface.index] = actor |
| ... | ... | @@ -471,7 +471,7 @@ class SurfaceManager(): |
| 471 | 471 | |
| 472 | 472 | mode = 'CONTOUR' # 'GRAYSCALE' |
| 473 | 473 | min_value, max_value = mask.threshold_range |
| 474 | - colour = mask.colour | |
| 474 | + colour = mask.colour[:3] | |
| 475 | 475 | |
| 476 | 476 | try: |
| 477 | 477 | overwrite = surface_parameters['options']['overwrite'] |
| ... | ... | @@ -521,7 +521,7 @@ class SurfaceManager(): |
| 521 | 521 | q_out = multiprocessing.Queue() |
| 522 | 522 | |
| 523 | 523 | p = [] |
| 524 | - for i in xrange(n_processors): | |
| 524 | + for i in range(n_processors): | |
| 525 | 525 | sp = surface_process.SurfaceProcess(pipe_in, filename_img, |
| 526 | 526 | matrix.shape, matrix.dtype, |
| 527 | 527 | mask.temp_file, |
| ... | ... | @@ -539,12 +539,12 @@ class SurfaceManager(): |
| 539 | 539 | p.append(sp) |
| 540 | 540 | sp.start() |
| 541 | 541 | |
| 542 | - for i in xrange(n_pieces): | |
| 542 | + for i in range(n_pieces): | |
| 543 | 543 | init = i * piece_size |
| 544 | 544 | end = init + piece_size + o_piece |
| 545 | 545 | roi = slice(init, end) |
| 546 | 546 | q_in.put(roi) |
| 547 | - print "new_piece", roi | |
| 547 | + print("new_piece", roi) | |
| 548 | 548 | |
| 549 | 549 | for i in p: |
| 550 | 550 | q_in.put(None) |
| ... | ... | @@ -664,7 +664,7 @@ class SurfaceManager(): |
| 664 | 664 | |
| 665 | 665 | |
| 666 | 666 | if decimate_reduction: |
| 667 | - print "Decimating", decimate_reduction | |
| 667 | + print("Decimating", decimate_reduction) | |
| 668 | 668 | decimation = vtk.vtkQuadricDecimation() |
| 669 | 669 | # decimation.ReleaseDataFlagOn() |
| 670 | 670 | decimation.SetInputData(polydata) |
| ... | ... | @@ -902,7 +902,7 @@ class SurfaceManager(): |
| 902 | 902 | """ |
| 903 | 903 | """ |
| 904 | 904 | index, colour = pubsub_evt.data |
| 905 | - self.actors_dict[index].GetProperty().SetColor(colour) | |
| 905 | + self.actors_dict[index].GetProperty().SetColor(colour[:3]) | |
| 906 | 906 | # Update value in project's surface_dict |
| 907 | 907 | proj = prj.Project() |
| 908 | 908 | proj.surface_dict[index].colour = colour |
| ... | ... | @@ -925,7 +925,7 @@ class SurfaceManager(): |
| 925 | 925 | temp_file = win32api.GetShortPathName(temp_file) |
| 926 | 926 | os.remove(_temp_file) |
| 927 | 927 | |
| 928 | - temp_file = temp_file.decode(const.FS_ENCODE) | |
| 928 | + temp_file = utl.decode(temp_file, const.FS_ENCODE) | |
| 929 | 929 | self._export_surface(temp_file, filetype) |
| 930 | 930 | |
| 931 | 931 | shutil.move(temp_file, filename) | ... | ... |
invesalius/data/surface_process.py
invesalius/data/trackers.py
| ... | ... | @@ -50,10 +50,10 @@ def DefaultTracker(tracker_id): |
| 50 | 50 | trck_init = None |
| 51 | 51 | try: |
| 52 | 52 | # import spatial tracker library |
| 53 | - print 'Connect to default tracking device.' | |
| 53 | + print('Connect to default tracking device.') | |
| 54 | 54 | |
| 55 | 55 | except: |
| 56 | - print 'Could not connect to default tracker.' | |
| 56 | + print('Could not connect to default tracker.') | |
| 57 | 57 | |
| 58 | 58 | # return tracker initialization variable and type of connection |
| 59 | 59 | return trck_init, 'wrapper' |
| ... | ... | @@ -78,13 +78,13 @@ def ClaronTracker(tracker_id): |
| 78 | 78 | |
| 79 | 79 | if trck_init.GetIdentifyingCamera(): |
| 80 | 80 | trck_init.Run() |
| 81 | - print "MicronTracker camera identified." | |
| 81 | + print("MicronTracker camera identified.") | |
| 82 | 82 | else: |
| 83 | 83 | trck_init = None |
| 84 | 84 | |
| 85 | 85 | except ImportError: |
| 86 | 86 | lib_mode = 'error' |
| 87 | - print 'The ClaronTracker library is not installed.' | |
| 87 | + print('The ClaronTracker library is not installed.') | |
| 88 | 88 | |
| 89 | 89 | return trck_init, lib_mode |
| 90 | 90 | |
| ... | ... | @@ -94,24 +94,24 @@ def PolhemusTracker(tracker_id): |
| 94 | 94 | trck_init = PlhWrapperConnection(tracker_id) |
| 95 | 95 | lib_mode = 'wrapper' |
| 96 | 96 | if not trck_init: |
| 97 | - print 'Could not connect with Polhemus wrapper, trying USB connection...' | |
| 97 | + print('Could not connect with Polhemus wrapper, trying USB connection...') | |
| 98 | 98 | trck_init = PlhUSBConnection(tracker_id) |
| 99 | 99 | lib_mode = 'usb' |
| 100 | 100 | if not trck_init: |
| 101 | - print 'Could not connect with Polhemus USB, trying serial connection...' | |
| 101 | + print('Could not connect with Polhemus USB, trying serial connection...') | |
| 102 | 102 | trck_init = PlhSerialConnection(tracker_id) |
| 103 | 103 | lib_mode = 'serial' |
| 104 | 104 | except: |
| 105 | 105 | trck_init = None |
| 106 | 106 | lib_mode = 'error' |
| 107 | - print 'Could not connect to Polhemus.' | |
| 107 | + print('Could not connect to Polhemus.') | |
| 108 | 108 | |
| 109 | 109 | return trck_init, lib_mode |
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | def DebugTracker(tracker_id): |
| 113 | 113 | trck_init = True |
| 114 | - print 'Debug device started.' | |
| 114 | + print('Debug device started.') | |
| 115 | 115 | return trck_init, 'debug' |
| 116 | 116 | |
| 117 | 117 | |
| ... | ... | @@ -134,10 +134,10 @@ def PlhWrapperConnection(tracker_id): |
| 134 | 134 | sleep(0.175) |
| 135 | 135 | else: |
| 136 | 136 | trck_init = None |
| 137 | - print 'Could not connect to Polhemus via wrapper without error.' | |
| 137 | + print('Could not connect to Polhemus via wrapper without error.') | |
| 138 | 138 | except: |
| 139 | 139 | trck_init = None |
| 140 | - print 'Could not connect to Polhemus via wrapper with error.' | |
| 140 | + print('Could not connect to Polhemus via wrapper with error.') | |
| 141 | 141 | |
| 142 | 142 | return trck_init |
| 143 | 143 | |
| ... | ... | @@ -163,11 +163,11 @@ def PlhSerialConnection(tracker_id): |
| 163 | 163 | |
| 164 | 164 | if not data: |
| 165 | 165 | trck_init = None |
| 166 | - print 'Could not connect to Polhemus serial without error.' | |
| 166 | + print('Could not connect to Polhemus serial without error.') | |
| 167 | 167 | |
| 168 | 168 | except: |
| 169 | 169 | trck_init = None |
| 170 | - print 'Could not connect to Polhemus serial with error.' | |
| 170 | + print('Could not connect to Polhemus serial with error.') | |
| 171 | 171 | |
| 172 | 172 | return trck_init |
| 173 | 173 | |
| ... | ... | @@ -198,10 +198,10 @@ def PlhUSBConnection(tracker_id): |
| 198 | 198 | endpoint.wMaxPacketSize) |
| 199 | 199 | if not data: |
| 200 | 200 | trck_init = None |
| 201 | - print 'Could not connect to Polhemus USB without error.' | |
| 201 | + print('Could not connect to Polhemus USB without error.') | |
| 202 | 202 | |
| 203 | 203 | except: |
| 204 | - print 'Could not connect to Polhemus USB with error.' | |
| 204 | + print('Could not connect to Polhemus USB with error.') | |
| 205 | 205 | |
| 206 | 206 | return trck_init |
| 207 | 207 | |
| ... | ... | @@ -217,16 +217,16 @@ def DisconnectTracker(tracker_id, trck_init): |
| 217 | 217 | if tracker_id == 5: |
| 218 | 218 | trck_init = False |
| 219 | 219 | lib_mode = 'debug' |
| 220 | - print 'Debug tracker disconnected.' | |
| 220 | + print('Debug tracker disconnected.') | |
| 221 | 221 | else: |
| 222 | 222 | try: |
| 223 | 223 | trck_init.Close() |
| 224 | 224 | trck_init = False |
| 225 | 225 | lib_mode = 'wrapper' |
| 226 | - print 'Tracker disconnected.' | |
| 226 | + print('Tracker disconnected.') | |
| 227 | 227 | except: |
| 228 | 228 | trck_init = True |
| 229 | 229 | lib_mode = 'error' |
| 230 | - print 'The tracker could not be disconnected.' | |
| 230 | + print('The tracker could not be disconnected.') | |
| 231 | 231 | |
| 232 | - return trck_init, lib_mode | |
| 233 | 232 | \ No newline at end of file |
| 233 | + return trck_init, lib_mode | ... | ... |
invesalius/data/viewer_slice.py
| ... | ... | @@ -105,10 +105,16 @@ class ContourMIPConfig(wx.Panel): |
| 105 | 105 | sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 106 | 106 | sizer.Add(txt_mip_size, 0, wx.EXPAND | wx.ALL, 2) |
| 107 | 107 | sizer.Add(self.mip_size_spin, 0, wx.EXPAND) |
| 108 | - sizer.AddSpacer((10, 0)) | |
| 108 | + try: | |
| 109 | + sizer.Add(10, 0) | |
| 110 | + except TypeError: | |
| 111 | + sizer.Add((10, 0)) | |
| 109 | 112 | sizer.Add(self.txt_mip_border, 0, wx.EXPAND | wx.ALL, 2) |
| 110 | 113 | sizer.Add(self.border_spin, 0, wx.EXPAND) |
| 111 | - sizer.AddSpacer((10, 0)) | |
| 114 | + try: | |
| 115 | + sizer.Add(10, 0) | |
| 116 | + except TypeError: | |
| 117 | + sizer.Add((10, 0)) | |
| 112 | 118 | sizer.Add(self.inverted, 0, wx.EXPAND) |
| 113 | 119 | self.SetSizer(sizer) |
| 114 | 120 | sizer.Fit(self) |
| ... | ... | @@ -206,7 +212,10 @@ class CanvasRendererCTX: |
| 206 | 212 | self.alpha = np.zeros((h, w, 1), dtype=np.uint8) |
| 207 | 213 | |
| 208 | 214 | self.bitmap = wx.EmptyBitmapRGBA(w, h) |
| 209 | - self.image = wx.ImageFromBuffer(w, h, self.rgb, self.alpha) | |
| 215 | + try: | |
| 216 | + self.image = wx.Image(w, h, self.rgb, self.alpha) | |
| 217 | + except TypeError: | |
| 218 | + self.image = wx.ImageFromBuffer(w, h, self.rgb, self.alpha) | |
| 210 | 219 | |
| 211 | 220 | def _resize_canvas(self, w, h): |
| 212 | 221 | self._array = np.zeros((h, w, 4), dtype=np.uint8) |
| ... | ... | @@ -218,7 +227,10 @@ class CanvasRendererCTX: |
| 218 | 227 | self.alpha = np.zeros((h, w, 1), dtype=np.uint8) |
| 219 | 228 | |
| 220 | 229 | self.bitmap = wx.EmptyBitmapRGBA(w, h) |
| 221 | - self.image = wx.ImageFromBuffer(w, h, self.rgb, self.alpha) | |
| 230 | + try: | |
| 231 | + self.image = wx.Image(w, h, self.rgb, self.alpha) | |
| 232 | + except TypeError: | |
| 233 | + self.image = wx.ImageFromBuffer(w, h, self.rgb, self.alpha) | |
| 222 | 234 | |
| 223 | 235 | self.modified = True |
| 224 | 236 | |
| ... | ... | @@ -325,7 +337,7 @@ class CanvasRendererCTX: |
| 325 | 337 | p0y = -p0y |
| 326 | 338 | p1y = -p1y |
| 327 | 339 | |
| 328 | - pen = wx.Pen(wx.Colour(*colour), width, wx.SOLID) | |
| 340 | + pen = wx.Pen(wx.Colour(*[int(c) for c in colour]), width, wx.SOLID) | |
| 329 | 341 | pen.SetCap(wx.CAP_BUTT) |
| 330 | 342 | gc.SetPen(pen) |
| 331 | 343 | |
| ... | ... | @@ -496,7 +508,7 @@ class CanvasRendererCTX: |
| 496 | 508 | if self.gc is None: |
| 497 | 509 | return None |
| 498 | 510 | gc = self.gc |
| 499 | - pen = wx.Pen(wx.Colour(*line_colour), width, wx.SOLID) | |
| 511 | + pen = wx.Pen(wx.Colour(*[int(c) for c in line_colour]), width, wx.SOLID) | |
| 500 | 512 | gc.SetPen(pen) |
| 501 | 513 | |
| 502 | 514 | c = np.array(center) |
| ... | ... | @@ -521,7 +533,7 @@ class CanvasRendererCTX: |
| 521 | 533 | ea = a0 |
| 522 | 534 | |
| 523 | 535 | path = gc.CreatePath() |
| 524 | - path.AddArc((c[0], c[1]), min(s0, s1), sa, ea) | |
| 536 | + path.AddArc(float(c[0]), float(c[1]), float(min(s0, s1)), float(sa), float(ea), True) | |
| 525 | 537 | gc.StrokePath(path) |
| 526 | 538 | self._drawn = True |
| 527 | 539 | |
| ... | ... | @@ -600,7 +612,7 @@ class Viewer(wx.Panel): |
| 600 | 612 | sizer.Add(scroll, 0, wx.EXPAND|wx.GROW) |
| 601 | 613 | |
| 602 | 614 | background_sizer = wx.BoxSizer(wx.VERTICAL) |
| 603 | - background_sizer.AddSizer(sizer, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 615 | + background_sizer.Add(sizer, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 604 | 616 | #background_sizer.Add(self.mip_ctrls, 0, wx.EXPAND|wx.GROW|wx.ALL, 2) |
| 605 | 617 | self.SetSizer(background_sizer) |
| 606 | 618 | background_sizer.Fit(self) |
| ... | ... | @@ -1382,7 +1394,7 @@ class Viewer(wx.Panel): |
| 1382 | 1394 | number_renderers = self.layout[0] * self.layout[1] |
| 1383 | 1395 | diff = number_renderers - len(self.slice_data_list) |
| 1384 | 1396 | if diff > 0: |
| 1385 | - for i in xrange(diff): | |
| 1397 | + for i in range(diff): | |
| 1386 | 1398 | slice_data = self.create_slice_window(imagedata) |
| 1387 | 1399 | self.slice_data_list.append(slice_data) |
| 1388 | 1400 | elif diff < 0: |
| ... | ... | @@ -1400,8 +1412,8 @@ class Viewer(wx.Panel): |
| 1400 | 1412 | w *= proportion_x |
| 1401 | 1413 | h *= proportion_y |
| 1402 | 1414 | n = 0 |
| 1403 | - for j in xrange(self.layout[1]-1, -1, -1): | |
| 1404 | - for i in xrange(self.layout[0]): | |
| 1415 | + for j in range(self.layout[1]-1, -1, -1): | |
| 1416 | + for i in range(self.layout[0]): | |
| 1405 | 1417 | slice_xi = i*proportion_x |
| 1406 | 1418 | slice_xf = (i+1)*proportion_x |
| 1407 | 1419 | slice_yi = j*proportion_y | ... | ... |
invesalius/data/viewer_volume.py
| ... | ... | @@ -507,7 +507,7 @@ class Viewer(wx.Panel): |
| 507 | 507 | """ |
| 508 | 508 | self.ball_id = pubsub_evt.data[0] |
| 509 | 509 | ballsize = pubsub_evt.data[1] |
| 510 | - ballcolour = pubsub_evt.data[2] | |
| 510 | + ballcolour = pubsub_evt.data[2][:3] | |
| 511 | 511 | coord = pubsub_evt.data[3] |
| 512 | 512 | x, y, z = bases.flip_x(coord) |
| 513 | 513 | |
| ... | ... | @@ -1124,7 +1124,7 @@ class Viewer(wx.Panel): |
| 1124 | 1124 | """ |
| 1125 | 1125 | Coil for navigation rendered in volume viewer. |
| 1126 | 1126 | """ |
| 1127 | - | |
| 1127 | + filename = utils.decode(filename, const.FS_ENCODE) | |
| 1128 | 1128 | if filename: |
| 1129 | 1129 | if filename.lower().endswith('.stl'): |
| 1130 | 1130 | reader = vtk.vtkSTLReader() |
| ... | ... | @@ -1451,9 +1451,9 @@ class Viewer(wx.Panel): |
| 1451 | 1451 | if _has_win32api: |
| 1452 | 1452 | utils.touch(filename) |
| 1453 | 1453 | win_filename = win32api.GetShortPathName(filename) |
| 1454 | - self._export_surface(win_filename.encode(const.FS_ENCODE), filetype) | |
| 1454 | + self._export_surface(win_filename, filetype) | |
| 1455 | 1455 | else: |
| 1456 | - self._export_surface(filename.encode(const.FS_ENCODE), filetype) | |
| 1456 | + self._export_surface(filename, filetype) | |
| 1457 | 1457 | |
| 1458 | 1458 | def _export_surface(self, filename, filetype): |
| 1459 | 1459 | fileprefix = filename.split(".")[-2] |
| ... | ... | @@ -1526,7 +1526,7 @@ class Viewer(wx.Panel): |
| 1526 | 1526 | |
| 1527 | 1527 | def ChangeBackgroundColour(self, pubsub_evt): |
| 1528 | 1528 | colour = pubsub_evt.data |
| 1529 | - self.ren.SetBackground(colour) | |
| 1529 | + self.ren.SetBackground(colour[:3]) | |
| 1530 | 1530 | self.UpdateRender() |
| 1531 | 1531 | |
| 1532 | 1532 | def LoadActor(self, pubsub_evt): | ... | ... |
invesalius/data/volume.py
| ... | ... | @@ -161,22 +161,22 @@ class Volume(): |
| 161 | 161 | self.LoadVolume() |
| 162 | 162 | |
| 163 | 163 | def OnHideVolume(self, pubsub_evt): |
| 164 | - print 'Hide Volume' | |
| 164 | + print('Hide Volume') | |
| 165 | 165 | self.volume.SetVisibility(0) |
| 166 | 166 | if (self.plane and self.plane_on): |
| 167 | 167 | self.plane.Disable() |
| 168 | 168 | Publisher.sendMessage('Render volume viewer') |
| 169 | 169 | |
| 170 | 170 | def OnShowVolume(self, pubsub_evt = None): |
| 171 | - print 'Show volume' | |
| 171 | + print('Show volume') | |
| 172 | 172 | if self.exist: |
| 173 | - print 'Volume exists' | |
| 173 | + print('Volume exists') | |
| 174 | 174 | self.volume.SetVisibility(1) |
| 175 | 175 | if (self.plane and self.plane_on): |
| 176 | 176 | self.plane.Enable() |
| 177 | 177 | Publisher.sendMessage('Render volume viewer') |
| 178 | 178 | else: |
| 179 | - print 'Volume doesnt exit' | |
| 179 | + print('Volume doesnt exit') | |
| 180 | 180 | Publisher.sendMessage('Load raycasting preset', const.RAYCASTING_LABEL) |
| 181 | 181 | self.LoadConfig() |
| 182 | 182 | self.LoadVolume() |
| ... | ... | @@ -222,7 +222,7 @@ class Volume(): |
| 222 | 222 | Publisher.sendMessage('Render volume viewer') |
| 223 | 223 | |
| 224 | 224 | def OnFlipVolume(self, pubsub_evt): |
| 225 | - print "Flipping Volume" | |
| 225 | + print("Flipping Volume") | |
| 226 | 226 | self.loaded_image = False |
| 227 | 227 | del self.image |
| 228 | 228 | self.image = None |
| ... | ... | @@ -360,10 +360,10 @@ class Volume(): |
| 360 | 360 | r = p['Red'] |
| 361 | 361 | g = p['Green'] |
| 362 | 362 | b = p['Blue'] |
| 363 | - colors = zip(r,g,b) | |
| 363 | + colors = list(zip(r,g,b)) | |
| 364 | 364 | else: |
| 365 | 365 | # Grayscale from black to white |
| 366 | - colors = [(i, i, i) for i in xrange(256)] | |
| 366 | + colors = [(i, i, i) for i in range(256)] | |
| 367 | 367 | |
| 368 | 368 | ww = self.config['ww'] |
| 369 | 369 | wl = self.TranslateScale(scale, self.config['wl']) | ... | ... |
invesalius/data/vtk_utils.py
| ... | ... | @@ -140,11 +140,10 @@ class Text(object): |
| 140 | 140 | # With some encoding in some dicom fields (like name) raises a |
| 141 | 141 | # UnicodeEncodeError because they have non-ascii characters. To avoid |
| 142 | 142 | # that we encode in utf-8. |
| 143 | - | |
| 144 | - if sys.platform == 'win32': | |
| 143 | + if sys.platform == 'win32': | |
| 145 | 144 | self.mapper.SetInput(value.encode("utf-8")) |
| 146 | 145 | else: |
| 147 | - try: | |
| 146 | + try: | |
| 148 | 147 | self.mapper.SetInput(value.encode("latin-1")) |
| 149 | 148 | except(UnicodeEncodeError): |
| 150 | 149 | self.mapper.SetInput(value.encode("utf-8")) | ... | ... |
invesalius/gui/bitmap_preview_panel.py
| ... | ... | @@ -218,7 +218,10 @@ class Preview(wx.Panel): |
| 218 | 218 | |
| 219 | 219 | def OnEnter(self, evt): |
| 220 | 220 | if not self.select_on: |
| 221 | - c = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE) | |
| 221 | + try: | |
| 222 | + c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE) | |
| 223 | + except AttributeError: | |
| 224 | + c = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE) | |
| 222 | 225 | self.SetBackgroundColour(c) |
| 223 | 226 | |
| 224 | 227 | def OnLeave(self, evt): |
| ... | ... | @@ -257,7 +260,10 @@ class Preview(wx.Panel): |
| 257 | 260 | |
| 258 | 261 | def Select(self, on=True): |
| 259 | 262 | if self.select_on: |
| 260 | - c = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT) | |
| 263 | + try: | |
| 264 | + c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT) | |
| 265 | + except AttributeError: | |
| 266 | + c = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT) | |
| 261 | 267 | else: |
| 262 | 268 | c = (PREVIEW_BACKGROUND) |
| 263 | 269 | self.SetBackgroundColour(c) |
| ... | ... | @@ -291,10 +297,10 @@ class BitmapPreviewSeries(wx.Panel): |
| 291 | 297 | self.grid = wx.GridSizer(rows=NROWS, cols=NCOLS, vgap=3, hgap=3) |
| 292 | 298 | |
| 293 | 299 | sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 294 | - sizer.AddSizer(self.grid, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 300 | + sizer.Add(self.grid, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 295 | 301 | |
| 296 | 302 | background_sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 297 | - background_sizer.AddSizer(sizer, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 303 | + background_sizer.Add(sizer, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 298 | 304 | background_sizer.Add(scroll, 0, wx.EXPAND|wx.GROW) |
| 299 | 305 | self.SetSizer(background_sizer) |
| 300 | 306 | background_sizer.Fit(self) |
| ... | ... | @@ -311,8 +317,8 @@ class BitmapPreviewSeries(wx.Panel): |
| 311 | 317 | |
| 312 | 318 | def _Add_Panels_Preview(self): |
| 313 | 319 | self.previews = [] |
| 314 | - for i in xrange(NROWS): | |
| 315 | - for j in xrange(NCOLS): | |
| 320 | + for i in range(NROWS): | |
| 321 | + for j in range(NCOLS): | |
| 316 | 322 | p = Preview(self) |
| 317 | 323 | p.Bind(EVT_PREVIEW_CLICK, self.OnSelect) |
| 318 | 324 | |
| ... | ... | @@ -387,7 +393,7 @@ class BitmapPreviewSeries(wx.Panel): |
| 387 | 393 | initial = self.displayed_position * NCOLS |
| 388 | 394 | final = initial + NUM_PREVIEWS |
| 389 | 395 | if len(self.files) < final: |
| 390 | - for i in xrange(final-len(self.files)): | |
| 396 | + for i in range(final-len(self.files)): | |
| 391 | 397 | try: |
| 392 | 398 | self.previews[-i-1].Hide() |
| 393 | 399 | except IndexError: |
| ... | ... | @@ -396,7 +402,7 @@ class BitmapPreviewSeries(wx.Panel): |
| 396 | 402 | self.nhidden_last_display = final-len(self.files) |
| 397 | 403 | else: |
| 398 | 404 | if self.nhidden_last_display: |
| 399 | - for i in xrange(self.nhidden_last_display): | |
| 405 | + for i in range(self.nhidden_last_display): | |
| 400 | 406 | try: |
| 401 | 407 | self.previews[-i-1].Show() |
| 402 | 408 | except IndexError: |
| ... | ... | @@ -504,7 +510,7 @@ class SingleImagePreview(wx.Panel): |
| 504 | 510 | maxValue=99, |
| 505 | 511 | style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS) |
| 506 | 512 | slider.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) |
| 507 | - slider.SetTickFreq(1, 1) | |
| 513 | + slider.SetTickFreq(1) | |
| 508 | 514 | self.slider = slider |
| 509 | 515 | |
| 510 | 516 | checkbox = wx.CheckBox(self, -1, _("Auto-play")) | ... | ... |
invesalius/gui/data_notebook.py
| ... | ... | @@ -29,7 +29,11 @@ except ImportError: |
| 29 | 29 | |
| 30 | 30 | import wx |
| 31 | 31 | import wx.grid |
| 32 | -import wx.lib.flatnotebook as fnb | |
| 32 | +try: | |
| 33 | + import wx.lib.agw.flatnotebook as fnb | |
| 34 | +except ImportError: | |
| 35 | + import wx.lib.flatnotebook as fnb | |
| 36 | + | |
| 33 | 37 | import wx.lib.platebtn as pbtn |
| 34 | 38 | from wx.lib.pubsub import pub as Publisher |
| 35 | 39 | |
| ... | ... | @@ -40,7 +44,7 @@ import invesalius.gui.widgets.listctrl as listmix |
| 40 | 44 | import invesalius.utils as ul |
| 41 | 45 | |
| 42 | 46 | |
| 43 | -BTN_NEW, BTN_REMOVE, BTN_DUPLICATE, BTN_OPEN = [wx.NewId() for i in xrange(4)] | |
| 47 | +BTN_NEW, BTN_REMOVE, BTN_DUPLICATE, BTN_OPEN = [wx.NewId() for i in range(4)] | |
| 44 | 48 | |
| 45 | 49 | TYPE = {const.LINEAR: _(u"Linear"), |
| 46 | 50 | const.ANGULAR: _(u"Angular"), |
| ... | ... | @@ -505,8 +509,8 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 505 | 509 | """ |
| 506 | 510 | image = self.image_gray |
| 507 | 511 | new_image = Image.new("RGB", image.size) |
| 508 | - for x in xrange(image.size[0]): | |
| 509 | - for y in xrange(image.size[1]): | |
| 512 | + for x in range(image.size[0]): | |
| 513 | + for y in range(image.size[1]): | |
| 510 | 514 | pixel_colour = [int(i*image.getpixel((x,y))) |
| 511 | 515 | for i in colour] |
| 512 | 516 | new_image.putpixel((x,y), tuple(pixel_colour)) |
| ... | ... | @@ -881,11 +885,17 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 881 | 885 | self.surface_list_index[index] = image_index |
| 882 | 886 | |
| 883 | 887 | if (index in index_list) and index_list: |
| 884 | - self.UpdateItemInfo(index, name, volume, area, transparency, colour) | |
| 888 | + try: | |
| 889 | + self.UpdateItemInfo(index, name, volume, area, transparency, colour) | |
| 890 | + except wx._core.wxAssertionError: | |
| 891 | + self.InsertNewItem(index, name, volume, area, transparency, colour) | |
| 885 | 892 | else: |
| 886 | 893 | self.InsertNewItem(index, name, volume, area, transparency, colour) |
| 887 | 894 | else: |
| 888 | - self.UpdateItemInfo(index, name, volume, area, transparency, colour) | |
| 895 | + try: | |
| 896 | + self.UpdateItemInfo(index, name, volume, area, transparency, colour) | |
| 897 | + except wx._core.wxAssertionError: | |
| 898 | + self.InsertNewItem(index, name, volume, area, transparency, colour) | |
| 889 | 899 | |
| 890 | 900 | def InsertNewItem(self, index=0, label="Surface 1", volume="0 mm3", |
| 891 | 901 | area="0 mm2", transparency="0%%", colour=None): |
| ... | ... | @@ -899,6 +909,8 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 899 | 909 | |
| 900 | 910 | def UpdateItemInfo(self, index=0, label="Surface 1", volume="0 mm3", |
| 901 | 911 | area="0 mm2", transparency="0%%", colour=None): |
| 912 | + print("UpdateItemInfo", index) | |
| 913 | + # TODO: Retornar esse codigo | |
| 902 | 914 | self.SetStringItem(index, 1, label, |
| 903 | 915 | imageId = self.surface_list_index[index]) |
| 904 | 916 | self.SetStringItem(index, 2, volume) |
| ... | ... | @@ -913,8 +925,8 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 913 | 925 | """ |
| 914 | 926 | image = self.image_gray |
| 915 | 927 | new_image = Image.new("RGB", image.size) |
| 916 | - for x in xrange(image.size[0]): | |
| 917 | - for y in xrange(image.size[1]): | |
| 928 | + for x in range(image.size[0]): | |
| 929 | + for y in range(image.size[1]): | |
| 918 | 930 | pixel_colour = [int(i*image.getpixel((x,y))) |
| 919 | 931 | for i in colour] |
| 920 | 932 | new_image.putpixel((x,y), tuple(pixel_colour)) |
| ... | ... | @@ -1172,11 +1184,17 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 1172 | 1184 | self._list_index[index] = image_index |
| 1173 | 1185 | |
| 1174 | 1186 | if (index in index_list) and index_list: |
| 1175 | - self.UpdateItemInfo(index, name, colour, location, type_, value) | |
| 1187 | + try: | |
| 1188 | + self.UpdateItemInfo(index, name, colour, location, type_, value) | |
| 1189 | + except wx._core.wxAssertionError: | |
| 1190 | + self.InsertNewItem(index, name, colour, location, type_, value) | |
| 1176 | 1191 | else: |
| 1177 | 1192 | self.InsertNewItem(index, name, colour, location, type_, value) |
| 1178 | 1193 | else: |
| 1179 | - self.UpdateItemInfo(index, name, colour, location, type_, value) | |
| 1194 | + try: | |
| 1195 | + self.UpdateItemInfo(index, name, colour, location, type_, value) | |
| 1196 | + except wx._core.wxAssertionError: | |
| 1197 | + self.InsertNewItem(index, name, colour, location, type_, value) | |
| 1180 | 1198 | |
| 1181 | 1199 | |
| 1182 | 1200 | |
| ... | ... | @@ -1208,8 +1226,8 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 1208 | 1226 | """ |
| 1209 | 1227 | image = self.image_gray |
| 1210 | 1228 | new_image = Image.new("RGB", image.size) |
| 1211 | - for x in xrange(image.size[0]): | |
| 1212 | - for y in xrange(image.size[1]): | |
| 1229 | + for x in range(image.size[0]): | |
| 1230 | + for y in range(image.size[1]): | |
| 1213 | 1231 | pixel_colour = [int(i*image.getpixel((x,y))) |
| 1214 | 1232 | for i in colour] |
| 1215 | 1233 | new_image.putpixel((x,y), tuple(pixel_colour)) |
| ... | ... | @@ -1301,9 +1319,9 @@ class AnnotationsListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 1301 | 1319 | def OnCheckItem(self, index, flag): |
| 1302 | 1320 | # TODO: use pubsub to communicate to models |
| 1303 | 1321 | if flag: |
| 1304 | - print "checked, ", index | |
| 1322 | + print("checked, ", index) | |
| 1305 | 1323 | else: |
| 1306 | - print "unchecked, ", index | |
| 1324 | + print("unchecked, ", index) | |
| 1307 | 1325 | |
| 1308 | 1326 | def InsertNewItem(self, index=0, name="Axial 1", type_="2d", |
| 1309 | 1327 | value="bla", colour=None): | ... | ... |
invesalius/gui/default_tasks.py
| ... | ... | @@ -18,7 +18,10 @@ |
| 18 | 18 | #-------------------------------------------------------------------------- |
| 19 | 19 | |
| 20 | 20 | import wx |
| 21 | -import wx.lib.foldpanelbar as fpb | |
| 21 | +try: | |
| 22 | + import wx.lib.agw.foldpanelbar as fpb | |
| 23 | +except ModuleNotFoundError: | |
| 24 | + import wx.lib.foldpanelbar as fpb | |
| 22 | 25 | from wx.lib.pubsub import pub as Publisher |
| 23 | 26 | |
| 24 | 27 | import invesalius.constants as const |
| ... | ... | @@ -35,7 +38,7 @@ FPB_DEFAULT_STYLE = 2621440 |
| 35 | 38 | |
| 36 | 39 | def GetCollapsedIconData(): |
| 37 | 40 | return \ |
| 38 | -'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ | |
| 41 | +b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ | |
| 39 | 42 | \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ |
| 40 | 43 | \x00\x01\x8eIDAT8\x8d\xa5\x93-n\xe4@\x10\x85?g\x03\n6lh)\xc4\xd2\x12\xc3\x81\ |
| 41 | 44 | \xd6\xa2I\x90\x154\xb9\x81\x8f1G\xc8\x11\x16\x86\xcd\xa0\x99F\xb3A\x91\xa1\ |
| ... | ... | @@ -58,13 +61,13 @@ def GetCollapsedIconBitmap(): |
| 58 | 61 | return wx.BitmapFromImage(GetCollapsedIconImage()) |
| 59 | 62 | |
| 60 | 63 | def GetCollapsedIconImage(): |
| 61 | - import cStringIO | |
| 62 | - stream = cStringIO.StringIO(GetCollapsedIconData()) | |
| 64 | + from io import BytesIO | |
| 65 | + stream = BytesIO(GetCollapsedIconData()) | |
| 63 | 66 | return wx.ImageFromStream(stream) |
| 64 | 67 | |
| 65 | 68 | def GetExpandedIconData(): |
| 66 | 69 | return \ |
| 67 | -'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ | |
| 70 | +b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ | |
| 68 | 71 | \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ |
| 69 | 72 | \x00\x01\x9fIDAT8\x8d\x95\x93\xa1\x8e\xdc0\x14EO\xb2\xc4\xd0\xd2\x12\xb7(mI\ |
| 70 | 73 | \xa4%V\xd1lQT4[4-\x9a\xfe\xc1\xc2|\xc6\xc2~BY\x83:A3E\xd3\xa0*\xa4\xd2\x90H!\ |
| ... | ... | @@ -89,8 +92,8 @@ def GetExpandedIconBitmap(): |
| 89 | 92 | return wx.BitmapFromImage(GetExpandedIconImage()) |
| 90 | 93 | |
| 91 | 94 | def GetExpandedIconImage(): |
| 92 | - import cStringIO | |
| 93 | - stream = cStringIO.StringIO(GetExpandedIconData()) | |
| 95 | + from io import BytesIO | |
| 96 | + stream = BytesIO(GetExpandedIconData()) | |
| 94 | 97 | return wx.ImageFromStream(stream) |
| 95 | 98 | |
| 96 | 99 | |
| ... | ... | @@ -239,7 +242,7 @@ class UpperTaskPanel(wx.Panel): |
| 239 | 242 | self.overwrite = False |
| 240 | 243 | |
| 241 | 244 | session = ses.Session() |
| 242 | - print "session mode: ", session.mode | |
| 245 | + print("session mode: ", session.mode) | |
| 243 | 246 | if int(session.mode) == const.MODE_RP: |
| 244 | 247 | tasks = [(_("Load data"), importer.TaskPanel), |
| 245 | 248 | (_("Select region of interest"), slice_.TaskPanel), |
| ... | ... | @@ -253,7 +256,7 @@ class UpperTaskPanel(wx.Panel): |
| 253 | 256 | (_("Export data"), exporter.TaskPanel), |
| 254 | 257 | (_("Navigation system"), navigator.TaskPanel)] |
| 255 | 258 | |
| 256 | - for i in xrange(len(tasks)): | |
| 259 | + for i in range(len(tasks)): | |
| 257 | 260 | (name, panel) = tasks[i] |
| 258 | 261 | # Create panel |
| 259 | 262 | item = fold_panel.AddFoldPanel("%d. %s"%(i+1, name), | ... | ... |
invesalius/gui/default_viewers.py
| ... | ... | @@ -306,7 +306,7 @@ import wx.lib.colourselect as csel |
| 306 | 306 | |
| 307 | 307 | import invesalius.constants as const |
| 308 | 308 | |
| 309 | -[BUTTON_RAYCASTING, BUTTON_VIEW, BUTTON_SLICE_PLANE, BUTTON_3D_STEREO, BUTTON_TARGET] = [wx.NewId() for num in xrange(5)] | |
| 309 | +[BUTTON_RAYCASTING, BUTTON_VIEW, BUTTON_SLICE_PLANE, BUTTON_3D_STEREO, BUTTON_TARGET] = [wx.NewId() for num in range(5)] | |
| 310 | 310 | RAYCASTING_TOOLS = wx.NewId() |
| 311 | 311 | |
| 312 | 312 | ID_TO_NAME = {} | ... | ... |
invesalius/gui/dialogs.py
| ... | ... | @@ -34,7 +34,10 @@ else: |
| 34 | 34 | |
| 35 | 35 | import vtk |
| 36 | 36 | import wx |
| 37 | -import wx.combo | |
| 37 | +try: | |
| 38 | + from wx.adv import BitmapComboBox | |
| 39 | +except ImportError: | |
| 40 | + from wx.combo import BitmapComboBox | |
| 38 | 41 | |
| 39 | 42 | from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor |
| 40 | 43 | from wx.lib import masked |
| ... | ... | @@ -67,11 +70,16 @@ EVT_MASK_SET = wx.PyEventBinder(myEVT_MASK_SET, 1) |
| 67 | 70 | |
| 68 | 71 | class NumberDialog(wx.Dialog): |
| 69 | 72 | def __init__(self, message, value=0): |
| 70 | - pre = wx.PreDialog() | |
| 71 | - pre.Create(None, -1, "InVesalius 3", size=wx.DefaultSize, | |
| 72 | - pos=wx.DefaultPosition, | |
| 73 | - style=wx.DEFAULT_DIALOG_STYLE) | |
| 74 | - self.PostCreate(pre) | |
| 73 | + try: | |
| 74 | + pre = wx.PreDialog() | |
| 75 | + pre.Create(None, -1, "InVesalius 3", size=wx.DefaultSize, | |
| 76 | + pos=wx.DefaultPosition, | |
| 77 | + style=wx.DEFAULT_DIALOG_STYLE) | |
| 78 | + self.PostCreate(pre) | |
| 79 | + except AttributeError: | |
| 80 | + wx.Dialog.__init__(self, None, -1, "InVesalius 3", size=wx.DefaultSize, | |
| 81 | + pos=wx.DefaultPosition, | |
| 82 | + style=wx.DEFAULT_DIALOG_STYLE) | |
| 75 | 83 | |
| 76 | 84 | # Static text which contains message to user |
| 77 | 85 | label = wx.StaticText(self, -1, message) |
| ... | ... | @@ -117,11 +125,16 @@ class NumberDialog(wx.Dialog): |
| 117 | 125 | class ResizeImageDialog(wx.Dialog): |
| 118 | 126 | |
| 119 | 127 | def __init__(self):#, message, value=0): |
| 120 | - pre = self.pre = wx.PreDialog() | |
| 121 | - pre.Create(None, -1, "InVesalius 3", size=wx.DefaultSize, | |
| 122 | - pos=wx.DefaultPosition, | |
| 123 | - style=wx.DEFAULT_DIALOG_STYLE) | |
| 124 | - self.PostCreate(pre) | |
| 128 | + try: | |
| 129 | + pre = self.pre = wx.PreDialog() | |
| 130 | + pre.Create(None, -1, "InVesalius 3", size=wx.DefaultSize, | |
| 131 | + pos=wx.DefaultPosition, | |
| 132 | + style=wx.DEFAULT_DIALOG_STYLE) | |
| 133 | + self.PostCreate(pre) | |
| 134 | + except AttributeError: | |
| 135 | + wx.Dialog.__init__(self, None, -1, "InVesalius 3", size=wx.DefaultSize, | |
| 136 | + pos=wx.DefaultPosition, | |
| 137 | + style=wx.DEFAULT_DIALOG_STYLE) | |
| 125 | 138 | |
| 126 | 139 | lbl_message = wx.StaticText(self, -1, _("InVesalius is running on a 32-bit operating system or has insufficient memory. \nIf you want to work with 3D surfaces or volume rendering, \nit is recommended to reduce the medical images resolution.")) |
| 127 | 140 | icon = wx.ArtProvider.GetBitmap(wx.ART_WARNING, wx.ART_MESSAGE_BOX, (32,32)) |
| ... | ... | @@ -149,12 +162,12 @@ class ResizeImageDialog(wx.Dialog): |
| 149 | 162 | |
| 150 | 163 | sizer_itens = wx.BoxSizer(wx.VERTICAL) |
| 151 | 164 | sizer_itens.Add(lbl_message, 0, wx.EXPAND|wx.ALL, 5) |
| 152 | - sizer_itens.AddSizer(sizer_percent, 0, wx.EXPAND|wx.ALL, 5) | |
| 165 | + sizer_itens.Add(sizer_percent, 0, wx.EXPAND|wx.ALL, 5) | |
| 153 | 166 | sizer_itens.Add(btn_sizer, 0, wx.EXPAND|wx.ALL, 5) |
| 154 | 167 | |
| 155 | 168 | sizer_general = wx.BoxSizer(wx.HORIZONTAL) |
| 156 | 169 | sizer_general.Add(bmp, 0, wx.ALIGN_CENTRE|wx.ALL, 10) |
| 157 | - sizer_general.AddSizer(sizer_itens, 0, wx.ALL , 5) | |
| 170 | + sizer_general.Add(sizer_itens, 0, wx.ALL , 5) | |
| 158 | 171 | |
| 159 | 172 | #self.SetAutoLayout(True) |
| 160 | 173 | self.SetSizer(sizer_general) |
| ... | ... | @@ -169,7 +182,7 @@ class ResizeImageDialog(wx.Dialog): |
| 169 | 182 | return self.num_ctrl_porcent.GetValue() |
| 170 | 183 | |
| 171 | 184 | def Close(self): |
| 172 | - self.pre.Destroy() | |
| 185 | + self.Destroy() | |
| 173 | 186 | |
| 174 | 187 | def ShowNumberDialog(message, value=0): |
| 175 | 188 | dlg = NumberDialog(message, value) |
| ... | ... | @@ -465,7 +478,7 @@ def ShowSaveMarkersDialog(default_filename=None): |
| 465 | 478 | "", # last used directory |
| 466 | 479 | default_filename, |
| 467 | 480 | _("Markers files (*.mks)|*.mks"), |
| 468 | - wx.SAVE | wx.OVERWRITE_PROMPT) | |
| 481 | + wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) | |
| 469 | 482 | # dlg.SetFilterIndex(0) # default is VTI |
| 470 | 483 | |
| 471 | 484 | filename = None |
| ... | ... | @@ -495,7 +508,7 @@ def ShowSaveCoordsDialog(default_filename=None): |
| 495 | 508 | "", # last used directory |
| 496 | 509 | default_filename, |
| 497 | 510 | _("Coordinates files (*.csv)|*.csv"), |
| 498 | - wx.SAVE | wx.OVERWRITE_PROMPT) | |
| 511 | + wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) | |
| 499 | 512 | # dlg.SetFilterIndex(0) # default is VTI |
| 500 | 513 | |
| 501 | 514 | filename = None |
| ... | ... | @@ -526,7 +539,7 @@ def ShowLoadMarkersDialog(): |
| 526 | 539 | defaultDir="", |
| 527 | 540 | defaultFile="", |
| 528 | 541 | wildcard=_("Markers files (*.mks)|*.mks"), |
| 529 | - style=wx.OPEN|wx.CHANGE_DIR) | |
| 542 | + style=wx.FD_OPEN|wx.FD_CHANGE_DIR) | |
| 530 | 543 | |
| 531 | 544 | # inv3 filter is default |
| 532 | 545 | dlg.SetFilterIndex(0) |
| ... | ... | @@ -555,7 +568,7 @@ def ShowSaveRegistrationDialog(default_filename=None): |
| 555 | 568 | "", # last used directory |
| 556 | 569 | default_filename, |
| 557 | 570 | _("Registration files (*.obr)|*.obr"), |
| 558 | - wx.SAVE | wx.OVERWRITE_PROMPT) | |
| 571 | + wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) | |
| 559 | 572 | # dlg.SetFilterIndex(0) # default is VTI |
| 560 | 573 | |
| 561 | 574 | filename = None |
| ... | ... | @@ -586,7 +599,7 @@ def ShowLoadRegistrationDialog(): |
| 586 | 599 | defaultDir="", |
| 587 | 600 | defaultFile="", |
| 588 | 601 | wildcard=_("Registration files (*.obr)|*.obr"), |
| 589 | - style=wx.OPEN|wx.CHANGE_DIR) | |
| 602 | + style=wx.FD_OPEN|wx.FD_CHANGE_DIR) | |
| 590 | 603 | |
| 591 | 604 | # inv3 filter is default |
| 592 | 605 | dlg.SetFilterIndex(0) |
| ... | ... | @@ -610,10 +623,14 @@ def ShowLoadRegistrationDialog(): |
| 610 | 623 | |
| 611 | 624 | class MessageDialog(wx.Dialog): |
| 612 | 625 | def __init__(self, message): |
| 613 | - pre = wx.PreDialog() | |
| 614 | - pre.Create(None, -1, "InVesalius 3", size=(360, 370), pos=wx.DefaultPosition, | |
| 615 | - style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION) | |
| 616 | - self.PostCreate(pre) | |
| 626 | + try: | |
| 627 | + pre = wx.PreDialog() | |
| 628 | + pre.Create(None, -1, "InVesalius 3", size=(360, 370), pos=wx.DefaultPosition, | |
| 629 | + style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION) | |
| 630 | + self.PostCreate(pre) | |
| 631 | + except AttributeError: | |
| 632 | + wx.Dialog.__init__(self, None, -1, "InVesalius 3", size=(360, 370), pos=wx.DefaultPosition, | |
| 633 | + style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION) | |
| 617 | 634 | |
| 618 | 635 | # Static text which contains message to user |
| 619 | 636 | label = wx.StaticText(self, -1, message) |
| ... | ... | @@ -652,10 +669,14 @@ class UpdateMessageDialog(wx.Dialog): |
| 652 | 669 | title=_("Invesalius Update") |
| 653 | 670 | self.url = url |
| 654 | 671 | |
| 655 | - pre = wx.PreDialog() | |
| 656 | - pre.Create(None, -1, title, size=(360, 370), pos=wx.DefaultPosition, | |
| 657 | - style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION) | |
| 658 | - self.PostCreate(pre) | |
| 672 | + try: | |
| 673 | + pre = wx.PreDialog() | |
| 674 | + pre.Create(None, -1, title, size=(360, 370), pos=wx.DefaultPosition, | |
| 675 | + style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION) | |
| 676 | + self.PostCreate(pre) | |
| 677 | + except AttributeError: | |
| 678 | + wx.Dialog.__init__(self, None, -1, title, size=(360, 370), pos=wx.DefaultPosition, | |
| 679 | + style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION) | |
| 659 | 680 | |
| 660 | 681 | # Static text which contains message to user |
| 661 | 682 | label = wx.StaticText(self, -1, msg) |
| ... | ... | @@ -993,18 +1014,22 @@ class NewMask(wx.Dialog): |
| 993 | 1014 | import invesalius.data.mask as mask |
| 994 | 1015 | import invesalius.project as prj |
| 995 | 1016 | |
| 996 | - # Instead of calling wx.Dialog.__init__ we precreate the dialog | |
| 997 | - # so we can set an extra style that must be set before | |
| 998 | - # creation, and then we create the GUI object using the Create | |
| 999 | - # method. | |
| 1000 | - pre = wx.PreDialog() | |
| 1001 | - pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) | |
| 1002 | - pre.Create(parent, ID, title, pos, (500,300), style) | |
| 1017 | + try: | |
| 1018 | + # Instead of calling wx.Dialog.__init__ we precreate the dialog | |
| 1019 | + # so we can set an extra style that must be set before | |
| 1020 | + # creation, and then we create the GUI object using the Create | |
| 1021 | + # method. | |
| 1022 | + pre = wx.PreDialog() | |
| 1023 | + pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) | |
| 1024 | + pre.Create(parent, ID, title, pos, (500,300), style) | |
| 1025 | + # This next step is the most important, it turns this Python | |
| 1026 | + # object into the real wrapper of the dialog (instead of pre) | |
| 1027 | + # as far as the wxPython extension is concerned. | |
| 1028 | + self.PostCreate(pre) | |
| 1029 | + except AttributeError: | |
| 1030 | + wx.Dialog.__init__(self, parent, ID, title, pos, (500,300), style) | |
| 1031 | + self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) | |
| 1003 | 1032 | |
| 1004 | - # This next step is the most important, it turns this Python | |
| 1005 | - # object into the real wrapper of the dialog (instead of pre) | |
| 1006 | - # as far as the wxPython extension is concerned. | |
| 1007 | - self.PostCreate(pre) | |
| 1008 | 1033 | |
| 1009 | 1034 | self.CenterOnScreen() |
| 1010 | 1035 | |
| ... | ... | @@ -1031,8 +1056,7 @@ class NewMask(wx.Dialog): |
| 1031 | 1056 | |
| 1032 | 1057 | # Retrieve existing masks |
| 1033 | 1058 | project = prj.Project() |
| 1034 | - thresh_list = project.threshold_modes.keys() | |
| 1035 | - thresh_list.sort() | |
| 1059 | + thresh_list = sorted(project.threshold_modes.keys()) | |
| 1036 | 1060 | default_index = thresh_list.index(_("Bone")) |
| 1037 | 1061 | self.thresh_list = thresh_list |
| 1038 | 1062 | |
| ... | ... | @@ -1285,18 +1309,22 @@ class NewSurfaceDialog(wx.Dialog): |
| 1285 | 1309 | import invesalius.data.surface as surface |
| 1286 | 1310 | import invesalius.project as prj |
| 1287 | 1311 | |
| 1288 | - # Instead of calling wx.Dialog.__init__ we precreate the dialog | |
| 1289 | - # so we can set an extra style that must be set before | |
| 1290 | - # creation, and then we create the GUI object using the Create | |
| 1291 | - # method. | |
| 1292 | - pre = wx.PreDialog() | |
| 1293 | - pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) | |
| 1294 | - pre.Create(parent, ID, title, pos, (500,300), style) | |
| 1295 | - | |
| 1296 | - # This next step is the most important, it turns this Python | |
| 1297 | - # object into the real wrapper of the dialog (instead of pre) | |
| 1298 | - # as far as the wxPython extension is concerned. | |
| 1299 | - self.PostCreate(pre) | |
| 1312 | + try: | |
| 1313 | + # Instead of calling wx.Dialog.__init__ we precreate the dialog | |
| 1314 | + # so we can set an extra style that must be set before | |
| 1315 | + # creation, and then we create the GUI object using the Create | |
| 1316 | + # method. | |
| 1317 | + pre = wx.PreDialog() | |
| 1318 | + pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) | |
| 1319 | + pre.Create(parent, ID, title, pos, (500,300), style) | |
| 1320 | + | |
| 1321 | + # This next step is the most important, it turns this Python | |
| 1322 | + # object into the real wrapper of the dialog (instead of pre) | |
| 1323 | + # as far as the wxPython extension is concerned. | |
| 1324 | + self.PostCreate(pre) | |
| 1325 | + except AttributeError: | |
| 1326 | + wx.Dialog.__init__(self, parent, ID, title, pos, (500,300), style) | |
| 1327 | + self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) | |
| 1300 | 1328 | |
| 1301 | 1329 | self.CenterOnScreen() |
| 1302 | 1330 | |
| ... | ... | @@ -1323,8 +1351,7 @@ class NewSurfaceDialog(wx.Dialog): |
| 1323 | 1351 | |
| 1324 | 1352 | # Retrieve existing masks |
| 1325 | 1353 | project = prj.Project() |
| 1326 | - index_list = project.mask_dict.keys() | |
| 1327 | - index_list.sort() | |
| 1354 | + index_list = sorted(project.mask_dict.keys()) | |
| 1328 | 1355 | self.mask_list = [project.mask_dict[index].name for index in index_list] |
| 1329 | 1356 | |
| 1330 | 1357 | |
| ... | ... | @@ -1498,18 +1525,24 @@ class SurfaceCreationDialog(wx.Dialog): |
| 1498 | 1525 | # so we can set an extra style that must be set before |
| 1499 | 1526 | # creation, and then we create the GUI object using the Create |
| 1500 | 1527 | # method. |
| 1501 | - pre = wx.PreDialog() | |
| 1502 | - pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) | |
| 1503 | - pre.Create(parent, ID, title, pos, (500,300), style) | |
| 1504 | - | |
| 1505 | - # This extra style can be set after the UI object has been created. | |
| 1506 | - if 'wxMac' in wx.PlatformInfo and useMetal: | |
| 1507 | - self.SetExtraStyle(wx.DIALOG_EX_METAL) | |
| 1508 | - | |
| 1509 | - # This next step is the most important, it turns this Python | |
| 1510 | - # object into the real wrapper of the dialog (instead of pre) | |
| 1511 | - # as far as the wxPython extension is concerned. | |
| 1512 | - self.PostCreate(pre) | |
| 1528 | + try: | |
| 1529 | + pre = wx.PreDialog() | |
| 1530 | + pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) | |
| 1531 | + pre.Create(parent, ID, title, pos, (500,300), style) | |
| 1532 | + | |
| 1533 | + # This extra style can be set after the UI object has been created. | |
| 1534 | + if 'wxMac' in wx.PlatformInfo and useMetal: | |
| 1535 | + self.SetExtraStyle(wx.DIALOG_EX_METAL) | |
| 1536 | + | |
| 1537 | + # This next step is the most important, it turns this Python | |
| 1538 | + # object into the real wrapper of the dialog (instead of pre) | |
| 1539 | + # as far as the wxPython extension is concerned. | |
| 1540 | + self.PostCreate(pre) | |
| 1541 | + except AttributeError: | |
| 1542 | + wx.Dialog.__init__(self, parent, ID, title, pos, size, style) | |
| 1543 | + self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) | |
| 1544 | + if 'wxMac' in wx.PlatformInfo and useMetal: | |
| 1545 | + self.SetExtraStyle(wx.DIALOG_EX_METAL) | |
| 1513 | 1546 | |
| 1514 | 1547 | self.CenterOnScreen() |
| 1515 | 1548 | |
| ... | ... | @@ -1583,8 +1616,7 @@ class SurfaceCreationOptionsPanel(wx.Panel): |
| 1583 | 1616 | #Retrieve existing masks |
| 1584 | 1617 | project = prj.Project() |
| 1585 | 1618 | index_list = project.mask_dict.keys() |
| 1586 | - index_list.sort() | |
| 1587 | - self.mask_list = [project.mask_dict[index].name for index in index_list] | |
| 1619 | + self.mask_list = [project.mask_dict[index].name for index in sorted(index_list)] | |
| 1588 | 1620 | |
| 1589 | 1621 | active_mask = slc.Slice().current_mask.index |
| 1590 | 1622 | #active_mask = len(self.mask_list)-1 |
| ... | ... | @@ -1810,9 +1842,12 @@ class SurfaceMethodPanel(wx.Panel): |
| 1810 | 1842 | |
| 1811 | 1843 | class ClutImagedataDialog(wx.Dialog): |
| 1812 | 1844 | def __init__(self, histogram, init, end, nodes=None): |
| 1813 | - pre = wx.PreDialog() | |
| 1814 | - pre.Create(wx.GetApp().GetTopWindow(), -1, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 1815 | - self.PostCreate(pre) | |
| 1845 | + try: | |
| 1846 | + pre = wx.PreDialog() | |
| 1847 | + pre.Create(wx.GetApp().GetTopWindow(), -1, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 1848 | + self.PostCreate(pre) | |
| 1849 | + except AttributeError: | |
| 1850 | + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 1816 | 1851 | |
| 1817 | 1852 | self.histogram = histogram |
| 1818 | 1853 | self.init = init |
| ... | ... | @@ -1910,10 +1945,13 @@ class WatershedOptionsPanel(wx.Panel): |
| 1910 | 1945 | |
| 1911 | 1946 | |
| 1912 | 1947 | class WatershedOptionsDialog(wx.Dialog): |
| 1913 | - def __init__(self, config): | |
| 1914 | - pre = wx.PreDialog() | |
| 1915 | - pre.Create(wx.GetApp().GetTopWindow(), -1, _(u'Watershed'), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 1916 | - self.PostCreate(pre) | |
| 1948 | + def __init__(self, config, ID=-1, title=_(u'Watershed'), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT): | |
| 1949 | + try: | |
| 1950 | + pre = wx.PreDialog() | |
| 1951 | + pre.Create(wx.GetApp().GetTopWindow(), ID, title=title, style=style) | |
| 1952 | + self.PostCreate(pre) | |
| 1953 | + except AttributeError: | |
| 1954 | + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style) | |
| 1917 | 1955 | |
| 1918 | 1956 | self.config = config |
| 1919 | 1957 | |
| ... | ... | @@ -1951,10 +1989,13 @@ class WatershedOptionsDialog(wx.Dialog): |
| 1951 | 1989 | evt.Skip() |
| 1952 | 1990 | |
| 1953 | 1991 | class MaskBooleanDialog(wx.Dialog): |
| 1954 | - def __init__(self, masks): | |
| 1955 | - pre = wx.PreDialog() | |
| 1956 | - pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Boolean operations"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP) | |
| 1957 | - self.PostCreate(pre) | |
| 1992 | + def __init__(self, masks, ID=-1, title=_(u"Boolean operations"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP): | |
| 1993 | + try: | |
| 1994 | + pre = wx.PreDialog() | |
| 1995 | + pre.Create(wx.GetApp().GetTopWindow(), ID, title=title, style=style) | |
| 1996 | + self.PostCreate(pre) | |
| 1997 | + except AttributeError: | |
| 1998 | + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style) | |
| 1958 | 1999 | |
| 1959 | 2000 | self._init_gui(masks) |
| 1960 | 2001 | self.CenterOnScreen() |
| ... | ... | @@ -1980,7 +2021,7 @@ class MaskBooleanDialog(wx.Dialog): |
| 1980 | 2021 | (_(u"Difference"), const.BOOLEAN_DIFF, 'bool_difference.png'), |
| 1981 | 2022 | (_(u"Intersection"), const.BOOLEAN_AND, 'bool_intersection.png'), |
| 1982 | 2023 | (_(u"Exclusive disjunction"), const.BOOLEAN_XOR, 'bool_disjunction.png')) |
| 1983 | - self.op_boolean = wx.combo.BitmapComboBox(self, -1, op_choices[0][0], choices=[]) | |
| 2024 | + self.op_boolean = BitmapComboBox(self, -1, op_choices[0][0], choices=[]) | |
| 1984 | 2025 | |
| 1985 | 2026 | for n, i, f in op_choices: |
| 1986 | 2027 | bmp = wx.Bitmap(os.path.join(icon_folder, f), wx.BITMAP_TYPE_PNG) |
| ... | ... | @@ -2031,10 +2072,13 @@ class MaskBooleanDialog(wx.Dialog): |
| 2031 | 2072 | |
| 2032 | 2073 | |
| 2033 | 2074 | class ReorientImageDialog(wx.Dialog): |
| 2034 | - def __init__(self): | |
| 2035 | - pre = wx.PreDialog() | |
| 2036 | - pre.Create(wx.GetApp().GetTopWindow(), -1, _(u'Image reorientation'), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 2037 | - self.PostCreate(pre) | |
| 2075 | + def __init__(self, ID=-1, title=_(u'Image reorientation'), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT): | |
| 2076 | + try: | |
| 2077 | + pre = wx.PreDialog() | |
| 2078 | + pre.Create(wx.GetApp().GetTopWindow(), ID, title=title, style=style) | |
| 2079 | + self.PostCreate(pre) | |
| 2080 | + except AttributeError: | |
| 2081 | + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style) | |
| 2038 | 2082 | |
| 2039 | 2083 | self._closed = False |
| 2040 | 2084 | |
| ... | ... | @@ -2149,22 +2193,25 @@ class ImportBitmapParameters(wx.Dialog): |
| 2149 | 2193 | from os import sys |
| 2150 | 2194 | |
| 2151 | 2195 | def __init__(self): |
| 2152 | - pre = wx.PreDialog() | |
| 2153 | - | |
| 2154 | 2196 | if sys.platform == 'win32': |
| 2155 | 2197 | size=wx.Size(380,180) |
| 2156 | 2198 | else: |
| 2157 | 2199 | size=wx.Size(380,210) |
| 2158 | 2200 | |
| 2159 | - pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Create project from bitmap"),size=size,\ | |
| 2160 | - style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP) | |
| 2201 | + try: | |
| 2202 | + pre = wx.PreDialog() | |
| 2203 | + pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Create project from bitmap"),size=size, | |
| 2204 | + style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP) | |
| 2205 | + self.PostCreate(pre) | |
| 2206 | + except AttributeError: | |
| 2207 | + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, | |
| 2208 | + _(u"Create project from bitmap"), | |
| 2209 | + size=size, | |
| 2210 | + style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP) | |
| 2161 | 2211 | |
| 2162 | 2212 | self.interval = 0 |
| 2163 | - | |
| 2164 | - self.PostCreate(pre) | |
| 2165 | 2213 | |
| 2166 | 2214 | self._init_gui() |
| 2167 | - | |
| 2168 | 2215 | self.bind_evts() |
| 2169 | 2216 | self.CenterOnScreen() |
| 2170 | 2217 | |
| ... | ... | @@ -2195,13 +2242,19 @@ class ImportBitmapParameters(wx.Dialog): |
| 2195 | 2242 | |
| 2196 | 2243 | gbs.Add(stx_name, (0,0), flag=flag_labels) |
| 2197 | 2244 | gbs.Add(tx_name, (0,1)) |
| 2198 | - gbs.AddStretchSpacer((1,0)) | |
| 2245 | + try: | |
| 2246 | + gbs.Add(0, 0, (1,0)) | |
| 2247 | + except TypeError: | |
| 2248 | + gbs.AddStretchSpacer((1,0)) | |
| 2199 | 2249 | |
| 2200 | 2250 | gbs.Add(stx_orientation, (2,0), flag=flag_labels) |
| 2201 | 2251 | gbs.Add(cb_orientation, (2,1)) |
| 2202 | 2252 | |
| 2203 | 2253 | gbs.Add(stx_spacing, (3,0)) |
| 2204 | - gbs.AddStretchSpacer((4,0)) | |
| 2254 | + try: | |
| 2255 | + gbs.Add(0, 0, (4,0)) | |
| 2256 | + except TypeError: | |
| 2257 | + gbs.AddStretchSpacer((4,0)) | |
| 2205 | 2258 | |
| 2206 | 2259 | #--- spacing -------------- |
| 2207 | 2260 | gbs_spacing = wx.GridBagSizer(2, 6) |
| ... | ... | @@ -2251,17 +2304,23 @@ class ImportBitmapParameters(wx.Dialog): |
| 2251 | 2304 | |
| 2252 | 2305 | btn_cancel = wx.Button(p, wx.ID_CANCEL) |
| 2253 | 2306 | |
| 2254 | - gbs_button.AddStretchSpacer((0,2)) | |
| 2307 | + try: | |
| 2308 | + gbs_button.Add(0, 0, (0,2)) | |
| 2309 | + except TypeError: | |
| 2310 | + gbs_button.AddStretchSpacer((0,2)) | |
| 2255 | 2311 | gbs_button.Add(btn_cancel, (1,2)) |
| 2256 | 2312 | gbs_button.Add(btn_ok, (1,3)) |
| 2257 | 2313 | |
| 2258 | - gbs_principal.AddSizer(gbs, (0,0), flag = wx.ALL|wx.EXPAND) | |
| 2259 | - gbs_principal.AddSizer(gbs_spacing, (1,0), flag=wx.ALL|wx.EXPAND) | |
| 2260 | - gbs_principal.AddStretchSpacer((2,0)) | |
| 2261 | - gbs_principal.AddSizer(gbs_button, (3,0), flag = wx.ALIGN_RIGHT) | |
| 2314 | + gbs_principal.Add(gbs, (0,0), flag = wx.ALL|wx.EXPAND) | |
| 2315 | + gbs_principal.Add(gbs_spacing, (1,0), flag=wx.ALL|wx.EXPAND) | |
| 2316 | + try: | |
| 2317 | + gbs_principal.Add(0, 0, (2,0)) | |
| 2318 | + except TypeError: | |
| 2319 | + gbs_principal.AddStretchSpacer((2,0)) | |
| 2320 | + gbs_principal.Add(gbs_button, (3,0), flag = wx.ALIGN_RIGHT) | |
| 2262 | 2321 | |
| 2263 | 2322 | box = wx.BoxSizer() |
| 2264 | - box.AddSizer(gbs_principal, 1, wx.ALL|wx.EXPAND, 10) | |
| 2323 | + box.Add(gbs_principal, 1, wx.ALL|wx.EXPAND, 10) | |
| 2265 | 2324 | |
| 2266 | 2325 | p.SetSizer(box) |
| 2267 | 2326 | box.Fit(self) |
| ... | ... | @@ -2312,10 +2371,16 @@ class PanelTargeFFill(wx.Panel): |
| 2312 | 2371 | |
| 2313 | 2372 | sizer = wx.GridBagSizer(5, 5) |
| 2314 | 2373 | |
| 2315 | - sizer.AddStretchSpacer((0, 0)) | |
| 2374 | + try: | |
| 2375 | + sizer.Add(0, 0, (0, 0)) | |
| 2376 | + except TypeError: | |
| 2377 | + sizer.AddStretchSpacer((0, 0)) | |
| 2316 | 2378 | sizer.Add(self.target_2d, (1, 0), (1, 6), flag=wx.LEFT, border=5) |
| 2317 | 2379 | sizer.Add(self.target_3d, (2, 0), (1, 6), flag=wx.LEFT, border=5) |
| 2318 | - sizer.AddStretchSpacer((3, 0)) | |
| 2380 | + try: | |
| 2381 | + sizer.Add(0, 0, (3, 0)) | |
| 2382 | + except TypeError: | |
| 2383 | + sizer.AddStretchSpacer((3, 0)) | |
| 2319 | 2384 | |
| 2320 | 2385 | self.SetSizer(sizer) |
| 2321 | 2386 | sizer.Fit(self) |
| ... | ... | @@ -2332,11 +2397,17 @@ class Panel2DConnectivity(wx.Panel): |
| 2332 | 2397 | |
| 2333 | 2398 | sizer = wx.GridBagSizer(5, 5) |
| 2334 | 2399 | |
| 2335 | - sizer.AddStretchSpacer((0, 0)) | |
| 2400 | + try: | |
| 2401 | + sizer.Add(0, 0, (0, 0)) | |
| 2402 | + except TypeError: | |
| 2403 | + sizer.AddStretchSpacer((0, 0)) | |
| 2336 | 2404 | sizer.Add(wx.StaticText(self, -1, _(u"2D Connectivity")), (1, 0), (1, 6), flag=wx.LEFT, border=5) |
| 2337 | 2405 | sizer.Add(self.conect2D_4, (2, 0), flag=wx.LEFT, border=7) |
| 2338 | 2406 | sizer.Add(self.conect2D_8, (2, 1), flag=wx.LEFT, border=7) |
| 2339 | - sizer.AddStretchSpacer((3, 0)) | |
| 2407 | + try: | |
| 2408 | + sizer.Add(0, 0, (3, 0)) | |
| 2409 | + except TypeError: | |
| 2410 | + sizer.AddStretchSpacer((3, 0)) | |
| 2340 | 2411 | |
| 2341 | 2412 | if show_orientation: |
| 2342 | 2413 | self.cmb_orientation = wx.ComboBox(self, -1, choices=(_(u"Axial"), _(u"Coronal"), _(u"Sagital")), style=wx.CB_READONLY) |
| ... | ... | @@ -2344,7 +2415,10 @@ class Panel2DConnectivity(wx.Panel): |
| 2344 | 2415 | |
| 2345 | 2416 | sizer.Add(wx.StaticText(self, -1, _(u"Orientation")), (4, 0), (1, 6), flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, border=5) |
| 2346 | 2417 | sizer.Add(self.cmb_orientation, (5, 0), (1, 10), flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7) |
| 2347 | - sizer.AddStretchSpacer((6, 0)) | |
| 2418 | + try: | |
| 2419 | + sizer.Add(0, 0, (6, 0)) | |
| 2420 | + except TypeError: | |
| 2421 | + sizer.AddStretchSpacer((6, 0)) | |
| 2348 | 2422 | |
| 2349 | 2423 | self.SetSizer(sizer) |
| 2350 | 2424 | sizer.Fit(self) |
| ... | ... | @@ -2378,12 +2452,18 @@ class Panel3DConnectivity(wx.Panel): |
| 2378 | 2452 | |
| 2379 | 2453 | sizer = wx.GridBagSizer(5, 5) |
| 2380 | 2454 | |
| 2381 | - sizer.AddStretchSpacer((0, 0)) | |
| 2455 | + try: | |
| 2456 | + sizer.Add(0, 0, (0, 0)) | |
| 2457 | + except TypeError: | |
| 2458 | + sizer.AddStretchSpacer((0, 0)) | |
| 2382 | 2459 | sizer.Add(wx.StaticText(self, -1, _(u"3D Connectivity")), (1, 0), (1, 6), flag=wx.LEFT, border=5) |
| 2383 | 2460 | sizer.Add(self.conect3D_6, (2, 0), flag=wx.LEFT, border=9) |
| 2384 | 2461 | sizer.Add(self.conect3D_18, (2, 1), flag=wx.LEFT, border=9) |
| 2385 | 2462 | sizer.Add(self.conect3D_26, (2, 2), flag=wx.LEFT, border=9) |
| 2386 | - sizer.AddStretchSpacer((3, 0)) | |
| 2463 | + try: | |
| 2464 | + sizer.Add(0, 0, (3, 0)) | |
| 2465 | + except TypeError: | |
| 2466 | + sizer.AddStretchSpacer((3, 0)) | |
| 2387 | 2467 | |
| 2388 | 2468 | self.SetSizer(sizer) |
| 2389 | 2469 | sizer.Fit(self) |
| ... | ... | @@ -2434,7 +2514,7 @@ class PanelFFillThreshold(wx.Panel): |
| 2434 | 2514 | def OnSlideChanged(self, evt): |
| 2435 | 2515 | self.config.t0 = int(self.threshold.GetMinValue()) |
| 2436 | 2516 | self.config.t1 = int(self.threshold.GetMaxValue()) |
| 2437 | - print self.config.t0, self.config.t1 | |
| 2517 | + print(self.config.t0, self.config.t1) | |
| 2438 | 2518 | |
| 2439 | 2519 | |
| 2440 | 2520 | class PanelFFillDynamic(wx.Panel): |
| ... | ... | @@ -2458,11 +2538,17 @@ class PanelFFillDynamic(wx.Panel): |
| 2458 | 2538 | |
| 2459 | 2539 | sizer = wx.GridBagSizer(5, 5) |
| 2460 | 2540 | |
| 2461 | - sizer.AddStretchSpacer((0, 0)) | |
| 2541 | + try: | |
| 2542 | + sizer.Add(0, 0, (0, 0)) | |
| 2543 | + except TypeError: | |
| 2544 | + sizer.AddStretchSpacer((0, 0)) | |
| 2462 | 2545 | |
| 2463 | 2546 | sizer.Add(self.use_ww_wl, (1, 0), (1, 6), flag=wx.LEFT, border=5) |
| 2464 | 2547 | |
| 2465 | - sizer.AddStretchSpacer((2, 0)) | |
| 2548 | + try: | |
| 2549 | + sizer.Add(0, 0, (2, 0)) | |
| 2550 | + except TypeError: | |
| 2551 | + sizer.AddStretchSpacer((2, 0)) | |
| 2466 | 2552 | |
| 2467 | 2553 | sizer.Add(wx.StaticText(self, -1, _(u"Deviation")), (3, 0), (1, 6), flag=wx.LEFT, border=5) |
| 2468 | 2554 | |
| ... | ... | @@ -2472,7 +2558,10 @@ class PanelFFillDynamic(wx.Panel): |
| 2472 | 2558 | sizer.Add(wx.StaticText(self, -1, _(u"Max:")), (4, 2), flag=wx.ALIGN_CENTER_VERTICAL|wx.LEFT, border=9) |
| 2473 | 2559 | sizer.Add(self.deviation_max, (4, 3)) |
| 2474 | 2560 | |
| 2475 | - sizer.AddStretchSpacer((5, 0)) | |
| 2561 | + try: | |
| 2562 | + sizer.Add(0, 0, (5, 0)) | |
| 2563 | + except TypeError: | |
| 2564 | + sizer.AddStretchSpacer((5, 0)) | |
| 2476 | 2565 | |
| 2477 | 2566 | self.SetSizer(sizer) |
| 2478 | 2567 | sizer.Fit(self) |
| ... | ... | @@ -2516,19 +2605,28 @@ class PanelFFillConfidence(wx.Panel): |
| 2516 | 2605 | |
| 2517 | 2606 | sizer = wx.GridBagSizer(5, 5) |
| 2518 | 2607 | |
| 2519 | - sizer.AddStretchSpacer((0, 0)) | |
| 2608 | + try: | |
| 2609 | + sizer.Add(0, 0, (0, 0)) | |
| 2610 | + except TypeError: | |
| 2611 | + sizer.AddStretchSpacer((0, 0)) | |
| 2520 | 2612 | |
| 2521 | 2613 | sizer.Add(self.use_ww_wl, (1, 0), (1, 6), flag=wx.LEFT, border=5) |
| 2522 | 2614 | |
| 2523 | - sizer.AddStretchSpacer((2, 0)) | |
| 2615 | + try: | |
| 2616 | + sizer.Add(0, 0, (2, 0)) | |
| 2617 | + except TypeError: | |
| 2618 | + sizer.AddStretchSpacer((2, 0)) | |
| 2524 | 2619 | |
| 2525 | 2620 | sizer.Add(wx.StaticText(self, -1, _(u"Multiplier")), (3, 0), (1, 3), flag=wx.ALIGN_CENTER_VERTICAL|wx.LEFT, border=5) |
| 2526 | - sizer.Add(self.spin_mult, (3, 3), (1, 2)) | |
| 2621 | + sizer.Add(self.spin_mult, (3, 3), (1, 3)) | |
| 2527 | 2622 | |
| 2528 | 2623 | sizer.Add(wx.StaticText(self, -1, _(u"Iterations")), (4, 0), (1, 3), flag=wx.ALIGN_CENTER_VERTICAL|wx.LEFT, border=5) |
| 2529 | 2624 | sizer.Add(self.spin_iters, (4, 3), (1, 2)) |
| 2530 | 2625 | |
| 2531 | - sizer.AddStretchSpacer((5, 0)) | |
| 2626 | + try: | |
| 2627 | + sizer.Add(0, 0, (5, 0)) | |
| 2628 | + except TypeError: | |
| 2629 | + sizer.AddStretchSpacer((5, 0)) | |
| 2532 | 2630 | |
| 2533 | 2631 | self.SetSizer(sizer) |
| 2534 | 2632 | sizer.Fit(self) |
| ... | ... | @@ -2550,9 +2648,12 @@ class PanelFFillConfidence(wx.Panel): |
| 2550 | 2648 | |
| 2551 | 2649 | class FFillOptionsDialog(wx.Dialog): |
| 2552 | 2650 | def __init__(self, title, config): |
| 2553 | - pre = wx.PreDialog() | |
| 2554 | - pre.Create(wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 2555 | - self.PostCreate(pre) | |
| 2651 | + try: | |
| 2652 | + pre = wx.PreDialog() | |
| 2653 | + pre.Create(wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 2654 | + self.PostCreate(pre) | |
| 2655 | + except AttributeError: | |
| 2656 | + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 2556 | 2657 | |
| 2557 | 2658 | self.config = config |
| 2558 | 2659 | |
| ... | ... | @@ -2651,7 +2752,7 @@ class FFillOptionsDialog(wx.Dialog): |
| 2651 | 2752 | self.config.con_3d = 26 |
| 2652 | 2753 | |
| 2653 | 2754 | def OnClose(self, evt): |
| 2654 | - print "ONCLOSE" | |
| 2755 | + print("ONCLOSE") | |
| 2655 | 2756 | if self.config.dlg_visible: |
| 2656 | 2757 | Publisher.sendMessage('Disable style', const.SLICE_STATE_MASK_FFILL) |
| 2657 | 2758 | evt.Skip() |
| ... | ... | @@ -2660,9 +2761,12 @@ class FFillOptionsDialog(wx.Dialog): |
| 2660 | 2761 | |
| 2661 | 2762 | class SelectPartsOptionsDialog(wx.Dialog): |
| 2662 | 2763 | def __init__(self, config): |
| 2663 | - pre = wx.PreDialog() | |
| 2664 | - pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Select mask parts"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 2665 | - self.PostCreate(pre) | |
| 2764 | + try: | |
| 2765 | + pre = wx.PreDialog() | |
| 2766 | + pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Select mask parts"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 2767 | + self.PostCreate(pre) | |
| 2768 | + except AttributeError: | |
| 2769 | + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, _(u"Select mask parts"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 2666 | 2770 | |
| 2667 | 2771 | self.config = config |
| 2668 | 2772 | |
| ... | ... | @@ -2700,7 +2804,7 @@ class SelectPartsOptionsDialog(wx.Dialog): |
| 2700 | 2804 | btn_sizer.Add(self.btn_ok, 0, flag=wx.ALIGN_RIGHT, border=5) |
| 2701 | 2805 | btn_sizer.Add(self.btn_cancel, 0, flag=wx.LEFT|wx.ALIGN_RIGHT, border=5) |
| 2702 | 2806 | |
| 2703 | - sizer.AddSizer(btn_sizer, 0, flag=wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT, border=5) | |
| 2807 | + sizer.Add(btn_sizer, 0, flag=wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT, border=5) | |
| 2704 | 2808 | sizer.AddSpacer(5) |
| 2705 | 2809 | |
| 2706 | 2810 | self.SetSizer(sizer) |
| ... | ... | @@ -2741,10 +2845,13 @@ class SelectPartsOptionsDialog(wx.Dialog): |
| 2741 | 2845 | self.Destroy() |
| 2742 | 2846 | |
| 2743 | 2847 | class FFillSegmentationOptionsDialog(wx.Dialog): |
| 2744 | - def __init__(self, config): | |
| 2745 | - pre = wx.PreDialog() | |
| 2746 | - pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Region growing"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 2747 | - self.PostCreate(pre) | |
| 2848 | + def __init__(self, config, ID=-1, title=_(u"Region growing"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT): | |
| 2849 | + try: | |
| 2850 | + pre = wx.PreDialog() | |
| 2851 | + pre.Create(wx.GetApp().GetTopWindow(), ID, title=title, style=style) | |
| 2852 | + self.PostCreate(pre) | |
| 2853 | + except AttributeError: | |
| 2854 | + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style) | |
| 2748 | 2855 | |
| 2749 | 2856 | self.config = config |
| 2750 | 2857 | |
| ... | ... | @@ -2816,20 +2923,38 @@ class FFillSegmentationOptionsDialog(wx.Dialog): |
| 2816 | 2923 | # Sizer |
| 2817 | 2924 | sizer = wx.GridBagSizer(2, 2) |
| 2818 | 2925 | |
| 2819 | - sizer.AddStretchSpacer((0, 0)) | |
| 2926 | + try: | |
| 2927 | + sizer.Add(0, 0, (0, 0)) | |
| 2928 | + except TypeError: | |
| 2929 | + sizer.AddStretchSpacer((0, 0)) | |
| 2820 | 2930 | sizer.Add(wx.StaticText(self, -1, _(u"Parameters")), (1, 0), (1, 6), flag=wx.LEFT, border=5) |
| 2821 | - sizer.AddStretchSpacer((2, 0)) | |
| 2931 | + try: | |
| 2932 | + sizer.Add(0, 0, (2, 0)) | |
| 2933 | + except TypeError: | |
| 2934 | + sizer.AddStretchSpacer((2, 0)) | |
| 2822 | 2935 | sizer.Add(self.panel_target, (3, 0), (1, 6), flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7) |
| 2823 | - sizer.AddStretchSpacer((4, 0)) | |
| 2936 | + try: | |
| 2937 | + sizer.Add(0, 0, (4, 0)) | |
| 2938 | + except TypeError: | |
| 2939 | + sizer.AddStretchSpacer((4, 0)) | |
| 2824 | 2940 | sizer.Add(self.panel2dcon, (5, 0), (1, 6), flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7) |
| 2825 | - sizer.AddStretchSpacer((6, 0)) | |
| 2941 | + try: | |
| 2942 | + sizer.Add(0, 0, (6, 0)) | |
| 2943 | + except TypeError: | |
| 2944 | + sizer.AddStretchSpacer((6, 0)) | |
| 2826 | 2945 | sizer.Add(self.panel3dcon, (7, 0), (1, 6), flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7) |
| 2827 | - sizer.AddStretchSpacer((8, 0)) | |
| 2946 | + try: | |
| 2947 | + sizer.Add(0, 0, (8, 0)) | |
| 2948 | + except TypeError: | |
| 2949 | + sizer.AddStretchSpacer((8, 0)) | |
| 2828 | 2950 | |
| 2829 | 2951 | sizer.Add(wx.StaticText(self, -1, _(u"Method")), (9, 0), (1, 1), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=7) |
| 2830 | 2952 | sizer.Add(self.cmb_method, (9, 1), (1, 5), flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7) |
| 2831 | 2953 | |
| 2832 | - sizer.AddStretchSpacer((10, 0)) | |
| 2954 | + try: | |
| 2955 | + sizer.Add(0, 0, (10, 0)) | |
| 2956 | + except TypeError: | |
| 2957 | + sizer.AddStretchSpacer((10, 0)) | |
| 2833 | 2958 | |
| 2834 | 2959 | if self.config.method == 'dynamic': |
| 2835 | 2960 | self.cmb_method.SetSelection(0) |
| ... | ... | @@ -2845,9 +2970,15 @@ class FFillSegmentationOptionsDialog(wx.Dialog): |
| 2845 | 2970 | sizer.Add(self.panel_ffill_threshold, (11, 0), (1, 6), flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7) |
| 2846 | 2971 | self.config.method = 'threshold' |
| 2847 | 2972 | |
| 2848 | - sizer.AddStretchSpacer((12, 0)) | |
| 2973 | + try: | |
| 2974 | + sizer.Add(0, 0, (12, 0)) | |
| 2975 | + except TypeError: | |
| 2976 | + sizer.AddStretchSpacer((12, 0)) | |
| 2849 | 2977 | sizer.Add(self.close_btn, (13, 0), (1, 6), flag=wx.ALIGN_RIGHT|wx.RIGHT, border=5) |
| 2850 | - sizer.AddStretchSpacer((14, 0)) | |
| 2978 | + try: | |
| 2979 | + sizer.Add(0, 0, (14, 0)) | |
| 2980 | + except TypeError: | |
| 2981 | + sizer.AddStretchSpacer((14, 0)) | |
| 2851 | 2982 | |
| 2852 | 2983 | self.SetSizer(sizer) |
| 2853 | 2984 | sizer.Fit(self) |
| ... | ... | @@ -2919,13 +3050,16 @@ class FFillSegmentationOptionsDialog(wx.Dialog): |
| 2919 | 3050 | |
| 2920 | 3051 | class CropOptionsDialog(wx.Dialog): |
| 2921 | 3052 | |
| 2922 | - def __init__(self, config): | |
| 3053 | + def __init__(self, config, ID=-1, title=_(u"Crop mask"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT): | |
| 2923 | 3054 | self.config = config |
| 2924 | - pre = wx.PreDialog() | |
| 3055 | + try: | |
| 3056 | + pre = wx.PreDialog() | |
| 3057 | + | |
| 3058 | + pre.Create(wx.GetApp().GetTopWindow(), ID, title=title, style=style) | |
| 3059 | + self.PostCreate(pre) | |
| 3060 | + except AttributeError: | |
| 3061 | + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style) | |
| 2925 | 3062 | |
| 2926 | - pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Crop mask"),\ | |
| 2927 | - style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 2928 | - self.PostCreate(pre) | |
| 2929 | 3063 | |
| 2930 | 3064 | self._init_gui() |
| 2931 | 3065 | |
| ... | ... | @@ -3000,13 +3134,17 @@ class CropOptionsDialog(wx.Dialog): |
| 3000 | 3134 | gbs_button.Add(btn_cancel, (0,0)) |
| 3001 | 3135 | gbs_button.Add(btn_ok, (0,1)) |
| 3002 | 3136 | |
| 3003 | - gbs_principal.AddSizer(gbs, (0,0), flag = wx.ALL|wx.EXPAND) | |
| 3004 | - gbs_principal.AddStretchSpacer((1,0)) | |
| 3005 | - gbs_principal.AddStretchSpacer((2,0)) | |
| 3006 | - gbs_principal.AddSizer(gbs_button, (3,0), flag = wx.ALIGN_RIGHT) | |
| 3137 | + gbs_principal.Add(gbs, (0,0), flag = wx.ALL|wx.EXPAND) | |
| 3138 | + try: | |
| 3139 | + gbs_principal.Add(0, 0, (1, 0)) | |
| 3140 | + gbs_principal.Add(0, 0, (2, 0)) | |
| 3141 | + except TypeError: | |
| 3142 | + gbs_principal.AddStretchSpacer((1, 0)) | |
| 3143 | + gbs_principal.AddStretchSpacer((2, 0)) | |
| 3144 | + gbs_principal.Add(gbs_button, (3,0), flag = wx.ALIGN_RIGHT) | |
| 3007 | 3145 | |
| 3008 | 3146 | box = wx.BoxSizer() |
| 3009 | - box.AddSizer(gbs_principal, 1, wx.ALL|wx.EXPAND, 10) | |
| 3147 | + box.Add(gbs_principal, 1, wx.ALL|wx.EXPAND, 10) | |
| 3010 | 3148 | |
| 3011 | 3149 | p.SetSizer(box) |
| 3012 | 3150 | box.Fit(p) |
| ... | ... | @@ -3039,9 +3177,12 @@ class CropOptionsDialog(wx.Dialog): |
| 3039 | 3177 | |
| 3040 | 3178 | class FillHolesAutoDialog(wx.Dialog): |
| 3041 | 3179 | def __init__(self, title): |
| 3042 | - pre = wx.PreDialog() | |
| 3043 | - pre.Create(wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 3044 | - self.PostCreate(pre) | |
| 3180 | + try: | |
| 3181 | + pre = wx.PreDialog() | |
| 3182 | + pre.Create(wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 3183 | + self.PostCreate(pre) | |
| 3184 | + except AttributeError: | |
| 3185 | + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 3045 | 3186 | |
| 3046 | 3187 | self._init_gui() |
| 3047 | 3188 | |
| ... | ... | @@ -3056,10 +3197,13 @@ class FillHolesAutoDialog(wx.Dialog): |
| 3056 | 3197 | self.panel2dcon = Panel2DConnectivity(self, show_orientation=True, style=border_style|wx.TAB_TRAVERSAL) |
| 3057 | 3198 | self.panel3dcon = Panel3DConnectivity(self, style=border_style|wx.TAB_TRAVERSAL) |
| 3058 | 3199 | |
| 3059 | - self.panel_target.target_2d.SetValue(1) | |
| 3060 | 3200 | self.panel2dcon.Enable(1) |
| 3061 | 3201 | self.panel3dcon.Enable(0) |
| 3062 | 3202 | |
| 3203 | + self.panel_target.target_2d.SetValue(1) | |
| 3204 | + self.panel2dcon.conect2D_4.SetValue(1) | |
| 3205 | + self.panel3dcon.conect3D_6.SetValue(1) | |
| 3206 | + | |
| 3063 | 3207 | self.apply_btn = wx.Button(self, wx.ID_APPLY) |
| 3064 | 3208 | self.close_btn = wx.Button(self, wx.ID_CLOSE) |
| 3065 | 3209 | |
| ... | ... | @@ -3089,7 +3233,7 @@ class FillHolesAutoDialog(wx.Dialog): |
| 3089 | 3233 | btn_sizer.Add(self.apply_btn, 0, flag=wx.ALIGN_RIGHT, border=5) |
| 3090 | 3234 | btn_sizer.Add(self.close_btn, 0, flag=wx.LEFT|wx.ALIGN_RIGHT, border=5) |
| 3091 | 3235 | |
| 3092 | - sizer.AddSizer(btn_sizer, 0, flag=wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT, border=5) | |
| 3236 | + sizer.Add(btn_sizer, 0, flag=wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT, border=5) | |
| 3093 | 3237 | |
| 3094 | 3238 | sizer.AddSpacer(5) |
| 3095 | 3239 | |
| ... | ... | @@ -3147,10 +3291,14 @@ class ObjectCalibrationDialog(wx.Dialog): |
| 3147 | 3291 | self.obj_fiducials = np.full([5, 3], np.nan) |
| 3148 | 3292 | self.obj_orients = np.full([5, 3], np.nan) |
| 3149 | 3293 | |
| 3150 | - pre = wx.PreDialog() | |
| 3151 | - pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Object calibration"), size=(450, 440), | |
| 3152 | - style=wx.DEFAULT_DIALOG_STYLE | wx.FRAME_FLOAT_ON_PARENT) | |
| 3153 | - self.PostCreate(pre) | |
| 3294 | + try: | |
| 3295 | + pre = wx.PreDialog() | |
| 3296 | + pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Object calibration"), size=(450, 440), | |
| 3297 | + style=wx.DEFAULT_DIALOG_STYLE | wx.FRAME_FLOAT_ON_PARENT) | |
| 3298 | + self.PostCreate(pre) | |
| 3299 | + except AttributeError: | |
| 3300 | + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, _(u"Object calibration"), size=(450, 440), | |
| 3301 | + style=wx.DEFAULT_DIALOG_STYLE | wx.FRAME_FLOAT_ON_PARENT) | |
| 3154 | 3302 | |
| 3155 | 3303 | self._init_gui() |
| 3156 | 3304 | self.LoadObject() |
| ... | ... | @@ -3191,8 +3339,8 @@ class ObjectCalibrationDialog(wx.Dialog): |
| 3191 | 3339 | tips_obj = const.TIPS_OBJ |
| 3192 | 3340 | |
| 3193 | 3341 | for k in btns_obj: |
| 3194 | - n = btns_obj[k].keys()[0] | |
| 3195 | - lab = btns_obj[k].values()[0] | |
| 3342 | + n = list(btns_obj[k].keys())[0] | |
| 3343 | + lab = list(btns_obj[k].values())[0] | |
| 3196 | 3344 | self.btns_coord[n] = wx.Button(self, k, label=lab, size=wx.Size(60, 23)) |
| 3197 | 3345 | self.btns_coord[n].SetToolTip(wx.ToolTip(tips_obj[n])) |
| 3198 | 3346 | self.btns_coord[n].Bind(wx.EVT_BUTTON, self.OnGetObjectFiducials) |
| ... | ... | @@ -3332,7 +3480,7 @@ class ObjectCalibrationDialog(wx.Dialog): |
| 3332 | 3480 | return ball_actor, tactor |
| 3333 | 3481 | |
| 3334 | 3482 | def OnGetObjectFiducials(self, evt): |
| 3335 | - btn_id = const.BTNS_OBJ[evt.GetId()].keys()[0] | |
| 3483 | + btn_id = list(const.BTNS_OBJ[evt.GetId()].keys())[0] | |
| 3336 | 3484 | |
| 3337 | 3485 | if self.trk_init and self.tracker_id: |
| 3338 | 3486 | coord_raw = dco.GetCoordinates(self.trk_init, self.tracker_id, self.obj_ref_id) | ... | ... |
invesalius/gui/dicom_preview_panel.py
| ... | ... | @@ -272,7 +272,10 @@ class Preview(wx.Panel): |
| 272 | 272 | def OnEnter(self, evt): |
| 273 | 273 | if not self.select_on: |
| 274 | 274 | #c = wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DHILIGHT) |
| 275 | - c = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE) | |
| 275 | + try: | |
| 276 | + c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE) | |
| 277 | + except AttributeError: | |
| 278 | + c = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE) | |
| 276 | 279 | self.SetBackgroundColour(c) |
| 277 | 280 | |
| 278 | 281 | def OnLeave(self, evt): |
| ... | ... | @@ -320,7 +323,10 @@ class Preview(wx.Panel): |
| 320 | 323 | |
| 321 | 324 | def Select(self, on=True): |
| 322 | 325 | if self.select_on: |
| 323 | - c = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT) | |
| 326 | + try: | |
| 327 | + c = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT) | |
| 328 | + except AttributeError: | |
| 329 | + c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT) | |
| 324 | 330 | else: |
| 325 | 331 | c = (PREVIEW_BACKGROUND) |
| 326 | 332 | self.SetBackgroundColour(c) |
| ... | ... | @@ -355,10 +361,10 @@ class DicomPreviewSeries(wx.Panel): |
| 355 | 361 | self.grid = wx.GridSizer(rows=NROWS, cols=NCOLS, vgap=3, hgap=3) |
| 356 | 362 | |
| 357 | 363 | sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 358 | - sizer.AddSizer(self.grid, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 364 | + sizer.Add(self.grid, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 359 | 365 | |
| 360 | 366 | background_sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 361 | - background_sizer.AddSizer(sizer, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 367 | + background_sizer.Add(sizer, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 362 | 368 | background_sizer.Add(scroll, 0, wx.EXPAND|wx.GROW) |
| 363 | 369 | self.SetSizer(background_sizer) |
| 364 | 370 | background_sizer.Fit(self) |
| ... | ... | @@ -374,8 +380,8 @@ class DicomPreviewSeries(wx.Panel): |
| 374 | 380 | |
| 375 | 381 | def _Add_Panels_Preview(self): |
| 376 | 382 | self.previews = [] |
| 377 | - for i in xrange(NROWS): | |
| 378 | - for j in xrange(NCOLS): | |
| 383 | + for i in range(NROWS): | |
| 384 | + for j in range(NCOLS): | |
| 379 | 385 | p = Preview(self) |
| 380 | 386 | p.Bind(EVT_PREVIEW_CLICK, self.OnSelect) |
| 381 | 387 | #if (i == j == 0): |
| ... | ... | @@ -432,7 +438,7 @@ class DicomPreviewSeries(wx.Panel): |
| 432 | 438 | initial = self.displayed_position * NCOLS |
| 433 | 439 | final = initial + NUM_PREVIEWS |
| 434 | 440 | if len(self.files) < final: |
| 435 | - for i in xrange(final-len(self.files)): | |
| 441 | + for i in range(final-len(self.files)): | |
| 436 | 442 | try: |
| 437 | 443 | self.previews[-i-1].Hide() |
| 438 | 444 | except IndexError: |
| ... | ... | @@ -441,7 +447,7 @@ class DicomPreviewSeries(wx.Panel): |
| 441 | 447 | self.nhidden_last_display = final-len(self.files) |
| 442 | 448 | else: |
| 443 | 449 | if self.nhidden_last_display: |
| 444 | - for i in xrange(self.nhidden_last_display): | |
| 450 | + for i in range(self.nhidden_last_display): | |
| 445 | 451 | try: |
| 446 | 452 | self.previews[-i-1].Show() |
| 447 | 453 | except IndexError: |
| ... | ... | @@ -492,10 +498,10 @@ class DicomPreviewSlice(wx.Panel): |
| 492 | 498 | self.grid = wx.GridSizer(rows=NROWS, cols=NCOLS, vgap=3, hgap=3) |
| 493 | 499 | |
| 494 | 500 | sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 495 | - sizer.AddSizer(self.grid, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 501 | + sizer.Add(self.grid, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 496 | 502 | |
| 497 | 503 | background_sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 498 | - background_sizer.AddSizer(sizer, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 504 | + background_sizer.Add(sizer, 1, wx.EXPAND|wx.GROW|wx.ALL, 2) | |
| 499 | 505 | background_sizer.Add(scroll, 0, wx.EXPAND|wx.GROW) |
| 500 | 506 | self.SetSizer(background_sizer) |
| 501 | 507 | background_sizer.Fit(self) |
| ... | ... | @@ -511,8 +517,8 @@ class DicomPreviewSlice(wx.Panel): |
| 511 | 517 | |
| 512 | 518 | def _Add_Panels_Preview(self): |
| 513 | 519 | self.previews = [] |
| 514 | - for i in xrange(NROWS): | |
| 515 | - for j in xrange(NCOLS): | |
| 520 | + for i in range(NROWS): | |
| 521 | + for j in range(NCOLS): | |
| 516 | 522 | p = Preview(self) |
| 517 | 523 | p.Bind(EVT_PREVIEW_CLICK, self.OnPreviewClick) |
| 518 | 524 | #p.Hide() |
| ... | ... | @@ -545,7 +551,7 @@ class DicomPreviewSlice(wx.Panel): |
| 545 | 551 | if isinstance(dicom.image.thumbnail_path, list): |
| 546 | 552 | _slice = 0 |
| 547 | 553 | for thumbnail in dicom.image.thumbnail_path: |
| 548 | - print thumbnail | |
| 554 | + print(thumbnail) | |
| 549 | 555 | info = DicomInfo(n, dicom, |
| 550 | 556 | _("Image %d") % (n), |
| 551 | 557 | "%.2f" % (dicom.image.position[2]), _slice) |
| ... | ... | @@ -577,7 +583,7 @@ class DicomPreviewSlice(wx.Panel): |
| 577 | 583 | if isinstance(dicom.image.thumbnail_path, list): |
| 578 | 584 | _slice = 0 |
| 579 | 585 | for thumbnail in dicom.image.thumbnail_path: |
| 580 | - print thumbnail | |
| 586 | + print(thumbnail) | |
| 581 | 587 | info = DicomInfo(n, dicom, |
| 582 | 588 | _("Image %d") % int(n), |
| 583 | 589 | "%.2f" % (dicom.image.position[2]), _slice) |
| ... | ... | @@ -603,7 +609,7 @@ class DicomPreviewSlice(wx.Panel): |
| 603 | 609 | initial = self.displayed_position * NCOLS |
| 604 | 610 | final = initial + NUM_PREVIEWS |
| 605 | 611 | if len(self.files) < final: |
| 606 | - for i in xrange(final-len(self.files)): | |
| 612 | + for i in range(final-len(self.files)): | |
| 607 | 613 | try: |
| 608 | 614 | self.previews[-i-1].Hide() |
| 609 | 615 | except IndexError: |
| ... | ... | @@ -611,7 +617,7 @@ class DicomPreviewSlice(wx.Panel): |
| 611 | 617 | self.nhidden_last_display = final-len(self.files) |
| 612 | 618 | else: |
| 613 | 619 | if self.nhidden_last_display: |
| 614 | - for i in xrange(self.nhidden_last_display): | |
| 620 | + for i in range(self.nhidden_last_display): | |
| 615 | 621 | try: |
| 616 | 622 | self.previews[-i-1].Show() |
| 617 | 623 | except IndexError: |
| ... | ... | @@ -648,7 +654,7 @@ class DicomPreviewSlice(wx.Panel): |
| 648 | 654 | self.first_selection = dicom_id |
| 649 | 655 | self.last_selection = dicom_id |
| 650 | 656 | |
| 651 | - for i in xrange(len(self.files)): | |
| 657 | + for i in range(len(self.files)): | |
| 652 | 658 | |
| 653 | 659 | if i == dicom_id: |
| 654 | 660 | self.files[i].selected = True |
| ... | ... | @@ -666,7 +672,7 @@ class DicomPreviewSlice(wx.Panel): |
| 666 | 672 | self.selected_panel.select_on = self.selected_panel is evt.GetEventObject() |
| 667 | 673 | |
| 668 | 674 | if self.first_selection != self.last_selection: |
| 669 | - for i in xrange(len(self.files)): | |
| 675 | + for i in range(len(self.files)): | |
| 670 | 676 | if i >= self.first_selection and i <= self.last_selection: |
| 671 | 677 | self.files[i].selected = True |
| 672 | 678 | else: |
| ... | ... | @@ -772,7 +778,7 @@ class SingleImagePreview(wx.Panel): |
| 772 | 778 | maxValue=99, |
| 773 | 779 | style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS) |
| 774 | 780 | slider.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) |
| 775 | - slider.SetTickFreq(1, 1) | |
| 781 | + slider.SetTickFreq(1) | |
| 776 | 782 | self.slider = slider |
| 777 | 783 | |
| 778 | 784 | checkbox = wx.CheckBox(self, -1, _("Auto-play")) | ... | ... |
invesalius/gui/frame.py
| ... | ... | @@ -24,6 +24,12 @@ import sys |
| 24 | 24 | import webbrowser |
| 25 | 25 | |
| 26 | 26 | import wx |
| 27 | + | |
| 28 | +try: | |
| 29 | + from wx.adv import TaskBarIcon as wx_TaskBarIcon | |
| 30 | +except ImportError: | |
| 31 | + from wx import TaskBarIcon as wx_TaskBarIcon | |
| 32 | + | |
| 27 | 33 | import wx.aui |
| 28 | 34 | from wx.lib.pubsub import pub as Publisher |
| 29 | 35 | import wx.lib.agw.toasterbox as TB |
| ... | ... | @@ -386,6 +392,7 @@ class Frame(wx.Frame): |
| 386 | 392 | s = ses.Session() |
| 387 | 393 | if not s.IsOpen() or not s.project_path: |
| 388 | 394 | Publisher.sendMessage('Exit') |
| 395 | + self.aui_manager.UnInit() | |
| 389 | 396 | |
| 390 | 397 | def OnMenuClick(self, evt): |
| 391 | 398 | """ |
| ... | ... | @@ -1127,7 +1134,7 @@ class StatusBar(wx.StatusBar): |
| 1127 | 1134 | # ------------------------------------------------------------------ |
| 1128 | 1135 | # ------------------------------------------------------------------ |
| 1129 | 1136 | |
| 1130 | -class TaskBarIcon(wx.TaskBarIcon): | |
| 1137 | +class TaskBarIcon(wx_TaskBarIcon): | |
| 1131 | 1138 | """ |
| 1132 | 1139 | TaskBarIcon has different behaviours according to the platform: |
| 1133 | 1140 | - win32: Show icon on "Notification Area" (near clock) |
| ... | ... | @@ -1135,7 +1142,7 @@ class TaskBarIcon(wx.TaskBarIcon): |
| 1135 | 1142 | - linux2: Show icon on "Notification Area" (near clock) |
| 1136 | 1143 | """ |
| 1137 | 1144 | def __init__(self, parent=None): |
| 1138 | - wx.TaskBarIcon.__init__(self) | |
| 1145 | + wx_TaskBarIcon.__init__(self) | |
| 1139 | 1146 | self.frame = parent |
| 1140 | 1147 | |
| 1141 | 1148 | icon = wx.Icon(os.path.join(const.ICON_DIR, "invesalius.ico"), | ... | ... |
invesalius/gui/import_bitmap_panel.py
| ... | ... | @@ -101,7 +101,7 @@ class InnerPanel(wx.Panel): |
| 101 | 101 | self.combo_interval.SetSelection(0) |
| 102 | 102 | |
| 103 | 103 | inner_sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 104 | - inner_sizer.AddSizer(btnsizer, 0, wx.LEFT|wx.TOP, 5) | |
| 104 | + inner_sizer.Add(btnsizer, 0, wx.LEFT|wx.TOP, 5) | |
| 105 | 105 | inner_sizer.Add(self.combo_interval, 0, wx.LEFT|wx.RIGHT|wx.TOP, 5) |
| 106 | 106 | panel.SetSizer(inner_sizer) |
| 107 | 107 | inner_sizer.Fit(panel) |
| ... | ... | @@ -192,7 +192,7 @@ class TextPanel(wx.Panel): |
| 192 | 192 | wx.TR_DEFAULT_STYLE |
| 193 | 193 | | wx.TR_HIDE_ROOT |
| 194 | 194 | | wx.TR_ROW_LINES |
| 195 | - | wx.TR_COLUMN_LINES | |
| 195 | + # | wx.TR_COLUMN_LINES | |
| 196 | 196 | | wx.TR_FULL_ROW_HIGHLIGHT |
| 197 | 197 | | wx.TR_MULTIPLE |
| 198 | 198 | | wx.TR_HIDE_ROOT |
| ... | ... | @@ -308,7 +308,8 @@ class ImagePanel(wx.Panel): |
| 308 | 308 | splitter.SetOrientation(wx.HORIZONTAL) |
| 309 | 309 | self.splitter = splitter |
| 310 | 310 | |
| 311 | - splitter.ContainingSizer = wx.BoxSizer(wx.HORIZONTAL) | |
| 311 | + # TODO: Rever isso | |
| 312 | + # splitter.ContainingSizer = wx.BoxSizer(wx.HORIZONTAL) | |
| 312 | 313 | |
| 313 | 314 | sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 314 | 315 | sizer.Add(splitter, 1, wx.EXPAND) | ... | ... |
invesalius/gui/import_network_panel.py
| ... | ... | @@ -110,7 +110,7 @@ class InnerPanel(wx.Panel): |
| 110 | 110 | self.combo_interval.SetSelection(0) |
| 111 | 111 | |
| 112 | 112 | inner_sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 113 | - inner_sizer.AddSizer(btnsizer, 0, wx.LEFT|wx.TOP, 5) | |
| 113 | + inner_sizer.Add(btnsizer, 0, wx.LEFT|wx.TOP, 5) | |
| 114 | 114 | inner_sizer.Add(self.combo_interval, 0, wx.LEFT|wx.RIGHT|wx.TOP, 5) |
| 115 | 115 | panel.SetSizer(inner_sizer) |
| 116 | 116 | inner_sizer.Fit(panel) |
| ... | ... | @@ -230,7 +230,7 @@ class TextPanel(wx.Panel): |
| 230 | 230 | wx.TR_DEFAULT_STYLE |
| 231 | 231 | | wx.TR_HIDE_ROOT |
| 232 | 232 | | wx.TR_ROW_LINES |
| 233 | - | wx.TR_COLUMN_LINES | |
| 233 | + # | wx.TR_COLUMN_LINES | |
| 234 | 234 | | wx.TR_FULL_ROW_HIGHLIGHT |
| 235 | 235 | | wx.TR_SINGLE |
| 236 | 236 | ) |
| ... | ... | @@ -507,8 +507,8 @@ class FindPanel(wx.Panel): |
| 507 | 507 | sizer_txt_find.Add(self.btn_find) |
| 508 | 508 | |
| 509 | 509 | self.sizer.Add((0, 5), 0, wx.EXPAND|wx.HORIZONTAL) |
| 510 | - self.sizer.AddSizer(sizer_word_label) | |
| 511 | - self.sizer.AddSizer(sizer_txt_find) | |
| 510 | + self.sizer.Add(sizer_word_label) | |
| 511 | + self.sizer.Add(sizer_txt_find) | |
| 512 | 512 | |
| 513 | 513 | #self.sizer.Add(self.serie_preview, 1, wx.EXPAND | wx.ALL, 5) |
| 514 | 514 | #self.sizer.Add(self.dicom_preview, 1, wx.EXPAND | wx.ALL, 5) |
| ... | ... | @@ -568,7 +568,8 @@ class HostFindPanel(wx.Panel): |
| 568 | 568 | splitter.SetOrientation(wx.HORIZONTAL) |
| 569 | 569 | self.splitter = splitter |
| 570 | 570 | |
| 571 | - splitter.ContainingSizer = wx.BoxSizer(wx.HORIZONTAL) | |
| 571 | + # TODO: Rever isso | |
| 572 | + # splitter.ContainingSizer = wx.BoxSizer(wx.HORIZONTAL) | |
| 572 | 573 | |
| 573 | 574 | sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 574 | 575 | sizer.Add(splitter, 1, wx.EXPAND) |
| ... | ... | @@ -673,7 +674,7 @@ class NodesPanel(wx.Panel): |
| 673 | 674 | self.tree_node.SetColumnWidth(4, 80) |
| 674 | 675 | |
| 675 | 676 | self.hosts[0] = [True, "localhost", "", "invesalius"] |
| 676 | - index = self.tree_node.InsertStringItem(sys.maxint, "") | |
| 677 | + index = self.tree_node.InsertStringItem(sys.maxsize, "") | |
| 677 | 678 | self.tree_node.SetStringItem(index, 1, "localhost") |
| 678 | 679 | self.tree_node.SetStringItem(index, 2, "") |
| 679 | 680 | self.tree_node.SetStringItem(index, 3, "invesalius") |
| ... | ... | @@ -704,7 +705,7 @@ class NodesPanel(wx.Panel): |
| 704 | 705 | |
| 705 | 706 | sizer = wx.BoxSizer(wx.VERTICAL) |
| 706 | 707 | sizer.Add(self.tree_node, 85, wx.GROW|wx.EXPAND) |
| 707 | - sizer.AddSizer(sizer_btn, 15) | |
| 708 | + sizer.Add(sizer_btn, 15) | |
| 708 | 709 | sizer.Fit(self) |
| 709 | 710 | self.SetSizer(sizer) |
| 710 | 711 | self.Layout() |
| ... | ... | @@ -728,7 +729,7 @@ class NodesPanel(wx.Panel): |
| 728 | 729 | |
| 729 | 730 | def OnButtonAdd(self, evt): |
| 730 | 731 | #adiciona vazio a coluna de check |
| 731 | - index = self.tree_node.InsertStringItem(sys.maxint, "") | |
| 732 | + index = self.tree_node.InsertStringItem(sys.maxsize, "") | |
| 732 | 733 | |
| 733 | 734 | self.hosts[index] = [True, "localhost", "80", ""] |
| 734 | 735 | self.tree_node.SetStringItem(index, 1, "localhost") | ... | ... |
invesalius/gui/import_panel.py
| ... | ... | @@ -103,7 +103,7 @@ class InnerPanel(wx.Panel): |
| 103 | 103 | self.combo_interval.SetSelection(0) |
| 104 | 104 | |
| 105 | 105 | inner_sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 106 | - inner_sizer.AddSizer(btnsizer, 0, wx.LEFT|wx.TOP, 5) | |
| 106 | + inner_sizer.Add(btnsizer, 0, wx.LEFT|wx.TOP, 5) | |
| 107 | 107 | inner_sizer.Add(self.combo_interval, 0, wx.LEFT|wx.RIGHT|wx.TOP, 5) |
| 108 | 108 | panel.SetSizer(inner_sizer) |
| 109 | 109 | inner_sizer.Fit(panel) |
| ... | ... | @@ -215,7 +215,7 @@ class TextPanel(wx.Panel): |
| 215 | 215 | wx.TR_DEFAULT_STYLE |
| 216 | 216 | | wx.TR_HIDE_ROOT |
| 217 | 217 | | wx.TR_ROW_LINES |
| 218 | - | wx.TR_COLUMN_LINES | |
| 218 | + # | wx.TR_COLUMN_LINES | |
| 219 | 219 | | wx.TR_FULL_ROW_HIGHLIGHT |
| 220 | 220 | | wx.TR_SINGLE |
| 221 | 221 | ) |
| ... | ... | @@ -362,7 +362,8 @@ class ImagePanel(wx.Panel): |
| 362 | 362 | splitter.SetOrientation(wx.HORIZONTAL) |
| 363 | 363 | self.splitter = splitter |
| 364 | 364 | |
| 365 | - splitter.ContainingSizer = wx.BoxSizer(wx.HORIZONTAL) | |
| 365 | + # TODO Rever isso | |
| 366 | + # splitter.ContainingSizer = wx.BoxSizer(wx.HORIZONTAL) | |
| 366 | 367 | |
| 367 | 368 | sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 368 | 369 | sizer.Add(splitter, 1, wx.EXPAND) | ... | ... |
invesalius/gui/language_dialog.py
| ... | ... | @@ -20,7 +20,10 @@ |
| 20 | 20 | import os |
| 21 | 21 | import sys |
| 22 | 22 | import wx |
| 23 | -import wx.combo | |
| 23 | +try: | |
| 24 | + from wx.adv import BitmapComboBox | |
| 25 | +except ImportError: | |
| 26 | + from wx.combo import BitmapComboBox | |
| 24 | 27 | |
| 25 | 28 | import invesalius.i18n as i18n |
| 26 | 29 | |
| ... | ... | @@ -48,7 +51,7 @@ class ComboBoxLanguage: |
| 48 | 51 | |
| 49 | 52 | # Retrieve locales names and sort them |
| 50 | 53 | self.locales = dict_locales.values() |
| 51 | - self.locales.sort() | |
| 54 | + self.locales = sorted(self.locales) | |
| 52 | 55 | |
| 53 | 56 | # Retrieve locales keys (eg: pt_BR for Portuguese(Brazilian)) |
| 54 | 57 | self.locales_key = [dict_locales.get_key(value)[0] for value in self.locales] |
| ... | ... | @@ -65,7 +68,7 @@ class ComboBoxLanguage: |
| 65 | 68 | selection = self.locales_key.index('en') |
| 66 | 69 | |
| 67 | 70 | # Create bitmap combo |
| 68 | - self.bitmapCmb = bitmapCmb = wx.combo.BitmapComboBox(parent, style=wx.CB_READONLY) | |
| 71 | + self.bitmapCmb = bitmapCmb = BitmapComboBox(parent, style=wx.CB_READONLY) | |
| 69 | 72 | for key in self.locales_key: |
| 70 | 73 | # Based on composed flag filename, get bitmap |
| 71 | 74 | filepath = os.path.join(ICON_DIR, "%s.bmp"%(key)) |
| ... | ... | @@ -117,7 +120,7 @@ class LanguageDialog(wx.Dialog): |
| 117 | 120 | # selection = self.locales_key.index('en') |
| 118 | 121 | |
| 119 | 122 | # # Create bitmap combo |
| 120 | - # self.bitmapCmb = bitmapCmb = wx.combo.BitmapComboBox(self, style=wx.CB_READONLY) | |
| 123 | + # self.bitmapCmb = bitmapCmb = BitmapComboBox(self, style=wx.CB_READONLY) | |
| 121 | 124 | # for key in self.locales_key: |
| 122 | 125 | # # Based on composed flag filename, get bitmap |
| 123 | 126 | # filepath = os.path.join(ICON_DIR, "%s.bmp"%(key)) | ... | ... |
invesalius/gui/preferences.py
| ... | ... | @@ -17,11 +17,15 @@ class Preferences(wx.Dialog): |
| 17 | 17 | def __init__( self, parent, id = ID, title = _("Preferences"), size=wx.DefaultSize,\ |
| 18 | 18 | pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE): |
| 19 | 19 | |
| 20 | - pre = wx.PreDialog() | |
| 21 | - pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) | |
| 22 | - pre.Create(parent, ID, title, pos, size, style) | |
| 20 | + try: | |
| 21 | + pre = wx.PreDialog() | |
| 22 | + pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) | |
| 23 | + pre.Create(parent, ID, title, pos, size, style) | |
| 23 | 24 | |
| 24 | - self.PostCreate(pre) | |
| 25 | + self.PostCreate(pre) | |
| 26 | + except AttributeError: | |
| 27 | + wx.Dialog.__init__(self, parent, ID, title, pos, size, style) | |
| 28 | + self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) | |
| 25 | 29 | |
| 26 | 30 | sizer = wx.BoxSizer(wx.VERTICAL) |
| 27 | 31 | |
| ... | ... | @@ -55,7 +59,7 @@ class Preferences(wx.Dialog): |
| 55 | 59 | |
| 56 | 60 | btnsizer.Realize() |
| 57 | 61 | |
| 58 | - sizer.AddSizer(btnsizer, 10, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP|wx.BOTTOM, 5) | |
| 62 | + sizer.Add(btnsizer, 10, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP|wx.BOTTOM, 5) | |
| 59 | 63 | |
| 60 | 64 | self.SetSizer(sizer) |
| 61 | 65 | sizer.Fit(self) | ... | ... |
invesalius/gui/task_exporter.py
| ... | ... | @@ -21,7 +21,12 @@ import os |
| 21 | 21 | import sys |
| 22 | 22 | |
| 23 | 23 | import wx |
| 24 | -import wx.lib.hyperlink as hl | |
| 24 | + | |
| 25 | +try: | |
| 26 | + import wx.lib.agw.hyperlink as hl | |
| 27 | +except ImportError: | |
| 28 | + import wx.lib.hyperlink as hl | |
| 29 | + | |
| 25 | 30 | import wx.lib.platebtn as pbtn |
| 26 | 31 | from wx.lib.pubsub import pub as Publisher |
| 27 | 32 | ... | ... |
invesalius/gui/task_importer.py
| ... | ... | @@ -20,8 +20,12 @@ import os |
| 20 | 20 | import sys |
| 21 | 21 | |
| 22 | 22 | import wx |
| 23 | -import wx.lib.hyperlink as hl | |
| 23 | +try: | |
| 24 | + import wx.lib.agw.hyperlink as hl | |
| 25 | +except ImportError: | |
| 26 | + import wx.lib.hyperlink as hl | |
| 24 | 27 | import wx.lib.platebtn as pbtn |
| 28 | + | |
| 25 | 29 | from wx.lib.pubsub import pub as Publisher |
| 26 | 30 | |
| 27 | 31 | import invesalius.constants as const |
| ... | ... | @@ -222,7 +226,7 @@ class InnerTaskPanel(wx.Panel): |
| 222 | 226 | |
| 223 | 227 | |
| 224 | 228 | def ImportPACS(self): |
| 225 | - print "TODO: Send Signal - Import DICOM files from PACS" | |
| 229 | + print("TODO: Send Signal - Import DICOM files from PACS") | |
| 226 | 230 | |
| 227 | 231 | |
| 228 | 232 | ####### |
| ... | ... | @@ -264,7 +268,7 @@ class InnerTaskPanel(wx.Panel): |
| 264 | 268 | """ |
| 265 | 269 | |
| 266 | 270 | # Remove each project from sizer |
| 267 | - for i in xrange(0, self.proj_count): | |
| 271 | + for i in range(0, self.proj_count): | |
| 268 | 272 | self.sizer.Remove(self.float_hyper_list[i]) |
| 269 | 273 | |
| 270 | 274 | # Delete hyperlinks | ... | ... |
invesalius/gui/task_navigator.py
| ... | ... | @@ -23,9 +23,15 @@ import os |
| 23 | 23 | |
| 24 | 24 | import numpy as np |
| 25 | 25 | import wx |
| 26 | -import wx.lib.hyperlink as hl | |
| 26 | + | |
| 27 | +try: | |
| 28 | + import wx.lib.agw.hyperlink as hl | |
| 29 | + import wx.lib.agw.foldpanelbar as fpb | |
| 30 | +except ImportError: | |
| 31 | + import wx.lib.hyperlink as hl | |
| 32 | + import wx.lib.foldpanelbar as fpb | |
| 33 | + | |
| 27 | 34 | import wx.lib.masked.numctrl |
| 28 | -import wx.lib.foldpanelbar as fpb | |
| 29 | 35 | from wx.lib.pubsub import pub as Publisher |
| 30 | 36 | import wx.lib.colourselect as csel |
| 31 | 37 | import wx.lib.platebtn as pbtn |
| ... | ... | @@ -42,6 +48,7 @@ import invesalius.data.trackers as dt |
| 42 | 48 | import invesalius.data.trigger as trig |
| 43 | 49 | import invesalius.data.record_coords as rec |
| 44 | 50 | import invesalius.gui.dialogs as dlg |
| 51 | +from invesalius import utils | |
| 45 | 52 | |
| 46 | 53 | BTN_NEW = wx.NewId() |
| 47 | 54 | BTN_IMPORT_LOCAL = wx.NewId() |
| ... | ... | @@ -114,7 +121,10 @@ class FoldPanel(wx.Panel): |
| 114 | 121 | class InnerFoldPanel(wx.Panel): |
| 115 | 122 | def __init__(self, parent): |
| 116 | 123 | wx.Panel.__init__(self, parent) |
| 117 | - default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 124 | + try: | |
| 125 | + default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 126 | + except AttributeError: | |
| 127 | + default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 118 | 128 | self.SetBackgroundColour(default_colour) |
| 119 | 129 | |
| 120 | 130 | self.__bind_events() |
| ... | ... | @@ -253,7 +263,10 @@ class InnerFoldPanel(wx.Panel): |
| 253 | 263 | class NeuronavigationPanel(wx.Panel): |
| 254 | 264 | def __init__(self, parent): |
| 255 | 265 | wx.Panel.__init__(self, parent) |
| 256 | - default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 266 | + try: | |
| 267 | + default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 268 | + except AttributeError: | |
| 269 | + default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 257 | 270 | self.SetBackgroundColour(default_colour) |
| 258 | 271 | |
| 259 | 272 | self.SetAutoLayout(1) |
| ... | ... | @@ -300,8 +313,8 @@ class NeuronavigationPanel(wx.Panel): |
| 300 | 313 | tips_img = const.TIPS_IMG |
| 301 | 314 | |
| 302 | 315 | for k in btns_img: |
| 303 | - n = btns_img[k].keys()[0] | |
| 304 | - lab = btns_img[k].values()[0] | |
| 316 | + n = list(btns_img[k].keys())[0] | |
| 317 | + lab = list(btns_img[k].values())[0] | |
| 305 | 318 | self.btns_coord[n] = wx.ToggleButton(self, k, label=lab, size=wx.Size(45, 23)) |
| 306 | 319 | self.btns_coord[n].SetToolTip(wx.ToolTip(tips_img[n])) |
| 307 | 320 | self.btns_coord[n].Bind(wx.EVT_TOGGLEBUTTON, self.OnImageFiducials) |
| ... | ... | @@ -311,8 +324,8 @@ class NeuronavigationPanel(wx.Panel): |
| 311 | 324 | tips_trk = const.TIPS_TRK |
| 312 | 325 | |
| 313 | 326 | for k in btns_trk: |
| 314 | - n = btns_trk[k].keys()[0] | |
| 315 | - lab = btns_trk[k].values()[0] | |
| 327 | + n = list(btns_trk[k].keys())[0] | |
| 328 | + lab = list(btns_trk[k].values())[0] | |
| 316 | 329 | self.btns_coord[n] = wx.Button(self, k, label=lab, size=wx.Size(45, 23)) |
| 317 | 330 | self.btns_coord[n].SetToolTip(wx.ToolTip(tips_trk[n-3])) |
| 318 | 331 | # Exception for event of button that set image coordinates |
| ... | ... | @@ -393,8 +406,8 @@ class NeuronavigationPanel(wx.Panel): |
| 393 | 406 | marker_id = pubsub_evt.data[0] |
| 394 | 407 | coord = pubsub_evt.data[1] |
| 395 | 408 | for n in const.BTNS_IMG_MKS: |
| 396 | - btn_id = const.BTNS_IMG_MKS[n].keys()[0] | |
| 397 | - fid_id = const.BTNS_IMG_MKS[n].values()[0] | |
| 409 | + btn_id = list(const.BTNS_IMG_MKS[n].keys())[0] | |
| 410 | + fid_id = list(const.BTNS_IMG_MKS[n].values())[0] | |
| 398 | 411 | if marker_id == fid_id and not self.btns_coord[btn_id].GetValue(): |
| 399 | 412 | self.btns_coord[btn_id].SetValue(True) |
| 400 | 413 | self.fiducials[btn_id, :] = coord[0:3] |
| ... | ... | @@ -461,11 +474,11 @@ class NeuronavigationPanel(wx.Panel): |
| 461 | 474 | if not self.trk_init[0]: |
| 462 | 475 | dlg.NavigationTrackerWarning(self.tracker_id, self.trk_init[1]) |
| 463 | 476 | ctrl.SetSelection(0) |
| 464 | - print "Tracker not connected!" | |
| 477 | + print("Tracker not connected!") | |
| 465 | 478 | else: |
| 466 | 479 | Publisher.sendMessage('Update status text in GUI', _("Ready")) |
| 467 | 480 | ctrl.SetSelection(self.tracker_id) |
| 468 | - print "Tracker connected!" | |
| 481 | + print("Tracker connected!") | |
| 469 | 482 | elif choice == 6: |
| 470 | 483 | if trck: |
| 471 | 484 | Publisher.sendMessage('Update status text in GUI', _("Disconnecting tracker ...")) |
| ... | ... | @@ -477,10 +490,10 @@ class NeuronavigationPanel(wx.Panel): |
| 477 | 490 | self.tracker_id = 0 |
| 478 | 491 | ctrl.SetSelection(self.tracker_id) |
| 479 | 492 | Publisher.sendMessage('Update status text in GUI', _("Tracker disconnected")) |
| 480 | - print "Tracker disconnected!" | |
| 493 | + print("Tracker disconnected!") | |
| 481 | 494 | else: |
| 482 | 495 | Publisher.sendMessage('Update status text in GUI', _("Tracker still connected")) |
| 483 | - print "Tracker still connected!" | |
| 496 | + print("Tracker still connected!") | |
| 484 | 497 | else: |
| 485 | 498 | ctrl.SetSelection(self.tracker_id) |
| 486 | 499 | |
| ... | ... | @@ -506,11 +519,11 @@ class NeuronavigationPanel(wx.Panel): |
| 506 | 519 | # TODO: Improve the restarting of trackers after changing reference mode |
| 507 | 520 | # self.OnChoiceTracker(None, ctrl) |
| 508 | 521 | Publisher.sendMessage('Update tracker initializer', (self.tracker_id, self.trk_init, self.ref_mode_id)) |
| 509 | - print "Reference mode changed!" | |
| 522 | + print("Reference mode changed!") | |
| 510 | 523 | |
| 511 | 524 | def OnSetImageCoordinates(self, evt): |
| 512 | 525 | # FIXME: Cross does not update in last clicked slice, only on the other two |
| 513 | - btn_id = const.BTNS_TRK[evt.GetId()].keys()[0] | |
| 526 | + btn_id = list(const.BTNS_TRK[evt.GetId()].keys())[0] | |
| 514 | 527 | |
| 515 | 528 | ux, uy, uz = self.numctrls_coord[btn_id][0].GetValue(),\ |
| 516 | 529 | self.numctrls_coord[btn_id][1].GetValue(),\ |
| ... | ... | @@ -518,12 +531,12 @@ class NeuronavigationPanel(wx.Panel): |
| 518 | 531 | |
| 519 | 532 | Publisher.sendMessage('Set ball reference position', (ux, uy, uz)) |
| 520 | 533 | # Publisher.sendMessage('Set camera in volume', (ux, uy, uz)) |
| 521 | - Publisher.sendMessage('Co-registered points', (ux, uy, uz, 0., 0., 0.)) | |
| 534 | + Publisher.sendMessage('Co-registered points', ((ux, uy, uz), (0., 0., 0.))) | |
| 522 | 535 | Publisher.sendMessage('Update cross position', (ux, uy, uz)) |
| 523 | 536 | |
| 524 | 537 | def OnImageFiducials(self, evt): |
| 525 | - btn_id = const.BTNS_IMG_MKS[evt.GetId()].keys()[0] | |
| 526 | - marker_id = const.BTNS_IMG_MKS[evt.GetId()].values()[0] | |
| 538 | + btn_id = list(const.BTNS_IMG_MKS[evt.GetId()].keys())[0] | |
| 539 | + marker_id = list(const.BTNS_IMG_MKS[evt.GetId()].values())[0] | |
| 527 | 540 | |
| 528 | 541 | if self.btns_coord[btn_id].GetValue(): |
| 529 | 542 | coord = self.numctrls_coord[btn_id][0].GetValue(),\ |
| ... | ... | @@ -540,7 +553,7 @@ class NeuronavigationPanel(wx.Panel): |
| 540 | 553 | Publisher.sendMessage('Delete fiducial marker', marker_id) |
| 541 | 554 | |
| 542 | 555 | def OnTrackerFiducials(self, evt): |
| 543 | - btn_id = const.BTNS_TRK[evt.GetId()].keys()[0] | |
| 556 | + btn_id = list(const.BTNS_TRK[evt.GetId()].keys())[0] | |
| 544 | 557 | coord = None |
| 545 | 558 | |
| 546 | 559 | if self.trk_init and self.tracker_id: |
| ... | ... | @@ -704,7 +717,10 @@ class NeuronavigationPanel(wx.Panel): |
| 704 | 717 | class ObjectRegistrationPanel(wx.Panel): |
| 705 | 718 | def __init__(self, parent): |
| 706 | 719 | wx.Panel.__init__(self, parent) |
| 707 | - default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 720 | + try: | |
| 721 | + default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 722 | + except AttributeError: | |
| 723 | + default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 708 | 724 | self.SetBackgroundColour(default_colour) |
| 709 | 725 | |
| 710 | 726 | self.coil_list = const.COIL |
| ... | ... | @@ -917,7 +933,7 @@ class ObjectRegistrationPanel(wx.Panel): |
| 917 | 933 | else: |
| 918 | 934 | filename = dlg.ShowSaveRegistrationDialog("object_registration.obr") |
| 919 | 935 | if filename: |
| 920 | - hdr = 'Object' + "\t" + self.obj_name + "\t" + 'Reference' + "\t" + str('%d' % self.obj_ref_mode) | |
| 936 | + hdr = 'Object' + "\t" + utils.decode(self.obj_name, const.FS_ENCODE) + "\t" + 'Reference' + "\t" + str('%d' % self.obj_ref_mode) | |
| 921 | 937 | data = np.hstack([self.obj_fiducials, self.obj_orients]) |
| 922 | 938 | np.savetxt(filename, data, fmt='%.4f', delimiter='\t', newline='\n', header=hdr) |
| 923 | 939 | wx.MessageBox(_("Object file successfully saved"), _("Save")) |
| ... | ... | @@ -939,7 +955,10 @@ class ObjectRegistrationPanel(wx.Panel): |
| 939 | 955 | class MarkersPanel(wx.Panel): |
| 940 | 956 | def __init__(self, parent): |
| 941 | 957 | wx.Panel.__init__(self, parent) |
| 942 | - default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 958 | + try: | |
| 959 | + default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 960 | + except AttributeError: | |
| 961 | + default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 943 | 962 | self.SetBackgroundColour(default_colour) |
| 944 | 963 | |
| 945 | 964 | self.SetAutoLayout(1) |
| ... | ... | @@ -1137,7 +1156,7 @@ class MarkersPanel(wx.Panel): |
| 1137 | 1156 | item = self.lc.GetItem(id_n, 4) |
| 1138 | 1157 | if item.GetText() == marker_id: |
| 1139 | 1158 | for i in const.BTNS_IMG_MKS: |
| 1140 | - if marker_id in const.BTNS_IMG_MKS[i].values()[0]: | |
| 1159 | + if marker_id in list(const.BTNS_IMG_MKS[i].values())[0]: | |
| 1141 | 1160 | self.lc.Focus(item.GetId()) |
| 1142 | 1161 | index = [self.lc.GetFocusedItem()] |
| 1143 | 1162 | else: |
| ... | ... | @@ -1192,7 +1211,7 @@ class MarkersPanel(wx.Panel): |
| 1192 | 1211 | |
| 1193 | 1212 | if len(line) == 11: |
| 1194 | 1213 | for i in const.BTNS_IMG_MKS: |
| 1195 | - if line[10] in const.BTNS_IMG_MKS[i].values()[0]: | |
| 1214 | + if line[10] in list(const.BTNS_IMG_MKS[i].values())[0]: | |
| 1196 | 1215 | Publisher.sendMessage('Load image fiducials', (line[10], coord)) |
| 1197 | 1216 | elif line[10] == 'TARGET': |
| 1198 | 1217 | target = count_line |
| ... | ... | @@ -1210,7 +1229,7 @@ class MarkersPanel(wx.Panel): |
| 1210 | 1229 | |
| 1211 | 1230 | if len(line) == 8: |
| 1212 | 1231 | for i in const.BTNS_IMG_MKS: |
| 1213 | - if line[7] in const.BTNS_IMG_MKS[i].values()[0]: | |
| 1232 | + if line[7] in list(const.BTNS_IMG_MKS[i].values())[0]: | |
| 1214 | 1233 | Publisher.sendMessage('Load image fiducials', (line[7], coord)) |
| 1215 | 1234 | else: |
| 1216 | 1235 | line.append("") | ... | ... |
invesalius/gui/task_slice.py
| ... | ... | @@ -21,9 +21,15 @@ import sys |
| 21 | 21 | import os |
| 22 | 22 | |
| 23 | 23 | import wx |
| 24 | -import wx.lib.hyperlink as hl | |
| 24 | + | |
| 25 | +try: | |
| 26 | + import wx.lib.agw.hyperlink as hl | |
| 27 | + import wx.lib.agw.foldpanelbar as fpb | |
| 28 | +except ImportError: | |
| 29 | + import wx.lib.hyperlink as hl | |
| 30 | + import wx.lib.foldpanelbar as fpb | |
| 31 | + | |
| 25 | 32 | import wx.lib.platebtn as pbtn |
| 26 | -import wx.lib.foldpanelbar as fpb | |
| 27 | 33 | import wx.lib.colourselect as csel |
| 28 | 34 | from wx.lib.pubsub import pub as Publisher |
| 29 | 35 | |
| ... | ... | @@ -110,7 +116,10 @@ class InnerTaskPanel(wx.Panel): |
| 110 | 116 | #print wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) |
| 111 | 117 | #print wx.SystemSettings_GetColour(wx.SYS_COLOUR_SCROLLBAR) |
| 112 | 118 | #print wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUHILIGHT) |
| 113 | - default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 119 | + try: | |
| 120 | + default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 121 | + except AttributeError: | |
| 122 | + default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 114 | 123 | fold_panel = FoldPanel(self) |
| 115 | 124 | fold_panel.SetBackgroundColour(default_colour) |
| 116 | 125 | self.fold_panel = fold_panel |
| ... | ... | @@ -136,7 +145,7 @@ class InnerTaskPanel(wx.Panel): |
| 136 | 145 | main_sizer = wx.BoxSizer(wx.VERTICAL) |
| 137 | 146 | main_sizer.Add(line_new, 0,wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) |
| 138 | 147 | main_sizer.Add(fold_panel, 1, wx.GROW|wx.EXPAND|wx.ALL, 5) |
| 139 | - main_sizer.AddSizer(line_sizer, 0, wx.GROW|wx.EXPAND) | |
| 148 | + main_sizer.Add(line_sizer, 0, wx.GROW|wx.EXPAND) | |
| 140 | 149 | main_sizer.AddSpacer(5) |
| 141 | 150 | main_sizer.Fit(self) |
| 142 | 151 | |
| ... | ... | @@ -238,7 +247,10 @@ class FoldPanel(wx.Panel): |
| 238 | 247 | class InnerFoldPanel(wx.Panel): |
| 239 | 248 | def __init__(self, parent): |
| 240 | 249 | wx.Panel.__init__(self, parent) |
| 241 | - default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 250 | + try: | |
| 251 | + default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 252 | + except AttributeError: | |
| 253 | + default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 242 | 254 | self.SetBackgroundColour(default_colour) |
| 243 | 255 | |
| 244 | 256 | # Fold panel and its style settings |
| ... | ... | @@ -508,10 +520,10 @@ class MaskProperties(wx.Panel): |
| 508 | 520 | |
| 509 | 521 | def CloseProject(self): |
| 510 | 522 | n = self.combo_mask_name.GetCount() |
| 511 | - for i in xrange(n-1, -1, -1): | |
| 523 | + for i in range(n-1, -1, -1): | |
| 512 | 524 | self.combo_mask_name.Delete(i) |
| 513 | 525 | n = self.combo_thresh.GetCount() |
| 514 | - for i in xrange(n-1, -1, -1): | |
| 526 | + for i in range(n-1, -1, -1): | |
| 515 | 527 | self.combo_thresh.Delete(i) |
| 516 | 528 | |
| 517 | 529 | def OnRemoveMasks(self, pubsub_evt): |
| ... | ... | @@ -659,14 +671,17 @@ class MaskProperties(wx.Panel): |
| 659 | 671 | session.ChangeProject() |
| 660 | 672 | |
| 661 | 673 | def OnSelectColour(self, evt): |
| 662 | - colour = evt.GetValue() | |
| 674 | + colour = evt.GetValue()[:3] | |
| 663 | 675 | self.gradient.SetColour(colour) |
| 664 | 676 | Publisher.sendMessage('Change mask colour', colour) |
| 665 | 677 | |
| 666 | 678 | class EditionTools(wx.Panel): |
| 667 | 679 | def __init__(self, parent): |
| 668 | 680 | wx.Panel.__init__(self, parent) |
| 669 | - default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 681 | + try: | |
| 682 | + default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 683 | + except AttributeError: | |
| 684 | + default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 670 | 685 | self.SetBackgroundColour(default_colour) |
| 671 | 686 | |
| 672 | 687 | ## LINE 1 |
| ... | ... | @@ -830,7 +845,10 @@ class EditionTools(wx.Panel): |
| 830 | 845 | class WatershedTool(EditionTools): |
| 831 | 846 | def __init__(self, parent): |
| 832 | 847 | wx.Panel.__init__(self, parent) |
| 833 | - default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 848 | + try: | |
| 849 | + default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 850 | + except AttributeError: | |
| 851 | + default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 834 | 852 | self.SetBackgroundColour(default_colour) |
| 835 | 853 | |
| 836 | 854 | ## LINE 1 | ... | ... |
invesalius/gui/task_surface.py
| ... | ... | @@ -20,9 +20,15 @@ import sys |
| 20 | 20 | import os |
| 21 | 21 | |
| 22 | 22 | import wx |
| 23 | -import wx.lib.hyperlink as hl | |
| 23 | + | |
| 24 | +try: | |
| 25 | + import wx.lib.agw.hyperlink as hl | |
| 26 | + import wx.lib.agw.foldpanelbar as fpb | |
| 27 | +except ImportError: | |
| 28 | + import wx.lib.hyperlink as hl | |
| 29 | + import wx.lib.foldpanelbar as fpb | |
| 30 | + | |
| 24 | 31 | from wx.lib.pubsub import pub as Publisher |
| 25 | -import wx.lib.foldpanelbar as fpb | |
| 26 | 32 | import wx.lib.colourselect as csel |
| 27 | 33 | |
| 28 | 34 | import invesalius.constants as const |
| ... | ... | @@ -211,7 +217,10 @@ class FoldPanel(wx.Panel): |
| 211 | 217 | class InnerFoldPanel(wx.Panel): |
| 212 | 218 | def __init__(self, parent): |
| 213 | 219 | wx.Panel.__init__(self, parent) |
| 214 | - default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 220 | + try: | |
| 221 | + default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 222 | + except AttributeError: | |
| 223 | + default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 215 | 224 | self.SetBackgroundColour(default_colour) |
| 216 | 225 | |
| 217 | 226 | # Fold panel and its style settings |
| ... | ... | @@ -280,7 +289,10 @@ BTN_SEEDS = wx.NewId() |
| 280 | 289 | class SurfaceTools(wx.Panel): |
| 281 | 290 | def __init__(self, parent): |
| 282 | 291 | wx.Panel.__init__(self, parent) |
| 283 | - default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 292 | + try: | |
| 293 | + default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 294 | + except AttributeError: | |
| 295 | + default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 284 | 296 | self.SetBackgroundColour(default_colour) |
| 285 | 297 | |
| 286 | 298 | #self.SetBackgroundColour(wx.Colour(255,255,255)) |
| ... | ... | @@ -411,12 +423,12 @@ class SurfaceTools(wx.Panel): |
| 411 | 423 | self.EndSeeding() |
| 412 | 424 | |
| 413 | 425 | def StartSeeding(self): |
| 414 | - print "Start Seeding" | |
| 426 | + print("Start Seeding") | |
| 415 | 427 | Publisher.sendMessage('Enable style', const.VOLUME_STATE_SEED) |
| 416 | 428 | Publisher.sendMessage('Create surface by seeding - start') |
| 417 | 429 | |
| 418 | 430 | def EndSeeding(self): |
| 419 | - print "End Seeding" | |
| 431 | + print("End Seeding") | |
| 420 | 432 | Publisher.sendMessage('Disable style', const.VOLUME_STATE_SEED) |
| 421 | 433 | Publisher.sendMessage('Create surface by seeding - end') |
| 422 | 434 | |
| ... | ... | @@ -425,7 +437,10 @@ class SurfaceTools(wx.Panel): |
| 425 | 437 | class SurfaceProperties(wx.Panel): |
| 426 | 438 | def __init__(self, parent): |
| 427 | 439 | wx.Panel.__init__(self, parent) |
| 428 | - default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 440 | + try: | |
| 441 | + default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 442 | + except AttributeError: | |
| 443 | + default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 429 | 444 | self.SetBackgroundColour(default_colour) |
| 430 | 445 | |
| 431 | 446 | self.surface_list = [] |
| ... | ... | @@ -526,7 +541,7 @@ class SurfaceProperties(wx.Panel): |
| 526 | 541 | |
| 527 | 542 | def CloseProject(self): |
| 528 | 543 | n = self.combo_surface_name.GetCount() |
| 529 | - for i in xrange(n-1, -1, -1): | |
| 544 | + for i in range(n-1, -1, -1): | |
| 530 | 545 | self.combo_surface_name.Delete(i) |
| 531 | 546 | self.surface_list = [] |
| 532 | 547 | |
| ... | ... | @@ -587,7 +602,10 @@ class QualityAdjustment(wx.Panel): |
| 587 | 602 | def __init__(self, parent): |
| 588 | 603 | import invesalius.constants as const |
| 589 | 604 | wx.Panel.__init__(self, parent) |
| 590 | - default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 605 | + try: | |
| 606 | + default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 607 | + except AttributeError: | |
| 608 | + default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) | |
| 591 | 609 | self.SetBackgroundColour(default_colour) |
| 592 | 610 | |
| 593 | 611 | # LINE 1 |
| ... | ... | @@ -643,7 +661,7 @@ class QualityAdjustment(wx.Panel): |
| 643 | 661 | self.SetAutoLayout(1) |
| 644 | 662 | |
| 645 | 663 | def OnComboQuality(self, evt): |
| 646 | - print "TODO: Send Signal - Change surface quality: %s" % (evt.GetString()) | |
| 664 | + print("TODO: Send Signal - Change surface quality: %s" % (evt.GetString())) | |
| 647 | 665 | |
| 648 | 666 | def OnDecimate(self, evt): |
| 649 | - print "TODO: Send Signal - Decimate: %s" % float(self.spin.GetValue())/100 | |
| 667 | + print("TODO: Send Signal - Decimate: %s" % float(self.spin.GetValue())/100) | ... | ... |
invesalius/gui/task_tools.py
| ... | ... | @@ -20,7 +20,12 @@ |
| 20 | 20 | import wx |
| 21 | 21 | import os |
| 22 | 22 | import wx.lib.embeddedimage as emb |
| 23 | -import wx.lib.hyperlink as hl | |
| 23 | + | |
| 24 | +try: | |
| 25 | + import wx.lib.agw.hyperlink as hl | |
| 26 | +except ImportError: | |
| 27 | + import wx.lib.hyperlink as hl | |
| 28 | + | |
| 24 | 29 | import wx.lib.platebtn as pbtn |
| 25 | 30 | from wx.lib.pubsub import pub as Publisher |
| 26 | 31 | |
| ... | ... | @@ -120,7 +125,7 @@ class InnerTaskPanel(wx.Panel): |
| 120 | 125 | self.sizer = main_sizer |
| 121 | 126 | |
| 122 | 127 | def OnTextAnnotation(self, evt=None): |
| 123 | - print "TODO: Send Signal - Add text annotation (both 2d and 3d)" | |
| 128 | + print("TODO: Send Signal - Add text annotation (both 2d and 3d)") | |
| 124 | 129 | |
| 125 | 130 | def OnLinkLinearMeasure(self): |
| 126 | 131 | Publisher.sendMessage('Enable style', | ... | ... |
invesalius/gui/widgets/clut_imagedata.py
| 1 | +import functools | |
| 1 | 2 | import math |
| 2 | 3 | import wx |
| 3 | 4 | |
| ... | ... | @@ -33,6 +34,7 @@ myEVT_CLUT_NODE_CHANGED = wx.NewEventType() |
| 33 | 34 | EVT_CLUT_NODE_CHANGED = wx.PyEventBinder(myEVT_CLUT_NODE_CHANGED, 1) |
| 34 | 35 | |
| 35 | 36 | |
| 37 | +@functools.total_ordering | |
| 36 | 38 | class Node(object): |
| 37 | 39 | def __init__(self, value, colour): |
| 38 | 40 | self.value = value |
| ... | ... | @@ -41,6 +43,12 @@ class Node(object): |
| 41 | 43 | def __cmp__(self, o): |
| 42 | 44 | return cmp(self.value, o.value) |
| 43 | 45 | |
| 46 | + def __lt__(self, other): | |
| 47 | + return self.value < other.value | |
| 48 | + | |
| 49 | + def __eq__(self, other): | |
| 50 | + return self.value == other.value | |
| 51 | + | |
| 44 | 52 | def __repr__(self): |
| 45 | 53 | return "(%d %s)" % (self.value, self.colour) |
| 46 | 54 | |
| ... | ... | @@ -147,7 +155,7 @@ class CLUTImageDataWidget(wx.Panel): |
| 147 | 155 | prop_y = (h) * 1.0 / (y_end - y_init) |
| 148 | 156 | |
| 149 | 157 | self._d_hist = [] |
| 150 | - for i in xrange(w): | |
| 158 | + for i in range(w): | |
| 151 | 159 | x = i / prop_x + x_init - 1 |
| 152 | 160 | if self.i_init <= x < self.i_end: |
| 153 | 161 | try: |
| ... | ... | @@ -218,7 +226,7 @@ class CLUTImageDataWidget(wx.Panel): |
| 218 | 226 | self.middle_pressed = False |
| 219 | 227 | |
| 220 | 228 | def OnClick(self, evt): |
| 221 | - px, py = evt.GetPositionTuple() | |
| 229 | + px, py = evt.GetPosition() | |
| 222 | 230 | self.left_pressed = True |
| 223 | 231 | self.selected_node = self.get_node_clicked(px, py) |
| 224 | 232 | self.last_selected = self.selected_node |
| ... | ... | @@ -231,7 +239,7 @@ class CLUTImageDataWidget(wx.Panel): |
| 231 | 239 | |
| 232 | 240 | def OnDoubleClick(self, evt): |
| 233 | 241 | w, h = self.GetVirtualSize() |
| 234 | - px, py = evt.GetPositionTuple() | |
| 242 | + px, py = evt.GetPosition() | |
| 235 | 243 | |
| 236 | 244 | # Verifying if the user double-click in a node-colour. |
| 237 | 245 | selected_node = self.get_node_clicked(px, py) |
| ... | ... | @@ -240,7 +248,7 @@ class CLUTImageDataWidget(wx.Panel): |
| 240 | 248 | # option to change the color from this node. |
| 241 | 249 | colour_dialog = wx.GetColourFromUser(self, (0, 0, 0)) |
| 242 | 250 | if colour_dialog.IsOk(): |
| 243 | - r, g, b = colour_dialog.Get() | |
| 251 | + r, g, b = colour_dialog.Get()[:3] | |
| 244 | 252 | selected_node.colour = r, g, b |
| 245 | 253 | self._generate_event() |
| 246 | 254 | else: |
| ... | ... | @@ -255,7 +263,7 @@ class CLUTImageDataWidget(wx.Panel): |
| 255 | 263 | |
| 256 | 264 | def OnRightClick(self, evt): |
| 257 | 265 | w, h = self.GetVirtualSize() |
| 258 | - px, py = evt.GetPositionTuple() | |
| 266 | + px, py = evt.GetPosition() | |
| 259 | 267 | selected_node = self.get_node_clicked(px, py) |
| 260 | 268 | |
| 261 | 269 | if selected_node: | ... | ... |
invesalius/gui/widgets/clut_raycasting.py
| ... | ... | @@ -97,8 +97,8 @@ class Button(object): |
| 97 | 97 | """ |
| 98 | 98 | Test if the button was clicked. |
| 99 | 99 | """ |
| 100 | - print self.position | |
| 101 | - print self.size | |
| 100 | + print(self.position) | |
| 101 | + print(self.size) | |
| 102 | 102 | m_x, m_y = position |
| 103 | 103 | i_x, i_y = self.position |
| 104 | 104 | w, h = self.size |
| ... | ... | @@ -146,7 +146,7 @@ class CLUTRaycastingWidget(wx.Panel): |
| 146 | 146 | Se the range from hounsfield |
| 147 | 147 | """ |
| 148 | 148 | self.init, self.end = range |
| 149 | - print "Range", range | |
| 149 | + print("Range", range) | |
| 150 | 150 | self.CalculatePixelPoints() |
| 151 | 151 | |
| 152 | 152 | def SetPadding(self, padding): |
| ... | ... | @@ -169,9 +169,9 @@ class CLUTRaycastingWidget(wx.Panel): |
| 169 | 169 | pass |
| 170 | 170 | |
| 171 | 171 | def OnClick(self, evt): |
| 172 | - x, y = evt.GetPositionTuple() | |
| 173 | - if self.save_button.HasClicked(evt.GetPositionTuple()): | |
| 174 | - print "Salvando" | |
| 172 | + x, y = evt.GetPosition() | |
| 173 | + if self.save_button.HasClicked((x, y)): | |
| 174 | + print("Salvando") | |
| 175 | 175 | filename = dialog.ShowSavePresetDialog() |
| 176 | 176 | if filename: |
| 177 | 177 | Publisher.sendMessage('Save raycasting preset', filename) |
| ... | ... | @@ -218,7 +218,7 @@ class CLUTRaycastingWidget(wx.Panel): |
| 218 | 218 | """ |
| 219 | 219 | Used to change the colour of a point |
| 220 | 220 | """ |
| 221 | - point = self._has_clicked_in_a_point(evt.GetPositionTuple()) | |
| 221 | + point = self._has_clicked_in_a_point(evt.GetPosition()) | |
| 222 | 222 | if point: |
| 223 | 223 | i, j = point |
| 224 | 224 | actual_colour = self.curves[i].nodes[j].colour |
| ... | ... | @@ -240,18 +240,18 @@ class CLUTRaycastingWidget(wx.Panel): |
| 240 | 240 | """ |
| 241 | 241 | Used to remove a point |
| 242 | 242 | """ |
| 243 | - point = self._has_clicked_in_a_point(evt.GetPositionTuple()) | |
| 243 | + point = self._has_clicked_in_a_point(evt.GetPosition()) | |
| 244 | 244 | if point: |
| 245 | 245 | i, j = point |
| 246 | - print "RightClick", i, j | |
| 246 | + print("RightClick", i, j) | |
| 247 | 247 | self.RemovePoint(i, j) |
| 248 | 248 | self.Refresh() |
| 249 | 249 | nevt = CLUTEvent(myEVT_CLUT_POINT_RELEASE, self.GetId(), i) |
| 250 | 250 | self.GetEventHandler().ProcessEvent(nevt) |
| 251 | 251 | return |
| 252 | - n_curve = self._has_clicked_in_selection_curve(evt.GetPositionTuple()) | |
| 252 | + n_curve = self._has_clicked_in_selection_curve(evt.GetPosition()) | |
| 253 | 253 | if n_curve is not None: |
| 254 | - print "Removing a curve" | |
| 254 | + print("Removing a curve") | |
| 255 | 255 | self.RemoveCurve(n_curve) |
| 256 | 256 | self.Refresh() |
| 257 | 257 | nevt = CLUTEvent(myEVT_CLUT_POINT_RELEASE, self.GetId(), n_curve) |
| ... | ... | @@ -280,7 +280,7 @@ class CLUTRaycastingWidget(wx.Panel): |
| 280 | 280 | direction = evt.GetWheelRotation() / evt.GetWheelDelta() |
| 281 | 281 | init = self.init - RANGE * direction |
| 282 | 282 | end = self.end + RANGE * direction |
| 283 | - print direction, init, end | |
| 283 | + print(direction, init, end) | |
| 284 | 284 | self.SetRange((init, end)) |
| 285 | 285 | self.Refresh() |
| 286 | 286 | |
| ... | ... | @@ -369,7 +369,7 @@ class CLUTRaycastingWidget(wx.Panel): |
| 369 | 369 | |
| 370 | 370 | def _has_clicked_in_save(self, clicked_point): |
| 371 | 371 | x, y = clicked_point |
| 372 | - print x, y | |
| 372 | + print(x, y) | |
| 373 | 373 | if self.padding < x < self.padding + 24 and \ |
| 374 | 374 | self.padding < y < self.padding + 24: |
| 375 | 375 | return True |
| ... | ... | @@ -559,7 +559,7 @@ class CLUTRaycastingWidget(wx.Panel): |
| 559 | 559 | def _draw_histogram(self, ctx, height): |
| 560 | 560 | # The histogram |
| 561 | 561 | x,y = self.Histogram.points[0] |
| 562 | - print "=>", x,y | |
| 562 | + print("=>", x,y) | |
| 563 | 563 | |
| 564 | 564 | ctx.SetPen(wx.Pen(HISTOGRAM_LINE_COLOUR, HISTOGRAM_LINE_WIDTH)) |
| 565 | 565 | ctx.SetBrush(wx.Brush(HISTOGRAM_FILL_COLOUR)) |
| ... | ... | @@ -567,7 +567,7 @@ class CLUTRaycastingWidget(wx.Panel): |
| 567 | 567 | path = ctx.CreatePath() |
| 568 | 568 | path.MoveToPoint(x,y) |
| 569 | 569 | for x,y in self.Histogram.points: |
| 570 | - print x,y | |
| 570 | + print(x,y) | |
| 571 | 571 | path.AddLineToPoint(x, y) |
| 572 | 572 | |
| 573 | 573 | ctx.PushState() |
| ... | ... | @@ -624,7 +624,7 @@ class CLUTRaycastingWidget(wx.Panel): |
| 624 | 624 | proportion_x = width * 1.0 / (x_end - x_init) |
| 625 | 625 | proportion_y = height * 1.0 / (y_end - y_init) |
| 626 | 626 | self.Histogram.points = [] |
| 627 | - for i in xrange(0, len(self.histogram_array), 5): | |
| 627 | + for i in range(0, len(self.histogram_array), 5): | |
| 628 | 628 | if self.histogram_array[i]: |
| 629 | 629 | y = math.log(self.histogram_array[i]) |
| 630 | 630 | else: |
| ... | ... | @@ -649,7 +649,7 @@ class CLUTRaycastingWidget(wx.Panel): |
| 649 | 649 | """ |
| 650 | 650 | for n, (point, colour) in enumerate(zip(self.points, self.colours)): |
| 651 | 651 | point_colour = zip(point, colour) |
| 652 | - point_colour.sort(key=lambda x: x[0]['x']) | |
| 652 | + point_colour = sorted(point_colour, key=lambda x: x[0]['x']) | |
| 653 | 653 | self.points[n] = [i[0] for i in point_colour] |
| 654 | 654 | self.colours[n] = [i[1] for i in point_colour] |
| 655 | 655 | ... | ... |
invesalius/gui/widgets/gradient.py
| ... | ... | @@ -121,8 +121,11 @@ class GradientSlider(wx.Panel): |
| 121 | 121 | dc.GradientFillLinear((x_init_gradient, y_init_gradient, |
| 122 | 122 | width_gradient, height_gradient), |
| 123 | 123 | (0, 0, 0), (255,255, 255)) |
| 124 | - | |
| 125 | - n = wx.RendererNative_Get() | |
| 124 | + | |
| 125 | + try: | |
| 126 | + n = wx.RendererNative.Get() | |
| 127 | + except AttributeError: | |
| 128 | + n = wx.RendererNative_Get() | |
| 126 | 129 | |
| 127 | 130 | # Drawing the push buttons |
| 128 | 131 | n.DrawPushButton(self, dc, (x_init_push1, 0, PUSH_WIDTH, h)) |
| ... | ... | @@ -327,7 +330,7 @@ class GradientCtrl(wx.Panel): |
| 327 | 330 | self.max_range = maxRange |
| 328 | 331 | self.minimun = minValue |
| 329 | 332 | self.maximun = maxValue |
| 330 | - self.colour = colour | |
| 333 | + self.colour = colour[:3] | |
| 331 | 334 | self.changed = False |
| 332 | 335 | self._draw_controls() |
| 333 | 336 | self._bind_events_wx() |
| ... | ... | @@ -433,7 +436,7 @@ class GradientCtrl(wx.Panel): |
| 433 | 436 | self._GenerateEvent(myEVT_THRESHOLD_CHANGING) |
| 434 | 437 | |
| 435 | 438 | def SetColour(self, colour): |
| 436 | - colour = list(colour) + [90,] | |
| 439 | + colour = list(colour[:3]) + [90,] | |
| 437 | 440 | self.colour = colour |
| 438 | 441 | self.gradient_slider.SetColour(colour) |
| 439 | 442 | self.gradient_slider.Refresh() | ... | ... |
invesalius/gui/widgets/listctrl.py
| ... | ... | @@ -63,7 +63,7 @@ class ColumnSorterMixin: |
| 63 | 63 | self.SetColumnCount(numColumns) |
| 64 | 64 | list = self.GetListCtrl() |
| 65 | 65 | if not list: |
| 66 | - raise ValueError, "No wx.ListCtrl available" | |
| 66 | + raise ValueError("No wx.ListCtrl available") | |
| 67 | 67 | list.Bind(wx.EVT_LIST_COL_CLICK, self.__OnColClick, list) |
| 68 | 68 | |
| 69 | 69 | ... | ... |
invesalius/gui/widgets/slice_menu.py
| ... | ... | @@ -183,17 +183,17 @@ class SliceMenu(wx.Menu): |
| 183 | 183 | |
| 184 | 184 | def FirstItemSelect(self, pusub_evt): |
| 185 | 185 | item = self.ID_TO_TOOL_ITEM[self.id_wl_first] |
| 186 | - item.Check(1) | |
| 186 | + item.Check(True) | |
| 187 | 187 | |
| 188 | 188 | for i in self.pseudo_color_items: |
| 189 | 189 | it = self.pseudo_color_items[i] |
| 190 | 190 | if it.IsChecked(): |
| 191 | - it.Toggle() | |
| 191 | + it.Check(False) | |
| 192 | 192 | item = self.ID_TO_TOOL_ITEM[self.id_pseudo_first] |
| 193 | - item.Check(1) | |
| 193 | + item.Check(True) | |
| 194 | 194 | |
| 195 | - item = self.ID_TO_TOOL_ITEM[self.id_tiling_first] | |
| 196 | - item.Check(1) | |
| 195 | + # item = self.ID_TO_TOOL_ITEM[self.id_tiling_first] | |
| 196 | + # item.Check(True) | |
| 197 | 197 | |
| 198 | 198 | def CheckWindowLevelOther(self, pubsub_evt): |
| 199 | 199 | item = self.ID_TO_TOOL_ITEM[self.other_wl_id] | ... | ... |
invesalius/i18n.py
| ... | ... | @@ -83,6 +83,10 @@ def InstallLanguage(language): |
| 83 | 83 | |
| 84 | 84 | lang = gettext.translation('invesalius', language_dir,\ |
| 85 | 85 | languages=[language], codeset='utf8') |
| 86 | - # Using unicode | |
| 87 | - lang.install(unicode=1) | |
| 88 | - return lang.ugettext | |
| 86 | + # Using unicode | |
| 87 | + try: | |
| 88 | + lang.install(unicode=1) | |
| 89 | + return lang.ugettext | |
| 90 | + except TypeError: | |
| 91 | + lang.install() | |
| 92 | + return lang.gettext | ... | ... |
invesalius/net/dicom.py
| ... | ... | @@ -165,14 +165,14 @@ class DicomNet: |
| 165 | 165 | const char *call=NULL, |
| 166 | 166 | const char *outputdir=NULL)""" |
| 167 | 167 | |
| 168 | - print ">>>>>", self.address, int(self.port), theQuery, 11112, self.aetitle,\ | |
| 169 | - self.aetitle_call, "/home/phamorim/Desktop/output/" | |
| 168 | + print(">>>>>", self.address, int(self.port), theQuery, 11112, self.aetitle, | |
| 169 | + self.aetitle_call, "/home/phamorim/Desktop/output/") | |
| 170 | 170 | |
| 171 | 171 | |
| 172 | 172 | cnf.CMove(self.address, int(self.port), theQuery, 11112, self.aetitle,\ |
| 173 | 173 | self.aetitle_call, "/home/phamorim/Desktop/") |
| 174 | 174 | |
| 175 | - print "BAIXOUUUUUUUU" | |
| 175 | + print("BAIXOUUUUUUUU") | |
| 176 | 176 | #ret = gdcm.DataSetArrayType() |
| 177 | 177 | |
| 178 | 178 | #cnf.CFind(self.address, int(self.port), theQuery, ret, self.aetitle,\ | ... | ... |
invesalius/presets.py
| ... | ... | @@ -43,7 +43,7 @@ class Presets(): |
| 43 | 43 | _("Fat Tissue (Child)"):(-212,-72), |
| 44 | 44 | _("Skin Tissue (Adult)"):(-718,-177), |
| 45 | 45 | _("Skin Tissue (Child)"):(-766,-202), |
| 46 | - _("Custom"):('', '') | |
| 46 | + _("Custom"):(0, 0) | |
| 47 | 47 | }) |
| 48 | 48 | |
| 49 | 49 | self.thresh_mri = TwoWaysDictionary({ |
| ... | ... | @@ -61,7 +61,7 @@ class Presets(): |
| 61 | 61 | _("Fat Tissue (Child)"):(812,952), |
| 62 | 62 | _("Skin Tissue (Adult)"):(306,847), |
| 63 | 63 | _("Skin Tissue (Child)"):(258,822), |
| 64 | - _("Custom"):('', '') | |
| 64 | + _("Custom"):(0, 0) | |
| 65 | 65 | }) |
| 66 | 66 | self.__bind_events() |
| 67 | 67 | |
| ... | ... | @@ -78,6 +78,7 @@ class Presets(): |
| 78 | 78 | for key in presets: |
| 79 | 79 | (t_min, t_max) = presets[key] |
| 80 | 80 | |
| 81 | + print(key, t_min, t_max) | |
| 81 | 82 | |
| 82 | 83 | if (t_min is None) or (t_max is None): # setting custom preset |
| 83 | 84 | t_min = thresh_min |
| ... | ... | @@ -181,7 +182,7 @@ def get_wwwl_preset_colours(pfile): |
| 181 | 182 | preset = plistlib.readPlist(pfile) |
| 182 | 183 | ncolours = len(preset['Blue']) |
| 183 | 184 | colours = [] |
| 184 | - for i in xrange(ncolours): | |
| 185 | + for i in range(ncolours): | |
| 185 | 186 | r = preset['Red'][i] |
| 186 | 187 | g = preset['Green'][i] |
| 187 | 188 | b = preset['Blue'][i] | ... | ... |
invesalius/project.py
| ... | ... | @@ -17,6 +17,8 @@ |
| 17 | 17 | # detalhes. |
| 18 | 18 | #-------------------------------------------------------------------------- |
| 19 | 19 | |
| 20 | +from six import with_metaclass | |
| 21 | + | |
| 20 | 22 | import datetime |
| 21 | 23 | import glob |
| 22 | 24 | import os |
| ... | ... | @@ -33,7 +35,7 @@ import vtk |
| 33 | 35 | import invesalius.constants as const |
| 34 | 36 | import invesalius.data.polydata_utils as pu |
| 35 | 37 | from invesalius.presets import Presets |
| 36 | -from invesalius.utils import Singleton, debug, touch | |
| 38 | +from invesalius.utils import Singleton, debug, touch, decode | |
| 37 | 39 | import invesalius.version as version |
| 38 | 40 | |
| 39 | 41 | if sys.platform == 'win32': |
| ... | ... | @@ -45,11 +47,9 @@ if sys.platform == 'win32': |
| 45 | 47 | else: |
| 46 | 48 | _has_win32api = False |
| 47 | 49 | |
| 48 | -class Project(object): | |
| 49 | - # Only one project will be initialized per time. Therefore, we use | |
| 50 | - # Singleton design pattern for implementing it | |
| 51 | - __metaclass__= Singleton | |
| 52 | - | |
| 50 | +# Only one project will be initialized per time. Therefore, we use | |
| 51 | +# Singleton design pattern for implementing it | |
| 52 | +class Project(with_metaclass(Singleton, object)): | |
| 53 | 53 | def __init__(self): |
| 54 | 54 | # Patient/ acquistion information |
| 55 | 55 | self.name = '' |
| ... | ... | @@ -205,7 +205,7 @@ class Project(object): |
| 205 | 205 | return measures |
| 206 | 206 | |
| 207 | 207 | def SavePlistProject(self, dir_, filename, compress=False): |
| 208 | - dir_temp = tempfile.mkdtemp().decode(const.FS_ENCODE) | |
| 208 | + dir_temp = decode(tempfile.mkdtemp(), const.FS_ENCODE) | |
| 209 | 209 | |
| 210 | 210 | self.compress = compress |
| 211 | 211 | |
| ... | ... | @@ -357,7 +357,7 @@ def Compress(folder, filename, filelist, compress=False): |
| 357 | 357 | touch(temp_inv3) |
| 358 | 358 | temp_inv3 = win32api.GetShortPathName(temp_inv3) |
| 359 | 359 | |
| 360 | - temp_inv3 = temp_inv3.decode(const.FS_ENCODE) | |
| 360 | + temp_inv3 = decode(temp_inv3, const.FS_ENCODE) | |
| 361 | 361 | #os.chdir(tmpdir) |
| 362 | 362 | #file_list = glob.glob(os.path.join(tmpdir_,"*")) |
| 363 | 363 | if compress: |
| ... | ... | @@ -374,16 +374,16 @@ def Compress(folder, filename, filelist, compress=False): |
| 374 | 374 | def Extract(filename, folder): |
| 375 | 375 | if _has_win32api: |
| 376 | 376 | folder = win32api.GetShortPathName(folder) |
| 377 | - folder = folder.decode(const.FS_ENCODE) | |
| 377 | + folder = decode(folder, const.FS_ENCODE) | |
| 378 | 378 | |
| 379 | 379 | tar = tarfile.open(filename, "r") |
| 380 | - idir = os.path.split(tar.getnames()[0])[0].decode('utf8') | |
| 380 | + idir = decode(os.path.split(tar.getnames()[0])[0], 'utf8') | |
| 381 | 381 | os.mkdir(os.path.join(folder, idir)) |
| 382 | 382 | filelist = [] |
| 383 | 383 | for t in tar.getmembers(): |
| 384 | 384 | fsrc = tar.extractfile(t) |
| 385 | - fname = os.path.join(folder, t.name.decode('utf-8')) | |
| 386 | - fdst = file(fname, 'wb') | |
| 385 | + fname = os.path.join(folder, decode(t.name, 'utf-8')) | |
| 386 | + fdst = open(fname, 'wb') | |
| 387 | 387 | shutil.copyfileobj(fsrc, fdst) |
| 388 | 388 | filelist.append(fname) |
| 389 | 389 | fsrc.close() | ... | ... |
invesalius/reader/bitmap_reader.py
| ... | ... | @@ -17,7 +17,6 @@ |
| 17 | 17 | # detalhes. |
| 18 | 18 | #-------------------------------------------------------------------------- |
| 19 | 19 | import os |
| 20 | -import Queue | |
| 21 | 20 | import threading |
| 22 | 21 | import tempfile |
| 23 | 22 | import sys |
| ... | ... | @@ -136,7 +135,7 @@ class LoadBitmap: |
| 136 | 135 | |
| 137 | 136 | def __init__(self, bmp_file, filepath): |
| 138 | 137 | self.bmp_file = bmp_file |
| 139 | - self.filepath = filepath | |
| 138 | + self.filepath = utils.decode(filepath, const.FS_ENCODE) | |
| 140 | 139 | |
| 141 | 140 | self.run() |
| 142 | 141 | |
| ... | ... | @@ -355,8 +354,10 @@ def ReadBitmap(filepath): |
| 355 | 354 | filepath = win32api.GetShortPathName(filepath) |
| 356 | 355 | |
| 357 | 356 | if t == False: |
| 358 | - measures_info = GetPixelSpacingFromInfoFile(filepath) | |
| 359 | - | |
| 357 | + try: | |
| 358 | + measures_info = GetPixelSpacingFromInfoFile(filepath) | |
| 359 | + except UnicodeDecodeError: | |
| 360 | + measures_info = False | |
| 360 | 361 | if measures_info: |
| 361 | 362 | Publisher.sendMessage('Set bitmap spacing', measures_info) |
| 362 | 363 | |
| ... | ... | @@ -377,6 +378,9 @@ def ReadBitmap(filepath): |
| 377 | 378 | |
| 378 | 379 | |
| 379 | 380 | def GetPixelSpacingFromInfoFile(filepath): |
| 381 | + filepath = utils.decode(filepath, const.FS_ENCODE) | |
| 382 | + if filepath.endswith('.DS_Store'): | |
| 383 | + return False | |
| 380 | 384 | fi = open(filepath, 'r') |
| 381 | 385 | lines = fi.readlines() |
| 382 | 386 | measure_scale = 'mm' | ... | ... |
invesalius/reader/dicom.py
| ... | ... | @@ -1240,7 +1240,7 @@ class Parser(): |
| 1240 | 1240 | encoding = self.GetEncoding() |
| 1241 | 1241 | try: |
| 1242 | 1242 | # Returns a unicode decoded in the own dicom encoding |
| 1243 | - return name.decode(encoding, 'replace') | |
| 1243 | + return utils.decode(name, encoding, 'replace') | |
| 1244 | 1244 | except(UnicodeEncodeError): |
| 1245 | 1245 | return name |
| 1246 | 1246 | |
| ... | ... | @@ -1285,7 +1285,7 @@ class Parser(): |
| 1285 | 1285 | |
| 1286 | 1286 | try: |
| 1287 | 1287 | # Returns a unicode decoded in the own dicom encoding |
| 1288 | - return name.decode(encoding, 'replace') | |
| 1288 | + return utils.decode(name, encoding, 'replace') | |
| 1289 | 1289 | except(UnicodeEncodeError): |
| 1290 | 1290 | return name |
| 1291 | 1291 | |
| ... | ... | @@ -1308,7 +1308,7 @@ class Parser(): |
| 1308 | 1308 | encoding = self.GetEncoding() |
| 1309 | 1309 | # Returns a unicode decoded in the own dicom encoding |
| 1310 | 1310 | try: |
| 1311 | - return data.decode(encoding, 'replace') | |
| 1311 | + return utils.decode(data, encoding, 'replace') | |
| 1312 | 1312 | except(UnicodeEncodeError): |
| 1313 | 1313 | return data |
| 1314 | 1314 | return "" |
| ... | ... | @@ -1526,10 +1526,8 @@ class Parser(): |
| 1526 | 1526 | try: |
| 1527 | 1527 | data = self.data_image[str(0x0008)][str(0x1030)] |
| 1528 | 1528 | if (data): |
| 1529 | - if isinstance(data, unicode): | |
| 1530 | - return data | |
| 1531 | 1529 | encoding = self.GetEncoding() |
| 1532 | - return data.decode(encoding, 'replace') | |
| 1530 | + return utils.decode(data, encoding, 'replace') | |
| 1533 | 1531 | except(KeyError): |
| 1534 | 1532 | return "" |
| 1535 | 1533 | |
| ... | ... | @@ -1843,31 +1841,31 @@ if __name__ == "__main__": |
| 1843 | 1841 | fail_count = 0 |
| 1844 | 1842 | total = 48 |
| 1845 | 1843 | |
| 1846 | - for i in xrange(1,total+1): | |
| 1844 | + for i in range(1,total+1): | |
| 1847 | 1845 | filename = "..//data//"+str(i)+".dcm" |
| 1848 | 1846 | |
| 1849 | 1847 | parser = Parser() |
| 1850 | 1848 | if parser.SetFileName(filename): |
| 1851 | - print "p:", parser.GetPatientName() | |
| 1852 | - print "l:", parser.GetImageLocation() | |
| 1853 | - print "o:", parser.GetImagePatientOrientation() | |
| 1854 | - print "t:", parser.GetImageThickness() | |
| 1855 | - print "s:", parser.GetPixelSpacing() | |
| 1856 | - print "x:", parser.GetDimensionX() | |
| 1857 | - print "y:", parser.GetDimensionY() | |
| 1858 | - print "z:", parser.GetDimensionZ() | |
| 1849 | + print("p:", parser.GetPatientName()) | |
| 1850 | + print("l:", parser.GetImageLocation()) | |
| 1851 | + print("o:", parser.GetImagePatientOrientation()) | |
| 1852 | + print("t:", parser.GetImageThickness()) | |
| 1853 | + print("s:", parser.GetPixelSpacing()) | |
| 1854 | + print("x:", parser.GetDimensionX()) | |
| 1855 | + print("y:", parser.GetDimensionY()) | |
| 1856 | + print("z:", parser.GetDimensionZ()) | |
| 1859 | 1857 | else: |
| 1860 | - print "--------------------------------------------------" | |
| 1858 | + print("--------------------------------------------------") | |
| 1861 | 1859 | total-=1 |
| 1862 | 1860 | fail_count+=1 |
| 1863 | 1861 | |
| 1864 | - print "\nREPORT:" | |
| 1865 | - print "failed: ", fail_count | |
| 1866 | - print "sucess: ", total | |
| 1862 | + print("\nREPORT:") | |
| 1863 | + print("failed: ", fail_count) | |
| 1864 | + print("sucess: ", total) | |
| 1867 | 1865 | |
| 1868 | 1866 | # Example of how to use auxiliary functions |
| 1869 | 1867 | total = 38 |
| 1870 | - for i in xrange(1,total+1): | |
| 1868 | + for i in range(1,total+1): | |
| 1871 | 1869 | if (i==8) or (i==9) or (i==13): |
| 1872 | 1870 | pass |
| 1873 | 1871 | else: | ... | ... |
invesalius/reader/dicom_grouper.py
| ... | ... | @@ -124,7 +124,7 @@ class DicomGroup: |
| 124 | 124 | # (interpolated) |
| 125 | 125 | |
| 126 | 126 | if _has_win32api: |
| 127 | - filelist = [win32api.GetShortPathName(dicom.image.file).encode(const.FS_ENCODE) | |
| 127 | + filelist = [win32api.GetShortPathName(dicom.image.file) | |
| 128 | 128 | for dicom in |
| 129 | 129 | self.slices_dict.values()] |
| 130 | 130 | else: |
| ... | ... | @@ -132,16 +132,19 @@ class DicomGroup: |
| 132 | 132 | self.slices_dict.values()] |
| 133 | 133 | |
| 134 | 134 | # Sort slices using GDCM |
| 135 | - if (self.dicom.image.orientation_label <> "CORONAL"): | |
| 135 | + if (self.dicom.image.orientation_label != "CORONAL"): | |
| 136 | 136 | #Organize reversed image |
| 137 | 137 | sorter = gdcm.IPPSorter() |
| 138 | 138 | sorter.SetComputeZSpacing(True) |
| 139 | 139 | sorter.SetZSpacingTolerance(1e-10) |
| 140 | - sorter.Sort(filelist) | |
| 140 | + try: | |
| 141 | + sorter.Sort([utils.encode(i, const.FS_ENCODE) for i in filelist]) | |
| 142 | + except TypeError: | |
| 143 | + sorter.Sort(filelist) | |
| 141 | 144 | filelist = sorter.GetFilenames() |
| 142 | 145 | |
| 143 | 146 | # for breast-CT of koning manufacturing (KBCT) |
| 144 | - if self.slices_dict.values()[0].parser.GetManufacturerName() == "Koning": | |
| 147 | + if list(self.slices_dict.values())[0].parser.GetManufacturerName() == "Koning": | |
| 145 | 148 | filelist.sort() |
| 146 | 149 | |
| 147 | 150 | return filelist |
| ... | ... | @@ -149,7 +152,7 @@ class DicomGroup: |
| 149 | 152 | def GetHandSortedList(self): |
| 150 | 153 | # This will be used to fix problem 1, after merging |
| 151 | 154 | # single DicomGroups of same study_id and orientation |
| 152 | - list_ = self.slices_dict.values() | |
| 155 | + list_ = list(self.slices_dict.values()) | |
| 153 | 156 | dicom = list_[0] |
| 154 | 157 | axis = ORIENT_MAP[dicom.image.orientation_label] |
| 155 | 158 | #list_ = sorted(list_, key = lambda dicom:dicom.image.position[axis]) |
| ... | ... | @@ -173,7 +176,7 @@ class DicomGroup: |
| 173 | 176 | |
| 174 | 177 | def GetDicomSample(self): |
| 175 | 178 | size = len(self.slices_dict) |
| 176 | - dicom = self.GetHandSortedList()[size/2] | |
| 179 | + dicom = self.GetHandSortedList()[size//2] | |
| 177 | 180 | return dicom |
| 178 | 181 | |
| 179 | 182 | class PatientGroup: |
| ... | ... | @@ -306,7 +309,7 @@ class PatientGroup: |
| 306 | 309 | |
| 307 | 310 | # 3rd STEP: CHECK DIFFERENCES |
| 308 | 311 | axis = ORIENT_MAP[group_key[0]] # based on orientation |
| 309 | - for index in xrange(len(sorted_list)-1): | |
| 312 | + for index in range(len(sorted_list)-1): | |
| 310 | 313 | current = sorted_list[index] |
| 311 | 314 | next = sorted_list[index+1] |
| 312 | 315 | ... | ... |
invesalius/reader/dicom_reader.py
| ... | ... | @@ -17,7 +17,6 @@ |
| 17 | 17 | # detalhes. |
| 18 | 18 | #-------------------------------------------------------------------------- |
| 19 | 19 | import os |
| 20 | -import Queue | |
| 21 | 20 | import threading |
| 22 | 21 | import tempfile |
| 23 | 22 | import sys |
| ... | ... | @@ -79,7 +78,7 @@ def SelectLargerDicomGroup(patient_group): |
| 79 | 78 | def SortFiles(filelist, dicom): |
| 80 | 79 | # Sort slices |
| 81 | 80 | # FIXME: Coronal Crash. necessary verify |
| 82 | - if (dicom.image.orientation_label <> "CORONAL"): | |
| 81 | + if (dicom.image.orientation_label != "CORONAL"): | |
| 83 | 82 | ##Organize reversed image |
| 84 | 83 | sorter = gdcm.IPPSorter() |
| 85 | 84 | sorter.SetComputeZSpacing(True) |
| ... | ... | @@ -96,27 +95,29 @@ main_dict = {} |
| 96 | 95 | dict_file = {} |
| 97 | 96 | |
| 98 | 97 | class LoadDicom: |
| 99 | - | |
| 100 | 98 | def __init__(self, grouper, filepath): |
| 101 | 99 | self.grouper = grouper |
| 102 | - self.filepath = filepath | |
| 103 | - | |
| 100 | + self.filepath = utils.decode(filepath, const.FS_ENCODE) | |
| 104 | 101 | self.run() |
| 105 | - | |
| 102 | + | |
| 106 | 103 | def run(self): |
| 107 | 104 | grouper = self.grouper |
| 108 | 105 | reader = gdcm.ImageReader() |
| 109 | 106 | if _has_win32api: |
| 110 | - reader.SetFileName(win32api.GetShortPathName(self.filepath).encode(const.FS_ENCODE)) | |
| 107 | + try: | |
| 108 | + reader.SetFileName(utils.encode(win32api.GetShortPathName(self.filepath), | |
| 109 | + const.FS_ENCODE)) | |
| 110 | + except TypeError: | |
| 111 | + reader.SetFileName(win32api.GetShortPathName(self.filepath)) | |
| 111 | 112 | else: |
| 112 | - reader.SetFileName(self.filepath) | |
| 113 | - | |
| 113 | + try: | |
| 114 | + reader.SetFileName(utils.encode(self.filepath, const.FS_ENCODE)) | |
| 115 | + except TypeError: | |
| 116 | + reader.SetFileName(self.filepath) | |
| 114 | 117 | if (reader.Read()): |
| 115 | 118 | file = reader.GetFile() |
| 116 | - | |
| 117 | 119 | # Retrieve data set |
| 118 | 120 | dataSet = file.GetDataSet() |
| 119 | - | |
| 120 | 121 | # Retrieve header |
| 121 | 122 | header = file.GetHeader() |
| 122 | 123 | stf = gdcm.StringFilter() |
| ... | ... | @@ -158,7 +159,7 @@ class LoadDicom: |
| 158 | 159 | data_dict[group] = {} |
| 159 | 160 | |
| 160 | 161 | if not(utils.VerifyInvalidPListCharacter(data[1])): |
| 161 | - data_dict[group][field] = data[1].decode(encoding) | |
| 162 | + data_dict[group][field] = utils.decode(data[1], encoding) | |
| 162 | 163 | else: |
| 163 | 164 | data_dict[group][field] = "Invalid Character" |
| 164 | 165 | |
| ... | ... | @@ -183,7 +184,7 @@ class LoadDicom: |
| 183 | 184 | data_dict[group] = {} |
| 184 | 185 | |
| 185 | 186 | if not(utils.VerifyInvalidPListCharacter(data[1])): |
| 186 | - data_dict[group][field] = data[1].decode(encoding, 'replace') | |
| 187 | + data_dict[group][field] = utils.decode(data[1], encoding, 'replace') | |
| 187 | 188 | else: |
| 188 | 189 | data_dict[group][field] = "Invalid Character" |
| 189 | 190 | |
| ... | ... | @@ -201,7 +202,7 @@ class LoadDicom: |
| 201 | 202 | window = None |
| 202 | 203 | |
| 203 | 204 | if _has_win32api: |
| 204 | - thumbnail_path = imagedata_utils.create_dicom_thumbnails(win32api.GetShortPathName(self.filepath).encode(const.FS_ENCODE), window, level) | |
| 205 | + thumbnail_path = imagedata_utils.create_dicom_thumbnails(win32api.GetShortPathName(self.filepath), window, level) | |
| 205 | 206 | else: |
| 206 | 207 | thumbnail_path = imagedata_utils.create_dicom_thumbnails(self.filepath, window, level) |
| 207 | 208 | |
| ... | ... | @@ -211,10 +212,10 @@ class LoadDicom: |
| 211 | 212 | direc_cosines = img.GetDirectionCosines() |
| 212 | 213 | orientation = gdcm.Orientation() |
| 213 | 214 | try: |
| 214 | - type = orientation.GetType(tuple(direc_cosines)) | |
| 215 | + _type = orientation.GetType(tuple(direc_cosines)) | |
| 215 | 216 | except TypeError: |
| 216 | - type = orientation.GetType(direc_cosines) | |
| 217 | - label = orientation.GetLabel(type) | |
| 217 | + _type = orientation.GetType(direc_cosines) | |
| 218 | + label = orientation.GetLabel(_type) | |
| 218 | 219 | |
| 219 | 220 | |
| 220 | 221 | # ---------- Refactory -------------------------------------- |
| ... | ... | @@ -305,7 +306,7 @@ def yGetDicomGroups(directory, recursive=True, gui=True): |
| 305 | 306 | |
| 306 | 307 | |
| 307 | 308 | def GetDicomGroups(directory, recursive=True): |
| 308 | - return yGetDicomGroups(directory, recursive, gui=False).next() | |
| 309 | + return next(yGetDicomGroups(directory, recursive, gui=False)) | |
| 309 | 310 | |
| 310 | 311 | |
| 311 | 312 | class ProgressDicomReader: |
| ... | ... | @@ -333,7 +334,7 @@ class ProgressDicomReader: |
| 333 | 334 | def GetDicomGroups(self, path, recursive): |
| 334 | 335 | |
| 335 | 336 | if not const.VTK_WARNING: |
| 336 | - log_path = os.path.join(const.USER_LOG_DIR, 'vtkoutput.txt').encode(const.FS_ENCODE) | |
| 337 | + log_path = utils.encode(os.path.join(const.USER_LOG_DIR, 'vtkoutput.txt'), const.FS_ENCODE) | |
| 337 | 338 | fow = vtk.vtkFileOutputWindow() |
| 338 | 339 | fow.SetFileName(log_path) |
| 339 | 340 | ow = vtk.vtkOutputWindow() |
| ... | ... | @@ -341,7 +342,7 @@ class ProgressDicomReader: |
| 341 | 342 | |
| 342 | 343 | y = yGetDicomGroups(path, recursive) |
| 343 | 344 | for value_progress in y: |
| 344 | - print ">>>>", value_progress | |
| 345 | + print(">>>>", value_progress) | |
| 345 | 346 | if not self.running: |
| 346 | 347 | break |
| 347 | 348 | if isinstance(value_progress, tuple): | ... | ... |
invesalius/session.py
| ... | ... | @@ -17,6 +17,8 @@ |
| 17 | 17 | # detalhes. |
| 18 | 18 | #-------------------------------------------------------------------------- |
| 19 | 19 | |
| 20 | +from six import with_metaclass | |
| 21 | + | |
| 20 | 22 | try: |
| 21 | 23 | import configparser as ConfigParser |
| 22 | 24 | except(ImportError): |
| ... | ... | @@ -33,7 +35,7 @@ import codecs |
| 33 | 35 | from wx.lib.pubsub import pub as Publisher |
| 34 | 36 | import wx |
| 35 | 37 | |
| 36 | -from invesalius.utils import Singleton, debug | |
| 38 | +from invesalius.utils import Singleton, debug, decode | |
| 37 | 39 | from random import randint |
| 38 | 40 | |
| 39 | 41 | FS_ENCODE = sys.getfilesystemencoding() |
| ... | ... | @@ -43,9 +45,9 @@ if sys.platform == 'win32': |
| 43 | 45 | try: |
| 44 | 46 | USER_DIR = expand_user() |
| 45 | 47 | except: |
| 46 | - USER_DIR = os.path.expanduser('~').decode(FS_ENCODE) | |
| 48 | + USER_DIR = decode(os.path.expanduser('~'), FS_ENCODE) | |
| 47 | 49 | else: |
| 48 | - USER_DIR = os.path.expanduser('~').decode(FS_ENCODE) | |
| 50 | + USER_DIR = decode(os.path.expanduser('~'), FS_ENCODE) | |
| 49 | 51 | |
| 50 | 52 | USER_INV_DIR = os.path.join(USER_DIR, u'.invesalius') |
| 51 | 53 | USER_PRESET_DIR = os.path.join(USER_INV_DIR, u'presets') |
| ... | ... | @@ -55,10 +57,9 @@ USER_INV_CFG_PATH = os.path.join(USER_INV_DIR, 'config.cfg') |
| 55 | 57 | SESSION_ENCODING = 'utf8' |
| 56 | 58 | |
| 57 | 59 | |
| 58 | -class Session(object): | |
| 59 | - # Only one session will be initialized per time. Therefore, we use | |
| 60 | - # Singleton design pattern for implementing it | |
| 61 | - __metaclass__= Singleton | |
| 60 | +# Only one session will be initialized per time. Therefore, we use | |
| 61 | +# Singleton design pattern for implementing it | |
| 62 | +class Session(with_metaclass(Singleton, object)): | |
| 62 | 63 | |
| 63 | 64 | def __init__(self): |
| 64 | 65 | self.temp_item = False |
| ... | ... | @@ -221,7 +222,7 @@ class Session(object): |
| 221 | 222 | |
| 222 | 223 | # Remove oldest projects from list |
| 223 | 224 | if len(l)>const.PROJ_MAX: |
| 224 | - for i in xrange(len(l)-const.PROJ_MAX): | |
| 225 | + for i in range(len(l)-const.PROJ_MAX): | |
| 225 | 226 | l.pop() |
| 226 | 227 | |
| 227 | 228 | def GetLanguage(self): | ... | ... |
invesalius/style.py
| ... | ... | @@ -64,7 +64,7 @@ from wx.lib.pubsub import pub as Publisher |
| 64 | 64 | #---------------------- |
| 65 | 65 | |
| 66 | 66 | |
| 67 | -import constants as const | |
| 67 | +import invesalius.constants as const | |
| 68 | 68 | |
| 69 | 69 | class StyleStateManager(object): |
| 70 | 70 | # don't need to be singleton, only needs to be instantiated inside | ... | ... |
invesalius/utils.py
| ... | ... | @@ -239,13 +239,13 @@ def calculate_resizing_tofitmemory(x_size,y_size,n_slices,byte): |
| 239 | 239 | ram_total = psutil.phymem_usage().total |
| 240 | 240 | swap_free = psutil.virtmem_usage().free |
| 241 | 241 | except: |
| 242 | - print "Exception! psutil version < 0.3 (not recommended)" | |
| 242 | + print("Exception! psutil version < 0.3 (not recommended)") | |
| 243 | 243 | ram_total = psutil.TOTAL_PHYMEM # this is for psutil < 0.3 |
| 244 | 244 | ram_free = 0.8 * psutil.TOTAL_PHYMEM |
| 245 | 245 | swap_free = psutil.avail_virtmem() |
| 246 | 246 | |
| 247 | - print "RAM_FREE=", ram_free | |
| 248 | - print "RAM_TOTAL=", ram_total | |
| 247 | + print("RAM_FREE=", ram_free) | |
| 248 | + print( "RAM_TOTAL=", ram_total) | |
| 249 | 249 | |
| 250 | 250 | if (sys.platform == 'win32'): |
| 251 | 251 | if (platform.architecture()[0] == '32bit'): |
| ... | ... | @@ -371,8 +371,14 @@ def get_system_encoding(): |
| 371 | 371 | |
| 372 | 372 | |
| 373 | 373 | def UpdateCheck(): |
| 374 | - import urllib | |
| 375 | - import urllib2 | |
| 374 | + try: | |
| 375 | + from urllib.parse import urlencode | |
| 376 | + from urllib.request import urlopen, Request | |
| 377 | + from urllib.error import HTTPError | |
| 378 | + except ImportError: | |
| 379 | + from urllib import urlencode | |
| 380 | + from urllib2 import urlopen, Request, HTTPError | |
| 381 | + | |
| 376 | 382 | import wx |
| 377 | 383 | import invesalius.session as ses |
| 378 | 384 | def _show_update_info(): |
| ... | ... | @@ -385,7 +391,7 @@ def UpdateCheck(): |
| 385 | 391 | msgdlg.Show() |
| 386 | 392 | #msgdlg.Destroy() |
| 387 | 393 | |
| 388 | - print "Checking updates..." | |
| 394 | + print("Checking updates...") | |
| 389 | 395 | |
| 390 | 396 | # Check if there is a language set |
| 391 | 397 | #import invesalius.i18n as i18n import invesalius.session as ses |
| ... | ... | @@ -411,14 +417,14 @@ def UpdateCheck(): |
| 411 | 417 | 'architecture' : platform.architecture()[0], |
| 412 | 418 | 'language' : lang, |
| 413 | 419 | 'random_id' : random_id } |
| 414 | - data = urllib.urlencode(data) | |
| 415 | - req = urllib2.Request(url, data, headers) | |
| 420 | + data = urlencode(data).encode('utf8') | |
| 421 | + req = Request(url, data, headers) | |
| 416 | 422 | try: |
| 417 | - response = urllib2.urlopen(req, timeout=10) | |
| 423 | + response = urlopen(req, timeout=10) | |
| 418 | 424 | except: |
| 419 | 425 | return |
| 420 | - last = response.readline().rstrip() | |
| 421 | - url = response.readline().rstrip() | |
| 426 | + last = response.readline().rstrip().decode('utf8') | |
| 427 | + url = response.readline().rstrip().decode('utf8') | |
| 422 | 428 | |
| 423 | 429 | try: |
| 424 | 430 | last_ver = LooseVersion(last) |
| ... | ... | @@ -427,14 +433,14 @@ def UpdateCheck(): |
| 427 | 433 | return |
| 428 | 434 | |
| 429 | 435 | if last_ver > actual_ver: |
| 430 | - print " ...New update found!!! -> version:", last #, ", url=",url | |
| 436 | + print(" ...New update found!!! -> version:", last) #, ", url=",url | |
| 431 | 437 | wx.CallAfter(wx.CallLater, 1000, _show_update_info) |
| 432 | 438 | |
| 433 | 439 | |
| 434 | 440 | def vtkarray_to_numpy(m): |
| 435 | 441 | nm = np.zeros((4, 4)) |
| 436 | - for i in xrange(4): | |
| 437 | - for j in xrange(4): | |
| 442 | + for i in range(4): | |
| 443 | + for j in range(4): | |
| 438 | 444 | nm[i, j] = m.GetElement(i, j) |
| 439 | 445 | return nm |
| 440 | 446 | |
| ... | ... | @@ -442,3 +448,17 @@ def vtkarray_to_numpy(m): |
| 442 | 448 | def touch(fname): |
| 443 | 449 | with open(fname, 'a'): |
| 444 | 450 | pass |
| 451 | + | |
| 452 | + | |
| 453 | +def decode(text, encoding, *args): | |
| 454 | + try: | |
| 455 | + return text.decode(encoding, *args) | |
| 456 | + except AttributeError: | |
| 457 | + return text | |
| 458 | + | |
| 459 | + | |
| 460 | +def encode(text, encoding, *args): | |
| 461 | + try: | |
| 462 | + return text.encode(encoding, *args) | |
| 463 | + except AttributeError: | |
| 464 | + return text | |
| 445 | 465 | \ No newline at end of file | ... | ... |