Commit fbd518e2bbba9bbc27f84140166d0fa9327eacea

Authored by tatiana
1 parent dabdb21a

ENH: (under devel) save session plist

.gitattributes
... ... @@ -135,7 +135,6 @@ invesalius/gui/widgets/gradient.py -text
135 135 invesalius/gui/widgets/listctrl.py -text
136 136 invesalius/gui/widgets/slice_menu.py -text
137 137 invesalius/invesalius.py -text
138   -invesalius/mode.py -text
139 138 invesalius/presets.py -text
140 139 invesalius/project.py -text
141 140 invesalius/reader/__init__.py -text
... ...
invesalius/mode.py
... ... @@ -1,128 +0,0 @@
1   -#--------------------------------------------------------------------------
2   -# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
3   -# Copyright: (C) 2001 Centro de Pesquisas Renato Archer
4   -# Homepage: http://www.softwarepublico.gov.br
5   -# Contact: invesalius@cti.gov.br
6   -# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
7   -#--------------------------------------------------------------------------
8   -# Este programa e software livre; voce pode redistribui-lo e/ou
9   -# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
10   -# publicada pela Free Software Foundation; de acordo com a versao 2
11   -# da Licenca.
12   -#
13   -# Este programa eh distribuido na expectativa de ser util, mas SEM
14   -# QUALQUER GARANTIA; sem mesmo a garantia implicita de
15   -# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
16   -# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
17   -# detalhes.
18   -#--------------------------------------------------------------------------
19   -
20   -import wx.lib.pubsub as ps
21   -
22   -
23   -# mode.py
24   -# to be instanced inside Controller (control.py)
25   -
26   -
27   -
28   -# IMPORTANT: When adding a new state, remember o insert it into LEVEL
29   -# dictionary
30   -
31   -
32   -# RULE:
33   -# default is the only level 0
34   -# states controlled somehow by taskmenu are level 1
35   -# states controlled by toolbar are level 2
36   -#LEVEL = {SLICE_STATE_DEFAULT: 0,
37   -# SLICE_STATE_EDITOR: 1,
38   -# SLICE_STATE_WL: 2,
39   -# SLICE_STATE_SPIN: 2,
40   -# SLICE_STATE_ZOOM: 2,
41   -# SLICE_STATE_ZOOM_SL: 2}
42   -#----------------------
43   -# TODO: Add to viewer_slice.py:
44   -
45   -#ps.Publisher().subscribe(self.OnSetMode, 'Set slice mode')
46   -
47   -#def OnSetMode(self, pubsub_evt):
48   -# mode = pubsub_evt.data
49   - # according to mode, set cursor, interaction, etc
50   -#----------------------
51   -# TODO: Add GUI classes (frame, tasks related to slice, toolbar):
52   -
53   -# always bind to this class (regarding slice mode) and not to
54   -# viewer_slice directly
55   -
56   -# example - pseudo code
57   -#def OnToggleButtonSpin(self, evt)
58   -# if evt.toggle: # doesn't exist, just to illustrate
59   -# ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_ZOOM)
60   -# else:
61   -# ps.Publisher().subscribe('Disable mode', const.SLICE_STATE_ZOOM)
62   -
63   -
64   -#----------------------
65   -
66   -
67   -import constants as const
68   -
69   -class SliceMode(object):
70   -# don't need to be singleton, only needs to be instantiated inside
71   -# (Controller) self.slice_mode = SliceMode()
72   -
73   - def __init__(self):
74   - self.stack = {}
75   -
76   - # push default value to stack
77   - self.stack[const.LEVEL[const.STATE_DEFAULT]] = \
78   - const.STATE_DEFAULT
79   - print "Foi chamando............................."
80   - # bind pubsub evt
81   - self.__bind_events()
82   -
83   - def __bind_events(self):
84   - print "__bind_events"
85   - ps.Publisher().subscribe(self.OnEnableState, 'Enable mode')
86   - ps.Publisher().subscribe(self.OnDisableState, 'Disable mode')
87   -
88   - def OnEnableState(self, pubsub_evt):
89   - state = pubsub_evt.data
90   - self.AddState(state)
91   -
92   - def OnDisableState(self, pubsub_evt):
93   - state = pubsub_evt.data
94   - self.RemoveState(state)
95   -
96   - def AddState(self, state):
97   -
98   - level = const.LEVEL[state]
99   - max_level = max(self.stack.keys())
100   -
101   - # Insert new state into stack
102   - self.stack[level] = state
103   -
104   - ps.Publisher().sendMessage('Set slice mode', state)
105   -
106   - def RemoveState(self, state):
107   - level = const.LEVEL[state]
108   - max_level = max(self.stack.keys())
109   -
110   - # Remove item from stack
111   -
112   - self.stack.pop(level)
113   -
114   - # New max level
115   - new_max_level = max(self.stack.keys())
116   -
117   - # Only will affect InVesalius behaviour if the highest
118   - # level in stack has been removed
119   - if level == max_level:
120   - new_state = self.stack[new_max_level]
121   -
122   - #Case one state in the stack
123   - if(len(self.stack) == 1):
124   - state = self.stack[self.stack.keys()[0]]
125   -
126   - ps.Publisher().sendMessage('Set slice mode', state)
127   -
128   -
129 0 \ No newline at end of file
invesalius/session.py
... ... @@ -4,12 +4,13 @@ import constants as const
4 4 from utils import Singleton
5 5  
6 6 class Session(object):
7   - # Only one project will be initialized per time. Therefore, we use
  7 + # Only one session will be initialized per time. Therefore, we use
