diff options
Diffstat (limited to 'lib/gui/simulator')
| -rw-r--r-- | lib/gui/simulator/drawing_panel.py | 56 | ||||
| -rw-r--r-- | lib/gui/simulator/simulator_panel.py | 4 | ||||
| -rw-r--r-- | lib/gui/simulator/simulator_window.py | 3 | ||||
| -rw-r--r-- | lib/gui/simulator/view_panel.py | 17 |
4 files changed, 78 insertions, 2 deletions
diff --git a/lib/gui/simulator/drawing_panel.py b/lib/gui/simulator/drawing_panel.py index 9b705716..0d1b0afe 100644 --- a/lib/gui/simulator/drawing_panel.py +++ b/lib/gui/simulator/drawing_panel.py @@ -7,6 +7,7 @@ import time import wx from numpy import split +from ...debug.debug import debug from ...i18n import _ from ...svg import PIXELS_PER_MM from ...utils.settings import global_settings @@ -59,6 +60,9 @@ class DrawingPanel(wx.Panel): self.width = 0 self.height = 0 self.loaded = False + self.page_specs = {} + self.show_page = True + self.background_color = None # desired simulation speed in stitches per second self.speed = 16 @@ -122,6 +126,34 @@ class DrawingPanel(wx.Panel): self.draw_stitches(canvas) self.draw_scale(canvas) + def draw_page(self, canvas): + self._update_background_color() + + if not self.page_specs or not self.show_page: + return + + with debug.log_exceptions(): + border_color = wx.Colour(self.page_specs['border_color']) + if self.page_specs['show_page_shadow']: + canvas.SetPen(wx.TRANSPARENT_PEN) + canvas.SetBrush(canvas.CreateBrush(wx.Brush(wx.Colour(border_color.Red(), border_color.Green(), border_color.Blue(), alpha=65)))) + canvas.DrawRoundedRectangle( + (-self.page_specs['x'] + 4) * self.PIXEL_DENSITY, (-self.page_specs['y'] + 4) * self.PIXEL_DENSITY, + self.page_specs['width'] * self.PIXEL_DENSITY, self.page_specs['height'] * self.PIXEL_DENSITY, + 1 * self.PIXEL_DENSITY + ) + + pen = canvas.CreatePen( + wx.GraphicsPenInfo(wx.Colour(border_color)).Width(1 * self.PIXEL_DENSITY).Join(wx.JOIN_MITER) + ) + canvas.SetPen(pen) + canvas.SetBrush(wx.Brush(wx.Colour(self.background_color or self.page_specs['page_color']))) + + canvas.DrawRectangle( + -self.page_specs['x'] * self.PIXEL_DENSITY, -self.page_specs['y'] * self.PIXEL_DENSITY, + self.page_specs['width'] * self.PIXEL_DENSITY, self.page_specs['height'] * self.PIXEL_DENSITY + ) + def draw_stitches(self, canvas): canvas.BeginLayer(1) @@ -130,6 +162,8 @@ class DrawingPanel(wx.Panel): transform.Scale(self.zoom / self.PIXEL_DENSITY, self.zoom / self.PIXEL_DENSITY) canvas.SetTransform(transform) + self.draw_page(canvas) + stitch = 0 last_stitch = None @@ -252,6 +286,28 @@ class DrawingPanel(wx.Panel): if hasattr(self.view_panel, 'info_panel'): self.view_panel.info_panel.update() + def set_page_specs(self, page_specs): + self.SetBackgroundColour(page_specs['desk_color']) + self.page_specs = page_specs + + def set_background_color(self, color): + self.background_color = color + # this refresh is necessary for macOS + self.Refresh() + + def _update_background_color(self): + if not self.page_specs: + self.SetBackgroundColour(self.background_color or "#FFFFFF") + else: + if self.show_page: + self.SetBackgroundColour(self.page_specs['desk_color']) + else: + self.SetBackgroundColour(self.background_color or self.page_specs['page_color']) + + def set_show_page(self, show_page): + self.show_page = show_page + self._update_background_color() + def choose_zoom_and_pan(self, event=None): # ignore if EVT_SIZE fired before we load the stitch plan if not self.width and not self.height and event is not None: diff --git a/lib/gui/simulator/simulator_panel.py b/lib/gui/simulator/simulator_panel.py index 593b551a..1cea9214 100644 --- a/lib/gui/simulator/simulator_panel.py +++ b/lib/gui/simulator/simulator_panel.py @@ -30,6 +30,7 @@ class SimulatorPanel(wx.Panel): self.cp.set_drawing_panel(self.dp) self.vp.set_drawing_panel(self.dp) self.vp.set_background_color(wx.Colour(background_color)) + self.dp.set_background_color(wx.Colour(background_color)) dvSizer = wx.BoxSizer(wx.HORIZONTAL) @@ -93,3 +94,6 @@ class SimulatorPanel(wx.Panel): def clear(self): self.dp.clear() self.cp.clear() + + def set_page_specs(self, page_specs): + self.dp.set_page_specs(page_specs) diff --git a/lib/gui/simulator/simulator_window.py b/lib/gui/simulator/simulator_window.py index 2318041b..6ddc6f33 100644 --- a/lib/gui/simulator/simulator_window.py +++ b/lib/gui/simulator/simulator_window.py @@ -53,3 +53,6 @@ class SimulatorWindow(wx.Frame): def go(self): self.panel.go() + + def set_page_specs(self, page_specs): + self.panel.set_page_specs(page_specs) diff --git a/lib/gui/simulator/view_panel.py b/lib/gui/simulator/view_panel.py index 9cfe3331..27a89352 100644 --- a/lib/gui/simulator/view_panel.py +++ b/lib/gui/simulator/view_panel.py @@ -56,6 +56,13 @@ class ViewPanel(ScrolledPanel): self.btnBackgroundColor.SetToolTip(_("Change background color")) self.btnBackgroundColor.Bind(wx.EVT_COLOURPICKER_CHANGED, self.on_update_background_color) + if not self.detach_callback: + self.btnPage = wx.BitmapToggleButton(self, -1, style=self.button_style) + self.btnPage.Bind(wx.EVT_TOGGLEBUTTON, self.toggle_page) + self.btnPage.SetValue(True) + self.btnPage.SetBitmap(self.control_panel.load_icon('page')) + self.btnPage.SetToolTip(_('Show page')) + self.btnSettings = wx.BitmapToggleButton(self, -1, style=self.button_style) self.btnSettings.SetToolTip(_('Open settings dialog')) self.btnSettings.SetBitmap(self.control_panel.load_icon('settings')) @@ -94,6 +101,8 @@ class ViewPanel(ScrolledPanel): settings_sizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, _("Settings")), wx.VERTICAL) settings_inner_sizer = wx.BoxSizer(wx.VERTICAL) settings_inner_sizer.Add(self.btnBackgroundColor, 0, wx.EXPAND | wx.ALL, 2) + if not self.detach_callback: + settings_inner_sizer.Add(self.btnPage, 0, wx.EXPAND | wx.ALL, 2) settings_inner_sizer.Add(self.btnSettings, 0, wx.EXPAND | wx.ALL, 2) if self.detach_callback: settings_inner_sizer.Add(self.btnDetachSimulator, 0, wx.ALL, 2) @@ -109,11 +118,10 @@ class ViewPanel(ScrolledPanel): def on_update_background_color(self, event): self.set_background_color(event.Colour) + self.drawing_panel.set_background_color(event.Colour) def set_background_color(self, color): self.btnBackgroundColor.SetColour(color) - self.drawing_panel.SetBackgroundColour(color) - self.drawing_panel.Refresh() def on_toggle_npp_shortcut(self, event): self.btnNpp.SetValue(not self.btnNpp.GetValue()) @@ -122,6 +130,11 @@ class ViewPanel(ScrolledPanel): def toggle_npp(self, event): self.drawing_panel.Refresh() + def toggle_page(self, event): + debug.log("toggle page") + self.drawing_panel.set_show_page(self.btnPage.GetValue()) + self.drawing_panel.Refresh() + def on_marker_button(self, marker_type, event): self.control_panel.slider.enable_marker_list(marker_type, event.GetEventObject().GetValue()) if marker_type == 'jump': |
