I am having a little trouble and I was hoping someone might have some insight.
I am trying to set the display property based on which pageID is found in the session information. I have tried a lot of different property and configurations. I literally have a text box for each of the session.page.props.pageid, path, and primaryView but, I am not able to make the script roll through the containers correctly.
Here is the snippet I am using. Any help would be GREATLY appreciated:
def enable_active_page_bar(self):
try:
system.util.getLogger("NavBar").info("Starting enable_active_page_bar function")
# Check if self exists and has necessary attributes
if self is None:
system.util.getLogger("NavBar").error("self is None")
return
if not hasattr(self, 'page'):
system.util.getLogger("NavBar").error("self has no 'page' attribute")
return
if self.page is None:
system.util.getLogger("NavBar").error("self.page is None")
return
# Get the current page path
current_page = self.page.props.path
system.util.getLogger("NavBar").info("Current page path: %s" % current_page)
# Define a dictionary mapping pages to container indices
page_to_container = {
'/OverviewTest1': 0,
'/Dashboard': 0,
'/OverviewTest2': 1,
'/Details': 1,
'/Schedule': 2,
'/Tasks': 2,
'/Users': 3,
'/Settings': 3
}
# Set the active container based on the current page
active_index = page_to_container.get(current_page, 0) # Default to 0 if not found
system.util.getLogger("NavBar").info("Active index: %d" % active_index)
# Check if self has a PH child
ph = self.getChild("PH")
if ph is None:
system.util.getLogger("NavBar").error("PH container not found")
return
# Update the display property for each container
for i in range(1, 5):
container_name = 'PH_{}'.format(i)
try:
container = self.getChild("PH").getChild(container_name)
if container:
if hasattr(container.props, 'style'):
container.position.display = (i - 1 == active_index)
system.util.getLogger("NavBar").info("Set display for %s to %s" % (container_name, str(i - 1 == active_index)))
else:
system.util.getLogger("NavBar").warn("Container %s has no style property" % container_name)
else:
system.util.getLogger("NavBar").warn("Container %s not found" % container_name)
except Exception as e:
system.util.getLogger("NavBar").error("Error setting display for %s: %s" % (container_name, str(e)))
# Check if self has a session property
if not hasattr(self, 'session') or self.session is None:
system.util.getLogger("NavBar").error("self.session is None")
return
# Store the current active container index in a session prop for later use
self.session.props.activeNavContainerIndex = active_index
system.util.getLogger("NavBar").info("Session prop set: %d" % self.session.props.activeNavContainerIndex)
except Exception as e:
system.util.getLogger("NavBar").error("Unexpected error in enable_active_page_bar: %s" % str(e))
import traceback
system.util.getLogger("NavBar").error(traceback.format_exc())