summaryrefslogtreecommitdiff
path: root/lib/gui/element_info.py
blob: cee93e3e1c319e0c7462b430dbcf5de121100021 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Authors: see git history
#
# Copyright (c) 2023 Authors
# Licensed under the GNU GPL version 3.0 or later.  See the file LICENSE for details.

import wx
import wx.adv

from ..i18n import _


class ElementInfoFrame(wx.Frame):

    def __init__(self, *args, **kwargs):
        self.list_items = kwargs.pop("list_items")
        self.index = 0
        wx.Frame.__init__(self, None, wx.ID_ANY, _("Element Info"), *args, **kwargs)

        self.SetWindowStyle(wx.FRAME_FLOAT_ON_PARENT | wx.DEFAULT_FRAME_STYLE)

        self.main_panel = wx.Panel(self, wx.ID_ANY)

        notebook_sizer = wx.BoxSizer(wx.VERTICAL)
        self.notebook = wx.Notebook(self.main_panel, wx.ID_ANY)
        notebook_sizer.Add(self.notebook, 1, wx.EXPAND, 0)

        self.info = wx.Panel(self.notebook, wx.ID_ANY)
        self.notebook.AddPage(self.info, _("Info"))

        info_sizer = wx.BoxSizer(wx.VERTICAL)

        self.info_list = wx.ListCtrl(self.info, wx.ID_ANY, style=wx.BORDER_SUNKEN | wx.LC_HRULES | wx.LC_REPORT | wx.LC_VRULES)
        self.info_list.AppendColumn(_("Name"), format=wx.LIST_FORMAT_LEFT)
        self.info_list.AppendColumn(_("Value"), format=wx.LIST_FORMAT_LEFT)
        self._fill_info_list()
        self.info_list.SetColumnWidth(0, -1)
        self.info_list.SetColumnWidth(1, -1)
        info_sizer.Add(self.info_list, 1, wx.ALL | wx.EXPAND, 10)

        self.help = wx.Panel(self.notebook, wx.ID_ANY)
        self.notebook.AddPage(self.help, _("Help"))

        help_sizer = wx.BoxSizer(wx.VERTICAL)

        help_text = wx.StaticText(
            self.help,
            wx.ID_ANY,
            _("This extension informs about various parameters of selected stitch elements."),
            style=wx.ALIGN_LEFT
        )
        help_text.Wrap(500)
        help_sizer.Add(help_text, 0, wx.ALL, 8)

        help_sizer.Add((20, 20), 0, 0, 0)

        website_info = wx.StaticText(self.help, wx.ID_ANY, _("More information on our website:"))
        help_sizer.Add(website_info, 0, wx.ALL, 8)

        self.website_link = wx.adv.HyperlinkCtrl(
            self.help,
            wx.ID_ANY,
            _("https://inkstitch.org/docs/troubleshoot#element-info"),
            _("https://inkstitch.org/docs/troubleshoot#element-info")
        )
        help_sizer.Add(self.website_link, 0, wx.ALL, 8)

        self.help.SetSizer(help_sizer)
        self.info.SetSizer(info_sizer)
        self.main_panel.SetSizer(notebook_sizer)

        self.SetSizeHints(notebook_sizer.CalcMin())

        self.Layout()

    def _fill_info_list(self):
        for item in self.list_items:
            self.info_list.InsertItem(self.index, item.name)
            if item.headline:
                self.info_list.SetItemBackgroundColour(self.index, "black")
                self.info_list.SetItemTextColour(self.index, "white")
                self.index += 1
                self.info_list.InsertItem(self.index, "")
                self.info_list.SetItemBackgroundColour(self.index, item.value)
            elif item.warning:
                self.info_list.SetItem(self.index, 1, item.value)
                self.info_list.SetItemBackgroundColour(self.index, "#ffdddd")
            else:
                self.info_list.SetItem(self.index, 1, item.value)
            self.index += 1


class ElementInfoApp(wx.App):
    def __init__(self, list_items):
        self.list_items = list_items
        super().__init__()

    def OnInit(self):
        self.frame = ElementInfoFrame(list_items=self.list_items)
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True