Ok, so I pretty much have my program up and running, but it's not the best looking program aesthetically, and I am trying to do a couple of things to make it look better, and none of them are working.
Here is what I want to do.
1) change the button sizes to be all the same size (buttons are labeled decrease, surrender, remain, etc...)
2) move the buttons to the middle of the screen.
3) change the background to transparent black (like the Pro terminal on the Mac) or, at the very least, to change it just to black.
I have tried implementing all of these, but none of it seems to work. Please help!
PS It looks like a lot... but there are 2 screens (the main gui and the preferences window). I am hoping to effect the above changes on both of the screens).
from Tkinter import *
import os
import tkMessageBox
import threading
import time
import re
import preferences
import scraper
import seleniumbrowser
import template1
import template2
import template3
import template4
class PreferencesWindow(object):
def __init__(self, master):
self.top = Toplevel(master)
self.top.transient(master)
self.top.grab_set()
row = 0
default_height = 3
default_width = 50
self._make_label(self.top, 'Decrease Payment', row)
row += 1
self.dec_payment = Text(self.top)
self.dec_payment.config(height=3, width=50)
self.dec_payment.grid(row=row, column=0)
row += default_height
self._make_label(self.top, 'Increase Payment', row)
row += 1
self.inc_payment = Text(self.top)
self.inc_payment.config(height=3, width=50)
self.inc_payment.grid(row=row, column=0)
row += default_height
self._make_label(self.top, 'Surrender Property', row)
row += 1
self.surr_property = Text(self.top)
self.surr_property.config(height=3, width=50)
self.surr_property.grid(row=row, column=0)
row += default_height
self._make_label(self.top, 'Not Surrendering Property', row)
row += 1
self.not_surr_property = Text(self.top)
self.not_surr_property.config(height=3, width=50)
self.not_surr_property.grid(row=row, column=0)
row += default_height
self._make_label(self.top, 'Other Provisions- Remain', row)
row += 1
self.op_remain = Text(self.top)
self.op_remain.config(height=3, width=50)
self.op_remain.grid(row=row, column=0)
row += default_height
self._make_label(self.top, 'Other Provisions- Decrease', row)
row += 1
self.op_decrease = Text(self.top)
self.op_decrease.config(height=3, width=50)
self.op_decrease.grid(row=row, column=0)
row += default_height
self._make_label(self.top, 'Basis for Modifying: Claims Filed ', row)
row += 1
self.bm_claims = Text(self.top)
self.bm_claims.config(height=3, width=50)
self.bm_claims.grid(row=row, column=0)
row += default_height
self._make_label(self.top, 'Basis for Modifying: Income', row)
row += 1
self.bm_income = Text(self.top)
self.bm_income.config(height=3, width=50)
self.bm_income.grid(row=row, column=0)
row += default_height
self.save_button = Button(self.top, text='Save Changes',
command=self._save_preferences)
self.save_button.grid(row=row, column=0)
self.preferences_keys = {
'%dec_payment': self.dec_payment,
'%inc_payment': self.inc_payment,
'%surr_property': self.surr_property,
'%not_surr_property': self.not_surr_property,
'%op_remain': self.op_remain,
'%op_decrease': self.op_decrease,
'%bm_claims': self.bm_claims,
'%bm_income': self.bm_income
}
self.pref = preferences.Preferences(self.preferences_keys.keys())
self._load_preferences()
def _make_label(self, master, text, row, column=0):
Label(master, text=text).grid(row=row, column=column)
def _save_preferences(self):
result_dict = {}
for key, val in self.preferences_keys.iteritems():
result_dict[key] = val.get(1.0, END)
self.pref.save_preferences(result_dict)
def _load_preferences(self):
result_dict = self.pref.get_preferences()
for key, val in result_dict.iteritems():
self.preferences_keys[key].insert(END, val)
def _close(self):
self.top.quit()
class MainGUI(object):
def __init__(self, master):
self.master = master
self.master.resizable(0,0)
self.case_num = StringVar()
self.new_payment = StringVar()
self.payment = StringVar()
self.property = StringVar()
self.provisions = StringVar()
self.basis = StringVar()
self.amending = StringVar()
self.include = StringVar()
self.selenium_server = seleniumbrowser.SeleniumServerController()
self.selenium_server.start()
self.master.protocol('WM_DELETE_WINDOW', self.quit)
options_grid = (
('Payment', self.payment, ('decrease', 'increase')),
('Property', self.property, ('no surrender', 'surrender')),
('Other provisions', self.provisions, ('remain', 'decrease')),
('Basis', self.basis, ('claims filed', 'income')),
('Amending I & J', self.amending, ('no', 'yes')),
('Include date', self.include, ('no', 'yes')),
)
row = 0
# case number prompt
self._make_label(master, 'Case number:', row)
entry = Entry(master, textvariable=self.case_num)
entry.grid(row=row, column=1)
row += 1
self._make_label(master, 'New Payment:', row)
entry = Entry(master, textvariable=self.new_payment)
entry.grid(row=row, column=1)
row += 1
for text, var, options in options_grid:
self._make_option(master, text, var, options, row)
row += 1
self.preferences_button = Button(master, text='Preferences',
command=self._edit_preferences)
self.preferences_button.grid(row=row, column=0)
self.make_report_button = Button(master, text='Make reports',
command=self._generate_reports)
self.make_report_button.grid(row=row, column=1)
row += 1
self.status_bar = Label(master, bd=1)
self.status_bar.config(text='')
self.status_bar.grid(row=row, column=0, columnspan=2, sticky=W)
self.debtors_thread = None
self.debtors = None
def _generate_reports(self):
self.case_number = self.case_num.get().strip()
if self.debtors_thread and self.debtors_thread.is_alive():
return
if not self.selenium_server.is_server_up():
tkMessageBox.showerror('Error', 'Failed to start Selenium server.\r\n'\
'Please, start it manually.')
return
if not self.case_number:
tkMessageBox.showerror('Error', 'Case number must be provided.')
return
elif not re.search(r'^\d{2}\-\d{5}$', self.case_number):
tkMessageBox.showerror('Error', 'Case number must be in DD-DDDDD format.')
self.debtors_thread = threading.Thread(target=self._fetch_debtors,
args=(self.case_number,))
self.debtors_thread.start()
def _fetch_debtors(self, case_num):
self.make_report_button.configure(state=DISABLED)
web_site = scraper.CourtWebSite()
web_site.login()
debtors = web_site.run_report(case_num, web_site._get_debtor_name)
web_site.close()
self.debtors = '<br>'.join(debtors)
#self.debtors = 'some debtor'
print self.debtors
pref = preferences.Preferences().get_preferences()
report_dict = {}
report_dict['%debtors'] = self.debtors
report_dict['%case_num'] = case_num
report_dict['%new_payment'] = self.new_payment.get()
if self.payment.get() == 'increase':
report_dict['%inc_dec'] = 'Increase'
report_dict['%payment'] = pref['%inc_payment']
else:
report_dict['%inc_dec'] = 'Decrease'
report_dict['%payment'] = pref['%dec_payment']
if self.property.get() == 'no surrender':
report_dict['%property'] = ''
else:
report_dict['%property'] = pref['%surr_property']
if self.provisions.get() == 'remain':
report_dict['%provisions'] = pref['%op_remain']
else:
report_dict['%provisions'] = pref['%op_decrease']
if self.basis.get() == 'income':
report_dict['%basis'] = pref['%bm_income']
else:
report_dict['%basis'] = pref['%bm_claims']
if self.include.get() == 'yes':
report_dict['%date'] = 'some day'
else:
report_dict['%date'] = ''
if self.amending.get() == 'yes':
self.write_reports(report_dict, True)
else:
self.write_reports(report_dict, False)
self.make_report_button.configure(state=NORMAL)
#print report_dict
def write_reports(self, report_dict, include_amending):
templates = (template1.template, template2.template, template3.template)
filenames = ('temp1', 'temp2', 'temp3')
extensions = ('.doc', '.html')
if include_amending:
templates += (template4.template,)
filenames += ('amending.doc',)
case_number = report_dict['%case_num']
if not os.path.isdir(case_number):
os.mkdir(case_number)
for filename, template in zip(filenames, templates):
text = template
for key, val in report_dict.iteritems():
text = text.replace(key, val)
text = text.replace('%new_payment', report_dict['%new_payment'])
for ext in extensions:
fd = open(os.path.join(case_number, filename + ext), 'w')
fd.write(text)
fd.close()
def _edit_preferences(self):
d = PreferencesWindow(self.master)
self.master.wait_window(d.top)
def _make_option(self, master, text, var, options, row):
self._make_label(master, text, row)
self._make_select_list(master, var, options, row)
def _make_label(self, master, text, row, column=0):
Label(master, text=text).grid(row=row, column=column)
def _make_select_list(self, master, var, options, row, column=1):
if options:
var.set(options[0])
OptionMenu(master, var, *options).grid(row=row, column=column)
def quit(self):
try:
self.selenium_server.stop()
except:
pass
self.master.quit()
if __name__ == '__main__':
root = Tk()
#photo = PhotoImage(file="py.gif")
#label = Label(image=photo)
#label.image = photo # keep a reference!
#label.pack()
# to change title
root.title('Title of my Program')
# to change icon, set path to your icon file and uncomment
# the line below
root.wm_iconbitmap('py.ico')
root.geometry("300x300")
app = MainGUI(root)
root.mainloop()