[a9d5684] | 1 | import wx |
---|
| 2 | import sys |
---|
| 3 | |
---|
| 4 | if sys.platform.count("win32") > 0: |
---|
| 5 | FONT_VARIANT = 0 |
---|
| 6 | PNL_WIDTH = 460 |
---|
| 7 | else: |
---|
| 8 | FONT_VARIANT = 1 |
---|
| 9 | PNL_WIDTH = 500 |
---|
[79492222] | 10 | FAMILY = ['serif', 'sas-serif', 'fantasy', 'monospace'] |
---|
[a9d5684] | 11 | SIZE = [8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72] |
---|
| 12 | STYLE = ['normal', 'italic'] |
---|
| 13 | WEIGHT = ['light', 'normal', 'bold'] |
---|
| 14 | COLOR = ['black', 'blue', 'green', 'red', 'cyan', 'magenta', 'yellow'] |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | class 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 |
---|
[3477478] | 24 | # Font |
---|
[a9d5684] | 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 |
---|
[3477478] | 33 | # Dialog interface |
---|
| 34 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[a9d5684] | 35 | text_box = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 36 | sizer = wx.GridBagSizer(1, 3) |
---|
| 37 | _BOX_WIDTH = 60 |
---|
[3477478] | 38 | font_description = wx.StaticBox(self, -1, 'Font', size=(PNL_WIDTH - 20, 70)) |
---|
[a9d5684] | 39 | font_box = wx.StaticBoxSizer(font_description, wx.VERTICAL) |
---|
| 40 | family_box = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 41 | style_box = wx.BoxSizer(wx.HORIZONTAL) |
---|
[3477478] | 42 | # tcA |
---|
[a9d5684] | 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.") |
---|
[3477478] | 53 | self.tick_label_check = wx.CheckBox(self, -1, '', (10, 10)) |
---|
[a9d5684] | 54 | self.tick_label_check.SetValue(False) |
---|
| 55 | self.tick_label_check.SetToolTipString("Apply to tick label too.") |
---|
[3477478] | 56 | wx.EVT_CHECKBOX(self, self.tick_label_check.GetId(), |
---|
[a9d5684] | 57 | self.on_tick_label) |
---|
| 58 | enter_text = 'Enter text:' |
---|
| 59 | else: |
---|
[3477478] | 60 | styles = wx.TAB_TRAVERSAL | wx.TE_MULTILINE | wx.TE_LINEWRAP | \ |
---|
| 61 | wx.TE_PROCESS_ENTER | wx.SUNKEN_BORDER | wx.HSCROLL |
---|
[a9d5684] | 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 += ":" |
---|
[3477478] | 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)) |
---|
[a9d5684] | 80 | self._set_family_list() |
---|
[3477478] | 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)) |
---|
[a9d5684] | 87 | self._set_weight_list() |
---|
[3477478] | 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)) |
---|
[a9d5684] | 94 | self._set_size_list() |
---|
[3477478] | 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)) |
---|
[a9d5684] | 101 | self._set_style_list() |
---|
[3477478] | 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)) |
---|
[a9d5684] | 108 | self._set_color_list() |
---|
[3477478] | 109 | self.font_color.SetSelection(0) |
---|
| 110 | self.font_color.SetToolTipString("Font color of the text.") |
---|
[a9d5684] | 111 | # Buttons on the bottom |
---|
| 112 | self.static_line_1 = wx.StaticLine(self, -1) |
---|
[3477478] | 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 | |
---|
[a9d5684] | 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), |
---|
[3477478] | 122 | (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
[a9d5684] | 123 | family_box.Add(wx.StaticText(self, -1, 'Family :'), -1, 0) |
---|
[3477478] | 124 | family_box.Add(self.font_family, -1, 0) |
---|
| 125 | family_box.Add((_BOX_WIDTH / 2, -1)) |
---|
[a9d5684] | 126 | family_box.Add(wx.StaticText(self, -1, 'Size :'), -1, 0) |
---|
[3477478] | 127 | family_box.Add(self.font_size, -1, 0) |
---|
[a9d5684] | 128 | if unit_box != None: |
---|
[3477478] | 129 | family_box.Add((_BOX_WIDTH / 2, -1)) |
---|
[a9d5684] | 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) |
---|
[3477478] | 133 | style_box.Add(self.font_style, -1, 0) |
---|
| 134 | style_box.Add((_BOX_WIDTH / 2, -1)) |
---|
[a9d5684] | 135 | style_box.Add(wx.StaticText(self, -1, 'Weight :'), -1, 0) |
---|
[3477478] | 136 | style_box.Add(self.font_weight, -1, 0) |
---|
| 137 | style_box.Add((_BOX_WIDTH / 2, -1)) |
---|
[a9d5684] | 138 | style_box.Add(wx.StaticText(self, -1, 'Color :'), -1, 0) |
---|
[3477478] | 139 | style_box.Add(self.font_color, -1, 0) |
---|
[a9d5684] | 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), |
---|
[3477478] | 145 | (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
[a9d5684] | 146 | iy += 2 |
---|
| 147 | ix = 0 |
---|
| 148 | sizer.Add(wx.StaticText(self, -1, enter_text), (iy, ix), |
---|
[3477478] | 149 | (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
[a9d5684] | 150 | text_box.Add((15, 10)) |
---|
[3477478] | 151 | text_box.Add(self.text_string) |
---|
[a9d5684] | 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) |
---|
[3477478] | 156 | vbox.Add((5, 5)) |
---|
| 157 | vbox.Add(unit_box, 0, wx.LEFT, 15) |
---|
| 158 | |
---|
[a9d5684] | 159 | vbox.Add((10, 10)) |
---|
| 160 | vbox.Add(self.static_line_1, 0, wx.EXPAND, 10) |
---|
| 161 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
[3477478] | 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) |
---|
[a9d5684] | 168 | self.SetSizer(vbox) |
---|
| 169 | self.Centre() |
---|
[3477478] | 170 | |
---|
[a9d5684] | 171 | def _set_family_list(self): |
---|
| 172 | """ |
---|
| 173 | Set the list of font family |
---|
| 174 | """ |
---|
| 175 | # list of family choices |
---|
[3477478] | 176 | for idx in range(len(FAMILY)): |
---|
| 177 | self.font_family.Append(FAMILY[idx], idx) |
---|
| 178 | |
---|
[a9d5684] | 179 | def _set_size_list(self): |
---|
| 180 | """ |
---|
| 181 | Set the list of font size |
---|
| 182 | """ |
---|
| 183 | # list of size choices |
---|
[3477478] | 184 | for idx in range(len(SIZE)): |
---|
| 185 | self.font_size.Append(str(SIZE[idx]), idx) |
---|
| 186 | |
---|
[a9d5684] | 187 | def _set_weight_list(self): |
---|
| 188 | """ |
---|
| 189 | Set the list of font weight |
---|
| 190 | """ |
---|
| 191 | # list of weight choices |
---|
[3477478] | 192 | for idx in range(len(WEIGHT)): |
---|
| 193 | self.font_weight.Append(WEIGHT[idx], idx) |
---|
| 194 | |
---|
[a9d5684] | 195 | def _set_style_list(self): |
---|
| 196 | """ |
---|
| 197 | Set the list of font style |
---|
| 198 | """ |
---|
| 199 | # list of style choices |
---|
[3477478] | 200 | for idx in range(len(STYLE)): |
---|
| 201 | self.font_style.Append(STYLE[idx], idx) |
---|
| 202 | |
---|
[a9d5684] | 203 | def _set_color_list(self): |
---|
| 204 | """ |
---|
| 205 | Set the list of font color |
---|
| 206 | """ |
---|
| 207 | # list of tyle choices |
---|
[3477478] | 208 | for idx in range(len(COLOR)): |
---|
| 209 | self.font_color.Append(COLOR[idx], idx) |
---|
| 210 | |
---|
[a9d5684] | 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() |
---|
[3477478] | 217 | |
---|
[a9d5684] | 218 | def on_family(self, event): |
---|
| 219 | """ |
---|
| 220 | Set the family |
---|
| 221 | """ |
---|
| 222 | event.Skip() |
---|
[3477478] | 223 | self.family = self.font_family.GetValue() |
---|
| 224 | |
---|
[a9d5684] | 225 | def on_style(self, event): |
---|
| 226 | """ |
---|
| 227 | Set the style |
---|
| 228 | """ |
---|
| 229 | event.Skip() |
---|
[3477478] | 230 | self.style = self.font_style.GetValue() |
---|
| 231 | |
---|
[a9d5684] | 232 | def on_weight(self, event): |
---|
| 233 | """ |
---|
| 234 | Set the weight |
---|
| 235 | """ |
---|
| 236 | event.Skip() |
---|
[3477478] | 237 | self.weight = self.font_weight.GetValue() |
---|
| 238 | |
---|
[a9d5684] | 239 | def on_size(self, event): |
---|
| 240 | """ |
---|
| 241 | Set the size |
---|
| 242 | """ |
---|
| 243 | event.Skip() |
---|
[3477478] | 244 | self.size = self.font_size.GetValue() |
---|
| 245 | |
---|
[a9d5684] | 246 | def on_color(self, event): |
---|
| 247 | """ |
---|
| 248 | Set the color |
---|
| 249 | """ |
---|
| 250 | event.Skip() |
---|
[3477478] | 251 | self.color = self.font_color.GetValue() |
---|
| 252 | |
---|
[a9d5684] | 253 | def getText(self): |
---|
| 254 | """ |
---|
| 255 | Returns text string as input by user. |
---|
| 256 | """ |
---|
[3477478] | 257 | return self.text_string.GetValue() |
---|
| 258 | |
---|
[a9d5684] | 259 | def getUnit(self): |
---|
| 260 | """ |
---|
| 261 | Returns unit string as input by user. |
---|
| 262 | """ |
---|
| 263 | return self.unit_ctrl.GetValue() |
---|
[3477478] | 264 | |
---|
[a9d5684] | 265 | def getFamily(self): |
---|
| 266 | """ |
---|
| 267 | Returns font family for the text box |
---|
| 268 | """ |
---|
| 269 | return str(self.family) |
---|
[3477478] | 270 | |
---|
[a9d5684] | 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) |
---|
[3477478] | 282 | |
---|
[a9d5684] | 283 | def getSize(self): |
---|
| 284 | """ |
---|
| 285 | Returns font size for the text box |
---|
| 286 | """ |
---|
| 287 | return int(self.size) |
---|
[3477478] | 288 | |
---|
[a9d5684] | 289 | def getColor(self): |
---|
| 290 | """ |
---|
| 291 | Returns font size for the text box |
---|
| 292 | """ |
---|
| 293 | return str(self.color) |
---|
[3477478] | 294 | |
---|
[a9d5684] | 295 | def getTickLabel(self): |
---|
| 296 | """ |
---|
| 297 | Bool for use on tick label |
---|
| 298 | """ |
---|
| 299 | return self.tick_label |
---|