summaryrefslogtreecommitdiff
path: root/lib/gui/windows.py
blob: 42c34cc84e858b6dc1cb19ad82571a1c128d817a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import wx


class SimpleBox(wx.Panel):
    """Draw a box around one window.

    Usage:

        window = SomeWindow(your_window_or_panel, wx.ID_ANY)
        box = SimpleBox(your_window_or_panel, window)
        some_sizer.Add(box, ...)

    """

    def __init__(self, parent, window, *args, width=1, radius=2, **kwargs):
        super().__init__(parent, wx.ID_ANY, *args, **kwargs)

        window.Reparent(self)
        self.window = window
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(window, 1, wx.EXPAND | wx.ALL, 2)
        self.SetSizer(self.sizer)

        self.width = width
        self.radius = radius

        self.Bind(wx.EVT_ERASE_BACKGROUND, self.on_erase_background)

    def on_erase_background(self, event):
        dc = event.GetDC()
        if not dc:
            dc = wx.ClientDC(self)
        size = self.GetClientSize()

        if wx.SystemSettings().GetAppearance().IsDark():
            dc.SetPen(wx.Pen(wx.Colour(32, 32, 32), width=self.width))
        else:
            dc.SetPen(wx.Pen(wx.Colour(128, 128, 128), width=self.width))

        dc.SetBrush(wx.NullBrush)
        dc.DrawRoundedRectangle(0, 0, size.x, size.y, self.radius)