def __init__(self, text: str, button: object, command: list, cooldown: int = 0, timeout: int = 3, callback: object = None, isEndingLine: bool = True): ScreenElement.__init__(self) Log.__init__(self, "SimpleOsCommandElement") self._commandText = text self._button = button self._command = command self._parentCallback = callback self._procHandler = ProcHandler(command=command, onSuccess=self._onSuccess, onError=self._onError, cooldown=cooldown, timeout=timeout) self._finishedProcess = None self._dataElement = ScreenElement(isEndingLine=isEndingLine) self.addChild(self._dataElement) self._resetText()
def __init__(self, passwordList: object, keyStroker: object): ScreenElement.__init__(self, buttonDownMap={ Button.PRESS: self.onOkButtonDown, Button.LEFT: self.onPrevButtonDown, Button.RIGHT: self.onNextButtonDown, Button.DOWN: self.onIncreaseButtonDown, Button.UP: self.onDecreaseButtonDown }) Log.__init__(self, className="PasswordManagerMenuElement") self._passwordList = passwordList self._keyStroker = keyStroker self._accountDict = None self._active = False self._confirmed = False self._titleElement = ScreenElement(isEndingLine=True) self._titleElement.text, self._titleElement.color = "", Color.DEFAULT self._dataElement = ScreenElement() self.addChildren([self._titleElement, self._dataElement]) self.setEnablePropagation(False) self.setButtonDownMapActive(False)
def __init__(self): ScreenElement.__init__(self, buttonDownMap={ Button.LEFT: self.onCancelButtonDown, Button.RIGHT: self.onOkButtonDown }) Log.__init__(self, className="PasswordManagerElement") self._titleElement = ScreenElement(isEndingLine=True, text="[pwman]") self._passwordList = PasswordList() self._keyStroker = KeyStroker() self._pwTextElement = PasswordEditElement() self._accountMenuElement = PasswordManagerMenuElement( passwordList=self._passwordList, keyStroker=self._keyStroker) self._dataWrapperElement = ScreenElement( children=[self._pwTextElement]) self.addChild(self._titleElement) self.addChild(self._dataWrapperElement) self._editingPassword = False self.setEnablePropagation(False)
def __init__( self, dictNavigator, title : str, onSelected ): ScreenElement.__init__( self, buttonDownMap={ Button.PRESS : self.onOkButtonDown, Button.LEFT : self.onPrevButtonDown, Button.RIGHT : self.onNextButtonDown, Button.DOWN : self.onIncreaseButtonDown, Button.UP : self.onDecreaseButtonDown } ) Log.__init__( self, className="DictNavigatorElement" ) self._titleElement = ScreenElement( isEndingLine=True, text=title ) self._upperDataElement = ScreenElement( isEndingLine=True ) self._lowerDataElement = ScreenElement() self._onSelected = onSelected self._dict = raiseNotInstanceOf( dictNavigator, DictNavigator ) self._started = False self._selectionConfirmed = False self.addChildren( [ self._titleElement, self._upperDataElement, self._lowerDataElement ] ) self.setEnablePropagation( False )
def __init__(self, osCommand=None, cooldown: int = 5, timeout: int = 3): ScreenElement.__init__(self) Log.__init__(self, className="PollingElement") self.dataChildElement = ScreenElement() self.addChild(self.dataChildElement) self.osCommand = osCommand self.dataProcHandler = ProcHandler(command=self.osCommand.getCommand(), callback=self._procResult, cooldown=cooldown, timeout=timeout)
def __init__( self ): ScreenElement.__init__( self, children=[ ScreenElement( children=[ CurrentTimeElement( "%d.%m %H:%M:%S" ) ], isEndingLine=True ), ScreenElement( children=[ ScreenElement( text="GPU ", color=Color.DEFAULT ), PollingElement( osCommand=GetGPUTempCommand, cooldown=10, timeout=3 ), ScreenElement( text=" ", color=Color.DEFAULT ), PollingElement( osCommand=GetGPUMemUsageCommand, cooldown=10, timeout=3 ) ], isEndingLine=True ), ScreenElement( children=[ ScreenElement( text="CPU ", color=Color.DEFAULT ), PollingElement( osCommand=GetCPUTempCommand, cooldown=10, timeout=3 ) ], isEndingLine=True ) ], buttonDownMap={ Button.PRESS : self.toggleSplash } ) Log.__init__( self, "Overview" ) self.menu = MainMenu() self.statusLine = ScreenElement( isEndingLine=True ) self.addChild( self.menu ) self.addChild( self.statusLine ) self.splashProcHandler = ProcHandler( command=CMD_DISPLAY_SPLASH ) self.splashDisplayed = False if Global.DISPLAY_SPLASH: self.enableSplash()
def __init__( self, buttonNext = None, buttonPrev = None ): ScreenElement.__init__( self ) Log.__init__( self, "MainMenu" ) self.log( "buttonNext: {bn} buttonPrev: {bp}".format( bn=buttonNext, bp=buttonPrev ) ) self._buttonNext = buttonNext or Button.DOWN self._buttonPrev = buttonPrev or Button.UP self._keyStroker = KeyStroker() self._sysCmdProc = None self._sysCmdTempDictName = None self._sysCmdTempKeyName = None self.menuItems = [] self.menuItems.append( PasswordManagerElement() ) try: with open( SHITTALKER_FILE, "rb" ) as file: MainMenu._shitTalkerDict = DictNavigator( json.load( file ) ) self.menuItems.append( DictNavigatorElement( dictNavigator=MainMenu._shitTalkerDict, title="[shittalker]", onSelected=self._onShitTalkerSelected ) ) except Exception as e: self.log("Error loading {err}".format( err=e ) ) self.menuItems.append( DictNavigatorElement( dictNavigator=MainMenu._runtimeConfigDict, title="[cfg]", onSelected=self._onRuntimeConfigSelected )) self.menuItems.append( DictNavigatorElement( dictNavigator=MainMenu._sysCmdDict, title="[cmd]", onSelected=self._onSysCmdSelected )) self._activeElementWrapper = ScreenElement( isEndingLine=True ) self.addChildren( [ ScreenElement( text="---------------", isEndingLine=True, color=COLOR.BORDER ), self._activeElementWrapper ] ) self._activeElement = None self._activeElementIndex = 0 self._setActiveElement() self.setEnablePropagation( False )
def __init__(self, hideUnselectedChars: bool = True): ScreenElement.__init__(self, buttonDownMap={ Button.PRESS: self.onOkButtonDown, Button.RIGHT: self.onNextButtonDown, Button.LEFT: self.onPrevButtonDown, Button.UP: self.onDecreaseButtonDown, Button.DOWN: self.onIncreaseButtonDown, Button.KEY1: self.onCapsButtonDown, Button.KEY2: self.onNumbersButtonDown, Button.KEY3: self.onSymbolsButtonDown }) Log.__init__(self, className="PasswordEditElement") self._charPoolManager = CharPoolManager() self._parentOnEditingFinished = None self._parentOnEditingCancelled = None self._titleElement = ScreenElement(isEndingLine=True) self._pwTextPreElement = ScreenElement() self._pwTextCharElement = ScreenElement(color=Color.BLACKWHITE) self._pwTextPostElement = ScreenElement() self.addChildren([ self._titleElement, self._pwTextPreElement, self._pwTextCharElement, self._pwTextPostElement ]) self._pwText = "" self._pwTextCurrentChar = "a" self._pwTextCurrentCharIndex = 0 self._hideUnselectedChars = hideUnselectedChars self.setButtonDownMapActive(False)
class MainMenu( ScreenElement, Log ): _runtimeConfigDict = DictNavigator( { RUNTIME_CONFIG_KEY.keymap : { "de" : KEYSETTING.de, "en" : KEYSETTING.en }, RUNTIME_CONFIG_KEY.keyTimeout : { "0" : "0", "0.005" : "0.005", "0.01" : "0.01", "0.02" : "0.02", "0.05" : "0.05", "0.1" : "0.1", "0.2" : "0.2", "0.5" : "0.5" } }) _sysCmdDict = DictNavigator( { "poweroff" : VALUE_POWEROFF, "reboot" : VALUE_REBOOT, "wlan0" : { "up" : VALUE_IFCONFIG_WLAN0_UP, "down" : VALUE_IFCONFIG_WLAN0_DOWN }, "dhcpcd" : { "start" : VALUE_WPA_SUPPLICANT_START, "stop" : VALUE_WPA_SUPPLICANT_STOP, "status" : VALUE_WPA_SUPPLICANT_STATUS }, "wpa_supplicant" : { "start" : VALUE_DHCPCD_START, "stop" : VALUE_DHCPCD_STOP, "status" : VALUE_DHCPCD_STATUS } } ) _shitTalkerDict = None def __init__( self, buttonNext = None, buttonPrev = None ): ScreenElement.__init__( self ) Log.__init__( self, "MainMenu" ) self.log( "buttonNext: {bn} buttonPrev: {bp}".format( bn=buttonNext, bp=buttonPrev ) ) self._buttonNext = buttonNext or Button.DOWN self._buttonPrev = buttonPrev or Button.UP self._keyStroker = KeyStroker() self._sysCmdProc = None self._sysCmdTempDictName = None self._sysCmdTempKeyName = None self.menuItems = [] self.menuItems.append( PasswordManagerElement() ) try: with open( SHITTALKER_FILE, "rb" ) as file: MainMenu._shitTalkerDict = DictNavigator( json.load( file ) ) self.menuItems.append( DictNavigatorElement( dictNavigator=MainMenu._shitTalkerDict, title="[shittalker]", onSelected=self._onShitTalkerSelected ) ) except Exception as e: self.log("Error loading {err}".format( err=e ) ) self.menuItems.append( DictNavigatorElement( dictNavigator=MainMenu._runtimeConfigDict, title="[cfg]", onSelected=self._onRuntimeConfigSelected )) self.menuItems.append( DictNavigatorElement( dictNavigator=MainMenu._sysCmdDict, title="[cmd]", onSelected=self._onSysCmdSelected )) self._activeElementWrapper = ScreenElement( isEndingLine=True ) self.addChildren( [ ScreenElement( text="---------------", isEndingLine=True, color=COLOR.BORDER ), self._activeElementWrapper ] ) self._activeElement = None self._activeElementIndex = 0 self._setActiveElement() self.setEnablePropagation( False ) def _onSysCmdError( self ): d = MainMenu._sysCmdDict self.log() Log.pushStatus( "{k}{s}".format( s=" {sd}".format( sd=self._sysCmdTempDictName ) if self._sysCmdTempDictName else EMPTY_STRING, k=self._sysCmdTempKeyName ), COLOR.STATUS_ERROR ) self._sysCmdTempDictName = None self._sysCmdTempKeyName = None del self._sysCmdProc self._sysCmdProc = None def _onSysCmdSuccess( self ): d = MainMenu._sysCmdDict self.log() Log.pushStatus( "{k}{s}".format( s=" {sd}".format( sd=self._sysCmdTempDictName ) if self._sysCmdTempDictName else EMPTY_STRING, k=self._sysCmdTempKeyName ), COLOR.STATUS_SUCCESS ) self._sysCmdTempDictName = None self._sysCmdTempKeyName = None del self._sysCmdProc self._sysCmdProc = None def _onSysCmdSelected( self ): if not self._sysCmdProc: d = MainMenu._sysCmdDict v = d.getValue() cmd = procMap[ v ] self._sysCmdTempDictName = d.getSubDictKey() if d.hasOpenedSubDict() else None self._sysCmdTempKeyName = d.getValue() self._sysCmdProc = ProcHandler( command=cmd, onError=self._onSysCmdError, onSuccess=self._onSysCmdSuccess, timeout=5 ) self._sysCmdProc.run() def _onRuntimeConfigSelected( self ): self.logStart() d = MainMenu._runtimeConfigDict GlobalRuntime.setRuntimeConfig( d.getSubDictKey(), d.getValue() ) self.log( "set {k}: {v}".format( k=d.getSubDictKey(), v=d.getValue() ) ) Log.pushStatus( "set {k}: {v}".format( k=d.getSubDictKey(), v=d.getValue() ), COLOR.STATUS_DEFAULT ) self.logEnd() def _onShitTalkerSelected( self ): self.logStart() d = MainMenu._shitTalkerDict self._keyStroker.send( d.getValue() ) self.log( "sent: {k}".format( k=d.getKey() ) ) Log.pushStatus( "sent: {k}".format( k=d.getKey() ), COLOR.STATUS_DEFAULT ) self.logEnd() def _getActiveElement( self ): return self._activeElement def _setActiveElement( self, index : int = -1 ): self.logStart("index: {index}".format( index=index )) if index >= 0 and index < len( self.menuItems ): self._activeElementIndex = index self.logStart("index valid") self._activeElement = self.menuItems[self._activeElementIndex] self._activeElementWrapper.emptyChildren() self._activeElementWrapper.addChild( self._activeElement ) self.logEnd() def onButtonDown( self, button ): self.logStart("button: {button}".format( button=button )) if button == self._buttonNext: self._setActiveElement( self._activeElementIndex + 1 ) elif button == self._buttonPrev: self._setActiveElement( self._activeElementIndex - 1 ) else: self.log("sending to: {e}".format( e=self._getActiveElement() )) self._getActiveElement().onButtonDown( button ) self.logEnd()
def __init__(self, dateFormatString): ScreenElement.__init__(self) self.text = "time" self.color = Color.BLACKWHITE self.dateFormatString = dateFormatString
class PasswordManagerElement(ScreenElement, Log): def __init__(self): ScreenElement.__init__(self, buttonDownMap={ Button.LEFT: self.onCancelButtonDown, Button.RIGHT: self.onOkButtonDown }) Log.__init__(self, className="PasswordManagerElement") self._titleElement = ScreenElement(isEndingLine=True, text="[pwman]") self._passwordList = PasswordList() self._keyStroker = KeyStroker() self._pwTextElement = PasswordEditElement() self._accountMenuElement = PasswordManagerMenuElement( passwordList=self._passwordList, keyStroker=self._keyStroker) self._dataWrapperElement = ScreenElement( children=[self._pwTextElement]) self.addChild(self._titleElement) self.addChild(self._dataWrapperElement) self._editingPassword = False self.setEnablePropagation(False) def passwordsLoaded(self): Log.pushStatus("pws loaded", COLOR.STATUS_SUCCESS) self._dataWrapperElement.emptyChildren() self._dataWrapperElement.addChild(self._accountMenuElement) self._accountMenuElement.start() def onPwEditFinished(self, password: str): self.logStart("password len {p}".format(p=len(password))) self._passwordList.loadPasswords(password=password, onSuccess=self.onPasswordLoadSuccess, onError=self.onPasswordLoadError) self._editingPassword = False self.logEnd() def onPwEditCancelled(self, password: str): self.logStart("password len {p}".format(p=len(password))) self._editingPassword = False self.logEnd() def onPasswordLoadSuccess(self): self.passwordsLoaded() def onPasswordLoadError(self): Log.pushStatus("ERR loading pw", COLOR.STATUS_ERROR) def onOkButtonDown(self, button): self.logStart("button {b}".format(b=button)) if self._passwordList.isLoaded(): self.passwordsLoaded() else: if not self._editingPassword: self._editingPassword = True self._pwTextElement.startEditing( onEditingFinished=self.onPwEditFinished, onEditingCancelled=self.onPwEditCancelled) Log.pushStatus("start edit", COLOR.STATUS_DEFAULT) self.logEnd() def onCancelButtonDown(self, button): self.logStart("button {b}".format(b=button)) self.logEnd() def onPrevButtonDown(self, button): self.logStart("button {b}".format(b=button)) self.logEnd() def onNextButtonDown(self, button): self.logStart("button {b}".format(b=button)) self.logEnd()