diff options
| author | LaureFR38 <63351363+LaureFR38@users.noreply.github.com> | 2021-02-04 16:40:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-04 16:40:02 +0100 |
| commit | 1cb501986f9c1135c861472366737563ebe79681 (patch) | |
| tree | 00f62bc52928e48100b9b5dab2384d09aedf4034 /lib/gui | |
| parent | dac312f01fe83f6ade1b0b1845c92106587ff89e (diff) | |
Update font.py (#848)
* Add new fonts
* Update old fonts
* Update lettering gui
Co-authored-by: Lex Neva
Co-authored-by: kalleen
Diffstat (limited to 'lib/gui')
| -rw-r--r-- | lib/gui/__init__.py | 9 | ||||
| -rw-r--r-- | lib/gui/subtitle_combo_box.py | 85 |
2 files changed, 4 insertions, 90 deletions
diff --git a/lib/gui/__init__.py b/lib/gui/__init__.py index 2214db5d..8869fb6d 100644 --- a/lib/gui/__init__.py +++ b/lib/gui/__init__.py @@ -1,5 +1,4 @@ -from dialogs import info_dialog, confirm_dialog -from electron import open_url -from presets import PresetsPanel -from simulator import EmbroiderySimulator, SimulatorPreview, show_simulator -from subtitle_combo_box import SubtitleComboBox +from .dialogs import confirm_dialog, info_dialog +from .electron import open_url +from .presets import PresetsPanel +from .simulator import EmbroiderySimulator, SimulatorPreview, show_simulator diff --git a/lib/gui/subtitle_combo_box.py b/lib/gui/subtitle_combo_box.py deleted file mode 100644 index 64c42153..00000000 --- a/lib/gui/subtitle_combo_box.py +++ /dev/null @@ -1,85 +0,0 @@ -import wx -import wx.adv -from wx.lib.wordwrap import wordwrap - - -class SubtitleComboBox(wx.adv.OwnerDrawnComboBox): - TITLE_FONT_SIZE = 12 - SUBTITLE_FONT_SIZE = 10 - - # I'd love to make this 12 too, but if I do it seems to get drawn as 10 - # initially no matter what I do. - CONTROL_FONT_SIZE = 12 - - MARGIN = 5 - - def __init__(self, *args, **kwargs): - self.titles = kwargs.get('choices', []) - subtitles = kwargs.pop('subtitles', {}) - self.subtitles = [subtitles.get(title, '') for title in self.titles] - wx.adv.OwnerDrawnComboBox.__init__(self, *args, **kwargs) - - self.control_font = wx.Font(pointSize=self.CONTROL_FONT_SIZE, family=wx.DEFAULT, style=wx.NORMAL, weight=wx.NORMAL) - self.title_font = wx.Font(pointSize=self.TITLE_FONT_SIZE, family=wx.DEFAULT, style=wx.NORMAL, weight=wx.NORMAL) - self.subtitle_font = wx.Font(pointSize=self.SUBTITLE_FONT_SIZE, family=wx.DEFAULT, style=wx.NORMAL, weight=wx.NORMAL) - - def OnMeasureItemWidth(self, item): - # This _should_ allow us to set the width of the combobox to match the - # width of the widest title. In reality, this method is never called - # and I can't figure out why. We just use self.GetSize().GetWidth() - # instead and rely on the parent window to size us appropriately. Ugh. - - title = self.titles[item] - - # technique from https://stackoverflow.com/a/23529463/4249120 - dc = wx.ScreenDC() - dc.SetFont(self.title_font) - - return dc.GetTextExtent(title).GetWidth() + 2 * self.MARGIN - - def OnMeasureItem(self, item): - title = self.titles[item] - subtitle = self.subtitles[item] - - dc = wx.ScreenDC() - dc.SetFont(self.subtitle_font) - wrapped = wordwrap(subtitle, self.GetSize().GetWidth(), dc) - subtitle_height = dc.GetTextExtent(wrapped).GetHeight() - - dc = wx.ScreenDC() - dc.SetFont(self.title_font) - title_height = dc.GetTextExtent(title).GetHeight() - - return subtitle_height + title_height + 3 * self.MARGIN - - def OnDrawBackground(self, dc, rect, item, flags): - if flags & wx.adv.ODCB_PAINTING_SELECTED: - # let the parent class draw the selected item so we don't - # hae to figure out the highlight color - wx.adv.OwnerDrawnComboBox.OnDrawBackground(self, dc, rect, item, flags) - else: - # alternate white and grey for the dropdown items, and draw the - # combo box itself as white - if flags & wx.adv.ODCB_PAINTING_CONTROL or item % 2 == 0: - background_color = wx.Colour(255, 255, 255) - else: - background_color = wx.Colour(240, 240, 240) - - dc.SetBrush(wx.Brush(background_color)) - dc.SetPen(wx.Pen(background_color)) - dc.DrawRectangle(rect) - - def OnDrawItem(self, dc, rect, item, flags): - if flags & wx.adv.ODCB_PAINTING_CONTROL: - # painting the selected item in the box - dc.SetFont(self.control_font) - dc.DrawText(self.titles[item], rect.x + self.MARGIN, rect.y + self.MARGIN) - else: - # painting the items in the popup - dc.SetFont(self.title_font) - title_height = dc.GetCharHeight() - dc.DrawText(self.titles[item], rect.x + self.MARGIN, rect.y + self.MARGIN) - - dc.SetFont(self.subtitle_font) - subtitle = wordwrap(self.subtitles[item], self.GetSize().GetWidth(), dc) - dc.DrawText(subtitle, rect.x + self.MARGIN, rect.y + title_height + self.MARGIN * 2) |
