You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.0 KiB

  1. """
  2. Collection of Utility methods for creating often used, pre-styled wx Widgets
  3. """
  4. import wx
  5. from contextlib import contextmanager
  6. from gooey.gui.three_to_four import Constants
  7. @contextmanager
  8. def transactUI(obj):
  9. """
  10. Coarse grain UI locking to avoid glitchy UI updates
  11. """
  12. obj.Freeze()
  13. try:
  14. yield
  15. finally:
  16. obj.Layout()
  17. obj.Thaw()
  18. styles = {
  19. 'h0': (wx.FONTFAMILY_DEFAULT, Constants.WX_FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False),
  20. 'h1': (wx.FONTFAMILY_DEFAULT, Constants.WX_FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False),
  21. 'h2': (wx.FONTFAMILY_DEFAULT, Constants.WX_FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False),
  22. 'bold': (wx.FONTFAMILY_DEFAULT, Constants.WX_FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False)
  23. }
  24. def make_bold(statictext):
  25. pointsize = statictext.GetFont().GetPointSize()
  26. font = wx.Font(pointsize, *styles['bold'])
  27. statictext.SetFont(font)
  28. def dark_grey(statictext):
  29. return withColor(statictext, (54, 54, 54))
  30. def withColor(statictext, hex):
  31. statictext.SetForegroundColour(hex)
  32. return statictext
  33. def h0(parent, label):
  34. text = wx.StaticText(parent, label=label)
  35. font_size = text.GetFont().GetPointSize()
  36. font = wx.Font(int(font_size * 1.4, *styles['h0']))
  37. text.SetFont(font)
  38. return text
  39. def h1(parent, label):
  40. return _header(parent, label, styles['h1'])
  41. def h2(parent, label):
  42. return _header(parent, label, styles['h2'])
  43. def _header(parent, label, styles):
  44. text = wx.StaticText(parent, label=label)
  45. font_size = text.GetFont().GetPointSize()
  46. font = wx.Font(int(font_size * 1.2), *styles)
  47. text.SetFont(font)
  48. return text
  49. def horizontal_rule(parent):
  50. return _rule(parent, wx.LI_HORIZONTAL)
  51. def vertical_rule(parent):
  52. return _rule(parent, wx.LI_VERTICAL)
  53. def _rule(parent, direction):
  54. line = wx.StaticLine(parent, -1, style=direction)
  55. line.SetSize((10, 10))
  56. return line