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

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since edbd4b6 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
RevLine 
[a9d5684]1
2"""
[51f14603]3This software was developed by Institut Laue-Langevin as part of
4Distributed Data Analysis of Neutron Scattering Experiments (DANSE).
[a9d5684]5
[51f14603]6Copyright 2012 Institut Laue-Langevin
[a9d5684]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
[79492222]15FAMILY = ['serif', 'sas-serif', 'fantasy', 'monospace']
[a9d5684]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):
[3477478]22    def __init__(self, parent, id, title):
[a9d5684]23
[3477478]24        wx.Dialog.__init__(self, parent, id, title, size=(440, 160))
[a9d5684]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()
[3477478]37
[a9d5684]38    def InitUI(self):
[3477478]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))
[a9d5684]44        self.tick_label_check.SetValue(False)
[3477478]45        wx.Button(self, wx.ID_OK, 'OK', pos=(215, 100))
46        wx.Button(self, wx.ID_CANCEL, 'Cancel', pos=(315, 100))
47
[a9d5684]48        self._set_family_list()
49        self._set_style_list()
50        self._set_weight_list()
51        self._set_point_list()
[3477478]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))
[a9d5684]58        tick_label_text.SetToolTipString("Apply to tick label too.")
[3477478]59
[a9d5684]60    def _set_family_list(self):
61        # list of font family
[3477478]62        for idx in range(len(FAMILY)):
63            self.font_family.Append(FAMILY[idx], idx)
[a9d5684]64
65    def _set_style_list(self):
66        # list of styles
[3477478]67        for idx in range(len(STYLE)):
68            self.font_style.Append(STYLE[idx], idx)
[a9d5684]69
70    def _set_weight_list(self):
[3477478]71        # list of weights
72        for idx in range(len(WEIGHT)):
73            self.font_weight.Append(WEIGHT[idx], idx)
[a9d5684]74
75    def _set_point_list(self):
76        # list of point sizes
[3477478]77        for idx in range(len(SIZE)):
78            self.font_point.Append(str(SIZE[idx]), idx)
[a9d5684]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
[3477478]93    def set_default_font(self, font):
94
[a9d5684]95        if not font:
[3477478]96            self.font_family.SetSelection(1)
97            self.font_weight.SetSelection(1)
98            self.font_point.SetSelection(3)
99            self.font_style.SetSelection(0)
[a9d5684]100        else:
[3477478]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
[a9d5684]106    def get_font(self):
[3477478]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()))
[a9d5684]113
114        return font
Note: See TracBrowser for help on using the repository browser.