-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.py
90 lines (69 loc) · 2.78 KB
/
utility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import tkinter as tk
color_yellow = "#FFFFD9"
color_light_green = "#D6F6D6"
color_dark_green = "#008080"
color_orange = "#FFDDCC"
color_grey = "#D0D0D0"
color_red = "#ff4d4d"
color_white = "#FFFFFF"
color_black = "#000000"
initial_bk_file = '''#BUSINESS=Example Business
#CURRENCY=Rs.
#CURRENCY_FORMAT=ind
#NAME=Example User Name
'''
def string_to_int(val):
try:
return int(val)
except ValueError:
return 0
def format_currency(amount, _type, currency):
c = ""
a = abs(amount)
if _type == "ind":
s, *d = str(a).partition(".")
r = ",".join([s[x - 2:x] for x in range(-3, -len(s), -2)][::-1] + [s[-3:]])
c = currency + ("".join([r] + d))
else:
c = currency + ("{:,}".format(a))
if amount < 0:
c = "(" + c + ")"
return c
class Modal:
TYPE_ALERT = 1
TYPE_QUESTION = 2
def __init__(self, parent, message, modal_type):
self.type = modal_type
self.positive_method = None
self.negative_method = None
# modal
self.modal = tk.Frame(parent, background=color_orange, height=200, width=200, highlightbackground=color_red,
highlightthickness=1)
self.modal.place(x=0, rely=1, anchor='sw')
tk.Label(self.modal, text=message, bg=self.modal["background"],
font="arial 12 normal", wraplength=200).place(relx=0.5, rely=0.3, anchor='center')
self.modal.focus()
self.modal.bind("<Return>", lambda event: self.positive_method())
self.modal.bind("<Escape>", lambda event: self.cancel_modal())
self.modal.bind("<Tab>", lambda event: 'break')
if self.type == Modal.TYPE_ALERT:
tk.Button(self.modal, text="Okay", background=self.modal["background"], border=0, font="arial 12 bold",
command=lambda: self.positive_method()).place(relx=0.5, rely=0.9, anchor='center')
elif self.type == Modal.TYPE_QUESTION:
tk.Button(self.modal, text="Yes", background=self.modal["background"], border=0, font="arial 12 bold",
command=lambda: self.positive_method()).place(relx=0.1, rely=0.9, anchor='sw')
tk.Button(self.modal, text="No", background=self.modal["background"], border=0, font="arial 12 bold",
command=lambda: self.negative_method()).place(relx=0.9, rely=0.9, anchor='se')
def destroy(self):
for widget in self.modal.winfo_children():
widget.destroy()
self.modal.destroy()
def cancel_modal(self):
if self.type == Modal.TYPE_QUESTION:
self.negative_method()
else:
self.positive_method()
def set_positive(self, method):
self.positive_method = method
def set_negative(self, method):
self.negative_method = method