示例#1
0
    def create_user(self):
        """
        This function is assigned to the "create" button.
        If the entry box is empty an error message is displayed.
        If the user id exists, an error message is displayed to let the user know that duplicate user id is
        not accepted.
        Else, the users information: name, surname and user id is saved in users_db file to register the new user.
        """

        fmanager = FileManager()
        if self.name.get() == "" or self.surname.get(
        ) == "" or self.userid.get() == "":
            self.message.set("Please fill in all the boxes.")
        # To avoid duplicate user id(primary key).
        elif fmanager.check_if_userid_exists(self.userid.get()):
            self.ent_userid.delete(0, tk.END)
            self.message.set(
                "This User ID already exists. Please enter a different User ID."
            )
        else:
            fmanager.save_to_userList(self.name.get(), self.surname.get(),
                                      self.userid.get())
            self.ent_name.delete(0, tk.END)
            self.ent_surname.delete(0, tk.END)
            self.ent_userid.delete(0, tk.END)
            self.message.set("Congratulation, your account has been created.")
示例#2
0
    def login_user(self):
        """
        It checks if the user id already exists in the users_db. If it does, the display switches to home
        page, else it displays an error message.
        """

        fmanager = FileManager()
        self.login_prompt.set("")
        if not fmanager.check_if_userid_exists(self.ent_login_userid.get()):
            self.login_prompt.set("Invalid User ID. Please try again.")
        else:
            home_view = self.controller.get_page("HomeView")
            home_view.populate_tree(
                self.controller.shared_data["username"].get())
            self.controller.show_frame("HomeView")
示例#3
0
    def add_button_action(self):
        """
        Adding shift information(date and time) to shift_db.

        Raises
        ------
        ValueError
            If an empty value is passed in as date.
        TypeError
            If an invalid input is entered. For e.g. A string is passed in instead of an integer.
        """

        fmanager = FileManager()
        try:
            self.date = date(int(self.ent_date_year.get()),
                             int(self.ent_date_month.get()),
                             int(self.ent_date_day.get()))
            self.start_time = time(hour=int(self.ent_from.get().split(":")[0]),
                                   minute=int(
                                       self.ent_from.get().split(":")[1]))
            self.end_time = time(minute=int(self.ent_to.get().split(":")[1]),
                                 hour=int(self.ent_to.get().split(":")[0]))

            self.no_of_hours = (datetime.combine(self.date, self.end_time) -
                                datetime.combine(self.date, self.start_time))
            self.no_of_hours = round(self.no_of_hours.seconds / 3600, 2)

            fmanager.add_entry_to_shift_db(
                self.controller.shared_data["username"].get(), self.date,
                self.start_time, self.end_time, self.no_of_hours)
            hview = self.controller.get_page("HomeView")
            hview.update_shift_entry_table(self.date, self.start_time,
                                           self.end_time, self.no_of_hours)
            self.controller.show_frame("HomeView")
        except ValueError:
            self.message.set(
                "Value Error! Please fill in the boxes with appropriate entry."
            )
        except TypeError:
            self.message.set(
                "Type Error! Please fill in the boxes with appropriate entry.")
        self.ent_date_day.delete(0, tk.END)
        self.ent_date_month.delete(0, tk.END)
        self.ent_date_year.delete(0, tk.END)
        self.ent_from.delete(0, tk.END)
        self.ent_from.insert(0, "HH:MM")
        self.ent_to.delete(0, tk.END)
        self.ent_to.insert(0, "HH:MM")
示例#4
0
    def delete_selected_entry(self):
        """
        Deletes the selected entry from the table.
        If the delete button is clicked without selecting a target an error message is shown.
        The shift_db is also updated.
        """

        try:
            selected_entry = self.tv_shift_table.selection()[0]
            self.tv_shift_table.delete(int(selected_entry))
            self.shift_db = self.shift_db.drop(int(selected_entry))
        except IndexError:
            print("No entry selected.")
        except KeyError:
            print("Key Error")
        fmanager = FileManager()
        fmanager.updated_shift_db(self.shift_db)
