Пример #1
0
def try_again(window: sg.Window):
    """Press [Enter] to try again"""
    QT_ENTER_KEY1 = "special 16777220"
    QT_ENTER_KEY2 = "special 16777221"
    while True:
        event, _ = window.read(timeout=20)

        if event in (sg.WIN_CLOSED, "Exit"):
            break
        elif event in ("Return:36", "\r", QT_ENTER_KEY1, QT_ENTER_KEY2):
            return
    window.close()
    exit(0)
Пример #2
0
def accept_deny(window: sg.Window) -> bool:
    """Press [Enter] to accept image, [Escape] to try again"""
    QT_ENTER_KEY1 = "special 16777220"
    QT_ENTER_KEY2 = "special 16777221"
    while True:
        event, _ = window.read(timeout=20)

        if event in (sg.WIN_CLOSED, "Exit"):
            break
        elif event in ("Return:36", "\r", QT_ENTER_KEY1, QT_ENTER_KEY2):
            window["text_instruction"].update("", text_color="white")
            return True
        elif event.startswith("Escape"):
            return False
    window.close()
    exit(0)
Пример #3
0
    def Signup(self):
        signup_active = True

        layout = [
            [T("Signup for Xpnsit", **heading_format), ],
            [T("First Name:"), Input(size=(15, 1), key="f_name"), T(
                " "), T("Last Name:"), Input(size=(15, 1), key="l_name")],
            [T("Username:"******"user")],
            [T("Password:"******"pass", password_char="*")],
            [],
            [T(' '*40), Submit()]
        ]

        signup_win = Window("Xpnsit - Signup", layout=layout)

        while signup_active:  # <------------ Event Loop -----------------> #
            event, values = signup_win.Read()

            if event in (None, 'Exit'):
                signup_active = False
                login_active = True

            if event == 'Submit':
                self.vals = [values["user"], values["pass"],
                             values["mail"], values["f_name"], values["l_name"]]
                if not username_used(self.vals[0]):
                    create_account(*self.vals)

                    # <------------------- Confirmation of Insertion ------------------> #
                    success = check_login_info(values["user"], values["pass"])

                    if success == True:
                        print("Signup Successful.")
                        Popup(
                            "Signup Successful!",
                            "Exit this popup to return to the login page"
                        )
                        signup_win.close()
                        signup_active = False
                        login_active = True
                else:
                    PopupError("ERROR: Username already in usage",
                               title="Username already taken")
Пример #4
0
    def run(self, window: Window, fields: list) -> map:
        """ This method control the logic of load records selection window
        
        Args:
            window: the window contains the table
            fields: the fields that need to be get

        Returns: a map that contains selected record data

        """ ""

        info = window.Element('_OR_TABLE_').get()[self.values["_OR_TABLE_"][0]]
        window.close()
        i = 0
        for each in fields:
            self.record[each] = info[i]
            i += 1
        return self.record
Пример #5
0
def ah_read(ah: ArtsHandler, event: str, values: ValuesType,
            serialized: ValuesType, ls: LoopSlicerGui, load_values: bool,
            window: sg.Window) -> ty.Tuple[ArtsHandler, sg.Window]:
    ah_read_ret = ah.read(event, values)
    if isinstance(ah_read_ret, tuple) and isinstance(ah_read_ret[0], ty.List):
        ah = ArtsHandler(tabs_layout=ah_read_ret[0],
                         arts_instances=ah_read_ret[1])
        ls = LoopSlicerGui()
        if serialized is not None:
            rpr.Project().set_ext_state(GUI_SECTION,
                                        GUI_KEY,
                                        serialized,
                                        pickled=True)
        wind1 = _make_window(ls, ah, load_values)
        window.close()
        window = wind1
    else:
        check_for_exception(ah_read_ret)  # type:ignore
    return ah, window
