diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2019-07-04 10:51:22 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-04 10:51:22 -0400 |
| commit | 32548e8e51d13d511813ba4e2a4571bd73e440e5 (patch) | |
| tree | a5c1d8e8932048f6f4c02d55e144023fa82b2e8f /lib/gui | |
| parent | 4db305a36dd87dc9fc21034571eaebb078054bd3 (diff) | |
| parent | c51ae9ccb7052e4015b4a3dd3e2817d8625e3ab0 (diff) | |
lettering features (#399)
lettering features
Diffstat (limited to 'lib/gui')
| -rw-r--r-- | lib/gui/__init__.py | 1 | ||||
| -rw-r--r-- | lib/gui/presets.py | 11 | ||||
| -rw-r--r-- | lib/gui/simulator.py | 55 | ||||
| -rw-r--r-- | lib/gui/subtitle_combo_box.py | 85 |
4 files changed, 138 insertions, 14 deletions
diff --git a/lib/gui/__init__.py b/lib/gui/__init__.py index 5e249a55..2214db5d 100644 --- a/lib/gui/__init__.py +++ b/lib/gui/__init__.py @@ -2,3 +2,4 @@ from dialogs import info_dialog, confirm_dialog from electron import open_url from presets import PresetsPanel from simulator import EmbroiderySimulator, SimulatorPreview, show_simulator +from subtitle_combo_box import SubtitleComboBox diff --git a/lib/gui/presets.py b/lib/gui/presets.py index 5337d879..bd0b1787 100644 --- a/lib/gui/presets.py +++ b/lib/gui/presets.py @@ -63,11 +63,12 @@ class PresetsPanel(wx.Panel): self.delete_preset_button.Bind(wx.EVT_BUTTON, self.delete_preset) presets_sizer = wx.StaticBoxSizer(self.presets_box, wx.HORIZONTAL) - presets_sizer.Add(self.preset_chooser, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 10) - presets_sizer.Add(self.load_preset_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 10) - presets_sizer.Add(self.add_preset_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 10) - presets_sizer.Add(self.overwrite_preset_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 10) - presets_sizer.Add(self.delete_preset_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 10) + self.preset_chooser.SetMinSize((200, -1)) + presets_sizer.Add(self.preset_chooser, 1, wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.BOTTOM | wx.EXPAND, 10) + presets_sizer.Add(self.load_preset_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT, 10) + presets_sizer.Add(self.add_preset_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT, 10) + presets_sizer.Add(self.overwrite_preset_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT, 10) + presets_sizer.Add(self.delete_preset_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 10) self.SetSizerAndFit(presets_sizer) self.Layout() diff --git a/lib/gui/simulator.py b/lib/gui/simulator.py index 25149149..7184a012 100644 --- a/lib/gui/simulator.py +++ b/lib/gui/simulator.py @@ -390,14 +390,51 @@ class DrawingPanel(wx.Panel): self.last_frame_duration = time.time() - start if last_stitch: - x = last_stitch[0] - y = last_stitch[1] - x, y = transform.TransformPoint(float(x), float(y)) - canvas.SetTransform(canvas.CreateMatrix()) - crosshair_radius = 10 - 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))) + self.draw_crosshair(last_stitch[0], last_stitch[1], canvas, transform) + + self.draw_scale(canvas) + + def draw_crosshair(self, x, y, canvas, transform): + x, y = transform.TransformPoint(float(x), float(y)) + canvas.SetTransform(canvas.CreateMatrix()) + crosshair_radius = 10 + 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))) + + def draw_scale(self, canvas): + canvas_width, canvas_height = self.GetClientSize() + + one_mm = PIXELS_PER_MM * self.zoom + scale_width = one_mm + max_width = min(canvas_width * 0.5, 300) + + while scale_width > max_width: + scale_width /= 2.0 + + while scale_width < 50: + scale_width += one_mm + + scale_width_mm = scale_width / self.zoom / PIXELS_PER_MM + + # The scale bar looks like this: + # + # | | + # |_____|_____| + + scale_lower_left_x = 20 + scale_lower_left_y = canvas_height - 20 + + canvas.DrawLines(((scale_lower_left_x, scale_lower_left_y - 6), + (scale_lower_left_x, scale_lower_left_y), + (scale_lower_left_x + scale_width / 2.0, scale_lower_left_y), + (scale_lower_left_x + scale_width / 2.0, scale_lower_left_y - 3), + (scale_lower_left_x + scale_width / 2.0, scale_lower_left_y), + (scale_lower_left_x + scale_width, scale_lower_left_y), + (scale_lower_left_x + scale_width, scale_lower_left_y - 5))) + + canvas.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL), wx.Colour((0, 0, 0))) + canvas.DrawText("%s mm" % scale_width_mm, scale_lower_left_x, scale_lower_left_y + 5) def draw_needle_penetration_points(self, canvas, pen, stitches): if self.control_panel.nppBtn.GetValue(): @@ -560,7 +597,7 @@ class DrawingPanel(wx.Panel): # If we just change the zoom, the design will appear to move on the # screen. We have to adjust the pan to compensate. We want to keep # the part of the design under the mouse pointer in the same spot - # after we zoom, so that we appar to be zooming centered on the + # after we zoom, so that we appear to be zooming centered on the # mouse pointer. # This will create a matrix that takes a point in the design and diff --git a/lib/gui/subtitle_combo_box.py b/lib/gui/subtitle_combo_box.py new file mode 100644 index 00000000..64c42153 --- /dev/null +++ b/lib/gui/subtitle_combo_box.py @@ -0,0 +1,85 @@ +import wx +import wx.adv +from wx.lib.wordwrap import wordwrap + + +class SubtitleComboBox(wx.adv.OwnerDrawnComboBox): + TITLE_FONT_SIZE = 12 + SUBTITLE_FONT_SIZE = 10 + + # I'd love to make this 12 too, but if I do it seems to get drawn as 10 + # initially no matter what I do. + CONTROL_FONT_SIZE = 12 + + MARGIN = 5 + + def __init__(self, *args, **kwargs): + self.titles = kwargs.get('choices', []) + subtitles = kwargs.pop('subtitles', {}) + self.subtitles = [subtitles.get(title, '') for title in self.titles] + wx.adv.OwnerDrawnComboBox.__init__(self, *args, **kwargs) + + self.control_font = wx.Font(pointSize=self.CONTROL_FONT_SIZE, family=wx.DEFAULT, style=wx.NORMAL, weight=wx.NORMAL) + self.title_font = wx.Font(pointSize=self.TITLE_FONT_SIZE, family=wx.DEFAULT, style=wx.NORMAL, weight=wx.NORMAL) + self.subtitle_font = wx.Font(pointSize=self.SUBTITLE_FONT_SIZE, family=wx.DEFAULT, style=wx.NORMAL, weight=wx.NORMAL) + + def OnMeasureItemWidth(self, item): + # This _should_ allow us to set the width of the combobox to match the + # width of the widest title. In reality, this method is never called + # and I can't figure out why. We just use self.GetSize().GetWidth() + # instead and rely on the parent window to size us appropriately. Ugh. + + title = self.titles[item] + + # technique from https://stackoverflow.com/a/23529463/4249120 + dc = wx.ScreenDC() + dc.SetFont(self.title_font) + + return dc.GetTextExtent(title).GetWidth() + 2 * self.MARGIN + + def OnMeasureItem(self, item): + title = self.titles[item] + subtitle = self.subtitles[item] + + dc = wx.ScreenDC() + dc.SetFont(self.subtitle_font) + wrapped = wordwrap(subtitle, self.GetSize().GetWidth(), dc) + subtitle_height = dc.GetTextExtent(wrapped).GetHeight() + + dc = wx.ScreenDC() + dc.SetFont(self.title_font) + title_height = dc.GetTextExtent(title).GetHeight() + + return subtitle_height + title_height + 3 * self.MARGIN + + def OnDrawBackground(self, dc, rect, item, flags): + if flags & wx.adv.ODCB_PAINTING_SELECTED: + # let the parent class draw the selected item so we don't + # hae to figure out the highlight color + wx.adv.OwnerDrawnComboBox.OnDrawBackground(self, dc, rect, item, flags) + else: + # alternate white and grey for the dropdown items, and draw the + # combo box itself as white + if flags & wx.adv.ODCB_PAINTING_CONTROL or item % 2 == 0: + background_color = wx.Colour(255, 255, 255) + else: + background_color = wx.Colour(240, 240, 240) + + dc.SetBrush(wx.Brush(background_color)) + dc.SetPen(wx.Pen(background_color)) + dc.DrawRectangle(rect) + + def OnDrawItem(self, dc, rect, item, flags): + if flags & wx.adv.ODCB_PAINTING_CONTROL: + # painting the selected item in the box + dc.SetFont(self.control_font) + dc.DrawText(self.titles[item], rect.x + self.MARGIN, rect.y + self.MARGIN) + else: + # painting the items in the popup + dc.SetFont(self.title_font) + title_height = dc.GetCharHeight() + dc.DrawText(self.titles[item], rect.x + self.MARGIN, rect.y + self.MARGIN) + + dc.SetFont(self.subtitle_font) + subtitle = wordwrap(self.subtitles[item], self.GetSize().GetWidth(), dc) + dc.DrawText(subtitle, rect.x + self.MARGIN, rect.y + title_height + self.MARGIN * 2) |
