[8f59e95] | 1 | |
---|
| 2 | """ |
---|
| 3 | /** |
---|
| 4 | This software was developed by Institut Laue-Langevin as part of |
---|
| 5 | Distributed Data Analysis of Neutron Scattering Experiments (DANSE). |
---|
| 6 | |
---|
| 7 | Copyright 2012 Institut Laue-Langevin |
---|
| 8 | |
---|
| 9 | **/ |
---|
| 10 | |
---|
| 11 | """ |
---|
| 12 | |
---|
| 13 | # this is a dead simple dialog for getting font family, size,style and weight |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | import wx |
---|
| 17 | from matplotlib.font_manager import FontProperties |
---|
| 18 | |
---|
| 19 | FAMILY = ['serif', 'sans-serif', 'fantasy', 'monospace'] |
---|
| 20 | SIZE = [8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72] |
---|
| 21 | STYLE = ['normal', 'italic'] |
---|
| 22 | WEIGHT = ['light', 'normal', 'bold'] |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | class SimpleFont(wx.Dialog): |
---|
| 26 | def __init__(self,parent,id,title): |
---|
| 27 | |
---|
| 28 | wx.Dialog.__init__(self,parent,id,title,size=(440,160)) |
---|
| 29 | self.parent = parent |
---|
| 30 | # self.SetWindowVariant(variant=FONT_VARIANT) |
---|
| 31 | |
---|
| 32 | self.family = FAMILY[1] |
---|
| 33 | self.size = SIZE[3] |
---|
| 34 | self.style = STYLE[0] |
---|
| 35 | self.weight = WEIGHT[1] |
---|
[657e52c] | 36 | self.tick_label = None |
---|
| 37 | self.tick_label_check = None |
---|
[8f59e95] | 38 | self.InitUI() |
---|
| 39 | self.Centre() |
---|
| 40 | self.Show() |
---|
[657e52c] | 41 | |
---|
[8f59e95] | 42 | def InitUI(self): |
---|
| 43 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 44 | hbox1 = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 45 | hbox2 = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 46 | hbox3 = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 47 | |
---|
| 48 | gs = wx.GridSizer(2,4,-1,-1) |
---|
| 49 | |
---|
| 50 | self.fontFamily = wx.ComboBox(self,pos=(80,10),style=wx.CB_READONLY, |
---|
| 51 | size=(100,-1)) |
---|
| 52 | self.fontStyle = wx.ComboBox(self,pos=(80,60),style=wx.CB_READONLY, |
---|
| 53 | size=(100,-1)) |
---|
| 54 | |
---|
| 55 | self.fontPoint = wx.ComboBox(self,pos=(300,10),style=wx.CB_READONLY, |
---|
| 56 | size=(100,-1)) |
---|
| 57 | self.fontWeight = wx.ComboBox(self,pos=(300,60), |
---|
| 58 | style=wx.CB_READONLY,size=(100,-1)) |
---|
[657e52c] | 59 | self.tick_label_check = wx.CheckBox(self, -1, label='', pos=(80, 100), |
---|
| 60 | size=(15, -1)) |
---|
| 61 | self.tick_label_check.SetValue(False) |
---|
[8f59e95] | 62 | self.okButton = wx.Button(self,wx.ID_OK,'OK',pos=(215,100)) |
---|
| 63 | self.closeButton = wx.Button(self,wx.ID_CANCEL,'Cancel',pos=(315,100)) |
---|
[657e52c] | 64 | |
---|
[8f59e95] | 65 | self._set_family_list() |
---|
| 66 | self._set_style_list() |
---|
| 67 | self._set_weight_list() |
---|
| 68 | self._set_point_list() |
---|
[657e52c] | 69 | |
---|
[8f59e95] | 70 | familyText = wx.StaticText(self, label='Family:', pos=(10,12)) |
---|
| 71 | sizeText = wx.StaticText(self, label='Size:',pos=(220,12)) |
---|
| 72 | styleText = wx.StaticText(self, label='Style:',pos=(10,62)) |
---|
| 73 | weightText = wx.StaticText(self, label='Weight:',pos=(220,62)) |
---|
[657e52c] | 74 | tick_label_text = wx.StaticText(self,label='Tick label?', pos=(10, 100)) |
---|
| 75 | tick_label_text.SetToolTipString("Apply to tick label too.") |
---|
| 76 | |
---|
[8f59e95] | 77 | def _set_family_list(self): |
---|
| 78 | # list of font family |
---|
| 79 | list = FAMILY |
---|
| 80 | for idx in range(len(list)): |
---|
| 81 | self.fontFamily.Append(list[idx],idx) |
---|
| 82 | |
---|
| 83 | def _set_style_list(self): |
---|
| 84 | # list of styles |
---|
| 85 | list = STYLE |
---|
| 86 | for idx in range(len(list)): |
---|
| 87 | self.fontStyle.Append(list[idx],idx) |
---|
| 88 | |
---|
| 89 | def _set_weight_list(self): |
---|
| 90 | #list of weights |
---|
| 91 | list = WEIGHT |
---|
| 92 | for idx in range(len(list)): |
---|
| 93 | self.fontWeight.Append(list[idx],idx) |
---|
| 94 | |
---|
| 95 | def _set_point_list(self): |
---|
| 96 | # list of point sizes |
---|
| 97 | list = SIZE |
---|
| 98 | for idx in range(len(list)): |
---|
| 99 | self.fontPoint.Append(str(list[idx]),idx) |
---|
| 100 | |
---|
[657e52c] | 101 | def get_ticklabel_check(self): |
---|
| 102 | """ |
---|
| 103 | Get tick label check value |
---|
| 104 | """ |
---|
| 105 | self.tick_label = self.tick_label_check.GetValue() |
---|
| 106 | return self.tick_label |
---|
| 107 | |
---|
| 108 | def set_ticklabel_check(self, check=False): |
---|
| 109 | """ |
---|
| 110 | Set tick label check value |
---|
| 111 | """ |
---|
| 112 | self.tick_label_check.SetValue(check) |
---|
[8f59e95] | 113 | |
---|
| 114 | def set_default_font(self,font): |
---|
| 115 | |
---|
| 116 | if not font: |
---|
| 117 | self.fontFamily.SetSelection(1) |
---|
| 118 | self.fontWeight.SetSelection(1) |
---|
| 119 | self.fontPoint.SetSelection(3) |
---|
| 120 | self.fontStyle.SetSelection(0) |
---|
| 121 | else: |
---|
[657e52c] | 122 | self.fontWeight.SetStringSelection(str(font.get_weight())) |
---|
| 123 | self.fontPoint.SetStringSelection(str(int(font.get_size()))) |
---|
| 124 | self.fontFamily.SetStringSelection(str(font.get_family()[0])) |
---|
| 125 | self.fontStyle.SetStringSelection(str(font.get_style())) |
---|
| 126 | |
---|
[8f59e95] | 127 | def get_font(self): |
---|
| 128 | FONT = FontProperties() |
---|
| 129 | font = FONT.copy() |
---|
[657e52c] | 130 | font.set_size(str(self.fontPoint.GetValue())) |
---|
[8f59e95] | 131 | font.set_name(str(self.fontFamily.GetValue())) |
---|
| 132 | font.set_slant(str(self.fontStyle.GetValue())) |
---|
| 133 | font.set_weight(str(self.fontWeight.GetValue())) |
---|
| 134 | |
---|
| 135 | return font |
---|