Пример #6
0
    def Login(self):
        login_active = True
        layout = [
            [T("Xpnsit", **heading_format)],
            [T("Username:"******"user")],
            [T("Password:"******"pass", password_char='*')],
            [Button("Login", bind_return_key=True), Button("Signup")]
        ]

        win = Window("Xpnsit", layout=layout)

        while login_active:  # <------------ Event Loop -----------------> #
            event, values = win.Read()

            if event is None:
                print("Exiting event loop")
                login_active = False
                self.app_state = False
                win.close()
                del win
                break

            if event == "Login":
                success = check_login_info(values["user"], values["pass"])

                if success == True:
                    print("Login Successful.")

                    self.user_details = get_user_details(values["user"])
                    self.user = NewUser(*self.user_details)

                    win.close()

                    self.Interface()
                    login_active = False
                else:
                    PopupError(
                        "ERROR: Username or password incorrect.\nPlease try again.")

            if event == "Signup":
                self.Signup()
Пример #7
0
def camera_mode(
    window: sg.Window,
    q: Queue,
    q2: Queue,
    lock2: threading.Lock,
    event: str,
    values: Union[Dict[Any, Any]],
):
    """A new GUI loop for camera mode, wait for Enter and Escape buttons"""
    QT_ENTER_KEY1 = "special 16777220"
    QT_ENTER_KEY2 = "special 16777221"
    while True:
        event, values = window.read(timeout=20)
        if event in (sg.WIN_CLOSED, "Exit"):
            break
        if event == "-SHOW CAMERA-":
            window["camera_image"].update(data=values[event][0])
            nm_faces = values[event][1]
        if (event in values and isinstance(values[event], list)
                and isinstance(values[event][0], bool) and values[event][0]):
            window[values[event][1]].update(values[event][2],
                                            text_color=values[event][3])
        elif (event in ("Return:36", "\r", QT_ENTER_KEY1,
                        QT_ENTER_KEY2)) and nm_faces > 1:
            window["text_instruction"].update(
                "Multiple faces detected. Press [Enter] to try again",
                text_color="white")
            # q.put("Pause")
            # try_again(window)
            # q.put("Continue")
        elif (event in ("Return:36", "\r", QT_ENTER_KEY1,
                        QT_ENTER_KEY2)) and nm_faces < 1:
            window["text_instruction"].update(
                "No faces detected. Press [Enter] to try again",
                text_color="white")
        elif (event in ("Return:36", "\r", QT_ENTER_KEY1,
                        QT_ENTER_KEY2)) and nm_faces == 1:
            window["text_instruction"].update(
                "Press [Enter] to accept image, [Escape] to try again",
                text_color="white")
            exit_outer_loop = False
            wait_for_signal = False
            while True:
                # The order of this if clause is important!
                if not wait_for_signal and lock2.acquire(False):
                    if accept_deny(window):
                        q.put("Done")
                        wait_for_signal = True
                        lock2.release()
                    else:
                        window["text_instruction"].update(
                            "Press [Enter] to capture image",
                            text_color="white")
                        lock2.release()
                        break
                elif wait_for_signal and not q2.empty():
                    q2.get()
                    return
                event, values = window.read(timeout=20)
                if event in (sg.WIN_CLOSED, "Exit"):
                    exit_outer_loop = True
                    break
                if event == "-SHOW CAMERA-":
                    window["camera_image"].update(data=values[event][0])
                    nm_faces = values[event][1]

            if exit_outer_loop:
                break
    window.close()
    exit(0)
Пример #8
0
             if ana_event == sg.WIN_CLOSED or ana_event == 'Ok':
                 break
             elif ana_event == 'remove':
                 try:
                     if ana_values.get('-del-') in dict1:
                         del dict1[values['-NEW-PASSWORD-']]
                         bloomf.dits.remove(ana_values.get('-del-'))
                         print(bloomf.dits)
                         sg.PopupOK("Update successfully")
                     else:
                         sg.PopupError(
                             "Update was unsuccessfully The Password not found ! , try again !  "
                         )
                 except:  # invalid data or mistake
                     pass
         filter_visual_window.close()
         pass
     except:
         pass
 elif event == 'Insert new password':
     try:
         if len(values['-NEW-PASSWORD-']) != 0:
             if bloomf.check_if_add(values['-NEW-PASSWORD-']):
                 sg.PopupError("inserted not successfully  This word[ " +
                               str(values['-NEW-PASSWORD-']) +
                               " ] in bloom filter , Try Again!")
             else:
                 bloomf.add(values['-NEW-PASSWORD-'])
                 sg.PopupOK(
                     "The password has been inserted successfully [ we Found overlap "
                     + str(bloomf.c) + "bits]")
