source: sasview/src/sans/guiframe/local_perspectives/plotting/appearanceDialog.py @ 51f14603

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 51f14603 was 51f14603, checked in by Peter Parker, 10 years ago

Refs #202 - Fix Sphinx build errors (not including park-1.2.1/). Most warnings remain.

  • Property mode set to 100644
File size: 7.6 KB
Line 
1#!/usr/bin/python
2"""
3Dialog for appearance of plot symbols, color, size etc.
4
5This software was developed by Institut Laue-Langevin as part of
6Distributed Data Analysis of Neutron Scattering Experiments (DANSE).
7
8Copyright 2012 Institut Laue-Langevin
9"""
10import wx
11import operator
12
13class appearanceDialog(wx.Frame):
14    """
15    Appearance dialog
16    """
17    def __init__(self, parent, title):
18        """
19        Initialization of the Panel
20        """
21        super(appearanceDialog, self).__init__(parent, title=title, 
22                        size=(570,450), 
23                        style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT)
24
25        self.okay_clicked = False
26        self.parent = parent
27        self.symbo_labels = self.parent.get_symbol_label()
28        self.color_labels = self.parent.get_color_label()
29        self.init_ui()
30        self.Centre()
31        self.Show()
32
33    def init_ui(self):
34        """
35        Create spacing needed
36        """
37        panel = wx.Panel(self)
38
39        vbox = wx.BoxSizer(wx.VERTICAL)
40
41        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
42        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
43        hbox3 = wx.BoxSizer(wx.HORIZONTAL)
44
45        ivbox1 = wx.BoxSizer(wx.VERTICAL)
46        ivbox2 = wx.BoxSizer(wx.VERTICAL)
47 
48        ihbox1 = wx.BoxSizer(wx.HORIZONTAL)
49        ihbox2 = wx.BoxSizer(wx.HORIZONTAL)
50
51        symbolstaticbox = wx.StaticBox(panel, -1, 'Symbol')
52        symbolstaticboxsizer = wx.StaticBoxSizer(symbolstaticbox, wx.VERTICAL)
53
54        # add widgets - reverse order!
55        # texts
56        symboltext = wx.StaticText(panel, label='Shape')
57        colortext = wx.StaticText(panel, label='Color')
58        sizetext = wx.StaticText(panel, label='Size ')
59        labeltext = wx.StaticText(panel, label='Legend Label')
60
61        # selection widgets
62        self.symbollistbox = wx.ListBox(panel, -1, size=(200, 200))
63        self.colorlistbox = wx.ComboBox(panel, style=wx.CB_READONLY, 
64                                        size=(185, -1))
65        self.sizecombobox = wx.ComboBox(panel, style=wx.CB_READONLY, 
66                                        size=(90, -1))
67        self.sizecombobox.Bind(wx.EVT_COMBOBOX, self.combo_click)
68        self.sizecustombutton = wx.Button(panel, label='Custom...')
69        self.sizecustombutton.Bind(wx.EVT_BUTTON, self.custom_size)
70        self.labeltextbox = wx.TextCtrl(panel, -1, "",  size=(440, -1))
71
72        # buttons
73        okbutton = wx.Button(panel, label='OK')
74        okbutton.Bind(wx.EVT_BUTTON, self.on_ok)
75        cancelbutton = wx.Button(panel, label='Cancel')
76        cancelbutton.Bind(wx.EVT_BUTTON, self.close_dlg)
77
78        # now Add all the widgets to relevant spacer - tricky
79        ivbox1.Add(symboltext, flag=wx.ALL|wx.ALIGN_LEFT, border=10)
80        ivbox1.Add(self.symbollistbox, flag=wx.ALL|wx.ALIGN_LEFT, border=10)
81
82        ihbox1.Add(sizetext, flag=wx.ALL|wx.ALIGN_LEFT, border=10)
83        ihbox1.Add(self.sizecombobox, 
84                   flag= wx.ALL|wx.RIGHT|wx.ALIGN_LEFT, border=10)
85        ihbox1.Add(self.sizecustombutton, 
86                   flag=wx.ALIGN_LEFT|wx.ALL, border=10)
87
88        ihbox2.Add(colortext, flag=wx.ALL|wx.ALIGN_LEFT, border=10)
89        ihbox2.Add(self.colorlistbox, flag=wx.ALL|wx.ALIGN_LEFT, border=10)
90
91        ivbox2.Add(ihbox1, flag=wx.ALIGN_LEFT, border=10)
92        ivbox2.Add(ihbox2, flag=wx.ALIGN_LEFT, border=10)
93
94        hbox1.Add(ivbox1, flag=wx.ALIGN_LEFT, border=10)
95        hbox1.Add(ivbox2, flag=wx.ALIGN_LEFT, border=10)
96
97        hbox2.Add(okbutton, flag=wx.ALL| wx.ALIGN_RIGHT, border=10)
98        hbox2.Add(cancelbutton, flag=wx.ALL|wx.ALIGN_RIGHT, border=10)
99
100        hbox3.Add(labeltext, flag=wx.EXPAND|wx.ALL|wx.ALIGN_LEFT, border=10)
101        hbox3.Add(self.labeltextbox, flag=wx.EXPAND|wx.ALL|wx.ALIGN_LEFT, border=10)
102 
103        symbolstaticboxsizer.Add(hbox1, flag=wx.ALL|wx.EXPAND, border=10)
104        vbox.Add(symbolstaticboxsizer, flag=wx.ALL|wx.EXPAND, border=10)
105        vbox.Add(hbox3, flag=wx.EXPAND|wx.RIGHT, border=10)
106        vbox.Add(wx.StaticLine(panel), 0, wx.ALL|wx.EXPAND, 5)
107        vbox.Add(hbox2, flag=wx.RIGHT|wx.ALIGN_RIGHT, border=10)
108
109        panel.SetSizer(vbox)
110
111        self.populate_symbol()
112        self.populate_color()
113        self.populate_size()
114
115        self.SetDefaultItem(self.symbollistbox)
116
117    def custom_size(self, event):
118        """
119        On custom size
120        """
121        dlg = wx.TextEntryDialog(self, 
122                                 'Enter custom size', 
123                                 'Custom size', 
124                                 str(self.final_size))
125        if(dlg.ShowModal() == wx.ID_OK):
126            if(float(dlg.GetValue()) < 0):
127                msg = "Unfortunately imaginary icons are not yet supported."
128                msg += "Please enter a positive value"
129                dial = wx.MessageDialog(None, msg, 'Error',
130                                         wx.OK|wx.ICON_ERROR)
131                dial.ShowModal()
132                dlg.Destroy()
133                self.custom_size(event)
134            else:
135                self.final_size = dlg.GetValue()
136                dlg.Destroy()
137        else:
138            dlg.Destroy()
139
140    def set_defaults(self, size, color, symbol, label):
141        """
142        Set Defaults
143        """
144        self.final_size = size
145        # set up gui values
146        self.labeltextbox.SetValue(label)
147        if(size % 1 == 0 and size > 1 and size < 11):
148            self.sizecombobox.SetSelection(int(size) - 1)
149        else:
150            self.sizecombobox.SetSelection(4)
151        self.symbollistbox.SetSelection(self.sorted_sym_dic[symbol])
152        colorname = appearanceDialog.find_key(self.parent.get_color_label(), 
153                                              color)
154        self.colorlistbox.SetStringSelection(colorname)
155
156    def populate_symbol(self):
157        """
158        Populate Symbols
159        """
160        self.sorted_symbo_labels = sorted(self.symbo_labels.iteritems(), 
161                                          key=operator.itemgetter(1))
162        self.sorted_sym_dic = {}
163        i = 0
164        for label in self.sorted_symbo_labels:
165            self.symbollistbox.Append(str(label[0]))
166            self.sorted_sym_dic[str(label[0])] = i
167            i += 1
168
169    def populate_color(self):
170        """
171        Populate Colors
172        """
173        sortedcolor_labels = sorted(self.color_labels.iteritems(), 
174                                   key=operator.itemgetter(1))
175        for color in sortedcolor_labels:
176            self.colorlistbox.Append(str(color[0]))
177 
178    def populate_size(self):
179        """
180        Populate Size
181        """
182        for i in range(1, 11):
183            self.sizecombobox.Append(str(i) + '.0')
184
185    def combo_click(self, event):
186        """
187        Combox on click
188        """
189        event.Skip()
190        self.final_size = self.sizecombobox.GetValue()
191
192    def close_dlg(self, event):
193        """
194        On Close Dlg
195        """
196        event.Skip()
197        self.Destroy()
198
199    @staticmethod
200    def find_key(dic, val):
201        """
202        Find key
203        """
204        return [k for k, v in dic.iteritems() if v == val][0]
205       
206    def get_current_values(self): 
207        """
208        Get Current Values
209        :returns : (size, color, symbol, dataname)
210        """
211        size = float(self.final_size)
212        name = str(self.labeltextbox.GetValue())
213        seltuple = self.symbollistbox.GetSelections()
214        symbol = appearanceDialog.find_key(self.sorted_sym_dic, 
215                                           int(seltuple[0]))
216        color = str(self.colorlistbox.GetValue()) 
217        return(size, color, symbol, name)
218
219    def on_ok(self, event):
220        """
221        On OK button clicked
222        """
223        event.Skip()
224        self.okay_clicked = True
225        self.Close()
Note: See TracBrowser for help on using the repository browser.