From a1440903cb91f3effd7cd23a395dbe3f8f9bed00 Mon Sep 17 00:00:00 2001 From: Momo Date: Mon, 20 Aug 2018 18:28:52 +0200 Subject: update slider maxValue when params have changed --- lib/extensions/params.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/extensions') diff --git a/lib/extensions/params.py b/lib/extensions/params.py index c464e044..ce06cf2c 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -287,7 +287,6 @@ class ParamsTab(ScrolledPanel): summary_box = wx.StaticBox(self, wx.ID_ANY, label=_("Inkscape objects")) sizer = wx.StaticBoxSizer(summary_box, wx.HORIZONTAL) -# sizer = wx.BoxSizer(wx.HORIZONTAL) self.description = wx.StaticText(self) self.update_description() self.description.SetLabel(self.description_text) @@ -423,6 +422,12 @@ class SettingsFrame(wx.Frame): if self.simulate_window: self.simulate_window.stop() self.simulate_window.load(stitch_plan=stitch_plan) + + children = self.simulate_window.GetChildren() + for child in children: + if isinstance(child, wx.Slider): + child.Destroy() + self.simulate_window.set_slider() else: params_rect = self.GetScreenRect() simulator_pos = params_rect.GetTopRight() -- cgit v1.3.1 From 505388a9c1f16f351e353061e0588543fd96c824 Mon Sep 17 00:00:00 2001 From: Momo Date: Wed, 22 Aug 2018 19:24:53 +0200 Subject: fix jumping timeline and remove symbols --- lib/extensions/params.py | 3 +++ lib/simulator.py | 57 ++++++++++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 24 deletions(-) (limited to 'lib/extensions') diff --git a/lib/extensions/params.py b/lib/extensions/params.py index ce06cf2c..4b21d1dc 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -428,6 +428,9 @@ class SettingsFrame(wx.Frame): if isinstance(child, wx.Slider): child.Destroy() self.simulate_window.set_slider() + + self.simulate_window.Layout() + self.simulate_window.Refresh() else: params_rect = self.GetScreenRect() simulator_pos = params_rect.GetTopRight() diff --git a/lib/simulator.py b/lib/simulator.py index ad8ead8d..d7059b53 100644 --- a/lib/simulator.py +++ b/lib/simulator.py @@ -1,9 +1,9 @@ import sys import numpy import wx +import time import colorsys from itertools import izip -from itertools import cycle from .svg import PIXELS_PER_MM, color_block_to_point_lists @@ -24,7 +24,7 @@ class EmbroiderySimulator(wx.Frame): self.max_height = kwargs.pop('max_height', screen_rect[3]) self.scale = 1 - self.min_width = 600 + self.min_width = 800 if self.max_width < self.min_width: self.max_width = self.min_width @@ -32,23 +32,23 @@ class EmbroiderySimulator(wx.Frame): wx.Frame.__init__(self, *args, **kwargs) - self.SetBackgroundColour('white') - self.panel = wx.Panel(self, wx.ID_ANY) self.panel.SetBackgroundStyle(wx.BG_STYLE_PAINT) + self.SetBackgroundColour('white') + self.slider_sizer = wx.BoxSizer(wx.HORIZONTAL) self.set_slider() self.button_sizer = wx.StdDialogButtonSizer() self.button_label = ( - [u"\u2BC7", _('Play backwards (arrow left)'), self.animation_backwards], - [u"\u2BC8", _('Play forwards (arrow right)'), self.animation_forwards], - [u"\u2BC5", _('Speed up (arrow up)'), self.animation_speed_up], - [u"\u2BC6", _('Slow down (arrow down)'), self.animation_slow_down], - [u"\u23F8", _("Pause (P)"), self.animation_pause], - [u"\u2B8C", _("Restart (R)"), self.animation_restart], - [u"\u2BBF", _("Close (Q)"), self.animation_quit]) + [_("Reverse"), _('Play reverse (arrow left)'), self.animation_backwards], + [_("Forward"), _('Play forward (arrow right)'), self.animation_forwards], + [_("Speed up"), _('Speed up (+ or arrow up)'), self.animation_speed_up], + [_("Slow down"), _('Slow down (- or arrow down)'), self.animation_slow_down], + [_("Pause"), _("Pause (P)"), self.animation_pause], + [_("Restart"), _("Restart (R)"), self.animation_restart], + [_("Quit"), _("Close (Q)"), self.animation_quit]) self.buttons = [] for i in range(0, len(self.button_label)): @@ -64,6 +64,8 @@ class EmbroiderySimulator(wx.Frame): self.sizer.Add(self.button_sizer, 0, wx.EXPAND) self.SetSizer(self.sizer) + self.calculate_dimensions() + if self.target_duration: self.adjust_speed(self.target_duration) @@ -137,7 +139,6 @@ class EmbroiderySimulator(wx.Frame): self.mirror = False self.stitch_plan_to_lines(stitch_plan) self.move_to_top_left() - self.calculate_dimensions() return def adjust_speed(self, duration): @@ -196,14 +197,8 @@ class EmbroiderySimulator(wx.Frame): self.timer.StartOnce(self.frame_period) def set_stitch_counter(self, current_frame): - if hasattr(self.panel, 'stitch_counter'): - self.panel.stitch_counter.SetLabel(_("Stitch # ") + str(current_frame) + ' / ' + str(len(self.lines))) - else: - self.font = wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL) - self.panel.stitch_counter = wx.StaticText(self, label=_("Stitch #") + '1 / ' + str(len(self.lines)), pos=(30, 10)) - self.panel.stitch_counter.SetFont(self.font) - self.panel.stitch_counter.SetForegroundColour('red') - self.panel.stitch_counter.SetBackgroundColour('white') + self.dc.SetTextForeground('red') + self.dc.DrawText(_("Stitch # ") + str(current_frame) + ' / ' + str(len(self.lines)), 30, 10) def on_slider(self, event): self.panel.SetFocus() @@ -278,7 +273,11 @@ class EmbroiderySimulator(wx.Frame): self.width = width self.height = height - self.scale = min(float(self.max_width - self.margin * 2) / width, float(self.max_height - self.margin * 2 - 90) / height) + button_width, button_height = self.buttons[0].GetSize() + slider_width, slider_height = self.stitch_slider.GetSize() + self.controls_height = button_height + slider_height + + self.scale = min(float(self.max_width - self.margin * 2) / width, float(self.max_height - self.margin * 2 - self.controls_height) / height) # make room for decorations and the margin self.scale *= 0.95 @@ -329,10 +328,10 @@ class EmbroiderySimulator(wx.Frame): client_width, client_height = self.GetClientSize() decorations_width = window_width - client_width - decorations_height = window_height - client_height + 90 + decorations_height = window_height - client_height + self.controls_height setsize_window_width = self.width * self.scale + decorations_width + self.margin * 2 - setsize_window_height = (self.height) * self.scale + decorations_height + self.margin * 2 + setsize_window_height = self.height * self.scale + decorations_height + self.margin * 2 # set minimum width (force space for control buttons) if setsize_window_width < self.min_width: @@ -342,7 +341,7 @@ class EmbroiderySimulator(wx.Frame): # center the simulation on screen if not called by params # else center vertically - if self.x_position == None: + if self.x_position is None: self.Centre() else: display_rect = self.get_current_screen_rect() @@ -386,3 +385,13 @@ class EmbroiderySimulator(wx.Frame): self.visible_lines = self.lines[:self.current_frame] self.dc.DrawLineList(self.visible_lines, self.pens[:self.current_frame]) + ''' + Calculate time_to_next_frame + start = time.time() + self.draw_one_frame() + duration = time.time() - start + duration_ms = int(duration * 1000) + time_to_next_frame = self.frame_period - duration_ms + time_to_next_frame = max(0.01, time_to_next_frame) + self.timer.StartOnce(time_to_next_frame) + ''' -- cgit v1.3.1 From 56e153e87187a6bdad99faebc43253dfc40d4588 Mon Sep 17 00:00:00 2001 From: Momo Date: Thu, 23 Aug 2018 12:48:41 +0200 Subject: merge forward/backward/speed --- lib/extensions/params.py | 1 + lib/simulator.py | 135 ++++++++++++++++++++++++++++++----------------- 2 files changed, 88 insertions(+), 48 deletions(-) (limited to 'lib/extensions') diff --git a/lib/extensions/params.py b/lib/extensions/params.py index 4b21d1dc..a77c96f1 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -422,6 +422,7 @@ class SettingsFrame(wx.Frame): if self.simulate_window: self.simulate_window.stop() self.simulate_window.load(stitch_plan=stitch_plan) + self.simulate_window.calculate_dimensions() children = self.simulate_window.GetChildren() for child in children: diff --git a/lib/simulator.py b/lib/simulator.py index c3ddc55e..41302822 100644 --- a/lib/simulator.py +++ b/lib/simulator.py @@ -24,7 +24,7 @@ class EmbroiderySimulator(wx.Frame): self.max_height = kwargs.pop('max_height', screen_rect[3]) self.scale = 1 - self.min_width = 800 + self.min_width = 600 if self.max_width < self.min_width: self.max_width = self.min_width @@ -42,10 +42,10 @@ class EmbroiderySimulator(wx.Frame): self.button_sizer = wx.StdDialogButtonSizer() self.button_label = ( - [_("Reverse"), _('Play reverse (arrow left)'), self.animation_backwards], - [_("Forward"), _('Play forward (arrow right)'), self.animation_forwards], - [_("Speed up"), _('Speed up (+ or arrow up)'), self.animation_speed_up], - [_("Slow down"), _('Slow down (- or arrow down)'), self.animation_slow_down], + [_("<<"), _('Speed / Play reverse (arrow left)'), self.animation_reverse], + [_(">>"), _('Speed / Play forward (arrow right)'), self.animation_forward], + #[_("Speed up"), _('Speed up (+ or arrow up)'), self.animation_speed_up], + #[_("Slow down"), _('Slow down (- or arrow down)'), self.animation_slow_down], [_("Pause"), _("Pause (P)"), self.animation_pause], [_("Restart"), _("Restart (R)"), self.animation_restart], [_("Quit"), _("Close (Q)"), self.animation_quit]) @@ -64,6 +64,8 @@ class EmbroiderySimulator(wx.Frame): self.sizer.Add(self.button_sizer, 0, wx.EXPAND) self.SetSizer(self.sizer) + self.calculate_dimensions() + if self.target_duration: self.adjust_speed(self.target_duration) @@ -75,8 +77,9 @@ class EmbroiderySimulator(wx.Frame): self.clear() self.current_frame = 0 - self.set_stitch_counter(0) self.animation_direction = 1 + self.speed_info = self.calculate_speed_level() + self.set_stitch_counter(0) shortcut_keys = [ (wx.ACCEL_NORMAL, ord('+'), self.animation_speed_up), @@ -92,10 +95,10 @@ class EmbroiderySimulator(wx.Frame): (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_SUBTRACT, self.animation_slow_down), (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_DOWN, self.animation_slow_down), (wx.ACCEL_NORMAL, wx.WXK_DOWN, self.animation_slow_down), - (wx.ACCEL_NORMAL, wx.WXK_RIGHT, self.animation_forwards), - (wx.ACCEL_NORMAL, wx.WXK_LEFT, self.animation_backwards), - (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_RIGHT, self.animation_forwards), - (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_LEFT, self.animation_backwards), + (wx.ACCEL_NORMAL, wx.WXK_RIGHT, self.animation_forward), + (wx.ACCEL_NORMAL, wx.WXK_LEFT, self.animation_reverse), + (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_RIGHT, self.animation_forward), + (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_LEFT, self.animation_reverse), (wx.ACCEL_NORMAL, ord('r'), self.animation_restart), (wx.ACCEL_NORMAL, ord('p'), self.animation_pause), (wx.ACCEL_NORMAL, ord('q'), self.animation_quit)] @@ -121,11 +124,6 @@ class EmbroiderySimulator(wx.Frame): self.last_pos = None - def set_slider(self): - self.stitch_slider = wx.Slider(self, value=1, minValue=1, maxValue=len(self.lines), - style = wx.SL_HORIZONTAL|wx.SL_LABELS) - self.slider_sizer.Add(self.stitch_slider, 1, wx.EXPAND) - def get_current_screen_rect(self): current_screen = wx.Display.GetFromPoint(wx.GetMousePosition()) display = wx.Display(current_screen) @@ -137,7 +135,6 @@ class EmbroiderySimulator(wx.Frame): self.mirror = False self.stitch_plan_to_lines(stitch_plan) self.move_to_top_left() - self.calculate_dimensions() return def adjust_speed(self, duration): @@ -148,18 +145,44 @@ class EmbroiderySimulator(wx.Frame): self.frame_period *= 2 self.stitches_per_frame *= 2 - def animation_speed_up(self, event): - if self.frame_period == 1: - self.stitches_per_frame *= 2 + def animation_forward(self, event): + if self.current_frame == 1: + self.animation_direction = 1 + self.timer.StartOnce(self.frame_period) + elif self.animation_direction == -1 and self.frame_period > 1280: + self.animation_direction = 1 + self.set_speed_info(self.calculate_speed_level()) + elif self.animation_direction == 1: + self.animation_speed_up('speed_up') else: - self.frame_period = self.frame_period / 2 + self.animation_slow_down('slow_down') + + def animation_reverse(self, event): + if self.current_frame == len(self.lines): + self.animation_direction = -1 + self.timer.StartOnce(self.frame_period) + elif self.animation_direction == 1 and self.frame_period > 1280: + self.animation_direction = -1 + self.set_speed_info(self.calculate_speed_level()) + elif self.animation_direction == -1: + self.animation_speed_up('speed_up') + else: + self.animation_slow_down('slow_down') + + def animation_speed_up(self, event): + if self.stitches_per_frame <= 2560: + if self.frame_period == 1: + self.stitches_per_frame *= 2 + else: + self.frame_period = self.frame_period / 2 self.animation_update_timer() def animation_slow_down(self, event): - if self.stitches_per_frame == 1: - self.frame_period *= 2 - else: - self.stitches_per_frame /= 2 + if self.frame_period <= 2560: + if self.stitches_per_frame == 1: + self.frame_period *= 2 + else: + self.stitches_per_frame /= 2 self.animation_update_timer() def animation_restart(self, event): @@ -180,24 +203,36 @@ class EmbroiderySimulator(wx.Frame): def animation_update_timer(self): self.frame_period = max(1, self.frame_period) self.stitches_per_frame = max(self.stitches_per_frame, 1) + self.speed_info = self.calculate_speed_level() self.set_stitch_counter(self.current_frame) if self.timer.IsRunning(): self.timer.Stop() self.timer.StartOnce(self.frame_period) - def animation_backwards(self, event): - self.animation_direction = -1 - if self.current_frame > 1: - self.timer.StartOnce(self.frame_period) - - def animation_forwards(self, event): - self.animation_direction = 1 - if self.current_frame < len(self.lines): - self.timer.StartOnce(self.frame_period) + def calculate_speed_level(self): + count = 0 + speed = self.frame_period + speed_plus = 1 + animation_direction = '>>' if self.animation_direction == 1 else '<<' + while speed <= 2560: + speed = speed * 2 + count += 1 + while speed_plus < self.stitches_per_frame: + speed_plus = speed_plus * 2 + count += 1 + return animation_direction + ' x' + str(count) def set_stitch_counter(self, current_frame): self.dc.SetTextForeground('red') - self.dc.DrawText(_("Stitch # ") + str(current_frame) + ' / ' + str(len(self.lines)), 30, 10) + stitch_counter_text = _("Stitch # ") + str(current_frame) + ' / ' + str(len(self.lines)) + self.dc.DrawText(stitch_counter_text, 30, 5) + self.set_speed_info(self.speed_info) + + def set_speed_info(self, speed_info): + self.speed_info = speed_info + #counter_width, counter_height= self.dc.GetTextExtent(speed_info) + self.dc.SetTextForeground('blue') + self.dc.DrawText(_("Speed ") + str(speed_info), 220, 5) def on_slider(self, event): self.panel.SetFocus() @@ -206,6 +241,11 @@ class EmbroiderySimulator(wx.Frame): self.current_frame = obj.GetValue() self.animation_update_timer() + def set_slider(self): + self.stitch_slider = wx.Slider(self, value=1, minValue=1, maxValue=len(self.lines), + style=wx.SL_HORIZONTAL | wx.SL_LABELS) + self.slider_sizer.Add(self.stitch_slider, 1, wx.EXPAND) + def set_stitch_slider(self, val): self.stitch_slider.SetValue(val) @@ -272,7 +312,11 @@ class EmbroiderySimulator(wx.Frame): self.width = width self.height = height - self.scale = min(float(self.max_width - self.margin * 2) / width, float(self.max_height - self.margin * 2) / height) + button_width, button_height = self.buttons[0].GetSize() + slider_width, slider_height = self.stitch_slider.GetSize() + self.controls_height = button_height + slider_height + + self.scale = min(float(self.max_width - self.margin * 2) / width, float(self.max_height - self.margin * 2 - self.controls_height) / height) # make room for decorations and the margin self.scale *= 0.95 @@ -326,7 +370,7 @@ class EmbroiderySimulator(wx.Frame): decorations_height = window_height - client_height setsize_window_width = self.width * self.scale + decorations_width + self.margin * 2 - setsize_window_height = self.height * self.scale + decorations_height + self.margin * 2 + setsize_window_height = self.height * self.scale + decorations_height + self.controls_height + self.margin * 2 # set minimum width (force space for control buttons) if setsize_window_width < self.min_width: @@ -361,8 +405,14 @@ class EmbroiderySimulator(wx.Frame): self.current_frame += self.stitches_per_frame * self.animation_direction if self.current_frame <= len(self.lines) and self.current_frame >= 1: + #Calculate time_to_next_frame + start = time.time() self.draw_one_frame() - self.timer.StartOnce(self.frame_period) + duration = time.time() - start + duration_ms = int(duration * 1000) + time_to_next_frame = self.frame_period - duration_ms + time_to_next_frame = max(1, time_to_next_frame) + self.timer.StartOnce(time_to_next_frame) elif self.current_frame > len(self.lines): self.current_frame = len(self.lines) self.draw_one_frame() @@ -379,14 +429,3 @@ class EmbroiderySimulator(wx.Frame): self.clear() self.visible_lines = self.lines[:self.current_frame] self.dc.DrawLineList(self.visible_lines, self.pens[:self.current_frame]) - - ''' - Calculate time_to_next_frame - start = time.time() - self.draw_one_frame() - duration = time.time() - start - duration_ms = int(duration * 1000) - time_to_next_frame = self.frame_period - duration_ms - time_to_next_frame = max(0.01, time_to_next_frame) - self.timer.StartOnce(time_to_next_frame) - ''' -- cgit v1.3.1 From c5bd1878846c17309c99ad7554d4645088de9629 Mon Sep 17 00:00:00 2001 From: Momo Date: Sat, 25 Aug 2018 10:57:17 +0200 Subject: * seperated controls * one frame movements --- lib/extensions/params.py | 1 - lib/simulator.py | 130 +++++++++++++++++++++-------------------------- 2 files changed, 58 insertions(+), 73 deletions(-) (limited to 'lib/extensions') diff --git a/lib/extensions/params.py b/lib/extensions/params.py index a77c96f1..6d1464a3 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -431,7 +431,6 @@ class SettingsFrame(wx.Frame): self.simulate_window.set_slider() self.simulate_window.Layout() - self.simulate_window.Refresh() else: params_rect = self.GetScreenRect() simulator_pos = params_rect.GetTopRight() diff --git a/lib/simulator.py b/lib/simulator.py index 10ee0569..e662eaf9 100644 --- a/lib/simulator.py +++ b/lib/simulator.py @@ -40,15 +40,17 @@ class EmbroiderySimulator(wx.Frame): self.button_sizer = wx.StdDialogButtonSizer() self.button_label = ( - [_("<<"), - _('Speed | Play reverse (arrow left)'), - self.animation_reverse], - [_(">>"), - _('Speed | Play forward (arrow right)'), - self.animation_forward], - [_("Pause"), _("Pause (P)"), self.animation_pause], - [_("Restart"), _("Restart (R)"), self.animation_restart], - [_("Quit"), _("Close (Q)"), self.animation_quit]) + # Switch direction button (currently not in use - would this be better?) + #[_('>>'), _('Switch direction | Play reverse (arrow left) | Play forward (arrow right)'), self.animation_switch_direction], + [_('<<'), _('Play reverse (arrow left)'), self.animation_reverse], + [_('-'), _('Play one frame backward (+)'), self.animation_one_frame_back], + [_('+'), _('Play one frame forward (+)'), self.animation_one_frame_forward], + [_('>>'), _('Play forward (arrow right)'), self.animation_forward], + [_('^'), _('Speed up (arrow up)'), self.animation_speed_up], + [_('v'), _('Slow down (arrow down)'), self.animation_slow_down], + [_('Pause'), _('Pause (P)'), self.animation_pause], + [_('Restart'), _('Restart (R)'), self.animation_restart], + [_('Quit'), _('Close (Q)'), self.animation_quit]) self.buttons = [] for i in range(0, len(self.button_label)): @@ -80,29 +82,30 @@ class EmbroiderySimulator(wx.Frame): self.current_frame = 0 self.animation_direction = 1 - self.speed_info = self.calculate_speed_level() self.set_stitch_counter(0) shortcut_keys = [ - (wx.ACCEL_NORMAL, ord('+'), self.animation_speed_up), - (wx.ACCEL_NORMAL, ord('='), self.animation_speed_up), - (wx.ACCEL_SHIFT, ord('='), self.animation_speed_up), - (wx.ACCEL_NORMAL, wx.WXK_ADD, self.animation_speed_up), - (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_ADD, self.animation_speed_up), - (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_UP, self.animation_speed_up), - (wx.ACCEL_NORMAL, wx.WXK_UP, self.animation_speed_up), - (wx.ACCEL_NORMAL, ord('-'), self.animation_slow_down), - (wx.ACCEL_NORMAL, ord('_'), self.animation_slow_down), - (wx.ACCEL_NORMAL, wx.WXK_SUBTRACT, self.animation_slow_down), - (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_SUBTRACT, self.animation_slow_down), - (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_DOWN, self.animation_slow_down), - (wx.ACCEL_NORMAL, wx.WXK_DOWN, self.animation_slow_down), (wx.ACCEL_NORMAL, wx.WXK_RIGHT, self.animation_forward), - (wx.ACCEL_NORMAL, wx.WXK_LEFT, self.animation_reverse), (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_RIGHT, self.animation_forward), + (wx.ACCEL_NORMAL, wx.WXK_LEFT, self.animation_reverse), (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_LEFT, self.animation_reverse), + (wx.ACCEL_NORMAL, wx.WXK_UP, self.animation_speed_up), + (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_UP, self.animation_speed_up), + (wx.ACCEL_NORMAL, wx.WXK_DOWN, self.animation_slow_down), + (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_DOWN, self.animation_slow_down), + (wx.ACCEL_NORMAL, ord('+'), self.animation_one_frame_forward), + (wx.ACCEL_NORMAL, ord('='), self.animation_one_frame_forward), + (wx.ACCEL_SHIFT, ord('='), self.animation_one_frame_forward), + (wx.ACCEL_NORMAL, wx.WXK_ADD, self.animation_one_frame_forward), + (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_ADD, self.animation_one_frame_forward), + (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_UP, self.animation_one_frame_forward), + (wx.ACCEL_NORMAL, ord('-'), self.animation_one_frame_back), + (wx.ACCEL_NORMAL, ord('_'), self.animation_one_frame_back), + (wx.ACCEL_NORMAL, wx.WXK_SUBTRACT, self.animation_one_frame_back), + (wx.ACCEL_NORMAL, wx.WXK_NUMPAD_SUBTRACT, self.animation_one_frame_back), (wx.ACCEL_NORMAL, ord('r'), self.animation_restart), (wx.ACCEL_NORMAL, ord('p'), self.animation_pause), + (wx.ACCEL_NORMAL, wx.WXK_SPACE, self.animation_pause), (wx.ACCEL_NORMAL, ord('q'), self.animation_quit)] accel_entries = [] @@ -139,14 +142,6 @@ class EmbroiderySimulator(wx.Frame): self.move_to_top_left() return - def reset_speed(self): - if self.target_duration: - self.adjust_speed(self, self.target_duration) - else: - self.stitches_per_frame = 1 - self.frame_period = 80 - self.set_speed_info(self.calculate_speed_level()) - def adjust_speed(self, duration): self.frame_period = 1000 * float(duration) / len(self.lines) self.stitches_per_frame = 1 @@ -155,31 +150,42 @@ class EmbroiderySimulator(wx.Frame): self.frame_period *= 2 self.stitches_per_frame *= 2 + # Switch direction button (currently not in use - would this be better?) + def animation_switch_direction(self, event): + direction_button = event.GetEventObject() + lbl = direction_button.GetLabel() + if self.animation_direction == 1: + self.animation_reverse('backward') + direction_button.SetLabel('<<') + else: + self.animation_forward('forward') + direction_button.SetLabel('>>') + def animation_forward(self, event): - if self.current_frame == 1: - self.animation_direction = 1 - self.reset_speed() + self.animation_direction = 1 + if not self.timer.IsRunning(): self.timer.StartOnce(self.frame_period) - elif self.animation_direction == -1 and self.frame_period > 1280: - self.animation_direction = 1 - self.set_speed_info(self.calculate_speed_level()) - elif self.animation_direction == 1: - self.animation_speed_up('speed_up') - else: - self.animation_slow_down('slow_down') def animation_reverse(self, event): - if self.current_frame == len(self.lines): - self.animation_direction = -1 - self.reset_speed() + self.animation_direction = -1 + if not self.timer.IsRunning(): self.timer.StartOnce(self.frame_period) - elif self.animation_direction == 1 and self.frame_period > 1280: - self.animation_direction = -1 - self.set_speed_info(self.calculate_speed_level()) - elif self.animation_direction == -1: - self.animation_speed_up('speed_up') - else: - self.animation_slow_down('slow_down') + + def animation_one_frame_forward(self, event): + if self.current_frame < len(self.lines): + self.timer.Stop() + self.current_frame = self.current_frame + 1 + self.draw_one_frame() + self.set_stitch_counter(self.current_frame) + self.set_stitch_slider(self.current_frame) + + def animation_one_frame_back(self, event): + if self.current_frame > 1: + self.timer.Stop() + self.current_frame = self.current_frame - 1 + self.draw_one_frame() + self.set_stitch_counter(self.current_frame) + self.set_stitch_slider(self.current_frame) def animation_speed_up(self, event): if self.stitches_per_frame <= 1280: @@ -215,36 +221,16 @@ class EmbroiderySimulator(wx.Frame): def animation_update_timer(self): self.frame_period = max(1, self.frame_period) self.stitches_per_frame = max(self.stitches_per_frame, 1) - self.speed_info = self.calculate_speed_level() self.set_stitch_counter(self.current_frame) if self.timer.IsRunning(): self.timer.Stop() self.timer.StartOnce(self.frame_period) - def calculate_speed_level(self): - count = 0 - speed = self.frame_period - speed_plus = 1 - animation_direction = '>>' if self.animation_direction == 1 else '<<' - while speed <= 2560: - speed = speed * 2 - count += 1 - while speed_plus < self.stitches_per_frame: - speed_plus = speed_plus * 2 - count += 1 - return animation_direction + ' x' + str(count) - def set_stitch_counter(self, current_frame): self.dc.SetTextForeground('red') stitch_counter_text = _("Stitch # ") + \ str(current_frame) + ' / ' + str(len(self.lines)) self.dc.DrawText(stitch_counter_text, 30, 5) - self.set_speed_info(self.speed_info) - - def set_speed_info(self, speed_info): - self.speed_info = speed_info - self.dc.SetTextForeground('blue') - self.dc.DrawText(_("Speed ") + str(speed_info), 210, 5) def on_slider(self, event): self.panel.SetFocus() -- cgit v1.3.1 From a355af287484a62a021808b4ced20c4b85877759 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 26 Aug 2018 15:02:51 -0400 Subject: handle window size and target duration --- lib/extensions/params.py | 11 ++++------ lib/extensions/simulate.py | 4 +++- lib/simulator.py | 34 ++++++++++++++++++++--------- messages.po | 54 +++++++++++++++++++++++----------------------- 4 files changed, 58 insertions(+), 45 deletions(-) (limited to 'lib/extensions') diff --git a/lib/extensions/params.py b/lib/extensions/params.py index 6d1464a3..9bde2a66 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -440,19 +440,16 @@ class SettingsFrame(wx.Frame): display = wx.Display(current_screen) screen_rect = display.GetClientArea() - max_width = screen_rect.GetWidth() - params_rect.GetWidth() - max_height = screen_rect.GetHeight() + width = screen_rect.GetWidth() - params_rect.GetWidth() + height = screen_rect.GetHeight() try: self.simulate_window = EmbroiderySimulator(None, -1, _("Preview"), simulator_pos, - size=(300, 300), - x_position=simulator_pos.x, + size=(width, height), stitch_plan=stitch_plan, on_close=self.simulate_window_closed, - target_duration=5, - max_width=max_width, - max_height=max_height) + target_duration=5) except: error = traceback.format_exc() diff --git a/lib/extensions/simulate.py b/lib/extensions/simulate.py index 38f86156..2e414ac6 100644 --- a/lib/extensions/simulate.py +++ b/lib/extensions/simulate.py @@ -25,8 +25,10 @@ class Simulate(InkstitchExtension): screen_rect = display.GetClientArea() simulator_pos = (screen_rect[0], screen_rect[1]) + width = screen_rect[2] + height = screen_rect[3] - frame = EmbroiderySimulator(None, -1, _("Embroidery Simulation"), pos=simulator_pos, size=(1000, 1000), stitch_plan=stitch_plan) + frame = EmbroiderySimulator(None, -1, _("Embroidery Simulation"), pos=simulator_pos, size=(width, height), stitch_plan=stitch_plan) app.SetTopWindow(frame) frame.Show() wx.CallAfter(frame.go) diff --git a/lib/simulator.py b/lib/simulator.py index 4483d653..5be503ef 100644 --- a/lib/simulator.py +++ b/lib/simulator.py @@ -14,6 +14,8 @@ class ControlPanel(wx.Panel): self.parent = parent self.drawing_panel = kwargs.pop('drawing_panel') self.stitch_plan = kwargs.pop('stitch_plan') + stitches_per_second = kwargs.pop('stitches_per_second') + target_duration = kwargs.pop('target_duration') kwargs['style'] = wx.BORDER_SUNKEN wx.Panel.__init__(self, parent, *args, **kwargs) @@ -93,10 +95,17 @@ class ControlPanel(wx.Panel): self.SetAcceleratorTable(accel_table) self.current_stitch = 1 - self.set_speed(16) + + self.choose_speed(stitches_per_second, target_duration) self.SetFocus() + def choose_speed(self, stitches_per_second, target_duration): + if target_duration: + self.set_speed(int(self.num_stitches / float(target_duration))) + else: + self.set_speed(stitches_per_second) + def animation_forward(self, event=None): self.direction.SetLabel(">>") self.drawing_panel.forward() @@ -370,11 +379,17 @@ class SimulatorPanel(wx.Panel): """""" self.parent = parent stitch_plan = kwargs.pop('stitch_plan') + target_duration = kwargs.pop('target_duration') + stitches_per_second = kwargs.pop('stitches_per_second') kwargs['style'] = wx.BORDER_SUNKEN wx.Panel.__init__(self, parent, *args, **kwargs) self.dp = DrawingPanel(self, stitch_plan=stitch_plan) - self.cp = ControlPanel(self, stitch_plan=stitch_plan, drawing_panel=self.dp) + self.cp = ControlPanel(self, + stitch_plan=stitch_plan, + drawing_panel=self.dp, + stitches_per_second=stitches_per_second, + target_duration=target_duration) self.dp.set_control_panel(self.cp) vbSizer = wx.BoxSizer(wx.VERTICAL) @@ -393,20 +408,19 @@ class SimulatorPanel(wx.Panel): class EmbroiderySimulator(wx.Frame): def __init__(self, *args, **kwargs): - stitch_plan = kwargs.pop('stitch_plan', None) - self.x_position = kwargs.pop('x_position', None) self.on_close_hook = kwargs.pop('on_close', None) - self.frame_period = kwargs.pop('frame_period', 80) - self.stitches_per_frame = kwargs.pop('stitches_per_frame', 1) - self.target_duration = kwargs.pop('target_duration', None) - self.max_height = kwargs.pop('max_height', None) - self.max_width = kwargs.pop('max_width', None) + stitch_plan = kwargs.pop('stitch_plan', None) + stitches_per_second = kwargs.pop('stitches_per_second', 16) + target_duration = kwargs.pop('target_duration', None) wx.Frame.__init__(self, *args, **kwargs) # self.status_bar = self.CreateStatusBar() # self.status_bar.SetStatusText(text) - self.simulator_panel = SimulatorPanel(self, stitch_plan=stitch_plan) + self.simulator_panel = SimulatorPanel(self, + stitch_plan=stitch_plan, + target_duration=target_duration, + stitches_per_second=stitches_per_second) self.Bind(wx.EVT_CLOSE, self.on_close) def quit(self): diff --git a/messages.po b/messages.po index a09b61e6..ccb247e4 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-08-26 14:43-0400\n" +"POT-Creation-Date: 2018-08-26 15:02-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -612,25 +612,25 @@ msgstr "" msgid "Preview" msgstr "" -#: lib/extensions/params.py:466 +#: lib/extensions/params.py:463 msgid "Internal Error" msgstr "" -#: lib/extensions/params.py:519 +#: lib/extensions/params.py:516 msgid "Please enter or select a preset name first." msgstr "" -#: lib/extensions/params.py:519 lib/extensions/params.py:525 -#: lib/extensions/params.py:553 +#: lib/extensions/params.py:516 lib/extensions/params.py:522 +#: lib/extensions/params.py:550 msgid "Preset" msgstr "" -#: lib/extensions/params.py:525 +#: lib/extensions/params.py:522 #, python-format msgid "Preset \"%s\" not found." msgstr "" -#: lib/extensions/params.py:553 +#: lib/extensions/params.py:550 #, python-format msgid "" "Preset \"%s\" already exists. Please use another name or press " @@ -659,7 +659,7 @@ msgstr "" msgid "Ink/Stitch Print" msgstr "" -#: lib/extensions/simulate.py:29 +#: lib/extensions/simulate.py:31 msgid "Embroidery Simulation" msgstr "" @@ -674,79 +674,79 @@ msgstr "" msgid "Generate INX files" msgstr "" -#: lib/simulator.py:463 +#: lib/simulator.py:477 msgid "<<" msgstr "" -#: lib/simulator.py:463 +#: lib/simulator.py:477 msgid "Play reverse (arrow left)" msgstr "" -#: lib/simulator.py:464 +#: lib/simulator.py:478 msgid "-" msgstr "" -#: lib/simulator.py:464 +#: lib/simulator.py:478 msgid "Play one frame backward (+)" msgstr "" -#: lib/simulator.py:465 +#: lib/simulator.py:479 msgid "+" msgstr "" -#: lib/simulator.py:465 +#: lib/simulator.py:479 msgid "Play one frame forward (+)" msgstr "" -#: lib/simulator.py:466 +#: lib/simulator.py:480 msgid ">>" msgstr "" -#: lib/simulator.py:466 +#: lib/simulator.py:480 msgid "Play forward (arrow right)" msgstr "" -#: lib/simulator.py:467 +#: lib/simulator.py:481 msgid "^" msgstr "" -#: lib/simulator.py:467 +#: lib/simulator.py:481 msgid "Speed up (arrow up)" msgstr "" -#: lib/simulator.py:468 +#: lib/simulator.py:482 msgid "v" msgstr "" -#: lib/simulator.py:468 +#: lib/simulator.py:482 msgid "Slow down (arrow down)" msgstr "" -#: lib/simulator.py:469 +#: lib/simulator.py:483 msgid "Pause" msgstr "" -#: lib/simulator.py:469 +#: lib/simulator.py:483 msgid "Pause (P)" msgstr "" -#: lib/simulator.py:470 +#: lib/simulator.py:484 msgid "Restart" msgstr "" -#: lib/simulator.py:470 +#: lib/simulator.py:484 msgid "Restart (R)" msgstr "" -#: lib/simulator.py:471 +#: lib/simulator.py:485 msgid "Quit" msgstr "" -#: lib/simulator.py:471 +#: lib/simulator.py:485 msgid "Close (Q)" msgstr "" -#: lib/simulator.py:649 +#: lib/simulator.py:663 msgid "Stitch # " msgstr "" -- cgit v1.3.1 From e854df43073ce3158654b0db304edd0bba7a7d6d Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 26 Aug 2018 15:34:13 -0400 Subject: handle auto-refresh from Params --- lib/extensions/params.py | 11 +---- lib/simulator.py | 109 +++++++++++++++++++++++++++++++---------------- messages.po | 54 +++++++++++------------ 3 files changed, 100 insertions(+), 74 deletions(-) (limited to 'lib/extensions') diff --git a/lib/extensions/params.py b/lib/extensions/params.py index 9bde2a66..73ce069d 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -421,16 +421,7 @@ class SettingsFrame(wx.Frame): stitch_plan = patches_to_stitch_plan(patches) if self.simulate_window: self.simulate_window.stop() - self.simulate_window.load(stitch_plan=stitch_plan) - self.simulate_window.calculate_dimensions() - - children = self.simulate_window.GetChildren() - for child in children: - if isinstance(child, wx.Slider): - child.Destroy() - self.simulate_window.set_slider() - - self.simulate_window.Layout() + self.simulate_window.load(stitch_plan) else: params_rect = self.GetScreenRect() simulator_pos = params_rect.GetTopRight() diff --git a/lib/simulator.py b/lib/simulator.py index 5be503ef..cae0e019 100644 --- a/lib/simulator.py +++ b/lib/simulator.py @@ -12,14 +12,16 @@ class ControlPanel(wx.Panel): def __init__(self, parent, *args, **kwargs): """""" self.parent = parent - self.drawing_panel = kwargs.pop('drawing_panel') self.stitch_plan = kwargs.pop('stitch_plan') - stitches_per_second = kwargs.pop('stitches_per_second') - target_duration = kwargs.pop('target_duration') + self.target_stitches_per_second = kwargs.pop('stitches_per_second') + self.target_duration = kwargs.pop('target_duration') kwargs['style'] = wx.BORDER_SUNKEN wx.Panel.__init__(self, parent, *args, **kwargs) - self.num_stitches = self.stitch_plan.num_stitches + self.drawing_panel = None + self.num_stitches = 1 + self.current_stitch = 0 + self.speed = 1 # Widgets self.btnMinus = wx.Button(self, -1, label='-') @@ -34,7 +36,7 @@ class ControlPanel(wx.Panel): self.restartBtn.Bind(wx.EVT_BUTTON, self.animation_restart) self.quitBtn = wx.Button(self, -1, label='Quit') self.quitBtn.Bind(wx.EVT_BUTTON, self.animation_quit) - self.slider = wx.Slider(self, -1, value=1, minValue=1, maxValue=self.num_stitches, + self.slider = wx.Slider(self, -1, value=0, minValue=0, maxValue=self.num_stitches, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.slider.Bind(wx.EVT_SLIDER, self.on_slider) self.stitchBox = IntCtrl(self, -1, value=1, min=0, max=self.num_stitches, limited=True, allow_none=False) @@ -93,18 +95,23 @@ class ControlPanel(wx.Panel): accel_table = wx.AcceleratorTable(accel_entries) self.SetAcceleratorTable(accel_table) + self.SetFocus() - self.current_stitch = 1 - - self.choose_speed(stitches_per_second, target_duration) + def set_drawing_panel(self, drawing_panel): + self.drawing_panel = drawing_panel + self.drawing_panel.set_speed(self.speed) - self.SetFocus() + def set_num_stitches(self, num_stitches): + self.num_stitches = num_stitches + self.stitchBox.SetMax(num_stitches) + self.slider.SetMax(num_stitches) + self.choose_speed() - def choose_speed(self, stitches_per_second, target_duration): - if target_duration: - self.set_speed(int(self.num_stitches / float(target_duration))) + def choose_speed(self): + if self.target_duration: + self.set_speed(int(self.num_stitches / float(self.target_duration))) else: - self.set_speed(stitches_per_second) + self.set_speed(self.target_stitches_per_second) def animation_forward(self, event=None): self.direction.SetLabel(">>") @@ -124,14 +131,18 @@ class ControlPanel(wx.Panel): def set_speed(self, speed): self.speed = int(max(speed, 1)) - self.drawing_panel.set_speed(self.speed) self.speedST.SetLabel('Speed: %s stitches/sec' % self.speed) self.hbSizer2.Layout() + if self.drawing_panel: + self.drawing_panel.set_speed(self.speed) + def on_slider(self, event): stitch = event.GetEventObject().GetValue() self.stitchBox.SetValue(stitch) - self.drawing_panel.set_current_stitch(stitch) + + if self.drawing_panel: + self.drawing_panel.set_current_stitch(stitch) def on_current_stitch(self, stitch): if self.current_stitch != stitch: @@ -145,7 +156,9 @@ class ControlPanel(wx.Panel): def on_stitch_box(self, event): stitch = self.stitchBox.GetValue() self.slider.SetValue(stitch) - self.drawing_panel.set_current_stitch(stitch) + + if self.drawing_panel: + self.drawing_panel.set_current_stitch(stitch) def animation_slow_down(self, event): """""" @@ -157,12 +170,16 @@ class ControlPanel(wx.Panel): def animation_pause(self, event=None): self.drawing_panel.stop() - self.pauseBtn.SetLabel('Start') def animation_start(self, event=None): self.drawing_panel.go() + + def on_start(self): self.pauseBtn.SetLabel('Pause') + def on_stop(self): + self.pauseBtn.SetLabel('Start') + def on_pause_start_button(self, event): """""" if self.pauseBtn.GetLabel() == 'Pause': @@ -200,6 +217,7 @@ class DrawingPanel(wx.Panel): def __init__(self, *args, **kwargs): """""" self.stitch_plan = kwargs.pop('stitch_plan') + self.control_panel = kwargs.pop('control_panel') kwargs['style'] = wx.BORDER_SUNKEN wx.Panel.__init__(self, *args, **kwargs) @@ -211,10 +229,9 @@ class DrawingPanel(wx.Panel): self.last_frame_duration = 0 self.direction = 1 self.current_stitch = 0 - self.control_panel = None # desired simulation speed in stitches per second - self.speed = 10 + self.speed = 16 self.black_pen = self.create_pen((0, 0, 0)) @@ -222,9 +239,6 @@ class DrawingPanel(wx.Panel): self.Bind(wx.EVT_PAINT, self.OnPaint) - def set_control_panel(self, control_panel): - self.control_panel = control_panel - def clamp_current_stitch(self): if self.current_stitch < 0: self.current_stitch = 0 @@ -294,21 +308,29 @@ class DrawingPanel(wx.Panel): canvas.DrawLines(((x - crosshair_radius, y), (x + crosshair_radius, y))) canvas.DrawLines(((x, y - crosshair_radius), (x, y + crosshair_radius))) + def clear(self): + dc = wx.ClientDC(self) + dc.Clear() - def load(self, stitch_plan=None): - if stitch_plan: - self.num_stitches = stitch_plan.num_stitches - self.parse_stitch_plan(stitch_plan) - self.move_to_top_left() - return + def load(self, stitch_plan): + self.last_frame_duration = 0 + self.direction = 1 + self.num_stitches = stitch_plan.num_stitches + self.control_panel.set_num_stitches(self.num_stitches) + self.parse_stitch_plan(stitch_plan) + self.move_to_top_left() + self.set_current_stitch(0) + self.go() def stop(self): self.animating = False + self.control_panel.on_stop() def go(self): if not self.animating: self.animating = True self.animate() + self.control_panel.on_start() def create_pen(self, rgb): return wx.Pen(rgb, width=int(0.4 * self.PIXEL_DENSITY)) @@ -352,12 +374,10 @@ class DrawingPanel(wx.Panel): def set_current_stitch(self, stitch): self.current_stitch = stitch self.clamp_current_stitch() + self.control_panel.on_current_stitch(self.current_stitch) self.stop_if_at_end() self.Refresh() - if self.control_panel: - self.control_panel.on_current_stitch(self.current_stitch) - def restart(self): if self.direction == 1: self.current_stitch = 0 @@ -384,27 +404,33 @@ class SimulatorPanel(wx.Panel): kwargs['style'] = wx.BORDER_SUNKEN wx.Panel.__init__(self, parent, *args, **kwargs) - self.dp = DrawingPanel(self, stitch_plan=stitch_plan) self.cp = ControlPanel(self, stitch_plan=stitch_plan, - drawing_panel=self.dp, stitches_per_second=stitches_per_second, target_duration=target_duration) - self.dp.set_control_panel(self.cp) + self.dp = DrawingPanel(self, stitch_plan=stitch_plan, control_panel=self.cp) + self.cp.set_drawing_panel(self.dp) vbSizer = wx.BoxSizer(wx.VERTICAL) vbSizer.Add(self.dp, 1, wx.EXPAND | wx.ALL, 2) vbSizer.Add(self.cp, 0, wx.EXPAND | wx.ALL, 2) self.SetSizer(vbSizer) - self.dp.go() - def quit(self): self.parent.quit() + def go(self): + self.dp.go() + def stop(self): self.dp.stop() + def load(self, stitch_plan): + self.dp.load(stitch_plan) + + def clear(self): + self.dp.clear() + class EmbroiderySimulator(wx.Frame): def __init__(self, *args, **kwargs): @@ -435,7 +461,16 @@ class EmbroiderySimulator(wx.Frame): self.Destroy() def go(self): - pass + self.simulator_panel.go() + + def stop(self): + self.simulator_panel.stop() + + def load(self, stitch_plan): + self.simulator_panel.load(stitch_plan) + + def clear(self): + self.simulator_panel.clear() class OldEmbroiderySimulator(wx.Frame): diff --git a/messages.po b/messages.po index ccb247e4..a79e8529 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-08-26 15:02-0400\n" +"POT-Creation-Date: 2018-08-26 15:34-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -608,29 +608,29 @@ msgstr "" msgid "Apply and Quit" msgstr "" -#: lib/extensions/params.py:447 +#: lib/extensions/params.py:438 msgid "Preview" msgstr "" -#: lib/extensions/params.py:463 +#: lib/extensions/params.py:454 msgid "Internal Error" msgstr "" -#: lib/extensions/params.py:516 +#: lib/extensions/params.py:507 msgid "Please enter or select a preset name first." msgstr "" -#: lib/extensions/params.py:516 lib/extensions/params.py:522 -#: lib/extensions/params.py:550 +#: lib/extensions/params.py:507 lib/extensions/params.py:513 +#: lib/extensions/params.py:541 msgid "Preset" msgstr "" -#: lib/extensions/params.py:522 +#: lib/extensions/params.py:513 #, python-format msgid "Preset \"%s\" not found." msgstr "" -#: lib/extensions/params.py:550 +#: lib/extensions/params.py:541 #, python-format msgid "" "Preset \"%s\" already exists. Please use another name or press " @@ -674,79 +674,79 @@ msgstr "" msgid "Generate INX files" msgstr "" -#: lib/simulator.py:477 +#: lib/simulator.py:512 msgid "<<" msgstr "" -#: lib/simulator.py:477 +#: lib/simulator.py:512 msgid "Play reverse (arrow left)" msgstr "" -#: lib/simulator.py:478 +#: lib/simulator.py:513 msgid "-" msgstr "" -#: lib/simulator.py:478 +#: lib/simulator.py:513 msgid "Play one frame backward (+)" msgstr "" -#: lib/simulator.py:479 +#: lib/simulator.py:514 msgid "+" msgstr "" -#: lib/simulator.py:479 +#: lib/simulator.py:514 msgid "Play one frame forward (+)" msgstr "" -#: lib/simulator.py:480 +#: lib/simulator.py:515 msgid ">>" msgstr "" -#: lib/simulator.py:480 +#: lib/simulator.py:515 msgid "Play forward (arrow right)" msgstr "" -#: lib/simulator.py:481 +#: lib/simulator.py:516 msgid "^" msgstr "" -#: lib/simulator.py:481 +#: lib/simulator.py:516 msgid "Speed up (arrow up)" msgstr "" -#: lib/simulator.py:482 +#: lib/simulator.py:517 msgid "v" msgstr "" -#: lib/simulator.py:482 +#: lib/simulator.py:517 msgid "Slow down (arrow down)" msgstr "" -#: lib/simulator.py:483 +#: lib/simulator.py:518 msgid "Pause" msgstr "" -#: lib/simulator.py:483 +#: lib/simulator.py:518 msgid "Pause (P)" msgstr "" -#: lib/simulator.py:484 +#: lib/simulator.py:519 msgid "Restart" msgstr "" -#: lib/simulator.py:484 +#: lib/simulator.py:519 msgid "Restart (R)" msgstr "" -#: lib/simulator.py:485 +#: lib/simulator.py:520 msgid "Quit" msgstr "" -#: lib/simulator.py:485 +#: lib/simulator.py:520 msgid "Close (Q)" msgstr "" -#: lib/simulator.py:663 +#: lib/simulator.py:698 msgid "Stitch # " msgstr "" -- cgit v1.3.1 From b3516785aafef79a02059cf29591ec978331e703 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 26 Aug 2018 16:14:03 -0400 Subject: automatically scale and center the design --- lib/extensions/simulate.py | 7 +++--- lib/simulator.py | 63 +++++++++++++++++++++++++++++++++------------- messages.po | 42 +++++++++++++++---------------- 3 files changed, 71 insertions(+), 41 deletions(-) (limited to 'lib/extensions') diff --git a/lib/extensions/simulate.py b/lib/extensions/simulate.py index 2e414ac6..dcb5e604 100644 --- a/lib/extensions/simulate.py +++ b/lib/extensions/simulate.py @@ -25,11 +25,12 @@ class Simulate(InkstitchExtension): screen_rect = display.GetClientArea() simulator_pos = (screen_rect[0], screen_rect[1]) - width = screen_rect[2] - height = screen_rect[3] + + # subtract 1 because otherwise the window becomes maximized on Linux + width = screen_rect[2] - 1 + height = screen_rect[3] - 1 frame = EmbroiderySimulator(None, -1, _("Embroidery Simulation"), pos=simulator_pos, size=(width, height), stitch_plan=stitch_plan) app.SetTopWindow(frame) frame.Show() - wx.CallAfter(frame.go) app.MainLoop() diff --git a/lib/simulator.py b/lib/simulator.py index cae0e019..2565e42f 100644 --- a/lib/simulator.py +++ b/lib/simulator.py @@ -229,15 +229,19 @@ class DrawingPanel(wx.Panel): self.last_frame_duration = 0 self.direction = 1 self.current_stitch = 0 + self.black_pen = self.create_pen((0, 0, 0)) + self.width = 0 + self.height = 0 + self.loaded = False # desired simulation speed in stitches per second self.speed = 16 - self.black_pen = self.create_pen((0, 0, 0)) - - self.load(self.stitch_plan) - self.Bind(wx.EVT_PAINT, self.OnPaint) + self.Bind(wx.EVT_SIZE, self.choose_zoom_and_pan) + + # wait for layouts so that panel size is set + wx.CallLater(50, self.load, self.stitch_plan) def clamp_current_stitch(self): if self.current_stitch < 0: @@ -275,11 +279,16 @@ class DrawingPanel(wx.Panel): wx.CallLater(int(1000 * frame_time), self.animate) def OnPaint(self, e): + if not self.loaded: + return + dc = wx.PaintDC(self) canvas = wx.GraphicsContext.Create(dc) transform = canvas.GetTransform() - transform.Scale(2.0 / self.PIXEL_DENSITY, 2.0 / self.PIXEL_DENSITY) + transform.Translate(*self.pan) + transform.Scale(self.zoom / self.PIXEL_DENSITY, self.zoom / self.PIXEL_DENSITY) + #transform.Translate(self.pan[0] * self.PIXEL_DENSITY, self.pan[1] * self.PIXEL_DENSITY) canvas.SetTransform(transform) stitch = 0 @@ -303,7 +312,7 @@ class DrawingPanel(wx.Panel): if last_stitch: x = last_stitch[0] y = last_stitch[1] - crosshair_radius = 4 * self.PIXEL_DENSITY + crosshair_radius = 10 / self.zoom * self.PIXEL_DENSITY canvas.SetPen(self.black_pen) canvas.DrawLines(((x - crosshair_radius, y), (x + crosshair_radius, y))) canvas.DrawLines(((x, y - crosshair_radius), (x, y + crosshair_radius))) @@ -317,16 +326,39 @@ class DrawingPanel(wx.Panel): self.direction = 1 self.num_stitches = stitch_plan.num_stitches self.control_panel.set_num_stitches(self.num_stitches) + self.minx, self.miny, self.maxx, self.maxy = stitch_plan.bounding_box + self.width = self.maxx - self.minx + self.height = self.maxy - self.miny self.parse_stitch_plan(stitch_plan) - self.move_to_top_left() + self.choose_zoom_and_pan() self.set_current_stitch(0) + self.loaded = True self.go() + def choose_zoom_and_pan(self, event=None): + # ignore if called before we load the stitch plan + if not self.width or not self.height: + return + + panel_width, panel_height = self.GetClientSize() + + # add some padding to make stitches at the edge more visible + width_ratio = panel_width / float(self.width + 10) + height_ratio = panel_height / float(self.height + 10) + self.zoom = min(width_ratio, height_ratio) + + # center the design + self.pan = ((panel_width - self.zoom * self.width) / 2.0, + (panel_height - self.zoom * self.height) / 2.0) + def stop(self): self.animating = False self.control_panel.on_stop() def go(self): + if not self.loaded: + return + if not self.animating: self.animating = True self.animate() @@ -347,18 +379,15 @@ class DrawingPanel(wx.Panel): for point_list in color_block_to_point_lists(color_block): self.pens.append(pen) - self.stitch_blocks.append(point_list) - - def move_to_top_left(self): - """remove any unnecessary whitespace around the design""" - minx, miny, maxx, maxy = self.stitch_plan.bounding_box + points = [] + for x, y in point_list: + # trim any whitespace on the left and top and scale to the + # pixel density + points.append((self.PIXEL_DENSITY * (x - self.minx), + self.PIXEL_DENSITY * (y - self.miny))) - for block in self.stitch_blocks: - stitches = [] - for stitch in block: - stitches.append((self.PIXEL_DENSITY * (stitch[0] - minx), self.PIXEL_DENSITY * (stitch[1] - miny))) - block[:] = stitches + self.stitch_blocks.append(points) def set_speed(self, speed): self.speed = speed diff --git a/messages.po b/messages.po index a79e8529..0cdb527c 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-08-26 15:34-0400\n" +"POT-Creation-Date: 2018-08-26 16:14-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -659,7 +659,7 @@ msgstr "" msgid "Ink/Stitch Print" msgstr "" -#: lib/extensions/simulate.py:31 +#: lib/extensions/simulate.py:33 msgid "Embroidery Simulation" msgstr "" @@ -674,79 +674,79 @@ msgstr "" msgid "Generate INX files" msgstr "" -#: lib/simulator.py:512 +#: lib/simulator.py:541 msgid "<<" msgstr "" -#: lib/simulator.py:512 +#: lib/simulator.py:541 msgid "Play reverse (arrow left)" msgstr "" -#: lib/simulator.py:513 +#: lib/simulator.py:542 msgid "-" msgstr "" -#: lib/simulator.py:513 +#: lib/simulator.py:542 msgid "Play one frame backward (+)" msgstr "" -#: lib/simulator.py:514 +#: lib/simulator.py:543 msgid "+" msgstr "" -#: lib/simulator.py:514 +#: lib/simulator.py:543 msgid "Play one frame forward (+)" msgstr "" -#: lib/simulator.py:515 +#: lib/simulator.py:544 msgid ">>" msgstr "" -#: lib/simulator.py:515 +#: lib/simulator.py:544 msgid "Play forward (arrow right)" msgstr "" -#: lib/simulator.py:516 +#: lib/simulator.py:545 msgid "^" msgstr "" -#: lib/simulator.py:516 +#: lib/simulator.py:545 msgid "Speed up (arrow up)" msgstr "" -#: lib/simulator.py:517 +#: lib/simulator.py:546 msgid "v" msgstr "" -#: lib/simulator.py:517 +#: lib/simulator.py:546 msgid "Slow down (arrow down)" msgstr "" -#: lib/simulator.py:518 +#: lib/simulator.py:547 msgid "Pause" msgstr "" -#: lib/simulator.py:518 +#: lib/simulator.py:547 msgid "Pause (P)" msgstr "" -#: lib/simulator.py:519 +#: lib/simulator.py:548 msgid "Restart" msgstr "" -#: lib/simulator.py:519 +#: lib/simulator.py:548 msgid "Restart (R)" msgstr "" -#: lib/simulator.py:520 +#: lib/simulator.py:549 msgid "Quit" msgstr "" -#: lib/simulator.py:520 +#: lib/simulator.py:549 msgid "Close (Q)" msgstr "" -#: lib/simulator.py:698 +#: lib/simulator.py:727 msgid "Stitch # " msgstr "" -- cgit v1.3.1 From 8d196ace7fb01d2ac011d1c685ff422ef891320c Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 27 Aug 2018 16:43:23 -0400 Subject: position params's simulator window at the top of the screen --- lib/extensions/params.py | 1 + messages.po | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'lib/extensions') diff --git a/lib/extensions/params.py b/lib/extensions/params.py index 73ce069d..c9c994c9 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -430,6 +430,7 @@ class SettingsFrame(wx.Frame): current_screen = wx.Display.GetFromPoint(wx.GetMousePosition()) display = wx.Display(current_screen) screen_rect = display.GetClientArea() + simulator_pos.y = screen_rect.GetTop() width = screen_rect.GetWidth() - params_rect.GetWidth() height = screen_rect.GetHeight() diff --git a/messages.po b/messages.po index 15718012..f17c39dc 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-08-27 16:15-0400\n" +"POT-Creation-Date: 2018-08-27 16:43-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -608,29 +608,29 @@ msgstr "" msgid "Apply and Quit" msgstr "" -#: lib/extensions/params.py:438 +#: lib/extensions/params.py:439 msgid "Preview" msgstr "" -#: lib/extensions/params.py:454 +#: lib/extensions/params.py:455 msgid "Internal Error" msgstr "" -#: lib/extensions/params.py:507 +#: lib/extensions/params.py:508 msgid "Please enter or select a preset name first." msgstr "" -#: lib/extensions/params.py:507 lib/extensions/params.py:513 -#: lib/extensions/params.py:541 +#: lib/extensions/params.py:508 lib/extensions/params.py:514 +#: lib/extensions/params.py:542 msgid "Preset" msgstr "" -#: lib/extensions/params.py:513 +#: lib/extensions/params.py:514 #, python-format msgid "Preset \"%s\" not found." msgstr "" -#: lib/extensions/params.py:541 +#: lib/extensions/params.py:542 #, python-format msgid "" "Preset \"%s\" already exists. Please use another name or press " -- cgit v1.3.1 From 3fe3399d909de6549a7ce64f4347b342933b2465 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 1 Sep 2018 13:35:47 -0400 Subject: simulator standalone mode --- lib/extensions/simulate.py | 20 ++------------------ lib/simulator.py | 28 ++++++++++++++++++++++++++-- lib/stitch_plan/__init__.py | 3 ++- lib/stitch_plan/read_file.py | 21 +++++++++++++++++++++ messages.po | 30 +++++++++++++++--------------- 5 files changed, 66 insertions(+), 36 deletions(-) create mode 100644 lib/stitch_plan/read_file.py (limited to 'lib/extensions') diff --git a/lib/extensions/simulate.py b/lib/extensions/simulate.py index dcb5e604..e23d391b 100644 --- a/lib/extensions/simulate.py +++ b/lib/extensions/simulate.py @@ -1,8 +1,6 @@ -import wx - from .base import InkstitchExtension from ..i18n import _ -from ..simulator import EmbroiderySimulator +from ..simulator import show_simulator from ..stitch_plan import patches_to_stitch_plan @@ -19,18 +17,4 @@ class Simulate(InkstitchExtension): return patches = self.elements_to_patches(self.elements) stitch_plan = patches_to_stitch_plan(patches) - app = wx.App() - current_screen = wx.Display.GetFromPoint(wx.GetMousePosition()) - display = wx.Display(current_screen) - screen_rect = display.GetClientArea() - - simulator_pos = (screen_rect[0], screen_rect[1]) - - # subtract 1 because otherwise the window becomes maximized on Linux - width = screen_rect[2] - 1 - height = screen_rect[3] - 1 - - frame = EmbroiderySimulator(None, -1, _("Embroidery Simulation"), pos=simulator_pos, size=(width, height), stitch_plan=stitch_plan) - app.SetTopWindow(frame) - frame.Show() - app.MainLoop() + show_simulator(stitch_plan) diff --git a/lib/simulator.py b/lib/simulator.py index c797d221..8f316be3 100644 --- a/lib/simulator.py +++ b/lib/simulator.py @@ -4,8 +4,9 @@ from wx.lib.intctrl import IntCtrl import time from itertools import izip -from .svg import color_block_to_point_lists, PIXELS_PER_MM +from .svg import PIXELS_PER_MM from .i18n import _ +from .stitch_plan import stitch_plan_from_file # L10N command label at bottom of simulator window COMMAND_NAMES = [_("STITCH"), _("JUMP"), _("TRIM"), _("STOP"), _("COLOR CHANGE")] @@ -330,7 +331,8 @@ class DrawingPanel(wx.Panel): canvas.SetPen(pen) if stitch + len(stitches) < self.current_stitch: stitch += len(stitches) - canvas.DrawLines(stitches) + if len(stitches) > 1: + canvas.DrawLines(stitches) last_stitch = stitches[-1] else: stitches = stitches[:self.current_stitch - stitch] @@ -615,3 +617,25 @@ class EmbroiderySimulator(wx.Frame): def clear(self): self.simulator_panel.clear() + +def show_simulator(stitch_plan): + app = wx.App() + current_screen = wx.Display.GetFromPoint(wx.GetMousePosition()) + display = wx.Display(current_screen) + screen_rect = display.GetClientArea() + + simulator_pos = (screen_rect[0], screen_rect[1]) + + # subtract 1 because otherwise the window becomes maximized on Linux + width = screen_rect[2] - 1 + height = screen_rect[3] - 1 + + frame = EmbroiderySimulator(None, -1, _("Embroidery Simulation"), pos=simulator_pos, size=(width, height), stitch_plan=stitch_plan) + app.SetTopWindow(frame) + frame.Show() + app.MainLoop() + + +if __name__ == "__main__": + stitch_plan = stitch_plan_from_file(sys.argv[1]) + show_simulator(stitch_plan) diff --git a/lib/stitch_plan/__init__.py b/lib/stitch_plan/__init__.py index 791a5f20..2aaa0ab9 100644 --- a/lib/stitch_plan/__init__.py +++ b/lib/stitch_plan/__init__.py @@ -1,2 +1,3 @@ -from stitch_plan import patches_to_stitch_plan, StitchPlan, ColorBlock +from .stitch_plan import patches_to_stitch_plan, StitchPlan, ColorBlock from .stitch import Stitch +from .read_file import stitch_plan_from_file diff --git a/lib/stitch_plan/read_file.py b/lib/stitch_plan/read_file.py new file mode 100644 index 00000000..ff5a68ac --- /dev/null +++ b/lib/stitch_plan/read_file.py @@ -0,0 +1,21 @@ +import pyembroidery +from .stitch_plan import StitchPlan + +from ..svg import PIXELS_PER_MM + + +def stitch_plan_from_file(embroidery_file): + """Read a machine embroidery file in any supported format and return a stitch plan.""" + pattern = pyembroidery.read(embroidery_file) + + stitch_plan = StitchPlan() + color_block = None + + for raw_stitches, thread in pattern.get_as_colorblocks(): + color_block = stitch_plan.new_color_block(thread) + for x, y, command in raw_stitches: + color_block.add_stitch(x * PIXELS_PER_MM / 10.0, y * PIXELS_PER_MM / 10.0, + jump=(command == pyembroidery.JUMP), + trim=(command == pyembroidery.TRIM)) + + return stitch_plan diff --git a/messages.po b/messages.po index f58a88ec..fb2d593f 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-08-27 21:56-0400\n" +"POT-Creation-Date: 2018-09-01 13:35-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -659,10 +659,6 @@ msgstr "" msgid "Ink/Stitch Print" msgstr "" -#: lib/extensions/simulate.py:33 -msgid "Embroidery Simulation" -msgstr "" - #: lib/extensions/zip.py:49 msgid "No embroidery file formats selected." msgstr "" @@ -675,47 +671,51 @@ msgid "Generate INX files" msgstr "" #. command label at bottom of simulator window -#: lib/simulator.py:11 +#: lib/simulator.py:12 msgid "STITCH" msgstr "" -#: lib/simulator.py:11 +#: lib/simulator.py:12 msgid "JUMP" msgstr "" -#: lib/simulator.py:11 +#: lib/simulator.py:12 msgid "TRIM" msgstr "" -#: lib/simulator.py:11 +#: lib/simulator.py:12 msgid "STOP" msgstr "" -#: lib/simulator.py:11 +#: lib/simulator.py:12 msgid "COLOR CHANGE" msgstr "" -#: lib/simulator.py:48 lib/simulator.py:207 lib/simulator.py:214 +#: lib/simulator.py:49 lib/simulator.py:208 lib/simulator.py:215 msgid "Pause" msgstr "" -#: lib/simulator.py:50 +#: lib/simulator.py:51 msgid "Restart" msgstr "" -#: lib/simulator.py:52 +#: lib/simulator.py:53 msgid "Quit" msgstr "" -#: lib/simulator.py:167 +#: lib/simulator.py:168 #, python-format msgid "Speed: %d stitches/sec" msgstr "" -#: lib/simulator.py:210 +#: lib/simulator.py:211 msgid "Start" msgstr "" +#: lib/simulator.py:633 +msgid "Embroidery Simulation" +msgstr "" + #: lib/stitches/auto_fill.py:167 msgid "" "Unable to autofill. This most often happens because your shape is made " -- cgit v1.3.1 From 9360e9b9304a6b9a50c5586a04ebf0a13859d5fe Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 1 Sep 2018 14:22:46 -0400 Subject: fix code style --- lib/extensions/simulate.py | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/extensions') diff --git a/lib/extensions/simulate.py b/lib/extensions/simulate.py index e23d391b..f962b206 100644 --- a/lib/extensions/simulate.py +++ b/lib/extensions/simulate.py @@ -1,5 +1,4 @@ from .base import InkstitchExtension -from ..i18n import _ from ..simulator import show_simulator from ..stitch_plan import patches_to_stitch_plan -- cgit v1.3.1