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

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

Small fixes to appearance dialogs

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