Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ProfessorHomeDirectory
*.pyc
omsi_answer*
*.png
.idea/
67 changes: 51 additions & 16 deletions OmsiGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import filecmp
import time
import OmsiClient

import configparser
import pdb

# This is the GUI portion of the OMSI application.
Expand All @@ -28,6 +28,8 @@ def __init__(self, master):
self.pdfCmd = None
self.OmsiClient = None
self.version = None
self.configfile = "config.ini"
self.loadprefs() #Needs to be after widgets is called

def donothing(self):
filewin = Toplevel(self.parent)
Expand Down Expand Up @@ -480,6 +482,12 @@ def validate(self):
if not self.host or not self.port or not self.email \
or not self.examID:
raise ValueError
# Update the config email here
config = configparser.ConfigParser()
config.read(self.configfile)
config.set("USER", "email", str(self.emailEntry.get()))
with open(self.configfile, mode='w') as newfile:
config.write(newfile) # Update the config
return 1
except ValueError:
tkMessageBox.showwarning(
Expand Down Expand Up @@ -516,40 +524,49 @@ def widgets(self):
self.parent.grid_columnconfigure(1, weight=6)
self.parent.grid_rowconfigure(0, weight=1)
menubar = Menu(self.parent)

# File menu
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="New", command=self.donothing)
# filemenu.add_command(label="Open", command = self.onOpen)
filemenu.add_command(label="Connect", command=self.getConnectionInfo)
filemenu.add_command(label="Save", command=self.saveAnswer)
# remove Save All option, as some students thought there was
# also Submit All
# filemenu.add_command(label="Save All", command=self.saveAllAnswers)
filemenu.add_command(label="Submit", command=self.submitAnswer)
# filemenu.add_command(label="Submit All", command=self.submitAllAnswers)
# filemenu.add_command(label="Close", command=self.donothing)
filemenu.add_command(label="Compile", command=self.compileProgram)
filemenu.add_command(label="Submit & Run", command=self.runProgram)
filemenu.add_command(label="CopyQtoA", command=self.copyQtoA)
filemenu.add_command(label="View PDF", command=self.viewPDF)

filemenu.add_separator()

filemenu.add_command(label="Exit", command=self.parent.quit)
menubar.add_cascade(label="File", menu=filemenu)

# Edit menu, not added right now
editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="Undo", command=self.donothing)

editmenu.add_separator()

editmenu.add_command(label="Cut", command=self.donothing)
editmenu.add_command(label="Copy", command=self.donothing)
editmenu.add_command(label="Paste", command=self.donothing)
editmenu.add_command(label="Delete", command=self.donothing)
editmenu.add_command(label="Select All", command=self.donothing)

# menubar.add_cascade(label="Edit", menu=editmenu)

#The sub-menus

#Font size menu
fontmenu = Menu(tearoff=0)
fontmenu.add_command(label="8", command=lambda: self.changefont(8) )
fontmenu.add_command(label="10", command=lambda: self.changefont(10))
fontmenu.add_command(label="12", command=lambda: self.changefont(12))
fontmenu.add_command(label="14", command=lambda: self.changefont(14))
fontmenu.add_command(label="16", command=lambda: self.changefont(16))
fontmenu.add_command(label="18", command=lambda: self.changefont(18))

# Preference menu, for looks
prefmenu = Menu(menubar, tearoff=0)
prefmenu.add_cascade(label="Font Size", menu=fontmenu)
menubar.add_cascade(label="Preferences", menu=prefmenu)


self.parent.config(menu=menubar)

self.questionFrame = Frame(self.parent, bg="ghost white")
Expand All @@ -558,23 +575,22 @@ def widgets(self):
self.lb = Listbox(self.questionFrame, width=20, bg="lavender")
self.lb.insert(1, "Click on File to connect to server...")
self.lb.bind('<<ListboxSelect>>', self.listboxSelected)

self.lb.pack(fill=BOTH, expand=1, padx=5, pady=5)

# Frame for the question and answer text boxes
self.textFrame = Frame(self.parent, bg="azure")
pWindow = PanedWindow(self.textFrame, orient=VERTICAL, bg="LightBlue1")


self.textFrame.grid(row=0, column=1, sticky="nswe")

# self.textFrame.grid_rowconfigure(0, weight=2)
# self.textFrame.grid_rowconfigure(1, weight=2)
# self.textFrame.grid_columnconfigure(0, weight=1)

# Question text box
qframe = Frame(pWindow, bd=0)
#TODO Add a preference to change this background color
self.question = Text(qframe, bg="pale turquoise",
font=("sans-serif", 20),wrap=WORD)
font=("sans-serif", 14),wrap=WORD) #Making them the same size
## pWindow.add(self.question,sticky = "nwe")
self.question.config(state=DISABLED)
# self.question.grid(row=0,sticky="nswe",padx=5,pady =5)
Expand All @@ -598,6 +614,25 @@ def widgets(self):
# self.txt.grid(row=1,sticky="nswe",pa dx=5,pady=5)
pWindow.pack(fill=BOTH, expand=1, pady=5)
# self.loadQuestionsFromFile()

def changefont(self, fontsize):
self.question.configure(font = ("sans-serif", fontsize))
self.txt.configure(font = ("sans-serif", fontsize))
# Update prefs
config = configparser.ConfigParser()
config.read(self.configfile)
config.set("USER", "fontsize", str(fontsize))
with open(self.configfile, mode='w') as newfile:
config.write(newfile) # Update the config

# Load the config file any set any values that may be in there
def loadprefs(self):
config = configparser.ConfigParser()
config.read('config.ini')
# Will automatically grab the default value if the user does not have any
self.question.configure(font = ("sans-serif", config["USER"]["fontsize"]))
self.txt.configure(font = ("sans-serif", config["USER"]["fontsize"]))
self.email = config["USER"]["email"]


def main():
Expand Down
5 changes: 5 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[DEFAULT]
fontsize = 14
email = example@ucdavis.edu

[USER]