Example #1
0
class EditMeView(Frame):
    '''
    this Frame collects new data and send them back to main.py via callback()
    callback1 will close tab after clicking btn submit.
    callback2 to show err
    '''
    def __init__(self,
                 username,
                 master=None,
                 callback=None,
                 callback1=None,
                 callback2=None):
        super().__init__(master)
        self.username = username
        self.callback = callback  # set_my_info()
        self.callback1 = callback1  # close_tab()
        self.callback2 = callback2
        self.pack()

        # Defining widgets
        self.lbl_username = tk.Label(self, text="Username:"******"Password:"******"*")
        self.ent_pass.grid(row=1, column=1)

        self.btn_submit = Button(self, text="Submit", command=self.submit)
        self.btn_submit.grid(row=2, column=0, columnspan=2)

        # Preview texts in entry based on self.username
        self.ent_username.insert(tk.END, self.username)

    def submit(self):
        data = self.return_data()
        if self.callback:  # sending data to main.py
            result = self.callback(*data, self.callback2)
            self.clear()
            if result:
                if self.callback1:  # = if no err occured then close the tab.
                    self.callback1()

    def return_data(self):
        new_username = self.ent_username.get()
        new_pass = self.ent_pass.get()
        new_data = (new_username, new_pass)
        return [
            data if not data.isspace() and data != "" else None
            for data in new_data
        ]

    def clear(self):
        self.ent_username.delete(0, tk.END)
        self.ent_pass.delete(0, tk.END)
Example #2
0
class Change_my_info(Frame):
    def __init__(self,
                 name,
                 master=None,
                 callback1=None,
                 callback2=None,
                 callback3=None):
        super().__init__(master)
        self.name = name
        self.callback1 = callback1
        self.callback2 = callback2
        self.callback3 = callback3
        self.pack()

        self.lbl_name = tk.Label(self, text="Username:"******"Password:"******"*")
        self.ent_pass.grid(row=1, column=1)

        self.btn_submit = Button(self, text="Submit", command=self.submit)
        self.btn_submit.grid(row=2, column=0, columnspan=2)

        self.ent_username.insert(tk.END, self.name)

    def submit(self):
        data = self.return_data()
        if self.callback1:  # sending data to main.py
            result = self.callback1(*data, self.callback3)
            self.clear()
            if result:
                if self.callback2:  # = if no err occured then close the tab.
                    self.callback2()

    def return_data(self):
        new_username = self.ent_name.get()
        new_pass = self.ent_pass.get()
        new_data = (new_name, new_pass)
        return [
            data if not data.isspace() and data != "" else None
            for data in new_data
        ]

    def clear(self):
        self.ent_name.delete(0, tk.END)
        self.ent_pass.delete(0, tk.END)
Example #3
0
class ShowAll(Frame):

    def __init__ (self,master=None , callback1 = None , callback2= None , callback3=None
                  ,):
        super().__init__(master)
        self.callback1=callback1
        self.callback2=callback2
        self.callback3=callback3
        self.all_employees_salary={}
        self.all_manager={}
        self.customer={}
        
        self.pack()


        self.btn_all = Button(self, text = "show all manager",font=("Tahoma",12),
                                    command = self.all_manager)
        self.btn_all.grid(row = 4, column = 0, columnspan = 4)

        self.btn_all = Button(self, text = "show all customer",font=("Tahoma",12),
                                    command = self.all_customer)
        self.btn_all.grid(row = 6, column = 0, columnspan = 4)

        
        self.btn_all = Button(self, text = "show all employee salary",font=("Tahoma",12)
                                    ,command = self.all_employees_salary)
        self.btn_all.grid(row = 8, column = 0, columnspan = 4)

        
    def all_employee(self): # generator
        for key, value in self.all_employees:
            yield key, value
    
    def all_manager(self): # generator
        for key, value in self.all_manager:
            yield key, value
    def all_customer(self): # generator
        for key, value in self.all_customer:
            yield key, value
    def all_employees_salary(self):
        total = 0
        for key in self.all_employees:
            total += self.all_employees[key].salary
        return total