示例#5
0
    def __init__(self, parent, controller):
        """
        Parameters
        ----------
        parent : tk.Frame
            The root frame in the window which holds contains all the other frames.
        controller : tk.Tk
            The window of the application. It provides a way for all the other frames to interact with each other.
        """

        tk.Frame.__init__(self, parent)
        self.controller = controller

        self.frm_root = tk.Frame(master=self)
        self.frm_root.grid(row=0, column=0)

        self.fmanager = FileManager()

        self.lbl_username = tk.Label(
            master=self.frm_root,
            textvariable=self.controller.shared_data["username"],
            font=("*Font", 10),
            relief="groove")
        self.lbl_username.grid(row=0, column=0, padx=10, pady=10)
        self.frm_main = tk.Frame(master=self.frm_root)
        self.frm_main.grid(row=1, column=0)
        self.btn_add = tk.Button(master=self.frm_main,
                                 text="Add",
                                 width=10,
                                 command=self.open_add_window)
        self.btn_add.grid(row=1, column=1, pady=5, padx=5)
        self.btn_delete = tk.Button(master=self.frm_main,
                                    text="Delete",
                                    width=10,
                                    command=self.delete_selected_entry)
        self.btn_delete.grid(row=2, column=1, pady=5, padx=5)
        self.btn_cancel = tk.Button(master=self.frm_main,
                                    text="Logout",
                                    width=10,
                                    command=self.log_out_user)
        self.btn_cancel.grid(row=3, column=1, pady=5, padx=5)

        self.frm_shift_table = tk.Frame(master=self.frm_root)
        self.frm_shift_table.grid(row=1, column=1, padx=10)
        self.tv_shift_table = tk.ttk.Treeview(master=self.frm_shift_table)

        self.shift_db = self.fmanager.shift_db_df
        self.tbl_headers = self.shift_db.columns.tolist()

        self.tv_shift_table['columns'] = ('Date', 'Start time', 'End time',
                                          'No of hours')
        self.tv_shift_table.column('#0', width=0, stretch=tk.NO)
        self.tv_shift_table.column('Date', anchor=tk.CENTER)
        self.tv_shift_table.column('Start time', anchor=tk.CENTER)
        self.tv_shift_table.column('End time', anchor=tk.CENTER)
        self.tv_shift_table.column('No of hours', anchor=tk.CENTER)

        self.tv_shift_table.heading('#0', text='', anchor=tk.CENTER)
        self.tv_shift_table.heading('Date',
                                    text=self.tbl_headers[1],
                                    anchor=tk.CENTER)
        self.tv_shift_table.heading('Start time',
                                    text=self.tbl_headers[2],
                                    anchor=tk.CENTER)
        self.tv_shift_table.heading('End time',
                                    text=self.tbl_headers[3],
                                    anchor=tk.CENTER)
        self.tv_shift_table.heading('No of hours',
                                    text=self.tbl_headers[4],
                                    anchor=tk.CENTER)
