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':-1, |
---|
22 | 'GUIFRAME_HEIGHT':-1, |
---|
23 | 'PLOPANEL_WIDTH':-1, |
---|
24 | 'DATAPANEL_WIDTH':-1, |
---|
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 when\n" |
---|
87 | msg += "running this application next time." |
---|
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 | 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 == None or width > p_size: |
---|
132 | p_size = width |
---|
133 | if p_size == None: |
---|
134 | p_size = CURRENT_STRINGS['PLOPANEL_WIDTH'] |
---|
135 | self.current_string['PLOPANEL_WIDTH'] = p_size |
---|
136 | |
---|
137 | data_pw, _ = self.parent.panels["data_panel"].frame.GetSizeTuple() |
---|
138 | if data_pw == None: |
---|
139 | data_pw = CURRENT_STRINGS['DATAPANEL_WIDTH'] |
---|
140 | self.current_string['DATAPANEL_WIDTH'] = data_pw |
---|
141 | |
---|
142 | #label = self.parent._data_panel_menu.GetText() |
---|
143 | label = self.parent.panels['data_panel'].frame.IsShown() |
---|
144 | if label:# == 'Hide Data Explorer': |
---|
145 | self.current_string['DATALOADER_SHOW'] = True |
---|
146 | else: |
---|
147 | self.current_string['DATALOADER_SHOW'] = False |
---|
148 | |
---|
149 | if self.parent._toolbar.IsShown(): |
---|
150 | self.current_string['TOOLBAR_SHOW'] = True |
---|
151 | else: |
---|
152 | self.current_string['TOOLBAR_SHOW'] = False |
---|
153 | |
---|
154 | style = self._gui & GUIFRAME.FLOATING_PANEL |
---|
155 | if style == GUIFRAME.FLOATING_PANEL: |
---|
156 | self.current_string['FIXED_PANEL'] = False |
---|
157 | else: |
---|
158 | self.current_string['FIXED_PANEL'] = True |
---|
159 | |
---|
160 | if self.parent.panels['default'].frame.IsShown(): |
---|
161 | self.current_string['WELCOME_PANEL_SHOW'] = True |
---|
162 | else: |
---|
163 | self.current_string['WELCOME_PANEL_SHOW'] = False |
---|
164 | self.current_string['CLEANUP_PLOT'] = \ |
---|
165 | self.parent.cleanup_plots |
---|
166 | perspective = self.parent.get_current_perspective() |
---|
167 | self.current_string['DEFAULT_PERSPECTIVE'] =\ |
---|
168 | str(perspective.sub_menu) |
---|
169 | location = '' |
---|
170 | temp = self.parent._default_save_location.split("\\") |
---|
171 | for strings in temp: |
---|
172 | location += (strings + "/") |
---|
173 | self.current_string['DEFAULT_OPEN_FOLDER'] = location |
---|
174 | #self.parent._default_save_location.ascii_letters |
---|
175 | |
---|
176 | except: |
---|
177 | raise |
---|
178 | # event object and selection |
---|
179 | self.return_string = self.current_string |
---|
180 | return self.return_string |
---|
181 | |
---|
182 | def OnCancel(self, event): |
---|
183 | """ |
---|
184 | Close event |
---|
185 | """ |
---|
186 | # clear event |
---|
187 | event.Skip() |
---|
188 | self.return_string = {} |
---|
189 | self.Destroy() |
---|
190 | |
---|
191 | def OnClose(self, event): |
---|
192 | """ |
---|
193 | Close event |
---|
194 | """ |
---|
195 | # clear event |
---|
196 | event.Skip() |
---|
197 | fname = os.path.join(self.path, 'custom_config.py') |
---|
198 | self.write_string(fname, self.return_string) |
---|
199 | self.Destroy() |
---|
200 | |
---|
201 | def write_string(self, fname, strings): |
---|
202 | """ |
---|
203 | Write and Save file |
---|
204 | """ |
---|
205 | |
---|
206 | try: |
---|
207 | out_f = open(fname,'w') |
---|
208 | except : |
---|
209 | raise #RuntimeError, "Error: Can not change the configuration..." |
---|
210 | out_f.write("#Application appearance custom configuration\n" ) |
---|
211 | for key, item in strings.iteritems(): |
---|
212 | if (key == 'DEFAULT_PERSPECTIVE') or \ |
---|
213 | (key == 'DEFAULT_OPEN_FOLDER' and item != None): |
---|
214 | out_f.write("%s = \"%s\"\n" % (key,str(item))) |
---|
215 | else: |
---|
216 | out_f.write("%s = %s\n" % (key,str(item))) |
---|
217 | |
---|
218 | out_f.close() |
---|
219 | |
---|