Example #4
0
class EditBranch(Frame):
    def __init__(self,
                 name,
                 username,
                 master=None,
                 callback1=None,
                 callback2=None,
                 callback3=None):
        super().__init__(master)
        self.name = name
        self.username = username
        self.callback3 = callback3
        self.callback1 = callback1
        self.callback2 = callback2
        self.pack()

        self.lbl_name = tk.Label(self, text="Name:")
        self.lbl_name.grid(row=0, column=0)
        self.lbl_username = tk.Label(self, text="Username:"******"Password:"******"ID:")
        self.lbl_id.grid(row=6, column=0)

        self.ent_name = tk.Entry(self)
        self.ent_name.grid(row=0, column=1)
        self.ent_username = tk.Entry(self)
        self.ent_username.grid(row=2, column=1)
        self.ent_pass = tk.Entry(self, show="*")
        self.ent_pass.grid(row=4, column=1)
        self.ent_id = tk.Entry(self)
        self.ent_id.grid(row=6, column=1)

        self.btn_submit = Button(self, text="change", command=self.change)
        self.btn_submit.grid(row=8, column=0, columnspan=2)

        self.btn_new = Button(self, text="new", command=self.new_branch)
        self.btn_new.grid(row=10, column=0, columnspan=2)

        self.btn_new = Button(self, text="delete", command=self.del_branch)
        self.btn_new.grid(row=12, column=0, columnspan=2)

        self.ent_name.insert(tk.END, self.name)
        self.ent_username.insert(tk.END, self.username)

    def new_branch(self, branch, branch_ID):

        new_name = self.ent_name.get()
        new_id = self.ent_id.get()
        new_username = self.ent_username.get()
        new_pass = self.ent_pass.get()
        new_data = (self.old_user, new_username, new_id, new_pass, new_name)
        return [
            data if not data.isspace() and data != "" else None
            for data in new_data
        ]

    def del_branch(self, code):
        if ID in self.all_branch:
            del self.all_branch[code]
            return 1  #successful
        return 2  # not in list

    def change(self):
        data = self.new_branch()
        if self.callback:
            result = self.callback(*data, self.callback3)
            self.clear()
            if result:
                if self.callback2:
                    self.callback2()

    def clear(self):
        self.ent_name.delete(0, tk.END)
        self.ent_username.delete(0, tk.END)
        self.ent_pass.delete(0, tk.END)
        self.ent_id.delete(0, tk.END)