示例#6
0
class HomeView(tk.Frame):
    """
    This class is the main page of the app. The user is able to check their previous entry and also add and delete
    new and old ones respectively.

    Attributes
    ----------
    shift_db : list
        This is a dataframe of the "shift_db" file.
    tbl_headers : list
        List of columns in shift_db. They are: User id, Date, Start time, End time and No of hours.
    tv_shift_table : tk.TreeView
       To display user specific entries on the main page.

    Methods
    -------
    populate_tree(userid)
        Add shift entries to the tv_shift_table and update the shift_db file.
    clear_tree_data()
        Empty the tv_shift_table.
    delete_selected_entry()
        Delete the selected entry on the tv_shift_table and update the shift_db file.
    log_out_user()
        Log out the current user and switch the frame to login page.
    """
    def __init__(self, parent, controller):
        """
        Parameters
        ----------
        parent : tk.Frame
            The root frame in the window which holds contains all the other frames.
        controller : tk.Tk
            The window of the application. It provides a way for all the other frames to interact with each other.
        """

        tk.Frame.__init__(self, parent)
        self.controller = controller

        self.frm_root = tk.Frame(master=self)
        self.frm_root.grid(row=0, column=0)

        self.fmanager = FileManager()

        self.lbl_username = tk.Label(
            master=self.frm_root,
            textvariable=self.controller.shared_data["username"],
            font=("*Font", 10),
            relief="groove")
        self.lbl_username.grid(row=0, column=0, padx=10, pady=10)
        self.frm_main = tk.Frame(master=self.frm_root)
        self.frm_main.grid(row=1, column=0)
        self.btn_add = tk.Button(master=self.frm_main,
                                 text="Add",
                                 width=10,
                                 command=self.open_add_window)
        self.btn_add.grid(row=1, column=1, pady=5, padx=5)
        self.btn_delete = tk.Button(master=self.frm_main,
                                    text="Delete",
                                    width=10,
                                    command=self.delete_selected_entry)
        self.btn_delete.grid(row=2, column=1, pady=5, padx=5)
        self.btn_cancel = tk.Button(master=self.frm_main,
                                    text="Logout",
                                    width=10,
                                    command=self.log_out_user)
        self.btn_cancel.grid(row=3, column=1, pady=5, padx=5)

        self.frm_shift_table = tk.Frame(master=self.frm_root)
        self.frm_shift_table.grid(row=1, column=1, padx=10)
        self.tv_shift_table = tk.ttk.Treeview(master=self.frm_shift_table)

        self.shift_db = self.fmanager.shift_db_df
        self.tbl_headers = self.shift_db.columns.tolist()

        self.tv_shift_table['columns'] = ('Date', 'Start time', 'End time',
                                          'No of hours')
        self.tv_shift_table.column('#0', width=0, stretch=tk.NO)
        self.tv_shift_table.column('Date', anchor=tk.CENTER)
        self.tv_shift_table.column('Start time', anchor=tk.CENTER)
        self.tv_shift_table.column('End time', anchor=tk.CENTER)
        self.tv_shift_table.column('No of hours', anchor=tk.CENTER)

        self.tv_shift_table.heading('#0', text='', anchor=tk.CENTER)
        self.tv_shift_table.heading('Date',
                                    text=self.tbl_headers[1],
                                    anchor=tk.CENTER)
        self.tv_shift_table.heading('Start time',
                                    text=self.tbl_headers[2],
                                    anchor=tk.CENTER)
        self.tv_shift_table.heading('End time',
                                    text=self.tbl_headers[3],
                                    anchor=tk.CENTER)
        self.tv_shift_table.heading('No of hours',
                                    text=self.tbl_headers[4],
                                    anchor=tk.CENTER)

    def populate_tree(self, userid):
        """
        Populating the tree with current user's entries.

        Parameters
        ----------
        userid : String
            User id of current user.
        """

        tbl_values = self.fmanager.get_user_specific_entry(userid)

        for i in range(len(tbl_values)):
            self.tv_shift_table.insert(
                parent='',
                index=i,
                iid=i,
                text='',
                values=(tbl_values[i][2], tbl_values[i][3], tbl_values[i][4],
                        tbl_values[i][5]))
        self.tv_shift_table.grid(row=0, column=0)

    def update_shift_entry_table(self, date, start_time, end_time,
                                 no_of_hours):
        self.tv_shift_table.insert(
            parent='',
            index=len(self.tv_shift_table.get_children()) + 1,
            iid=len(self.tv_shift_table.get_children()) + 1,
            text='',
            values=(date, start_time, end_time, no_of_hours))

    def clear_tree_data(self):
        """
        Deleting all the data in tree.
        """

        for children in self.tv_shift_table.get_children():
            self.tv_shift_table.delete(children)

    def open_add_window(self):
        """
        Switch to add page.
        """

        self.controller.show_frame("AddWindow")

    def delete_selected_entry(self):
        """
        Deletes the selected entry from the table.
        If the delete button is clicked without selecting a target an error message is shown.
        The shift_db is also updated.
        """

        try:
            selected_entry = self.tv_shift_table.selection()[0]
            self.tv_shift_table.delete(int(selected_entry))
            self.shift_db = self.shift_db.drop(int(selected_entry))
        except IndexError:
            print("No entry selected.")
        except KeyError:
            print("Key Error")
        fmanager = FileManager()
        fmanager.updated_shift_db(self.shift_db)

    def log_out_user(self):
        """
        Log out the current user and switch to login page.
        """

        self.clear_tree_data()
        self.controller.show_frame("LoginView")
        login_view = self.controller.get_page("LoginView")
        login_view.ent_login_userid.delete(0, tk.END)
        login_view.ent_name.delete(0, tk.END)
        login_view.ent_surname.delete(0, tk.END)
        login_view.ent_userid.delete(0, tk.END)
        login_view.message.set("")
示例#7
0
 def test_FileManager(self):
     FileManager.test()
示例#8
0
import pop_engine as pop

# Wyjaśnienie sensu istnienia pliku:
# https://www.notion.so/szymanski/The-curious-case-of-the-UserInterface-socket-ab76cfc810d9486bb8ce9199f0cc7efc

if __name__ == "__main__":
    try:
        v1, v2, _ = platform.python_version().split('.')
        if v1 != '3' or int(v2) < 9:
            print(
                'Larch wymaga co najmniej Pythona 3.9 do działania. Zainstaluj go ze strony https://www.python.org/downloads/'
            )
            input()
            sys.exit()

        manager = FileManager(DEBUG, VERSION)
        manager.download_required(FORCE_DOWNLOAD)

        # Log clearing
        if os.path.exists('log.log'):
            os.remove('log.log')

        # UserInterface socket generation
        UI = pop.Socket('UserInterface',
                        os.path.abspath('plugins/UserInterface'), '0.0.1',
                        '__template__')

        # App run
        try:
            configs = os.listdir(os.path.abspath('config'))
        except FileNotFoundError:
示例#9
0
 def __loadWorldInfo(self):
     country = fm.loadWorldInfo('info/worldinfo.cfm')
     for k, c in country.items():
         self.config['country'][c['region']].append(c['name'])
示例#10
0
 def __loadConfigfile(self):
     self.config = fm.loadConfig('info/config.json')
     self.config['country'] = {}
     for region in self.config['region']:
         self.config['country'][region] = []