source: sasview/src/sas/plottools/TextDialog.py @ 3477478

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 3477478 was 3477478, checked in by Mathieu Doucet <doucetm@…>, 9 years ago

pylint fixes

  • Property mode set to 100644
File size: 10.5 KB
Line 
1import wx
2import sys
3
4if sys.platform.count("win32") > 0:
5    FONT_VARIANT = 0
6    PNL_WIDTH = 460
7else:
8    FONT_VARIANT = 1
9    PNL_WIDTH = 500
10FAMILY = ['serif', 'sas-serif', 'fantasy', 'monospace']
11SIZE = [8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72]
12STYLE = ['normal', 'italic']
13WEIGHT = ['light', 'normal', 'bold']
14COLOR = ['black', 'blue', 'green', 'red', 'cyan', 'magenta', 'yellow']
15
16
17class TextDialog(wx.Dialog):
18    def __init__(self, parent, id, title, label='', unit=None):
19        """
20        Dialog window pops- up when selecting 'Add Text' on the toolbar
21        """
22        wx.Dialog.__init__(self, parent, id, title, size=(PNL_WIDTH, 280))
23        self.parent = parent
24        # Font
25        self.SetWindowVariant(variant=FONT_VARIANT)
26        # default
27        self.family = FAMILY[1]
28        self.size = SIZE[3]
29        self.style = STYLE[0]
30        self.weight = WEIGHT[1]
31        self.color = COLOR[0]
32        self.tick_label = False
33        # Dialog interface
34        vbox = wx.BoxSizer(wx.VERTICAL)
35        text_box = wx.BoxSizer(wx.HORIZONTAL)
36        sizer = wx.GridBagSizer(1, 3)
37        _BOX_WIDTH = 60
38        font_description = wx.StaticBox(self, -1, 'Font', size=(PNL_WIDTH - 20, 70))
39        font_box = wx.StaticBoxSizer(font_description, wx.VERTICAL)
40        family_box = wx.BoxSizer(wx.HORIZONTAL)
41        style_box = wx.BoxSizer(wx.HORIZONTAL)
42        # tcA
43        if unit != None:
44            styles = wx.TAB_TRAVERSAL
45            height = -1
46            unit_text = wx.StaticText(self, -1, 'Unit :')
47            unit_text.SetToolTipString("Unit of the axis.")
48            self.unit_ctrl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1))
49            self.unit_ctrl.SetValue(str(unit))
50            unit_box = wx.BoxSizer(wx.HORIZONTAL)
51            tick_label_text = wx.StaticText(self, -1, 'Tick label')
52            tick_label_text.SetToolTipString("Apply to tick label too.")
53            self.tick_label_check = wx.CheckBox(self, -1, '', (10, 10))
54            self.tick_label_check.SetValue(False)
55            self.tick_label_check.SetToolTipString("Apply to tick label too.")
56            wx.EVT_CHECKBOX(self, self.tick_label_check.GetId(),
57                            self.on_tick_label)
58            enter_text = 'Enter text:'
59        else:
60            styles = wx.TAB_TRAVERSAL | wx.TE_MULTILINE | wx.TE_LINEWRAP | \
61                              wx.TE_PROCESS_ENTER | wx.SUNKEN_BORDER | wx.HSCROLL
62            height = 60
63            unit_text = None
64            self.unit_ctrl = None
65            unit_box = None
66            tick_label_text = None
67            self.tick_label_check = None
68            enter_text = 'Enter text'
69            if len(label) > 0:
70                enter_text += " (this text won't be auto-updated if modified.):"
71            else:
72                enter_text += ":"
73        self.text_string = wx.TextCtrl(self, -1, size=(PNL_WIDTH - 30, height), style=styles)
74        self.text_string.SetValue(str(label))
75        self.text_string.SetToolTipString("The text that will be displayed.")
76        # font family
77        self.font_family = wx.ComboBox(self, -1, style=wx.CB_READONLY)
78        wx.EVT_COMBOBOX(self.font_family, -1, self.on_family)
79        self.font_family.SetMinSize((_BOX_WIDTH, -1))
80        self._set_family_list()
81        self.font_family.SetSelection(1)
82        self.font_family.SetToolTipString("Font family of the text.")
83        # font weight
84        self.font_weight = wx.ComboBox(self, -1, style=wx.CB_READONLY)
85        wx.EVT_COMBOBOX(self.font_weight, -1, self.on_weight)
86        self.font_weight.SetMinSize((_BOX_WIDTH, -1))
87        self._set_weight_list()
88        self.font_weight.SetSelection(1)
89        self.font_weight.SetToolTipString("Font weight of the text.")
90        # font family
91        self.font_size = wx.ComboBox(self, -1, style=wx.CB_READONLY)
92        wx.EVT_COMBOBOX(self.font_size, -1, self.on_size)
93        self.font_size.SetMinSize((_BOX_WIDTH, -1))
94        self._set_size_list()
95        self.font_size.SetSelection(5)
96        self.font_size.SetToolTipString("Font size of the text.")
97        # font style
98        self.font_style = wx.ComboBox(self, -1, style=wx.CB_READONLY)
99        wx.EVT_COMBOBOX(self.font_style, -1, self.on_style)
100        self.font_style.SetMinSize((_BOX_WIDTH, -1))
101        self._set_style_list()
102        self.font_style.SetSelection(0)
103        self.font_style.SetToolTipString("Font style of the text.")
104        # font color
105        self.font_color = wx.ComboBox(self, -1, style=wx.CB_READONLY)
106        wx.EVT_COMBOBOX(self.font_color, -1, self.on_color)
107        self.font_color.SetMinSize((_BOX_WIDTH, -1))
108        self._set_color_list()
109        self.font_color.SetSelection(0)
110        self.font_color.SetToolTipString("Font color of the text.")
111        # Buttons on the bottom
112        self.static_line_1 = wx.StaticLine(self, -1)
113        self.ok_button = wx.Button(self, wx.ID_OK, 'OK', size=(_BOX_WIDTH, 25))
114        self.close_button = wx.Button(self, wx.ID_CANCEL, 'Cancel', size=(_BOX_WIDTH, 25))
115
116        # Intro
117        explanation = "Select font properties :"
118        vbox.Add(sizer)
119        ix = 0
120        iy = 1
121        sizer.Add(wx.StaticText(self, -1, explanation), (iy, ix),
122                  (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
123        family_box.Add(wx.StaticText(self, -1, 'Family :'), -1, 0)
124        family_box.Add(self.font_family, -1, 0)
125        family_box.Add((_BOX_WIDTH / 2, -1))
126        family_box.Add(wx.StaticText(self, -1, 'Size :'), -1, 0)
127        family_box.Add(self.font_size, -1, 0)
128        if unit_box != None:
129            family_box.Add((_BOX_WIDTH / 2, -1))
130            family_box.Add(tick_label_text, -1, 0)
131            family_box.Add(self.tick_label_check, -1, 0)
132        style_box.Add(wx.StaticText(self, -1, 'Style :'), -1, 0)
133        style_box.Add(self.font_style, -1, 0)
134        style_box.Add((_BOX_WIDTH / 2, -1))
135        style_box.Add(wx.StaticText(self, -1, 'Weight :'), -1, 0)
136        style_box.Add(self.font_weight, -1, 0)
137        style_box.Add((_BOX_WIDTH / 2, -1))
138        style_box.Add(wx.StaticText(self, -1, 'Color :'), -1, 0)
139        style_box.Add(self.font_color, -1, 0)
140        font_box.Add(family_box, -1, 10)
141        font_box.Add(style_box, -1, 10)
142        iy += 1
143        ix = 0
144        sizer.Add(font_box, (iy, ix),
145                  (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
146        iy += 2
147        ix = 0
148        sizer.Add(wx.StaticText(self, -1, enter_text), (iy, ix),
149                  (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
150        text_box.Add((15, 10))
151        text_box.Add(self.text_string)
152        vbox.Add(text_box, 0, wx.EXPAND, 15)
153        if unit_box != None:
154            unit_box.Add(unit_text, -1, 0)
155            unit_box.Add(self.unit_ctrl, -1, 0)
156            vbox.Add((5, 5))
157            vbox.Add(unit_box, 0, wx.LEFT, 15)
158
159        vbox.Add((10, 10))
160        vbox.Add(self.static_line_1, 0, wx.EXPAND, 10)
161        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
162        sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
163        sizer_button.Add(self.ok_button, 0,
164                         wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10)
165        sizer_button.Add(self.close_button, 0,
166                         wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10)
167        vbox.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10)
168        self.SetSizer(vbox)
169        self.Centre()
170
171    def _set_family_list(self):
172        """
173        Set the list of font family
174        """
175        # list of family choices
176        for idx in range(len(FAMILY)):
177            self.font_family.Append(FAMILY[idx], idx)
178
179    def _set_size_list(self):
180        """
181        Set the list of font size
182        """
183        # list of size choices
184        for idx in range(len(SIZE)):
185            self.font_size.Append(str(SIZE[idx]), idx)
186
187    def _set_weight_list(self):
188        """
189        Set the list of font weight
190        """
191        # list of weight choices
192        for idx in range(len(WEIGHT)):
193            self.font_weight.Append(WEIGHT[idx], idx)
194
195    def _set_style_list(self):
196        """
197        Set the list of font style
198        """
199        # list of style choices
200        for idx in range(len(STYLE)):
201            self.font_style.Append(STYLE[idx], idx)
202
203    def _set_color_list(self):
204        """
205        Set the list of font color
206        """
207        # list of tyle choices
208        for idx in range(len(COLOR)):
209            self.font_color.Append(COLOR[idx], idx)
210
211    def on_tick_label(self, event):
212        """
213        Set the font for tick label
214        """
215        event.Skip()
216        self.tick_label = self.tick_label_check.GetValue()
217
218    def on_family(self, event):
219        """
220        Set the family
221        """
222        event.Skip()
223        self.family = self.font_family.GetValue()
224
225    def on_style(self, event):
226        """
227        Set the style
228        """
229        event.Skip()
230        self.style = self.font_style.GetValue()
231
232    def on_weight(self, event):
233        """
234        Set the weight
235        """
236        event.Skip()
237        self.weight = self.font_weight.GetValue()
238
239    def on_size(self, event):
240        """
241        Set the size
242        """
243        event.Skip()
244        self.size = self.font_size.GetValue()
245
246    def on_color(self, event):
247        """
248        Set the color
249        """
250        event.Skip()
251        self.color = self.font_color.GetValue()
252
253    def getText(self):
254        """
255        Returns text string as input by user.
256        """
257        return self.text_string.GetValue()
258
259    def getUnit(self):
260        """
261        Returns unit string as input by user.
262        """
263        return self.unit_ctrl.GetValue()
264
265    def getFamily(self):
266        """
267        Returns font family for the text box
268        """
269        return str(self.family)
270
271    def getStyle(self):
272        """
273        Returns font tyle for the text box
274        """
275        return str(self.style)
276
277    def getWeight(self):
278        """
279        Returns font weight for the text box
280        """
281        return str(self.weight)
282
283    def getSize(self):
284        """
285        Returns font size for the text box
286        """
287        return int(self.size)
288
289    def getColor(self):
290        """
291        Returns font size for the text box
292        """
293        return str(self.color)
294
295    def getTickLabel(self):
296        """
297        Bool for use on tick label
298        """
299        return self.tick_label
Note: See TracBrowser for help on using the repository browser.