Skip to content

Commit

Permalink
fixes #595 remove tix
Browse files Browse the repository at this point in the history
- replace tix with ttk
  • Loading branch information
glwnd committed Dec 9, 2024
1 parent 3cfd680 commit 89d623e
Showing 1 changed file with 53 additions and 70 deletions.
123 changes: 53 additions & 70 deletions pyglossary/ui/ui_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import tkinter as tk
import traceback
from os.path import abspath, isfile, join, splitext
from tkinter import filedialog, tix, ttk
from tkinter import filedialog, ttk
from tkinter import font as tkFont
from typing import TYPE_CHECKING, Any, Literal

Expand All @@ -39,7 +39,6 @@
licenseText,
logo,
)
from .version import getVersion

if TYPE_CHECKING:
from collections.abc import Callable
Expand Down Expand Up @@ -149,11 +148,11 @@ def newReadOnlyText(
# if tkinter is 8.5 or above you'll want the selection background
# to appear like it does when the widget is activated
# comment this out for older versions of Tkinter
widget.configure(
inactiveselectbackground=widget.cget("selectbackground"),
bg=parent.cget("bg"),
relief="flat",
)
# widget.configure(
# inactiveselectbackground=widget.cget("selectbackground"),
# bg=parent.cget("bg"),
# relief="flat",
# )
return widget


Expand Down Expand Up @@ -206,8 +205,7 @@ def CallWrapper__call__(self, *args):
tk.CallWrapper.__call__ = CallWrapper__call__


class ProgressBar(tix.Frame):

class ProgressBar(ttk.Frame):
"""
Comes from John Grayson's book "Python and Tkinter programming"
Edited by Saeed Rasooli.
Expand Down Expand Up @@ -243,8 +241,8 @@ def __init__( # noqa: PLR0913
self.background = background
self.labelFormat = labelFormat
self.value = value
tix.Frame.__init__(self, rootWin, relief=appearance, bd=bd)
self.canvas = tix.Canvas(
ttk.Frame.__init__(self, rootWin, relief=appearance)
self.canvas = tk.Canvas(
self,
height=height,
width=width,
Expand Down Expand Up @@ -315,7 +313,7 @@ def update(self, event=None, labelText=""): # noqa: ARG002
self.canvas.update_idletasks()


class FormatDialog(tix.Toplevel):
class FormatDialog(tk.Toplevel):
def __init__( # noqa: PLR0913
self,
descList: list[str],
Expand All @@ -324,7 +322,7 @@ def __init__( # noqa: PLR0913
button: FormatButton,
activeDesc: str = "",
) -> None:
tix.Toplevel.__init__(self)
tk.Toplevel.__init__(self)
# bg="#0f0" does not work
self.descList = descList
self.items = self.descList
Expand Down Expand Up @@ -391,7 +389,7 @@ def __init__( # noqa: PLR0913

self.updateTree()

buttonBox = tix.Frame(master=self)
buttonBox = tk.Frame(master=self)

cancelButton = newButton(
buttonBox,
Expand Down Expand Up @@ -556,7 +554,7 @@ def onClick(self):
dialog.focus()


class FormatOptionsDialog(tix.Toplevel):
class FormatOptionsDialog(tk.Toplevel):
commentLen = 60
kindFormatsOptions = {
"Read": Glossary.formatsReadOptions,
Expand All @@ -570,7 +568,7 @@ def __init__(
values,
master=None, # noqa: ARG002
) -> None:
tix.Toplevel.__init__(self)
tk.Toplevel.__init__(self)
# bg="#0f0" does not work
self.resizable(width=True, height=True)
self.title(kind + " Options")
Expand All @@ -586,7 +584,7 @@ def __init__(

self.createOptionsList()

buttonBox = tix.Frame(self)
buttonBox = tk.Frame(self)
okButton = newButton(
buttonBox,
text=" OK ",
Expand Down Expand Up @@ -665,7 +663,7 @@ def valueMenuItemCustomSelected(

value = treev.set(optName, self.valueCol)

dialog = tix.Toplevel(master=treev) # bg="#0f0" does not work
dialog = tk.Toplevel(master=treev) # bg="#0f0" does not work
dialog.resizable(width=True, height=True)
dialog.title(optName)
set_window_icon(dialog)
Expand All @@ -683,7 +681,7 @@ def valueMenuItemCustomSelected(
),
)

frame = tix.Frame(master=dialog)
frame = ttk.Frame(master=dialog)

label = tk.Label(master=frame, text="Value for " + optName)
label.pack()
Expand Down Expand Up @@ -912,20 +910,20 @@ def buttonClicked(self):
dialog.focus()


class UI(tix.Frame, UIBase):
class UI(tk.Frame, UIBase):
fcd_dir_save_path = join(confDir, "ui-tk-fcd-dir")

def __init__(
self,
progressbar: bool = True,
) -> None:
rootWin = self.rootWin = tix.Tk()
rootWin = self.rootWin = tk.Tk()
# a hack that hides the window until we move it to the center of screen
if os.sep == "\\": # Windows
rootWin.attributes("-alpha", 0.0)
else: # Linux
rootWin.withdraw()
tix.Frame.__init__(self, rootWin)
tk.Frame.__init__(self, rootWin)
UIBase.__init__(self)
rootWin.title("PyGlossary (Tkinter)")
rootWin.resizable(True, False)
Expand Down Expand Up @@ -966,12 +964,8 @@ def __init__(
log.exception("")
self.fcd_dir = fcd_dir
######################
notebook = tix.NoteBook(self)
notebook.add("tabConvert", label="Convert", underline=0)
# notebook.add("tabReverse", label="Reverse", underline=0)
notebook.add("tabAbout", label="About", underline=0)
convertFrame = tix.Frame(notebook.tabConvert)
aboutFrame = tix.Frame(notebook.tabAbout)
notebook = ttk.Notebook(self)
convertFrame = tk.Frame(notebook, height=200)
###################
row = 0
label = tk.Label(convertFrame, text="Input File: ")
Expand All @@ -982,7 +976,7 @@ def __init__(
padx=5,
)
##
entry = tix.Entry(convertFrame)
entry = ttk.Entry(convertFrame)
entry.grid(
row=row,
column=1,
Expand Down Expand Up @@ -1090,7 +1084,7 @@ def __init__(
padx=5,
)
##
entry = tix.Entry(convertFrame)
entry = ttk.Entry(convertFrame)
entry.grid(
row=row,
column=1,
Expand Down Expand Up @@ -1142,7 +1136,7 @@ def __init__(
# convertFrame.grid(sticky=tk.W + tk.E + tk.N + tk.S)
#################
row += 1
console = tix.Text(
console = tk.Text(
convertFrame,
height=15,
background="#000",
Expand Down Expand Up @@ -1172,49 +1166,42 @@ def __init__(
####
self.console = console
##################
aboutFrame2 = tix.Frame(aboutFrame)
##
label = newLabelWithImage(aboutFrame2, file=logo)
label.pack(side="left")
##
##
label = tk.Label(aboutFrame2, text=f"PyGlossary\nVersion {getVersion()}")
label.pack(side="left")
# aboutFrame2 = ttk.Frame(aboutFrame)
##
aboutFrame2.pack(side="top", fill="x")
# label = newLabelWithImage(aboutFrame2, file=logo)
# label.pack(side="left")
# ##
# ##
# label = tk.Label(aboutFrame2, text=f"PyGlossary\nVersion {getVersion()}")
# label.pack(side="left")
# ##
# aboutFrame2.pack(side="top", fill="x")
##
style = ttk.Style(self)
style.configure("TNotebook", tabposition="wn")
# ws => to the left (west) and to the bottom (south)
# wn => to the left (west) and at top
aboutNotebook = ttk.Notebook(aboutFrame, style="TNotebook")
# aboutNotebook = tix.Notebook(aboutFrame)
# style = ttk.Style(self)
# style.configure("TNotebook", tabposition="wn")
# # ws => to the left (west) and to the bottom (south)
# # wn => to the left (west) and at top
# aboutNotebook = ttk.Notebook(aboutFrame, style="TNotebook")
# # aboutNotebook = tk.Notebook(aboutFrame)

aboutFrame3 = tk.Frame(aboutNotebook)
authorsFrame = tk.Frame(aboutNotebook)
licenseFrame = tk.Frame(aboutNotebook)
# aboutFrame3 = tk.Frame(notebook)
# authorsFrame = tk.Frame(notebook)
# licenseFrame = tk.Frame(notebook)

# tabImg = tk.PhotoImage(file=join(dataDir, "res", "dialog-information-22.png"))
# tabImg = tk.PhotoImage(file=join(dataDir, "res", "author-22.png"))
#
aboutFrame = ttk.Frame(notebook)
authorsFrame = ttk.Frame(notebook)
licenseFrame = ttk.Frame(notebook)

aboutNotebook.add(
aboutFrame3,
text="\n About \n",
# image=tabImg, # not working
# compound=tk.TOP,
# padding=50, # not working
)
aboutNotebook.add(
authorsFrame,
text="\nAuthors\n",
)
aboutNotebook.add(
licenseFrame,
text="\nLicense\n",
)
notebook.add(convertFrame, text="Convert", underline=0)
notebook.add(authorsFrame, text="Authors", underline=0)
notebook.add(licenseFrame, text="License", underline=0)
notebook.add(aboutFrame, text="About", underline=0)

label = newReadOnlyText(
aboutFrame3,
aboutFrame,
text=f"{aboutText}\nHome page: {core.homePage}",
font=("DejaVu Sans", 11, ""),
)
Expand All @@ -1236,10 +1223,6 @@ def __init__(
)
label.pack(fill="x")

aboutNotebook.pack(fill="x")

aboutFrame.pack(fill="x")

######################
tk.Grid.columnconfigure(convertFrame, 0, weight=1)
tk.Grid.columnconfigure(convertFrame, 1, weight=30)
Expand Down Expand Up @@ -1288,7 +1271,7 @@ def __init__(
4,
5,
)
comboVar.trace("w", self.verbosityChanged)
comboVar.trace_add("write", self.verbosityChanged)
combo.pack(side="left")
self.verbosityCombo = comboVar
comboVar.set(log.getVerbosity())
Expand Down

0 comments on commit 89d623e

Please sign in to comment.