[adf44c2] | 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 |
---|
[d85c194] | 15 | #import sas.sasgui.guiframe.gui_manager as gui |
---|
| 16 | from sas.sasgui.guiframe.events import StatusEvent |
---|
| 17 | from sas.sasgui.guiframe.gui_style import GUIFRAME |
---|
| 18 | from sas.sasgui.guiframe import gui_manager as CURRENT |
---|
| 19 | from sas.sasgui.guiframe.customdir import SetupCustom |
---|
[adf44c2] | 20 | # default configuration |
---|
[bf0acea] | 21 | DEFAULT_STRINGS = {'GUIFRAME_WIDTH':-1, |
---|
| 22 | 'GUIFRAME_HEIGHT':-1, |
---|
[53f9e40] | 23 | 'CONTROL_WIDTH':-1, |
---|
| 24 | 'CONTROL_HEIGHT':-1, |
---|
[bf0acea] | 25 | 'PLOPANEL_WIDTH':-1, |
---|
| 26 | 'DATAPANEL_WIDTH':-1, |
---|
[adf44c2] | 27 | 'DATALOADER_SHOW':True, |
---|
| 28 | 'TOOLBAR_SHOW':True, |
---|
| 29 | 'FIXED_PANEL':True, |
---|
| 30 | 'WELCOME_PANEL_SHOW':False, |
---|
[f2d9e76] | 31 | 'CLEANUP_PLOT':False, |
---|
[c994f8f] | 32 | 'DEFAULT_PERSPECTIVE':'Fitting', |
---|
[62243ae] | 33 | 'DEFAULT_OPEN_FOLDER': None, |
---|
| 34 | 'SAS_OPENCL': None} |
---|
[026041c] | 35 | try: |
---|
| 36 | CURRENT_STRINGS = {'GUIFRAME_WIDTH':CURRENT.GUIFRAME_WIDTH, |
---|
| 37 | 'GUIFRAME_HEIGHT':CURRENT.GUIFRAME_HEIGHT, |
---|
[53f9e40] | 38 | 'CONTROL_WIDTH':CURRENT.CONTROL_WIDTH, |
---|
| 39 | 'CONTROL_HEIGHT':CURRENT.CONTROL_HEIGHT, |
---|
[026041c] | 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, |
---|
[c994f8f] | 47 | 'DEFAULT_PERSPECTIVE':CURRENT.DEFAULT_PERSPECTIVE, |
---|
[62243ae] | 48 | 'DEFAULT_OPEN_FOLDER':CURRENT.DEFAULT_OPEN_FOLDER, |
---|
| 49 | 'SAS_OPENCL': None} |
---|
[026041c] | 50 | except: |
---|
| 51 | CURRENT_STRINGS = DEFAULT_STRINGS |
---|
[92c6c36] | 52 | FONT_VARIANT = 0 |
---|
| 53 | PANEL_WIDTH = 285 |
---|
| 54 | PANEL_HEIGHT = 215 |
---|
| 55 | |
---|
[adf44c2] | 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 |
---|
[493c90c] | 68 | self.path = SetupCustom().find_dir() |
---|
[adf44c2] | 69 | self._gui = gui |
---|
| 70 | # font size |
---|
| 71 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
[026041c] | 72 | self.current_string = copy.deepcopy(CURRENT_STRINGS) |
---|
[c994f8f] | 73 | self.return_string = copy.deepcopy(DEFAULT_STRINGS) |
---|
[adf44c2] | 74 | # build layout |
---|
| 75 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[062ebef] | 76 | title_text = wx.StaticText(self, id=wx.NewId(), label='Set interface configuration') |
---|
| 77 | |
---|
| 78 | default_bt = wx.RadioButton(self, -1, 'Default View', (15, 30), |
---|
[adf44c2] | 79 | style=wx.RB_GROUP) |
---|
| 80 | default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnDefault) |
---|
| 81 | default_bt.SetValue(True) |
---|
[062ebef] | 82 | current_bt = wx.RadioButton(self, -1, 'Current View', (15, 55)) |
---|
[adf44c2] | 83 | current_bt.SetValue(False) |
---|
| 84 | current_bt.Bind(wx.EVT_RADIOBUTTON, self.OnCurrent) |
---|
[657e52c] | 85 | msg = "\nThis new configuration will take effect when\n" |
---|
| 86 | msg += "running this application next time." |
---|
[062ebef] | 87 | note_txt = wx.StaticText(self, -1, msg, (15, 75)) |
---|
[b3de12a4] | 88 | note_txt.SetForegroundColour("black") |
---|
[f7bead2] | 89 | |
---|
[062ebef] | 90 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
[f7bead2] | 91 | okButton = wx.Button(self, wx.ID_OK, 'Set', size=(70, 25)) |
---|
| 92 | closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel', size=(70, 25)) |
---|
| 93 | hbox.Add(closeButton, 1, wx.RIGHT, 5) |
---|
[adf44c2] | 94 | hbox.Add(okButton, 1, wx.RIGHT, 5) |
---|
[062ebef] | 95 | |
---|
| 96 | vbox.Add(title_text, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10) |
---|
| 97 | vbox.Add(default_bt, 0, wx.LEFT, 20) |
---|
| 98 | vbox.Add(current_bt, 0, wx.LEFT, 20) |
---|
| 99 | vbox.Add(note_txt, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10) |
---|
| 100 | vbox.Add(hbox, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10) |
---|
| 101 | |
---|
[adf44c2] | 102 | self.SetSizer(vbox) |
---|
[062ebef] | 103 | |
---|
[adf44c2] | 104 | |
---|
| 105 | def OnDefault(self, event=None): |
---|
| 106 | """ |
---|
| 107 | Set to default |
---|
| 108 | """ |
---|
| 109 | event.Skip() |
---|
| 110 | # event object and selection |
---|
[026041c] | 111 | self.return_string = copy.deepcopy(DEFAULT_STRINGS) |
---|
| 112 | return self.return_string |
---|
[adf44c2] | 113 | |
---|
| 114 | def OnCurrent(self, event=None): |
---|
| 115 | """ |
---|
| 116 | Set to curent setup |
---|
| 117 | """ |
---|
| 118 | event.Skip() |
---|
[2ad3601] | 119 | if self.parent.IsMaximized(): |
---|
| 120 | gui_pw, gui_ph = (0, 0) |
---|
| 121 | else: |
---|
[6306f2f] | 122 | gui_pw, gui_ph = self.parent.get_window_size() |
---|
[adf44c2] | 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(): |
---|
[ae84427] | 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 |
---|
[adf44c2] | 133 | if p_size == None: |
---|
[026041c] | 134 | p_size = CURRENT_STRINGS['PLOPANEL_WIDTH'] |
---|
[adf44c2] | 135 | self.current_string['PLOPANEL_WIDTH'] = p_size |
---|
| 136 | |
---|
[53f9e40] | 137 | try: |
---|
| 138 | control_frame = self.parent.get_current_perspective().frame |
---|
| 139 | control_w, control_h = control_frame.GetSizeTuple() |
---|
| 140 | self.current_string['CONTROL_WIDTH'] = control_w |
---|
| 141 | self.current_string['CONTROL_HEIGHT'] = control_h |
---|
| 142 | except: |
---|
| 143 | self.current_string['CONTROL_WIDTH'] = -1 |
---|
| 144 | self.current_string['CONTROL_HEIGHT'] = -1 |
---|
| 145 | |
---|
[ae84427] | 146 | data_pw, _ = self.parent.panels["data_panel"].frame.GetSizeTuple() |
---|
[adf44c2] | 147 | if data_pw == None: |
---|
[026041c] | 148 | data_pw = CURRENT_STRINGS['DATAPANEL_WIDTH'] |
---|
[adf44c2] | 149 | self.current_string['DATAPANEL_WIDTH'] = data_pw |
---|
| 150 | |
---|
[6eea960] | 151 | #label = self.parent._data_panel_menu.GetText() |
---|
[ae84427] | 152 | label = self.parent.panels['data_panel'].frame.IsShown() |
---|
[6eea960] | 153 | if label:# == 'Hide Data Explorer': |
---|
[adf44c2] | 154 | self.current_string['DATALOADER_SHOW'] = True |
---|
| 155 | else: |
---|
| 156 | self.current_string['DATALOADER_SHOW'] = False |
---|
| 157 | |
---|
| 158 | if self.parent._toolbar.IsShown(): |
---|
| 159 | self.current_string['TOOLBAR_SHOW'] = True |
---|
| 160 | else: |
---|
| 161 | self.current_string['TOOLBAR_SHOW'] = False |
---|
| 162 | |
---|
| 163 | style = self._gui & GUIFRAME.FLOATING_PANEL |
---|
| 164 | if style == GUIFRAME.FLOATING_PANEL: |
---|
| 165 | self.current_string['FIXED_PANEL'] = False |
---|
| 166 | else: |
---|
| 167 | self.current_string['FIXED_PANEL'] = True |
---|
| 168 | |
---|
[ae84427] | 169 | if self.parent.panels['default'].frame.IsShown(): |
---|
[adf44c2] | 170 | self.current_string['WELCOME_PANEL_SHOW'] = True |
---|
| 171 | else: |
---|
| 172 | self.current_string['WELCOME_PANEL_SHOW'] = False |
---|
[f2d9e76] | 173 | self.current_string['CLEANUP_PLOT'] = \ |
---|
| 174 | self.parent.cleanup_plots |
---|
[adf44c2] | 175 | perspective = self.parent.get_current_perspective() |
---|
[c994f8f] | 176 | self.current_string['DEFAULT_PERSPECTIVE'] =\ |
---|
| 177 | str(perspective.sub_menu) |
---|
| 178 | location = '' |
---|
| 179 | temp = self.parent._default_save_location.split("\\") |
---|
| 180 | for strings in temp: |
---|
| 181 | location += (strings + "/") |
---|
| 182 | self.current_string['DEFAULT_OPEN_FOLDER'] = location |
---|
| 183 | #self.parent._default_save_location.ascii_letters |
---|
[adf44c2] | 184 | |
---|
| 185 | except: |
---|
| 186 | raise |
---|
| 187 | # event object and selection |
---|
[026041c] | 188 | self.return_string = self.current_string |
---|
| 189 | return self.return_string |
---|
[adf44c2] | 190 | |
---|
[f7bead2] | 191 | def write_custom_config(self): |
---|
[adf44c2] | 192 | """ |
---|
[f7bead2] | 193 | Write custom configuration |
---|
[adf44c2] | 194 | """ |
---|
| 195 | fname = os.path.join(self.path, 'custom_config.py') |
---|
[026041c] | 196 | self.write_string(fname, self.return_string) |
---|
[adf44c2] | 197 | |
---|
| 198 | def write_string(self, fname, strings): |
---|
| 199 | """ |
---|
| 200 | Write and Save file |
---|
| 201 | """ |
---|
| 202 | |
---|
| 203 | try: |
---|
| 204 | out_f = open(fname,'w') |
---|
| 205 | except : |
---|
| 206 | raise #RuntimeError, "Error: Can not change the configuration..." |
---|
| 207 | out_f.write("#Application appearance custom configuration\n" ) |
---|
| 208 | for key, item in strings.iteritems(): |
---|
[c994f8f] | 209 | if (key == 'DEFAULT_PERSPECTIVE') or \ |
---|
| 210 | (key == 'DEFAULT_OPEN_FOLDER' and item != None): |
---|
| 211 | out_f.write("%s = \"%s\"\n" % (key,str(item))) |
---|
[adf44c2] | 212 | else: |
---|
| 213 | out_f.write("%s = %s\n" % (key,str(item))) |
---|
| 214 | |
---|
[026041c] | 215 | out_f.close() |
---|
| 216 | |
---|