fenen/ui_context.py

24 lines
760 B
Python
Raw Normal View History

2023-07-26 23:11:46 +01:00
class UIContext:
context = "all"
prev_context = ""
data = {
"feed": "",
"post_url": "",
"search_query": "",
"items": [],
}
def revert_context(self):
self.context, self.prev_context = self.prev_context, self.context
def change_context(self, new_context):
if new_context not in ["all", "feed", "unread", "search"]:
raise NotImplementedError(f"There is no UI context {new_context}.")
self.prev_context = self.context
self.context = new_context
# Clear data fields so there's no lingering state from previous context
self.data["feed"] = ""
self.data["post_url"] = ""
self.data["search_query"] = ""
self.data["items"] = []