Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
UCSDA/pygui.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
245 lines (202 sloc)
8.49 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################### | |
#CS CANADA - UCONN SDP | |
#GUI for parsing and such | |
#Uses Tkinter - built-in GUI dev for Python | |
# 4/26 Astha: Made full separation of verif and tc design | |
# added text labels and switched layout. | |
############################################################### | |
from Tkinter import * | |
from ttk import * | |
import tkFileDialog | |
import tkMessageBox | |
import os | |
import os.path | |
import string | |
from docx import Document | |
from docx.shared import Inches | |
import sys | |
import parser_v7 as pv7 #edit version/parser file here | |
# THE GUI CLASS | |
class Window: | |
global srs | |
# global rules | |
global message | |
global repdir | |
global rep_type | |
global revdir | |
def __init__(self, master): | |
frame = LabelFrame( | |
master, # fg="black", | |
text="SRSTool", # padx=5, pady=5, | |
) | |
frame.pack(fill="both", expand="yes") | |
# Text 1: | |
l1 = Label(frame, text="Welcome to the SRS Tool! Select your SRS, directories, HLR file, and begin.\n", font=("Helvetica", 12)) | |
l1.grid(row=2, column=1, columnspan=3) | |
# BUTTONS | |
# srs choose | |
bsrs = Button(frame, text='SRS file', width=15, command= lambda: self.openfile('srs')) | |
bsrs.grid(row=3, column=1) | |
esrs = Entry(frame, textvariable=srs, width=80) | |
esrs.grid(row=3, column=2, columnspan=3) | |
# report | |
brep = Button(frame, text='Report Dir', width=15, command= lambda: self.opendir('repdir')) | |
brep.grid(row=5, column=1) | |
erep = Entry(frame, textvariable=repdir, width=80) | |
erep.grid(row=5, column=2, columnspan=3) | |
# revision | |
brev = Button(frame, text='Revisions Dir', width=15, command= lambda: self.opendir('revdir')) | |
brev.grid(row=6, column=1) | |
erev = Entry(frame, textvariable=revdir, width=80) | |
erev.grid(row=6, column=2, columnspan=3) | |
# hlr file choose | |
bhlr = Button(frame, text='HLR file', width=15, command= lambda: self.openfile('hlr')) | |
bhlr.grid(row=7, column=1) | |
ehlr = Entry(frame, textvariable=hlr, width=80) | |
ehlr.grid(row=7, column=2, columnspan=3) | |
l2 = Label(frame, text="\n1) Verify SRS to check text and HLRs. New SRS revision is SRS File - revision.docx\n2) Make Test Cases to... make test cases :D \n3) Name the report and save (report and file selections) for future reference.\n", font=("Helvetica", 9)) | |
l2.grid(row=9, column=1, columnspan=3) | |
#report type | |
rb_t = Radiobutton(frame, text=".txt", variable=rep_type, value=1 ) #, relief=RIDGE) | |
rb_t.grid(row=12, column=3) | |
rb_t.invoke() | |
rep_type.set(1); | |
rb_d = Radiobutton(frame, text=".docx", variable=rep_type, value=2) #, relief=RIDGE) | |
rb_d.grid(row=12, column=4) | |
# save and quit button | |
self.button = Button(frame, text="SAVE", width=15, command=lambda: saveReport()) | |
self.button.grid(row=12, column=1) | |
# Verify srs | |
bversrs = Button(frame, text='Verify SRS', width=15, command= lambda: parseSRS()) | |
bversrs.grid(row=14, column=1) | |
# Make Test Cases | |
bversrs = Button(frame, text='Make Test Cases', width=15, command= lambda: makeTC()) | |
bversrs.grid(row=15, column=1) | |
# MESSAGE CONSOLE | |
global tmsg | |
global emsg_title | |
emsg_title = Entry(frame) | |
emsg_title.grid(row=12, column=2, sticky="nsew") | |
emsg_title.insert(0, 'Report Title') | |
tmsg = Text(frame, height=20, relief=RIDGE, bg="white") | |
tmsg.grid(row=13, column=2, columnspan=3, rowspan=6, sticky="nsew") | |
tmsg.insert('1.0', 'REPORT:\n') | |
scrl = Scrollbar(frame, command=tmsg.yview) | |
scrl.grid(row=13, column=5, rowspan=6, sticky="nsew") | |
tmsg['yscrollcommand'] = scrl.set | |
# FUNCTIONS | |
def openfile(self, x): | |
file = tkFileDialog.askopenfile(parent=root,mode='rb',title='Choose a file') | |
if file is not None: | |
abs_path = os.path.abspath(file.name) | |
if x == 'srs': | |
srs.set(abs_path) | |
elif x == 'hlr': | |
hlr.set(abs_path) | |
name = file.name | |
file.close() | |
def opendir(self, y): | |
if y == 'repdir': | |
dir = tkFileDialog.askdirectory(parent=root,title='Choose where to save your report',mustexist=True, initialdir=repdir.get()) | |
repdir.set(os.path.abspath(dir)) | |
elif y == 'revdir': | |
dir = tkFileDialog.askdirectory(parent=root,title='Choose where to save your revisions',mustexist=True, initialdir=revdir.get()) | |
revdir.set(os.path.abspath(dir)) | |
# INITIALIZE GUI AND VARIABLES | |
root = Tk() | |
root.geometry("805x605") | |
root.protocol('WM_DELETE_WINDOW', lambda: FinalClose()) # override the X command | |
srs = StringVar() | |
hlr = StringVar() | |
message = StringVar() | |
repdir = StringVar() | |
rep_type = IntVar() | |
revdir = StringVar() | |
report_saved = 1 | |
# LOAD OLD DATA | |
try: | |
with open('template.txt') as f: | |
content = [x.strip('\n').split('=',2) for x in f.readlines()] | |
# print "Content:",content | |
for c in content: | |
if c[0] == 'srs': | |
srs.set(c[1]) | |
elif c[0] == 'hlr': | |
hlr.set(c[1]) | |
elif c[0] == 'repdir': | |
repdir.set(c[1]) | |
elif c[0] == 'revdir': | |
revdir.set(c[1]) | |
except IOError: | |
print '' | |
# print 'Srs', srs.get() | |
# print 'Rules', rules.get() | |
# print 'Repdir', repdir.get() | |
# print 'Msg', message | |
# ANY OTHER FUNCTIONS GO HERE... | |
def parseSRS(): | |
global report_saved | |
if (not report_saved) and tkMessageBox.askyesno( "Save Report?","Current report has not been saved. Would you like to save it?\n"): | |
saved = saveReport() | |
if not saved: | |
return | |
tmsg.delete('2.0', 'end') | |
tmsg.insert('end', '\nParsing SRS: %s\n' % srs.get().split('\\')[-1]) | |
# Test PARSER here | |
test = pv7.Parser(tmsg, srs.get(), revdir.get(), hlr.get()) | |
# test.make_test_cases() | |
test.verify_all_hlr() | |
tmsg.insert('end', 'Done with parsing\n') | |
report_saved = 0 | |
def makeTC(): | |
global report_saved | |
if (not report_saved) and tkMessageBox.askyesno( "Save Report?","Current report has not been saved. Would you like to save it?\n"): | |
saved = saveReport() | |
if not saved: | |
return | |
tmsg.delete('2.0', 'end') | |
tmsg.insert('end', '\nParsing and Making Test Cases for %s\n' % srs.get().split('\\')[-1] ) | |
# Test PARSER here | |
test = pv7.Parser(tmsg, srs.get(), revdir.get(), hlr.get()) | |
test.make_test_cases() | |
tmsg.insert('end', 'Test cases created\n') | |
report_saved = 0 | |
def saveReport(): | |
rep_data = tmsg.get('1.0', 'end') | |
rep_title = emsg_title.get() | |
safe_chars = '_-. ()' + string.digits + string.ascii_letters | |
all_chars = string.maketrans('', '') | |
deletions = ''.join(set(all_chars) - set(safe_chars)) | |
safe_title = rep_title.encode('utf-8').translate(all_chars, deletions) | |
if rep_type.get() == 1 and rep_title != '': #.txt format | |
safe_title = repdir.get() + '\\' + safe_title + '.txt'; | |
if os.path.isfile(safe_title) and not tkMessageBox.askokcancel( "Overwrite?","A report with this name already exists.\nPress 'OK' to overwrite or 'Cancel' to go back and enter a new name.\n"): | |
return 0 | |
fo = open(safe_title, "w") | |
fo.write(rep_title.encode('utf-8') + '\n' + rep_data.encode('utf-8')) | |
fo.close() | |
elif rep_type.get() == 2 and rep_title != '': #.docx format | |
safe_title = repdir.get() + '\\' + safe_title + '.docx' | |
if os.path.isfile(safe_title) and not tkMessageBox.askokcancel( "Overwrite?","A report with this name already exists.\nPress 'OK' to overwrite or 'Cancel' to go back and enter a new name.\n"): | |
return 0 | |
fo = Document() | |
fo.add_heading(rep_title, 0) | |
p = fo.add_paragraph(rep_data) | |
fo.save(safe_title) | |
# WRITE NEW MODIFICATIONS TO TEMPLATE.TXT | |
# if srs.get() != '' and revdir.get() != '' and repdir.get() != '': | |
fo = open("template.txt", "w") | |
str = "srs=" + srs.get() + "\nrepdir=" + repdir.get() + "\nrevdir=" + revdir.get() + "\nhlr=" + hlr.get() | |
fo.write(str) | |
fo.close() | |
global report_saved | |
report_saved = 1 | |
return 1 | |
def FinalClose(): | |
if (not report_saved) and tkMessageBox.askyesno( "Save Report?","Current report has not been saved. Would you like to save it?\n"): | |
saved = saveReport() | |
tkMessageBox.showinfo('Ok', 'Report has been saved!') | |
sys.exit() | |
# START GUI | |
win = Window(root) | |
root.mainloop() |