8 8 # Singleton design pattern for implementing it
9 9 __metaclass__= Singleton
10 10  
11 11 def __init__(self):
12 12 self.project_path = ()
  13 + self.debug = False
13 14  
14 15 self.project_status = const.PROJ_CLOSE
15 16 # const.PROJ_NEW*, const.PROJ_OPEN, const.PROJ_CHANGE*,
... ... @@ -32,12 +33,14 @@ class Session(object):
32 33 self.recent_projects = []
33 34  
34 35 def CloseProject(self):
  36 + print "-- CloseProject"
35 37 self.project_path = ()
36 38 self.project_status = const.PROJ_CLOSE
37 39 self.mode = const.MODE_RP
38 40 self.temp_item = False
39 41  
40 42 def SaveProject(self, path=()):
  43 + print "-- SaveProject"
41 44 self.project_status = const.PROJ_OPEN
42 45 if path:
43 46 self.project_path = path
... ... @@ -46,17 +49,19 @@ class Session(object):
46 49 self.temp_item = False
47 50  
48 51 def ChangeProject(self):
  52 + print "-- ChangeProject"
49 53 self.project_status = const.PROJ_CHANGE
50 54  
51 55 def CreateProject(self, filename):
  56 + print "-- CreateProject"
52 57 # Set session info
53 58 self.project_path = (self.invdir, filename)
54 59 self.project_status = const.PROJ_NEW
55 60 self.temp_item = True
56 61 return self.invdir
57   -
58 62  
59 63 def OpenProject(self, filepath):
  64 + print "-- OpenProject"
60 65 # Add item to recent projects list
61 66 item = (path, file) = os.path.split(filepath)
62 67 self.__add_to_list(item)
... ... @@ -88,4 +93,16 @@ class Session(object):
88 93 if len(l)>const.PROJ_MAX:
89 94 for i in xrange(len(l)-const.PROJ_MAX):
90 95 l.pop()
91   -
  96 +
  97 + def SavePlist(self):
  98 + filename = 'session.conf'
  99 + filepath = os.join(self.invdir, filename)
  100 + plistlib.writePlist(self.__dict__, filepath)
  101 +
  102 + def OpenPlist(self):
  103 + filename = 'session.conf'
  104 + filepath = os.join(self.invdir, filename)
  105 + # TODO: try/except
  106 + dict = plistlib.readPlist(main_plist)
  107 + for key in dict:
  108 + setattr(self, key, dict[key])
... ...