source: sasview/guiframe/startup_configuration.py @ 9d8f193

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 9d8f193 was 9d8f193, checked in by Jae Cho <jhjcho@…>, 13 years ago

minor fix on Setting View

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