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 sans.guiframe.gui_manager as gui |
---|
16 | from sans.guiframe.events import StatusEvent |
---|
17 | from sans.guiframe.gui_style import GUIFRAME |
---|
18 | from sans.guiframe import gui_manager as CURRENT |
---|
19 | from sans.guiframe.customdir import SetupCustom |
---|
20 | # default configuration |
---|
21 | DEFAULT_STRINGS = {'GUIFRAME_WIDTH':1150, |
---|
22 | 'GUIFRAME_HEIGHT':840, |
---|
23 | 'PLOPANEL_WIDTH':415, |
---|
24 | 'DATAPANEL_WIDTH':235, |
---|
25 | 'DATALOADER_SHOW':True, |
---|
26 | 'TOOLBAR_SHOW':True, |
---|
27 | 'FIXED_PANEL':True, |
---|
28 | 'WELCOME_PANEL_SHOW':False, |
---|
29 | 'CLEANUP_PLOT':False, |
---|
30 | 'DEFAULT_PERSPECTIVE':'Fitting', |
---|
31 | 'DEFAULT_OPEN_FOLDER': None} |
---|
32 | try: |
---|
33 | CURRENT_STRINGS = {'GUIFRAME_WIDTH':CURRENT.GUIFRAME_WIDTH, |
---|
34 | 'GUIFRAME_HEIGHT':CURRENT.GUIFRAME_HEIGHT, |
---|
35 | 'PLOPANEL_WIDTH':CURRENT.PLOPANEL_WIDTH, |
---|
36 | 'DATAPANEL_WIDTH':CURRENT.DATAPANEL_WIDTH, |
---|
37 | 'DATALOADER_SHOW':CURRENT.DATALOADER_SHOW, |
---|
38 | 'TOOLBAR_SHOW':CURRENT.TOOLBAR_SHOW, |
---|
39 | 'FIXED_PANEL':CURRENT.FIXED_PANEL, |
---|
40 | 'WELCOME_PANEL_SHOW':CURRENT.WELCOME_PANEL_SHOW, |
---|
41 | 'CLEANUP_PLOT':CURRENT.CLEANUP_PLOT, |
---|
42 | 'DEFAULT_PERSPECTIVE':CURRENT.DEFAULT_PERSPECTIVE, |
---|
43 | 'DEFAULT_OPEN_FOLDER':CURRENT.DEFAULT_OPEN_FOLDER} |
---|
44 | except: |
---|
45 | CURRENT_STRINGS = DEFAULT_STRINGS |
---|
46 | |
---|
47 | if sys.platform.count("win32") > 0: |
---|
48 | PANEL_WIDTH = 265 |
---|
49 | PANEL_HEIGHT = 235 |
---|
50 | FONT_VARIANT = 0 |
---|
51 | else: |
---|
52 | PANEL_WIDTH = 285 |
---|
53 | PANEL_HEIGHT = 255 |
---|
54 | FONT_VARIANT = 1 |
---|
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 | panel = wx.Panel(self, -1) |
---|
76 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
77 | wx.StaticBox(panel, -1, 'Set View-Configuration', (5, 5), |
---|
78 | (PANEL_WIDTH*0.94, PANEL_HEIGHT*0.7)) |
---|
79 | default_bt = wx.RadioButton(panel, -1, 'Default View', (15, 30), |
---|
80 | style=wx.RB_GROUP) |
---|
81 | default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnDefault) |
---|
82 | default_bt.SetValue(True) |
---|
83 | current_bt = wx.RadioButton(panel, -1, 'Current View', (15, 55)) |
---|
84 | current_bt.SetValue(False) |
---|
85 | current_bt.Bind(wx.EVT_RADIOBUTTON, self.OnCurrent) |
---|
86 | msg = "\nThis new configuration will take effect after\n" |
---|
87 | msg += "restarting the SansView application..." |
---|
88 | note_txt = wx.StaticText(panel, -1, msg, (15, 75)) |
---|
89 | note_txt.SetForegroundColour("black") |
---|
90 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
91 | cancelButton = wx.Button(self, -1, 'Cancel', size=(70, 25)) |
---|
92 | hbox.Add(cancelButton, 1, wx.RIGHT, 5) |
---|
93 | cancelButton.Bind(wx.EVT_BUTTON, self.OnCancel) |
---|
94 | okButton = wx.Button(self, -1, 'OK', size=(70, 25)) |
---|
95 | hbox.Add(okButton, 1, wx.RIGHT, 5) |
---|
96 | okButton.Bind(wx.EVT_BUTTON, self.OnClose) |
---|
97 | vbox.Add(panel) |
---|
98 | |
---|
99 | vbox.Add(hbox, 1, wx.ALIGN_CENTER | wx.RIGHT | wx.BOTTOM, 5) |
---|
100 | # set sizer |
---|
101 | self.SetSizer(vbox) |
---|
102 | #pos = self.parent.GetPosition() |
---|
103 | #self.SetPosition(pos) |
---|
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 | |
---|
120 | gui_pw, gui_ph = self.parent.GetSizeTuple() |
---|
121 | self.current_string['GUIFRAME_WIDTH'] = gui_pw |
---|
122 | self.current_string['GUIFRAME_HEIGHT'] = gui_ph |
---|
123 | try: |
---|
124 | p_size = None |
---|
125 | for panel in self.parent.plot_panels.values(): |
---|
126 | p_panel = self.parent._mgr.GetPane(panel.window_name) |
---|
127 | if p_panel.IsShown(): |
---|
128 | if p_size == None or panel.size > p_size: |
---|
129 | p_size = panel.size |
---|
130 | if p_size == None: |
---|
131 | p_size = CURRENT_STRINGS['PLOPANEL_WIDTH'] |
---|
132 | self.current_string['PLOPANEL_WIDTH'] = p_size |
---|
133 | |
---|
134 | data_pw, _ = self.parent.panels["data_panel"].GetSizeTuple() |
---|
135 | if data_pw == None: |
---|
136 | data_pw = CURRENT_STRINGS['DATAPANEL_WIDTH'] |
---|
137 | self.current_string['DATAPANEL_WIDTH'] = data_pw |
---|
138 | |
---|
139 | #label = self.parent._data_panel_menu.GetText() |
---|
140 | label = self.parent._mgr.GetPane(\ |
---|
141 | self.parent.panels['data_panel'].window_name).IsShown() |
---|
142 | if label:# == 'Hide Data Explorer': |
---|
143 | self.current_string['DATALOADER_SHOW'] = True |
---|
144 | else: |
---|
145 | self.current_string['DATALOADER_SHOW'] = False |
---|
146 | |
---|
147 | if self.parent._toolbar.IsShown(): |
---|
148 | self.current_string['TOOLBAR_SHOW'] = True |
---|
149 | else: |
---|
150 | self.current_string['TOOLBAR_SHOW'] = False |
---|
151 | |
---|
152 | style = self._gui & GUIFRAME.FLOATING_PANEL |
---|
153 | if style == GUIFRAME.FLOATING_PANEL: |
---|
154 | self.current_string['FIXED_PANEL'] = False |
---|
155 | else: |
---|
156 | self.current_string['FIXED_PANEL'] = True |
---|
157 | |
---|
158 | if self.parent._mgr.GetPane(self.parent.panels['default'].window_name).IsShown(): |
---|
159 | self.current_string['WELCOME_PANEL_SHOW'] = True |
---|
160 | else: |
---|
161 | self.current_string['WELCOME_PANEL_SHOW'] = False |
---|
162 | self.current_string['CLEANUP_PLOT'] = \ |
---|
163 | self.parent.cleanup_plots |
---|
164 | perspective = self.parent.get_current_perspective() |
---|
165 | self.current_string['DEFAULT_PERSPECTIVE'] =\ |
---|
166 | str(perspective.sub_menu) |
---|
167 | location = '' |
---|
168 | temp = self.parent._default_save_location.split("\\") |
---|
169 | for strings in temp: |
---|
170 | location += (strings + "/") |
---|
171 | self.current_string['DEFAULT_OPEN_FOLDER'] = location |
---|
172 | #self.parent._default_save_location.ascii_letters |
---|
173 | |
---|
174 | except: |
---|
175 | raise |
---|
176 | # event object and selection |
---|
177 | self.return_string = self.current_string |
---|
178 | return self.return_string |
---|
179 | |
---|
180 | def OnCancel(self, event): |
---|
181 | """ |
---|
182 | Close event |
---|
183 | """ |
---|
184 | # clear event |
---|
185 | event.Skip() |
---|
186 | self.return_string = {} |
---|
187 | self.Destroy() |
---|
188 | |
---|
189 | def OnClose(self, event): |
---|
190 | """ |
---|
191 | Close event |
---|
192 | """ |
---|
193 | # clear event |
---|
194 | event.Skip() |
---|
195 | fname = os.path.join(self.path, 'custom_config.py') |
---|
196 | self.write_string(fname, self.return_string) |
---|
197 | |
---|
198 | self.Destroy() |
---|
199 | |
---|
200 | def write_string(self, fname, strings): |
---|
201 | """ |
---|
202 | Write and Save file |
---|
203 | """ |
---|
204 | |
---|
205 | try: |
---|
206 | out_f = open(fname,'w') |
---|
207 | except : |
---|
208 | raise #RuntimeError, "Error: Can not change the configuration..." |
---|
209 | out_f.write("#Application appearance custom configuration\n" ) |
---|
210 | for key, item in strings.iteritems(): |
---|
211 | if (key == 'DEFAULT_PERSPECTIVE') or \ |
---|
212 | (key == 'DEFAULT_OPEN_FOLDER' and item != None): |
---|
213 | out_f.write("%s = \"%s\"\n" % (key,str(item))) |
---|
214 | else: |
---|
215 | out_f.write("%s = %s\n" % (key,str(item))) |
---|
216 | |
---|
217 | out_f.close() |
---|
218 | |
---|