Beispiel #1
0
    def __set_main_layout(self):
        '''Main function which setups the layout'''

        key = 0

        while key != ord('q'):
            h, w = self.__stdscr.getmaxyx()

            try:

                wrapper = textwrap.TextWrapper(width=w - 3)
                self.__stdscr.clear()
                utils.set_title(self.__stdscr, "LOGIN INSTRUCTIONS")
                start = self.__setup_array_text(
                    wrapper, w, 2, self.__app_password,
                    " Login Using App Password (Recommended):  ")
                start = self.__setup_array_text(
                    wrapper, w, start + 2, self.__less_secure,
                    " Enable less Secure apps :  ")
                # show the bottom bar
                BottomBar(self.__stdscr, self.options)
                self.__stdscr.refresh()
                key = self.__stdscr.getch()
            except:
                self.__stdscr.clear()
                wrapper = textwrap.TextWrapper(width=w - 2)
                error_msgs = wrapper.wrap(self.__screen_size_msg)
                for index, msg in enumerate(error_msgs):
                    x_pos = w // 2 - len(msg) // 2
                    y_pos = h // 2 + index
                    self.__stdscr.addstr(y_pos, x_pos, msg)
                self.__stdscr.refresh()
Beispiel #2
0
    def __set_email_list(self, isConfirm=False):
        '''To show the list of emails'''

        try:
            # Get the height and width of standard screen
            h, w = self.__stdscr.getmaxyx()

            self.__stdscr.clear()

            # setup title
            title = "Emails in " + self.__directory_name
            utils.set_title(self.__stdscr, title)

            # Start of emali list
            start = 2
            i = 0

            # Loop over the list until the screen or list is ended
            while start < h - 5 and i < len(self.__display_list):
                # Check if the list item is focused
                is_focused = i == self.__curr_position

                # Show the email
                start = self.__set_mail_item(start,
                                             self.__display_list[i]['Subject'],
                                             self.__display_list[i]['From'],
                                             self.__display_list[i]['Date'],
                                             h,
                                             w,
                                             is_focused=is_focused)
                i += 1

            # Setup the confirm email bottom menu if isConfirm is True
            if isConfirm:
                rectangle(self.__stdscr, h - 4, 0, h - 1, w - 2)
                title = " Do you want to delete email? ".upper()
                self.__stdscr.attron(curses.A_BOLD)
                self.__stdscr.addstr(h - 4, 1, title)
                self.__stdscr.attroff(curses.A_BOLD)
                self.__display_confirm_bottom_bar_menu()
            else:
                # Setup the bottom bar as screen was cleared
                self.__setup_bottom_bar()

            # Refresh the layout
            self.__stdscr.refresh()

            # Return the total number of shown emails
            return i
        except:
            utils.show_message(self.__stdscr,
                               "Something went wrong! Press 'q' to go back")
Beispiel #3
0
    def __set_default_screen(self, title, isMain=False, isConfirm=False):
        '''Setup Default Screen with title'''

        self.__stdscr.clear()
        utils.set_title(self.__stdscr, title)

        # Gives instructions to get different things done
        if isMain:
            self.__set_bottom_bar()

        # Need to call set main layout again as second function goes in infinite while loop
        if isConfirm:
            self.__set_main_layout(self.__body.splitlines())
            self.__set_confirm_email_bar()

        self.__stdscr.refresh()
