Re: detect laptop open/close from within Python?

2018-04-26 Thread Thomas Jollans
On 26/04/18 17:37, Skip Montanaro wrote:
> I'm going through a bout of RSI problems with my wrists, so klst night
> I refreshed an old typing watcher program I wrote a couple decades ago
> (there's a comment about Python 1.4 in the code!):
> 
> https://github.com/smontanaro/python-bits/blob/master/watch.py
> 
> It's far from perfect and I'm sure miles behind more modern stuff, but
> it does the trick for me.
> 
> I noticed a feww minutes ago that when I opened my laptop it
> immediately locked the screen. It would be nice to get notified of
> open/close events on the laptop. Any idea if there is a signal I can
> catch (Ubuntu 17.10) or a Tk event I can respond to?

I think there's a dbus event that you should be able to listen for (but
I'll let you do the googling as to what that event is, exactly)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: detect laptop open/close from within Python?

2018-04-26 Thread Skip Montanaro
> Thanks, I do have that. Now to figure out when it changes state...
> Unfortunately, the timestamp on the file seems to update continuously,
> not just on state changes. Maybe /proc/acpi/wakeup will be of some
> use.

It appears that I can, at least some of the time. Might need to check
it more frequently than I check for human input, but that will likely
be good enough for my needs.

Thanks again for the pointer.

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: detect laptop open/close from within Python?

2018-04-26 Thread Skip Montanaro
> No idea if it'll work on your system, but on my laptop, there's a
> pseudo-file /proc/acpi/button/lid/LID0/state that has whether the lid
> is open or closed.

Thanks, I do have that. Now to figure out when it changes state...
Unfortunately, the timestamp on the file seems to update continuously,
not just on state changes. Maybe /proc/acpi/wakeup will be of some
use.

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: detect laptop open/close from within Python?

2018-04-26 Thread Chris Angelico
On Fri, Apr 27, 2018 at 1:37 AM, Skip Montanaro
 wrote:
> I'm going through a bout of RSI problems with my wrists, so klst night
> I refreshed an old typing watcher program I wrote a couple decades ago
> (there's a comment about Python 1.4 in the code!):
>
> https://github.com/smontanaro/python-bits/blob/master/watch.py
>
> It's far from perfect and I'm sure miles behind more modern stuff, but
> it does the trick for me.
>
> I noticed a feww minutes ago that when I opened my laptop it
> immediately locked the screen. It would be nice to get notified of
> open/close events on the laptop. Any idea if there is a signal I can
> catch (Ubuntu 17.10) or a Tk event I can respond to?
>

No idea if it'll work on your system, but on my laptop, there's a
pseudo-file /proc/acpi/button/lid/LID0/state that has whether the lid
is open or closed.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list