Skip to content

Commit

Permalink
UI: Refactor Main UI to a Base class
Browse files Browse the repository at this point in the history
  • Loading branch information
tks18 committed May 23, 2021
1 parent 6eed8a4 commit 0917ca0
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 72 deletions.
22 changes: 17 additions & 5 deletions app/common/ui/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@


class base_ui:
def __init__(self, window_title, title):
def __init__(self, window_title, title, menu):
self.ui = tk.Tk()
self.ui.title(window_title)
self.ui.config(padx=40, pady=40, bg=BG)
self.icon = tk.PhotoImage(file=resource_path("images/logo.png"))
self.ui.iconphoto(False, self.icon)

self.menuButton = tk.Button(
self.ui, text="Menu", command=self.close_window, fg=FG, bg=BG
)
self.menuButton.grid(row=0, column=0)
if menu:
self.menuButton = tk.Button(
self.ui, text="Menu", command=self.close_window, fg=FG, bg=BG
)
self.menuButton.grid(row=0, column=0)

self.canvas = tk.Canvas(
self.ui, height=200, width=200, highlightthickness=0, bg=BG
)
Expand All @@ -32,6 +34,16 @@ def __init__(self, window_title, title):
self.ui.focus_force()
self.main_title.grid(row=2, column=0, columnspan=4)

self.developer_label_head = tk.Label(
self.ui, text="Developed by", font=("Arial", 10, "bold"), bg=BG, fg=FG
)
self.developer_label_head.grid(row=20, column=0, columnspan=4, pady=(20, 0))

self.developer_label_value = tk.Label(
self.ui, text="Shan.tk", font=("Arial", 9, "bold"), bg=BG, fg=FG
)
self.developer_label_value.grid(row=21, column=0, columnspan=4, pady=(0, 0))

def close_window(self):
self.ui.destroy()

Expand Down
21 changes: 21 additions & 0 deletions app/common/ui/main_ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import tkinter as tk
from app.common.ui.base import base_ui

from app.common.ui.common import BG, FG


class main_window(base_ui):
def __init__(self, window_title, title, buttons, menu):
super(main_window, self).__init__(window_title, title, menu)

utility_label = tk.Label(text="General Utilities", bg=BG, fg=FG)
utility_label.grid(row=3, column=0, columnspan=4)
for btn in buttons["utility_buttons"]:
new_btn = tk.Button(text=btn["title"], bg=BG, fg=FG, command=btn["command"])
new_btn.grid(row=btn["row"], column=btn["column"], pady=10, columnspan=2)

reco_label = tk.Label(text="Reconciliation Utilities", bg=BG, fg=FG)
reco_label.grid(row=5, column=0, columnspan=4)
for btn in buttons["reco_buttons"]:
new_btn = tk.Button(text=btn["title"], bg=BG, fg=FG, command=btn["command"])
new_btn.grid(row=btn["row"], column=btn["column"], pady=10, columnspan=4)
4 changes: 2 additions & 2 deletions app/common/ui/reco.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class gst_reco_ui(base_ui):
def __init__(self, window_title, title, button_commands):
super(gst_reco_ui, self).__init__(window_title, title)
def __init__(self, window_title, title, button_commands, menu):
super(gst_reco_ui, self).__init__(window_title, title, menu)

self.generate_csv_button = tk.Button(
self.ui,
Expand Down
12 changes: 2 additions & 10 deletions app/common/ui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class gst_utils_ui(base_ui):
def __init__(self, window_title, title, commands, start_button):
super(gst_utils_ui, self).__init__(window_title, title)
def __init__(self, window_title, title, commands, start_button, menu):
super(gst_utils_ui, self).__init__(window_title, title, menu)
self.app_generation_mode_label = tk.Label(
self.ui, text="Select App Working Mode", bg=BG, fg=FG
)
Expand Down Expand Up @@ -105,11 +105,3 @@ def __init__(self, window_title, title, commands, start_button):
pady=5,
)
self.app_status_text.grid(row=11, column=0, columnspan=4)

self.developer_label_head = tk.Label(self.ui, text="Developed by", bg=BG, fg=FG)
self.developer_label_head.grid(row=12, column=0, columnspan=4)

self.developer_label_value = tk.Label(
self.ui, text="Shan.tk", font=("Courier New", 12, "bold"), bg=BG, fg=FG
)
self.developer_label_value.grid(row=13, column=0, columnspan=4)
3 changes: 3 additions & 0 deletions app/reco/gstr_9c/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def start_window_app():
window_title="GSTR 9C Reco Utility",
title="GSTR 9C Utility",
button_commands={"generate_csv_cmd": generate_csv},
menu=True,
)