Example #5
0
class ManagerView(Tk):
    '''
    This class creates manager panel.
    Access to: 
        edit_user_view panel
        edit_me_view panel
        add_user_view panel
    '''
        
    def __init__(self, name, username, list_employees,
                 callback1 = None, callback2 = None,
                 callback3 = None, callback4 = None,
                 callback5 = None, callback6 = None):
        super().__init__()
        self.name = name
        self.username = username
        self.list_employees = list_employees
        self.callback1 = callback1  # add_employee()
        self.callback2 = callback2  # del_employee()
        self.callback3 = callback3  # change_employee()
        self.callback4 = callback4  # open_employee_panel()
        self.callback5 = callback5  # search()
        self.callback6 = callback6  # set_my_info()
        self.title(f"Panel manager: {self.name}")
        #self.icon (may add it)
        self.resizable(False, False)
        self.tabs = ttk.Notebook(self)
        self.tabs.grid(row = 0, column = 0)
        
        self.tab_main = Frame(self) 
        self.tab_main.grid(row = 0, column = 0)
        self.tab_edit_me = Frame(self)
        self.tab_edit_me.grid(row = 0, column = 0)
        self.tab_add_user = Frame(self)
        self.tab_add_user.grid(row = 0, column = 0)
        self.tab_edit_user = Frame(self)
        self.tab_edit_user.grid(row = 0, column = 0)        
        self.tabs.add(self.tab_main, text = "Main menu")
        
        # Defining Tab-main frames
        self.fr_aboutme = tk.LabelFrame(self.tab_main, text = "About me",
                                        bg = "#00a693")
        self.fr_aboutme.grid(row = 0, column = 0, rowspan = 2, padx = 10)
        self.fr_seachbar = Frame(self.tab_main)
        self.fr_seachbar.grid(row = 0, column = 1)
        self.fr_treev = Frame(self.tab_main)
        self.fr_treev.grid(row = 1, column = 1)
        self.fr_edit = Frame(self.tab_main)
        self.fr_edit.grid(row = 1, column = 2)
        
        # Frame about
        self.lbl_name = Label(self.fr_aboutme, text = "Name:")
        self.lbl_name.grid(row = 0, column = 0,
                           sticky = "w", padx = 10, pady = 5)
        self.lbl_name = Label(self.fr_aboutme, text = self.name)
        self.lbl_name.grid(row = 0, column = 1,
                           sticky = "w", padx = 10, pady = 5)
        self.lbl_username = Label(self.fr_aboutme, text = "Username:"******"w", padx = 10, pady = 5)
        self.lbl_username = Label(self.fr_aboutme, text = self.username)
        self.lbl_username.grid(row = 1, column = 1,
                               sticky = "w", padx = 10, pady = 5)
        self.btn_edit_me = Button(self.fr_aboutme, text = "Edit",
                                  command = self.edit_me, 
                                  relief = tk.GROOVE)
        self.btn_edit_me.grid(row = 2, column = 0, columnspan = 2, pady = 5)    
        
        # Frame search bar
        self.search_bar = tk.Entry(self.fr_seachbar, width = 21)
        self.search_bar.grid(row = 0, column = 0, pady = 10)
        self.search_bar.bind("<Return>", lambda _: self.btn_search.invoke())
        self.btn_search = Button(self.fr_seachbar, text = "search", 
                                 command = self.search_treev) 
        self.btn_search.grid(row = 0, column = 1, padx = 5)
        self.btn_refresh = Button(self.fr_seachbar, text = "Refresh", 
                                  command = self.refresh_treev)
        self.btn_refresh.grid(row = 0, column = 2)
        
        # Frame list
        self.users_treev = ttk.Treeview(self.fr_treev, selectmode = 'browse',
                                        height = 15)
        self.users_treev.grid(row = 0, column = 0)
        self.users_treev['columns'] = ("1", "2") 
        self.users_treev["show"] = "headings"
        self.users_treev.column("1", width = 140, anchor ='c')
        self.users_treev.column("2", width = 140, anchor ='c')

        self.users_treev.heading("1", text ="Name",
                                 command = lambda: \
                                 self.treev_cl_sort("1", False))
        self.users_treev.heading("2", text ="Username",
                                 command = lambda: \
                                 self.treev_cl_sort("2", False))

        self.scrollbar = ttk.Scrollbar(self.fr_treev,
                                       command = self.users_treev.yview, 
                                       orient = tk.VERTICAL)
        self.scrollbar.grid(row = 0, column = 1)
        self.users_treev.configure(xscrollcommand = self.scrollbar.set)
        
        # Frame edit
        self.btn_add_user = Button(self.fr_edit, text = "Add user",
                                   command = self.add_user)
        self.btn_add_user.grid(row = 0, column = 0)
        self.btn_edit_user = Button(self.fr_edit, text = "Edit user",
                                    command = self.edit_user)
        self.btn_edit_user.grid(row = 1, column = 0, pady = 10, padx = 10)
        self.btn_delete_user = Button(self.fr_edit, text = "Delete user",
                                      command = self.del_user)
        self.btn_delete_user.grid(row = 2, column = 0)
        
        for user in self.list_employees:
            self.users_treev.insert("", "end", values = user)
        self.users_treev.bind("<Double-1>", self.onDoubleClick)
    def onDoubleClick(self, event):
        '''
        assigning a double-click function to treev to open their panel.
        '''
        
        user = self.users_treev.selection()
        if user == ():  # double click on headings or any other empty space
            return None
        name, username = self.users_treev.item(user)["values"] # =(name, user)
        if self.callback4:
            self.callback4(username) 
        self.users_treev.selection_remove(user[0]) # clear selection
        
    def edit_me(self):
        children = self.tab_edit_me.winfo_children()
        if children != []:  # if a edit_view panel is open then ignore.
            return None
        panel = EditMeView(self.username, self.tab_edit_me, self.callback6, 
                           self.close_tab, self.msg_err)

        self.tabs.add(self.tab_edit_me, text = "Edit-me menu")
        
    def add_user(self):
        children = self.tab_add_user.winfo_children()
        if children != []:  # if a edit_view panel is open then ignore.
            return None
        panel = AddUserView(self.tab_add_user, self.callback1,
                            self.close_tab, self.msg_err)
        self.tabs.add(self.tab_add_user, text = "Add-user")
        
    def del_user(self):
        selected = self.users_treev.focus()  # returns selected item ID
        if selected == "":  # nothig selected, but btn is ckicked
            return None
        name, username = self.users_treev.item(selected, "values")
        self.users_treev.delete(selected)
        if self.callback2:
            self.callback2(username, self.msg_err)
        # update self.list_emplyees
        
    def edit_user(self):
        '''
        first delete any opened tab for editing and then open new tab for edit
        '''
        children = self.tab_edit_user.winfo_children()
        if children != []:
            for widget in children:  # wiget = last EditUserView()
                widget.destroy()
        selected = self.users_treev.focus()
        if selected == "":  # nothig selected, but btn is ckicked
            return None
        name, username = self.users_treev.item(selected, "values")
        panel = EditUserView(name, username, self.tab_edit_user,
                             self.callback3, self.close_tab, self.msg_err)
        self.tabs.add(self.tab_edit_user, text = f"Edit {name}")
        # update self.list_employees (update by order of main.py).
        # update treeview. call refresh_treev after list update.
        self.users_treev.selection_remove(selected) 
        
    def refresh_treev(self):
        '''simply deletes the entire treev and inserts items again'''
        
        self.users_treev.delete(*self.users_treev.get_children())
        for user in self.list_employees:
            self.users_treev.insert("", "end", values = user)
        
    def search_treev(self):
        '''
        gets anythin in self.search_bar and send to main.py.
        self.msg_err if nothing was found
        '''
        text = self.search_bar.get()
        if self.callback5:
            matched_items = self.callback5(text)
        if len(matched_items) > 0:
            self.users_treev.delete(*self.users_treev.get_children())
            for item in matched_items:
                self.users_treev.insert("", "end", values = item)
        else:
            self.msg_err("Error", "User not found")
   
    def treev_cl_sort(self, col, reverse):
        ''' click on each heading to sort by the values of it.'''
        
        users = [(self.users_treev.set(id_, col), id_) \
                      for id_ in self.users_treev.get_children()]
        # users = [(value 1, id-row 1), (value 2, id-row 2), ...]
        users.sort(reverse = reverse)  # sorted by values. not row-id !
        for index, (val, id_) in enumerate(users):
            self.users_treev.move(id_, '', index)
        self.users_treev.heading(col, command=lambda: \
                                 self.treev_cl_sort(col, not reverse))
            
    def close_tab(self):
        '''
        just closing the tab.
        used as callback for all tabs like edit_view, edit_me, etc.
        '''
        
        self.tabs.forget(self.tabs.select())
        
    def run(self):
        self.mainloop()
        
    def close(self):
        self.destroy()
    
    def msg_err(self, title = None, msg = None, master = None):
        if master is None:
            master = self
        tk.messagebox.showerror(title, msg, parent = master)
