Post by Uncle Buddy on Nov 25, 2022 18:11:33 GMT -8
<drive>:\treebard_gps\app\python\utes.py Last Changed 2022-12-03
# utes.py
import tkinter as tk
import dev_tools as dt
from dev_tools import looky, seeline
def stop_flashing(dlg, scrollbar_width=None):
""" Call when configuring scrollregion if flashing occurs for tiny
images. Doesn't always work if called after configuring scrollregion,
seems more reliable when called before. This was done because the
other way to stop the flashing is to drag the dialog any distance.
"""
dlg.update_idletasks()
size, position = dlg.geometry().split("+", 1)
w, h = size.split("x")
x, y = position.split("+")
if scrollbar_width:
dlg.geometry("{}x{}+{}+{}".format(
str(int(w)+scrollbar_width), h, x, str(int(y)+1)))
else:
dlg.geometry("{}x{}+{}+{}".format(w, h, x, str(int(y)+1)))
def split_sorter(date):
""" Create date sorter. """
sorter = date.split(",")
date = [int(i) for i in sorter]
return date
# capitalizE righT
def titlize(stg):
'''
function by Yugal Jindle. Python's `title()` method doesn't work right
if there are apostrophes etc. in the word, since it breaks words at
punctuation. According to https://bugs.python.org/issue7008, the
`string.capwords()` method is also buggy and should be deprecated. This
is to make "Linda's Tree" not be "Linda'S Tree".
'''
lst = []
for temp in stg.split(" "): lst.append(temp.capitalize())
return ' '.join(lst)
# CENTERING
def center_dialog(dlg, frame=None):
if frame:
dlg.update_idletasks()
win_width = frame.winfo_reqwidth()
win_height = frame.winfo_reqheight()
right_pos = int(dlg.winfo_screenwidth()/2 - win_width/2)
down_pos = int(dlg.winfo_screenheight()/2 - win_height/2)
else:
dlg.update_idletasks()
win_width = dlg.winfo_reqwidth()
win_height = dlg.winfo_reqheight()
right_pos = int(dlg.winfo_screenwidth()/2 - win_width/2)
down_pos = int(dlg.winfo_screenheight()/2 - win_height/2)
dlg.geometry("+{}+{}".format(right_pos, down_pos))
# # - - - - - - - - - - - - - - - #
# Tkinter keysyms for keys that actually type a character with len(keysym) > 1:
OK_PRINT_KEYS = (
"space",
"parenleft",
"parenright",
"underscore",
"minus",
"asterisk",
"slash",
"period",
"comma",
"equal",
"plus",
"ampersand",
"asciicircum",
"percent",
"dollar",
"numbersign",
"at",
"exclam",
"asciitilde",
"quoteleft",
"bar",
"backslash",
"less",
"greater",
"colon",
"semicolon",
"quotedbl",
"quoteright",
"bracketleft",
"braceleft",
"bracketright",
"braceright",
)