From fbd518e2bbba9bbc27f84140166d0fa9327eacea Mon Sep 17 00:00:00 2001 From: tatiana Date: Fri, 4 Dec 2009 16:30:32 +0000 Subject: [PATCH] ENH: (under devel) save session plist --- .gitattributes | 1 - invesalius/mode.py | 128 -------------------------------------------------------------------------------------------------------------------------------- invesalius/session.py | 23 ++++++++++++++++++++--- 3 files changed, 20 insertions(+), 132 deletions(-) delete mode 100644 invesalius/mode.py diff --git a/.gitattributes b/.gitattributes index 0650b20..3888c6e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -135,7 +135,6 @@ invesalius/gui/widgets/gradient.py -text invesalius/gui/widgets/listctrl.py -text invesalius/gui/widgets/slice_menu.py -text invesalius/invesalius.py -text -invesalius/mode.py -text invesalius/presets.py -text invesalius/project.py -text invesalius/reader/__init__.py -text diff --git a/invesalius/mode.py b/invesalius/mode.py deleted file mode 100644 index 75f75b7..0000000 --- a/invesalius/mode.py +++ /dev/null @@ -1,128 +0,0 @@ -#-------------------------------------------------------------------------- -# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas -# Copyright: (C) 2001 Centro de Pesquisas Renato Archer -# Homepage: http://www.softwarepublico.gov.br -# Contact: invesalius@cti.gov.br -# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt) -#-------------------------------------------------------------------------- -# Este programa e software livre; voce pode redistribui-lo e/ou -# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme -# publicada pela Free Software Foundation; de acordo com a versao 2 -# da Licenca. -# -# Este programa eh distribuido na expectativa de ser util, mas SEM -# QUALQUER GARANTIA; sem mesmo a garantia implicita de -# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM -# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais -# detalhes. -#-------------------------------------------------------------------------- - -import wx.lib.pubsub as ps - - -# mode.py -# to be instanced inside Controller (control.py) - - - -# IMPORTANT: When adding a new state, remember o insert it into LEVEL -# dictionary - - -# RULE: -# default is the only level 0 -# states controlled somehow by taskmenu are level 1 -# states controlled by toolbar are level 2 -#LEVEL = {SLICE_STATE_DEFAULT: 0, -# SLICE_STATE_EDITOR: 1, -# SLICE_STATE_WL: 2, -# SLICE_STATE_SPIN: 2, -# SLICE_STATE_ZOOM: 2, -# SLICE_STATE_ZOOM_SL: 2} -#---------------------- -# TODO: Add to viewer_slice.py: - -#ps.Publisher().subscribe(self.OnSetMode, 'Set slice mode') - -#def OnSetMode(self, pubsub_evt): -# mode = pubsub_evt.data - # according to mode, set cursor, interaction, etc -#---------------------- -# TODO: Add GUI classes (frame, tasks related to slice, toolbar): - -# always bind to this class (regarding slice mode) and not to -# viewer_slice directly - -# example - pseudo code -#def OnToggleButtonSpin(self, evt) -# if evt.toggle: # doesn't exist, just to illustrate -# ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_ZOOM) -# else: -# ps.Publisher().subscribe('Disable mode', const.SLICE_STATE_ZOOM) - - -#---------------------- - - -import constants as const - -class SliceMode(object): -# don't need to be singleton, only needs to be instantiated inside -# (Controller) self.slice_mode = SliceMode() - - def __init__(self): - self.stack = {} - - # push default value to stack - self.stack[const.LEVEL[const.STATE_DEFAULT]] = \ - const.STATE_DEFAULT - print "Foi chamando............................." - # bind pubsub evt - self.__bind_events() - - def __bind_events(self): - print "__bind_events" - ps.Publisher().subscribe(self.OnEnableState, 'Enable mode') - ps.Publisher().subscribe(self.OnDisableState, 'Disable mode') - - def OnEnableState(self, pubsub_evt): - state = pubsub_evt.data - self.AddState(state) - - def OnDisableState(self, pubsub_evt): - state = pubsub_evt.data - self.RemoveState(state) - - def AddState(self, state): - - level = const.LEVEL[state] - max_level = max(self.stack.keys()) - - # Insert new state into stack - self.stack[level] = state - - ps.Publisher().sendMessage('Set slice mode', state) - - def RemoveState(self, state): - level = const.LEVEL[state] - max_level = max(self.stack.keys()) - - # Remove item from stack - - self.stack.pop(level) - - # New max level - new_max_level = max(self.stack.keys()) - - # Only will affect InVesalius behaviour if the highest - # level in stack has been removed - if level == max_level: - new_state = self.stack[new_max_level] - - #Case one state in the stack - if(len(self.stack) == 1): - state = self.stack[self.stack.keys()[0]] - - ps.Publisher().sendMessage('Set slice mode', state) - - \ No newline at end of file diff --git a/invesalius/session.py b/invesalius/session.py index a60c8b9..73dcdb9 100644 --- a/invesalius/session.py +++ b/invesalius/session.py @@ -4,12 +4,13 @@ import constants as const from utils import Singleton class Session(object): - # Only one project will be initialized per time. Therefore, we use + # Only one session will be initialized per time. Therefore, we use # Singleton design pattern for implementing it __metaclass__= Singleton def __init__(self): self.project_path = () + self.debug = False self.project_status = const.PROJ_CLOSE # const.PROJ_NEW*, const.PROJ_OPEN, const.PROJ_CHANGE*, @@ -32,12 +33,14 @@ class Session(object): self.recent_projects = [] def CloseProject(self): + print "-- CloseProject" self.project_path = () self.project_status = const.PROJ_CLOSE self.mode = const.MODE_RP self.temp_item = False def SaveProject(self, path=()): + print "-- SaveProject" self.project_status = const.PROJ_OPEN if path: self.project_path = path @@ -46,17 +49,19 @@ class Session(object): self.temp_item = False def ChangeProject(self): + print "-- ChangeProject" self.project_status = const.PROJ_CHANGE def CreateProject(self, filename): + print "-- CreateProject" # Set session info self.project_path = (self.invdir, filename) self.project_status = const.PROJ_NEW self.temp_item = True return self.invdir - def OpenProject(self, filepath): + print "-- OpenProject" # Add item to recent projects list item = (path, file) = os.path.split(filepath) self.__add_to_list(item) @@ -88,4 +93,16 @@ class Session(object): if len(l)>const.PROJ_MAX: for i in xrange(len(l)-const.PROJ_MAX): l.pop() - + + def SavePlist(self): + filename = 'session.conf' + filepath = os.join(self.invdir, filename) + plistlib.writePlist(self.__dict__, filepath) + + def OpenPlist(self): + filename = 'session.conf' + filepath = os.join(self.invdir, filename) + # TODO: try/except + dict = plistlib.readPlist(main_plist) + for key in dict: + setattr(self, key, dict[key]) -- libgit2 0.21.2