Tabbed forms example and explanation

This commit is contained in:
MikeTheWatchGuy 2018-07-24 17:44:23 -04:00
parent a723b6f463
commit 13d99dcd75
2 changed files with 101 additions and 2 deletions

89
Demo Tabbed Form.py Normal file
View File

@ -0,0 +1,89 @@
import PySimpleGUI as sg
MAX_NUMBER_OF_THREADS = 12
def eBaySuperSearcherGUI():
# Drop Down list of options
configs = ('0 - Gruen - Started 2 days ago in Watches',
'1 - Gruen - Currently Active in Watches',
'2 - Alpina - Currently Active in Jewelry',
'3 - Gruen - Ends in 1 day in Watches',
'4 - Gruen - Completed in Watches',
'5 - Gruen - Advertising',
'6 - Gruen - Currently Active in Jewelry',
'7 - Gruen - Price Test',
'8 - Gruen - No brand name specified')
us_categories = ('Use Default with no change',
'All - 1',
'Jewelry - 281',
' Watches - 14324',
' Wristwatches - 31387',
' Pocket Watches - 3937',
'Advertising - 34',
' Watch Ads - 165254'
)
german_categories =('Use Default with no change',
'All - 1',
'Jewelry - 281',
' Watches - 14324',
' Wristwatches - 31387',
' Pocket Watches - 3937',
'Advertising - 1',
' Watch Ads - 19823'
)
# the form layout
with sg.FlexForm('EBay Super Searcher', auto_size_text=True) as form:
with sg.FlexForm('EBay Super Searcher') as form2:
layout_tab_1 = [[sg.Text('eBay Super Searcher!', size=(60,1), font=('helvetica', 15))],
[sg.Text('Choose base configuration to run')],
[sg.InputCombo(configs)],
[sg.Text('_'*100, size=(80,1))],
[sg.InputText(),sg.Text('Choose Destination Folder'), sg.FolderBrowse(target=(sg.ThisRow,0))],
[sg.InputText(),sg.Text('Custom text to add to folder name')],
[sg.Text('_'*100, size=(80,1))],
[sg.Checkbox('US', default=True, size=(15, 1)), sg.Checkbox('German', size=(15, 1), default=True, )],
[sg.Radio('Active Listings','ActiveComplete', default = True,size=(15, 1)), sg.Radio('Completed Listings', 'ActiveComplete', size=(15, 1))],
[sg.Text('_'*100, size=(80,1))],
[sg.Checkbox('Save Images', size=(15,1)),sg.Checkbox('Save PDFs', size=(15,1)), sg.Checkbox('Extract PDFs', size=(15,1))],
[sg.Text('_'*100, size=(80,1))],
[sg.Text('Time Filters')],
[sg.Radio('No change','time', default=True),sg.Radio('ALL listings','time'),sg.Radio('Started 1 day ago','time', size=(15,1)),sg.Radio('Started 2 days ago','time', size=(15,1)), sg.Radio('Ends in 1 day','time', size=(15,1))],
[sg.Text('_'*100, size=(80,1))],
[sg.Text('Price Range'), sg.InputText(size=(10,1)),sg.Text('To'), sg.InputText(size=(10,1))],
[sg.Text('_'*100, size=(80,1))],
[sg.Submit(button_color=('red', 'yellow')), sg.Cancel(button_color=('white', 'blue')), sg.Text(f'{MAX_NUMBER_OF_THREADS} Threads will be started')]]
# First category is default (need to special case this)
layout_tab_2 = [[sg.Text('Choose Category')],
[sg.Text('US Categories'),sg.Text('German Categories')],
[sg.Radio(us_categories[0],'CATUS', default=True), sg.Radio(german_categories[0], 'CATDE', default=True)]]
for i,cat in enumerate(us_categories):
if i == 0: continue # skip first one
layout_tab_2.append([sg.Radio(cat,'CATUS'), sg.Radio(german_categories[i],'CATDE')])
layout_tab_2.append([sg.Text('_' * 100, size=(75, 1))])
layout_tab_2.append([sg.Text('US Search String Override')])
layout_tab_2.append([sg.InputText(size=(100,1))])
layout_tab_2.append([sg.Text('German Search String Override')])
layout_tab_2.append([sg.InputText(size=(100,1))])
layout_tab_2.append([sg.Text('Typical US Search String')])
layout_tab_2.append([sg.InputText(size=(100,1), default_text='gruen -sara -quarz -quartz -embassy -bob -robert -elephants -adidas -LED ')])
layout_tab_2.append([sg.Text('_' * 100, size=(75, 1))])
layout_tab_2.append([sg.Submit(button_color=('red', 'yellow'),auto_size_text=True), sg.Cancel(button_color=('white', 'blue'), auto_size_text=True)])
results =sg.ShowTabbedForm('eBay Super Searcher', (form,layout_tab_1,'Where To Save'), (form2, layout_tab_2, 'Categories & Search String'))
return results
if __name__ == '__main__':
results = eBaySuperSearcherGUI()
print(results)
sg.MsgBox('Results', results)

View File

@ -1023,9 +1023,18 @@ Tabbed forms are shown using the `ShowTabbedForm` call. The call has the format
results = ShowTabbedForm('Title for the form',
(form,layout,'Tab 1 label'),
(form2,layout2, 'Tab 2 label'))
(form2,layout2, 'Tab 2 label'), ...)
Each of the tabs of the form is in fact a form. The same steps are taken to create the form as before. A `FlexForm` is created, then rows are filled with Elements, and finally the form is shown. When calling `ShowTabbedForm`, each form is passed in as a tuple. The tuple has the format: `(the form, the rows, a string shown on the tab)`
Results are returned as a list of lists. For each form you'll get a list that's in the same format as a normal form. A single tab's values would be:
(button, (values))
Recall that values is a list as well. Multiple tabs in the form would return like this:
((button1, (values1)), (button2, (values2))
Each of the tabs of the form is in fact a form. The same steps are taken to create the form as before. A `FlexForm` is created, then rows are filled with Elements, and finally the form is shown. When calling `ShowTabbedForm`, each form is passed in as a tuple. The tuple has the format: `(the form, the rows, a label shown on the tab)`
## Global Settings
**Global Settings**
@ -1305,3 +1314,4 @@ For Python questions, I simply start my query with 'Python'. Let's say you forg
In the hands of a competent programmer, this tool is **amazing**. It's a must-try kind of program that has completely changed my programming process. I'm not afraid of asking for help! You just have to be smart about using what you find.
The PySimpleGUI window that the results are shown in is an 'input' field which means you can copy and paste the results right into your code.