Skip to content

Commit

Permalink
Fonts: Remove Custom Fonts Causes Windows Glitch
Browse files Browse the repository at this point in the history
UI: Move UI Files to More Proper Folder Structure
UI: Completely Refactor to Use Custom Elements from base class
Update Imports for all Files
  • Loading branch information
tks18 committed Jul 8, 2021
1 parent ae90817 commit d8b99ac
Show file tree
Hide file tree
Showing 22 changed files with 208 additions and 189 deletions.
11 changes: 0 additions & 11 deletions app/helpers/font_loader.py

This file was deleted.

37 changes: 37 additions & 0 deletions app/helpers/ui/elements/button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from tkinter import Button


def small_button(master, label, command):
new_btn = Button(
master.ui,
text=label,
**master.theme,
command=command,
font=master.FONTS["buttons"]["small"]
)

return new_btn


def medium_button(master, label, command):
new_btn = Button(
master.ui,
text=label,
**master.theme,
command=command,
font=master.FONTS["buttons"]["medium"]
)

return new_btn


def large_button(master, label, command):
new_btn = Button(
master.ui,
text=label,
**master.theme,
command=command,
font=master.FONTS["buttons"]["large"]
)

return new_btn
19 changes: 19 additions & 0 deletions app/helpers/ui/elements/checkbutton.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from tkinter import Checkbutton


def check_btn(master, text, variable, command=None):
new_checkbtn = Checkbutton(
master.ui,
text=text,
variable=variable,
**master.theme,
command=command,
font=master.FONTS["buttons"]["small"],
activebackground=master.bg,
activeforeground=master.fg,
highlightcolor=master.bg,
selectcolor=master.bg,
onvalue=True,
offvalue=False,
)
return new_checkbtn
21 changes: 21 additions & 0 deletions app/helpers/ui/elements/init_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from app.helpers.ui.elements.button import small_button, medium_button, large_button
from app.helpers.ui.elements.label import small_label, medium_label, title_label
from app.helpers.ui.elements.checkbutton import check_btn
from app.helpers.ui.elements.radiobutton import radio_btn


class tk_elements:
def __init__(self):
# Buttons
self.small_btn = small_button
self.medium_btn = medium_button
self.large_btn = large_button

# labels
self.small_lbl = small_label
self.medium_lbl = medium_label
self.title_lbl = title_label

# others
self.check_btn = check_btn
self.radio_btn = radio_btn
18 changes: 18 additions & 0 deletions app/helpers/ui/elements/label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from tkinter import Label


def small_label(master, text, bold):
font_label = "small_bold" if bold else "small"
new_label = Label(master.ui, text=text, **master.theme, font=master.FONTS[font_label])
return new_label


def medium_label(master, text, bold):
font_label = "medium_bold" if bold else "medium"
new_label = Label(master.ui, text=text, **master.theme, font=master.FONTS[font_label])
return new_label


def title_label(master, text):
new_label = Label(master.ui, text=text, **master.theme, font=master.FONTS["title"])
return new_label
15 changes: 15 additions & 0 deletions app/helpers/ui/elements/radiobutton.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from tkinter import Radiobutton


def radio_btn(master, text, variable, value, command):
new_radiobtn = Radiobutton(
master.ui,
text=text,
variable=variable,
value=value,
**master.theme,
selectcolor=master.bg,
font=master.FONTS["buttons"]["small"],
command=command,
)
return new_radiobtn
43 changes: 13 additions & 30 deletions app/helpers/ui/base.py → app/helpers/ui/helpers/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import tkinter as tk
from tkinter import ttk

from app.helpers.utilities.path_helpers import resource_path

from app.helpers.ui.theme_constants import *
from app.helpers.ui.helpers.theme_constants import *
from app.helpers.ui.elements.init_class import tk_elements


class base_ui:
Expand All @@ -18,36 +18,25 @@ def __init__(self, window_title, title, menu, logo, maxcol=4):
self.ui.config(padx=20, pady=20, bg=self.bg)
self.icon = tk.PhotoImage(file=resource_path("images/logo.png"))
self.ui.iconphoto(False, self.icon)
self.elements = tk_elements()

