libtextworker 0.1.4
Cross-platform, free and open library for Python projects
__init__.py
1 """
2 @package libtextworker.interface.wx
3 Contains classes for wxPython.
4 wxPython must be installed first:
5 
6  $ pip install attrdict3
7  $ pip install wxPython
8 
9 Else libtextworker will refuse to use this package.
10 """
11 
12 # A cross-platform library for Python apps.
13 # Copyright (C) 2023-2024 Le Bao Nguyen and contributors.
14 # This is a part of the libtextworker project.
15 # Licensed under the GNU General Public License version 3.0 or later.
16 
17 from libtextworker import Importable
18 from . import constants
19 from .. import manager
20 
21 if Importable["wx"] == True:
22  import wx
23 else:
24  raise Exception("wxPython is needed to use libtextworker.interface.wx")
25 
26 
28  recursive_configure: bool = True
29 
30  def GetFont(this):
31  size, style, weight, family = manager.ColorManager.GetFont(this)
32 
33  _dict = {"system": "normal"}
34  weight = _dict.get(weight, weight)
35  style = _dict.get(style, style)
36 
37  return wx.Font(size, wx.FONTFAMILY_MODERN, constants.FONTST[style],
38  constants.FONTWT[weight], 0, family)
39 
40  def configure(this, widget: wx.Control, childs_too: bool = recursive_configure):
41  manager.ColorManager.configure(this, widget)
42 
43  # fore&back
44  bg, fg = this.GetColor()
45  bg = wx.Colour(*manager.hextorgb(bg))
46  fg = wx.Colour(*manager.hextorgb(fg))
47 
48  # font
49  font = this.GetFont()
50 
51  if childs_too and hasattr(widget, "GetChildren"):
52  widget.SetBackgroundColour(bg)
53  widget.SetForegroundColour(fg)
54  for children in widget.GetChildren():
55  this.configure(children, True)
56  else:
57  widget.SetOwnBackgroundColour(bg)
58  widget.SetOwnForegroundColour(fg)
59 
60  widget.SetFont(font)
61 
62 
63 clrmgr = None