source: sasview/src/sas/sasgui/guiframe/local_perspectives/plotting/graphAppearance.py @ 1abd19c

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.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 1abd19c was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

Remaining modules refactored

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