source: sasview/sansguiframe/src/sans/guiframe/local_perspectives/plotting/appearanceDialog.py @ f8be87d

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

Changes to include 1D appearance dialog

  • Property mode set to 100644
File size: 8.1 KB
Line 
1#!/usr/bin/python
2
3"""
4
5Appearance of graph symbols and legend label dialog.
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
20import operator
21
22
23# main appearance dialog starts here:
24
25
26class appearanceDialog(wx.Frame):
27
28    def __init__(self,parent,title):
29        super(appearanceDialog,self).__init__(parent, title=title,size=(570,400))
30
31        self.okay_clicked = False
32
33        self.symbolLabels = self.get_symbol_label()
34        self.colorLabels = self.get_color_label()
35
36
37        self.InitUI()
38        self.Centre()
39        self.Show()
40
41 
42    def InitUI(self):
43
44        # create spacing needed
45        panel = wx.Panel(self)
46
47        vbox = wx.BoxSizer(wx.VERTICAL)
48
49        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
50        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
51        hbox3 = wx.BoxSizer(wx.HORIZONTAL)
52
53        ivbox1 = wx.BoxSizer(wx.VERTICAL)
54        ivbox2 = wx.BoxSizer(wx.VERTICAL)
55 
56        ihbox1 = wx.BoxSizer(wx.HORIZONTAL)
57        ihbox2 = wx.BoxSizer(wx.HORIZONTAL)
58
59        symbolStaticBox = wx.StaticBox(panel, -1, 'Symbol')
60        symbolStaticBoxSizer = wx.StaticBoxSizer(symbolStaticBox, wx.VERTICAL)
61
62        # add widgets - reverse order!
63
64        # texts
65        symbolText = wx.StaticText(panel, label='Shape')
66        colorText = wx.StaticText(panel, label='Color')
67        sizeText = wx.StaticText(panel, label='Size')
68        labelText = wx.StaticText(panel, label='Legend label')
69
70        # selection widgets
71        self.symbolListBox = wx.ListBox(panel,-1,size=(200,200))
72        self.colorListBox = wx.ComboBox(panel,style=wx.CB_READONLY, size=(195,-1))
73        self.sizeComboBox = wx.ComboBox(panel,style=wx.CB_READONLY, size=(90,-1))
74        self.sizeComboBox.Bind(wx.EVT_COMBOBOX, self.combo_click)
75        self.sizeCustomButton = wx.Button(panel, label='Custom...')
76        self.sizeCustomButton.Bind(wx.EVT_BUTTON, self.customSize)
77        self.labelTextBox = wx.TextCtrl(panel,-1, "",size=(180,-1))
78
79        # buttons
80        OkButton = wx.Button(panel, label='OK')
81        OkButton.Bind(wx.EVT_BUTTON,self.onOK)
82        cancelButton = wx.Button(panel, label='Cancel')
83        cancelButton.Bind(wx.EVT_BUTTON, self.CloseDlg)
84
85        # now Add all the widgets to relevant spacer - tricky
86        ivbox1.Add(symbolText, flag =  wx.TOP | wx.LEFT | wx.ALIGN_LEFT ,border=10)
87        ivbox1.Add(self.symbolListBox, flag = wx.TOP | wx.LEFT | wx.ALIGN_LEFT ,border=10)
88
89        ihbox1.Add(sizeText, flag = wx.TOP | wx.LEFT | wx.ALIGN_LEFT , border=10)
90        ihbox1.Add((20,-1))
91        ihbox1.Add(self.sizeComboBox, flag =  wx.TOP | wx.LEFT | wx.ALIGN_LEFT , border=10)
92        ihbox1.Add((20,-1))
93        ihbox1.Add(self.sizeCustomButton, flag = wx.ALIGN_LEFT | wx.TOP, border=10)
94
95        ihbox2.Add(colorText,flag = wx.TOP |  wx.LEFT | wx.ALIGN_LEFT, border=10)
96        ihbox2.Add((20,-1))
97        ihbox2.Add(self.colorListBox, flag = wx.TOP | wx.LEFT | wx.ALIGN_LEFT, border=10)
98
99
100
101        ivbox2.Add(ihbox1, flag =  wx.TOP | wx.ALIGN_RIGHT,border=10)
102        ivbox2.Add(ihbox2, flag =  wx.TOP | wx.ALIGN_RIGHT,border=10)
103
104       
105        hbox1.Add((5,-1))
106        hbox1.Add(ivbox1,flag =  wx.EXPAND | wx.ALIGN_LEFT ,border=10)
107        hbox1.Add((5,-1))
108        hbox1.Add(ivbox2,flag =  wx.EXPAND | wx.ALIGN_RIGHT ,border=10)
109        hbox1.Add((5,-1))
110
111   
112        hbox2.Add(OkButton, flag = wx.RIGHT |  wx.ALIGN_RIGHT, border=10)
113        hbox2.Add(cancelButton, flag = wx.RIGHT | wx.ALIGN_RIGHT, border=10)
114
115        hbox3.Add(labelText, flag= wx.TOP | wx.LEFT | wx.ALIGN_LEFT, border=10)
116        hbox3.Add((20,-1))
117        hbox3.Add(self.labelTextBox, wx.TOP |wx.ALIGN_LEFT | wx.LEFT , border=10)
118        hbox3.Add((20,-1))
119 
120        vbox.Add((20,-1))
121        symbolStaticBoxSizer.Add(hbox1,flag = wx.TOP | wx.EXPAND,border=10)
122        vbox.Add(symbolStaticBoxSizer, flag = wx.TOP | wx.EXPAND,border=10)
123
124        vbox.Add((-1,20))
125        vbox.Add(hbox3,flag = wx.BOTTOM  | wx.ALIGN_RIGHT, border=20)
126
127
128        vbox.Add(hbox2,flag = wx.BOTTOM  | wx.ALIGN_RIGHT, border=20)
129
130
131        panel.SetSizer(vbox)
132
133        self.populateSymbol()
134        self.populateColor()
135        self.populateSize()
136
137        self.SetDefaultItem(self.symbolListBox)
138
139    def customSize(self,e):
140        dlg = wx.TextEntryDialog(self,
141                                 'Enter custom size',
142                                 'Custom size',
143                                 str(self.final_size))
144        if(dlg.ShowModal() == wx.ID_OK):
145            if(float(dlg.GetValue()) < 0):
146                dial = wx.MessageDialog(None, 
147                                        'Unfortunately imaginary icons are not yet supported. Please enter a positive value',
148                                        'Error',
149                                        wx.OK | wx.ICON_ERROR)
150                dial.ShowModal()
151                dlg.Destroy()
152                self.customSize(e)
153            else:
154                self.final_size = dlg.GetValue()
155                dlg.Destroy()
156        else:
157            dlg.Destroy()
158
159    def setDefaults(self,size,color,symbol,label):
160        self.final_size = size
161        # set up gui values
162        self.labelTextBox.SetValue(label)
163        if(size % 1 == 0 and size > 1 and size < 11):
164            self.sizeComboBox.SetSelection(int(size) - 1)
165        else:
166            self.sizeComboBox.SetSelection(4)
167        self.symbolListBox.SetSelection(self.sorted_sym_dic[symbol])
168        colorname = appearanceDialog.find_key(self.get_color_label(),color)
169        self.colorListBox.SetStringSelection(colorname)
170
171    def populateSymbol(self):
172        self.sorted_symbolLabels = sorted(self.symbolLabels.iteritems(),key=operator.itemgetter(1))
173        self.sorted_sym_dic = {}
174        i = 0
175        for label in self.sorted_symbolLabels:
176            self.symbolListBox.Append(str(label[0]))
177            self.sorted_sym_dic[str(label[0])] = i
178            i += 1
179
180    def populateColor(self):
181        sortedcolorLabels = sorted(self.colorLabels.iteritems(),key=operator.itemgetter(1))
182       
183        for color in sortedcolorLabels:
184             self.colorListBox.Append(str(color[0]))
185 
186    def populateSize(self):
187
188        for i in range(1,11):
189            self.sizeComboBox.Append(str(i) + '.0')
190
191    def combo_click(self,e):
192        self.final_size = self.sizeComboBox.GetValue()
193
194    def CloseDlg(self,e):
195        self.Destroy()
196
197
198    def get_symbol_label(self):
199        """
200        Associates label to symbol
201        """
202        _labels = {}
203        i = 0
204        _labels['Circle'] = i
205        i += 1
206        _labels['Cross X '] = i
207        i += 1
208        _labels['Triangle Down'] = i
209        i += 1
210        _labels['Triangle Up'] = i
211        i += 1
212        _labels['Triangle Left'] = i
213        i += 1
214        _labels['Triangle Right'] = i
215        i += 1
216        _labels['Cross +'] = i
217        i += 1
218        _labels['Square'] = i
219        i += 1
220        _labels['Diamond'] = i
221        i += 1
222        _labels['Hexagon1'] = i
223        i += 1
224        _labels['Hexagon2'] = i
225        i += 1
226        _labels['Pentagon'] = i
227        i += 1
228        _labels['Line'] = i
229        return _labels
230   
231    def get_color_label(self):
232        """
233        Associates label to a specific color
234        """
235        _labels = {}
236        i = 0
237        _labels['Blue'] = i
238        i += 1
239        _labels['Green'] = i
240        i += 1
241        _labels['Red'] = i
242        i += 1
243        _labels['Cyan'] = i
244        i += 1
245        _labels['Magenta'] = i
246        i += 1
247        _labels['Yellow'] = i
248        i += 1
249        _labels['Black'] = i
250        return _labels
251
252    @staticmethod
253    def find_key(dic,val):
254        return [k for k, v in dic.iteritems() if v == val][0]
255       
256    def getCurrentValues(self): # returns (size,color,symbol,dataname)
257
258        size = float(self.final_size)
259        name = str(self.labelTextBox.GetValue())
260        selTuple = self.symbolListBox.GetSelections()
261        symbol = appearanceDialog.find_key(self.sorted_sym_dic,int(selTuple[0]))
262        color = str(self.colorListBox.GetValue()) 
263 
264        return(size,color,symbol,name)
265
266    def onOK(self,e):
267        self.okay_clicked = True
268
269        self.Close()
Note: See TracBrowser for help on using the repository browser.