def return_to_stims_deletion(main, stimList, numStims, stimScrollingArea, remove_x): """ (tkinter.Tk, dict, int, tkinter.Frame, img) -> (none) After confirming with the user that the stimuli entries will be deleted, this function begins deleting the current entries and creates the specified number of stimuli. """ warningStims.destroy() ##Extract the number from the string. numStims = int(numStims.replace(' ', '')) ##Destroy the old frame. stimScrollingArea[0].destroy() ##Clear list for specified entries. stimList.clear() ##Make a new frame capable of scrolling to the new entry boxes specified ##by the user. stimScrollingArea[0] = vertSuperscroll.Scrolling_Area(main) stimScrollingArea[0].pack(expand = 1, fill=BOTH) for i in range(numStims): stimEntryFrame = Frame(stimScrollingArea[0].innerframe) stimEntry = Entry(stimEntryFrame) stimDeleteButton = Button(stimEntryFrame, image = remove_x, border = 0, highlightthickness = 0, command = lambda boxIndex=i: remove_stim(main, stimList, stimScrollingArea, boxIndex, remove_x)) stimList.append(stimEntry) stimEntry.pack(side = LEFT) stimDeleteButton.pack(side = RIGHT) stimEntryFrame.pack(side = TOP, pady = 10)
def remove_agent(main, agentFrames, agentScrollingArea, boxIndex, remove_x): """ (tkinter.Tk, dict, tkinter.Frame, int, tkinter.PhotoImage) -> (none) Removes the specified agent if the delete entry button was pressed. Also updates the scrolling area to adapt to this change. """ ##Make a new frame capable of scrolling to the new entry box. agentScrollingAreaTemp = vertSuperscroll.Scrolling_Area(main) agentScrollingAreaTemp.pack(expand=1, fill=BOTH, pady=(0, 80)) ##Delete agent at specified index in both lists. del agentFrames['agentNames'][boxIndex] del agentFrames['agentBev'][boxIndex] ##Generate the agents. for i in range(len(agentFrames['agentNames'])): ##Declare a frame in the scrolling area. agentEntryFrame = Frame(agentScrollingAreaTemp.innerframe, height=80) ####Declare widgets in the new frame. agentLabel = Label(agentEntryFrame, text='Agent Name:') agentEntry = Entry(agentEntryFrame, width=40) agentBevLabel = Label(agentEntryFrame, text='Agent Behaviour:') agentBevEntry = Entry(agentEntryFrame, width=40) agentDeleteButton = Button( agentEntryFrame, image=remove_x, border=0, command=lambda boxIndex=i: remove_agent( main, agentFrames, agentScrollingArea, boxIndex, remove_x)) ##Insert widgets in their respective data structures. agentEntry.insert( 0, agentFrames['agentNames'][i].get()) ##Get previous text. agentFrames['agentNames'][i] = agentEntry agentBevEntry.insert( 0, agentFrames['agentBev'][i].get()) ##Get previous text. agentFrames['agentBev'][i] = agentBevEntry ##Pack new frame/widgets. agentLabel.pack(side=TOP, anchor=W) agentEntry.pack(side=TOP, anchor=W) agentDeleteButton.pack(in_=agentEntryFrame, side=RIGHT, anchor=N, padx=20) agentBevLabel.pack(side=TOP, anchor=W) agentBevEntry.pack(side=TOP, anchor=W) agentEntryFrame.pack(side=TOP, anchor=W, fill=X, pady=20) ##Destroy old frame agentScrollingArea[0].destroy() ##Assign new frame agentScrollingArea[0] = agentScrollingAreaTemp
def remove_stim(main, stimList, stimScrollingArea, boxIndex, remove_x): """ (tkinter.Tk, list, tkinter.Frame, int, tkinter.PhotoImage) -> (none) Removes the specified stimuli entry box if the delete entry button was pressed. Also updates the scrolling area to adapt to this change. """ ##Get screen width to make dimensions relative to that value. screenWidth = main.winfo_screenwidth() ##Make a new frame capable of scrolling to the new entry box. stimScrollingAreaTemp = vertSuperscroll.Scrolling_Area(main) stimScrollingAreaTemp.canvas.config(height=int(main.winfo_screenheight() / 4.32)) stimScrollingAreaTemp.pack(expand=1, fill=BOTH) ##Delete entry at specified index in the frame lsit and stimuli list. del stimList[boxIndex] ##Generate the boxes. for i in range(len(stimList)): ##Declare a frame in the scrolling area. stimEntryFrame = Frame(stimScrollingAreaTemp.innerframe, height=27) ##Declare widgets in the frame. stimEntry = Entry(stimEntryFrame) stimDeleteButton = Button( stimEntryFrame, image=remove_x, border=0, command=lambda boxIndex=i: remove_stim( main, stimList, stimScrollingArea, boxIndex, remove_x)) ##Insert the widget in the data structure. stimEntry.insert(0, stimList[i].get()) ##Get previous text. stimList[i] = stimEntry ##Pack new frame/widgets. stimEntryFrame.pack(side=TOP, pady=10) stimEntry.pack(side=LEFT) stimDeleteButton.pack(side=RIGHT) ##Destroy old frame stimScrollingArea[0].destroy() ##Assign new frame stimScrollingArea[0] = stimScrollingAreaTemp
def set_CBS_data(window, agentNames, allBevDict, allAgentCBS, allTextBoxCBSFrame, allFormatCBS, allRadioButtons, allConcreteScrollingArea, allEntriesCBS, allTextBoxCBS, generatedCBS, moreThanOneAgent, boxIndex): oldEntries = allEntriesCBS[boxIndex] oldTextBoxCBS = allTextBoxCBS[boxIndex] ##If no concrete behaviours were yet generated for the behaviours, ##then we generate the rows for the CBS. if generatedCBS[boxIndex] == False: ##Frame for the two radio buttons. allFormatCBS[boxIndex] = Frame(window) ##Create a frame for the text box. allTextBoxCBSFrame[boxIndex] = Frame(window) ##Declaring x and y scrollbars for the CBS text box. xscrollbarCBS = Scrollbar(allTextBoxCBSFrame[boxIndex], orient=HORIZONTAL) xscrollbarCBS.grid(row=1, column=0, sticky=N + S + E + W) yscrollbarCBS = Scrollbar(allTextBoxCBSFrame[boxIndex]) yscrollbarCBS.grid(row=0, column=1, sticky=N + S + E + W) content = StringVar() ##Create the text box widget for the CBS page. allTextBoxCBS[boxIndex] = Text( allTextBoxCBSFrame[boxIndex], wrap=NONE, xscrollcommand=xscrollbarCBS.set, yscrollcommand=yscrollbarCBS.set, width=int(window.winfo_screenwidth() / 33), height=int(window.winfo_screenheight() / 52)) allTextBoxCBS[boxIndex].grid(row=0, column=0) xscrollbarCBS.config(command=allTextBoxCBS[boxIndex].xview) yscrollbarCBS.config(command=allTextBoxCBS[boxIndex].yview) ##Pack frame for the radio Buttons allFormatCBS[boxIndex].pack(side=BOTTOM, anchor=S, expand=True) ##Set a variable that the radio Buttons share to determine what happens when ##one of them is pressed. whichRadio = StringVar() whichRadio.set('Rows') radioRowsCBS = Radiobutton( window, text='CBS Rows', variable=whichRadio, value='Rows', state='disabled', command=lambda: change_CBS( radioRowsCBS, radioBoxCBS, allConcreteScrollingArea[ boxIndex], allTextBoxCBSFrame[boxIndex], whichRadio)) radioRowsCBS.pack(in_=allFormatCBS[boxIndex], side=LEFT) ##Pack the Buttons ##Radio button for the alternate style of entering concrete behaviours. radioBoxCBS = Radiobutton( window, text='CBS Box', variable=whichRadio, value='Box', command=lambda: change_CBS( radioRowsCBS, radioBoxCBS, allConcreteScrollingArea[ boxIndex], allTextBoxCBSFrame[boxIndex], whichRadio)) radioBoxCBS.pack(in_=allFormatCBS[boxIndex], side=RIGHT) if allRadioButtons[ boxIndex] != None: ##If True, this means the agent use to exist as multiple or single. radioRowsCBS.config( state=allRadioButtons[boxIndex][0].cget("state")) radioBoxCBS.config( state=allRadioButtons[boxIndex][1].cget("state")) whichRadio.set(allRadioButtons[boxIndex][2].get()) ##Pack the two radio buttons in allRadioButtons as a tupple, including whichRadio. allRadioButtons[boxIndex] = (radioRowsCBS, radioBoxCBS, whichRadio) ##Pack new labels for CBS. allAgentCBS[boxIndex] = Label(window, text=agentNames[boxIndex] + ' =>') allAgentCBS[boxIndex].pack(side=TOP, anchor=W) ##Create a vertical scrolling area for the rows. allConcreteScrollingArea[boxIndex] = [ vertSuperscroll.Scrolling_Area(window, width=1, height=1) ] allConcreteScrollingArea[boxIndex][0].pack(expand=1, fill=BOTH) if oldEntries != None: ##If True, this means the agent use to exist as multiple or single. recreate_CBS_entries( allBevDict[boxIndex + 1], allEntriesCBS[boxIndex], allConcreteScrollingArea[boxIndex][0].innerframe) if whichRadio.get() == 'Box': allConcreteScrollingArea[boxIndex][0].pack_forget() allTextBoxCBSFrame[boxIndex].pack() else: ##Call create_CBS_entries() to create the rows in the CBS scrolling area. allEntriesCBS[boxIndex] = create_CBS_entries( allBevDict[boxIndex + 1], allConcreteScrollingArea[boxIndex][0].innerframe) ##Save the number of CBS in the allBevDict dictionary at key (0, 0) since ##that coordinate is unused. allEntriesCBS[boxIndex][0, 0] = len(allBevDict[boxIndex + 1]) ##Set generatedCBS to True. generatedCBS[boxIndex] = True ##If concrete behaviours page was already generated, it must be modified ##if necessary to adapt to changes made on previous pages. else: ##Get a copy of the entries to check if any modifications are necessary once fix_CBS() is called. oldEntriesCBS = allEntriesCBS[boxIndex].copy() ##fix_CBS() function will modify the data scructures related to CBS. allEntriesCBS[boxIndex] = fix_CBS( allBevDict[boxIndex + 1], allConcreteScrollingArea[boxIndex][0].innerframe, allEntriesCBS[boxIndex]) if oldEntriesCBS != allEntriesCBS[boxIndex]: ##Means changes were made. ##Create a temporary scrolling area that will be later used as the main scrolling ##area. This is done in order to destroy the previous scrolling area ##at the end of the else statement once all the necessary widgets were ##saved from the old frame. concreteScrollingAreaTemp = vertSuperscroll.Scrolling_Area( window, width=1, height=1) ##calling recreate_CBS_entries() to recreate the CBS rows in the new ##temporary frame. allEntriesCBS[boxIndex] = recreate_CBS_entries( allBevDict[boxIndex + 1], allEntriesCBS[boxIndex], concreteScrollingAreaTemp.innerframe) ##Destroy the old scrolling area for the CBS. allConcreteScrollingArea[boxIndex][0].destroy() ##Asign to the new scrolling area. allConcreteScrollingArea[boxIndex] = [concreteScrollingAreaTemp] if not moreThanOneAgent: ##Re-pack title labels if True. allAgentCBS[boxIndex].pack(side=TOP, anchor=W) allFormatCBS[boxIndex].pack(side=BOTTOM, anchor=S, expand=True) else: ##more than one agent. allRadioButtons[boxIndex][0].config(command=lambda: change_CBS( allRadioButtons[boxIndex][0], allRadioButtons[boxIndex][1], allConcreteScrollingArea[boxIndex], allTextBoxCBSFrame[ boxIndex], allRadioButtons[boxIndex][2])) allRadioButtons[boxIndex][1].config(command=lambda: change_CBS( allRadioButtons[boxIndex][0], allRadioButtons[boxIndex][1], allConcreteScrollingArea[boxIndex], allTextBoxCBSFrame[ boxIndex], allRadioButtons[boxIndex][2])) ##Now pack the correct CBS layout. if allRadioButtons[boxIndex][2].get( ) == 'Rows': ##Repack the scrolling area if the user was previously using that display. ##Pack the new scrolling area and the new frame for the CBS. concreteScrollingAreaTemp.pack(expand=1, fill=BOTH) else: ##Repack the text box. allTextBoxCBSFrame[boxIndex].pack() else: ##No changes to tables. if not moreThanOneAgent: ##Re-pack the labels when one agent only. allAgentCBS[boxIndex].pack(side=TOP, anchor=W) allFormatCBS[boxIndex].pack(side=BOTTOM, anchor=S, expand=True) ##Now pack the correct CBS layout. if allRadioButtons[boxIndex][2].get( ) == 'Rows': ##Repack the scrolling area if the user was previously using that display. ##Pack the new scrolling area and the new frame for the CBS. allConcreteScrollingArea[boxIndex][0].pack(expand=1, fill=BOTH) else: ##Repack the text box. allTextBoxCBSFrame[boxIndex].pack()
image=left_arrow, border=0, highlightthickness=0) """Label and Buttons exclusive to page 1.""" ##Frame for the stim number Label, button and entry box (to specify ##a number of stimuli to be generated). stimFrame = Frame(main) stimFrame.pack(side=BOTTOM, anchor=S, expand=True, pady=50) ##Title for the stimuli on page 1. stimTitle = Label(main, text='Please Enter The Stimuli', font=label_font) stimTitle.pack(side=TOP, padx=(0, int(screenWidth / 240))) ##The scrolling area is at index zero of the stimScrollingArea list, this way, ##the scrolling area can be passed by reference and be modified by other functions. stimScrollingArea = [vertSuperscroll.Scrolling_Area(main)] stimScrollingArea[0].canvas.config(height=windowSize / 2) stimScrollingArea[0].pack(expand=1, fill=BOTH) ##Label, button and entry box to generate specified number of stimuli. enterStimLabel = Label(main, text='Enter # of stimuli : ', font=label_font) enterStimLabel.pack(in_=stimFrame, side=LEFT) enterStimButton = Button( main, image=check_mark, border=0, command=lambda: specify_stim(main, stimList, enterStimBox.get( ), stimScrollingArea, remove_x, return_arrow), highlightthickness=0) enterStimButton.pack(in_=stimFrame, side=RIGHT, anchor=N)
def add_stim(main, stimList, stimScrollingArea, remove_x): """ (tkinter.Tk, list, tkinter.Frame, tkinter.PhotoImage) -> (none) Adds a stimuli entry box to the addStim page, and updates the scrolling area. """ ##Make a new frame capable of scrolling to the new entry box. stimScrollingAreaTemp = vertSuperscroll.Scrolling_Area(main) stimScrollingAreaTemp.canvas.config(height=int(main.winfo_screenheight() / 4.32)) stimScrollingAreaTemp.pack(expand=1, fill=BOTH) ##Generate the boxes. for i in range(len(stimList)): ##Declare a frame in the scrolling area. stimEntryFrame = Frame(stimScrollingAreaTemp.innerframe, height=27) ##Declare widgets in the frame. stimEntry = Entry(stimEntryFrame) stimDeleteButton = Button( stimEntryFrame, image=remove_x, border=0, command=lambda boxIndex=i: remove_stim( main, stimList, stimScrollingArea, boxIndex, remove_x)) ##Insert widget in the data structure. stimEntry.insert(0, stimList[i].get()) ##Get previous text. stimList[i] = stimEntry ##Pack new frame/widgets. stimEntryFrame.pack(side=TOP, pady=10) stimEntry.pack(side=LEFT) stimDeleteButton.pack(side=RIGHT) ##Assign a new entry box to the scrolling area by making a new frame. stimEntryFrame = Frame(stimScrollingAreaTemp.innerframe, height=27) ####Declare widgets in the new frame. stimEntry = Entry(stimEntryFrame) stimDeleteButton = Button( stimEntryFrame, image=remove_x, border=0, command=lambda boxIndex=len(stimList): remove_stim( main, stimList, stimScrollingArea, boxIndex, remove_x)) ##Pack new frame/widgets. stimEntryFrame.pack(side=TOP, pady=10) stimEntry.pack(side=LEFT) stimDeleteButton.pack(side=RIGHT) ##Add the new entry and the frame to their respective list. stimList.append(stimEntry) ##Destroy old frame. stimScrollingArea[0].destroy() ##Assign new frame. stimScrollingArea[0] = stimScrollingAreaTemp
def add_agent(main, agentFrames, agentScrollingArea, remove_x): """ (tkinter.Tk, dict, tkinter.Frame, tkinter.PhotoImage) -> (none) Adds a frame to hold a new agent and its behaviour in the addBev page, and updates the scrolling area. """ ##Make a new frame capable of scrolling to the new agent frames. agentScrollingAreaTemp = vertSuperscroll.Scrolling_Area(main) agentScrollingAreaTemp.pack(expand=1, fill=BOTH, pady=(0, 80)) ##Generate the agents. for i in range(len(agentFrames['agentNames'])): ##Declare a frame in the scrolling area. agentEntryFrame = Frame(agentScrollingAreaTemp.innerframe, height=80) ####Declare widgets in the new frame. agentLabel = Label(agentEntryFrame, text='Agent Name:') agentEntry = Entry(agentEntryFrame, width=40) agentBevLabel = Label(agentEntryFrame, text='Agent Behaviour:') agentBevEntry = Entry(agentEntryFrame, width=40) agentDeleteButton = Button( agentEntryFrame, image=remove_x, border=0, command=lambda boxIndex=i: remove_agent( main, agentFrames, agentScrollingArea, boxIndex, remove_x)) ##Insert widgets in their respective data structures. agentEntry.insert( 0, agentFrames['agentNames'][i].get()) ##Get previous text. agentFrames['agentNames'][i] = agentEntry agentBevEntry.insert( 0, agentFrames['agentBev'][i].get()) ##Get previous text. agentFrames['agentBev'][i] = agentBevEntry ##Pack new frame/widgets. agentLabel.pack(side=TOP, anchor=W) agentEntry.pack(side=TOP, anchor=W) agentDeleteButton.pack(in_=agentEntryFrame, side=RIGHT, anchor=N, padx=20) agentBevLabel.pack(side=TOP, anchor=W) agentBevEntry.pack(side=TOP, anchor=W) agentEntryFrame.pack(side=TOP, anchor=W, fill=X, pady=20) ##Assign a the new entry boxes to the scrolling area by making a new frame. agentEntryFrame = Frame(agentScrollingAreaTemp.innerframe, height=80) ####Declare widgets in the new frame. agentLabel = Label(agentEntryFrame, text='Agent Name:') agentEntry = Entry(agentEntryFrame, width=40) agentBevLabel = Label(agentEntryFrame, text='Agent Behaviour:') agentBevEntry = Entry(agentEntryFrame, width=40) agentDeleteButton = Button( agentEntryFrame, image=remove_x, border=0, command=lambda boxIndex=len(agentFrames['agentNames']): remove_agent( main, agentFrames, agentScrollingArea, boxIndex, remove_x)) ##Pack new frame/widgets. agentLabel.pack(side=TOP, anchor=W) agentEntry.pack(side=TOP, anchor=W) agentDeleteButton.pack(in_=agentEntryFrame, side=RIGHT, anchor=N, padx=20) agentBevLabel.pack(side=TOP, anchor=W) agentBevEntry.pack(side=TOP, anchor=W) agentEntryFrame.pack(side=TOP, anchor=W, fill=X, pady=20) ##Add the new entries to their respective list. agentFrames['agentNames'].append(agentEntry) agentFrames['agentBev'].append(agentBevEntry) ##Destroy old frame. agentScrollingArea[0].destroy() ##Assign new frame. agentScrollingArea[0] = agentScrollingAreaTemp