1 | |
---|
2 | ################################################################################ |
---|
3 | #This software was developed by the University of Tennessee as part of the |
---|
4 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
5 | #project funded by the US National Science Foundation. |
---|
6 | # |
---|
7 | #See the license text in license.txt |
---|
8 | # |
---|
9 | #copyright 2009, University of Tennessee |
---|
10 | ################################################################################ |
---|
11 | import wx |
---|
12 | import os |
---|
13 | import sys |
---|
14 | import copy |
---|
15 | #import sas.sasgui.guiframe.gui_manager as gui |
---|
16 | from sas.sasgui.guiframe.events import StatusEvent |
---|
17 | from sas.sasgui.guiframe.gui_style import GUIFRAME |
---|
18 | from sas.sasgui.guiframe import gui_manager as CURRENT |
---|
19 | from sas.sasgui.guiframe.customdir import SetupCustom |
---|
20 | # default configuration |
---|
21 | DEFAULT_STRINGS = {'GUIFRAME_WIDTH':-1, |
---|
22 | 'GUIFRAME_HEIGHT':-1, |
---|
23 | 'CONTROL_WIDTH':-1, |
---|
24 | 'CONTROL_HEIGHT':-1, |
---|
25 | 'PLOPANEL_WIDTH':-1, |
---|
26 | 'DATAPANEL_WIDTH':-1, |
---|
27 | 'DATALOADER_SHOW':True, |
---|
28 | 'TOOLBAR_SHOW':True, |
---|
29 | 'FIXED_PANEL':True, |
---|
30 | 'WELCOME_PANEL_SHOW':False, |
---|
31 | 'CLEANUP_PLOT':False, |
---|
32 | 'DEFAULT_PERSPECTIVE':'Fitting', |
---|
33 | 'DEFAULT_OPEN_FOLDER': None, |
---|
34 | 'SAS_OPENCL': None} |
---|
35 | try: |
---|
36 | CURRENT_STRINGS = {'GUIFRAME_WIDTH':CURRENT.GUIFRAME_WIDTH, |
---|
37 | 'GUIFRAME_HEIGHT':CURRENT.GUIFRAME_HEIGHT, |
---|
38 | 'CONTROL_WIDTH':CURRENT.CONTROL_WIDTH, |
---|
39 | 'CONTROL_HEIGHT':CURRENT.CONTROL_HEIGHT, |
---|
40 | 'PLOPANEL_WIDTH':CURRENT.PLOPANEL_WIDTH, |
---|
41 | 'DATAPANEL_WIDTH':CURRENT.DATAPANEL_WIDTH, |
---|
42 | 'DATALOADER_SHOW':CURRENT.DATALOADER_SHOW, |
---|
43 | 'TOOLBAR_SHOW':CURRENT.TOOLBAR_SHOW, |
---|
44 | 'FIXED_PANEL':CURRENT.FIXED_PANEL, |
---|
45 | 'WELCOME_PANEL_SHOW':CURRENT.WELCOME_PANEL_SHOW, |
---|
46 | 'CLEANUP_PLOT':CURRENT.CLEANUP_PLOT, |
---|
47 | 'DEFAULT_PERSPECTIVE':CURRENT.DEFAULT_PERSPECTIVE, |
---|
48 | 'DEFAULT_OPEN_FOLDER':CURRENT.DEFAULT_OPEN_FOLDER, |
---|
49 | 'SAS_OPENCL': None} |
---|
50 | except: |
---|
51 | CURRENT_STRINGS = DEFAULT_STRINGS |
---|
52 | FONT_VARIANT = 0 |
---|
53 | PANEL_WIDTH = 285 |
---|
54 | PANEL_HEIGHT = 215 |
---|
55 | |
---|
56 | """ |
---|
57 | Dialog to set Appication startup configuration |
---|
58 | """ |
---|
59 | class StartupConfiguration(wx.Dialog): |
---|
60 | """ |
---|
61 | Dialog for Startup Configuration |
---|
62 | """ |
---|
63 | def __init__(self, parent, gui, id=-1, title="Startup Setting"): |
---|
64 | wx.Dialog.__init__(self, parent, id, title, |
---|
65 | size=(PANEL_WIDTH, PANEL_HEIGHT)) |
---|
66 | # parent |
---|
67 | self.parent = parent |
---|
68 | self.path = SetupCustom().find_dir() |
---|
69 | self._gui = gui |
---|
70 | # font size |
---|
71 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
72 | self.current_string = copy.deepcopy(CURRENT_STRINGS) |
---|
73 | self.return_string = copy.deepcopy(DEFAULT_STRINGS) |
---|
74 | # build layout |
---|
75 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
76 | title_text = wx.StaticText(self, id=wx.NewId(), label='Set interface configuration') |
---|
77 | |
---|
78 | default_bt = wx.RadioButton(self, -1, 'Default View', (15, 30), |
---|
79 | style=wx.RB_GROUP) |
---|
80 | default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnDefault) |
---|
81 | default_bt.SetValue(True) |
---|
82 | current_bt = wx.RadioButton(self, -1, 'Current View', (15, 55)) |
---|
83 | current_bt.SetValue(False) |
---|
84 | current_bt.Bind(wx.EVT_RADIOBUTTON, self.OnCurrent) |
---|
85 | msg = "\nThis new configuration will take effect when\n" |
---|
86 | msg += "running this application next time." |
---|
87 | note_txt = wx.StaticText(self, -1, msg, (15, 75)) |
---|
88 | note_txt.SetForegroundColour("black") |
---|
89 | |
---|
90 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
91 | okButton = wx.Button(self, wx.ID_OK, 'Set', size=(70, 25)) |
---|
92 | closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel', size=(70, 25)) |
---|
93 | hbox.Add(closeButton, 1, wx.RIGHT, 5) |
---|
94 | hbox.Add(okButton, 1, wx.RIGHT, 5) |
---|
95 | |
---|
96 | vbox.Add(title_text, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10) |
---|
97 | vbox.Add(default_bt, 0, wx.LEFT, 20) |
---|
98 | vbox.Add(current_bt, 0, wx.LEFT, 20) |
---|
99 | vbox.Add(note_txt, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10) |
---|
100 | vbox.Add(hbox, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10) |
---|
101 | |
---|
102 | self.SetSizer(vbox) |
---|
103 | |
---|
104 | |
---|
105 | def OnDefault(self, event=None): |
---|
106 | """ |
---|
107 | Set to default |
---|
108 | """ |
---|
109 | event.Skip() |
---|
110 | # event object and selection |
---|
111 | self.return_string = copy.deepcopy(DEFAULT_STRINGS) |
---|
112 | return self.return_string |
---|
113 | |
---|
114 | def OnCurrent(self, event=None): |
---|
115 | """ |
---|
116 | Set to curent setup |
---|
117 | """ |
---|
118 | event.Skip() |
---|
119 | if self.parent.IsMaximized(): |
---|
120 | gui_pw, gui_ph = (0, 0) |
---|
121 | else: |
---|
122 | gui_pw, gui_ph = self.parent.get_window_size() |
---|
123 | self.current_string['GUIFRAME_WIDTH'] = gui_pw |
---|
124 | self.current_string['GUIFRAME_HEIGHT'] = gui_ph |
---|
125 | try: |
---|
126 | p_size = None |
---|
127 | for panel in self.parent.plot_panels.values(): |
---|
128 | #p_panel = self.parent._mgr.GetPane(panel.window_name) |
---|
129 | width, _ = panel.frame.GetSizeTuple() |
---|
130 | if panel.frame.IsShown(): |
---|
131 | if p_size is None or width > p_size: |
---|
132 | p_size = width |
---|
133 | if p_size is None: |
---|
134 | p_size = CURRENT_STRINGS['PLOPANEL_WIDTH'] |
---|
135 | self.current_string['PLOPANEL_WIDTH'] = p_size |
---|
136 | |
---|
137 | try: |
---|
138 | control_frame = self.parent.get_current_perspective().frame |
---|
139 | control_w, control_h = control_frame.GetSizeTuple() |
---|
140 | self.current_string['CONTROL_WIDTH'] = control_w |
---|
141 | self.current_string['CONTROL_HEIGHT'] = control_h |
---|
142 | except: |
---|
143 | self.current_string['CONTROL_WIDTH'] = -1 |
---|
144 | self.current_string['CONTROL_HEIGHT'] = -1 |
---|
145 | |
---|
146 | data_pw, _ = self.parent.panels["data_panel"].frame.GetSizeTuple() |
---|
147 | if data_pw is None: |
---|
148 | data_pw = CURRENT_STRINGS['DATAPANEL_WIDTH'] |
---|
149 | self.current_string['DATAPANEL_WIDTH'] = data_pw |
---|
150 | |
---|
151 | #label = self.parent._data_panel_menu.GetText() |
---|
152 | label = self.parent.panels['data_panel'].frame.IsShown() |
---|
153 | if label:# == 'Hide Data Explorer': |
---|
154 | self.current_string['DATALOADER_SHOW'] = True |
---|
155 | else: |
---|
156 | self.current_string['DATALOADER_SHOW'] = False |
---|
157 | |
---|
158 | if self.parent._toolbar.IsShown(): |
---|
159 | self.current_string['TOOLBAR_SHOW'] = True |
---|
160 | else: |
---|
161 | self.current_string['TOOLBAR_SHOW'] = False |
---|
162 | |
---|
163 | style = self._gui & GUIFRAME.FLOATING_PANEL |
---|
164 | if style == GUIFRAME.FLOATING_PANEL: |
---|
165 | self.current_string['FIXED_PANEL'] = False |
---|
166 | else: |
---|
167 | self.current_string['FIXED_PANEL'] = True |
---|
168 | |
---|
169 | if self.parent.panels['default'].frame.IsShown(): |
---|
170 | self.current_string['WELCOME_PANEL_SHOW'] = True |
---|
171 | else: |
---|
172 | self.current_string['WELCOME_PANEL_SHOW'] = False |
---|
173 | self.current_string['CLEANUP_PLOT'] = \ |
---|
174 | self.parent.cleanup_plots |
---|
175 | perspective = self.parent.get_current_perspective() |
---|
176 | self.current_string['DEFAULT_PERSPECTIVE'] =\ |
---|
177 | str(perspective.sub_menu) |
---|
178 | location = '' |
---|
179 | temp = self.parent._default_save_location.split("\\") |
---|
180 | for strings in temp: |
---|
181 | location += (strings + "/") |
---|
182 | self.current_string['DEFAULT_OPEN_FOLDER'] = location |
---|
183 | #self.parent._default_save_location.ascii_letters |
---|
184 | |
---|
185 | except: |
---|
186 | raise |
---|
187 | # event object and selection |
---|
188 | self.return_string = self.current_string |
---|
189 | return self.return_string |
---|
190 | |
---|
191 | def write_custom_config(self): |
---|
192 | """ |
---|
193 | Write custom configuration |
---|
194 | """ |
---|
195 | fname = os.path.join(self.path, 'custom_config.py') |
---|
196 | self.write_string(fname, self.return_string) |
---|
197 | |
---|
198 | def write_string(self, fname, strings): |
---|
199 | """ |
---|
200 | Write and Save file |
---|
201 | """ |
---|
202 | |
---|
203 | try: |
---|
204 | out_f = open(fname,'w') |
---|
205 | except : |
---|
206 | raise #RuntimeError, "Error: Can not change the configuration..." |
---|
207 | out_f.write("#Application appearance custom configuration\n" ) |
---|
208 | for key, item in strings.iteritems(): |
---|
209 | if (key == 'DEFAULT_PERSPECTIVE') or \ |
---|
210 | (key == 'DEFAULT_OPEN_FOLDER' and item is not None): |
---|
211 | out_f.write("%s = \"%s\"\n" % (key,str(item))) |
---|
212 | else: |
---|
213 | out_f.write("%s = %s\n" % (key,str(item))) |
---|
214 | |
---|
215 | out_f.close() |
---|
216 | |
---|