Advertisement
Uno-Dan

Untitled

May 9th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.58 KB | None | 0 0
  1.  
  2.  
  3.     def forms_test_page(self):
  4.         wm = self.window_manager
  5.         page_name = 'Forms Test Page'
  6.         pg, page_cached = wm.page(page_name)
  7.  
  8.         if not page_cached:
  9.             pane = PanedWindow(pg, bg=self.__sidebar_bg, borderwidth=0, orient='vertical')
  10.             pane.grid(sticky='NSEW')
  11.  
  12.             canvas1 = Canvas(pane, borderwidth=0, highlightthickness=0)
  13.             canvas1.rowconfigure(0, weight=1)
  14.             canvas1.columnconfigure(0, weight=1)
  15.             pane.add(canvas1)
  16.  
  17.             canvas2 = Canvas(pane, borderwidth=0, highlightthickness=0)
  18.             canvas2.rowconfigure(0, weight=1)
  19.             canvas2.columnconfigure(0, weight=1)
  20.             pane.add(canvas2)
  21.  
  22.             frame = Frame(canvas2)
  23.             frame.rowconfigure(1, weight=1)
  24.             frame.columnconfigure(0, weight=1)
  25.             frame.grid(row=0, column=0, sticky='NSEW')
  26.  
  27.             f1 = Frame(frame)
  28.             f1.rowconfigure(0, weight=1)
  29.             f1.columnconfigure(0, weight=1)
  30.             f1.grid(row=0, column=0, sticky='NEW')
  31.  
  32.             f2 = Frame(frame)
  33.             f2.rowconfigure(0, weight=1)
  34.             f2.columnconfigure(0, weight=1)
  35.             f2.grid(row=1, column=0, sticky='NSEW')
  36.  
  37.             Label(
  38.                 f1,
  39.                 text='Season Win/Loss',
  40.                 font=("Helvetica", 15),
  41.                 bg='white'
  42.             ).grid(sticky='EW')
  43.  
  44.             columns = (
  45.                 {'id': '#0', 'anchor': 'w'},
  46.                 {'id': 'id'},
  47.                 {'id': 'starttime'},
  48.                 {'id': 'endtime'},
  49.                 {'id': 'totaltime'},
  50.                 {'id': 'minutes'},
  51.                 {'id': 'team1', 'width': 150},
  52.                 {'id': 'team2', 'width': 150},
  53.                 {'id': 'winner', 'width': 150}
  54.             )
  55.             headings = (
  56.                 {'id': '#0', 'text': '#', 'anchor': 'w'},
  57.                 {'id': 'id', 'text': 'ID'},
  58.                 {'id': 'starttime', 'text': 'Start Time'},
  59.                 {'id': 'endtime', 'text': 'End Time'},
  60.                 {'id': 'totaltime', 'text': 'Total Time'},
  61.                 {'id': 'minutes', 'text': 'Minutes'},
  62.                 {'id': 'team1', 'text': 'Team1'},
  63.                 {'id': 'team2', 'text': 'Team2'},
  64.                 {'id': 'winner', 'text': 'Winner'}
  65.             )
  66.  
  67.             table_data = self.table_data
  68.             table = TableView(f2, headings, columns)
  69.  
  70.             table['show'] = 'headings'
  71.             for i, row in enumerate(table_data, 1):
  72.                 tag = 'even' if i % 2 else 'odd'
  73.                 table.insert('', 'end', values=row, tags=(tag,))
  74.  
  75.             def new():
  76.                 def clear(groups):
  77.                     for i, itm in groups.items():
  78.                         if isinstance(itm, FormLabelFrame) or isinstance(itm, FormFrame):
  79.                             clear(itm.fields())
  80.                         elif isinstance(itm, NotebookField) or isinstance(itm, ButtonField):
  81.                             continue
  82.                         else:
  83.                             if isinstance(itm, ComboboxField):
  84.                                 itm.widget.current(itm.default)
  85.  
  86.                             if isinstance(itm, CheckbuttonField):
  87.                                 itm.value(itm.default)
  88.  
  89.                             if isinstance(itm, RadiobuttonField):
  90.                                 itm.value(itm.default)
  91.  
  92.                             if isinstance(itm, EntryField):
  93.                                 itm.value(itm.default)
  94.  
  95.                 clear(form.fields())
  96.  
  97.             def save():
  98.                 messagebox.showinfo('Test', 'Save button clicked!')
  99.  
  100.             def delete():
  101.                 messagebox.showinfo('Test', 'Delete button clicked!')
  102.  
  103.             def search():
  104.                 messagebox.showinfo('Test', 'Search button clicked!')
  105.  
  106.             def option():
  107.                 messagebox.showinfo('Info', 'You have set option ' + str(form.item('team/players/option').value() + 1))
  108.  
  109.             def great_player():
  110.                 val = form.item('team/players/great_player').value()
  111.                 if val:
  112.                     message = 'Great player is checked!'
  113.                 else:
  114.                     message = 'Great player has been cleared!'
  115.                 messagebox.showinfo('Info', message)
  116.  
  117.             def name_filter(widget):
  118.                 widget.value(sub('[^a-zA-Z-]+', '', widget.value()))
  119.  
  120.             def team_name_filter(widget):
  121.                 widget.value(sub('[^a-zA-Z-\s]+', '', widget.value()))
  122.  
  123.             # fields: id, label, type, callback, row, column, width, defaults, status
  124.             fields = (
  125.                 ('game', 'Game', 'LabelFrame', (
  126.                     ('id', 'Number', 'Entry', None, 0, 0, 5, '', 'normal'),
  127.                     ('winner', 'Winner', 'Combobox', None, 0, 1, 30, ['']+teams, 'normal'),
  128.                 ), 0, 0),
  129.                 ('match', 'Match', 'LabelFrame', (
  130.                     ('team1', 'Home Team', 'Combobox', team_name_filter, 0, 0, 30, ['']+teams, 'normal'),
  131.                     ('team2', 'Visiting Team', 'Combobox', team_name_filter, 1, 0, 30, ['']+teams, 'normal'),
  132.                 ), 1, 0),
  133.                 ('times', 'Times', 'LabelFrame', (
  134.                     ('starttime', 'Start', 'Entry', None, 0, 0, 10, '', 'normal'),
  135.                     ('endtime', 'Finish', 'Entry', None, 0, 1, 10, '', 'normal'),
  136.                     ('totaltime', 'Total Time', 'Entry', None, 1, 0, 10, '', 'normal'),
  137.                     ('minutes', 'Minutes Played', 'Entry', None, 1, 1, 10, '', 'normal'),
  138.                 ), 1, 1,),
  139.                 ('team', 'Team', 'LabelFrame', (
  140.                     ('team_name', 'Team Name', 'Combobox', team_name_filter, 0, 0, 30, ['']+teams, 'normal'),
  141.                     ('players', 'Players', 'LabelFrame', (
  142.                         ('first_name', 'First Name', 'Entry', name_filter, 0, 0, 25, None, 'normal'),
  143.                         ('middle_name', 'Middle Name', 'Entry', name_filter, 1, 0, 25, None, 'normal'),
  144.                         ('last_name', 'Last Name', 'Entry', name_filter, 2, 0, 25, None, 'normal'),
  145.                         ('gender', 'Gender', 'Combobox', None, 0, 1, 18, ('Male', 'Female'), 'normal'),
  146.                         ('great_player', 'Great Player', 'Checkbutton', great_player, 1, 1, 25, 0, 'normal'),
  147.                         ('option', None, 'Radiobutton', option, 2, 1, 25, ('Option1', 'Option2', 'Option3'), 'normal'),
  148.                         ('processing', 'Progressing', 'Progressbar', None, 3, 0, 25, '', 'normal'),
  149.                     ), 2, 0),
  150.                 ), 2, 0),
  151.                 ('notebook', '', 'Frame', (
  152.                     ('editor', None, 'Notebook', None, 0, 0, None, ('Tab One', 'Tab Two', 'Tab Three'), 'normal'),
  153.                 ), 3, 0),
  154.                 ('buttons', '', 'LabelFrame', (
  155.                     ('save', None, 'Button', save, 0, 0, 10, 'Save', 'normal'),
  156.                     ('delete', None, 'Button', delete, 0, 1, 10, 'Delete', 'normal'),
  157.                     ('new', None, 'Button', new, 0, 2, 10, 'New', 'normal'),
  158.                     ('search', None, 'Button', search, 0, 3, 10, 'Search', 'normal'),
  159.                 ), 4, 0),
  160.             )
  161.             form = Form(canvas1, table, fields)
  162.             form.rowconfigure(3, weight=1)
  163.             form.columnconfigure(1, weight=1)
  164.  
  165.             item = form.item
  166.             item('game').grid(sticky='NSEW', columnspan=2)
  167.  
  168.             for _, _item in form.groups().items():
  169.                 _item.grid(padx=2, pady=2)
  170.  
  171.             item('match/team1').grid(sticky='NE')
  172.             item('match/team2').grid(sticky='NE')
  173.  
  174.             item('times/starttime').grid(sticky='NE')
  175.             item('times/endtime').grid(sticky='NE')
  176.  
  177.             def gender_selected(event):
  178.                 messagebox.showinfo('Info', 'You have selected ' + event.widget.get())
  179.  
  180.             item('team').grid(sticky='NSEW', columnspan=2)
  181.             item('team').rowconfigure(0, weight=1)
  182.             item('team').columnconfigure(0, weight=1)
  183.  
  184.             item('team/team_name').grid(sticky='NW')
  185.  
  186.             item('team/players').grid(padx=2, pady=2, sticky='NSEW')
  187.             item('team/players/processing').grid(columnspan=5)
  188.             item('team/players/gender').widget.bind("<<ComboboxSelected>>", gender_selected)
  189.             item('team/players/first_name').grid(sticky='NE')
  190.             item('team/players/last_name').grid(sticky='NE')
  191.  
  192.             def progress_bar():
  193.                 pb.bytes += 500
  194.                 pb["value"] = pb.bytes
  195.                 if pb.bytes < pb.maxbytes:
  196.                     pb.after(100, progress_bar)
  197.                 else:
  198.                     messagebox.showinfo('Info', 'Process Completed Successfully')
  199.  
  200.             pb = item('team/players/processing').widget
  201.             pb.bytes = pb["value"] = 0
  202.             pb.maxbytes = pb["maximum"] = 50000
  203.             progress_bar()
  204.  
  205.             item('notebook').rowconfigure(0, weight=1)
  206.             item('notebook').columnconfigure(0, weight=1)
  207.             item('notebook').grid(sticky='NSEW', columnspan=2)
  208.             item('notebook/editor').config(padx=0, pady=7)
  209.             item('notebook/editor').grid(sticky='NSEW')
  210.             item('buttons').grid(sticky='NSEW', columnspan=2)
  211.  
  212.             print(item('notebook/editor').pad['Tab One'].text)
  213.             item('notebook/editor').pad['Tab One'].text.config(bg='#fffff6')
  214.             item('notebook/editor').pad['Tab Two'].text.config(bg='#e3ffe0')
  215.             item('notebook/editor').pad['Tab Three'].text.config(bg='#e7edff')
  216.  
  217.             form.grid(sticky='NSEW')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement