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

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 9f51c2c was 9f51c2c, checked in by Jae Cho <jhjcho@…>, 12 years ago

broken plot/graph modification panel fixes

  • Property mode set to 100644
File size: 8.0 KB
Line 
1#!/usr/bin/python
2
3"""
4
5Dialog for appearance of plot symbols, color, size etc.
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,450), style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT)
30
31        self.okay_clicked = False
32        self.parent = parent
33        self.symbolLabels = self.parent.get_symbol_label()
34        self.colorLabels = self.parent.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=(-1,-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.ALL  | wx.ALIGN_LEFT ,border=10)
87        ivbox1.Add(self.symbolListBox, flag = wx.ALL | wx.ALIGN_LEFT ,border=10)
88
89        ihbox1.Add(sizeText, flag = wx.ALL| wx.ALIGN_LEFT , border=10)
90        ihbox1.Add(self.sizeComboBox, flag =  wx.ALL|wx.RIGHT | wx.ALIGN_LEFT , border=10)
91        ihbox1.Add(self.sizeCustomButton, flag = wx.ALIGN_LEFT | wx.ALL, border=10)
92
93        ihbox2.Add(colorText,flag = wx.ALL | wx.ALIGN_LEFT, border=10)
94        ihbox2.Add(self.colorListBox, flag = wx.ALL  | wx.ALIGN_LEFT, border=10)
95
96
97
98        ivbox2.Add(ihbox1, flag =wx.ALIGN_LEFT,border=10)
99        ivbox2.Add(ihbox2, flag =wx.ALIGN_LEFT,border=10)
100
101       
102        hbox1.Add(ivbox1,flag =wx.ALIGN_LEFT ,border=10)
103        hbox1.Add(ivbox2,flag =wx.ALIGN_LEFT ,border=10)
104
105   
106        hbox2.Add(OkButton, flag = wx.ALL |  wx.ALIGN_RIGHT, border=10)
107        hbox2.Add(cancelButton, flag = wx.ALL | wx.ALIGN_RIGHT, border=10)
108
109        hbox3.Add(labelText, flag= wx.EXPAND | wx.RIGHT |  wx.ALIGN_LEFT, border=10)
110        hbox3.Add(self.labelTextBox, wx.EXPAND | wx.RIGHT |wx.ALIGN_LEFT , border=10)
111 
112        symbolStaticBoxSizer.Add(hbox1,flag = wx.ALL | wx.EXPAND,border=10)
113        vbox.Add(symbolStaticBoxSizer, flag = wx.ALL | wx.EXPAND,border=10)
114
115        vbox.Add(hbox3,flag = wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10)
116
117
118        vbox.Add(hbox2,flag = wx.ALL  | wx.ALIGN_RIGHT, border=10)
119
120
121        panel.SetSizer(vbox)
122
123        self.populateSymbol()
124        self.populateColor()
125        self.populateSize()
126
127        self.SetDefaultItem(self.symbolListBox)
128
129    def customSize(self,e):
130        dlg = wx.TextEntryDialog(self,
131                                 'Enter custom size',
132                                 'Custom size',
133                                 str(self.final_size))
134        if(dlg.ShowModal() == wx.ID_OK):
135            if(float(dlg.GetValue()) < 0):
136                dial = wx.MessageDialog(None, 
137                                        'Unfortunately imaginary icons are not yet supported. Please enter a positive value',
138                                        'Error',
139                                        wx.OK | wx.ICON_ERROR)
140                dial.ShowModal()
141                dlg.Destroy()
142                self.customSize(e)
143            else:
144                self.final_size = dlg.GetValue()
145                dlg.Destroy()
146        else:
147            dlg.Destroy()
148
149    def setDefaults(self,size,color,symbol,label):
150        self.final_size = size
151        # set up gui values
152        self.labelTextBox.SetValue(label)
153        if(size % 1 == 0 and size > 1 and size < 11):
154            self.sizeComboBox.SetSelection(int(size) - 1)
155        else:
156            self.sizeComboBox.SetSelection(4)
157        self.symbolListBox.SetSelection(self.sorted_sym_dic[symbol])
158        colorname = appearanceDialog.find_key(self.parent.get_color_label(),color)
159        self.colorListBox.SetStringSelection(colorname)
160
161    def populateSymbol(self):
162        self.sorted_symbolLabels = sorted(self.symbolLabels.iteritems(),key=operator.itemgetter(1))
163        self.sorted_sym_dic = {}
164        i = 0
165        for label in self.sorted_symbolLabels:
166            self.symbolListBox.Append(str(label[0]))
167            self.sorted_sym_dic[str(label[0])] = i
168            i += 1
169
170    def populateColor(self):
171        sortedcolorLabels = sorted(self.colorLabels.iteritems(),key=operator.itemgetter(1))
172       
173        for color in sortedcolorLabels:
174             self.colorListBox.Append(str(color[0]))
175 
176    def populateSize(self):
177
178        for i in range(1,11):
179            self.sizeComboBox.Append(str(i) + '.0')
180
181    def combo_click(self,e):
182        self.final_size = self.sizeComboBox.GetValue()
183
184    def CloseDlg(self,e):
185        self.Destroy()
186
187
188    def get_symbol_label(self):
189        """
190        Associates label to symbol
191        """
192        _labels = {}
193        i = 0
194        _labels['Circle'] = i
195        i += 1
196        _labels['Cross X '] = i
197        i += 1
198        _labels['Triangle Down'] = i
199        i += 1
200        _labels['Triangle Up'] = i
201        i += 1
202        _labels['Triangle Left'] = i
203        i += 1
204        _labels['Triangle Right'] = i
205        i += 1
206        _labels['Cross +'] = i
207        i += 1
208        _labels['Square'] = i
209        i += 1
210        _labels['Diamond'] = i
211        i += 1
212        _labels['Hexagon1'] = i
213        i += 1
214        _labels['Hexagon2'] = i
215        i += 1
216        _labels['Pentagon'] = i
217        i += 1
218        _labels['Line'] = i
219        i += 1
220        _labels['Dash'] = i
221        i += 1
222        _labels['Vline'] = i
223        i += 1
224        _labels['Step'] = i
225        return _labels
226   
227    def get_color_label(self):
228        """
229        Associates label to a specific color
230        """
231        _labels = {}
232        i = 0
233        _labels['Blue'] = i
234        i += 1
235        _labels['Green'] = i
236        i += 1
237        _labels['Red'] = i
238        i += 1
239        _labels['Cyan'] = i
240        i += 1
241        _labels['Magenta'] = i
242        i += 1
243        _labels['Yellow'] = i
244        i += 1
245        _labels['Black'] = i
246        return _labels
247
248    @staticmethod
249    def find_key(dic,val):
250        return [k for k, v in dic.iteritems() if v == val][0]
251       
252    def getCurrentValues(self): # returns (size,color,symbol,dataname)
253
254        size = float(self.final_size)
255        name = str(self.labelTextBox.GetValue())
256        selTuple = self.symbolListBox.GetSelections()
257        symbol = appearanceDialog.find_key(self.sorted_sym_dic,int(selTuple[0]))
258        color = str(self.colorListBox.GetValue()) 
259 
260        return(size,color,symbol,name)
261
262    def onOK(self,e):
263        self.okay_clicked = True
264
265        self.Close()
Note: See TracBrowser for help on using the repository browser.