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 os |
---|
12 | import copy |
---|
13 | |
---|
14 | import wx |
---|
15 | |
---|
16 | from sas.sasgui.customdir import get_custom_config_path |
---|
17 | from sas.sasgui.guiframe.gui_style import GUIFRAME |
---|
18 | from sas.sasgui.guiframe import gui_manager as CURRENT |
---|
19 | |
---|
20 | |
---|
21 | # default configuration |
---|
22 | DEFAULT_STRINGS = {'GUIFRAME_WIDTH':-1, |
---|
23 | 'GUIFRAME_HEIGHT':-1, |
---|
24 | 'CONTROL_WIDTH':-1, |
---|
25 | 'CONTROL_HEIGHT':-1, |
---|
26 | 'PLOPANEL_WIDTH':-1, |
---|
27 | 'DATAPANEL_WIDTH':-1, |
---|
28 | 'DATALOADER_SHOW':True, |
---|
29 | 'TOOLBAR_SHOW':True, |
---|
30 | 'FIXED_PANEL':True, |
---|
31 | 'WELCOME_PANEL_SHOW':False, |
---|
32 | 'CLEANUP_PLOT':False, |
---|
33 | 'DEFAULT_PERSPECTIVE':'Fitting', |
---|
34 | 'DEFAULT_OPEN_FOLDER': 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 | except: |
---|
50 | CURRENT_STRINGS = DEFAULT_STRINGS |
---|
51 | FONT_VARIANT = 0 |
---|
52 | PANEL_WIDTH = 285 |
---|
53 | PANEL_HEIGHT = 215 |
---|
54 | |
---|
55 | """ |
---|
56 | Dialog to set Appication startup configuration |
---|
57 | """ |
---|
58 | class StartupConfiguration(wx.Dialog): |
---|
59 | """ |
---|
60 | Dialog for Startup Configuration |
---|
61 | """ |
---|
62 | def __init__(self, parent, gui, id=-1, title="Startup Setting"): |
---|
63 | wx.Dialog.__init__(self, parent, id, title, |
---|
64 | size=(PANEL_WIDTH, PANEL_HEIGHT)) |
---|
65 | # parent |
---|
66 | self.parent = parent |
---|
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 | path = get_custom_config_path() |
---|
194 | with open(path, 'w') as out_f: |
---|
195 | out_f.write("#Application appearance custom configuration\n" ) |
---|
196 | for key, item in self.return_string.iteritems(): |
---|
197 | if (key == 'DEFAULT_PERSPECTIVE') or \ |
---|
198 | (key == 'DEFAULT_OPEN_FOLDER' and item != None): |
---|
199 | out_f.write("%s = \"%s\"\n" % (key,str(item))) |
---|
200 | else: |
---|
201 | out_f.write("%s = %s\n" % (key,str(item))) |
---|