commit
5624f8ae14
|
@ -1,8 +1,8 @@
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Threaded Demo - Uses Window.write_event_value communications
|
Threaded Demo - Uses Window.write_event_value communications
|
||||||
|
|
||||||
|
@ -30,8 +30,7 @@ def the_thread(window):
|
||||||
i = 0
|
i = 0
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
sg.cprint(f'thread info (in thread) = {threading.current_thread().name}', c='white on purple')
|
window.write_event_value('-THREAD-', (threading.current_thread().name, i)) # Data sent is a tuple of thread name and counter
|
||||||
window.write_event_value('-THREAD-', i)
|
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,27 +39,27 @@ def main():
|
||||||
The demo will display in the multiline info about the event and values dictionary as it is being
|
The demo will display in the multiline info about the event and values dictionary as it is being
|
||||||
returned from window.read()
|
returned from window.read()
|
||||||
Every time "Start" is clicked a new thread is started
|
Every time "Start" is clicked a new thread is started
|
||||||
Try clicking "go" to see that the window is active while the thread stuff is happening in the background
|
Try clicking "Dummy" to see that the window is active while the thread stuff is happening in the background
|
||||||
"""
|
"""
|
||||||
|
|
||||||
layout = [ [sg.Text('My Window')],
|
layout = [ [sg.Text('Output Area - cprint\'s route to here', font='Any 15')],
|
||||||
[sg.Multiline(size=(40,20), key='-ML-', autoscroll=True, reroute_stdout=True, write_only=True, reroute_cprint=True)],
|
[sg.Multiline(size=(65,20), key='-ML-', autoscroll=True, reroute_stdout=True, write_only=True, reroute_cprint=True)],
|
||||||
[sg.Input(key='-IN-')],
|
[sg.T('Input so you can see data in your dictionary')],
|
||||||
[sg.Button('Go'), sg.B('Start'), sg.Button('Exit')] ]
|
[sg.Input(key='-IN-', size=(30,1))],
|
||||||
|
[sg.B('Start A Thread'), sg.B('Dummy'), sg.Button('Exit')] ]
|
||||||
|
|
||||||
window = sg.Window('Window Title', layout)
|
window = sg.Window('Window Title', layout)
|
||||||
|
|
||||||
while True: # Event Loop
|
while True: # Event Loop
|
||||||
event, values = window.read()
|
event, values = window.read()
|
||||||
sg.cprint(event, values)
|
sg.cprint(event, values)
|
||||||
sg.cprint(f'thread info = {threading.current_thread().name}')
|
|
||||||
if event == sg.WIN_CLOSED or event == 'Exit':
|
if event == sg.WIN_CLOSED or event == 'Exit':
|
||||||
break
|
break
|
||||||
if event == 'Start':
|
if event.startswith('Start'):
|
||||||
thread = threading.Thread(target=the_thread, args=(window,), daemon=True)
|
threading.Thread(target=the_thread, args=(window,), daemon=True).start()
|
||||||
thread.start()
|
|
||||||
if event == THREAD_EVENT:
|
if event == THREAD_EVENT:
|
||||||
sg.cprint(f'Data from the thread = {values[THREAD_EVENT]}', colors='white on red')
|
sg.cprint(f'Data from the thread ', colors='white on purple', end='')
|
||||||
|
sg.cprint(f'{values[THREAD_EVENT]}', colors='white on red')
|
||||||
window.close()
|
window.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
version = __version__ = "4.25.0.1 Unreleased\nMoved creation of the multi-threaded "
|
version = __version__ = "4.26.0 Released 18-Jul-2020"
|
||||||
|
|
||||||
port = 'PySimpleGUI'
|
port = 'PySimpleGUI'
|
||||||
|
|
||||||
|
@ -6973,7 +6973,6 @@ class Window:
|
||||||
self.user_bind_event = None # Used when user defines a tkinter binding using bind method - event data from tkinter
|
self.user_bind_event = None # Used when user defines a tkinter binding using bind method - event data from tkinter
|
||||||
self.modal = modal
|
self.modal = modal
|
||||||
self.thread_queue = None # type: queue.Queue
|
self.thread_queue = None # type: queue.Queue
|
||||||
self.thread_key = None # type: Any
|
|
||||||
self.thread_strvar = None # type: tk.StringVar
|
self.thread_strvar = None # type: tk.StringVar
|
||||||
self.read_closed_window_count = 0
|
self.read_closed_window_count = 0
|
||||||
|
|
||||||
|
@ -8295,15 +8294,11 @@ class Window:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _create_thread_queue(self, key):
|
def _create_thread_queue(self):
|
||||||
"""
|
"""
|
||||||
Sets the key that will be returned if a thread communicates with this window.
|
Creates the queue used by threads to communicate with this window
|
||||||
|
|
||||||
:param key:
|
|
||||||
:type key: Any
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.thread_key = key
|
|
||||||
if self.thread_queue is None:
|
if self.thread_queue is None:
|
||||||
self.thread_queue = queue.Queue()
|
self.thread_queue = queue.Queue()
|
||||||
|
|
||||||
|
@ -8312,7 +8307,7 @@ class Window:
|
||||||
self.thread_strvar.trace('w', self._window_tkvar_changed_callback)
|
self.thread_strvar.trace('w', self._window_tkvar_changed_callback)
|
||||||
|
|
||||||
|
|
||||||
def write_event_value(self, key=None, value=None):
|
def write_event_value(self, key, value):
|
||||||
"""
|
"""
|
||||||
Adds a key & value tuple to the queue that is used by threads to communicate with the window
|
Adds a key & value tuple to the queue that is used by threads to communicate with the window
|
||||||
|
|
||||||
|
@ -8323,12 +8318,11 @@ class Window:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.thread_queue is None:
|
if self.thread_queue is None:
|
||||||
self._create_thread_queue(key)
|
print('*** Warning Window.write_event_value - no thread queue found ***')
|
||||||
|
return
|
||||||
|
|
||||||
if self.thread_queue:
|
self.thread_queue.put(item=(key, value))
|
||||||
key = key if key is not None else self.thread_key
|
self.thread_strvar.set('new item')
|
||||||
self.thread_queue.put(item=(key, value))
|
|
||||||
self.thread_strvar.set('new item')
|
|
||||||
|
|
||||||
|
|
||||||
def _queued_event_read(self):
|
def _queued_event_read(self):
|
||||||
|
@ -12045,7 +12039,7 @@ def StartupTK(my_flex_form):
|
||||||
|
|
||||||
my_flex_form.TKroot = root
|
my_flex_form.TKroot = root
|
||||||
|
|
||||||
my_flex_form._create_thread_queue('initialized queue')
|
my_flex_form._create_thread_queue()
|
||||||
|
|
||||||
# Make moveable window
|
# Make moveable window
|
||||||
if (my_flex_form.GrabAnywhere is not False and not (
|
if (my_flex_form.GrabAnywhere is not False and not (
|
||||||
|
|
|
@ -3434,7 +3434,7 @@ Parameter Descriptions:
|
||||||
|
|
||||||
|Type|Name|Meaning|
|
|Type|Name|Meaning|
|
||||||
|--|--|--|
|
|--|--|--|
|
||||||
| str | default_text | Text initially shown in the input box as a default value(Default value = '') |
|
| Any | default_text | Text initially shown in the input box as a default value(Default value = ''). Will automatically be converted to string |
|
||||||
| (int, int) (width, height) | size | w=characters-wide, h=rows-high |
|
| (int, int) (width, height) | size | w=characters-wide, h=rows-high |
|
||||||
| bool | disabled | set disable state for element (Default = False) |
|
| bool | disabled | set disable state for element (Default = False) |
|
||||||
| char | password_char | Password character if this is a password field (Default value = '') |
|
| char | password_char | Password character if this is a password field (Default value = '') |
|
||||||
|
@ -9869,7 +9869,7 @@ Returns True if the window was closed
|
||||||
Adds a key & value tuple to the queue that is used by threads to communicate with the window
|
Adds a key & value tuple to the queue that is used by threads to communicate with the window
|
||||||
|
|
||||||
```
|
```
|
||||||
write_event_value(key=None, value=None)
|
write_event_value(key, value)
|
||||||
```
|
```
|
||||||
|
|
||||||
Parameter Descriptions:
|
Parameter Descriptions:
|
||||||
|
|
|
@ -7384,6 +7384,13 @@ k element parameter
|
||||||
* New global variable __tclversion_detailed__ - string with full tkinter version (3 numbers instead of 2)
|
* New global variable __tclversion_detailed__ - string with full tkinter version (3 numbers instead of 2)
|
||||||
* Warning is displayed if tcl version is found to be 8.5.
|
* Warning is displayed if tcl version is found to be 8.5.
|
||||||
|
|
||||||
|
## 4.26.0 PySimpleGUI 18-Jul-2020
|
||||||
|
|
||||||
|
* Multi-threaded tkvar initialization location changed so that thread doesn't intialize it now
|
||||||
|
* Removed thread key - no longer needed
|
||||||
|
* Window.write_event_values - now requires both parms
|
||||||
|
* Upgrade button typo
|
||||||
|
|
||||||
### Upcoming
|
### Upcoming
|
||||||
|
|
||||||
There will always be overlapping work as the ports will never actually be "complete" as there's always something new that can be built. However there's a definition for the base functionality for PySimpleGUI. This is what is being strived for with the current ports that are underway.
|
There will always be overlapping work as the ports will never actually be "complete" as there's always something new that can be built. However there's a definition for the base functionality for PySimpleGUI. This is what is being strived for with the current ports that are underway.
|
||||||
|
|
|
@ -7384,6 +7384,13 @@ k element parameter
|
||||||
* New global variable __tclversion_detailed__ - string with full tkinter version (3 numbers instead of 2)
|
* New global variable __tclversion_detailed__ - string with full tkinter version (3 numbers instead of 2)
|
||||||
* Warning is displayed if tcl version is found to be 8.5.
|
* Warning is displayed if tcl version is found to be 8.5.
|
||||||
|
|
||||||
|
## 4.26.0 PySimpleGUI 18-Jul-2020
|
||||||
|
|
||||||
|
* Multi-threaded tkvar initialization location changed so that thread doesn't intialize it now
|
||||||
|
* Removed thread key - no longer needed
|
||||||
|
* Window.write_event_values - now requires both parms
|
||||||
|
* Upgrade button typo
|
||||||
|
|
||||||
### Upcoming
|
### Upcoming
|
||||||
|
|
||||||
There will always be overlapping work as the ports will never actually be "complete" as there's always something new that can be built. However there's a definition for the base functionality for PySimpleGUI. This is what is being strived for with the current ports that are underway.
|
There will always be overlapping work as the ports will never actually be "complete" as there's always something new that can be built. However there's a definition for the base functionality for PySimpleGUI. This is what is being strived for with the current ports that are underway.
|
||||||
|
|
Loading…
Reference in New Issue