Пример #9
0
                       pad=(0, 0))
            ]])
        ],
    ],
    pad=(0, 0))

col3 = Column([[
    Frame('Actions:', [[
        Column([[
            Button('Save'),
            Button('Clear'),
            Button('Delete'),
        ]],
               size=(450, 45),
               pad=(0, 0))
    ]])
]],
              pad=(0, 0))

layout = [[col1, col2], [col3]]

window = Window('Passwords', layout)

while True:
    event, values = window.read()
    print(event, values)
    if event is None:
        break

window.close()
Пример #10
0
def safe_close(window: sg.Window):
    """Closes and disposes of a window in a way that won't cause tkinter-related threading errors"""
    window.close()
    window.layout = None
    window.TKroot = None
    gc.collect()
Пример #11
0
    elif not f_window_active and event == '-FRIENDS-':
        f_window_active = True
        friends_list_layout = [
            [Frame('Your Friends', deepcopy(friends_frame_layout), font=('Courier', 12))],
            [Button('Add Friend', key='-ADD_FRIEND-', font=('Courier', 10))]
        ]
        f_window = Window('Friends', friends_list_layout)

    # while friends list page is active
    elif f_window_active:
        ev2, vals2 = f_window.read(timeout=100)

        if ev2 == sg.WIN_CLOSED:
            print("EXIT")
            f_window_active = False
            f_window.close()
            continue
        # if they click on friends list, set current friend to friend clicked.
        elif ev2 == '-FRIENDS_LIST-':
            for f in list_friends:
                if f['username'] == vals2['-FRIENDS_LIST-'][0]:
                    current_friend = f
                    window['-CURRENT_FRIEND-'].update(value=current_friend['username'])
                    window['-FRIEND_GOALS_LIST-'].update([i['title'] for i in back.getUsersGoals(f["userId"])])
                    window['-FRIEND_CAT-'].update(image_filename=getCatLevel(f["growthAmount"]))
                    # after choosing a friend, close window
                    f_window_active = False
                    f_window.close()
                    click_friend = True
            continue
