-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to remove all gdk threads_enter and leave calls
Changed used module for handling of threads from _thread to threading. Threading has better API and allows us to distinguish threads more easily. However there is a minor problem. When Gdk Window is passed as a argument to method executed in different thread then it is converted before execution of method into Gtk box. That is why i removed parent argument from connect method of GUI class. Parent argument has been removed from connect method of GUI class. Reasons described above. Connect was always called with the same parent anyway so this does not change its function. Added thread_operations.py file. It contains decorator which simulates some functionalities provided by deprecated functions. Some calls of deprecated functions have been replaced by Gdk_threads_add_idle function.
- Loading branch information
1 parent
e58d4c9
commit d9c828e
Showing
3 changed files
with
84 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import threading | ||
gi.require_version('Gdk', '3.0') | ||
from gi.repository import Gdk, GLib | ||
|
||
SCP_MAIN_THREAD_NAME = "SCP_MAIN_THREAD" | ||
|
||
def thread_safe_blocking_call(function): | ||
""" Make function/method thread safe and block until its call is finished | ||
""" | ||
|
||
blocker = threading.Event() | ||
|
||
def inner_wrapper(*args, **kwargs): | ||
function(*args, **kwargs) | ||
blocker.set() | ||
return False | ||
|
||
def wrapper(*args, **kwargs): | ||
# if this is the main thread then simply return function | ||
if threading.current_thread().name == SCP_MAIN_THREAD_NAME: | ||
return function(*args, **kwargs) | ||
Gdk.threads_add_idle( | ||
GLib.PRIORITY_DEFAULT_IDLE, | ||
inner_wrapper, | ||
*args, | ||
**kwargs | ||
) | ||
blocker.wait() | ||
|
||
return wrapper |