aboutsummaryrefslogtreecommitdiff
path: root/widgets.py
diff options
context:
space:
mode:
Diffstat (limited to 'widgets.py')
-rw-r--r--widgets.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/widgets.py b/widgets.py
new file mode 100644
index 0000000..afc715a
--- /dev/null
+++ b/widgets.py
@@ -0,0 +1,97 @@
+
+from tkinter import *
+from tkinter import messagebox
+from PIL import ImageTk, Image
+
+import os
+os.chdir('assets')
+HOME = os.getcwd()
+
+global USERNAME
+USERNAME = ""
+
+
+class ContentBox(Frame):
+ def __init__(self, master, image_file, *pargs):
+ Frame.__init__(self, master, *pargs)
+
+ self.background = Canvas(self, highlightthickness=0)
+ self.background.pack(fill=BOTH, expand=YES)
+ self.background.bind('<Configure>', self._resize_image)
+
+ self.image = Image.open(image_file)
+ self.img_copy = self.image.copy()
+ self.background_image = ImageTk.PhotoImage(self.image)
+ self.image_id = self.background.create_image(0, 0, image=self.background_image, anchor='nw')
+
+ def set(self, image_file):
+ self.image = Image.open(image_file)
+ self.img_copy = self.image.copy()
+ self.image = self.img_copy.resize((self.background.winfo_width(),
+ self.background.winfo_height()))
+ self.background_image = ImageTk.PhotoImage(self.image)
+ self.background.itemconfigure(self.image_id, image=self.background_image)
+
+ def _resize_image(self, event):
+ self.image = self.img_copy.resize((event.width, event.height))
+ self.background_image = ImageTk.PhotoImage(self.image)
+ self.background.itemconfigure(self.image_id, image=self.background_image)
+
+
+class ButtonMenu(Frame):
+ def __init__(self, master, *pargs):
+ Frame.__init__(self, master, *pargs)
+ self.place(relx=0.5, rely=0.85, anchor=CENTER)
+ def additem(self, name, command):
+ Button(self, text=name, command=command, font=('', 12, 'bold'),
+ height=2, width=16, borderwidth=0,
+ background='black', foreground='white').pack(side=LEFT)
+
+
+class StatusBar(Frame):
+ def __init__(self, master, msgvar, *pargs):
+ self.bgcolor='#fdcc03'
+ self.fgcolor='black'
+ self.msgfont=('', 12)
+ self.optfont=('monospace', 12, 'bold')
+ Frame.__init__(self, master, background=self.bgcolor, *pargs)
+ self.message = Label(self, textvariable=msgvar, background=self.bgcolor, font=self.msgfont, foreground=self.fgcolor)
+ global USERNAME
+ self.username = Label(self, text=USERNAME, font=self.msgfont, background=self.bgcolor, foreground=self.fgcolor)
+ self.username.pack(side=LEFT)
+ self.message.pack(side=LEFT, fill=X, expand=TRUE)
+ def addmenu(self, optvar, opts, command=None):
+ self.menu = OptionMenu(self, optvar, *opts, command=command)
+ self.menu.config(width=12, borderwidth=0, font=self.optfont,
+ background=self.bgcolor, foreground='darkblue',
+ highlightthickness=0)
+ self.menu.pack(side=RIGHT)
+
+
+class SearchBox(Frame):
+ def __init__(self, master, search, command, *pargs):
+ Frame.__init__(self, master, background='white', *pargs)
+
+ self.placeholder = " 🔍 Search ... "
+ self.search = search
+ self.searchbox = Entry(self, textvariable=self.search, borderwidth=0, highlightthickness=0)
+ self.searchbox.pack(fill=BOTH, expand=TRUE, padx=10, pady=5)
+ self.searchbox.bind('<Key>', command)
+ def erase_placeholder(event=None):
+ if self.search.get() == self.placeholder:
+ self.searchbox.delete(0, END)
+ self.searchbox.configure(fg='black')
+ def set_placeholder(event=None):
+ if self.search.get() == "":
+ self.searchbox.insert(0, self.placeholder)
+ self.searchbox.configure(fg='grey')
+ set_placeholder()
+ self.searchbox.bind("<FocusIn>", erase_placeholder)
+ self.searchbox.bind("<FocusOut>", set_placeholder)
+ self.searchbox.bind('<Escape>', lambda event: self.master.focus_set())
+ self.master.bind('<Control-f>', lambda event: self.searchbox.focus())
+ self.master.focus_set()
+
+ def findtxt(self, event=None):
+ self.searchbox.focus()
+