[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 |
---|
| 15 | #import sans.guiframe.gui_manager as gui |
---|
| 16 | from sans.guiframe.events import StatusEvent |
---|
| 17 | from sans.guiframe.gui_style import GUIFRAME |
---|
[026041c] | 18 | from sans.guiframe import gui_manager as CURRENT |
---|
[adf44c2] | 19 | # default configuration |
---|
| 20 | DEFAULT_STRINGS = {'GUIFRAME_WIDTH':1150, |
---|
| 21 | 'GUIFRAME_HEIGHT':840, |
---|
| 22 | 'PLOPANEL_WIDTH':415, |
---|
| 23 | 'DATAPANEL_WIDTH':235, |
---|
| 24 | 'DATALOADER_SHOW':True, |
---|
| 25 | 'TOOLBAR_SHOW':True, |
---|
| 26 | 'FIXED_PANEL':True, |
---|
| 27 | 'WELCOME_PANEL_SHOW':False, |
---|
[f2d9e76] | 28 | 'CLEANUP_PLOT':False, |
---|
[adf44c2] | 29 | 'DEFAULT_PERSPECTIVE':'Fitting'} |
---|
[026041c] | 30 | try: |
---|
| 31 | CURRENT_STRINGS = {'GUIFRAME_WIDTH':CURRENT.GUIFRAME_WIDTH, |
---|
| 32 | 'GUIFRAME_HEIGHT':CURRENT.GUIFRAME_HEIGHT, |
---|
| 33 | 'PLOPANEL_WIDTH':CURRENT.PLOPANEL_WIDTH, |
---|
| 34 | 'DATAPANEL_WIDTH':CURRENT.DATAPANEL_WIDTH, |
---|
| 35 | 'DATALOADER_SHOW':CURRENT.DATALOADER_SHOW, |
---|
| 36 | 'TOOLBAR_SHOW':CURRENT.TOOLBAR_SHOW, |
---|
| 37 | 'FIXED_PANEL':CURRENT.FIXED_PANEL, |
---|
| 38 | 'WELCOME_PANEL_SHOW':CURRENT.WELCOME_PANEL_SHOW, |
---|
| 39 | 'CLEANUP_PLOT':CURRENT.CLEANUP_PLOT, |
---|
| 40 | 'DEFAULT_PERSPECTIVE':CURRENT.DEFAULT_PERSPECTIVE} |
---|
| 41 | except: |
---|
| 42 | CURRENT_STRINGS = DEFAULT_STRINGS |
---|
| 43 | |
---|
[adf44c2] | 44 | if sys.platform.count("win32") > 0: |
---|
| 45 | PANEL_WIDTH = 265 |
---|
| 46 | PANEL_HEIGHT = 235 |
---|
| 47 | FONT_VARIANT = 0 |
---|
| 48 | else: |
---|
| 49 | PANEL_WIDTH = 285 |
---|
| 50 | PANEL_HEIGHT = 255 |
---|
| 51 | FONT_VARIANT = 1 |
---|
| 52 | |
---|
| 53 | """ |
---|
| 54 | Dialog to set Appication startup configuration |
---|
| 55 | """ |
---|
| 56 | class StartupConfiguration(wx.Dialog): |
---|
| 57 | """ |
---|
| 58 | Dialog for Startup Configuration |
---|
| 59 | """ |
---|
| 60 | def __init__(self, parent, gui, id=-1, title="Startup Setting"): |
---|
| 61 | wx.Dialog.__init__(self, parent, id, title, |
---|
| 62 | size=(PANEL_WIDTH, PANEL_HEIGHT)) |
---|
| 63 | # parent |
---|
| 64 | self.parent = parent |
---|
| 65 | self.path = parent.path |
---|
| 66 | self._gui = gui |
---|
| 67 | # font size |
---|
| 68 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
[026041c] | 69 | self.current_string = copy.deepcopy(CURRENT_STRINGS) |
---|
| 70 | self.return_string = {} |
---|
[adf44c2] | 71 | # build layout |
---|
| 72 | panel = wx.Panel(self, -1) |
---|
| 73 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[9d8f193] | 74 | wx.StaticBox(panel, -1, 'Set View-Configuration', (5, 5), |
---|
[adf44c2] | 75 | (PANEL_WIDTH*0.94, PANEL_HEIGHT*0.7)) |
---|
| 76 | default_bt = wx.RadioButton(panel, -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(panel, -1, 'Current View', (15, 55)) |
---|
| 81 | current_bt.SetValue(False) |
---|
| 82 | current_bt.Bind(wx.EVT_RADIOBUTTON, self.OnCurrent) |
---|
[b3de12a4] | 83 | msg = "\nThis new configuration will take effect after\n" |
---|
[f2d9e76] | 84 | msg += "restarting the SansView application..." |
---|
[adf44c2] | 85 | note_txt = wx.StaticText(panel, -1, msg, (15, 75)) |
---|
[b3de12a4] | 86 | note_txt.SetForegroundColour("black") |
---|
[adf44c2] | 87 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 88 | cancelButton = wx.Button(self, -1, 'Cancel', size=(70, 25)) |
---|
| 89 | hbox.Add(cancelButton, 1, wx.RIGHT, 5) |
---|
| 90 | cancelButton.Bind(wx.EVT_BUTTON, self.OnCancel) |
---|
| 91 | okButton = wx.Button(self, -1, 'OK', size=(70, 25)) |
---|
| 92 | hbox.Add(okButton, 1, wx.RIGHT, 5) |
---|
| 93 | okButton.Bind(wx.EVT_BUTTON, self.OnClose) |
---|
| 94 | vbox.Add(panel) |
---|
| 95 | |
---|
| 96 | vbox.Add(hbox, 1, wx.ALIGN_CENTER | wx.RIGHT | wx.BOTTOM, 5) |
---|
| 97 | # set sizer |
---|
| 98 | self.SetSizer(vbox) |
---|
| 99 | #pos = self.parent.GetPosition() |
---|
| 100 | #self.SetPosition(pos) |
---|
| 101 | |
---|
| 102 | def OnDefault(self, event=None): |
---|
| 103 | """ |
---|
| 104 | Set to default |
---|
| 105 | """ |
---|
| 106 | event.Skip() |
---|
| 107 | # event object and selection |
---|
[026041c] | 108 | self.return_string = copy.deepcopy(DEFAULT_STRINGS) |
---|
| 109 | return self.return_string |
---|
[adf44c2] | 110 | |
---|
| 111 | def OnCurrent(self, event=None): |
---|
| 112 | """ |
---|
| 113 | Set to curent setup |
---|
| 114 | """ |
---|
| 115 | event.Skip() |
---|
| 116 | |
---|
| 117 | gui_pw, gui_ph = self.parent.GetSizeTuple() |
---|
| 118 | self.current_string['GUIFRAME_WIDTH'] = gui_pw |
---|
| 119 | self.current_string['GUIFRAME_HEIGHT'] = gui_ph |
---|
| 120 | try: |
---|
| 121 | p_size = None |
---|
| 122 | for panel in self.parent.plot_panels.values(): |
---|
[f2d9e76] | 123 | p_panel = self.parent._mgr.GetPane(panel.window_name) |
---|
| 124 | if p_panel.IsShown(): |
---|
| 125 | if p_size == None or panel.size > p_size: |
---|
| 126 | p_size = panel.size |
---|
[adf44c2] | 127 | if p_size == None: |
---|
[026041c] | 128 | p_size = CURRENT_STRINGS['PLOPANEL_WIDTH'] |
---|
[adf44c2] | 129 | self.current_string['PLOPANEL_WIDTH'] = p_size |
---|
| 130 | |
---|
| 131 | data_pw, _ = self.parent.panels["data_panel"].GetSizeTuple() |
---|
| 132 | if data_pw == None: |
---|
[026041c] | 133 | data_pw = CURRENT_STRINGS['DATAPANEL_WIDTH'] |
---|
[adf44c2] | 134 | self.current_string['DATAPANEL_WIDTH'] = data_pw |
---|
| 135 | |
---|
[6eea960] | 136 | #label = self.parent._data_panel_menu.GetText() |
---|
| 137 | label = self.parent._mgr.GetPane(\ |
---|
| 138 | self.parent.panels['data_panel'].window_name).IsShown() |
---|
| 139 | if label:# == 'Hide Data Explorer': |
---|
[adf44c2] | 140 | self.current_string['DATALOADER_SHOW'] = True |
---|
| 141 | else: |
---|
| 142 | self.current_string['DATALOADER_SHOW'] = False |
---|
| 143 | |
---|
| 144 | if self.parent._toolbar.IsShown(): |
---|
| 145 | self.current_string['TOOLBAR_SHOW'] = True |
---|
| 146 | else: |
---|
| 147 | self.current_string['TOOLBAR_SHOW'] = False |
---|
| 148 | |
---|
| 149 | style = self._gui & GUIFRAME.FLOATING_PANEL |
---|
| 150 | if style == GUIFRAME.FLOATING_PANEL: |
---|
| 151 | self.current_string['FIXED_PANEL'] = False |
---|
| 152 | else: |
---|
| 153 | self.current_string['FIXED_PANEL'] = True |
---|
| 154 | |
---|
| 155 | if self.parent._mgr.GetPane(self.parent.panels['default'].window_name).IsShown(): |
---|
| 156 | self.current_string['WELCOME_PANEL_SHOW'] = True |
---|
| 157 | else: |
---|
| 158 | self.current_string['WELCOME_PANEL_SHOW'] = False |
---|
[f2d9e76] | 159 | self.current_string['CLEANUP_PLOT'] = \ |
---|
| 160 | self.parent.cleanup_plots |
---|
[adf44c2] | 161 | perspective = self.parent.get_current_perspective() |
---|
| 162 | self.current_string['DEFAULT_PERSPECTIVE'] = str(perspective.sub_menu) |
---|
| 163 | |
---|
| 164 | except: |
---|
| 165 | raise |
---|
| 166 | # event object and selection |
---|
[026041c] | 167 | self.return_string = self.current_string |
---|
| 168 | return self.return_string |
---|
[adf44c2] | 169 | |
---|
| 170 | def OnCancel(self, event): |
---|
| 171 | """ |
---|
| 172 | Close event |
---|
| 173 | """ |
---|
| 174 | # clear event |
---|
| 175 | event.Skip() |
---|
[026041c] | 176 | self.return_string = {} |
---|
[adf44c2] | 177 | self.Destroy() |
---|
| 178 | |
---|
| 179 | def OnClose(self, event): |
---|
| 180 | """ |
---|
| 181 | Close event |
---|
| 182 | """ |
---|
| 183 | # clear event |
---|
| 184 | event.Skip() |
---|
| 185 | fname = os.path.join(self.path, 'custom_config.py') |
---|
[026041c] | 186 | self.write_string(fname, self.return_string) |
---|
[adf44c2] | 187 | |
---|
| 188 | self.Destroy() |
---|
| 189 | |
---|
| 190 | def write_string(self, fname, strings): |
---|
| 191 | """ |
---|
| 192 | Write and Save file |
---|
| 193 | """ |
---|
| 194 | |
---|
| 195 | try: |
---|
| 196 | out_f = open(fname,'w') |
---|
| 197 | except : |
---|
| 198 | raise #RuntimeError, "Error: Can not change the configuration..." |
---|
| 199 | out_f.write("#Application appearance custom configuration\n" ) |
---|
| 200 | for key, item in strings.iteritems(): |
---|
| 201 | if key == 'DEFAULT_PERSPECTIVE': |
---|
| 202 | out_f.write("%s = '%s'\n" % (key,str(item))) |
---|
| 203 | else: |
---|
| 204 | out_f.write("%s = %s\n" % (key,str(item))) |
---|
| 205 | |
---|
[026041c] | 206 | out_f.close() |
---|
| 207 | |
---|