Example #6
0
class EditMeView(Frame):
    '''
    this Frame collects new data and send them back to main.py via callback()
    callback1 will close tab after clicking btn submit.
    callback2 to show err
    '''
    def __init__(self,
                 username,
                 master=None,
                 callback=None,
                 callback1=None,
                 callback2=None):
        super().__init__(master)
        self.username = username
        self.callback = callback  # set_my_info()
        self.callback1 = callback1  # close_tab()
        self.callback2 = callback2
        self.pack(expand=True)

        # Defining widgets
        self.lbl_username = Label(self, text="Username:"******"w")
        self.lbl_pass = Label(self, text="Password:"******"w")

        self.ent_username = tk.Entry(self)
        self.ent_username.grid(row=0, column=1)
        self.ent_pass = tk.Entry(self, show="*")
        self.ent_pass.grid(row=1, column=1)

        self.btn_submit = Button(self, text="Submit", command=self.submit)
        self.btn_submit.grid(row=2, column=0, columnspan=2, padx=10, pady=10)

        # Preview texts in entry based on self.username
        self.ent_username.insert(tk.END, self.username)
        self.ent_username.focus_set()

        # press Enter to go next, stop clickin!
        self.entries = [
            ent for ent in self.winfo_children() if isinstance(ent, tk.Entry)
        ]
        self.ent_username.bind("<Return>",
                               lambda _: self.entries[1].focus_set())
        self.ent_pass.bind("<Return>", lambda _: self.btn_submit.invoke())

    def submit(self):
        data = self.return_data()
        if self.callback:
            result = self.callback(*data)  # sending data to main.py
            self.clear()
            if isinstance(result, str):  # means an error occured
                self.callback2("Error", result)
            else:
                if self.callback1:  # = if no err occured then close the tab.
                    self.callback1()

    def return_data(self):
        new_username = self.ent_username.get()
        new_pass = self.ent_pass.get()
        new_data = (new_username, new_pass)
        return [
            data if not data.isspace() and data != "" else None
            for data in new_data
        ]

    def clear(self):
        self.ent_username.delete(0, tk.END)
        self.ent_pass.delete(0, tk.END)
