source: sasview/src/sas/plottools/SimpleFont.py @ e6e4af7

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 e6e4af7 was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

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