diff options
Diffstat (limited to 'lib/gui/simulator')
| -rw-r--r-- | lib/gui/simulator/control_panel.py | 8 | ||||
| -rw-r--r-- | lib/gui/simulator/drawing_panel.py | 3 | ||||
| -rw-r--r-- | lib/gui/simulator/simulator_preferences.py | 17 |
3 files changed, 25 insertions, 3 deletions
diff --git a/lib/gui/simulator/control_panel.py b/lib/gui/simulator/control_panel.py index e0efcd79..9226d5de 100644 --- a/lib/gui/simulator/control_panel.py +++ b/lib/gui/simulator/control_panel.py @@ -11,6 +11,7 @@ from wx.lib.intctrl import IntCtrl from ...debug.debug import debug from ...i18n import _ from ...utils import get_resource_dir +from ...utils.settings import global_settings from . import SimulatorSlider @@ -31,7 +32,7 @@ class ControlPanel(wx.Panel): self.drawing_panel = None self.num_stitches = 0 self.current_stitch = 0 - self.speed = 1 + self.speed = global_settings['simulator_speed'] self.direction = 1 self._last_color_block_end = 0 @@ -203,6 +204,9 @@ class ControlPanel(wx.Panel): return icon.ConvertToBitmap() def choose_speed(self): + if not global_settings['simulator_adaptive_speed']: + self.set_speed(global_settings['simulator_speed']) + return if self.target_duration: self.set_speed(int(self.num_stitches / float(self.target_duration))) else: @@ -225,6 +229,7 @@ class ControlPanel(wx.Panel): self.animation_reverse() def set_speed(self, speed): + global_settings['simulator_speed'] = speed self.speed = int(max(speed, 1)) self.update_speed_text() @@ -251,6 +256,7 @@ class ControlPanel(wx.Panel): if self.current_stitch != stitch: self.current_stitch = stitch self.slider.SetValue(stitch) + stitch = min(self.stitchBox.GetMax(), stitch) self.stitchBox.SetValue(stitch) def on_stitch_box_focus(self, event): diff --git a/lib/gui/simulator/drawing_panel.py b/lib/gui/simulator/drawing_panel.py index cb70db2d..ced11f00 100644 --- a/lib/gui/simulator/drawing_panel.py +++ b/lib/gui/simulator/drawing_panel.py @@ -65,7 +65,7 @@ class DrawingPanel(wx.Panel): self.background_color = None # desired simulation speed in stitches per second - self.speed = 16 + self.speed = global_settings['simulator_speed'] self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.choose_zoom_and_pan) @@ -399,6 +399,7 @@ class DrawingPanel(wx.Panel): def set_speed(self, speed): self.speed = speed + global_settings['simulator_speed'] = speed def forward(self): self.direction = 1 diff --git a/lib/gui/simulator/simulator_preferences.py b/lib/gui/simulator/simulator_preferences.py index ea134d22..7b72b87d 100644 --- a/lib/gui/simulator/simulator_preferences.py +++ b/lib/gui/simulator/simulator_preferences.py @@ -19,12 +19,19 @@ class SimulatorPreferenceDialog(wx.Dialog): self.view_panel = self.GetParent() self.drawing_panel = self.view_panel.drawing_panel + self.control_panel = self.view_panel.control_panel + self.adaptive_speed_value = global_settings['simulator_adaptive_speed'] self.line_width_value = global_settings['simulator_line_width'] self.npp_size_value = global_settings['simulator_npp_size'] sizer = wx.BoxSizer(wx.VERTICAL) - settings_sizer = wx.FlexGridSizer(2, 2, 5, 5) + settings_sizer = wx.FlexGridSizer(3, 2, 5, 5) + speed_label = wx.StaticText(self, label=_("Adapt speed to stitch count")) + self.adaptive_speed = wx.CheckBox(self) + self.adaptive_speed.SetToolTip(_("When enabled simulation speed adapts itself to the stitch count.")) + self.adaptive_speed.SetValue(self.adaptive_speed_value) + self.adaptive_speed.Bind(wx.EVT_CHECKBOX, self.on_adaptive_speed_changed) line_width_label = wx.StaticText(self, label=_("Line width (mm)")) self.line_width = wx.SpinCtrlDouble(self, min=0.03, max=2, initial=0.1, inc=0.01, style=wx.SP_WRAP | wx.SP_ARROW_KEYS) self.line_width.SetDigits(2) @@ -35,6 +42,8 @@ class SimulatorPreferenceDialog(wx.Dialog): self.npp_size.SetDigits(2) self.npp_size.SetValue(self.npp_size_value) self.npp_size.Bind(wx.EVT_SPINCTRLDOUBLE, lambda event: self.on_change("simulator_npp_size", event)) + settings_sizer.Add(speed_label, 0, wx.ALIGN_CENTRE | wx.ALL, 10) + settings_sizer.Add(self.adaptive_speed, 0, wx.EXPAND | wx.ALL, 10) settings_sizer.Add(line_width_label, 0, wx.ALIGN_CENTRE | wx.ALL, 10) settings_sizer.Add(self.line_width, 0, wx.EXPAND | wx.ALL, 10) settings_sizer.Add(npp_size_label, 0, wx.ALIGN_CENTRE | wx.ALL, 10) @@ -58,6 +67,12 @@ class SimulatorPreferenceDialog(wx.Dialog): self.drawing_panel.update_pen_size() self.drawing_panel.Refresh() + def on_adaptive_speed_changed(self, event=None): + adaptive_speed = self.adaptive_speed.GetValue() + global_settings['simulator_adaptive_speed'] = adaptive_speed + self.control_panel.choose_speed() + self.control_panel.Refresh() + def save_settings(self): global_settings['simulator_line_width'] = self.line_width.GetValue() global_settings['simulator_npp_size'] = self.npp_size.GetValue() |