Example #7
0
class AddUserView(Frame):
    '''
    this Frame collects new data and send them back to main.py via callback()
    callback1 will close tab after clicking btn submit.
    callback2 to show err
    '''
    def __init__(self,
                 master=None,
                 callback=None,
                 callback1=None,
                 callback2=None):
        super().__init__(master)
        self.callback = callback  # add_employee()
        self.callback1 = callback1  # close_tab()
        self.callback2 = callback2  # show_err()
        self.pack(expand=True)

        # Defining widgets
        self.lbl_name = Label(self, text="Name:")
        self.lbl_name.grid(row=0, column=0, padx=10, pady=10, sticky="w")
        self.lbl_id = Label(self, text="ID:")
        self.lbl_id.grid(row=1, column=0, padx=10, pady=10, sticky="w")
        self.lbl_username = Label(self, text="Username:"******"w")
        self.lbl_pass = Label(self, text="Password:"******"w")

        self.ent_name = tk.Entry(self)
        self.ent_name.grid(row=0, column=1)
        self.ent_id = tk.Entry(self)
        self.ent_id.grid(row=1, column=1)
        self.ent_username = tk.Entry(self)
        self.ent_username.grid(row=2, column=1)
        self.ent_pass = tk.Entry(self, show="*")
        self.ent_pass.grid(row=3, column=1)

        self.btn_submit = Button(self, text="Submit", command=self.submit)
        self.btn_submit.grid(row=4, column=0, columnspan=2, padx=10, pady=10)

        self.ent_name.focus_set()

        # press Enter to go next, stop clickin!
        self.entries = [
            ent for ent in self.winfo_children() if isinstance(ent, tk.Entry)
        ]
        self.ent_name.bind("<Return>", lambda _: self.entries[1].focus_set())
        self.ent_id.bind("<Return>", lambda _: self.entries[2].focus_set())
        self.ent_username.bind("<Return>",
                               lambda _: self.entries[3].focus_set())
        self.ent_pass.bind("<Return>", lambda _: self.btn_submit.invoke())

    def submit(self):
        data = self.return_data()
        if self.callback:
            result = self.callback(*data)  # sending data to main.py
            self.clear()
            if isinstance(result, str):  # means an error occured
                if self.callback2:
                    self.callback2("Error", result)
            else:
                if self.callback1:  # = if no err occured then close the tab.
                    self.callback1()

    def return_data(self):
        new_name = self.ent_name.get()
        new_id = self.ent_id.get()
        new_username = self.ent_username.get()
        new_pass = self.ent_pass.get()
        new_data = (new_name, new_username, new_id, new_pass)
        if all(item.isalnum() for item in new_data):
            return new_data

    def clear(self):
        self.ent_name.delete(0, tk.END)
        self.ent_id.delete(0, tk.END)
        self.ent_username.delete(0, tk.END)
        self.ent_pass.delete(0, tk.END)
