Commit bb6f3c391e9373c83886f968a53c491513bc86d7

Authored by Paulo Henrique Junqueira Amorim
1 parent a96cac21

ENH: FIX #77 save session file using python config

Showing 2 changed files with 36 additions and 26 deletions   Show diff stats
invesalius/invesalius.py
@@ -105,14 +105,17 @@ def parse_comand_line(): @@ -105,14 +105,17 @@ def parse_comand_line():
105 parser.add_option("-i", "--import", action="store", dest="dicom_dir") 105 parser.add_option("-i", "--import", action="store", dest="dicom_dir")
106 106
107 options, args = parser.parse_args() 107 options, args = parser.parse_args()
108 - 108 +
  109 + session = Session()
  110 + if not (session.ReadSession()):
  111 + session.CreateItens()
  112 +
109 if options.debug: 113 if options.debug:
110 # The user passed the debug option? 114 # The user passed the debug option?
111 # Yes! 115 # Yes!
112 # Then all pubsub message must be printed. 116 # Then all pubsub message must be printed.
113 ps.Publisher().subscribe(print_events, ps.ALL_TOPICS) 117 ps.Publisher().subscribe(print_events, ps.ALL_TOPICS)
114 118
115 - session = Session()  
116 session.debug = 1 119 session.debug = 1
117 120
118 if options.dicom_dir: 121 if options.dicom_dir:
invesalius/session.py
@@ -8,12 +8,22 @@ import constants as const @@ -8,12 +8,22 @@ import constants as const
8 from utils import Singleton 8 from utils import Singleton
9 9
10 import wx.lib.pubsub as ps 10 import wx.lib.pubsub as ps
  11 +
11 class Session(object): 12 class Session(object):
12 # Only one session will be initialized per time. Therefore, we use 13 # Only one session will be initialized per time. Therefore, we use
13 # Singleton design pattern for implementing it 14 # Singleton design pattern for implementing it
14 __metaclass__= Singleton 15 __metaclass__= Singleton
15 16
16 def __init__(self): 17 def __init__(self):
  18 + # ?
  19 + self.temp_item = False
  20 +
  21 + ws = self.ws = WriteSession(self)
  22 + ws.start()
  23 +
  24 + ps.Publisher().subscribe(self.StopRecording, "Stop Config Recording")
  25 +
  26 + def CreateItens(self):
17 self.project_path = () 27 self.project_path = ()
18 self.debug = False 28 self.debug = False
19 29
@@ -31,24 +41,16 @@ class Session(object): @@ -31,24 +41,16 @@ class Session(object):
31 if not os.path.isdir(invdir): 41 if not os.path.isdir(invdir):
32 os.makedirs(invdir) 42 os.makedirs(invdir)
33 self.invdir = invdir 43 self.invdir = invdir
34 -  
35 - # ?  
36 - self.temp_item = False  
37 -  
38 - # Recent projects list  
39 - self.recent_projects = []  
40 -  
41 - ws = self.ws = WriteSession(self)  
42 - ws.start()  
43 44
44 - ps.Publisher().subscribe(self.StopRecording, "Stop Config Recording") 45 + # GUI language
  46 + self.language = "" # "pt_BR", "es"
45 47
  48 + # Recent projects list
  49 + self.recent_projects = []
46 50
47 def StopRecording(self, pubsub_evt): 51 def StopRecording(self, pubsub_evt):
48 self.ws.Stop() 52 self.ws.Stop()
49 -  
50 - # GUI language  
51 - self.language = "en_GB" # "pt_BR", "es" 53 +
52 54
53 def CloseProject(self): 55 def CloseProject(self):
54 print "-- CloseProject" 56 print "-- CloseProject"
@@ -126,17 +128,22 @@ class Session(object): @@ -126,17 +128,22 @@ class Session(object):
126 setattr(self, key, dict[key]) 128 setattr(self, key, dict[key])
127 129
128 def ReadSession(self): 130 def ReadSession(self):
129 - config = ConfigParser.ConfigParser()  
130 - path = os.path.join(self.homedir ,'.invesalius', 'config.cfg')  
131 - config.read(path)  
132 -  
133 - self.mode = config.get('session', 'mode')  
134 - self.project_status = config.get('session', 'status')  
135 - self.debug = config.get('session','debug')  
136 - self.recent_projects = eval(config.get('project','recent_projects'))  
137 - self.homedir = config.get('paths','homedir')  
138 - self.invdir = config.get('paths','invdir')  
139 131
  132 + config = ConfigParser.ConfigParser()
  133 + home_path = os.path.expanduser('~')
  134 + path = os.path.join(home_path ,'.invesalius', 'config.cfg')
  135 + try:
  136 + config.read(path)
  137 + self.mode = config.get('session', 'mode')
  138 + self.project_status = config.get('session', 'status')
  139 + self.debug = config.get('session','debug')
  140 + self.language = config.get('session','language')
  141 + self.recent_projects = eval(config.get('project','recent_projects'))
  142 + self.homedir = config.get('paths','homedir')
  143 + self.invdir = config.get('paths','invdir')
  144 + return True
  145 + except(ConfigParser.NoSectionError):
  146 + return False
140 147
141 class WriteSession(Thread): 148 class WriteSession(Thread):
142 149
@@ -151,7 +158,6 @@ class WriteSession(Thread): @@ -151,7 +158,6 @@ class WriteSession(Thread):
151 self.Write() 158 self.Write()
152 159
153 def Stop(self): 160 def Stop(self):
154 - print "VAI PARAR A THREAD................"  
155 self.runing = 0 161 self.runing = 0
156 162
157 def Write(self): 163 def Write(self):
@@ -162,6 +168,7 @@ class WriteSession(Thread): @@ -162,6 +168,7 @@ class WriteSession(Thread):
162 config.set('session', 'mode', self.session.mode) 168 config.set('session', 'mode', self.session.mode)
163 config.set('session', 'status', self.session.project_status) 169 config.set('session', 'status', self.session.project_status)
164 config.set('session','debug', self.session.debug) 170 config.set('session','debug', self.session.debug)
  171 + config.set('session', 'language', self.session.language)
165 172
166 config.add_section('project') 173 config.add_section('project')
167 config.set('project', 'recent_projects', self.session.recent_projects) 174 config.set('project', 'recent_projects', self.session.recent_projects)