11#!/usr/bin/python3
22# -*- coding: utf-8 -*-
33
4- # local modules
5- from .base import DSIBase
6- from .window import WindowBase
7- from .image import Image
8- from .buttons import MouseButtons
9- from .box import Box
10-
114# built-in modules
5+ from typing import Optional
126import logging
137import ctypes .util
148from ctypes import (
2923 _SimpleCData
3024)
3125
26+ # local modules
27+ from .base import DSIBase
28+ from .window import WindowBase
29+ from .image import Image
30+ from .buttons import MouseButtons
31+ from .box import Box
32+
3233# Setup Xlib Structures
3334
3435
@@ -202,7 +203,7 @@ def get_logger() -> logging.Logger:
202203# Setup Xlib Variables
203204
204205
205- class Masks ( object ) :
206+ class Masks :
206207 """
207208 https://tronche.com/gui/x/xlib/events/mask.html\n
208209 /usr/include/X11/X.h: 150-175
@@ -235,7 +236,7 @@ class Masks(object):
235236 OwnerGrabButtonMask = 16777216
236237
237238
238- class EventTypes ( object ) :
239+ class EventTypes :
239240 """
240241 https://tronche.com/gui/x/xlib/events/types.html\n
241242 /usr/include/X11/X.h: 181-215
@@ -277,7 +278,7 @@ class EventTypes(object):
277278 LASTEvent = 36
278279
279280
280- class KeyMasks ( object ) :
281+ class KeyMasks :
281282 """
282283 https://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html\n
283284 /usr/include/X11/X.h: 221-228
@@ -292,12 +293,12 @@ class KeyMasks(object):
292293 Mod5Mask = 128
293294
294295
295- class Xlib ( object ) :
296+ class Xlib :
296297 def __init__ (self ):
297298 # load libX11.so.6
298299 x11 = ctypes .util .find_library ("X11" )
299300 if not x11 :
300- raise Exception ("X11 library not found!" )
301+ raise FileNotFoundError ("X11 library not found!" )
301302 self .xlib = ctypes .cdll .LoadLibrary (x11 )
302303
303304 self .xlib .XSetErrorHandler (error_handler )
@@ -370,8 +371,7 @@ def __init__(self):
370371 def __getattribute__ (self , __name : str ):
371372 if __name in ["xlib" , "display" , "root_window" ]:
372373 return super ().__getattribute__ (__name )
373- else :
374- return self .xlib .__getattribute__ (__name )
374+ return self .xlib .__getattribute__ (__name )
375375
376376
377377def get_window_property (xlib : Xlib , window_xid : int , property : str , type : _SimpleCData ):
@@ -431,8 +431,7 @@ def name(self) -> str:
431431 )
432432 if name :
433433 return name .decode ('utf-8' )
434- else :
435- return None
434+ return None
436435
437436 @property
438437 def pid (self ) -> int :
@@ -453,7 +452,7 @@ def geometry(self) -> Box:
453452 height = gwa .height
454453 )
455454
456- def get_image (self , geometry : Box = None ) -> Image :
455+ def get_image (self , geometry : Optional [ Box ] = None ) -> Image :
457456 if geometry is None :
458457 geometry = self .geometry
459458
@@ -518,7 +517,7 @@ def send_str(self, str: str) -> None:
518517 for chr in str :
519518 self .send_chr (chr )
520519
521- def warp_pointer (self , x : int , y : int , geometry : Box = None ) -> None :
520+ def warp_pointer (self , x : int , y : int , geometry : Optional [ Box ] = None ) -> None :
522521 if geometry is None :
523522 geometry = self .geometry
524523
0 commit comments