From 9d68938293aea1d57989fc7d8be51930f6f588cd Mon Sep 17 00:00:00 2001
From: A_D <aunderscored@gmail.com>
Date: Mon, 17 May 2021 08:22:35 +0200
Subject: [PATCH 1/3] Added the ability to copy individual entries from status

Currently no method for entire pages.

closes #1060
---
 stats.py | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/stats.py b/stats.py
index fcd514cc..d15d9622 100644
--- a/stats.py
+++ b/stats.py
@@ -3,7 +3,8 @@ import csv
 import tkinter as tk
 from sys import platform
 from tkinter import ttk
-from typing import TYPE_CHECKING, Any, AnyStr, Dict, List, NamedTuple, Optional, Sequence, cast
+import tkinter
+from typing import Callable, TYPE_CHECKING, Any, AnyStr, Dict, List, NamedTuple, Optional, Sequence, cast
 
 import companion
 import EDMCLogging
@@ -11,6 +12,7 @@ import myNotebook as nb  # noqa: N813
 from edmc_data import ship_name_map
 from l10n import Locale
 from monitor import monitor
+from ttkHyperlinkLabel import HyperlinkLabel
 
 logger = EDMCLogging.get_main_logger()
 
@@ -342,10 +344,11 @@ class StatsResults(tk.Toplevel):
 
         page = self.addpage(notebook)
         for thing in stats[1:3]:
-            self.addpagerow(page, [thing[0], self.credits(int(thing[1]))])  # assumes things two and three are money
+            # assumes things two and three are money
+            self.addpagerow(page, [thing[0], self.credits(int(thing[1]))], with_copy=True)
 
         for thing in stats[3:]:
-            self.addpagerow(page, thing)
+            self.addpagerow(page, thing, with_copy=True)
 
         ttk.Frame(page).grid(pady=5)   # bottom spacer
         notebook.add(page, text=_('Status'))  # Status dialog title
@@ -361,7 +364,7 @@ class StatsResults(tk.Toplevel):
         shiplist = ships(data)
         for ship_data in shiplist:
             # skip id, last item is money
-            self.addpagerow(page, list(ship_data[1:-1]) + [self.credits(int(ship_data[-1]))])
+            self.addpagerow(page, list(ship_data[1:-1]) + [self.credits(int(ship_data[-1]))], with_copy=True)
 
         ttk.Frame(page).grid(pady=5)         # bottom spacer
         notebook.add(page, text=_('Ships'))  # Status dialog title
@@ -417,14 +420,14 @@ class StatsResults(tk.Toplevel):
         :param header: The headers to add to the page
         :param align: The alignment of the page, defaults to None
         """
-        self.addpagerow(parent, header, align=align)
+        self.addpagerow(parent, header, align=align, with_copy=False)
         ttk.Separator(parent, orient=tk.HORIZONTAL).grid(columnspan=len(header), padx=10, pady=2, sticky=tk.EW)
 
     def addpagespacer(self, parent) -> None:
         """Add a spacer to the page."""
         self.addpagerow(parent, [''])
 
-    def addpagerow(self, parent: tk.Frame, content: Sequence[str], align: Optional[str] = None):
+    def addpagerow(self, parent: tk.Frame, content: Sequence[str], align: Optional[str] = None, with_copy: bool = False):
         """
         Add a single row to parent.
 
@@ -434,7 +437,11 @@ class StatsResults(tk.Toplevel):
         """
         row = -1  # To silence unbound warnings
         for i in range(len(content)):
+            # label = HyperlinkLabel(parent, text=content[i], popup_copy=True)
             label = nb.Label(parent, text=content[i])
+            if with_copy:
+                label.bind('<Button-1>', self.copy_callback(label, content[i]))
+
             if i == 0:
                 label.grid(padx=10, sticky=tk.W)
                 row = parent.grid_size()[1]-1
@@ -449,3 +456,16 @@ class StatsResults(tk.Toplevel):
         """Localised string of given int, including a trailing ` Cr`."""
         # TODO: Locale is a class, this calls an instance method on it with an int as its `self`
         return Locale.string_from_number(value, 0) + ' Cr'  # type: ignore
+
+    @staticmethod
+    def copy_callback(label: tk.Label, text_to_copy: str) -> Callable[..., None]:
+        """Copy data in Label to clipboard."""
+        def do_copy(event: tkinter.Event) -> None:
+            label.clipboard_clear()
+            label.clipboard_append(text_to_copy)
+            old_bg = label['bg']
+            label['bg'] = 'gray49'
+
+            label.after(100, (lambda: label.configure(bg=old_bg)))
+
+        return do_copy

From e68494035edfeebc6e21e5da0851ac110d74ff4b Mon Sep 17 00:00:00 2001
From: A_D <aunderscored@gmail.com>
Date: Mon, 17 May 2021 08:25:13 +0200
Subject: [PATCH 2/3] Sorted imports

---
 stats.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/stats.py b/stats.py
index d15d9622..3cc1c593 100644
--- a/stats.py
+++ b/stats.py
@@ -1,10 +1,10 @@
 """CMDR Status information."""
 import csv
+import tkinter
 import tkinter as tk
 from sys import platform
 from tkinter import ttk
-import tkinter
-from typing import Callable, TYPE_CHECKING, Any, AnyStr, Dict, List, NamedTuple, Optional, Sequence, cast
+from typing import TYPE_CHECKING, Any, AnyStr, Callable, Dict, List, NamedTuple, Optional, Sequence, cast
 
 import companion
 import EDMCLogging
@@ -12,7 +12,6 @@ import myNotebook as nb  # noqa: N813
 from edmc_data import ship_name_map
 from l10n import Locale
 from monitor import monitor
-from ttkHyperlinkLabel import HyperlinkLabel
 
 logger = EDMCLogging.get_main_logger()
 

From a89d4f1901bfd43ae160cae9c6e946001eb3550a Mon Sep 17 00:00:00 2001
From: A_D <aunderscored@gmail.com>
Date: Fri, 21 May 2021 11:02:51 +0200
Subject: [PATCH 3/3] Fixed line too long

---
 stats.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/stats.py b/stats.py
index 3cc1c593..704e4703 100644
--- a/stats.py
+++ b/stats.py
@@ -426,7 +426,9 @@ class StatsResults(tk.Toplevel):
         """Add a spacer to the page."""
         self.addpagerow(parent, [''])
 
-    def addpagerow(self, parent: tk.Frame, content: Sequence[str], align: Optional[str] = None, with_copy: bool = False):
+    def addpagerow(
+        self, parent: tk.Frame, content: Sequence[str], align: Optional[str] = None, with_copy: bool = False
+    ):
         """
         Add a single row to parent.