[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 |
---|
[493c90c] | 19 | from sans.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', |
---|
| 33 | 'DEFAULT_OPEN_FOLDER': None} |
---|
[026041c] | 34 | try: |
---|
| 35 | CURRENT_STRINGS = {'GUIFRAME_WIDTH':CURRENT.GUIFRAME_WIDTH, |
---|
| 36 | 'GUIFRAME_HEIGHT':CURRENT.GUIFRAME_HEIGHT, |
---|
[53f9e40] | 37 | 'CONTROL_WIDTH':CURRENT.CONTROL_WIDTH, |
---|
| 38 | 'CONTROL_HEIGHT':CURRENT.CONTROL_HEIGHT, |
---|
[026041c] | 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, |
---|
[c994f8f] | 46 | 'DEFAULT_PERSPECTIVE':CURRENT.DEFAULT_PERSPECTIVE, |
---|
| 47 | 'DEFAULT_OPEN_FOLDER':CURRENT.DEFAULT_OPEN_FOLDER} |
---|
[026041c] | 48 | except: |
---|
| 49 | CURRENT_STRINGS = DEFAULT_STRINGS |
---|
[92c6c36] | 50 | FONT_VARIANT = 0 |
---|
| 51 | PANEL_WIDTH = 285 |
---|
| 52 | PANEL_HEIGHT = 215 |
---|
| 53 | |
---|
[adf44c2] | 54 | """ |
---|
| 55 | Dialog to set Appication startup configuration |
---|
| 56 | """ |
---|
| 57 | class StartupConfiguration(wx.Dialog): |
---|
| 58 | """ |
---|
| 59 | Dialog for Startup Configuration |
---|
| 60 | """ |
---|
| 61 | def __init__(self, parent, gui, id=-1, title="Startup Setting"): |
---|
| 62 | wx.Dialog.__init__(self, parent, id, title, |
---|
| 63 | size=(PANEL_WIDTH, PANEL_HEIGHT)) |
---|
| 64 | # parent |
---|
| 65 | self.parent = parent |
---|
[493c90c] | 66 | self.path = SetupCustom().find_dir() |
---|
[adf44c2] | 67 | self._gui = gui |
---|
| 68 | # font size |
---|
| 69 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
[026041c] | 70 | self.current_string = copy.deepcopy(CURRENT_STRINGS) |
---|
[c994f8f] | 71 | self.return_string = copy.deepcopy(DEFAULT_STRINGS) |
---|
[adf44c2] | 72 | # build layout |
---|
| 73 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[062ebef] | 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), |
---|
[adf44c2] | 77 | style=wx.RB_GROUP) |
---|
| 78 | default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnDefault) |
---|
| 79 | default_bt.SetValue(True) |
---|
[062ebef] | 80 | current_bt = wx.RadioButton(self, -1, 'Current View', (15, 55)) |
---|
[adf44c2] | 81 | current_bt.SetValue(False) |
---|
| 82 | current_bt.Bind(wx.EVT_RADIOBUTTON, self.OnCurrent) |
---|
[657e52c] | 83 | msg = "\nThis new configuration will take effect when\n" |
---|
| 84 | msg += "running this application next time." |
---|
[062ebef] | 85 | note_txt = wx.StaticText(self, -1, msg, (15, 75)) |
---|
[b3de12a4] | 86 | note_txt.SetForegroundColour("black") |
---|
[f7bead2] | 87 | |
---|
[062ebef] | 88 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
[f7bead2] | 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) |
---|
[adf44c2] | 92 | hbox.Add(okButton, 1, wx.RIGHT, 5) |
---|
[062ebef] | 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 | |
---|
[adf44c2] | 100 | self.SetSizer(vbox) |
---|
[062ebef] | 101 | |
---|
[adf44c2] | 102 | |
---|
| 103 | def OnDefault(self, event=None): |
---|
| 104 | """ |
---|
| 105 | Set to default |
---|
| 106 | """ |
---|
| 107 | event.Skip() |
---|
| 108 | # event object and selection |
---|
[026041c] | 109 | self.return_string = copy.deepcopy(DEFAULT_STRINGS) |
---|
| 110 | return self.return_string |
---|
[adf44c2] | 111 | |
---|
| 112 | def OnCurrent(self, event=None): |
---|
| 113 | """ |
---|
| 114 | Set to curent setup |
---|
| 115 | """ |
---|
| 116 | event.Skip() |
---|
[2ad3601] | 117 | if self.parent.IsMaximized(): |
---|
| 118 | gui_pw, gui_ph = (0, 0) |
---|
| 119 | else: |
---|
[6306f2f] | 120 | gui_pw, gui_ph = self.parent.get_window_size() |
---|
[adf44c2] | 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(): |
---|
[ae84427] | 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 |
---|
[adf44c2] | 131 | if p_size == None: |
---|
[026041c] | 132 | p_size = CURRENT_STRINGS['PLOPANEL_WIDTH'] |
---|
[adf44c2] | 133 | self.current_string['PLOPANEL_WIDTH'] = p_size |
---|
| 134 | |
---|
[53f9e40] | 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 | |
---|
[ae84427] | 144 | data_pw, _ = self.parent.panels["data_panel"].frame.GetSizeTuple() |
---|
[adf44c2] | 145 | if data_pw == None: |
---|
[026041c] | 146 | data_pw = CURRENT_STRINGS['DATAPANEL_WIDTH'] |
---|
[adf44c2] | 147 | self.current_string['DATAPANEL_WIDTH'] = data_pw |
---|
| 148 | |
---|
[6eea960] | 149 | #label = self.parent._data_panel_menu.GetText() |
---|
[ae84427] | 150 | label = self.parent.panels['data_panel'].frame.IsShown() |
---|
[6eea960] | 151 | if label:# == 'Hide Data Explorer': |
---|
[adf44c2] | 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 | |
---|
[ae84427] | 167 | if self.parent.panels['default'].frame.IsShown(): |
---|
[adf44c2] | 168 | self.current_string['WELCOME_PANEL_SHOW'] = True |
---|
| 169 | else: |
---|
| 170 | self.current_string['WELCOME_PANEL_SHOW'] = False |
---|
[f2d9e76] | 171 | self.current_string['CLEANUP_PLOT'] = \ |
---|
| 172 | self.parent.cleanup_plots |
---|
[adf44c2] | 173 | perspective = self.parent.get_current_perspective() |
---|
[c994f8f] | 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 |
---|
[adf44c2] | 182 | |
---|
| 183 | except: |
---|
| 184 | raise |
---|
| 185 | # event object and selection |
---|
[026041c] | 186 | self.return_string = self.current_string |
---|
| 187 | return self.return_string |
---|
[adf44c2] | 188 | |
---|
[f7bead2] | 189 | def write_custom_config(self): |
---|
[adf44c2] | 190 | """ |
---|
[f7bead2] | 191 | Write custom configuration |
---|
[adf44c2] | 192 | """ |
---|
| 193 | fname = os.path.join(self.path, 'custom_config.py') |
---|
[026041c] | 194 | self.write_string(fname, self.return_string) |
---|
[adf44c2] | 195 | |
---|
| 196 | def write_string(self, fname, strings): |
---|
| 197 | """ |
---|
| 198 | Write and Save file |
---|
| 199 | """ |
---|
| 200 | |
---|
| 201 | try: |
---|
| 202 | out_f = open(fname,'w') |
---|
| 203 | except : |
---|
| 204 | raise #RuntimeError, "Error: Can not change the configuration..." |
---|
| 205 | out_f.write("#Application appearance custom configuration\n" ) |
---|
| 206 | for key, item in strings.iteritems(): |
---|
[c994f8f] | 207 | if (key == 'DEFAULT_PERSPECTIVE') or \ |
---|
| 208 | (key == 'DEFAULT_OPEN_FOLDER' and item != None): |
---|
| 209 | out_f.write("%s = \"%s\"\n" % (key,str(item))) |
---|
[adf44c2] | 210 | else: |
---|
| 211 | out_f.write("%s = %s\n" % (key,str(item))) |
---|
| 212 | |
---|
[026041c] | 213 | out_f.close() |
---|
| 214 | |
---|