source: sasview/sansguiframe/src/sans/guiframe/local_perspectives/plotting/graphAppearance.py @ 67fb83b

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 67fb83b was 67fb83b, checked in by Kieran Campbell <kieranrcampbell@…>, 12 years ago

A gift for pylint

  • Property mode set to 100644
File size: 9.5 KB
Line 
1#!/usr/bin/python
2
3"""
4
5Dialog for general graph appearance
6
7
8/**
9        This software was developed by Institut Laue-Langevin as part of
10        Distributed Data Analysis of Neutron Scattering Experiments (DANSE).
11
12        Copyright 2012 Institut Laue-Langevin
13
14**/
15
16
17"""
18
19import wx
20from danse.common.plottools.SimpleFont import SimpleFont
21
22COLOR = ['black', 'blue', 'green', 'red', 'cyan', 'magenta', 'yellow']
23
24
25class graphAppearance(wx.Frame):
26
27    def __init__(self, parent, title, legend=True):
28        super(graphAppearance, self).__init__(parent, title=title, size=(520, 435))
29
30        self.legend = legend
31
32        self.InitUI()
33        self.Centre()
34        self.Show()
35
36        self.xfont = None
37        self.yfont = None
38
39
40    def InitUI(self):
41
42        panel = wx.Panel(self)
43
44        vbox = wx.BoxSizer(wx.VERTICAL)
45        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
46        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
47
48        xhbox1 = wx.BoxSizer(wx.HORIZONTAL)
49        xhbox2 = wx.BoxSizer(wx.HORIZONTAL)
50        yhbox1 = wx.BoxSizer(wx.HORIZONTAL)
51        yhbox2 = wx.BoxSizer(wx.HORIZONTAL)
52
53
54
55        if self.legend:
56            legendLocText = wx.StaticText(panel, label='Legend location: ')
57            self.legend_loc_combo = wx.ComboBox(panel,style = wx.CB_READONLY, size=(180,-1))
58            self.fillLegendLocs()
59        else:
60            self.legend_loc_combo = None
61
62
63        if self.legend:
64            self.toggle_legend = wx.CheckBox(panel, label='Toggle legend on/off')
65        else:
66            self.toggle_legend = None
67
68        self.toggle_grid = wx.CheckBox(panel, label='Toggle grid on/off')
69
70       
71        xstatic_box = wx.StaticBox(panel, -1, 'x-axis label')
72        xstatic_box_sizer = wx.StaticBoxSizer(xstatic_box, wx.VERTICAL)
73        ystatic_box = wx.StaticBox(panel, -1, 'y-axis label')
74        ystatic_box_sizer = wx.StaticBoxSizer(ystatic_box, wx.VERTICAL)
75
76
77        xaxis_label = wx.StaticText(panel, label='X-axis: ')
78        yaxis_label = wx.StaticText(panel, label='Y-axis: ')
79        unitlabel_1 = wx.StaticText(panel, label='Units: ')
80        unitlabel_2 = wx.StaticText(panel, label='Units: ')
81
82        self.xaxis_text = wx.TextCtrl(panel, -1, "",size=(220, -1))
83        self.yaxis_text = wx.TextCtrl(panel, -1, "",size=(220, -1))
84
85        self.xaxis_unit_text = wx.TextCtrl(panel, -1,"",size=(100, -1))
86        self.yaxis_unit_text = wx.TextCtrl(panel, -1,"",size=(100, -1))
87
88
89
90        xcolorLabel = wx.StaticText(panel, label='Font color: ')
91        self.xfont_color = wx.ComboBox(panel, size=(100, -1), style=wx.CB_READONLY)
92        self.xfill_colors()
93        self.xfont_color.SetSelection(0)
94        xfont_button = wx.Button(panel, label='Font')
95        xfont_button.Bind(wx.EVT_BUTTON, self.onxFont)
96
97        ycolorLabel = wx.StaticText(panel, label='Font color: ')
98        self.yfont_color = wx.ComboBox(panel, size=(100, -1),style=wx.CB_READONLY)
99        self.yfill_colors()
100        self.yfont_color.SetSelection(0)
101        yfont_button = wx.Button(panel, label='Font')
102        yfont_button.Bind(wx.EVT_BUTTON, self.onyFont)
103
104       
105
106        self.cancel_button = wx.Button(panel, label='Cancel')
107        self.ok_button = wx.Button(panel, label='OK')
108
109        self.cancel_button.Bind(wx.EVT_BUTTON, self.onCancel)
110        self.ok_button.Bind(wx.EVT_BUTTON, self.on_ok)
111
112
113        xhbox1.Add(xaxis_label, flag= wx.ALL | wx.EXPAND  | wx.ALIGN_LEFT, border=10)
114        xhbox1.Add(self.xaxis_text, flag=wx.ALL | wx.EXPAND  | wx.ALIGN_LEFT, border=10)
115        xhbox1.Add(unitlabel_1, flag=wx.ALL | wx.EXPAND  | wx.ALIGN_RIGHT, border=10)
116        xhbox1.Add(self.xaxis_unit_text, flag=wx.ALL | wx.EXPAND  | wx.ALIGN_RIGHT, border=10)
117
118        yhbox1.Add(yaxis_label, flag= wx.ALL | wx.EXPAND  | wx.ALIGN_LEFT, border=10)
119        yhbox1.Add(self.yaxis_text, flag=wx.ALL | wx.EXPAND  | wx.ALIGN_LEFT, border=10)
120        yhbox1.Add(unitlabel_2, flag=wx.ALL | wx.EXPAND  | wx.ALIGN_RIGHT, border=10)
121        yhbox1.Add(self.yaxis_unit_text, flag=wx.ALL | wx.EXPAND  | wx.ALIGN_RIGHT, border=10)
122
123        xhbox2.Add(xcolorLabel, flag=wx.ALL | wx.ALIGN_RIGHT, border=10)
124        xhbox2.Add(self.xfont_color, flag=wx.ALL | wx.ALIGN_RIGHT, border=5)
125        xhbox2.Add(xfont_button, flag=wx.ALL | wx.ALIGN_RIGHT, border=5)
126
127        yhbox2.Add(ycolorLabel, flag=wx.ALL | wx.ALIGN_RIGHT, border=10)
128        yhbox2.Add(self.yfont_color, flag=wx.ALL | wx.ALIGN_RIGHT, border=5)
129        yhbox2.Add(yfont_button, flag=wx.ALL | wx.ALIGN_RIGHT, border=5)
130
131        if self.legend:
132            hbox1.Add(legendLocText, flag =  wx.ALL | wx.EXPAND  | wx.ALIGN_LEFT, border=5)
133            hbox1.Add(self.legend_loc_combo, flag =  wx.ALL | wx.EXPAND  | wx.ALIGN_LEFT, border=5)
134
135        if self.legend:
136            hbox1.Add((5, -1))
137            hbox1.Add(self.toggle_legend, flag = wx.ALL | wx.EXPAND  | wx.ALIGN_LEFT, border=5)
138
139        hbox2.Add(self.ok_button, flag = wx.ALL | wx.ALIGN_RIGHT, border=5)
140        hbox2.Add(self.cancel_button, flag = wx.ALL | wx.ALIGN_RIGHT, border=5)
141        hbox2.Add((15, -1))
142
143        xstatic_box_sizer.Add(xhbox1, flag= wx.EXPAND , border=5)
144        xstatic_box_sizer.Add(xhbox2, flag=wx.ALL | wx.ALIGN_RIGHT, border=5)
145        ystatic_box_sizer.Add(yhbox1, flag= wx.EXPAND, border=5)
146        ystatic_box_sizer.Add(yhbox2, flag=wx.ALL | wx.ALIGN_RIGHT, border=5)
147
148        vbox.Add((-1, 20))
149        vbox.Add(hbox1, flag = wx.EXPAND | wx.ALL, border=5)
150        vbox.Add(xstatic_box_sizer, flag = wx.ALL | wx.EXPAND, border=10)
151        vbox.Add(ystatic_box_sizer, flag = wx.ALL | wx.EXPAND, border=10)
152
153        vbox.Add(self.toggle_grid, flag = wx.ALIGN_RIGHT | wx.RIGHT, border=20)
154        vbox.Add(hbox2, flag = wx.ALIGN_RIGHT | wx.ALL , border=5)
155
156
157        panel.SetSizer(vbox)
158
159    def xfill_colors(self):
160        c_list = COLOR
161        for idx in range(len(c_list)):
162            self.xfont_color.Append(c_list[idx], idx)
163
164    def yfill_colors(self):
165        c_list = COLOR
166        for idx in range(len(c_list)):
167            self.yfont_color.Append(c_list[idx], idx)
168
169    def onxFont(self, e):
170        title = 'Modify x axis font'
171
172        fonty = SimpleFont(self, wx.NewId(), title)
173        fonty.set_default_font(self.xfont)
174        if(fonty.ShowModal() == wx.ID_OK):
175            self.xfont = fonty.get_font()
176
177    def onyFont(self, e):
178        title = 'Modify y axis font'
179        fonty = SimpleFont(self, wx.NewId(), title)
180        fonty.set_default_font(self.yfont)
181        if(fonty.ShowModal() == wx.ID_OK):
182            self.yfont = fonty.get_font()
183
184    def on_ok(self, e):
185        self.Close()
186
187    def onCancel(self, e):
188        self.Destroy()
189
190
191    def get_loc_label(self):
192        """
193        Associates label to a specific legend location
194        """
195        _labels = {}
196        i = 0
197        _labels['best'] = i
198        i += 1
199        _labels['upper right'] = i
200        i += 1
201        _labels['upper left'] = i
202        i += 1
203        _labels['lower left'] = i
204        i += 1
205        _labels['lower right'] = i
206        i += 1
207        _labels['right'] = i
208        i += 1
209        _labels['center left'] = i
210        i += 1
211        _labels['center right'] = i
212        i += 1
213        _labels['lower center'] = i
214        i += 1
215        _labels['upper center'] = i
216        i += 1
217        _labels['center'] = i
218        return _labels
219
220
221    def fillLegendLocs(self):
222
223        # labels = []
224        # for label in self.get_loc_label():
225        #     labels.append(str(label))
226
227        # for label in reversed(labels):
228        #     self.legend_loc_combo.Append(label)
229        for label in self.get_loc_label():
230            self.legend_loc_combo.Append(label)
231
232
233    def setDefaults(self,grid,legend,xlab,ylab,xunit,yunit,
234                    xaxis_font,yaxis_font,legend_loc,
235                    xcolor,ycolor):
236        self.toggle_grid.SetValue(grid)
237        if self.legend:
238            self.toggle_legend.SetValue(legend)
239        self.xaxis_text.SetValue(xlab)
240        self.yaxis_text.SetValue(ylab)
241        self.xaxis_unit_text.SetValue(xunit)
242        self.yaxis_unit_text.SetValue(yunit)
243        self.xfont = xaxis_font
244        self.yfont = yaxis_font
245
246        if not xcolor:
247            self.xfont_color.SetSelection(0)
248        else:
249            self.xfont_color.SetStringSelection(xcolor)
250
251        if not ycolor:
252            self.yfont_color.SetSelection(0)
253        else:
254            self.yfont_color.SetStringSelection(ycolor)
255           
256
257        if self.legend:
258            self.legend_loc_combo.SetStringSelection(legend_loc)
259
260
261    # get whether grid is toggled on/off
262    def get_togglegrid(self):
263        return self.toggle_grid.GetValue()
264
265    # get whether legend is toggled on/off
266    def get_togglelegend(self):
267        return self.toggle_legend.GetValue()
268
269    # get x label
270    def get_xlab(self):
271        return self.xaxis_text.GetValue()
272
273    # get y label
274    def get_ylab(self):
275        return self.yaxis_text.GetValue()
276
277    # get x unit
278    def get_xunit(self):
279        return self.xaxis_unit_text.GetValue()
280
281    # get y unit
282    def get_yunit(self):
283        return self.yaxis_unit_text.GetValue()
284
285    # get legend location
286    def get_legend_loc(self):
287        return self.get_loc_label()[self.legend_loc_combo.GetStringSelection()]
288
289    # get x axis label color
290    def get_xcolor(self):
291        return self.xfont_color.GetValue()
292
293    # get y axis label color
294    def get_ycolor(self):
295        return self.yfont_color.GetValue()
296
297    # get x axis font (type is FontProperties)
298    def get_xfont(self):
299        return self.xfont
300
301    # get y axis font
302    def get_yfont(self):
303        return self.yfont
304   
305
306if __name__ == '__main__':
307
308    app = wx.App()
309    graphD = graphAppearance(None,title='Modify graph appearance')
310    app.MainLoop()
311
312
313
Note: See TracBrowser for help on using the repository browser.