summaryrefslogtreecommitdiff
path: root/lib/gui/simulator/simulator_window.py
blob: 83321745d90a6b2c70ebbe7c6343a58c381437ab (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
# Authors: see git history
#
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later.  See the file LICENSE for details.
import wx

from ...i18n import _
from . import SimulatorPanel


class SimulatorWindow(wx.Frame):
    def __init__(self, panel=None, parent=None, **kwargs):
        background_color = kwargs.pop('background_color', 'white')
        super().__init__(None, title=_("Embroidery Simulation"), **kwargs)

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

        self.sizer = wx.BoxSizer(wx.VERTICAL)

        self.statusbar = self.CreateStatusBar(2)
        self.statusbar.SetStatusWidths((0, -1))

        if panel and parent:
            self.is_child = True
            self.panel = panel
            self.parent = parent
            self.panel.Reparent(self)
            self.sizer.Add(self.panel, 1, wx.EXPAND)
            self.panel.Show()
        else:
            self.is_child = False
            self.panel = SimulatorPanel(self, background_color=background_color)
            self.sizer.Add(self.panel, 1, wx.EXPAND)

        self.SetSizer(self.sizer)
        self.Layout()

        self.SetMinSize(self.sizer.CalcMin())

        if self.is_child:
            self.Bind(wx.EVT_CLOSE, self.on_close)
        else:
            self.Maximize()

    def detach_simulator_panel(self):
        self.sizer.Detach(self.panel)

    def on_close(self, event):
        self.parent.attach_simulator()

    def load(self, stitch_plan):
        self.panel.load(stitch_plan)

    def go(self):
        self.panel.go()