Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def forms_test_page(self):
- wm = self.window_manager
- page_name = 'Forms Test Page'
- pg, page_cached = wm.page(page_name)
- if not page_cached:
- pane = PanedWindow(pg, bg=self.__sidebar_bg, borderwidth=0, orient='vertical')
- pane.grid(sticky='NSEW')
- canvas1 = Canvas(pane, borderwidth=0, highlightthickness=0)
- canvas1.rowconfigure(0, weight=1)
- canvas1.columnconfigure(0, weight=1)
- pane.add(canvas1)
- canvas2 = Canvas(pane, borderwidth=0, highlightthickness=0)
- canvas2.rowconfigure(0, weight=1)
- canvas2.columnconfigure(0, weight=1)
- pane.add(canvas2)
- frame = Frame(canvas2)
- frame.rowconfigure(1, weight=1)
- frame.columnconfigure(0, weight=1)
- frame.grid(row=0, column=0, sticky='NSEW')
- f1 = Frame(frame)
- f1.rowconfigure(0, weight=1)
- f1.columnconfigure(0, weight=1)
- f1.grid(row=0, column=0, sticky='NEW')
- f2 = Frame(frame)
- f2.rowconfigure(0, weight=1)
- f2.columnconfigure(0, weight=1)
- f2.grid(row=1, column=0, sticky='NSEW')
- Label(
- f1,
- text='Season Win/Loss',
- font=("Helvetica", 15),
- bg='white'
- ).grid(sticky='EW')
- columns = (
- {'id': '#0', 'anchor': 'w'},
- {'id': 'id'},
- {'id': 'starttime'},
- {'id': 'endtime'},
- {'id': 'totaltime'},
- {'id': 'minutes'},
- {'id': 'team1', 'width': 150},
- {'id': 'team2', 'width': 150},
- {'id': 'winner', 'width': 150}
- )
- headings = (
- {'id': '#0', 'text': '#', 'anchor': 'w'},
- {'id': 'id', 'text': 'ID'},
- {'id': 'starttime', 'text': 'Start Time'},
- {'id': 'endtime', 'text': 'End Time'},
- {'id': 'totaltime', 'text': 'Total Time'},
- {'id': 'minutes', 'text': 'Minutes'},
- {'id': 'team1', 'text': 'Team1'},
- {'id': 'team2', 'text': 'Team2'},
- {'id': 'winner', 'text': 'Winner'}
- )
- table_data = self.table_data
- table = TableView(f2, headings, columns)
- table['show'] = 'headings'
- for i, row in enumerate(table_data, 1):
- tag = 'even' if i % 2 else 'odd'
- table.insert('', 'end', values=row, tags=(tag,))
- def new():
- def clear(groups):
- for i, itm in groups.items():
- if isinstance(itm, FormLabelFrame) or isinstance(itm, FormFrame):
- clear(itm.fields())
- elif isinstance(itm, NotebookField) or isinstance(itm, ButtonField):
- continue
- else:
- if isinstance(itm, ComboboxField):
- itm.widget.current(itm.default)
- if isinstance(itm, CheckbuttonField):
- itm.value(itm.default)
- if isinstance(itm, RadiobuttonField):
- itm.value(itm.default)
- if isinstance(itm, EntryField):
- itm.value(itm.default)
- clear(form.fields())
- def save():
- messagebox.showinfo('Test', 'Save button clicked!')
- def delete():
- messagebox.showinfo('Test', 'Delete button clicked!')
- def search():
- messagebox.showinfo('Test', 'Search button clicked!')
- def option():
- messagebox.showinfo('Info', 'You have set option ' + str(form.item('team/players/option').value() + 1))
- def great_player():
- val = form.item('team/players/great_player').value()
- if val:
- message = 'Great player is checked!'
- else:
- message = 'Great player has been cleared!'
- messagebox.showinfo('Info', message)
- def name_filter(widget):
- widget.value(sub('[^a-zA-Z-]+', '', widget.value()))
- def team_name_filter(widget):
- widget.value(sub('[^a-zA-Z-\s]+', '', widget.value()))
- # fields: id, label, type, callback, row, column, width, defaults, status
- fields = (
- ('game', 'Game', 'LabelFrame', (
- ('id', 'Number', 'Entry', None, 0, 0, 5, '', 'normal'),
- ('winner', 'Winner', 'Combobox', None, 0, 1, 30, ['']+teams, 'normal'),
- ), 0, 0),
- ('match', 'Match', 'LabelFrame', (
- ('team1', 'Home Team', 'Combobox', team_name_filter, 0, 0, 30, ['']+teams, 'normal'),
- ('team2', 'Visiting Team', 'Combobox', team_name_filter, 1, 0, 30, ['']+teams, 'normal'),
- ), 1, 0),
- ('times', 'Times', 'LabelFrame', (
- ('starttime', 'Start', 'Entry', None, 0, 0, 10, '', 'normal'),
- ('endtime', 'Finish', 'Entry', None, 0, 1, 10, '', 'normal'),
- ('totaltime', 'Total Time', 'Entry', None, 1, 0, 10, '', 'normal'),
- ('minutes', 'Minutes Played', 'Entry', None, 1, 1, 10, '', 'normal'),
- ), 1, 1,),
- ('team', 'Team', 'LabelFrame', (
- ('team_name', 'Team Name', 'Combobox', team_name_filter, 0, 0, 30, ['']+teams, 'normal'),
- ('players', 'Players', 'LabelFrame', (
- ('first_name', 'First Name', 'Entry', name_filter, 0, 0, 25, None, 'normal'),
- ('middle_name', 'Middle Name', 'Entry', name_filter, 1, 0, 25, None, 'normal'),
- ('last_name', 'Last Name', 'Entry', name_filter, 2, 0, 25, None, 'normal'),
- ('gender', 'Gender', 'Combobox', None, 0, 1, 18, ('Male', 'Female'), 'normal'),
- ('great_player', 'Great Player', 'Checkbutton', great_player, 1, 1, 25, 0, 'normal'),
- ('option', None, 'Radiobutton', option, 2, 1, 25, ('Option1', 'Option2', 'Option3'), 'normal'),
- ('processing', 'Progressing', 'Progressbar', None, 3, 0, 25, '', 'normal'),
- ), 2, 0),
- ), 2, 0),
- ('notebook', '', 'Frame', (
- ('editor', None, 'Notebook', None, 0, 0, None, ('Tab One', 'Tab Two', 'Tab Three'), 'normal'),
- ), 3, 0),
- ('buttons', '', 'LabelFrame', (
- ('save', None, 'Button', save, 0, 0, 10, 'Save', 'normal'),
- ('delete', None, 'Button', delete, 0, 1, 10, 'Delete', 'normal'),
- ('new', None, 'Button', new, 0, 2, 10, 'New', 'normal'),
- ('search', None, 'Button', search, 0, 3, 10, 'Search', 'normal'),
- ), 4, 0),
- )
- form = Form(canvas1, table, fields)
- form.rowconfigure(3, weight=1)
- form.columnconfigure(1, weight=1)
- item = form.item
- item('game').grid(sticky='NSEW', columnspan=2)
- for _, _item in form.groups().items():
- _item.grid(padx=2, pady=2)
- item('match/team1').grid(sticky='NE')
- item('match/team2').grid(sticky='NE')
- item('times/starttime').grid(sticky='NE')
- item('times/endtime').grid(sticky='NE')
- def gender_selected(event):
- messagebox.showinfo('Info', 'You have selected ' + event.widget.get())
- item('team').grid(sticky='NSEW', columnspan=2)
- item('team').rowconfigure(0, weight=1)
- item('team').columnconfigure(0, weight=1)
- item('team/team_name').grid(sticky='NW')
- item('team/players').grid(padx=2, pady=2, sticky='NSEW')
- item('team/players/processing').grid(columnspan=5)
- item('team/players/gender').widget.bind("<<ComboboxSelected>>", gender_selected)
- item('team/players/first_name').grid(sticky='NE')
- item('team/players/last_name').grid(sticky='NE')
- def progress_bar():
- pb.bytes += 500
- pb["value"] = pb.bytes
- if pb.bytes < pb.maxbytes:
- pb.after(100, progress_bar)
- else:
- messagebox.showinfo('Info', 'Process Completed Successfully')
- pb = item('team/players/processing').widget
- pb.bytes = pb["value"] = 0
- pb.maxbytes = pb["maximum"] = 50000
- progress_bar()
- item('notebook').rowconfigure(0, weight=1)
- item('notebook').columnconfigure(0, weight=1)
- item('notebook').grid(sticky='NSEW', columnspan=2)
- item('notebook/editor').config(padx=0, pady=7)
- item('notebook/editor').grid(sticky='NSEW')
- item('buttons').grid(sticky='NSEW', columnspan=2)
- print(item('notebook/editor').pad['Tab One'].text)
- item('notebook/editor').pad['Tab One'].text.config(bg='#fffff6')
- item('notebook/editor').pad['Tab Two'].text.config(bg='#e3ffe0')
- item('notebook/editor').pad['Tab Three'].text.config(bg='#e7edff')
- form.grid(sticky='NSEW')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement