From 2c3be600c3a17f676853fd42e00c0c31d6c674da Mon Sep 17 00:00:00 2001 From: Claudine Peyrat <88194877+claudinepeyrat06@users.noreply.github.com> Date: Sun, 22 Jun 2025 07:01:02 +0200 Subject: Claudine/unable element info copy (#3817) * firststeps * Update element_info.py * Update element_info.py * Update element_info.py add some help * make style... * rename a variable and fix a mistake * make headline nicer --- lib/extensions/element_info.py | 39 ++++++++++++++++++++++++++------------- lib/gui/element_info.py | 24 ++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/lib/extensions/element_info.py b/lib/extensions/element_info.py index ed879f43..3f2405fb 100644 --- a/lib/extensions/element_info.py +++ b/lib/extensions/element_info.py @@ -27,16 +27,17 @@ class ElementInfo(InkstitchExtension): self.list_items = [] self.max_stitch_lengths = [] self.min_stitch_lengths = [] + self.export_txt = "element_id\ttype\tmethod\tdimensions\tstitches\tjumps\tmax_stitch_length\tmin_stitch_length\n" next_elements = [None] if len(self.elements) > 1: next_elements = self.elements[1:] + next_elements previous_stitch_group = None for element, next_element in zip(self.elements, next_elements): - previous_stitch_group = self._element_info(element, previous_stitch_group, next_element) + text_export, previous_stitch_group = self._element_info(element, previous_stitch_group, next_element) + self.export_txt += text_export self._general_info() - - app = ElementInfoApp(self.list_items) + app = ElementInfoApp(self.list_items, self.export_txt) app.MainLoop() def _element_info(self, element, previous_stitch_group, next_element): @@ -46,18 +47,22 @@ class ElementInfo(InkstitchExtension): collapse_len=self.metadata['collapse_len_mm'], min_stitch_len=self.metadata['min_stitch_len_mm'] ) + label = element.node.label + element_id = element.node.get_id() self.list_items.append(ListItem( - name=f"{element.node.label} ({element.node.get_id()})", + name=f"{label} ({element_id})", value=stitch_groups[0].color, headline=True )) + element_name = element.element_name self.list_items.append(ListItem( name=_("Type"), - value=element.element_name + value=element_name )) if isinstance(element, FillStitch): fill_method = next((method.name for method in element._fill_methods if method.id == element.fill_method), "") + method = fill_method self.list_items.append(ListItem( name=_("Fill Method"), value=fill_method @@ -65,6 +70,7 @@ class ElementInfo(InkstitchExtension): if isinstance(element, SatinColumn): satin_method = next((method.name for method in element._satin_methods if method.id == element.satin_method), "") + method = satin_method self.list_items.append(ListItem( name=_("Satin Method"), value=satin_method @@ -72,14 +78,15 @@ class ElementInfo(InkstitchExtension): if isinstance(element, Stroke): stroke_method = next((method.name for method in element._stroke_methods if method.id == element.stroke_method), "") + method = stroke_method self.list_items.append(ListItem( name=_("Stroke Method"), value=stroke_method )) - + dimensions = "{:.2f} x {:.2f}".format(stitch_plan.dimensions_mm[0], stitch_plan.dimensions_mm[1]) self.list_items.append(ListItem( name=_("Dimensions (mm)"), - value="{:.2f} x {:.2f}".format(stitch_plan.dimensions_mm[0], stitch_plan.dimensions_mm[1]) + value=dimensions )) stitch_lengths = [] @@ -112,34 +119,40 @@ class ElementInfo(InkstitchExtension): name=_("Small stitches (removed)"), value=str(removed_stitches) )) - return stitch_groups[0] + return ("", stitch_groups[0]) stitches_per_group = "" if len(stitch_groups) > 1: stitches_per_group = f" ({', '.join([str(len(group.stitches)) for group in stitch_groups])})" + nb_stitches = str(stitch_plan.num_stitches - stitch_plan.num_jumps) + stitches_per_group self.list_items.append(ListItem( name=_("Stitches"), - value=str(stitch_plan.num_stitches - stitch_plan.num_jumps) + stitches_per_group + value=nb_stitches )) self.list_items.append(ListItem( name=_("Small stitches (removed)"), value=str(removed_stitches) )) + nb_jumps = str(stitch_plan.num_jumps - 1) self.list_items.append(ListItem( name=_("Jumps"), - value=str(stitch_plan.num_jumps - 1) + value=nb_jumps )) + max_stitch_length = "{:.2f}".format(max(stitch_lengths)) self.list_items.append(ListItem( name=_("Max stitch length"), - value="{:.2f}".format(max(stitch_lengths)) + value=max_stitch_length )) + min_stitch_length = "{:.2f}".format(min(stitch_lengths)) self.list_items.append(ListItem( name=_("Min stitch length"), - value="{:.2f}".format(min(stitch_lengths)) + value=min_stitch_length )) self.list_items.append(ListItem()) - return stitch_groups[0] + + text_export = f"{element_id}\t{element_name}\t{method}\t{dimensions}\t{nb_stitches}\t{nb_jumps}\t{max_stitch_length}\t{min_stitch_length}\n" + return (text_export, stitch_groups[0]) def _general_info(self): general_info_list_items = [] diff --git a/lib/gui/element_info.py b/lib/gui/element_info.py index cee93e3e..a2f0824e 100644 --- a/lib/gui/element_info.py +++ b/lib/gui/element_info.py @@ -13,6 +13,7 @@ class ElementInfoFrame(wx.Frame): def __init__(self, *args, **kwargs): self.list_items = kwargs.pop("list_items") + self.export_txt = kwargs.pop("export_txt") self.index = 0 wx.Frame.__init__(self, None, wx.ID_ANY, _("Element Info"), *args, **kwargs) @@ -64,6 +65,18 @@ class ElementInfoFrame(wx.Frame): ) help_sizer.Add(self.website_link, 0, wx.ALL, 8) + copy_info_text = wx.StaticText( + self.help, + wx.ID_ANY, + _("Click on Copy to copy the information in the Clipboard"), + style=wx.ALIGN_LEFT + ) + help_sizer.Add(copy_info_text, 0, wx.ALL, 8) + + cmd_copy = wx.Button(self.help, wx.ID_COPY) + cmd_copy.Bind(wx.EVT_BUTTON, self.on_copy) + help_sizer.Add(cmd_copy, 0, wx.ALL, 8) + self.help.SetSizer(help_sizer) self.info.SetSizer(info_sizer) self.main_panel.SetSizer(notebook_sizer) @@ -72,6 +85,12 @@ class ElementInfoFrame(wx.Frame): self.Layout() + def on_copy(self, event): + if wx.TheClipboard.Open(): + text = self.export_txt + data_object = wx.TextDataObject(text) + wx.TheClipboard.SetData(data_object) + def _fill_info_list(self): for item in self.list_items: self.info_list.InsertItem(self.index, item.name) @@ -90,12 +109,13 @@ class ElementInfoFrame(wx.Frame): class ElementInfoApp(wx.App): - def __init__(self, list_items): + def __init__(self, list_items, export_txt): self.list_items = list_items + self.export_txt = export_txt super().__init__() def OnInit(self): - self.frame = ElementInfoFrame(list_items=self.list_items) + self.frame = ElementInfoFrame(list_items=self.list_items, export_txt=self.export_txt) self.SetTopWindow(self.frame) self.frame.Show() return True -- cgit v1.2.3