Skip to content

Commit

Permalink
Making AdminScreen re-usable for different users
Browse files Browse the repository at this point in the history
  • Loading branch information
phorward committed Mar 26, 2018
1 parent 6023530 commit 524e00c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
46 changes: 30 additions & 16 deletions admin.py
Expand Up @@ -5,7 +5,7 @@
from widgets import TopBarWidget
from widgets.userlogoutmsg import UserLogoutMsg
from network import NetworkService, DeferredCall
from event import viInitializedEvent, EventDispatcher
from event import viInitializedEvent
from priorityqueue import HandlerClassSelector, initialHashHandler, startupQueue
from log import Log
from pane import Pane, GroupPane
Expand All @@ -32,17 +32,17 @@ def __init__(self, *args, **kwargs ):
self.workSpace["class"] = "vi_workspace"
self.appendChild(self.workSpace)

self.modulMgr = html5.Div()
self.modulMgr["class"] = "vi_wm"
self.appendChild(self.modulMgr)
self.moduleMgr = html5.Div()
self.moduleMgr["class"] = "vi_wm"
self.appendChild(self.moduleMgr)

self.modulList = html5.Nav()
self.modulList["class"] = "vi_manager"
self.modulMgr.appendChild(self.modulList)
self.moduleList = html5.Nav()
self.moduleList["class"] = "vi_manager"
self.moduleMgr.appendChild(self.moduleList)

self.moduleListUl = html5.Ul()
self.moduleListUl["class"] = "modullist"
self.modulList.appendChild(self.moduleListUl)
self.moduleList.appendChild(self.moduleListUl)

self.viewport = html5.Div()
self.viewport["class"] = "vi_viewer"
Expand All @@ -54,7 +54,8 @@ def __init__(self, *args, **kwargs ):
self.currentPane = None
self.nextPane = None #Which pane gains focus once the deferred call fires
self.panes = [] # List of known panes. The ordering represents the order in which the user visited them.
self.userLoggedOutMsg = UserLogoutMsg()

self.userLoggedOutMsg = None

# Register the error-handling for this iframe
le = eval("window.top.logError")
Expand All @@ -63,10 +64,25 @@ def __init__(self, *args, **kwargs ):
w = eval("window.top")
w.onerror = le

def reset(self):
self.moduleListUl.removeAllChildren()
self.viewport.removeAllChildren()
self.logWdg.reset()

self.currentPane = None
self.nextPane = None
self.panes = []

if self.userLoggedOutMsg:
self.userLoggedOutMsg.stopInterval()
self.userLoggedOutMsg = None

def invoke(self):
self.show()
self.lock()

self.reset()

# Run queue
startupQueue.setFinalElem(self.startup)
startupQueue.run()
Expand All @@ -92,6 +108,9 @@ def startup(self):
self.getCurrentUser()
return

self.userLoggedOutMsg = UserLogoutMsg()
self.topBar.invoke()

conf["server"] = config.get("configuration", {})

moduleGroups = []
Expand Down Expand Up @@ -191,11 +210,6 @@ def startup(self):
DeferredCall(self.checkInitialHash)
self.unlock()

def remove(self):
self.userLoggedOutMsg.stopInterval()
self.userLoggedOutMsg = None
super(AdminScreen, self).remove()

def log(self, type, msg ):
self.logWdg.log( type, msg )

Expand Down Expand Up @@ -254,10 +268,10 @@ def execCall(self, path, params = None):

def switchFullscreen(self, fullscreen = True):
if fullscreen:
self.modulMgr.hide()
self.moduleMgr.hide()
self.viewport.addClass("is_fullscreen")
else:
self.modulMgr.show()
self.moduleMgr.show()
self.viewport.removeClass("is_fullscreen")

def isFullscreen(self):
Expand Down
3 changes: 3 additions & 0 deletions log.py
Expand Up @@ -108,3 +108,6 @@ def log(self, type, msg ):

def removeNewCls(self,span):
span["class"].remove("is_new")

def reset(self):
self.logUL.removeAllChildren()
6 changes: 4 additions & 2 deletions main.py
Expand Up @@ -86,6 +86,10 @@ def login(self, logout=False):
if not self.loginScreen:
self.loginScreen = LoginScreen()

if self.adminScreen:
self.adminScreen.reset()
self.adminScreen.hide()

self.loginScreen.invoke(logout=logout)

def admin(self):
Expand All @@ -95,8 +99,6 @@ def admin(self):
self.startup()

def logout(self):
self.adminScreen.remove()
conf["mainWindow"] = self.adminScreen = None
self.login(logout=True)

if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions priorityqueue.py
Expand Up @@ -33,6 +33,7 @@ def next(self):
print("Running startup callback #%s" % str(self.currentElem))
cb()
elif self.currentElem == len( self.q ): #We should call the final element
#print("Running final callback %s" % str(self.finalElem))
self.finalElem()
self.reset()
else:
Expand Down
13 changes: 8 additions & 5 deletions widgets/topbar.py
Expand Up @@ -39,16 +39,19 @@ def __init__(self):
self.moduleName = html5.Span()
self.modulContainer.appendChild( self.moduleName )

for icon in conf[ "toplevelactions" ]:
widget = toplevelActionSelector.select( icon )
if widget:
self.iconnav.appendChild( widget() )

anav.appendChild(self.iconnav)
self.appendChild(anav)

DeferredCall(self.setTitle, _delay=500)

def invoke(self):
self.iconnav.removeAllChildren()

for icon in conf["toplevelactions"]:
widget = toplevelActionSelector.select(icon)
if widget:
self.iconnav.appendChild(widget())

def setTitle(self):
if not conf["server"]:
DeferredCall(self.setTitle, _delay=500)
Expand Down

0 comments on commit 524e00c

Please sign in to comment.