gstr_9c_ui.initialize_engine()

return False
1 change: 1 addition & 0 deletions app/utils/gstr_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ def start_window_app():
"app_processing": set_app_processing_mode,
},
start_button=start_gstr_1_process,
menu=True,
)

gstr_1_ui.ui.protocol("WM_DELETE_WINDOW", initiate_force_close)
Expand Down
1 change: 1 addition & 0 deletions app/utils/gstr_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def start_window_app():
"app_processing": set_app_processing_mode,
},
start_button=start_gstr_2_process,
menu=True,
)

gstr_2_ui.ui.protocol("WM_DELETE_WINDOW", initiate_force_close)
Expand Down
93 changes: 38 additions & 55 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import app.utils.gstr_2 as gstr_2_utils
import app.reco.gstr_9c.main as gstr_9c_utils

from tkinter import *
from app.common.helpers import resource_path
from app.common.ui.main_ui import main_window

BG = "#121212"
FG = "#FFFFFF"
Expand All @@ -12,83 +11,67 @@
def main_ui_window():
global main_ui

main_ui = Tk()
icon = PhotoImage(file=resource_path("images/logo.png"))
main_ui.iconphoto(False, icon)
main_ui.title("GSTR Utils by Shan.tk")
main_ui.config(padx=50, pady=50, bg=BG)

main_ui.focus_force()
main_ui_canvas = Canvas(highlightthickness=0, height=200, width=200, background=BG)
main_ui_canvas.create_image(100, 100, image=icon)
main_ui_canvas.grid(row=0, column=0, columnspan=2)
main_title = Label(
text="GSTR 1 & 2 Utilities",
font=("Courier New", 20, "bold"),
padx=10,
pady=20,
bg=BG,
fg=FG,
)
main_title.grid(row=1, column=0, columnspan=2)

utility_buttons = [
{
"title": "GSTR 1",
"command": open_gstr_1_window,
"row": 3,
"column": 0,
main_ui = main_window(
window_title="GSTR Utils by Shan.tk",
title="GST Utilities",
buttons={
"utility_buttons": [
{
"title": "GSTR 1",
"command": open_gstr_1_window,
"row": 4,
"column": 0,
},
{
"title": "GSTR 2",
"command": open_gstr_2_window,
"row": 4,
"column": 2,
},
],
"reco_buttons": [
{
"title": "GSTR 9C",
"command": open_gstr_9c_window,
"row": 6,
"column": 0,
}
],
},
{"title": "GSTR 2", "command": open_gstr_2_window, "row": 3, "column": 1},
]

utility_label = Label(text="General Utilities", bg=BG, fg=FG)
utility_label.grid(row=2, column=0, columnspan=2)
for btn in utility_buttons:
new_btn = Button(text=btn["title"], bg=BG, fg=FG, command=btn["command"])
new_btn.grid(row=btn["row"], column=btn["column"], pady=10)

reco_buttons = [
{"title": "GSTR 9C", "command": open_gstr_9c_window, "row": 5, "column": 0}
]

reco_label = Label(text="Reconciliation Utilities", bg=BG, fg=FG)
reco_label.grid(row=4, column=0, columnspan=2)
for btn in reco_buttons:
new_btn = Button(text=btn["title"], bg=BG, fg=FG, command=btn["command"])
new_btn.grid(row=btn["row"], column=btn["column"], pady=10)

developer_label = Label(
text="Shan.tk", font=("Courier New", 10, "bold"), bg=BG, fg=FG, padx=10, pady=30
menu=False,
)
developer_label.grid(row=6, column=0, columnspan=2)

main_ui.mainloop()
main_ui.initialize_engine()


def open_gstr_1_window():
global main_ui

main_ui.destroy()
main_ui.close_window()
close_app = gstr_1_utils.start_window_app()
if not close_app:
main_ui = None
main_ui_window()


def open_gstr_2_window():
global main_ui

main_ui.destroy()
main_ui.close_window()
close_app = gstr_2_utils.start_window_app()
if not close_app:
main_ui = None
main_ui_window()


def open_gstr_9c_window():
global main_ui

main_ui.destroy()
gstr_9c_utils.start_window_app()
main_ui.close_window()
close_app = gstr_9c_utils.start_window_app()
if not close_app:
main_ui = None
main_ui_window()


main_ui = None
Expand Down

0 comments on commit 0917ca0

Please sign in to comment.