source: sasview/src/sas/sasgui/plottools/SimpleFont.py @ d76beb4

ESS_GUI
Last change on this file since d76beb4 was d7bb526, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Refactored plottools into sasgui

  • Property mode set to 100644
File size: 3.9 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        self.font_family = wx.ComboBox(self, pos=(80, 10), style=wx.CB_READONLY, size=(100, -1))
40        self.font_style = wx.ComboBox(self, pos=(80, 60), style=wx.CB_READONLY, size=(100, -1))
41        self.font_point = wx.ComboBox(self, pos=(300, 10), style=wx.CB_READONLY, size=(100, -1))
42        self.font_weight = wx.ComboBox(self, pos=(300, 60), style=wx.CB_READONLY, size=(100, -1))
43        self.tick_label_check = wx.CheckBox(self, -1, label='', pos=(80, 100), size=(15, -1))
44        self.tick_label_check.SetValue(False)
45        wx.Button(self, wx.ID_OK, 'OK', pos=(215, 100))
46        wx.Button(self, wx.ID_CANCEL, 'Cancel', pos=(315, 100))
47
48        self._set_family_list()
49        self._set_style_list()
50        self._set_weight_list()
51        self._set_point_list()
52
53        wx.StaticText(self, label='Family:', pos=(10, 12))
54        wx.StaticText(self, label='Size:', pos=(220, 12))
55        wx.StaticText(self, label='Style:', pos=(10, 62))
56        wx.StaticText(self, label='Weight:', pos=(220, 62))
57        tick_label_text = wx.StaticText(self, label='Tick label?', pos=(10, 100))
58        tick_label_text.SetToolTipString("Apply to tick label too.")
59
60    def _set_family_list(self):
61        # list of font family
62        for idx in range(len(FAMILY)):
63            self.font_family.Append(FAMILY[idx], idx)
64
65    def _set_style_list(self):
66        # list of styles
67        for idx in range(len(STYLE)):
68            self.font_style.Append(STYLE[idx], idx)
69
70    def _set_weight_list(self):
71        # list of weights
72        for idx in range(len(WEIGHT)):
73            self.font_weight.Append(WEIGHT[idx], idx)
74
75    def _set_point_list(self):
76        # list of point sizes
77        for idx in range(len(SIZE)):
78            self.font_point.Append(str(SIZE[idx]), idx)
79
80    def get_ticklabel_check(self):
81        """
82        Get tick label check value
83        """
84        self.tick_label = self.tick_label_check.GetValue()
85        return self.tick_label
86
87    def set_ticklabel_check(self, check=False):
88        """
89        Set tick label check value
90        """
91        self.tick_label_check.SetValue(check)
92
93    def set_default_font(self, font):
94
95        if not font:
96            self.font_family.SetSelection(1)
97            self.font_weight.SetSelection(1)
98            self.font_point.SetSelection(3)
99            self.font_style.SetSelection(0)
100        else:
101            self.font_weight.SetStringSelection(str(font.get_weight()))
102            self.font_point.SetStringSelection(str(int(font.get_size())))
103            self.font_family.SetStringSelection(str(font.get_family()[0]))
104            self.font_style.SetStringSelection(str(font.get_style()))
105
106    def get_font(self):
107        font_properties = FontProperties()
108        font = font_properties.copy()
109        font.set_size(str(self.font_point.GetValue()))
110        font.set_name(str(self.font_family.GetValue()))
111        font.set_slant(str(self.font_style.GetValue()))
112        font.set_weight(str(self.font_weight.GetValue()))
113
114        return font
Note: See TracBrowser for help on using the repository browser.