Path: csiph.com!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!news.unit0.net!peer02.am4!peer.am4.highwinds-media.com!peer04.fr7!futter-mich.highwinds-media.com!news.highwinds-media.com!fx39.am4.POSTED!not-for-mail Received-SPF: neutral (Address does not pass the Sender Policy Framework) SPF=MAILFROM; sender=filbar@centrum.cz; remoteip=::ffff:93.187.105.137; remotehost=; helo=smtp-b.warnet.cz; receiver=hugo.zagamma.cz; From: filbar@centrum.cz X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=_hugo.zagamma.cz-15969-1523459001-0001-2" Received-SPF: neutral (Address does not pass the Sender Policy Framework) SPF=FROM; sender=filbar@centrum.cz; remoteip=::ffff:93.187.105.137; remotehost=; helo=smtp-b.warnet.cz; receiver=hugo.zagamma.cz; Subject: [python] =?utf-8?q?Python_Xlib_-_skript_na_usp=C3=A1v=C3=A1n?= =?utf-8?b?w60gUEM=?= X-BeenThere: python@py.cz X-Mailman-Version: 2.1.26 Precedence: list List-Id: Konference PyCZ List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: cz.comp.lang.python Message-ID: X-Mailman-Original-Message-ID: <20180411170319.1b7b9040.filbar@centrum.cz> References: <20180411170319.1b7b9040.filbar@centrum.cz> Lines: 164 X-Complaints-To: abuse@usenet-news.net NNTP-Posting-Date: Wed, 11 Apr 2018 15:03:23 UTC Organization: usenet-news.net Date: Wed, 11 Apr 2018 17:03:19 +0200 X-Received-Bytes: 7206 X-Received-Body-CRC: 3818979657 Xref: csiph.com cz.comp.lang.python:3282 This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --=_hugo.zagamma.cz-15969-1523459001-0001-2 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Ahojte, p=C5=99ed u=C5=BE hooodn=C4=9B dlouhoou dobou jsem si napsal skriptik na au= tomatick=C3=A9 uspavani PC(pou=C5=BE=C3=ADv=C3=A1m v linuxu velmi jednoduch=C3=BD desktop = manager icewm), jenom=C5=BEe p=C5=99ed cca p=C5=AFl rokem mi p=C5=99estal fungovat.=20 S pomoc=C3=AD http://www.abclinuxu.cz/poradna/linux/show/436097#6 jsem vy=C5=99e=C5=A1il prvn=C3=AD probl=C3=A9m, jenom=C5=BEe jsem zjistil, =C5= =BEe mi skript pad=C3=A1 je=C5=A1t=C4=9B na =C5=99=C3=A1dc=C3=ADch 62 a 74 na "Neopr=C3=A1vn=C4=9Bn=C3=BD p=C5=99=C3=AD= stup do pam=C4=9Bti (SIGSEGV)". Proto=C5=BEe nejsem =C5=BE=C3=A1dn=C3=BD odborn=C3=ADk na Python, sp=C3=AD= =C5=A1e si v n=C4=9Bm jednou za =C4=8Das nap=C3=AD=C5=A1u n=C4=9Bco jednoduch=C3=A9ho, cht=C4=9Bl jsem poprosit zdej= =C5=A1=C3=AD komunitu jestli by mi neporadili jak skript opravit. P=C5=99edem d=C4=9Bkuji za rady. Filip Bartmann --=_hugo.zagamma.cz-15969-1523459001-0001-2 Content-Type: text/x-python; charset=iso-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=powerman.py #!/usr/bin/env python2 from ctypes import *; import ctypes; import os; import sys; import getopt; import time; import configparser; import string; class XScreenSaverInfo(ctypes.Structure): """ typedef struct { ... } XScreenSaverInfo; """ _fields_ = [('window', ctypes.c_ulong), # screen saver window ('state', ctypes.c_int), # off,on,disabled ('kind', ctypes.c_int), # blanked,internal,external ('since', ctypes.c_ulong), # milliseconds ('idle', ctypes.c_ulong), # milliseconds ('event_mask', ctypes.c_ulong)] # events class PowerMan: def __init__( self): self.state=True; self.suspended=False; if(os.path.isfile(os.path.join(os.getenv('HOME'),'.powerman.cfg'))): config=configparser.RawConfigParser(); config.read(os.path.join(os.getenv('HOME'),'.powerman.cfg')); self.stime=int(config.getint('Base', 'time')); self.prog=config.get('Base', 'program'); else: self.stime=20; self.prog=""; opts, args=getopt.getopt(sys.argv[1:], "t:p:"); for o,a in opts: if o=='-t': self.stime=a; if o=='-p': self.prog=a; display_p=ctypes.c_void_p; xid=ctypes.c_ulong; self.xlib = ctypes.cdll.LoadLibrary('libX11.so.6'); self.xlib.XOpenDisplay.restype=display_p self.xlib.XOpenDisplay.argtypes=ctypes.c_char_p, self.xlib.XDefaultRootWindow.restype=xid self.xlib.XDefaultRootWindow.argtypes=display_p, self.dpy=self.xlib.XOpenDisplay(None); if not self.dpy: raise Exception('Cannot open display') self.root=self.xlib.XDefaultRootWindow(self.dpy) self.xss=ctypes.cdll.LoadLibrary('libXss.so.1') self.xss.XScreenSaverAllocInfo.restype=ctypes.POINTER(XScreenSaverInfo) self.xss_info=self.xss.XScreenSaverAllocInfo() def get_idle(self): # Zde pada self.xss.XScreenSaverQueryInfo(self.dpy,self.root,self.xss_info) self.idle=self.xss_info.contents.idle/1000; def get_idle_workaround(self): dummy=c_int(); standby=c_int(); suspend=c_int(); state=c_int(); onoff=c_int(); off=c_int(); dpms=ctypes.cdll.LoadLibrary("libXext.so"); # Zde pada if dpms.DPMSQueryExtension(self.dpy,byref(dummy),byref(dummy))==True: if dpms.DPMSCapable(self.dpy)==True: dpms.DPMSGetTimeouts(self.dpy,byref(standby),byref(suspend),byref(off)); dpms.DPMSInfo(self.dpy,byref(state),byref(onoff)); if int(onoff.value)==1: pstate=int(state.value); pstandby=int(standby.value); psuspend=int(suspend.value) poff=int(off.value); #DPMSModeStandby if pstate==1: if self.idle=int(self.stime): self.suspended=True; pid=os.fork(); if pid==0: self.idle=0; #os.execl(self.prog); os.execv(self.prog,[self.prog]); self.idle=0; else: self.idle=0; os.wait(); self.idle=0; time.sleep(1); def check_timeout(self): if self.state==True: if self.suspended==True: time.sleep(60); self.suspended=False; self.get_idle(); self.get_idle_workaround(); if int(self.idle/60)>=int(self.stime): self.suspended=True; pid=os.fork(); if pid==0: self.idle=0; os.execv(self.prog,[self.prog]); self.idle=0; else: self.idle=0; os.wait(); self.idle=0; return True; def quit(self): sys.exit(); if __name__ == "__main__": pm=PowerMan(); pm.run(); --=_hugo.zagamma.cz-15969-1523459001-0001-2--