Skip to content

Commit

Permalink
Using kwargs protocol from pypubsub (args1 deprecated) closes #141 (#143
Browse files Browse the repository at this point in the history
)

args1 pypubsub protocol was deprecated since wxpython3. In wxpython4 it was removed. This code updates invesalius to the new pypubsub protocol (kwargs).
  • Loading branch information
tfmoraes authored Aug 13, 2018
1 parent 6484ce4 commit 82be862
Show file tree
Hide file tree
Showing 37 changed files with 1,134 additions and 1,354 deletions.
36 changes: 21 additions & 15 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
except ImportError:
from wx import SplashScreen
#from wx.lib.pubsub import setupv1 #new wx
from wx.lib.pubsub import setuparg1# as psv1
# from wx.lib.pubsub import setuparg1# as psv1
#from wx.lib.pubsub import Publisher
#import wx.lib.pubsub as ps
from wx.lib.pubsub import pub as Publisher
Expand Down Expand Up @@ -117,7 +117,7 @@ def MacOpenFile(self, filename):
Open drag & drop files under darwin
"""
path = os.path.abspath(filename)
Publisher.sendMessage('Open project', path)
Publisher.sendMessage('Open project', filepath=path)

def Startup2(self):
self.control = self.splash.control
Expand Down Expand Up @@ -347,10 +347,10 @@ def use_cmd_optargs(options, args):
# If import DICOM argument...
if options.dicom_dir:
import_dir = options.dicom_dir
Publisher.sendMessage('Import directory', {'directory': import_dir, 'gui': not options.no_gui})
Publisher.sendMessage('Import directory', directory=import_dir, use_gui=not options.no_gui)

if options.save:
Publisher.sendMessage('Save project', os.path.abspath(options.save))
Publisher.sendMessage('Save project', filepath=os.path.abspath(options.save))
exit(0)

check_for_export(options)
Expand All @@ -360,9 +360,11 @@ def use_cmd_optargs(options, args):
import invesalius.reader.dicom_reader as dcm
for patient in dcm.GetDicomGroups(options.import_all):
for group in patient.GetGroups():
Publisher.sendMessage('Import group', {'group': group, 'gui': not options.no_gui})
Publisher.sendMessage('Import group',
group=group,
use_gui=not options.no_gui)
check_for_export(options, suffix=group.title, remove_surfaces=False)
Publisher.sendMessage('Remove masks', [0])
Publisher.sendMessage('Remove masks', mask_indexes=(0,))
return True

# Check if there is a file path somewhere in what the user wrote
Expand All @@ -373,14 +375,14 @@ def use_cmd_optargs(options, args):
file = utils.decode(arg, FS_ENCODE)
if os.path.isfile(file):
path = os.path.abspath(file)
Publisher.sendMessage('Open project', path)
Publisher.sendMessage('Open project', filepath=path)
check_for_export(options)
return True

file = utils.decode(arg, sys.stdin.encoding)
if os.path.isfile(file):
path = os.path.abspath(file)
Publisher.sendMessage('Open project', path)
Publisher.sendMessage('Open project', filepath=path)
check_for_export(options)
return True

Expand Down Expand Up @@ -428,7 +430,8 @@ def check_for_export(options, suffix='', remove_surfaces=False):
def export(path_, threshold_range, remove_surface=False):
import invesalius.constants as const

Publisher.sendMessage('Set threshold values', threshold_range)
Publisher.sendMessage('Set threshold values',
threshold_range=threshold_range)

surface_options = {
'method': {
Expand All @@ -443,17 +446,20 @@ def export(path_, threshold_range, remove_surface=False):
'overwrite': False,
}
}
Publisher.sendMessage('Create surface from index', surface_options)
Publisher.sendMessage('Export surface to file', (path_, const.FILETYPE_STL))
Publisher.sendMessage('Create surface from index',
surface_parameters=surface_options)
Publisher.sendMessage('Export surface to file',
filename=path_, filetype=const.FILETYPE_STL)
if remove_surface:
Publisher.sendMessage('Remove surfaces', [0])
Publisher.sendMessage('Remove surfaces',
surface_indexes=(0,))


def print_events(data):
def print_events(topic=Publisher.AUTO_TOPIC, **msg_data):
"""
Print pubsub messages
"""
utils.debug(data.topic)
utils.debug("%s\n\tParameters: %s" % (topic, msg_data))

def main():
"""
Expand Down
Loading

0 comments on commit 82be862

Please sign in to comment.