Created
December 12, 2017 14:51
-
-
Save monsieurh/8911decb6385b88fa0f1f937e5c02e08 to your computer and use it in GitHub Desktop.
screen abstraction proposition for ZPUI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyApp: | |
def __init__(self, o): | |
# type: (AbstractScreen) -> None | |
self.o = o | |
self.my_loading_bar = LoadingBar(o) # As an app developper I don't wanna know what the screens are ! | |
def on_start(self): | |
self.my_loading_bar.activate() | |
# or procedural if you prefer ;) | |
# def init_app(i,o): | |
# global my_loading_bar | |
# my_loading_bar = Loadingbar(o) | |
# | |
# def callback(): | |
# my_loading_bar.activate() | |
class LoadingBar: | |
def __new__(cls, o): | |
# here we use __new__ instead of __init__ so we can return something else instead | |
# of an instance of LoadingBar | |
return cls.find_ui_matching_requirement(o) | |
def activate(self): | |
pass | |
def find_ui_matching_requirement(self, o): | |
has_requirement = bool(set(o.supported_modes) & set(ImageLoadingBar.requirements)) | |
if has_requirement: | |
return ImageLoadingBar(o) | |
has_requirement = bool(set(o.supported_modes) & set(TextLoadingBar.requirements)) | |
if has_requirement: | |
return TextLoadingBar(o) | |
class ImageLoadingBar: | |
requirements = ['pixel'] | |
def __init__(self, o): | |
self.o = o | |
def activate(self): | |
pass # todo : remove | |
class TextLoadingBar: | |
requirements = ['char'] | |
def __init__(self, o): | |
self.o = o | |
def activate(self): | |
pass # todo : remove | |
class AbstractScreen: | |
requirements = [] | |
def __init__(self): | |
pass | |
class SomeBWScreen: | |
def __init__(self): | |
self.supported_modes = ['char', 'b&w', 'pixel'] # ... and more | |
class SomeCharacterScreen: | |
def __init__(self): | |
self.supported_modes = ['chars', 'pixel'] # ... and more |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment