Renamed to new PySimpleGUIQt name.... this time for sure
This commit is contained in:
parent
d1a1a41f32
commit
645482b3c6
8 changed files with 90 additions and 82 deletions
93
PySimpleGUIQt/Demo_HowDoI.py
Normal file
93
PySimpleGUIQt/Demo_HowDoI.py
Normal file
|
@ -0,0 +1,93 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
import PySimpleGUIQt as sg
|
||||
import subprocess
|
||||
|
||||
|
||||
# Test this command in a dos window if you are having trouble.
|
||||
HOW_DO_I_COMMAND = 'python -m howdoi.howdoi'
|
||||
|
||||
# if you want an icon on your taskbar for this gui, then change this line of code to point to the ICO file
|
||||
DEFAULT_ICON = 'question.ico'
|
||||
|
||||
def HowDoI():
|
||||
'''
|
||||
Make and show a window (PySimpleGUI form) that takes user input and sends to the HowDoI web oracle
|
||||
Excellent example of 2 GUI concepts
|
||||
1. Output Element that will show text in a scrolled window
|
||||
2. Non-Window-Closing Buttons - These buttons will cause the form to return with the form's values, but doesn't close the form
|
||||
:return: never returns
|
||||
'''
|
||||
# ------- Make a new Window ------- #
|
||||
sg.ChangeLookAndFeel('GreenTan') # give our form a spiffy set of colors
|
||||
|
||||
layout = [
|
||||
[sg.Text('Ask and your answer will appear here....')],
|
||||
[sg.Output(size=(900, 500), font=('Courier', 10))],
|
||||
[ sg.Spin(values=(1, 4), initial_value=1, size=(50, 25), key='Num Answers', font=('Helvetica', 15)),
|
||||
sg.Text('Num Answers',font=('Helvetica', 15), size=(170,22)), sg.Checkbox('Display Full Text', key='full text', font=('Helvetica', 15), size=(200,22)),
|
||||
sg.T('Command History', font=('Helvetica', 15)), sg.T('', size=(100,25), text_color=sg.BLUES[0], key='history'), sg.Stretch()],
|
||||
[sg.Multiline(size=(600, 100), enter_submits=True, focus=True, key='query', do_not_clear=False), sg.Stretch(),
|
||||
sg.ReadButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True),
|
||||
sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0])), sg.Stretch()]
|
||||
]
|
||||
|
||||
window = sg.Window('How Do I ??',
|
||||
default_element_size=(100, 25),
|
||||
# element_padding=(10,10),
|
||||
icon=DEFAULT_ICON,
|
||||
font=('Helvetica',14),
|
||||
default_button_element_size=(70,50),
|
||||
return_keyboard_events=True,
|
||||
no_titlebar=False,
|
||||
grab_anywhere=True,)
|
||||
|
||||
window.Layout(layout)
|
||||
# ---===--- Loop taking in user input and using it to query HowDoI --- #
|
||||
command_history = []
|
||||
history_offset = 0
|
||||
while True:
|
||||
event, values = window.Read()
|
||||
if event == 'SEND' or event == 'query':
|
||||
# window.FindElement('+OUTPUT+').Update('test of output') # manually clear input because keyboard events blocks clear
|
||||
|
||||
query = values['query'].rstrip()
|
||||
# print(query)
|
||||
QueryHowDoI(query, values['Num Answers'], values['full text']) # send the string to HowDoI
|
||||
command_history.append(query)
|
||||
history_offset = len(command_history)-1
|
||||
window.FindElement('query').Update('') # manually clear input because keyboard events blocks clear
|
||||
window.FindElement('history').Update('\n'.join(command_history[-3:]))
|
||||
elif event == None or event == 'EXIT': # if exit button or closed using X
|
||||
break
|
||||
elif 'Up' in event and len(command_history): # scroll back in history
|
||||
command = command_history[history_offset]
|
||||
history_offset -= 1 * (history_offset > 0) # decrement is not zero
|
||||
window.FindElement('query').Update(command)
|
||||
elif 'Down' in event and len(command_history): # scroll forward in history
|
||||
history_offset += 1 * (history_offset < len(command_history)-1) # increment up to end of list
|
||||
command = command_history[history_offset]
|
||||
window.FindElement('query').Update(command)
|
||||
elif 'Escape' in event: # clear currently line
|
||||
window.FindElement('query').Update('')
|
||||
|
||||
|
||||
def QueryHowDoI(Query, num_answers, full_text):
|
||||
'''
|
||||
Kicks off a subprocess to send the 'Query' to HowDoI
|
||||
Prints the result, which in this program will route to a gooeyGUI window
|
||||
:param Query: text english question to ask the HowDoI web engine
|
||||
:return: nothing
|
||||
'''
|
||||
howdoi_command = HOW_DO_I_COMMAND
|
||||
full_text_option = ' -a' if full_text else ''
|
||||
t = subprocess.Popen(howdoi_command + ' \"'+ Query + '\" -n ' + str(num_answers)+full_text_option, stdout=subprocess.PIPE)
|
||||
(output, err) = t.communicate()
|
||||
print('{:^88}'.format(Query.rstrip()))
|
||||
print('_'*60)
|
||||
print(output.decode("utf-8") )
|
||||
exit_code = t.wait()
|
||||
|
||||
if __name__ == '__main__':
|
||||
HowDoI()
|
||||
|
5679
PySimpleGUIQt/PySimpleGUIQt.py
Normal file
5679
PySimpleGUIQt/PySimpleGUIQt.py
Normal file
File diff suppressed because it is too large
Load diff
68
PySimpleGUIQt/Qt_All_Widgets.py
Normal file
68
PySimpleGUIQt/Qt_All_Widgets.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] >= 3:
|
||||
import PySimpleGUIQt as sg
|
||||
else:
|
||||
import PySimpleGUI27 as sg
|
||||
|
||||
sg.ChangeLookAndFeel('Topanga')
|
||||
# sg.SetOptions(element_padding=(0,0))
|
||||
# ------ Menu Definition ------ #
|
||||
menu_def = [['&File', ['&Open', '&Save', 'E&xit', 'Properties']],
|
||||
['&Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
|
||||
['&Help', '&About...'], ]
|
||||
|
||||
# ------ Column Definition ------ #
|
||||
column1 = [[sg.Text('Column 1', background_color='lightblue',text_color='black', justification='center', size=(100,22))],
|
||||
[sg.Spin((1,10), size=(100,22))],
|
||||
[sg.Spin((1,10), size=(100,22))],
|
||||
[sg.Spin((1,10), size=(100,22))],]
|
||||
|
||||
layout = [
|
||||
[sg.Menu(menu_def, tearoff=True)],
|
||||
[sg.Text('(Almost) All widgets in one Window!', justification='c', font=("Helvetica", 25), relief=sg.RELIEF_RIDGE)],
|
||||
[sg.Text('Here is some text.... and a place to enter text')],
|
||||
[sg.InputText('This is my text', size=(400,22))],
|
||||
[sg.Frame(layout=[
|
||||
[sg.Checkbox('Checkbox', size=(185,22)), sg.Checkbox('My second checkbox!', default=True)],
|
||||
[sg.Radio('My first Radio!', "RADIO1", default=True, size=(180,22), ),sg.Radio('My second Radio!', "RADIO1")],
|
||||
[sg.Radio('Third Radio!', "RADIO2", default=True, size=(180,22), ),sg.Radio('Fourth Radio!', "RADIO2")]
|
||||
|
||||
], title='Options',title_color='red', relief=sg.RELIEF_SUNKEN, tooltip='Use these to set flags', ), sg.Stretch()],
|
||||
[sg.Multiline(default_text='This is the default Text should you decide not to type anything', size=(220, 80)),
|
||||
sg.Multiline(default_text='A second multi-line', size=(220, 80))],
|
||||
[sg.InputCombo(('Combobox 1', 'Combobox 2'), size=(150, 22)), sg.Stretch(),
|
||||
sg.Slider(range=(1, 100), orientation='h', size=(300, 22), default_value=85)],
|
||||
[sg.InputOptionMenu(('Menu Option 1', 'Menu Option 2', 'Menu Option 3'))],
|
||||
[sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(200,100), select_mode=sg.LISTBOX_SELECT_MODE_SINGLE), sg.Stretch(),
|
||||
sg.Frame('Labelled Group',[[
|
||||
sg.Slider(range=(1, 100), orientation='v', default_value=25, tick_interval=25),
|
||||
sg.Slider(range=(1, 100), orientation='v', default_value=75),
|
||||
sg.Slider(range=(1, 100), orientation='v', default_value=10),
|
||||
sg.Column(column1, background_color='red')]]), sg.Stretch()],
|
||||
[sg.Text('_' * 50, justification='c')],
|
||||
[sg.Text('Choose A Folder')],
|
||||
[sg.Text('Your Folder'),
|
||||
sg.InputText('Default Folder', size=(300,22)), sg.FolderBrowse(), sg.Stretch()],
|
||||
[sg.Submit(tooltip='Click to submit this form',), sg.Cancel()]]
|
||||
|
||||
window = sg.Window('Everything bagel',
|
||||
grab_anywhere=False,
|
||||
font=('Helvetica', 12),
|
||||
no_titlebar=False,
|
||||
alpha_channel=1,
|
||||
keep_on_top=False,
|
||||
element_padding=(2,3),
|
||||
default_element_size=(100, 23),
|
||||
default_button_element_size=(120,30)
|
||||
).Layout(layout)
|
||||
event, values = window.Read()
|
||||
|
||||
window.Close()
|
||||
|
||||
sg.Popup('Title',
|
||||
'The results of the window.',
|
||||
'The button clicked was "{}"'.format(event),
|
||||
'The values are', values)
|
||||
|
||||
|
17
PySimpleGUIQt/Qt_Dial.py
Normal file
17
PySimpleGUIQt/Qt_Dial.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
import PySimpleGUIQt as sg
|
||||
|
||||
layout = [
|
||||
[sg.Text('This is the new Dial Element!')],
|
||||
[sg.Dial(range=(1,100), key='_DIAL_')],
|
||||
[sg.Button('Show'), sg.Button('Exit')]
|
||||
]
|
||||
|
||||
window = sg.Window('Window Title').Layout(layout)
|
||||
|
||||
while True: # Event Loop
|
||||
event, values = window.Read()
|
||||
print(event, values)
|
||||
if event is None or event == 'Exit':
|
||||
break
|
||||
|
||||
window.Close()
|
30
PySimpleGUIQt/Qt_Test.py
Normal file
30
PySimpleGUIQt/Qt_Test.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import PySimpleGUIQt as sg
|
||||
# sg.Popup('test 1')
|
||||
# sg.Popup('test 2')
|
||||
sg.ChangeLookAndFeel('GreenTan')
|
||||
layout = [
|
||||
[sg.Text('Hello From PySimpleGUIQt!', text_color='red', tooltip='This is my tooltip', justification='c', font=('Courier', 22), key='_TEXT_')],
|
||||
[sg.Text('Input something here'),sg.Stretch(), sg.Input('This is an InputText Element', key='_INPUT_', font=('Any', 14))],
|
||||
[sg.Text('This is the new Dial Element'), sg.Dial(background_color='red'), sg.Stretch()],
|
||||
[sg.Combo(['Combo 1', 'Combo 2', 'Combo 3'], key='+COMBO+', size=(150,30), text_color='green')],
|
||||
[sg.Listbox(['Listbox Item 1', 'Listbox Item 2', 'Listbox Item 3'], key='+LIST+', size=(200,150), text_color='blue'),sg.Slider((1,100), orientation='v', key='+SLIDER 1+')],
|
||||
[sg.Slider((1,10), size=(200,30), orientation='h', key='+SLIDER 2+'), sg.Stretch()],
|
||||
[sg.Checkbox('Checkbox 1', key='+CB1+'), sg.Checkbox('Checkbox 2', key='+CB2')],
|
||||
[sg.Checkbox('Checkbox 3'), sg.Checkbox('Checkbox 4')],
|
||||
[sg.Radio('Radio1', group_id=1),sg.Radio('Radio2', group_id=1)],
|
||||
[sg.Spin((5,8), size=(100,30))],
|
||||
[sg.Multiline('This is a Multiline Element', size=(300,300), key='+MULTI+')],
|
||||
[sg.Button('My Button', size=(120,30)), sg.Exit(), sg.Button('Change', key='_CHANGE_')],
|
||||
]
|
||||
|
||||
window = sg.Window('My first QT Window', auto_size_text=True, auto_size_buttons=False, font=('Helvetica', 16)).Layout(layout)
|
||||
|
||||
while True:
|
||||
event, values = window.Read()
|
||||
print(event, values)
|
||||
if event is None or event == 'Exit':
|
||||
break
|
||||
|
||||
window.FindElement('_TEXT_').Update(values['_INPUT_'], font=('Helvetica', 30))
|
||||
if event == '_CHANGE_':
|
||||
window.FindElement('_CHANGE_').Update('Disabled', disabled=True, button_color=('gray', 'gray20'),)
|
BIN
PySimpleGUIQt/__pycache__/PySimpleGUIQt.cpython-36.pyc
Normal file
BIN
PySimpleGUIQt/__pycache__/PySimpleGUIQt.cpython-36.pyc
Normal file
Binary file not shown.
BIN
PySimpleGUIQt/question.ico
Normal file
BIN
PySimpleGUIQt/question.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 43 KiB |
Loading…
Add table
Add a link
Reference in a new issue