Example #1
0
def login(username, password, window, remember):
    if username == '' or password == '':
        messagebox.showerror("Error", "Please fill in all the fields")
    else:
        data = server_local.get_user(username)
        if not data:
            messagebox.showerror("Error", "Invalid username or password")
        else:
            if data['Password'] != password:
                messagebox.showerror("Error", "Invalid username or password")
            else:
                if database_local.get_setting('username') != username:
                    try:
                        database_local.create_and_drop_table()
                        database_local.set_setting('username', username)

                        if os.path.isfile(f'images/profile_image/{username}_profile.jpeg'):
                            database_local.set_setting('profile_image', f"{username}_profile.jpeg")
                        else:
                            database_local.set_setting('profile_image', 'default_profile_image.jpeg')
                    except Exception as e:
                        pass

                if remember.get() == 1:
                    database_local.set_setting('remember', 'True')
                else:
                    database_local.set_setting('remember', 'False')

                window.destroy()
                view.default()
Example #2
0
def send_message(message, contact, page):
    page.destroy()
    if str(message).strip() == '':
        view.click(contact)
    else:
        now = datetime.datetime.now()
        server_local.send_message(message, contact[1], now, database_local.get_setting('username'))
        database_local.add_message(message, contact[1], now)
        view.click(contact)
Example #3
0
def change_status(current_status,new_status):
    if current_status == new_status:
        messagebox.showerror("Error", "New status is the same as old status")
    else:
        if len(new_status) > 60:
            messagebox.showerror("Error", "New status is too long")
        else:
            if server_local.change_status(database_local.get_setting('username'), new_status):
                messagebox.showinfo("Success", "Successfully Changed Your Status")
            else:
                messagebox.showerror("Failed", "Sorry! Failed to change your status, Please try again")
Example #4
0
def change_password(password, retype_password):
    if password != retype_password:
        messagebox.showerror("Error", "Password and re-type password does not match")
    else:
        if len(password) < 6:
            messagebox.showerror("Error", "Password should be atleast six characters long")
        else:
            if server_local.change_password(database_local.get_setting('username'), password):
                messagebox.showinfo("Success", "Successfully Changed Your Password")
            else:
                messagebox.showerror("Failed", "Sorry! Failed to change your password, Please try again")
Example #5
0
def add_contact(contact, window):
    if str(contact).strip() == '':
        messagebox.showerror("Error", "Please enter a username or email")
    else:
        if contact == database_local.get_setting('username'):
            messagebox.showerror("Error", "You cannot add yourself")
        else:
            if database_local.get_user(contact):
                messagebox.showerror("Error", "User already in contacts")
            else:
                if not server_local.get_contact(contact):
                    messagebox.showerror("Error", "No such user")
                else:
                    user = server_local.get_contact(contact)[0]
                    database_local.add_user((user[0], user[1], user[2], user[3], user[5]))

                    window.destroy()
                    view.default()
