Commit bb6f3c391e9373c83886f968a53c491513bc86d7
1 parent
a96cac21
Exists in
master
and in
6 other branches
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 | 105 | parser.add_option("-i", "--import", action="store", dest="dicom_dir") |
106 | 106 | |
107 | 107 | options, args = parser.parse_args() |
108 | - | |
108 | + | |
109 | + session = Session() | |
110 | + if not (session.ReadSession()): | |
111 | + session.CreateItens() | |
112 | + | |
109 | 113 | if options.debug: |
110 | 114 | # The user passed the debug option? |
111 | 115 | # Yes! |
112 | 116 | # Then all pubsub message must be printed. |
113 | 117 | ps.Publisher().subscribe(print_events, ps.ALL_TOPICS) |
114 | 118 | |
115 | - session = Session() | |
116 | 119 | session.debug = 1 |
117 | 120 | |
118 | 121 | if options.dicom_dir: | ... | ... |
invesalius/session.py
... | ... | @@ -8,12 +8,22 @@ import constants as const |
8 | 8 | from utils import Singleton |
9 | 9 | |
10 | 10 | import wx.lib.pubsub as ps |
11 | + | |
11 | 12 | class Session(object): |
12 | 13 | # Only one session will be initialized per time. Therefore, we use |
13 | 14 | # Singleton design pattern for implementing it |
14 | 15 | __metaclass__= Singleton |
15 | 16 | |
16 | 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 | 27 | self.project_path = () |
18 | 28 | self.debug = False |
19 | 29 | |
... | ... | @@ -31,24 +41,16 @@ class Session(object): |
31 | 41 | if not os.path.isdir(invdir): |
32 | 42 | os.makedirs(invdir) |
33 | 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 | 51 | def StopRecording(self, pubsub_evt): |
48 | 52 | self.ws.Stop() |
49 | - | |
50 | - # GUI language | |
51 | - self.language = "en_GB" # "pt_BR", "es" | |
53 | + | |
52 | 54 | |
53 | 55 | def CloseProject(self): |
54 | 56 | print "-- CloseProject" |
... | ... | @@ -126,17 +128,22 @@ class Session(object): |
126 | 128 | setattr(self, key, dict[key]) |
127 | 129 | |
128 | 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 | 148 | class WriteSession(Thread): |
142 | 149 | |
... | ... | @@ -151,7 +158,6 @@ class WriteSession(Thread): |
151 | 158 | self.Write() |
152 | 159 | |
153 | 160 | def Stop(self): |
154 | - print "VAI PARAR A THREAD................" | |
155 | 161 | self.runing = 0 |
156 | 162 | |
157 | 163 | def Write(self): |
... | ... | @@ -162,6 +168,7 @@ class WriteSession(Thread): |
162 | 168 | config.set('session', 'mode', self.session.mode) |
163 | 169 | config.set('session', 'status', self.session.project_status) |
164 | 170 | config.set('session','debug', self.session.debug) |
171 | + config.set('session', 'language', self.session.language) | |
165 | 172 | |
166 | 173 | config.add_section('project') |
167 | 174 | config.set('project', 'recent_projects', self.session.recent_projects) | ... | ... |