Beispiel #4
0
    def __setup_layout(self, email, password, isEdit=None):
        '''To set the default layout of login screen'''

        self.__stdscr.clear()
        utils.set_title(self.__stdscr, "LOGIN")
        # Setting up title and padding rectangle
        rectangle(self.__stdscr, self.__y_start - 3, self.__x_start - 4,
                  self.__y_end, self.__x_end + 6)
        title = " Login to your account ".upper()
        self.__stdscr.attron(curses.A_BOLD)
        self.__stdscr.addstr(self.__y_start - 3,
                             self.__width // 2 - len(title) // 2 + 1, title)
        self.__stdscr.attroff(curses.A_BOLD)

        # Setting up view of email textbox
        self.__stdscr.attron(curses.A_BOLD)
        rectangle(self.__stdscr, self.__y_start, self.__x_start,
                  self.__y_start + self.__nol + 1, self.__x_end + 2)
        email_msg = " Email: "
        if isEdit == False:
            email_msg += "(Ctrl + G to save) "
        self.__stdscr.addstr(self.__y_start, self.__x_start + 1, email_msg)

        # Setting up view of password textbox
        # TODO: Later add asterisk to editbox
        pass_start = self.__y_start + self.__nol + 3
        rectangle(self.__stdscr, pass_start, self.__x_start,
                  pass_start + self.__nol + 1, self.__x_end + 2)
        password_msg = " Password: "******"(Ctrl + G to save) "
        self.__stdscr.addstr(pass_start, self.__x_start + 1, password_msg)
        self.__stdscr.attroff(curses.A_BOLD)

        # Add the email and password on screen
        self.__stdscr.addstr(self.__y_start + 1, self.__x_start + 2, email)
        self.__stdscr.addstr(self.__y_start + 5, self.__x_start + 2, password)

        # setup bottom bar
        BottomBar(self.__stdscr, self.__options)

        self.__stdscr.refresh()
Beispiel #5
0
    def __main(self):
        '''Main function which setups the whole login page'''

        curses.curs_set(0)
        self.__setup_layout("", "")
        key = 1
        email = ""
        password = ""
        utils.set_title(self.__stdscr, "LOGIN")
        utils.show_status_message(
            self.__stdscr,
            "Please read login instructions before logging in!!",
            time_to_show=2)
        while key != ord('q'):
            # If the key is e then make the email box active
            if key == ord('e'):
                email = self.__edit_box(email, "*" * len(password),
                                        self.__y_start + 1, self.__x_start + 2)

            # If the key is p then make the password box active
            elif key == ord('p'):
                password = self.__edit_box(email,
                                           "*" * len(password),
                                           self.__y_start + 5,
                                           self.__x_start + 2,
                                           isPass=True)

            elif key == ord('l'):
                # Authenticate
                self.__authenticate(email, password)

            # Show login instructions
            elif key == ord('i'):
                Instructions(self.__stdscr)

            # This is to refresh the layout when user resizes the terminal
            self.__set_values()
            self.__setup_layout(email, "*" * len(password))

            self.__stdscr.refresh()
            key = self.__stdscr.getch()
        sys.exit()
Beispiel #6
0
 def update_query(self, q_str, warning=False):
     q_str = utils.get_hms() + " " + q_str
     utils.set_title(q_str)
     if warning:
         ""
     # self.logTxt['fg'] = "#ff5643" if warning else "#0096FF"
     # self.logTxt['text'] = qStr
     tup = tuple([q_str])
     var_str = self.get_string_var()
     if utils.var_is_empty(var_str):
         new_tup = tup
     else:
         v = utils.var_to_list(var_str)
         if len(v):
             new_tup = utils.append_tup(tuple(v), tup)
         else:
             new_tup = tup
     new_arr = list(new_tup)
     tmp_arr = []
     for item in new_arr:
         if item:
             tmp_arr.append(item)
     tup = tuple(tmp_arr)
     self.set_string_var(tup)
Beispiel #7
0
    def __set_main_layout(self, body):
        '''Function which sets up the whole layout of main page'''

        from_start = 3
        from_block_total = 4
        subject_lines = 4
        attachment_block = 0

        h, w = self.__stdscr.getmaxyx()
        self.__stdscr.clear()
        utils.set_title(self.__stdscr, "Email Information")

        # From, To part of UI
        self.__stdscr.addstr(from_start, 1, "From: " + self.__from)
        rectangle(self.__stdscr, from_start - 1, 0, from_start + 1, w - 1)

        self.__stdscr.addstr(from_start + 2, 1, "Date: " + self.__date)
        rectangle(self.__stdscr, from_start - 1, 0, from_start + 3, w - 1)

        # Subject part of UI
        rectangle(self.__stdscr, from_start + from_block_total, 0,
                  from_start + from_block_total + subject_lines, w - 1)
        self.__stdscr.addstr(from_start + from_block_total, 2, " SUBJECT ")

        if len(self.__subject.strip()) == 0:
            self.__subject = "(no subject)"

        # used to divide subject in multiple lines
        wrapper = textwrap.TextWrapper(width=w - 3)
        elipsize = "....."
        subject_arr = wrapper.wrap(self.__subject)
        # show the wrapped text
        for index, subject in enumerate(subject_arr):
            if index == 2:
                # If there are more than 3 lines then add elipsize
                subject = subject[0:w - 10] + elipsize
                self.__stdscr.addstr(from_start + from_block_total + 1 + index,
                                     1, subject)
                break
            self.__stdscr.addstr(from_start + from_block_total + 1 + index, 1,
                                 subject)

        # If attachment is present show the block for attachment
        if self.__is_attachment_present == True:
            attachment_block = 2
            attachment_start = from_start + from_block_total + subject_lines

            # Convert attachment array to string
            filename_string = "  ".join(
                name for name in self.__attachment_filenames)
            # Wrap the attachment
            attach_arr = wrapper.wrap(filename_string)

            # Show the attachments
            for item in attach_arr:
                self.__stdscr.addstr(attachment_start + attachment_block, 2,
                                     item)
                attachment_block += 1

            rectangle(self.__stdscr, attachment_start + 1, 0,
                      attachment_start + attachment_block, w - 2)
            self.__stdscr.addstr(attachment_start + 1, 2, " Attachments: ")

        # Body part of UI
        body_start = from_start + from_block_total + subject_lines + attachment_block
        rectangle(self.__stdscr, body_start + 1, 0, h - 5, w - 1)
        self.__stdscr.addstr(body_start + 1, 2, " BODY ")

        # Divide body into parts

        max_lines = (h - 5) - (body_start + 1) - 2
        body_start += 2
        body_end = body_start + max_lines
        for item in body:
            body_arr = wrapper.wrap(item)
            if body_start > body_end:
                break
            for body in body_arr:
                # ellipsize the text if it can't be fit into the box
                if body_start > body_end:
                    break
                self.__stdscr.addstr(body_start, 1, body)
                body_start += 1
        # return max number of lines
        return max_lines
Beispiel #8
0
 def set_title2(self, title, warning=False):
     new_title = utils.get_hms() + " " + title
     utils.set_title(self.titlePrefix + "-" + new_title)
     self.update_query(new_title, warning)
     print(new_title)