if menu:
self.menu_button = tk.Button(
self.ui,
text="Menu",
command=self.close_window,
**self.theme,
font=self.FONTS["buttons"]["small"],
self.menu_button = self.elements.small_btn(
self, label="Menu", command=self.close_window
)
self.menu_button.grid(
row=0,
column=0,
)

self.about_button = tk.Button(
self.ui,
text="About",
**self.theme,
font=self.FONTS["buttons"]["small"],
self.about_button = self.elements.small_btn(
self, label="About", command=self.close_window
)
self.about_button.grid(row=0, column=1)

self.main_title = tk.Label(
master=self.ui,
text=title,
font=self.FONTS["medium_bold"],
**self.theme,
)
self.ui.focus_force()
self.main_title = self.elements.medium_lbl(self, text=title, bold=True)
self.main_title.grid(row=1, column=0, columnspan=maxcol, pady=(10, 10))
self.ui.focus_force()

if logo:
self.canvas = tk.Canvas(
Expand All @@ -65,21 +54,15 @@ def __init__(self, window_title, title, menu, logo, maxcol=4):
)
self.style.theme_use("gstr_theme")

self.developer_label_head = tk.Label(
self.ui,
text="Developed by",
font=self.FONTS["small_bold"],
**self.theme,
self.developer_label_head = self.elements.small_lbl(
self, text="Developed by", bold=False
)
self.developer_label_head.grid(
row=20, column=0, columnspan=maxcol, pady=(20, 0)
)

self.developer_label_value = tk.Label(
self.ui,
text="Shan.tk",
font=self.FONTS["small_bold"],
**self.theme,
self.developer_label_value = self.elements.small_lbl(
self, text="Shan.tk", bold=True
)
self.developer_label_value.grid(
row=21, column=0, columnspan=maxcol, pady=(0, 0)
Expand Down
28 changes: 28 additions & 0 deletions app/helpers/ui/helpers/theme_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BG = "#121212"
FG = "#FFFFFF"
ACCENT = "#e84545"

THEME = {"background": BG, "foreground": FG}

FONTS = {
"small": ("Arial", 10, "normal"),
"small_bold": ("Arial", 10, "bold"),
"medium": ("Arial", 12, "normal"),
"medium_bold": ("Arial", 12, "bold"),
"title": ("Arial", 25, "bold"),
"buttons": {
"small": ("Arial", 9, "bold"),
"medium": ("Arial", 11, "bold"),
"large": ("Arial", 15, "bold"),
},
}

TTK_THEME = {
"TProgressbar": {
"configure": {
"troughcolor": BG,
"bordercolor": FG,
"background": ACCENT,
}
},
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import tkinter as tk
from app.helpers.ui.base import base_ui
from app.helpers.ui.helpers.base import base_ui


class main_window(base_ui):
Expand All @@ -10,28 +9,22 @@ def __init__(self, window_title, title, buttons, menu):

self.ui.config(padx=60, pady=60)

utility_label = tk.Label(
text="General Utilities", **self.theme, font=self.FONTS["small"]
utility_label = self.elements.small_lbl(
self, text="General Utilities", bold=True
)
utility_label.grid(row=3, column=0, columnspan=4)
for btn in buttons["utility_buttons"]:
new_btn = tk.Button(
text=btn["title"],
**self.theme,
command=btn["command"],
font=self.FONTS["buttons"]["small"]
new_btn = self.elements.small_btn(
self, label=btn["title"], command=btn["command"]
)
new_btn.grid(row=btn["row"], column=btn["column"], pady=10, columnspan=2)

reco_label = tk.Label(
text="Reconciliation Utilities", **self.theme, font=self.FONTS["small"]
reco_label = self.elements.small_lbl(
self, text="Reconciliation Utilities", bold=True
)
reco_label.grid(row=5, column=0, columnspan=4)
for btn in buttons["reco_buttons"]:
new_btn = tk.Button(
text=btn["title"],
**self.theme,
command=btn["command"],
font=self.FONTS["buttons"]["small"]
new_btn = self.elements.small_btn(
self, label=btn["title"], command=btn["command"]
)
new_btn.grid(row=btn["row"], column=btn["column"], pady=10, columnspan=4)
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import tkinter as tk
from app.helpers.ui.base import base_ui
from app.helpers.ui.helpers.base import base_ui


class gst_reco_ui(base_ui):
Expand All @@ -15,31 +14,21 @@ def __init__(self, window_title, title, button_commands):

self.button_commands = button_commands

self.project_init_status = tk.Label(
self.ui,
text="Project: Not Initialized",
**self.theme,
font=self.FONTS["small"],
self.project_init_status = self.elements.small_lbl(
self, text="Project: Not Initialized", bold=False
)
self.project_init_status.grid(row=3, column=0, columnspan=maxcol, pady=(0, 10))

self.project_command_label = tk.Label(
self.ui,
text="Manage Project",
**self.theme,
font=self.FONTS["small"],
self.project_command_label = self.elements.small_lbl(
self, text="Manage Project", bold=False
)
self.project_command_label.grid(row=4, column=0, columnspan=maxcol)

self.project_command_buttons = {}
for buttons in button_commands["project_commands"]:
for (button_key, button_props) in buttons.items():
self.project_command_buttons[button_key] = tk.Button(
self.ui,
text=button_key,
command=button_props["command"],
font=self.FONTS["small_bold"],
**self.theme,
self.project_command_buttons[button_key] = self.elements.small_btn(
self, label=button_key, command=button_props["command"]
)
self.project_command_buttons[button_key].grid(
row=button_props["row"],
Expand All @@ -48,12 +37,10 @@ def __init__(self, window_title, title, button_commands):
pady=5,
padx=5,
)
self.reset_button = tk.Button(
self.ui,
text=button_commands["reset_button"]["title"],
self.reset_button = self.elements.small_btn(
self,
label=button_commands["reset_button"]["title"],
command=button_commands["reset_button"]["command"],
**self.theme,
font=self.FONTS["small_bold"],
)
self.reset_button.grid(
row=button_commands["reset_button"]["row"],
Expand All @@ -62,12 +49,10 @@ def __init__(self, window_title, title, button_commands):
)
self.reset_button.grid_remove()

self.start_button = tk.Button(
self.ui,
text=button_commands["start_button"]["title"],
self.start_button = self.elements.medium_btn(
self,
label=button_commands["start_button"]["title"],
command=button_commands["start_button"]["command"],
**self.theme,
font=self.FONTS["buttons"]["medium"],
)
self.start_button.grid(
row=button_commands["start_button"]["row"],
Expand Down
Loading

0 comments on commit d8b99ac

Please sign in to comment.