#!/usr/bin/env python ## CURSES BASIC-MAIL GUI # This is the Basic-Mail program, a basic email client written in python # with a curses interface. # # To Run: Go to the Basic-Mail directory and type "python Basic-Mail.py", # without the quotes. # If it doesn't open, make sure that the size of the console window # is at least 80 x 30 pixels. ## ## Filename: interface.py ## # This file contains functions that work with tabs. ## ## IMPORTS ## import curses, curses.ascii, curses.panel # Curses imports import traceback, os, sys, select, string # Random imports from variables import * # Imports all variables from draw import * # Imports the window drawing functions ## Function: Searches to see if given tab is already open. ## If the tab is open, it returns the number of the tab ## If not, it returns 111 to indicate false. ## (Returning 0 for false would screw with tabs[0]) def find_tab(tab_name): tab_count = 0 while tab_count < len(tabs[0]): if tabs[0][tab_count][1:-3] == tab_name: return tab_count tab_count += 1 return 111 ## Function: Selects a specific tab. ## Returns the active tab. ## Usage: active_tab = select_tab(tab_number) def select_tab(count): select_bar(tab_bar,tabs,count,10,10,0) # Opens appropriate panel in the main window. if count == 0: tab1.top() active_tab = tab1 if count == 1 and len(tabs[0])>1: tab2.top() active_tab = tab2 if count == 2 and len(tabs[0])>2: tab3.top() active_tab = tab3 if count == 3 and len(tabs[0])>3: tab4.top() active_tab = tab4 if count == 4 and len(tabs[0])>4: tab5.top() active_tab = tab5 curses.panel.update_panels() curses.doupdate() draw_screen(active_tab) return active_tab ## Function: Opens a tab, either by selecting it or creating it. ## Returns the selected tab. ## Usage: active_tab = open_tab("Inbox") def open_tab(tab_name): # Checks if the tab is already open tab_count = find_tab(tab_name) # If it is, select it if tab_count != 111: return select_tab(tab_count) # Otherwise, open a new tab else: # Checks for too many open tabs from pop_up import create_pop_up if len(tabs[0]) == 5: useless = create_pop_up(2) else: # Adds the new tab to the tab array tabs[0].append("\%s:%s/" % (str(tab_name), str(len(tabs[0])+1))) return select_tab(len(tabs[0])-1) ## Function: Writes to a tab. ## You can give it a string or a list. ## Usage: win1 = write_tab(win1, word_list) def write_tab(window,string): window.addstr(10,50,string) return window