def default(query=''):
    user = db.get_setting('username')
    n = server_local.get_user(user)

    root = Tk()
    root.state("zoomed")
    root.title("Home Page")
    root.configure(background="#ECE5DD")
    root.iconbitmap('images/logo.ico')

    fra = Frame(root, bg="#25D366", width=2000, height=100)
    fra.place(relx=0.00001, rely=0.0000001)

    if query != '':
        backimg = Image.open('images/back.webp')
        backimage = backimg.resize((50, 50), Image.ANTIALIAS)
        openbackimage = ImageTk.PhotoImage(backimage, master=fra)

        backbutton = Button(fra, image=openbackimage, command=lambda: [root.destroy(), default()])

        backbutton["border"] = "0"
        backbutton["bg"] = "#25D366"
        backbutton.place(relx=0.02, rely=0.4, anchor=CENTER)
        backbutton.image = openbackimage

    else:
        pass

    Label(fra, text="HOME", bg="#25D366", fg="white", font=('Helvetica', 25, 'bold')).place(relx=0.32, rely=0.3)

    menuimg = Image.open('images/menu.webp')
    menuimageopen = menuimg.resize((50, 50), Image.ANTIALIAS)
    openmenuimage = ImageTk.PhotoImage(menuimageopen, master=root)

    button1 = Button(fra, bg='#25D366', image=openmenuimage,
                     command=lambda: [root.destroy(), settings()])
    button1.place(relx=0.65, rely=0.5, anchor=CENTER)
    button1.image = openmenuimage

    button1['border'] = 0

    Button(fra, text="Logout", width=10, bg="#075E54", fg="white",
           command=lambda: [db.set_setting('remember', 'False'), root.destroy(),
                            login()]).place(relx=0.55, rely=0.4)

    backimg = Image.open('images/home.png')
    backimage = backimg.resize((50, 50), Image.ANTIALIAS)
    openbackimage = ImageTk.PhotoImage(backimage, master=fra)

    homebutton = Label(fra, image=openbackimage, bg='#25D366')
    homebutton.place(relx=0.29, rely=0.3)

    username = Label(root, font=('Kalpurush', 20, 'bold'), text=f"{user}", bg="#ECE5DD", fg="#075E54")
    username.place(relx=0.5, rely=0.3, anchor=N)

    status = n['Status']

    statusLabel = Label(root,font=('Kalpurush',12,'bold'),text=status,bg='#ECE5DD',fg='#075E54')
    statusLabel.place(relx=0.425,rely=0.35)

    # x = n['ProfilePicture']
    x = db.get_setting('profile_image')

    userimg = Image.open(f'images/profile_image/{x}')
    userimage = userimg.resize((50, 50), Image.ANTIALIAS)
    openuserimage = ImageTk.PhotoImage(userimage, master=root)

    buttonforuserimage = Button(root, image=openuserimage, bg="#ECE5DD",command=lambda: [updateprofilepic(user, root)])

    buttonforuserimage["border"] = "0"
    buttonforuserimage["bg"] = "#ECE5DD"
    buttonforuserimage.place(relx=0.5, rely=0.24, anchor=CENTER)
    buttonforuserimage.image = openuserimage

    pathVar = StringVar()
    searchbar = Entry(root, bg="pink", fg="blue", justify="center", borderwidth=3, textvariable=pathVar)
    searchbar.place(relx=0.5, rely=0.4, width=250, anchor=CENTER)
    searchbar.bind('<KeyPress>', lambda event: [on_keypress(event.char, root, searchbar.get())])
    searchbar.focus()

    mainframe = Frame(root, bg="#ECE5DD")

    if query != '':
        mainframe.grid(row=18, column=10, rowspan=20, columnspan=5, padx=500, pady=300)
        searchbar.delete(0, END)
        searchbar.insert(0, query)
    else:
        mainframe.grid(row=18, column=10, rowspan=20, columnspan=5, padx=500, pady=300)
    canvas = Canvas(mainframe, height=375, bg="#ECE5DD")

    frame = Frame(canvas, bg="#ECE5DD")

    scroll_y = Scrollbar(mainframe, orient="vertical", command=canvas.yview)

    row = 8

    contacts_image = Image.open('images/add_contacts.png')
    add_contacts_image = contacts_image.resize((80, 80), Image.ANTIALIAS)
    open_add_contacts_image = ImageTk.PhotoImage(add_contacts_image, master=root)

    buttonadd_contact = Button(root, image=open_add_contacts_image, bg="#ECE5DD", command=lambda: [root.destroy(), add_contact()])

    buttonadd_contact["border"] = "0"
    buttonadd_contact["bg"] = "#ECE5DD"
    buttonadd_contact.place(relx=0.7, rely=0.9, anchor=CENTER)
    buttonadd_contact.image = open_add_contacts_image

    contactcount = 0

    if query == '':

        contacts = db.get_all_contacts()
    else:
        contacts = db.search_user(query)

    for contact in contacts:

        Button(frame, bg="#34B7F1", text=f"{contact[1]}\t\t {contact[3]}", width=48, height=2,
               anchor="center", justify="center", command=lambda c=contact: [root.destroy(), click(c)]).grid(row=row, column=4)

        img = Image.open(f'images/profile_image/{contact[4]}')

        image = img.resize((30, 30), Image.ANTIALIAS)
        openimg = ImageTk.PhotoImage(image, master=root)

        conbi = Button(frame, image=openimg, command=lambda c = contact : openimage(c[4],c[1]))

        conbi.grid(row=row, column=3)
        conbi.image = openimg
        contactcount += 1
        row += 1

    if len(contacts) == 0:
        Button(frame, text="No results found !!", bg='yellow', width=60, justify='center').grid(row=5, column=4)

    searchimage = Image.open('images/search.png')
    searchimageopen = searchimage.resize((20, 20), Image.ANTIALIAS)
    opensearchimage = ImageTk.PhotoImage(searchimageopen, master=root)

    button1 = Button(root, image=opensearchimage, command=lambda: [default()])
    button1.place(relx=0.6, rely=0.4, anchor=CENTER)
    button1.image = opensearchimage

    canvas.create_window(0, 0, anchor='nw', window=frame)

    canvas.update_idletasks()

    canvas.configure(scrollregion=canvas.bbox('all'), yscrollcommand=scroll_y.set)

    canvas.grid(row=18, column=12, columnspan=2, rowspan=2,pady=7)
    scroll_y.grid(row=18, column=14, rowspan=2, sticky='ns')

    root.mainloop()
