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