[959eb01] | 1 | ################################################################################ |
---|
| 2 | #This software was developed by the University of Tennessee as part of the |
---|
| 3 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
[914ba0a] | 4 | #project funded by the US National Science Foundation. |
---|
[959eb01] | 5 | # |
---|
| 6 | #See the license text in license.txt |
---|
| 7 | # |
---|
| 8 | #copyright 2009, University of Tennessee |
---|
| 9 | ################################################################################ |
---|
| 10 | import os |
---|
| 11 | import copy |
---|
[914ba0a] | 12 | |
---|
| 13 | import wx |
---|
| 14 | |
---|
| 15 | from sas.sasgui import get_custom_config_path |
---|
| 16 | from sas.sasgui.guiframe.events import StatusEvent |
---|
[959eb01] | 17 | from sas.sasgui.guiframe.gui_style import GUIFRAME |
---|
| 18 | from sas.sasgui.guiframe import gui_manager as CURRENT |
---|
[914ba0a] | 19 | |
---|
| 20 | |
---|
[959eb01] | 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 | 'SAS_OPENCL': None} |
---|
| 36 | try: |
---|
| 37 | CURRENT_STRINGS = {'GUIFRAME_WIDTH':CURRENT.GUIFRAME_WIDTH, |
---|
| 38 | 'GUIFRAME_HEIGHT':CURRENT.GUIFRAME_HEIGHT, |
---|
| 39 | 'CONTROL_WIDTH':CURRENT.CONTROL_WIDTH, |
---|
| 40 | 'CONTROL_HEIGHT':CURRENT.CONTROL_HEIGHT, |
---|
| 41 | 'PLOPANEL_WIDTH':CURRENT.PLOPANEL_WIDTH, |
---|
| 42 | 'DATAPANEL_WIDTH':CURRENT.DATAPANEL_WIDTH, |
---|
| 43 | 'DATALOADER_SHOW':CURRENT.DATALOADER_SHOW, |
---|
| 44 | 'TOOLBAR_SHOW':CURRENT.TOOLBAR_SHOW, |
---|
| 45 | 'FIXED_PANEL':CURRENT.FIXED_PANEL, |
---|
| 46 | 'WELCOME_PANEL_SHOW':CURRENT.WELCOME_PANEL_SHOW, |
---|
| 47 | 'CLEANUP_PLOT':CURRENT.CLEANUP_PLOT, |
---|
| 48 | 'DEFAULT_PERSPECTIVE':CURRENT.DEFAULT_PERSPECTIVE, |
---|
| 49 | 'DEFAULT_OPEN_FOLDER':CURRENT.DEFAULT_OPEN_FOLDER, |
---|
| 50 | 'SAS_OPENCL': None} |
---|
| 51 | except: |
---|
| 52 | CURRENT_STRINGS = DEFAULT_STRINGS |
---|
| 53 | FONT_VARIANT = 0 |
---|
| 54 | PANEL_WIDTH = 285 |
---|
| 55 | PANEL_HEIGHT = 215 |
---|
| 56 | |
---|
| 57 | """ |
---|
| 58 | Dialog to set Appication startup configuration |
---|
| 59 | """ |
---|
| 60 | class StartupConfiguration(wx.Dialog): |
---|
| 61 | """ |
---|
| 62 | Dialog for Startup Configuration |
---|
| 63 | """ |
---|
| 64 | def __init__(self, parent, gui, id=-1, title="Startup Setting"): |
---|
[914ba0a] | 65 | wx.Dialog.__init__(self, parent, id, title, |
---|
[959eb01] | 66 | size=(PANEL_WIDTH, PANEL_HEIGHT)) |
---|
| 67 | # parent |
---|
| 68 | self.parent = parent |
---|
| 69 | self._gui = gui |
---|
[914ba0a] | 70 | # font size |
---|
[959eb01] | 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 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 76 | title_text = wx.StaticText(self, id=wx.NewId(), label='Set interface configuration') |
---|
| 77 | |
---|
[914ba0a] | 78 | default_bt = wx.RadioButton(self, -1, 'Default View', (15, 30), |
---|
[959eb01] | 79 | style=wx.RB_GROUP) |
---|
| 80 | default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnDefault) |
---|
| 81 | default_bt.SetValue(True) |
---|
| 82 | current_bt = wx.RadioButton(self, -1, 'Current View', (15, 55)) |
---|
| 83 | current_bt.SetValue(False) |
---|
| 84 | current_bt.Bind(wx.EVT_RADIOBUTTON, self.OnCurrent) |
---|
| 85 | msg = "\nThis new configuration will take effect when\n" |
---|
| 86 | msg += "running this application next time." |
---|
| 87 | note_txt = wx.StaticText(self, -1, msg, (15, 75)) |
---|
| 88 | note_txt.SetForegroundColour("black") |
---|
[914ba0a] | 89 | |
---|
[959eb01] | 90 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 91 | okButton = wx.Button(self, wx.ID_OK, 'Set', size=(70, 25)) |
---|
[914ba0a] | 92 | closeButton = wx.Button(self, wx.ID_CANCEL, 'Cancel', size=(70, 25)) |
---|
[959eb01] | 93 | hbox.Add(closeButton, 1, wx.RIGHT, 5) |
---|
| 94 | hbox.Add(okButton, 1, wx.RIGHT, 5) |
---|
| 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 | |
---|
| 102 | self.SetSizer(vbox) |
---|
| 103 | |
---|
[914ba0a] | 104 | |
---|
[959eb01] | 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 |
---|
[914ba0a] | 113 | |
---|
[959eb01] | 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(): |
---|
[235f514] | 131 | if p_size is None or width > p_size: |
---|
[959eb01] | 132 | p_size = width |
---|
[235f514] | 133 | if p_size is None: |
---|
[959eb01] | 134 | p_size = CURRENT_STRINGS['PLOPANEL_WIDTH'] |
---|
| 135 | self.current_string['PLOPANEL_WIDTH'] = p_size |
---|
[914ba0a] | 136 | |
---|
[959eb01] | 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 |
---|
[914ba0a] | 145 | |
---|
[959eb01] | 146 | data_pw, _ = self.parent.panels["data_panel"].frame.GetSizeTuple() |
---|
[235f514] | 147 | if data_pw is None: |
---|
[959eb01] | 148 | data_pw = CURRENT_STRINGS['DATAPANEL_WIDTH'] |
---|
| 149 | self.current_string['DATAPANEL_WIDTH'] = data_pw |
---|
[914ba0a] | 150 | |
---|
[959eb01] | 151 | #label = self.parent._data_panel_menu.GetText() |
---|
| 152 | label = self.parent.panels['data_panel'].frame.IsShown() |
---|
| 153 | if label:# == 'Hide Data Explorer': |
---|
| 154 | self.current_string['DATALOADER_SHOW'] = True |
---|
| 155 | else: |
---|
| 156 | self.current_string['DATALOADER_SHOW'] = False |
---|
[914ba0a] | 157 | |
---|
[959eb01] | 158 | if self.parent._toolbar.IsShown(): |
---|
| 159 | self.current_string['TOOLBAR_SHOW'] = True |
---|
| 160 | else: |
---|
| 161 | self.current_string['TOOLBAR_SHOW'] = False |
---|
[914ba0a] | 162 | |
---|
[959eb01] | 163 | style = self._gui & GUIFRAME.FLOATING_PANEL |
---|
[914ba0a] | 164 | if style == GUIFRAME.FLOATING_PANEL: |
---|
[959eb01] | 165 | self.current_string['FIXED_PANEL'] = False |
---|
| 166 | else: |
---|
| 167 | self.current_string['FIXED_PANEL'] = True |
---|
[914ba0a] | 168 | |
---|
[959eb01] | 169 | if self.parent.panels['default'].frame.IsShown(): |
---|
| 170 | self.current_string['WELCOME_PANEL_SHOW'] = True |
---|
| 171 | else: |
---|
| 172 | self.current_string['WELCOME_PANEL_SHOW'] = False |
---|
| 173 | self.current_string['CLEANUP_PLOT'] = \ |
---|
| 174 | self.parent.cleanup_plots |
---|
| 175 | perspective = self.parent.get_current_perspective() |
---|
| 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 |
---|
[914ba0a] | 184 | |
---|
[959eb01] | 185 | except: |
---|
| 186 | raise |
---|
| 187 | # event object and selection |
---|
| 188 | self.return_string = self.current_string |
---|
| 189 | return self.return_string |
---|
| 190 | |
---|
[914ba0a] | 191 | |
---|
| 192 | def write_custom_config(self): |
---|
[959eb01] | 193 | """ |
---|
[914ba0a] | 194 | Write custom configuration |
---|
[959eb01] | 195 | """ |
---|
[914ba0a] | 196 | path = get_custom_config_path() |
---|
| 197 | with open(path, 'w') as out_f: |
---|
| 198 | out_f.write("#Application appearance custom configuration\n") |
---|
| 199 | for key, item in self.return_string.iteritems(): |
---|
| 200 | if (key == 'DEFAULT_PERSPECTIVE') or \ |
---|
| 201 | (key == 'DEFAULT_OPEN_FOLDER' and item != None): |
---|
| 202 | out_f.write("%s = \"%s\"\n" % (key, str(item))) |
---|
| 203 | else: |
---|
| 204 | out_f.write("%s = %s\n" % (key, str(item))) |
---|