Python - Constantly running an event handler without wxPython?Python: What OS am I running on?Is there a way to run Python on Android?How to get the filename without the extension from a path in Python?How do I check what version of Python is running my script?How to make a Python script standalone executable to run without ANY dependency?Why does Python code run faster in a function?wxPython combo.ComboCtrl event handling issuewxPython window immediately crashes/closes with Komodo on MacwxPython Ignore or Delete EventswxPython: Catching key events globally
Does the Long March-11 increase its thrust after clearing the launch tower?
Why does Sin[b-a] simplify to -Sin[a-b]?
Longest bridge/tunnel that can be cycled over/through?
Traversing Oceania: A Cryptic Journey
Does Disney no longer produce hand-drawn cartoon films?
Who are the Missing Members of this Noble Family?
How is the excise border managed in Ireland?
Active low-pass filters --- good to what frequencies?
What is the maximum number of net attacks that one can make in a round?
Is it possible for a vehicle to be manufactured without a catalytic converter?
Wooden cooking layout
How can I get an unreasonable manager to approve time off?
Is it legal for a bar bouncer to confiscate a fake ID
Why can I traceroute to this IP address, but not ping?
Meaning of 'lose their grip on the groins of their followers'
Getting UPS Power from One Room to Another
Is using 'echo' to display attacker-controlled data on the terminal dangerous?
Thread Pool C++ Implementation
What aircraft was used as Air Force One for the flight between Southampton and Shannon?
Second (easy access) account in case my bank screws up
Missing delay in heavyside step function
Extreme flexible working hours: how to get to know people and activities?
Why does logistic function use e rather than 2?
Has there been a multiethnic Star Trek character?
Python - Constantly running an event handler without wxPython?
Python: What OS am I running on?Is there a way to run Python on Android?How to get the filename without the extension from a path in Python?How do I check what version of Python is running my script?How to make a Python script standalone executable to run without ANY dependency?Why does Python code run faster in a function?wxPython combo.ComboCtrl event handling issuewxPython window immediately crashes/closes with Komodo on MacwxPython Ignore or Delete EventswxPython: Catching key events globally
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm currently attempting to write a script using Python 2.7 (on Windows 7) that displays notifications using the notification software Snarl. Making the connection to Snarl requires the pySnarl module (link). The pySnarl module includes and Event Handler that basically checks to see if the notification has been closed or clicked on by a user and allows the script to run a function if such an event has occurred. I'm trying to implement this, however I cannot seem to get the Event handler to constantly listen for a click. There is an example script written by the author of the module (link) which shows use of the event handler and it works perfectly, but it gets the event handler to listen for clicks by making use of wxPython's app.MainLoop() command. I can't do this because my script is GUIless, I just want to use Windows Task Scheduler to run it every now and then in the background. I've tried a while True loop to get the Event Handler method constantly running but it does nothing except consume heaps of CPU. Here is my script (in the code formatting because I can't post more than 2 links right now):
http://pastebin.com/4udVehg1
TLDR; I want an Event Handler to listen for events but I don't know how to get it running without using wxPython's app.MainLoop() feature and I want my script to be GUIless.
Any help would be greatly appreciated.
Regards,
Jono.
python python-2.7 wxpython python-2.x
add a comment |
I'm currently attempting to write a script using Python 2.7 (on Windows 7) that displays notifications using the notification software Snarl. Making the connection to Snarl requires the pySnarl module (link). The pySnarl module includes and Event Handler that basically checks to see if the notification has been closed or clicked on by a user and allows the script to run a function if such an event has occurred. I'm trying to implement this, however I cannot seem to get the Event handler to constantly listen for a click. There is an example script written by the author of the module (link) which shows use of the event handler and it works perfectly, but it gets the event handler to listen for clicks by making use of wxPython's app.MainLoop() command. I can't do this because my script is GUIless, I just want to use Windows Task Scheduler to run it every now and then in the background. I've tried a while True loop to get the Event Handler method constantly running but it does nothing except consume heaps of CPU. Here is my script (in the code formatting because I can't post more than 2 links right now):
http://pastebin.com/4udVehg1
TLDR; I want an Event Handler to listen for events but I don't know how to get it running without using wxPython's app.MainLoop() feature and I want my script to be GUIless.
Any help would be greatly appreciated.
Regards,
Jono.
python python-2.7 wxpython python-2.x
Check out Twisted
– alfasin
Jul 21 '14 at 6:31
add a comment |
I'm currently attempting to write a script using Python 2.7 (on Windows 7) that displays notifications using the notification software Snarl. Making the connection to Snarl requires the pySnarl module (link). The pySnarl module includes and Event Handler that basically checks to see if the notification has been closed or clicked on by a user and allows the script to run a function if such an event has occurred. I'm trying to implement this, however I cannot seem to get the Event handler to constantly listen for a click. There is an example script written by the author of the module (link) which shows use of the event handler and it works perfectly, but it gets the event handler to listen for clicks by making use of wxPython's app.MainLoop() command. I can't do this because my script is GUIless, I just want to use Windows Task Scheduler to run it every now and then in the background. I've tried a while True loop to get the Event Handler method constantly running but it does nothing except consume heaps of CPU. Here is my script (in the code formatting because I can't post more than 2 links right now):
http://pastebin.com/4udVehg1
TLDR; I want an Event Handler to listen for events but I don't know how to get it running without using wxPython's app.MainLoop() feature and I want my script to be GUIless.
Any help would be greatly appreciated.
Regards,
Jono.
python python-2.7 wxpython python-2.x
I'm currently attempting to write a script using Python 2.7 (on Windows 7) that displays notifications using the notification software Snarl. Making the connection to Snarl requires the pySnarl module (link). The pySnarl module includes and Event Handler that basically checks to see if the notification has been closed or clicked on by a user and allows the script to run a function if such an event has occurred. I'm trying to implement this, however I cannot seem to get the Event handler to constantly listen for a click. There is an example script written by the author of the module (link) which shows use of the event handler and it works perfectly, but it gets the event handler to listen for clicks by making use of wxPython's app.MainLoop() command. I can't do this because my script is GUIless, I just want to use Windows Task Scheduler to run it every now and then in the background. I've tried a while True loop to get the Event Handler method constantly running but it does nothing except consume heaps of CPU. Here is my script (in the code formatting because I can't post more than 2 links right now):
http://pastebin.com/4udVehg1
TLDR; I want an Event Handler to listen for events but I don't know how to get it running without using wxPython's app.MainLoop() feature and I want my script to be GUIless.
Any help would be greatly appreciated.
Regards,
Jono.
python python-2.7 wxpython python-2.x
python python-2.7 wxpython python-2.x
asked Jul 21 '14 at 6:22
HeyItsJonoHeyItsJono
215
215
Check out Twisted
– alfasin
Jul 21 '14 at 6:31
add a comment |
Check out Twisted
– alfasin
Jul 21 '14 at 6:31
Check out Twisted
– alfasin
Jul 21 '14 at 6:31
Check out Twisted
– alfasin
Jul 21 '14 at 6:31
add a comment |
2 Answers
2
active
oldest
votes
Found a solution. I just needed to run the following at the end of my script:
while event_handling is True:
win32gui.PumpMessages() # Check for events, needs to be sent a WM_QUIT message to stop, handled in disable_event_handling()
time.sleep(0.1) # Check every 0.1 seconds
Then on a event being activated just call the following function to stop the script checking for events:
main_thread_id = win32api.GetCurrentThreadId()
event_handling = True
def disable_event_handling(): # Puts a stop to the loop that checks for events
global event_handling
event_handling = False
win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0) # Sends a QUIT message to win32gui.PumpMessages(), without this it wouldn't stop checking for messages to pump
return event_handling
Thanks for all the help and suggestions guys c:
add a comment |
Sounds like a job for PyPubSub : a package which provides a publish - subscribe Python API that facilitates event-based programming.
Check it out: http://pubsub.sourceforge.net/
Edit: PyPubSub is at https://github.com/schollii/pypubsub (since 2016)
Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?
– HeyItsJono
Jul 21 '14 at 8:54
All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net
– Mike Driscoll
Jul 21 '14 at 13:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24858805%2fpython-constantly-running-an-event-handler-without-wxpython%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Found a solution. I just needed to run the following at the end of my script:
while event_handling is True:
win32gui.PumpMessages() # Check for events, needs to be sent a WM_QUIT message to stop, handled in disable_event_handling()
time.sleep(0.1) # Check every 0.1 seconds
Then on a event being activated just call the following function to stop the script checking for events:
main_thread_id = win32api.GetCurrentThreadId()
event_handling = True
def disable_event_handling(): # Puts a stop to the loop that checks for events
global event_handling
event_handling = False
win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0) # Sends a QUIT message to win32gui.PumpMessages(), without this it wouldn't stop checking for messages to pump
return event_handling
Thanks for all the help and suggestions guys c:
add a comment |
Found a solution. I just needed to run the following at the end of my script:
while event_handling is True:
win32gui.PumpMessages() # Check for events, needs to be sent a WM_QUIT message to stop, handled in disable_event_handling()
time.sleep(0.1) # Check every 0.1 seconds
Then on a event being activated just call the following function to stop the script checking for events:
main_thread_id = win32api.GetCurrentThreadId()
event_handling = True
def disable_event_handling(): # Puts a stop to the loop that checks for events
global event_handling
event_handling = False
win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0) # Sends a QUIT message to win32gui.PumpMessages(), without this it wouldn't stop checking for messages to pump
return event_handling
Thanks for all the help and suggestions guys c:
add a comment |
Found a solution. I just needed to run the following at the end of my script:
while event_handling is True:
win32gui.PumpMessages() # Check for events, needs to be sent a WM_QUIT message to stop, handled in disable_event_handling()
time.sleep(0.1) # Check every 0.1 seconds
Then on a event being activated just call the following function to stop the script checking for events:
main_thread_id = win32api.GetCurrentThreadId()
event_handling = True
def disable_event_handling(): # Puts a stop to the loop that checks for events
global event_handling
event_handling = False
win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0) # Sends a QUIT message to win32gui.PumpMessages(), without this it wouldn't stop checking for messages to pump
return event_handling
Thanks for all the help and suggestions guys c:
Found a solution. I just needed to run the following at the end of my script:
while event_handling is True:
win32gui.PumpMessages() # Check for events, needs to be sent a WM_QUIT message to stop, handled in disable_event_handling()
time.sleep(0.1) # Check every 0.1 seconds
Then on a event being activated just call the following function to stop the script checking for events:
main_thread_id = win32api.GetCurrentThreadId()
event_handling = True
def disable_event_handling(): # Puts a stop to the loop that checks for events
global event_handling
event_handling = False
win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0) # Sends a QUIT message to win32gui.PumpMessages(), without this it wouldn't stop checking for messages to pump
return event_handling
Thanks for all the help and suggestions guys c:
answered Jul 25 '14 at 9:54
HeyItsJonoHeyItsJono
215
215
add a comment |
add a comment |
Sounds like a job for PyPubSub : a package which provides a publish - subscribe Python API that facilitates event-based programming.
Check it out: http://pubsub.sourceforge.net/
Edit: PyPubSub is at https://github.com/schollii/pypubsub (since 2016)
Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?
– HeyItsJono
Jul 21 '14 at 8:54
All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net
– Mike Driscoll
Jul 21 '14 at 13:59
add a comment |
Sounds like a job for PyPubSub : a package which provides a publish - subscribe Python API that facilitates event-based programming.
Check it out: http://pubsub.sourceforge.net/
Edit: PyPubSub is at https://github.com/schollii/pypubsub (since 2016)
Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?
– HeyItsJono
Jul 21 '14 at 8:54
All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net
– Mike Driscoll
Jul 21 '14 at 13:59
add a comment |
Sounds like a job for PyPubSub : a package which provides a publish - subscribe Python API that facilitates event-based programming.
Check it out: http://pubsub.sourceforge.net/
Edit: PyPubSub is at https://github.com/schollii/pypubsub (since 2016)
Sounds like a job for PyPubSub : a package which provides a publish - subscribe Python API that facilitates event-based programming.
Check it out: http://pubsub.sourceforge.net/
Edit: PyPubSub is at https://github.com/schollii/pypubsub (since 2016)
edited Mar 24 at 19:01
Oliver
16.2k32648
16.2k32648
answered Jul 21 '14 at 7:04
user2963623user2963623
1,9501924
1,9501924
Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?
– HeyItsJono
Jul 21 '14 at 8:54
All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net
– Mike Driscoll
Jul 21 '14 at 13:59
add a comment |
Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?
– HeyItsJono
Jul 21 '14 at 8:54
All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net
– Mike Driscoll
Jul 21 '14 at 13:59
Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?
– HeyItsJono
Jul 21 '14 at 8:54
Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?
– HeyItsJono
Jul 21 '14 at 8:54
All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net
– Mike Driscoll
Jul 21 '14 at 13:59
All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net
– Mike Driscoll
Jul 21 '14 at 13:59
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24858805%2fpython-constantly-running-an-event-handler-without-wxpython%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Check out Twisted
– alfasin
Jul 21 '14 at 6:31