Skip to content

Commit 51d10c1

Browse files
committed
7.5.14
#### Removed: - Removed settings for cut_contents, copy_contents and the new plain equivalent added in `7.5.13`. These settings now use the same as the usual cut and copy settings. #### Changed: - Mac OS now binds both mouse button 2 and 3 for right click [#2](#2). - Changed copy text binding to `Ctrl + Ins`. - Changed copy text icon to differentiate from the normal copy. #### Added: - Right click binding setting to modify which buttons/keys are used for right click. - Setting for changing the to clipboard csv writer dialect. #### Fixed: - Tab characters causing cell text overflow. - Don't show tooltip when resizing is enabled and mouse is over grid lines in index or header. - More right click menu filtering based on selections.
1 parent 81deebf commit 51d10c1

15 files changed

+325
-227
lines changed

docs/CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
### Version 7.5.14
2-
####
2+
#### Removed:
3+
- Removed settings for cut_contents, copy_contents and the new plain equivalent added in `7.5.13`. These settings now use the same as the usual cut and copy settings.
4+
5+
#### Changed:
6+
- Mac OS now binds both mouse button 2 and 3 for right click [#2](https://github.com/ragardner/tksheet/issues/2).
7+
- Changed copy text binding to `Ctrl + Ins`.
8+
- Changed copy text icon to differentiate from the normal copy.
9+
10+
#### Added:
11+
- Right click binding setting to modify which buttons/keys are used for right click.
12+
- Setting for changing the to clipboard csv writer dialect.
13+
14+
#### Fixed:
15+
- Tab characters causing cell text overflow.
16+
- Don't show tooltip when resizing is enabled and mouse is over grid lines in index or header.
17+
- More right click menu filtering based on selections.
318

419
### Version 7.5.13
520
#### Fixed:

docs/DOCUMENTATION.html

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -702,15 +702,17 @@ <h1 id="about-tksheet"><strong>About tksheet</strong></h1>
702702
</li>
703703
</ul>
704704
<h3 id="known-issues"><strong>Known Issues</strong></h3>
705-
<ol>
705+
<ul>
706+
<li>Word wrap - Tabs and multiple spaces are rendered as a single space.</li>
707+
<li>Mac OS has both <code>&lt;2&gt;</code> and <code>&lt;3&gt;</code> bound for right click.</li>
706708
<li>When using <code>edit_validation()</code> to validate cell edits and pasting into the sheet:<ul>
707709
<li>If the sheets rows are expanded then the row numbers under the key <code>row</code> and <code>loc</code> are data indexes whereas the column numbers are displayed indexes.</li>
708710
<li>If the sheets columns are expanded then the column numbers under the key <code>column</code> and <code>loc</code> are data indexes whereas the row numbers are displayed indexes.</li>
709711
<li>This is only relevant when there are hidden rows or columns and you're using <code>edit_validation()</code> and you're using the event data keys <code>row</code>, <code>column</code> or <code>loc</code> in your bound <code>edit_validation()</code> function and you're using paste and the sheet can be expanded by paste.</li>
710712
</ul>
711713
</li>
712714
<li>There may be some issues with toggle select mode and deselection.</li>
713-
</ol>
715+
</ul>
714716
<h3 id="limitations"><strong>Limitations</strong></h3>
715717
<p>Some examples of things that are not possible with tksheet:</p>
716718
<ul>
@@ -974,6 +976,7 @@ <h1 id="initialization-options"><strong>Initialization Options</strong></h1>
974976
all_columns_displayed: bool = True,
975977
displayed_rows: list[int] | None = None,
976978
all_rows_displayed: bool = True,
979+
to_clipboard_dialect: csv.Dialect = csv.excel_tab,
977980
to_clipboard_delimiter: str = &quot;\t&quot;,
978981
to_clipboard_quotechar: str = '&quot;',
979982
to_clipboard_lineterminator: str = &quot;\n&quot;,
@@ -1438,21 +1441,16 @@ <h1 id="sheet-options"><strong>Sheet Options</strong></h1>
14381441
&quot;cut_accelerator&quot;: &quot;Ctrl+X&quot;,
14391442
&quot;cut_image&quot;: tk.PhotoImage(data=ICON_CUT),
14401443
&quot;cut_compound&quot;: &quot;left&quot;,
1441-
# cut contents
1442-
&quot;cut_contents_label&quot;: &quot;Cut contents&quot;,
1443-
&quot;cut_contents_accelerator&quot;: &quot;Ctrl+X&quot;,
1444-
&quot;cut_contents_image&quot;: tk.PhotoImage(data=ICON_CUT),
1445-
&quot;cut_contents_compound&quot;: &quot;left&quot;,
14461444
# copy
14471445
&quot;copy_label&quot;: &quot;Copy&quot;,
14481446
&quot;copy_accelerator&quot;: &quot;Ctrl+C&quot;,
14491447
&quot;copy_image&quot;: tk.PhotoImage(data=ICON_COPY),
14501448
&quot;copy_compound&quot;: &quot;left&quot;,
1451-
# copy contents
1452-
&quot;copy_contents_label&quot;: &quot;Copy contents&quot;,
1453-
&quot;copy_contents_accelerator&quot;: &quot;Ctrl+C&quot;,
1454-
&quot;copy_contents_image&quot;: tk.PhotoImage(data=ICON_COPY),
1455-
&quot;copy_contents_compound&quot;: &quot;left&quot;,
1449+
# copy plain
1450+
&quot;copy_plain_label&quot;: &quot;Copy text&quot;,
1451+
&quot;copy_plain_accelerator&quot;: &quot;Ctrl+Insert&quot;,
1452+
&quot;copy_plain_image&quot;: tk.PhotoImage(data=ICON_COPY),
1453+
&quot;copy_plain_compound&quot;: &quot;left&quot;,
14561454
# paste
14571455
&quot;paste_label&quot;: &quot;Paste&quot;,
14581456
&quot;paste_accelerator&quot;: &quot;Ctrl+V&quot;,
@@ -1581,10 +1579,14 @@ <h1 id="sheet-options"><strong>Sheet Options</strong></h1>
15811579
&quot;redo_image&quot;: tk.PhotoImage(data=ICON_REDO),
15821580
&quot;redo_compound&quot;: &quot;left&quot;,
15831581
# bindings
1582+
&quot;rc_bindings&quot;: [&quot;&lt;2&gt;&quot;, &quot;&lt;3&gt;&quot;] if USER_OS == &quot;darwin&quot; else [&quot;&lt;3&gt;&quot;],
15841583
&quot;copy_bindings&quot;: [
15851584
f&quot;&lt;{ctrl_key}-c&gt;&quot;,
15861585
f&quot;&lt;{ctrl_key}-C&gt;&quot;,
15871586
],
1587+
&quot;copy_plain_bindings&quot;: [
1588+
f&quot;&lt;{ctrl_key}-Insert&gt;&quot;,
1589+
],
15881590
&quot;cut_bindings&quot;: [
15891591
f&quot;&lt;{ctrl_key}-x&gt;&quot;,
15901592
f&quot;&lt;{ctrl_key}-X&gt;&quot;,
@@ -1686,6 +1688,7 @@ <h1 id="sheet-options"><strong>Sheet Options</strong></h1>
16861688
&quot;set_cell_sizes_on_zoom&quot;: False,
16871689
&quot;auto_resize_columns&quot;: None,
16881690
&quot;auto_resize_rows&quot;: None,
1691+
&quot;to_clipboard_dialect&quot;: csv.excel_tab,
16891692
&quot;to_clipboard_delimiter&quot;: &quot;\t&quot;,
16901693
&quot;to_clipboard_quotechar&quot;: '&quot;',
16911694
&quot;to_clipboard_lineterminator&quot;: &quot;\n&quot;,
@@ -2570,21 +2573,16 @@ <h4 id="changing-right-click-menu-labels"><strong>Changing right click menu labe
25702573
&quot;cut_accelerator&quot;: &quot;Ctrl+X&quot;,
25712574
&quot;cut_image&quot;: tk.PhotoImage(data=ICON_CUT),
25722575
&quot;cut_compound&quot;: &quot;left&quot;,
2573-
# cut contents
2574-
&quot;cut_contents_label&quot;: &quot;Cut contents&quot;,
2575-
&quot;cut_contents_accelerator&quot;: &quot;Ctrl+X&quot;,
2576-
&quot;cut_contents_image&quot;: tk.PhotoImage(data=ICON_CUT),
2577-
&quot;cut_contents_compound&quot;: &quot;left&quot;,
25782576
# copy
25792577
&quot;copy_label&quot;: &quot;Copy&quot;,
25802578
&quot;copy_accelerator&quot;: &quot;Ctrl+C&quot;,
25812579
&quot;copy_image&quot;: tk.PhotoImage(data=ICON_COPY),
25822580
&quot;copy_compound&quot;: &quot;left&quot;,
2583-
# copy contents
2584-
&quot;copy_contents_label&quot;: &quot;Copy contents&quot;,
2585-
&quot;copy_contents_accelerator&quot;: &quot;Ctrl+C&quot;,
2586-
&quot;copy_contents_image&quot;: tk.PhotoImage(data=ICON_COPY),
2587-
&quot;copy_contents_compound&quot;: &quot;left&quot;,
2581+
# copy plain
2582+
&quot;copy_plain_label&quot;: &quot;Copy text&quot;,
2583+
&quot;copy_plain_accelerator&quot;: &quot;Ctrl+Insert&quot;,
2584+
&quot;copy_plain_image&quot;: tk.PhotoImage(data=ICON_COPY),
2585+
&quot;copy_plain_compound&quot;: &quot;left&quot;,
25882586
# paste
25892587
&quot;paste_label&quot;: &quot;Paste&quot;,
25902588
&quot;paste_accelerator&quot;: &quot;Ctrl+V&quot;,
@@ -2717,6 +2715,29 @@ <h4 id="changing-right-click-menu-labels"><strong>Changing right click menu labe
27172715
<pre><code class="language-python"># changing the copy label to the spanish for Copy
27182716
sheet.set_options(copy_label=&quot;Copiar&quot;, copy_image=tk.PhotoImage(file=&quot;filepath_to_img.png&quot;), copy_compound=&quot;left&quot;)
27192717
</code></pre>
2718+
<p>Notes:</p>
2719+
<ul>
2720+
<li>To remove the <code>Copy plain</code> right click menu option when copy is enabled you can overwrite it, e.g.</li>
2721+
</ul>
2722+
<pre><code class="language-python">from tksheet import (
2723+
ICON_COPY,
2724+
Sheet,
2725+
ctrl_key,
2726+
)
2727+
2728+
# ...
2729+
2730+
self.sheet.set_options(
2731+
copy_plain_label=&quot;Copy&quot;,
2732+
copy_plain_accelerator=&quot;Ctrl+C&quot;,
2733+
copy_plain_image=tk.PhotoImage(data=ICON_COPY),
2734+
copy_plain_compound=&quot;left&quot;,
2735+
copy_plain_bindings=[
2736+
f&quot;&lt;{ctrl_key}-c&gt;&quot;,
2737+
f&quot;&lt;{ctrl_key}-C&gt;&quot;,
2738+
],
2739+
)
2740+
</code></pre>
27202741
<h4 id="changing-key-bindings"><strong>Changing key bindings</strong></h4>
27212742
<p>You can change the bindings for tksheets in-built functionality such as cut, copy, paste by using the <a href="#sheet-options"><code>set_options()</code> function</a> with any the following keyword arguments:</p>
27222743
<pre><code class="language-python">copy_bindings

docs/DOCUMENTATION.md

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
### **Known Issues**
1010

11-
1. When using `edit_validation()` to validate cell edits and pasting into the sheet:
11+
- Word wrap - Tabs and multiple spaces are rendered as a single space.
12+
- Mac OS has both `<2>` and `<3>` bound for right click.
13+
- When using `edit_validation()` to validate cell edits and pasting into the sheet:
1214
- If the sheets rows are expanded then the row numbers under the key `row` and `loc` are data indexes whereas the column numbers are displayed indexes.
1315
- If the sheets columns are expanded then the column numbers under the key `column` and `loc` are data indexes whereas the row numbers are displayed indexes.
1416
- This is only relevant when there are hidden rows or columns and you're using `edit_validation()` and you're using the event data keys `row`, `column` or `loc` in your bound `edit_validation()` function and you're using paste and the sheet can be expanded by paste.
15-
2. There may be some issues with toggle select mode and deselection.
17+
- There may be some issues with toggle select mode and deselection.
1618

1719
### **Limitations**
1820

@@ -292,6 +294,7 @@ def __init__(
292294
all_columns_displayed: bool = True,
293295
displayed_rows: list[int] | None = None,
294296
all_rows_displayed: bool = True,
297+
to_clipboard_dialect: csv.Dialect = csv.excel_tab,
295298
to_clipboard_delimiter: str = "\t",
296299
to_clipboard_quotechar: str = '"',
297300
to_clipboard_lineterminator: str = "\n",
@@ -781,31 +784,16 @@ Key word arguments available for `set_options()` (values are defaults):
781784
"cut_accelerator": "Ctrl+X",
782785
"cut_image": tk.PhotoImage(data=ICON_CUT),
783786
"cut_compound": "left",
784-
# cut contents
785-
"cut_contents_label": "Cut contents",
786-
"cut_contents_accelerator": "Ctrl+X",
787-
"cut_contents_image": tk.PhotoImage(data=ICON_CUT),
788-
"cut_contents_compound": "left",
789787
# copy
790788
"copy_label": "Copy",
791789
"copy_accelerator": "Ctrl+C",
792790
"copy_image": tk.PhotoImage(data=ICON_COPY),
793791
"copy_compound": "left",
794-
# copy contents
795-
"copy_contents_label": "Copy contents",
796-
"copy_contents_accelerator": "Ctrl+C",
797-
"copy_contents_image": tk.PhotoImage(data=ICON_COPY),
798-
"copy_contents_compound": "left",
799792
# copy plain
800793
"copy_plain_label": "Copy text",
801-
"copy_plain_accelerator": "Ctrl+Alt+C",
794+
"copy_plain_accelerator": "Ctrl+Insert",
802795
"copy_plain_image": tk.PhotoImage(data=ICON_COPY),
803796
"copy_plain_compound": "left",
804-
# copy contents plain
805-
"copy_contents_plain_label": "Copy text contents",
806-
"copy_contents_plain_accelerator": "Ctrl+Alt+C",
807-
"copy_contents_plain_image": tk.PhotoImage(data=ICON_COPY),
808-
"copy_contents_plain_compound": "left",
809797
# paste
810798
"paste_label": "Paste",
811799
"paste_accelerator": "Ctrl+V",
@@ -934,10 +922,14 @@ Key word arguments available for `set_options()` (values are defaults):
934922
"redo_image": tk.PhotoImage(data=ICON_REDO),
935923
"redo_compound": "left",
936924
# bindings
925+
"rc_bindings": ["<2>", "<3>"] if USER_OS == "darwin" else ["<3>"],
937926
"copy_bindings": [
938927
f"<{ctrl_key}-c>",
939928
f"<{ctrl_key}-C>",
940929
],
930+
"copy_plain_bindings": [
931+
f"<{ctrl_key}-Insert>",
932+
],
941933
"cut_bindings": [
942934
f"<{ctrl_key}-x>",
943935
f"<{ctrl_key}-X>",
@@ -1039,6 +1031,7 @@ else ["<Home>"],
10391031
"set_cell_sizes_on_zoom": False,
10401032
"auto_resize_columns": None,
10411033
"auto_resize_rows": None,
1034+
"to_clipboard_dialect": csv.excel_tab,
10421035
"to_clipboard_delimiter": "\t",
10431036
"to_clipboard_quotechar": '"',
10441037
"to_clipboard_lineterminator": "\n",
@@ -1894,31 +1887,16 @@ You can change the labels for tksheets in-built right click popup menu by using
18941887
"cut_accelerator": "Ctrl+X",
18951888
"cut_image": tk.PhotoImage(data=ICON_CUT),
18961889
"cut_compound": "left",
1897-
# cut contents
1898-
"cut_contents_label": "Cut contents",
1899-
"cut_contents_accelerator": "Ctrl+X",
1900-
"cut_contents_image": tk.PhotoImage(data=ICON_CUT),
1901-
"cut_contents_compound": "left",
19021890
# copy
19031891
"copy_label": "Copy",
19041892
"copy_accelerator": "Ctrl+C",
19051893
"copy_image": tk.PhotoImage(data=ICON_COPY),
19061894
"copy_compound": "left",
1907-
# copy contents
1908-
"copy_contents_label": "Copy contents",
1909-
"copy_contents_accelerator": "Ctrl+C",
1910-
"copy_contents_image": tk.PhotoImage(data=ICON_COPY),
1911-
"copy_contents_compound": "left",
19121895
# copy plain
19131896
"copy_plain_label": "Copy text",
1914-
"copy_plain_accelerator": "Ctrl+Alt+C",
1897+
"copy_plain_accelerator": "Ctrl+Insert",
19151898
"copy_plain_image": tk.PhotoImage(data=ICON_COPY),
19161899
"copy_plain_compound": "left",
1917-
# copy contents plain
1918-
"copy_contents_plain_label": "Copy text contents",
1919-
"copy_contents_plain_accelerator": "Ctrl+Alt+C",
1920-
"copy_contents_plain_image": tk.PhotoImage(data=ICON_COPY),
1921-
"copy_contents_plain_compound": "left",
19221900
# paste
19231901
"paste_label": "Paste",
19241902
"paste_accelerator": "Ctrl+V",
@@ -2055,6 +2033,31 @@ Example:
20552033
sheet.set_options(copy_label="Copiar", copy_image=tk.PhotoImage(file="filepath_to_img.png"), copy_compound="left")
20562034
```
20572035

2036+
Notes:
2037+
2038+
- To remove the `Copy plain` right click menu option when copy is enabled you can overwrite it, e.g.
2039+
2040+
```python
2041+
from tksheet import (
2042+
ICON_COPY,
2043+
Sheet,
2044+
ctrl_key,
2045+
)
2046+
2047+
# ...
2048+
2049+
self.sheet.set_options(
2050+
copy_plain_label="Copy",
2051+
copy_plain_accelerator="Ctrl+C",
2052+
copy_plain_image=tk.PhotoImage(data=ICON_COPY),
2053+
copy_plain_compound="left",
2054+
copy_plain_bindings=[
2055+
f"<{ctrl_key}-c>",
2056+
f"<{ctrl_key}-C>",
2057+
],
2058+
)
2059+
```
2060+
20582061
#### **Changing key bindings**
20592062

20602063
You can change the bindings for tksheets in-built functionality such as cut, copy, paste by using the [`set_options()` function](#sheet-options) with any the following keyword arguments:

tksheet/column_headers.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self, parent: tk.Misc, **kwargs) -> None:
6868
"menu_kwargs": get_menu_kwargs(self.ops),
6969
**get_bg_fg(self.ops),
7070
"scrollbar_style": f"Sheet{self.PAR.unique_id}.Vertical.TScrollbar",
71-
"rc_binding": self.ops.rc_binding,
71+
"rc_bindings": self.ops.rc_bindings,
7272
}
7373
)
7474
self.tooltip_widgets = widget_descendants(self.tooltip)
@@ -153,7 +153,8 @@ def basic_bindings(self, enable: bool = True) -> None:
153153
self.bind("<B1-Motion>", self.b1_motion)
154154
self.bind("<ButtonRelease-1>", self.b1_release)
155155
self.bind("<Double-Button-1>", self.double_b1)
156-
self.bind(self.ops.rc_binding, self.rc)
156+
for b in self.ops.rc_bindings:
157+
self.bind(b, self.rc)
157158
self.bind("<MouseWheel>", self.mousewheel)
158159
if USER_OS == "linux":
159160
self.bind("<Button-4>", self.mousewheel)
@@ -164,7 +165,8 @@ def basic_bindings(self, enable: bool = True) -> None:
164165
self.unbind("<B1-Motion>")
165166
self.unbind("<ButtonRelease-1>")
166167
self.unbind("<Double-Button-1>")
167-
self.unbind(self.ops.rc_binding)
168+
for b in self.ops.rc_bindings:
169+
self.unbind(b)
168170
self.unbind("<MouseWheel>")
169171
if USER_OS == "linux":
170172
self.unbind("<Button-4>")
@@ -1510,7 +1512,7 @@ def configure_scrollregion(self, last_col_line_pos: float) -> bool:
15101512
except Exception:
15111513
return False
15121514

1513-
def wrap_get_char_w(self, c: str) -> int:
1515+
def char_width_fn(self, c: str) -> int:
15141516
if c in self.MT.char_widths[self.header_font]:
15151517
return self.MT.char_widths[self.header_font][c]
15161518
else:
@@ -1703,7 +1705,7 @@ def redraw_grid_and_text(
17031705
text=text,
17041706
max_width=max_width,
17051707
max_lines=int((self.current_height - top - 2) / txt_h),
1706-
char_width_fn=self.wrap_get_char_w,
1708+
char_width_fn=self.char_width_fn,
17071709
widths=self.MT.char_widths[font],
17081710
wrap=wrap,
17091711
)
@@ -1824,7 +1826,11 @@ def check_and_show_tooltip(self, event: tk.Event | None = None) -> None:
18241826
current_x, current_y = self.winfo_pointerx(), self.winfo_pointery()
18251827
if current_x < 0 or current_y < 0:
18261828
return
1827-
if abs(current_x - self.tooltip_last_x) <= 1 and abs(current_y - self.tooltip_last_y) <= 1:
1829+
if (
1830+
not self.cget("cursor")
1831+
and abs(current_x - self.tooltip_last_x) <= 1
1832+
and abs(current_y - self.tooltip_last_y) <= 1
1833+
):
18281834
self.show_tooltip()
18291835
else:
18301836
self.tooltip_last_x, self.tooltip_last_y = current_x, current_y
@@ -1999,7 +2005,7 @@ def open_text_editor(
19992005
}
20002006
if not self.text_editor.window:
20012007
self.text_editor.window = TextEditor(
2002-
self, newline_binding=self.text_editor_newline_binding, rc_binding=self.ops.rc_binding
2008+
self, newline_binding=self.text_editor_newline_binding, rc_bindings=self.ops.rc_bindings
20032009
)
20042010
self.text_editor.canvas_id = self.create_window((x, y), window=self.text_editor.window, anchor="nw")
20052011
self.text_editor.window.reset(**kwargs)

0 commit comments

Comments
 (0)