def __init__(self, winTitle: str, Roster): self.title = winTitle self.mainWindow = tk.Tk() global USER_VIEW_OPEN USER_VIEW_OPEN = 1 self.canvas = tk.Label(self.mainWindow) self.button = tk.Button(self.canvas, text="EXIT", width=10, height=2, command=self.closeWindow) self.text = tk.Text(self.canvas, height=1, width=70, font=('Courier', 16)) self.canvas.pack() self.text.pack() self.button.pack() self.mainWindow.title(self.title) # set window title (grey bar at top) self.mainWindow.attributes( "-topmost", True) # keep the window in front of all other windows self.mainWindow.protocol( "WM_DELETE_WINDOW", self.closeWindow) # calls closeWindow() if user clicks red 'x' # for backend self.Roster = Roster # creat a golable Roster which is a quene of a Student object self.onDeck = initDeck( self.Roster ) # 4 student object on deck, current_Index will be the index self.current_Index = 0 # the picked student's index in onDeck queue self.flagQ = classQueue() # a list of student been flag self.path = "" # path for the source file
def initDeck(Roster): # given a Roster, # return onDeck Quene: 4 student object onDeck = classQueue() for i in range(4): pickOneStudent(onDeck, Roster) return onDeck
def main(): # init all the imformation Roster = initRoster() # # 4 student object on deck, current_Index will be the index onDeck = initDeck(Roster) # the picked student's index in onDeck queue current_Index = 0 # a list of student been flag flagQ = classQueue() # print(OnDeckString(current_Index, onDeck)) print("\n\n############ sucessfuly import!! ###################\n\n") # onDeck = initDeck(Roster) # print(OnDeckString(current_Index, onDeck)) # 1 # current_Index = right(current_Index, onDeck, Roster) # print(OnDeckString(current_Index, onDeck)) # 0 # current_Index = left(current_Index, onDeck, Roster) # # 3 # current_Index = left(current_Index, onDeck, Roster) # # 2 # current_Index = left(current_Index, onDeck, Roster) # # 1 # current_Index = left(current_Index, onDeck, Roster) print(OnDeckString(current_Index, onDeck)) current_Index = up(current_Index, onDeck, Roster, flagQ) print(OnDeckString(current_Index, onDeck)) flagQ.printQ() current_Index = right(current_Index, onDeck, Roster) # print(OnDeckString(current_Index, onDeck)) current_Index = down(current_Index, onDeck, Roster) print(OnDeckString(current_Index, onDeck)) # Roster.printQ() for i in range(Roster.length): print("Queue at index", i, "has", end=" ") sd = Roster.queue[i] print(sd.fname, sd.numCalled, sd.numFlags)
def initRoster(): # init a Roster which is a quene of a Student objects Roster = classQueue() # delet later # replace with a function later student1 = Student("Lucas", "Hyatt", 951550079, "*****@*****.**", "loo-kiss", True, 0, 0, []) student2 = Student("Maura", "McCabe", 111222333, "*****@*****.**", "mor-uh", True, 0, 0, []) student3 = Student("Noah", "Tigner", 123456789, "*****@*****.**", "no-uh", False, 0, 0, []) student4 = Student("Jimmy", "Lam", 987654321, "*****@*****.**", "ji-mee", True, 0, 0, []) student5 = Student("Yin", "Jin", 123789456, "*****@*****.**", "yi-n", False, 0, 0, []) student6 = Student("Anthony", "Hornoff", 123456789, "*****@*****.**", "hor-noff", True, 0, 0, []) student7 = Student("Lucas1", "Hyatt", 951550076, "*****@*****.**", "loo-kiss", True, 0, 0, []) student8 = Student("Maura1", "McCabe", 111222336, "*****@*****.**", "mor-uh", True, 0, 0, []) student9 = Student("Noah1", "Tigner", 123456786, "*****@*****.**", "no-uh", False, 0, 0, []) student10 = Student("Jimmy1", "Lam", 987654326, "*****@*****.**", "ji-mee", True, 0, 0, []) student11 = Student("Yin1", "Jin", 123789455, "*****@*****.**", "yi-n", False, 0, 0, []) student12 = Student("Anthony1", "Hornoff", 123456786, "*****@*****.**", "hor-noff", True, 0, 0, []) Roster.enqueue(student1) Roster.enqueue(student2) Roster.enqueue(student3) Roster.enqueue(student4) Roster.enqueue(student5) Roster.enqueue(student6) Roster.enqueue(student7) Roster.enqueue(student8) Roster.enqueue(student9) Roster.enqueue(student10) Roster.enqueue(student11) Roster.enqueue(student12) return Roster
def __init__(self, winTitle: str): self.title = winTitle self.mainWindow = tk.Tk() self.text = tk.Text(self.mainWindow, height=1, width=60, font=('Courier', 16)) self.mainWindow.title(self.title) # set window title (grey bar at top) self.mainWindow.attributes( "-topmost", True) # keep the window in front of all other windows # for backend self.Roster = initRoster( ) # creat a golable Roster which is a quene of a Student object self.onDeck = initDeck( self.Roster ) # 4 student object on deck, current_Index will be the index self.current_Index = 0 # the picked student's index in onDeck queue self.flagQ = classQueue() # a list of student been flag
def inputFile(firstTime=False, delimiter=None): ''' This method reads student data line by line from a roster file. Each line is parsed and used to create a Student object, which is added to the global STUDENTQUEUE data structure. Args: firstTime, a boolean representing if this method has been called before delimiter, a string. By default, lines are split by whitespace, but commas may also be specified Returns: ''' global ROSTERPATH, STUDENTQUEUE if not ROSTERPATH or not firstTime: if len(STUDENTQUEUE.queue) > 0: # Warn the user before overwriting STUDENTQUEUE messageBox = tk.messagebox.askquestion( 'Load New Data', 'Are you sure you want to load in a new file?', icon='warning') if messageBox == 'no': return # Prompt the user to select a txt file filepath = filedialog.askopenfilename(initialdir="./..", title="Select File") if filepath == '': return if 'config.txt' in filepath: print("can't open configuration file as a roster") GUI.displayMessage('Not a roster file', 'config.txt is not a valid roster') ROSTERPATH = None setSettings(None) return ROSTERPATH = filepath setSettings(filepath) STUDENTQUEUE = classQueue() # Overwrite the queue if ROSTERPATH[-4:] != '.txt' or ".txt" not in ROSTERPATH: print('File must be a text file') GUI.displayMessage('Unable to open file', 'File must be a text file') try: with open(ROSTERPATH, "r") as f: next(f) # skip first line of roster file (comments) for i, line in enumerate(f): elements = line.strip().split(delimiter) # print(elements) try: fname = str(elements[0]) lname = str(elements[1]) uoID = int(elements[2]) email = str(elements[3]) phonetic = str(elements[4]) reveal = 0 if len(elements) >= 9: numCalled = int(elements[6]) numFlags = int(elements[7]) # Sort Dates Chronologically dates = list(" ".join(elements[8:]).replace( "[", "").replace("]", "").split()) dates = [ datetime.strptime(date, "%d/%m/%y") for date in dates ] dates.sort(key=lambda date: date) dates = [date.strftime("%d/%m/%y") for date in dates] # dates = '[' + ' '.join(dates) + ']' else: numCalled = 0 numFlags = 0 dates = [] # Create Student object, Insert into Queue STUDENTQUEUE.enqueue( Student(fname, lname, uoID, email, phonetic, reveal, numCalled, numFlags, dates)) except (ValueError, IndexError): print("Line {} of roster file is formatted incorrectly". format(i + 1)) # Reset these in case of a bad input file ROSTERPATH = None setSettings(None) # display error box heading = 'Unable to open file' msg = 'Line {} is formatted incorrectly'.format(i + 1) GUI.displayMessage(heading, msg) return except FileNotFoundError: print('File Can\'t Be Opened') # Reset these in case of a bad input file ROSTERPATH = None setSettings(None) # display error box heading = 'Unable to open file' msg = "File Cannot Be Opened" GUI.displayMessage(heading, msg) return except: print('File Can\'t Be Opened') # Reset these in case of a bad input file ROSTERPATH = None setSettings(None) # display error box heading = 'Unable to open file' msg = "File Cannot Be Opened" GUI.displayMessage(heading, msg) return
Author: Jimmy Lam Last Modified: 2/2/20 ''' '''======================================Imports==========================================''' import tkinter as tk from tkinter import filedialog, Text, messagebox import tkinter.ttk as ttk import tkinter.font import os import GUI import sys from datetime import datetime from backend.objects import Student, classQueue '''======================================Functions==========================================''' STUDENTQUEUE = classQueue() ROSTERPATH = "" # global roster path, set by inputFile def switch_view(): global ROSTERPATH if ROSTERPATH is not None and 'config.txt' in ROSTERPATH: ROSTERPATH = '' if not GUI.userViewOpen( ): # prevent 2 user view windows from opening simultaneously if ROSTERPATH != '' and ROSTERPATH is not None: GUI.testcontrol(ROSTERPATH, STUDENTQUEUE) else: messageBox = tk.messagebox.askokcancel(
def testimport(): Roster = classQueue() importFun()