def settings(user=db.get_setting('username')):
    s = Tk()
    s.state('zoomed')
    s.title('Settings')
    s.configure(background='#ECE5DD')

    print(server_local.get_user(user))

    s.iconbitmap('images/logo.ico')

    userdetails = server_local.get_user(user)

    frame = Frame(s,bg="#25D366",width=2000,height=100)
    frame.place(relx=0.00001,rely=0.0000001)

    Label(frame,text="SETTINGS",bg="#25D366",fg="white",font=('Helvetica',15,'bold')).place(relx=0.32,rely=0.25)

    backimg = Image.open('images/back.webp')
    backimage = backimg.resize((50, 50), Image.ANTIALIAS)
    openbackimage = ImageTk.PhotoImage(backimage, master=frame)

    backbutton = Button(frame, image=openbackimage,command=lambda: [s.destroy(), default()] )

    backbutton["border"] = "0"
    backbutton["bg"] = "#25D366"
    backbutton.place(relx=0.02, rely=0.4, anchor=CENTER)
    backbutton.image = openbackimage

    x = userdetails['ProfilePicture']

    print(x)

    userimg = Image.open(f'images/profile_image/{x}')
    userimage = userimg.resize((50, 50), Image.ANTIALIAS)
    openuserimage = ImageTk.PhotoImage(userimage, master=s)

    buttonforuserimage = Button(s, image=openuserimage)

    buttonforuserimage["border"] = "0"
    buttonforuserimage["bg"] = "#ECE5DD"
    buttonforuserimage.place(relx=0.5, rely=0.24, anchor=CENTER)
    buttonforuserimage.image = openuserimage

    Label(s, text=f"{user}", bg='#ECE5DD', fg='#075E54', font=('Kalpurush', 20, 'bold')).place(relx=0.45, rely=0.3)

    b = Button(s,text='Change your Password',bg="#ECE5DD",fg="#075E54",font=('Kalpurush', 20, 'bold'),width=90,relief='flat',anchor='w', command = lambda : [s.destroy(),changepassword(user)])
    b.place(relx=0.04,rely=0.4)

    menuimg = Image.open('images/password.jpg')
    menuimageopen = menuimg.resize((50, 50), Image.ANTIALIAS)
    openmenuimage = ImageTk.PhotoImage(menuimageopen, master=s)

    button1 = Button(s, bg="#ECE5DD", image=openmenuimage, anchor = 'w',command= lambda : [s.destroy(),changepassword(user)])
    button1.place(relx=0.02, rely=0.45, anchor=CENTER)
    button1.image = openmenuimage

    b = Button(s,text='Change your Profile Picture',bg="#ECE5DD",fg="#075E54",font=('Kalpurush', 20, 'bold'),width=90,relief='flat',anchor='w')#command = lambda : [s.destroy(),updateprofilepic(user)])
    b.place(relx=0.00001,rely=0.5)

    b = Button(s,text='Change the Theme',bg="#ECE5DD",fg="#075E54",font=('Kalpurush', 20, 'bold'),width=90,relief='flat',anchor='w', command = lambda : [s.destroy(),changetheme()])
    b.place(relx=0.00001,rely=0.6)

    b = Button(s,text='Turn off Notifications',bg="#ECE5DD",fg="#075E54",font=('Kalpurush', 20, 'bold'),width=90,relief='flat',anchor='w')
    b.place(relx=0.00001,rely=0.7)

    b = Button(s,text='Change your status',bg="#ECE5DD",fg="#075E54",font=('Kalpurush', 20, 'bold'),width=90,relief='flat',anchor='w',command = lambda : [s.destroy(),updatestatus(user)])
    b.place(relx=0.00001,rely=0.8)

    b = Button(s,text='About Us',bg="#ECE5DD",fg="#075E54",font=('Kalpurush', 20, 'bold'),width=90,relief='flat',anchor='w',command = lambda : [s.destroy(),aboutus()])
    b.place(relx=0.00001,rely=0.9)


    s.mainloop()
def hello():
    if db.get_setting('remember') == 'True':
        default()
    else:
        login()