Use abstract classes, add missing final newlines, add missing __init__.py, fix ternary

This commit is contained in:
Charles Milette 2018-07-22 19:27:39 -04:00 committed by Samuel Henrique
parent 0746e92b8d
commit 5edce4c2d7
7 changed files with 38 additions and 20 deletions

View file

@ -85,7 +85,7 @@ def main(argv=None):
if not options.wallpaper:
print("[I]gnore and continue / ", end='')
print("[A]bort")
inp = input("Pick one: ").lower() # FIXME weird bug: s doesn not actually closes the older process but -c does
inp = input("Pick one: ").lower() # FIXME weird bug: inputting s here doesn't actually close the older process but "pokemon -c" does
if inp == 's':
e.set()
break
@ -95,7 +95,6 @@ def main(argv=None):
return
else:
print("Not a valid option!\n")
continue
if options.slideshow <= 0:
print("Time has to be greater then 0. You can use decimal values.")
return

View file

View file

@ -1,57 +1,67 @@
class NamedEvent:
from abc import ABC, abstractmethod
class NamedEvent(ABC):
"""
Interface representing an operating system event object with a name.
"""
@abstractmethod
def __init__(self, name: str):
"""
create NamedEvent object
:param name Name of the event
"""
raise NotImplementedError()
pass
@abstractmethod
def is_set(self) -> bool:
"""
check if event set
:return a boolean indicating wether the event has been set.
"""
raise NotImplementedError()
pass
@abstractmethod
def set(self):
"""
sets the event
"""
raise NotImplementedError()
pass
@abstractmethod
def clear(self):
"""
resets the event
"""
raise NotImplementedError()
pass
@abstractmethod
def wait(self, timeout=None):
"""
block until event is set
:param timeout Optional timeout for wait in seconds.
"""
raise NotImplementedError()
pass
@abstractmethod
def is_duplicate(self) -> bool:
"""
determines if the event was created or opened as a result of creating this class
:return True if it was opened. False if it was created.
"""
raise NotImplementedError()
pass
@abstractmethod
def name(self) -> str:
"""
gets the name set at creation of the event
:return Name of the event
"""
raise NotImplementedError()
pass
@abstractmethod
def close(self):
"""
release native resources
"""
raise NotImplementedError()
pass

View file

@ -16,7 +16,7 @@ class PosixNamedEvent(NamedEvent):
self.__semaphore = posix_ipc.Semaphore(semaphore_name)
self.__duplicate = False
# NOTE this doesn't works on macOS
# NOTE this doesn't works on macOS, see http://semanchuk.com/philip/posix_ipc/#platforms
def is_set(self) -> bool:
return self.__semaphore.value > 0
@ -26,7 +26,7 @@ class PosixNamedEvent(NamedEvent):
def clear(self):
try:
# Decrement until we reach 0 (in which case BusyError will be thrown)
for _ in range(posix_ipc.SEMAPHORE_VALUE_MAX if posix_ipc.SEMAPHORE_VALUE_SUPPORTED else self.__semaphore.value):
for _ in range(self.__semaphore.value if posix_ipc.SEMAPHORE_VALUE_SUPPORTED else posix_ipc.SEMAPHORE_VALUE_MAX):
self.__semaphore.acquire(0)
except posix_ipc.BusyError:
return
@ -41,4 +41,4 @@ class PosixNamedEvent(NamedEvent):
return self.__semaphore.name
def close(self):
self.__semaphore.close()
self.__semaphore.close()

View file

@ -56,4 +56,4 @@ class WindowsNamedEvent(NamedEvent):
def close(self):
result = ctypes.windll.kernel32.CloseHandle(self.__event)
if result == 0:
WindowsNamedEvent.__raise_last_error()
WindowsNamedEvent.__raise_last_error()

View file

@ -1,27 +1,32 @@
class TerminalProvider:
from abc import ABC, abstractmethod
class TerminalProvider(ABC):
"""
Interface representing all the different terminal emulators supported
by pokemon-terminal if you want to implement a TE, create a module in this
folder that implements this interface, reflection will do the rest.
"""
@abstractmethod
def change_terminal(path: str):
"""
This sets the wallpaper of the corresponding TE of this adapter.
:param path The full path of the required pokemon image
"""
raise NotImplementedError()
pass
@abstractmethod
def is_compatible() -> bool:
"""
checks for compatibility
:return a boolean saying whether or not the current adaptor is
compatible with the running TE
"""
raise NotImplementedError()
pass
@abstractmethod
def clear():
"""
Clear the terminal's background image.
"""
raise NotImplementedError()
pass

View file

@ -1,10 +1,13 @@
class WallpaperProvider:
from abc import ABC, abstractmethod
class WallpaperProvider(ABC):
"""
Interface representing all the different desktop environments supported
by pokemon-terminal if you want to implement a DE, create a module in this
folder that implements this interface, reflection will do the rest.
"""
@abstractmethod
def change_wallpaper(path: str):
"""
This sets the wallpaper of the corresponding D.E of this adapter.
@ -12,6 +15,7 @@ class WallpaperProvider:
"""
raise NotImplementedError()
@abstractmethod
def is_compatible() -> bool:
"""
checks for compatibility