Skip to content

Commit

Permalink
fix compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ragardner committed May 29, 2023
1 parent dc517e9 commit 9cd4193
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 42 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Version 6.2.0
#### Fixed:
- Removed some type hinting that was only available to python versions >= 3.9

### Version 6.1.9
#### Fixed:
- Issues that follow selection boxes being recreated such as resizing columns/rows
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# **tksheet** [![PyPI version shields.io](https://img.shields.io/pypi/v/tksheet.svg)](https://pypi.python.org/pypi/tksheet/) ![python](https://img.shields.io/badge/python-3.8+-blue) [![License: MIT](https://img.shields.io/badge/License-MIT%20-blue.svg)](https://github.com/ragardner/tksheet/blob/master/LICENSE.txt) [![GitHub Release Date](https://img.shields.io/github/release-date-pre/ragardner/tksheet.svg)](https://github.com/ragardner/tksheet/releases) [![Downloads](https://img.shields.io/pypi/dm/tksheet.svg)](https://pypi.org/project/tksheet/)
# **tksheet** [![PyPI version shields.io](https://img.shields.io/pypi/v/tksheet.svg)](https://pypi.python.org/pypi/tksheet/) ![python](https://img.shields.io/badge/python-3.6+-blue) [![License: MIT](https://img.shields.io/badge/License-MIT%20-blue.svg)](https://github.com/ragardner/tksheet/blob/master/LICENSE.txt) [![GitHub Release Date](https://img.shields.io/github/release-date-pre/ragardner/tksheet.svg)](https://github.com/ragardner/tksheet/releases) [![Downloads](https://img.shields.io/pypi/dm/tksheet.svg)](https://pypi.org/project/tksheet/)

## **Python tkinter table widget**

