source: sasview/src/sans/plottools/SimpleFont.py @ 6675651

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 6675651 was a9d5684, checked in by Mathieu Doucet <doucetm@…>, 11 years ago
  • Property mode set to 100644
File size: 4.4 KB
Line 
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
16import wx
17from matplotlib.font_manager import FontProperties
18
19FAMILY = ['serif', 'sans-serif', 'fantasy', 'monospace']
20SIZE = [8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72]
21STYLE = ['normal', 'italic']
22WEIGHT = ['light', 'normal', 'bold']
23
24
25class 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]
36        self.tick_label = None
37        self.tick_label_check = None
38        self.InitUI()
39        self.Centre()
40        self.Show()
41       
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))
59        self.tick_label_check = wx.CheckBox(self, -1, label='', pos=(80, 100), 
60                                                                                size=(15, -1))
61        self.tick_label_check.SetValue(False)
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))
64       
65        self._set_family_list()
66        self._set_style_list()
67        self._set_weight_list()
68        self._set_point_list()
69       
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))
74        tick_label_text = wx.StaticText(self,label='Tick label?', pos=(10, 100))
75        tick_label_text.SetToolTipString("Apply to tick label too.")
76               
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
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)
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:
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               
127    def get_font(self):
128        FONT = FontProperties()
129        font = FONT.copy()
130        font.set_size(str(self.fontPoint.GetValue()))
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
Note: See TracBrowser for help on using the repository browser.