Commit 8ac676ad265f6d15b5f1389e74dd3a7505354288
1 parent
08b16644
Exists in
master
and in
61 other branches
Not using thread anymore to write session file
Showing
2 changed files
with
9 additions
and
66 deletions
Show diff stats
invesalius/invesalius.py
invesalius/session.py
... | ... | @@ -38,10 +38,6 @@ class Session(object): |
38 | 38 | def __init__(self): |
39 | 39 | self.temp_item = False |
40 | 40 | |
41 | - ws = self.ws = WriteSession(self) | |
42 | - ws.start() | |
43 | - Publisher.subscribe(self.StopRecording, "Stop Config Recording") | |
44 | - | |
45 | 41 | def CreateItens(self): |
46 | 42 | import constants as const |
47 | 43 | self.project_path = () |
... | ... | @@ -72,10 +68,7 @@ class Session(object): |
72 | 68 | self.last_dicom_folder = '' |
73 | 69 | self.surface_interpolation = 1 |
74 | 70 | self.rendering = 0 |
75 | - self.CreateSessionFile() | |
76 | - | |
77 | - def StopRecording(self, pubsub_evt): | |
78 | - self.ws.Stop() | |
71 | + self.WriteSessionFile() | |
79 | 72 | |
80 | 73 | def SaveConfigFileBackup(self): |
81 | 74 | path = os.path.join(self.homedir , |
... | ... | @@ -103,6 +96,7 @@ class Session(object): |
103 | 96 | self.project_status = const.PROJ_CLOSE |
104 | 97 | #self.mode = const.MODE_RP |
105 | 98 | self.temp_item = False |
99 | + self.WriteSessionFile() | |
106 | 100 | |
107 | 101 | def SaveProject(self, path=()): |
108 | 102 | import constants as const |
... | ... | @@ -113,6 +107,7 @@ class Session(object): |
113 | 107 | self.__add_to_list(path) |
114 | 108 | if self.temp_item: |
115 | 109 | self.temp_item = False |
110 | + self.WriteSessionFile() | |
116 | 111 | |
117 | 112 | def ChangeProject(self): |
118 | 113 | import constants as const |
... | ... | @@ -127,6 +122,7 @@ class Session(object): |
127 | 122 | self.project_path = (self.tempdir, filename) |
128 | 123 | self.project_status = const.PROJ_NEW |
129 | 124 | self.temp_item = True |
125 | + self.WriteSessionFile() | |
130 | 126 | return self.tempdir |
131 | 127 | |
132 | 128 | def OpenProject(self, filepath): |
... | ... | @@ -139,6 +135,7 @@ class Session(object): |
139 | 135 | # Set session info |
140 | 136 | self.project_path = item |
141 | 137 | self.project_status = const.PROJ_OPEN |
138 | + self.WriteSessionFile() | |
142 | 139 | |
143 | 140 | def RemoveTemp(self): |
144 | 141 | if self.temp_item: |
... | ... | @@ -147,7 +144,7 @@ class Session(object): |
147 | 144 | os.remove(path) |
148 | 145 | self.temp_item = False |
149 | 146 | |
150 | - def CreateSessionFile(self): | |
147 | + def WriteSessionFile(self): | |
151 | 148 | config = ConfigParser.RawConfigParser() |
152 | 149 | |
153 | 150 | config.add_section('session') |
... | ... | @@ -210,7 +207,7 @@ class Session(object): |
210 | 207 | |
211 | 208 | def SetLastDicomFolder(self, folder): |
212 | 209 | self.last_dicom_folder = folder |
213 | - self.CreateSessionFile() | |
210 | + self.WriteSessionFile() | |
214 | 211 | |
215 | 212 | def ReadLanguage(self): |
216 | 213 | config = ConfigParser.ConfigParser() |
... | ... | @@ -273,59 +270,5 @@ class Session(object): |
273 | 270 | self.surface_interpolation = 0 |
274 | 271 | self.rendering = 0 |
275 | 272 | self.random_id = randint(0,pow(10,16)) |
276 | - self.CreateSessionFile() | |
273 | + self.WriteSessionFile() | |
277 | 274 | return True |
278 | - | |
279 | - | |
280 | -class WriteSession(Thread): | |
281 | - | |
282 | - def __init__ (self, session): | |
283 | - Thread.__init__(self) | |
284 | - self.session = session | |
285 | - self.runing = 1 | |
286 | - | |
287 | - def run(self): | |
288 | - while self.runing: | |
289 | - time.sleep(10) | |
290 | - try: | |
291 | - self.Write() | |
292 | - except AttributeError: | |
293 | - debug("Session: trying to write into inexistent file") | |
294 | - | |
295 | - def Stop(self): | |
296 | - self.runing = 0 | |
297 | - | |
298 | - def Write(self): | |
299 | - import utils as utl | |
300 | - | |
301 | - config = ConfigParser.RawConfigParser() | |
302 | - | |
303 | - config.add_section('session') | |
304 | - config.set('session', 'mode', self.session.mode) | |
305 | - config.set('session', 'status', self.session.project_status) | |
306 | - config.set('session','debug', self.session.debug) | |
307 | - config.set('session', 'language', self.session.language) | |
308 | - config.set('session', 'random_id', self.session.random_id) | |
309 | - config.set('session', 'surface_interpolation', self.session.surface_interpolation) | |
310 | - config.set('session', 'rendering', self.session.rendering) | |
311 | - | |
312 | - config.add_section('project') | |
313 | - config.set('project', 'recent_projects', self.session.recent_projects) | |
314 | - | |
315 | - config.add_section('paths') | |
316 | - config.set('paths','homedir',self.session.homedir) | |
317 | - config.set('paths','tempdir',self.session.tempdir) | |
318 | - config.set('paths','last_dicom_folder', self.session.last_dicom_folder) | |
319 | - | |
320 | - path = os.path.join(self.session.homedir , | |
321 | - '.invesalius', 'config.cfg') | |
322 | - | |
323 | - try: | |
324 | - configfile = open(path, 'wb') | |
325 | - except IOError: | |
326 | - return | |
327 | - utl.debug("Session - IOError") | |
328 | - finally: | |
329 | - self.session.CreateSessionFile() | |
330 | - | |
331 | - configfile.close() | ... | ... |