Expand Down Expand Up @@ -54,4 +54,4 @@ With versions `5.5.0`+ if you use `extra_bindings()` with `"edit_cell"`/`"end_ed

----

![tksheet black theme](https://i.imgur.com/JeF9vJe.jpeg)
![tksheet black theme](https://i.imgur.com/JeF9vJe.jpeg)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
setup(
name = 'tksheet',
packages = ['tksheet'],
version = '6.1.9',
version = '6.2.0',
python_requires = '>=3.6',
license = 'MIT',
description = 'Tkinter table / sheet widget',
Expand All @@ -17,7 +17,7 @@
author = 'ragardner',
author_email = '[email protected]',
url = 'https://github.com/ragardner/tksheet',
download_url = 'https://github.com/ragardner/tksheet/archive/6.1.9.tar.gz',
download_url = 'https://github.com/ragardner/tksheet/archive/6.2.0.tar.gz',
keywords = ['tkinter', 'table', 'widget', 'sheet', 'grid', 'tk'],
install_requires = [],
classifiers = [
Expand Down
46 changes: 23 additions & 23 deletions tksheet/_tksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from itertools import accumulate, chain, islice
from tkinter import ttk
import bisect
from typing import Union, Callable
from typing import Union, Callable, List, Set, Tuple

from ._tksheet_column_headers import ColumnHeaders
from ._tksheet_main_table import MainTable
Expand Down Expand Up @@ -44,8 +44,8 @@ def __init__(
show_y_scrollbar: bool = True,
width: int = None,
height: int = None,
headers: list = None,
header: list = None,
headers: List = None,
header: List = None,
default_header: str = "letters", # letters, numbers or both
default_row_index: str = "numbers", # letters, numbers or both
to_clipboard_delimiter="\t",
Expand All @@ -62,16 +62,16 @@ def __init__(
arrow_key_down_right_scroll_page: bool = False,
enable_edit_cell_auto_resize: bool = True,
edit_cell_validation: bool = True,
data_reference: list = None,
data: list = None,
data_reference: List = None,
data: List = None,
# either (start row, end row, "rows"),
# or (start column, end column, "columns")
# or (cells start row,
# cells start column,
# cells end row,
# cells end column,
# "cells")
startup_select: tuple = None,
startup_select: Tuple = None,
startup_focus: bool = True,
total_columns: int = None,
total_rows: int = None,
Expand All @@ -81,25 +81,25 @@ def __init__(
max_row_height: str = "inf", # str or int
max_header_height: str = "inf", # str or int
max_index_width: str = "inf", # str or int
row_index: list = None,
index: list = None,
row_index: List = None,
index: List = None,
after_redraw_time_ms: int = 20,
row_index_width: int = None,
auto_resize_default_row_index: bool = True,
auto_resize_columns: Union[int, None] = None,
auto_resize_rows: Union[int, None] = None,
set_all_heights_and_widths: bool = False,
row_height: str = "1", # str or int
font: tuple = get_font(),
header_font: tuple = get_heading_font(),
index_font: tuple = get_index_font(), # currently has no effect
popup_menu_font: tuple = get_font(),
font: Tuple = get_font(),
header_font: Tuple = get_heading_font(),
index_font: Tuple = get_index_font(), # currently has no effect
popup_menu_font: Tuple = get_font(),
align: str = "w",
header_align: str = "center",
row_index_align: str = "center",
displayed_columns: list = [],
displayed_columns: List = [],
all_columns_displayed: bool = True,
displayed_rows: list = [],
displayed_rows: List = [],
all_rows_displayed: bool = True,
max_undos: int = 30,
outline_thickness: int = 0,
Expand Down Expand Up @@ -835,7 +835,7 @@ def emit_event(self, event, data={}):
def bind_event(self, sequence: str, func: Callable, add: Union[str, None] = None) -> None:
widget = self

def _substitute(*args) -> tuple[None]:
def _substitute(*args) -> Tuple[None]:
def e() -> None:
return None

Expand Down Expand Up @@ -1135,7 +1135,7 @@ def set_row_heights(self, row_heights=None, canvas_positions=False, reset=False,
else:
self.MT.row_positions = list(accumulate(chain([0], (height for height in row_heights))))

def verify_row_heights(self, row_heights: list, canvas_positions=False):
def verify_row_heights(self, row_heights: List, canvas_positions=False):
if row_heights[0] != 0 or isinstance(row_heights[0], bool):
return False
if not isinstance(row_heights, list):
Expand All @@ -1151,7 +1151,7 @@ def verify_row_heights(self, row_heights: list, canvas_positions=False):
return False
return True

def verify_column_widths(self, column_widths: list, canvas_positions=False):
def verify_column_widths(self, column_widths: List, canvas_positions=False):
if column_widths[0] != 0 or isinstance(column_widths[0], bool):
return False
if not isinstance(column_widths, list):
Expand Down Expand Up @@ -1217,7 +1217,7 @@ def delete_row(self, idx=0, deselect_all=False, redraw=True):
self.delete_rows(rows={idx}, deselect_all=deselect_all, redraw=False)
self.set_refresh_timer(redraw)

def delete_rows(self, rows: set = set(), deselect_all=False, redraw=True):
def delete_rows(self, rows: Set = set(), deselect_all=False, redraw=True):
if deselect_all:
self.deselect("all", redraw=False)
if isinstance(rows, set):
Expand Down Expand Up @@ -1350,7 +1350,7 @@ def delete_column(self, idx=0, deselect_all=False, redraw=True):
self.delete_columns(columns={idx}, deselect_all=deselect_all, redraw=False)
self.set_refresh_timer(redraw)

def delete_columns(self, columns: set = set(), deselect_all=False, redraw=True):
def delete_columns(self, columns: Set = set(), deselect_all=False, redraw=True):
if deselect_all:
self.deselect("all", redraw=False)
if isinstance(columns, set):
Expand Down Expand Up @@ -2697,7 +2697,7 @@ def set_column_data(self, c, values=tuple(), add_rows=True, redraw=False, keep_f

def insert_column(
self,
values: Union[list, tuple, int, None] = None,
values: Union[List, Tuple, int, None] = None,
idx: Union[str, int] = "end",
width=None,
deselect_all=False,
Expand All @@ -2719,7 +2719,7 @@ def insert_column(

def insert_columns(
self,
columns: Union[list, tuple, int, None] = 1,
columns: Union[List, Tuple, int, None] = 1,
idx: Union[str, int] = "end",
widths=None,
deselect_all=False,
Expand Down Expand Up @@ -2808,7 +2808,7 @@ def insert_columns(

def insert_row(
self,
values: Union[list, None] = None,
values: Union[List, None] = None,
idx: Union[str, int] = "end",
height=None,
deselect_all=False,
Expand All @@ -2828,7 +2828,7 @@ def insert_row(

def insert_rows(
self,
rows: Union[list, int] = 1,
rows: Union[List, int] = 1,
idx: Union[str, int] = "end",
heights=None,
deselect_all=False,
Expand Down
22 changes: 11 additions & 11 deletions tksheet/_tksheet_formatters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Union
from typing import Any, Union, Dict

from ._tksheet_vars import (
falsy,
Expand Down Expand Up @@ -64,11 +64,11 @@ def is_bool_like(v: Any, **kwargs):
return False


def to_str(v: Any, **kwargs: dict) -> str:
def to_str(v: Any, **kwargs: Dict) -> str:
return f"{v}"


def float_to_str(v: Union[int, float], **kwargs: dict) -> str:
def float_to_str(v: Union[int, float], **kwargs: Dict) -> str:
if isinstance(v, float):
if v.is_integer():
return f"{int(v)}"
Expand All @@ -79,7 +79,7 @@ def float_to_str(v: Union[int, float], **kwargs: dict) -> str:
return f"{v}"


def percentage_to_str(v: Union[int, float], **kwargs: dict) -> str:
def percentage_to_str(v: Union[int, float], **kwargs: Dict) -> str:
if isinstance(v, (int, float)):
x = v * 100
if isinstance(x, float):
Expand All @@ -92,7 +92,7 @@ def percentage_to_str(v: Union[int, float], **kwargs: dict) -> str:
return f"{x}%"


def bool_to_str(v: Any, **kwargs: dict) -> str:
def bool_to_str(v: Any, **kwargs: Dict) -> str:
return f"{v}"


Expand All @@ -101,7 +101,7 @@ def int_formatter(
format_function=to_int,
to_str_function=to_str,
**kwargs,
) -> dict:
) -> Dict:
return formatter(
datatypes=datatypes,
format_function=format_function,
Expand All @@ -116,7 +116,7 @@ def float_formatter(
to_str_function=float_to_str,
decimals=2,
**kwargs,
) -> dict:
) -> Dict:
return formatter(
datatypes=datatypes,
format_function=format_function,
Expand All @@ -132,7 +132,7 @@ def percentage_formatter(
to_str_function=percentage_to_str,
decimals=2,
**kwargs,
) -> dict:
) -> Dict:
return formatter(
datatypes=datatypes,
format_function=format_function,
Expand All @@ -150,7 +150,7 @@ def bool_formatter(
truthy_values=truthy,
falsy_values=falsy,
**kwargs,
) -> dict:
) -> Dict:
return formatter(
datatypes=datatypes,
format_function=format_function,
Expand All @@ -172,7 +172,7 @@ def formatter(
post_format_function=None,
clipboard_function=None,
**kwargs,
) -> dict:
) -> Dict:
return {
**dict(
datatypes=datatypes,
Expand Down Expand Up @@ -311,7 +311,7 @@ def get_clipboard_data(self):
return self.value
return self.__str__()

def __eq__(self, __value: object) -> bool:
def __eq__(self, __value) -> bool:
# in case of custom formatter class
# compare the values
try:
Expand Down
7 changes: 3 additions & 4 deletions tksheet/_tksheet_main_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from math import ceil, floor
from tkinter import TclError
from typing import Any, Union

from ._tksheet_formatters import (
data_to_str,
format_data,
Expand Down Expand Up @@ -336,10 +335,10 @@ def __init__(self, *args, **kwargs):
self.basic_bindings()
self.create_rc_menus()

def refresh(self, event=None) -> None:
def refresh(self, event=None):
self.main_table_redraw_grid_and_text(True, True)

def window_configured(self, event) -> None:
def window_configured(self, event):
w = self.parentframe.winfo_width()
if w != self.parentframe_width:
self.parentframe_width = w
Expand Down Expand Up @@ -3506,7 +3505,7 @@ def set_header_font_help(self):
self.set_min_column_width()
self.CH.set_height(self.default_header_height[1], set_TL=True)

def set_index_font(self, newfont: Union[tuple, None] = None) -> tuple:
def set_index_font(self, newfont=None):
if newfont:
if not isinstance(newfont, tuple):
raise ValueError("Argument must be tuple e.g. ('Carlito', 12, 'normal')")
Expand Down

2 comments on commit 9cd4193

@rdbende
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting with Python 3.7, if you put a from __future__ import annotations statement on the top of the file, these new kinds of type hints will work as they would on Python >= 3.9

@ragardner
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for pointing this out! It seems as though | instead of Union also works for Python 3.7 with from __future__ import annotations, very helpful

Please sign in to comment.