Skip to content

Commit

Permalink
header font bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ragardner committed May 16, 2023
1 parent 4a1dbaf commit 933b032
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
### Version 6.1.4
#### Fixed:
- Error with setting/getting header font
- Setting fonts with `set_options()` not working
- Setting fonts after table initialization didn't refresh selection boxes or top left rectangle dimensions

#### Changed:
- Replaced wildcard imports
- Format code with 120 line length
Expand Down
10 changes: 5 additions & 5 deletions tksheet/_tksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,10 +2117,10 @@ def row_index_align(self, align: str = None, redraw=True):
self.set_refresh_timer(redraw)

def font(self, newfont=None, reset_row_positions=True):
self.MT.font(newfont, reset_row_positions=reset_row_positions)
return self.MT.set_table_font(newfont, reset_row_positions=reset_row_positions)

def header_font(self, newfont=None):
self.MT.header_font(newfont)
return self.MT.set_header_font(newfont)

def set_options(self, redraw=True, **kwargs):
if "to_clipboard_delimiter" in kwargs:
Expand Down Expand Up @@ -2242,11 +2242,11 @@ def set_options(self, redraw=True, **kwargs):
if "max_index_width" in kwargs:
self.MT.max_index_width = float(kwargs["max_index_width"])
if "font" in kwargs:
self.MT.font(kwargs["font"])
self.MT.set_table_font(kwargs["font"])
if "header_font" in kwargs:
self.MT.header_font(kwargs["header_font"])
self.MT.set_header_font(kwargs["header_font"])
if "index_font" in kwargs:
self.MT.index_font(kwargs["index_font"])
self.MT.set_index_font(kwargs["index_font"])
if "theme" in kwargs:
self.change_theme(kwargs["theme"])
if "show_selected_cells_border" in kwargs:
Expand Down
2 changes: 1 addition & 1 deletion tksheet/_tksheet_column_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def set_height(self, new_height, set_TL=False):
self.config(height=new_height)
except Exception:
return
if set_TL:
if set_TL and self.TL is not None:
self.TL.set_dimensions(new_h=new_height)

def enable_bindings(self, binding):
Expand Down
58 changes: 36 additions & 22 deletions tksheet/_tksheet_main_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,6 @@ def __init__(self, *args, **kwargs):
self.row_options = {}
self.options = {}

"""
cell options dict looks like:
{(row int, column int): {'dropdown': {'values': values,
'window': "no dropdown open",
'select_function': selection_function,
'keypress_function': keypress_function,
'state': state},
'highlight: (bg, fg),
'align': "e",
'readonly': True,
'format': {}
}
"""
self.arrowkey_binding_functions = {
"tab": self.tab_key,
"up": self.arrowkey_UP,
Expand Down Expand Up @@ -196,7 +183,8 @@ def __init__(self, *args, **kwargs):
self.select_all_binding_func = None

self.single_selection_enabled = False
self.toggle_selection_enabled = False # with this mode every left click adds the cell to selected cells
# with this mode every left click adds the cell to selected cells
self.toggle_selection_enabled = False
self.show_dropdown_borders = kwargs["show_dropdown_borders"]
self.drag_selection_enabled = False
self.select_all_enabled = False
Expand Down Expand Up @@ -3420,7 +3408,7 @@ def set_min_column_width(self):
if self.min_column_width > self.default_column_width:
self.default_column_width = self.min_column_width + 20

def font(self, newfont=None, reset_row_positions=False):
def set_table_font(self, newfont=None, reset_row_positions=False):
if newfont:
if not isinstance(newfont, tuple):
raise ValueError("Argument must be tuple e.g. ('Carlito',12,'normal')")
Expand All @@ -3437,6 +3425,7 @@ def font(self, newfont=None, reset_row_positions=False):
self.set_font_help()
if reset_row_positions:
self.reset_row_positions()
self.recreate_all_selection_boxes()
else:
return self.table_font

Expand All @@ -3461,7 +3450,7 @@ def set_font_help(self):
)
self.set_min_column_width()

def header_font(self, newfont=None):
def set_header_font(self, newfont=None):
if newfont:
if not isinstance(newfont, tuple):
raise ValueError("Argument must be tuple e.g. ('Carlito', 12, 'normal')")
Expand All @@ -3476,6 +3465,7 @@ def header_font(self, newfont=None):
self.header_font_sze = newfont[1]
self.header_font_wgt = newfont[2]
self.set_header_font_help()
self.recreate_all_selection_boxes()
else:
return self.header_font

Expand All @@ -3496,10 +3486,34 @@ def set_header_font_help(self):
else self.default_header_height[1],
)
self.set_min_column_width()
self.CH.set_height(self.default_header_height[1])
self.CH.set_height(self.default_header_height[1], set_TL=True)

def set_index_font(self, newfont: Union[tuple, None] = None) -> tuple:
if newfont:
if not isinstance(newfont, tuple):
raise ValueError("Argument must be tuple e.g. ('Carlito', 12, 'normal')")
if len(newfont) != 3:
raise ValueError("Argument must be three-tuple")
if not isinstance(newfont[0], str) or not isinstance(newfont[1], int) or not isinstance(newfont[2], str):
raise ValueError(
"Argument must be font, size and 'normal', 'bold' or" "'italic' e.g. ('Carlito',12,'normal')"
)
self.index_font = newfont
self.index_font_fam = newfont[0]
self.index_font_sze = newfont[1]
self.index_font_wgt = newfont[2]
self.set_index_font_help()
return self.index_font

def set_index_font_help(self):
pass
self.index_txt_width, self.index_txt_height = self.get_txt_dimensions("|", self.index_font)
self.index_half_txt_height = ceil(self.index_txt_height / 2)
if self.index_half_txt_height % 2 == 0:
self.index_first_ln_ins = self.index_half_txt_height + 2
else:
self.index_first_ln_ins = self.index_half_txt_height + 3
self.index_xtra_lines_increment = self.index_txt_height
self.min_index_width = 5

def data_reference(
self,
Expand Down Expand Up @@ -6742,10 +6756,10 @@ def get_valid_cell_data_as_str(self, datarn, datacn, get_displayed=False, **kwar
return f"{get_data_with_valid_check(value, **kwargs)}"
else:
if get_displayed:
# assumed given formatter class has __str__() function
# assumed given formatter class has __str__() function
return f"{value}"
else:
# assumed given formatter class has get_data_with_valid_check() function
# assumed given formatter class has get_data_with_valid_check() function
return f"{value.get_data_with_valid_check()}"
return "" if value is None else f"{value}"

Expand Down Expand Up @@ -6789,8 +6803,8 @@ def get_cell_clipboard(self, datarn, datacn) -> Union[str, int, float, bool]:
if kwargs["formatter"] is None:
return get_clipboard_data(value, **kwargs)
else:
# assumed given formatter class has get_clipboard_data()
# function and it returns one of above type hints
# assumed given formatter class has get_clipboard_data()
# function and it returns one of above type hints
return value.get_clipboard_data()
return f"{value}"

Expand Down

0 comments on commit 933b032

Please sign in to comment.