Example #8
0
class Accounts_view(Frame):
    def __init__(self,
                 id_,
                 master=None,
                 callback=None,
                 callback1=None,
                 callback2=None,
                 callback3=None):
        super().__init__(master)
        self.id_ = id_
        self.callback = callback  # add_account()
        self.callback1 = callback1  # get_accounts()
        self.callback2 = callback2  # remove_account()
        self.callback3 = callback3  # add_money()
        self.pack()

        # Defining main frames
        self.fr_buttons = Frame(self)
        self.fr_buttons.grid(row=0, column=0)
        self.fr_treeview = Frame(self)
        self.fr_treeview.grid(row=0, column=1)

        # Frame Buttons
        self.btn_add_acc = Button(self.fr_buttons,
                                  text="add account",
                                  command=self.add_account)
        self.btn_add_acc.grid(row=0, column=0)
        self.btn_del_acc = Button(self.fr_buttons,
                                  text="delete account",
                                  command=self.del_account)
        self.btn_del_acc.grid(row=1, column=0)
        self.btn_add_money = Button(self.fr_buttons,
                                    text="add money",
                                    command=self.add_money)
        self.btn_add_money.grid(row=2, column=0)

        # Frame Treev

        self.treev = ttk.Treeview(self.fr_treeview,
                                  selectmode="browse",
                                  height=15)
        self.treev.grid(row=0, column=0)
        self.treev['columns'] = ("1", "2")
        self.treev["show"] = "headings"
        self.treev.column("1", width=140, anchor='c')
        self.treev.column("2", width=140, anchor='c')
        self.treev.heading("1", text="account number")
        self.treev.heading("2", text="remaining")
        self.scrollbar = ttk.Scrollbar(self.fr_treeview,
                                       command=self.treev.yview,
                                       orient=tk.VERTICAL)
        self.scrollbar.grid(row=0, column=1)
        self.treev.configure(xscrollcommand=self.scrollbar.set)

        if self.callback1:  # filling treeview
            for data in self.callback1():
                self.treev.insert("", "end", values=data)

    def add_money(self):
        selected = self.treev.selection()
        if selected == ():
            return None
        acc_num, remaining = self.treev.item(selected, "values")
        if self.callback3:
            self.callback3(acc_num)

    def del_account(self):
        selected = self.treev.selection()
        if selected == ():
            return None
        acc_num, remaining = self.treev.item(selected, "values")
        self.treev.delete(selected)
        if self.callback2:
            self.callback2(acc_num)

    def add_account(self):
        if self.callback:
            card_num = self.callback(self.id_)
            self.treev.insert("", "end", values=(card_num, "0"))
Example #9
0
class AddUserView(Frame):
    '''
    this Frame collects new data and send them back to main.py via callback()
    callback1 will close tab after clicking btn submit.
    callback2 to show err
    '''
    def __init__(self,
                 master=None,
                 callback=None,
                 callback1=None,
                 callback2=None):
        super().__init__(master)
        self.callback = callback  # add_employee()
        self.callback1 = callback1  # close_tab()
        self.scallback2 = callback2  # show_err()
        self.pack()

        # Defining widgets
        self.lbl_name = tk.Label(self, text="Name:")
        self.lbl_name.grid(row=0, column=0)
        self.lbl_id = tk.Label(self, text="ID:")
        self.lbl_id.grid(row=1, column=0)
        self.lbl_username = tk.Label(self, text="Username:"******"Password:"******"*")
        self.ent_pass.grid(row=3, column=1)

        self.btn_submit = Button(self, text="Submit", command=self.submit)
        self.btn_submit.grid(row=4, column=0, columnspan=2)

    def submit(self):
        data = self.return_data()
        if self.callback:  # sending data to main.py
            result = self.callback(*data, self.callback2)
            self.clear()
            if result:
                if self.callback1:  # = if no err occured then close the tab.
                    self.callback1()

    def return_data(self):
        new_name = self.ent_name.get()
        new_id = self.ent_id.get()
        new_username = self.ent_username.get()
        new_pass = self.ent_pass.get()
        new_data = (new_name, new_username, new_id, new_pass)
        if all(item.isalnum() for item in new_data):
            return new_data

    def clear(self):
        self.ent_name.delete(0, tk.END)
        self.ent_id.delete(0, tk.END)
        self.ent_username.delete(0, tk.END)
        self.ent_pass.delete(0, tk.END)