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 | |
---|
51 | if sys.platform.count("win32") > 0: |
---|
52 | PANEL_WIDTH = 265 |
---|
53 | PANEL_HEIGHT = 235 |
---|
54 | FONT_VARIANT = 0 |
---|
55 | else: |
---|
56 | PANEL_WIDTH = 285 |
---|
57 | PANEL_HEIGHT = 255 |
---|
58 | FONT_VARIANT = 1 |
---|
59 | |
---|
60 | """ |
---|
61 | Dialog to set Appication startup configuration |
---|
62 | """ |
---|
63 | class StartupConfiguration(wx.Dialog): |
---|
64 | """ |
---|
65 | Dialog for Startup Configuration |
---|
66 | """ |
---|
67 | def __init__(self, parent, gui, id=-1, title="Startup Setting"): |
---|
68 | wx.Dialog.__init__(self, parent, id, title, |
---|
69 | size=(PANEL_WIDTH, PANEL_HEIGHT)) |
---|
70 | # parent |
---|
71 | self.parent = parent |
---|
72 | self.path = SetupCustom().find_dir() |
---|
73 | self._gui = gui |
---|
74 | # font size |
---|
75 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
76 | self.current_string = copy.deepcopy(CURRENT_STRINGS) |
---|
77 | self.return_string = copy.deepcopy(DEFAULT_STRINGS) |
---|
78 | # build layout |
---|
79 | panel = wx.Panel(self, -1) |
---|
80 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
81 | wx.StaticBox(panel, -1, 'Set View-Configuration', (5, 5), |
---|
82 | (PANEL_WIDTH*0.94, PANEL_HEIGHT*0.7)) |
---|
83 | default_bt = wx.RadioButton(panel, -1, 'Default View', (15, 30), |
---|
84 | style=wx.RB_GROUP) |
---|
85 | default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnDefault) |
---|
86 | default_bt.SetValue(True) |
---|
87 | current_bt = wx.RadioButton(panel, -1, 'Current View', (15, 55)) |
---|
88 | current_bt.SetValue(False) |
---|
89 | current_bt.Bind(wx.EVT_RADIOBUTTON, self.OnCurrent) |
---|
90 | msg = "\nThis new configuration will take effect when\n" |
---|
91 | msg += "running this application next time." |
---|
92 | note_txt = wx.StaticText(panel, -1, msg, (15, 75)) |
---|
93 | note_txt.SetForegroundColour("black") |
---|
94 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
95 | |
---|
96 | okButton = wx.Button(self, wx.ID_OK, 'Set', size=(70, 25)) |
---|
97 | closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel', size=(70, 25)) |
---|
98 | hbox.Add(closeButton, 1, wx.RIGHT, 5) |
---|
99 | hbox.Add(okButton, 1, wx.RIGHT, 5) |
---|
100 | vbox.Add(panel, 1, wx.ALIGN_CENTER | wx.BOTTOM, 5) |
---|
101 | vbox.Add(hbox, 1, wx.ALIGN_CENTER | wx.BOTTOM, 5) |
---|
102 | # set sizer |
---|
103 | self.SetSizer(vbox) |
---|
104 | #pos = self.parent.GetPosition() |
---|
105 | #self.SetPosition(pos) |
---|
106 | |
---|
107 | def OnDefault(self, event=None): |
---|
108 | """ |
---|
109 | Set to default |
---|
110 | """ |
---|
111 | event.Skip() |
---|
112 | # event object and selection |
---|
113 | self.return_string = copy.deepcopy(DEFAULT_STRINGS) |
---|
114 | return self.return_string |
---|
115 | |
---|
116 | def OnCurrent(self, event=None): |
---|
117 | """ |
---|
118 | Set to curent setup |
---|
119 | """ |
---|
120 | event.Skip() |
---|
121 | if self.parent.IsMaximized(): |
---|
122 | gui_pw, gui_ph = (0, 0) |
---|
123 | else: |
---|
124 | gui_pw, gui_ph = self.parent.get_window_size() |
---|
125 | self.current_string['GUIFRAME_WIDTH'] = gui_pw |
---|
126 | self.current_string['GUIFRAME_HEIGHT'] = gui_ph |
---|
127 | try: |
---|
128 | p_size = None |
---|
129 | for panel in self.parent.plot_panels.values(): |
---|
130 | #p_panel = self.parent._mgr.GetPane(panel.window_name) |
---|
131 | width, _ = panel.frame.GetSizeTuple() |
---|
132 | if panel.frame.IsShown(): |
---|
133 | if p_size == None or width > p_size: |
---|
134 | p_size = width |
---|
135 | if p_size == None: |
---|
136 | p_size = CURRENT_STRINGS['PLOPANEL_WIDTH'] |
---|
137 | self.current_string['PLOPANEL_WIDTH'] = p_size |
---|
138 | |
---|
139 | try: |
---|
140 | control_frame = self.parent.get_current_perspective().frame |
---|
141 | control_w, control_h = control_frame.GetSizeTuple() |
---|
142 | self.current_string['CONTROL_WIDTH'] = control_w |
---|
143 | self.current_string['CONTROL_HEIGHT'] = control_h |
---|
144 | except: |
---|
145 | self.current_string['CONTROL_WIDTH'] = -1 |
---|
146 | self.current_string['CONTROL_HEIGHT'] = -1 |
---|
147 | |
---|
148 | data_pw, _ = self.parent.panels["data_panel"].frame.GetSizeTuple() |
---|
149 | if data_pw == None: |
---|
150 | data_pw = CURRENT_STRINGS['DATAPANEL_WIDTH'] |
---|
151 | self.current_string['DATAPANEL_WIDTH'] = data_pw |
---|
152 | |
---|
153 | #label = self.parent._data_panel_menu.GetText() |
---|
154 | label = self.parent.panels['data_panel'].frame.IsShown() |
---|
155 | if label:# == 'Hide Data Explorer': |
---|
156 | self.current_string['DATALOADER_SHOW'] = True |
---|
157 | else: |
---|
158 | self.current_string['DATALOADER_SHOW'] = False |
---|
159 | |
---|
160 | if self.parent._toolbar.IsShown(): |
---|
161 | self.current_string['TOOLBAR_SHOW'] = True |
---|
162 | else: |
---|
163 | self.current_string['TOOLBAR_SHOW'] = False |
---|
164 | |
---|
165 | style = self._gui & GUIFRAME.FLOATING_PANEL |
---|
166 | if style == GUIFRAME.FLOATING_PANEL: |
---|
167 | self.current_string['FIXED_PANEL'] = False |
---|
168 | else: |
---|
169 | self.current_string['FIXED_PANEL'] = True |
---|
170 | |
---|
171 | if self.parent.panels['default'].frame.IsShown(): |
---|
172 | self.current_string['WELCOME_PANEL_SHOW'] = True |
---|
173 | else: |
---|
174 | self.current_string['WELCOME_PANEL_SHOW'] = False |
---|
175 | self.current_string['CLEANUP_PLOT'] = \ |
---|
176 | self.parent.cleanup_plots |
---|
177 | perspective = self.parent.get_current_perspective() |
---|
178 | self.current_string['DEFAULT_PERSPECTIVE'] =\ |
---|
179 | str(perspective.sub_menu) |
---|
180 | location = '' |
---|
181 | temp = self.parent._default_save_location.split("\\") |
---|
182 | for strings in temp: |
---|
183 | location += (strings + "/") |
---|
184 | self.current_string['DEFAULT_OPEN_FOLDER'] = location |
---|
185 | #self.parent._default_save_location.ascii_letters |
---|
186 | |
---|
187 | except: |
---|
188 | raise |
---|
189 | # event object and selection |
---|
190 | self.return_string = self.current_string |
---|
191 | return self.return_string |
---|
192 | |
---|
193 | def write_custom_config(self): |
---|
194 | """ |
---|
195 | Write custom configuration |
---|
196 | """ |
---|
197 | fname = os.path.join(self.path, 'custom_config.py') |
---|
198 | self.write_string(fname, self.return_string) |
---|
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 | |
---|