Пример #12
0
class Xpnsit:
    
    def __init__(self):
        self.app_state: bool = True
    # <------------------- Misc. Functions (Layouts and Updaters and stuff) --------------------> #

    def Add_Trans(self, particulars: str, _type: str, amount: float, date: str):
        cursor = conn.cursor()

        try:
            cursor.execute(f"""
            INSERT INTO transactions (
                user_id,
                username,
                particulars,
                exp_type,
                amount,
                exp_date
            )
            VALUES (
                {self.user.user_id},
                '{self.user.uname}',
                '{particulars}',
                '{_type}',
                {amount},
                "{date}"
                );
            """)

            conn.commit()

            Popup("Transaction successfully added.")
            self.win.Refresh()

        except SQLErrors.ProgrammingError:
            PopupError("ERROR: Invalid details.\nRectify and try again.")

        cursor.close()

    def Create_Add_Trans_Layout(self):
        layout = [
            [T("New Transaction", font=("Helvetica", 18))],
            [T("NOTE:", font=("Helvetica", 20)), T(
                "All fields are required to be filled.")],
            [T("Particulars:"), Multiline("Enter details of transaction",
                                          autoscroll=True, key="Particulars")],
            [T("Transaction type:"), Combo(["Select", "Credit", "Debit"],
                                           "Select", readonly=True, key="new_type")],
            [T("Amount:"), Input(enable_events=True, key="amount")],
            [T("Date Of Transaction:"), Input("YYYY-MM-DD or use the button on the right",
                                              key="date"), CalendarButton("Select Date", target="date", format="%Y-%m-%d")],
            [Submit()]
        ]

        return layout

    def History(self):
        history_values, table, no_of_records = get_transactions(
            self.user.uname)

        self.slider = sg.Slider(
            range=(0, no_of_records),
            default_value=no_of_records,
            orientation='h',
            enable_events=True,
            key='slider'
        )

        layout = [
            [T("Transaction History", font=("Helvetica", 18))],
            [T("All your transactions, in one place. Right click any one to delete or edit it.")],
            [T('Number of records to be shown:'), self.slider],
            [T("Show records from "),
             Input(f"{year}-{month}-1", key="start_date", size=(10, 1)),
             CalendarButton("Start date", target="start_date", default_date_m_d_y=(
                 month, 1, year), button_color=("white", "green"), format="%Y-%m-%d"),
             T("to"),
             Input(f"{year}-{month}-{day}", key="end_date", size=(10, 1)),
             CalendarButton("End date", target="end_date", default_date_m_d_y=(
                 month, day, year), button_color=("white", "red"), format="%Y-%m-%d")
             ],
            [T("Type:"), Combo(["All", "Credit", "Debit"],
                               default_value="All", key="used_type", readonly=True)],
            [T("Sort by:"), Combo(["Name", "Amount", "Date of Transaction"],
                                  default_value="Name", key="sort_by", readonly=True), Combo(["Ascending", "Descending"], default_value="Ascending", key="asc_or_desc", readonly=True)],
            [table, Button("Refresh", button_color=(
                "white", "orange"), bind_return_key=True, key="refresh")],


        ]
        self.history_active = True

        return layout

    def update_table(self):
        start, end = self.values['start_date'], self.values["end_date"]
        aod = 'ASC' if self.values["asc_or_desc"] == "Ascending" else "DESC"
        sort = "particulars" if self.values["sort_by"] == "Name" else "amount" if self.values["sort_by"] == "Amount" else "exp_date"
        n = self.values["slider"] if self.event == 'slider' else 10000
        new_trans, new_table, new_number_of_trans = get_transactions(
            self.user.user_id,
            int(n),
            start,
            end,
            aod,  # a(scending)o(r)d(escending)
            sort
        )
        print(new_trans, new_table, new_number_of_trans)

        self.win["table"].Update(new_trans)  # Updates table

        # Updates max number of records to be possibly displayed
        self.win["slider"].Update(range=(0, new_number_of_trans+1))

        # Updates the default value of the slider to be the max
        self.slider.Update(value=new_number_of_trans)

        self.win.Refresh()

    def create_graph(self):

        fig, w, h = get_graph_values(
            self.values['a_start_date'],
            self.values['a_end_date'],
            self.values["a_type"],
        )
        self.figure_agg = draw_figure(
            self.win['canvas'].TKCanvas, fig)
    # <------------------ Main Screens --------------------> #

    def Login(self):
        login_active = True
        layout = [
            [T("Xpnsit", **heading_format)],
            [T("Username:"******"user")],
            [T("Password:"******"pass", password_char='*')],
            [Button("Login", bind_return_key=True), Button("Signup")]
        ]

        win = Window("Xpnsit", layout=layout)

        while login_active:  # <------------ Event Loop -----------------> #
            event, values = win.Read()

            if event is None:
                print("Exiting event loop")
                login_active = False
                self.app_state = False
                win.close()
                del win
                break

            if event == "Login":
                success = check_login_info(values["user"], values["pass"])

                if success == True:
                    print("Login Successful.")

                    self.user_details = get_user_details(values["user"])
                    self.user = NewUser(*self.user_details)

                    win.close()

                    self.Interface()
                    login_active = False
                else:
                    PopupError(
                        "ERROR: Username or password incorrect.\nPlease try again.")

            if event == "Signup":
                self.Signup()

    def Signup(self):
        signup_active = True

        layout = [
            [T("Signup for Xpnsit", **heading_format), ],
            [T("First Name:"), Input(size=(15, 1), key="f_name"), T(
                " "), T("Last Name:"), Input(size=(15, 1), key="l_name")],
            [T("Username:"******"user")],
            [T("Password:"******"pass", password_char="*")],
            [],
            [T(' '*40), Submit()]
        ]

        signup_win = Window("Xpnsit - Signup", layout=layout)

        while signup_active:  # <------------ Event Loop -----------------> #
            event, values = signup_win.Read()

            if event in (None, 'Exit'):
                signup_active = False
                login_active = True

            if event == 'Submit':
                self.vals = [values["user"], values["pass"],
                             values["mail"], values["f_name"], values["l_name"]]
                if not username_used(self.vals[0]):
                    create_account(*self.vals)

                    # <------------------- Confirmation of Insertion ------------------> #
                    success = check_login_info(values["user"], values["pass"])

                    if success == True:
                        print("Signup Successful.")
                        Popup(
                            "Signup Successful!",
                            "Exit this popup to return to the login page"
                        )
                        signup_win.close()
                        signup_active = False
                        login_active = True
                else:
                    PopupError("ERROR: Username already in usage",
                               title="Username already taken")

    def Dashboard(self):
        income, expenses = get_income_and_expense(self.user.uname)

        if (income, expenses) == (None, None):
            dash_layout = [
                [T(f"Welcome {self.user.first_name}")],
                [T("Looks like you have no transactions!\nGo add one in the Transactions tab.",
                   justification="center")],
                [T("-"*60, text_color="gray")],
            ]
        else:
            dash_layout = [
                [T(f"Welcome {self.user.first_name}")],
                [T(f"Your expenses for {month_name}-{year} are:"),
                 T(str(expenses), font=("Arial", 20))],
                [T(f"Your income for {month_name}-{year} is:"),
                 T(str(income), font=("Arial", 20))],
                [T("-"*80, text_color="gray")],
                [T("Net Profit/Loss:", font=("Segoe", 18)),
                 T(str(income-expenses), font=("Arial", 24))]
            ]

        dash_active = True

        return dash_layout

    def Transactions(self):
        transaction_layout = [
            [T("Transactions", font=("Helvetica", 18))],
            [TabGroup(
                [
                    [Tab("New Transaction", self.Create_Add_Trans_Layout())],
                    [Tab("History", self.History())]
                ]
            )]
        ]

        return transaction_layout

    def Analytics(self):
        fig, w, h = get_graph_values()


        analysis_layout = [
            [T("Analytics", font=("Helvetica", 18))],
            [T("Here you can find and generate graphs for your desired timeframe\nand observe trends in your balance.")],
            [T("Generate for records from "),
             Input(f"{year}-{month}-1", key="a_start_date", size=(10, 1)),
             CalendarButton("Start date", target="a_start_date", default_date_m_d_y=(
                 month, 1, year), button_color=("white", "green"), format="%Y-%m-%d"),
             T("to"),
             Input(f"{year}-{month}-{day}", key="a_end_date", size=(10, 1)),
             CalendarButton("End date", target="a_end_date", default_date_m_d_y=(
                 month, day, year), button_color=("white", "red"), format="%Y-%m-%d")
             ],
            [T("Type:"), Combo(["All", "Credit", "Debit"],
                               default_value="All", key="a_type", readonly=True)],
            [Button("Generate", button_color=("white", "orange"))],
            [Canvas(size=(w, h), key="canvas")]
        ]

        return analysis_layout

    def Interface(self):
        global graph_active


        layout = [
            [T("Xpnsit", **heading_format), T(" "*50), Button("Settings"),
             Button("Log Out", button_color=("black", "yellow"))],
            [TabGroup([
                [
                    Tab("Dashboard", self.Dashboard(
                    ), tooltip="See an overview of your account", font=("Arial", 12)),
                    Tab("Transactions", self.Transactions(
                    ), tooltip="View,add and delete transactions", font=("Arial", 12), key="transactions"),
                    Tab("Analytics", self.Analytics(
                    ), tooltip="Get a graphical insight to your spendings.", font=("Arial", 12))
                ]
            ],)]
        ]

        self.win = Window("Xpnsit v1.0", layout=layout, size = (590,640),resizable=True)
        while True:
            self.event, self.values = self.win.Read()
            self.figure_agg = self.create_graph()

            if self.event == "Log Out":
                logout = PopupYesNo("Are you sure you want to log out?")

                if logout == 'Yes':
                    sg.popup_quick_message(
                        "Okay, closing. Bye", auto_close_duration=10)
                    self.win.close()
                    # self.app_state = False
                    del self.win
                    break
            elif self.event is None:
                self.win.close()
                self.app_state = False
                del self.win
                break

            if self.event != sg.TIMEOUT_KEY:
                print(f"Event = {self.event}\nValues = {self.values}\n")


            if self.event == "Submit":
                _type = "CR" if self.values["new_type"] in (
                    "Credit", "Select") else "DR"
                self.Add_Trans(
                    self.values["Particulars"],
                    _type,
                    self.values["amount"],
                    self.values["date"])

            if self.event in ("slider", "refresh"):

                self.update_table()
                self.win.refresh()

            if self.event == "Generate":
                # self.create_graph()
                delete_figure_agg(self.figure_agg)
                self.create_graph()
                self.win.read()
                self.win.refresh()