status_bar: fixed seleected_pgroup bug where sometimes dialog would be closed before geting the value. Updated logic of the session menu and label based on who has the session
This commit is contained in:
@@ -210,6 +210,10 @@ class StatusBar(QStatusBar):
|
||||
session_flag = """<span style="color: green ; "> Owned ⬤ </span>"""
|
||||
elif status.session.session == SessionsStateEnum.OwnedByElse:
|
||||
session_flag = """<span style="color: red ; "> Other 🔒 </span>"""
|
||||
elif status.session.session == SessionsStateEnum.PendingYouToElse:
|
||||
session_flag = """<span style="color: orange ; "> Waiting... ⏳ </span>"""
|
||||
elif status.session.session == SessionsStateEnum.PendingElseToYou:
|
||||
session_flag = """<span style="color: cyan ; "> Request! ⚡ </span>"""
|
||||
|
||||
html_content_session = f"""Session: {session_flag}"""
|
||||
self.session_label.setText(html_content_session)
|
||||
@@ -272,15 +276,18 @@ class StatusBar(QStatusBar):
|
||||
# Base text
|
||||
if session_state == SessionsStateEnum.OwnedByYou:
|
||||
text = "Session: You"
|
||||
if self._baton_status and self._baton_status.incoming_request:
|
||||
text = "Session: You (⚡ Request)"
|
||||
elif session_state == SessionsStateEnum.PendingElseToYou:
|
||||
text = "Session: You (⚡ Request)"
|
||||
elif session_state == SessionsStateEnum.OwnedByElse:
|
||||
holder_name = ""
|
||||
if self._baton_status and self._baton_status.holder:
|
||||
holder_name = self._baton_status.holder.username
|
||||
text = f"Session: {holder_name or 'Other'}"
|
||||
if self._has_pending_request:
|
||||
text += " (⏳ Waiting)"
|
||||
elif session_state == SessionsStateEnum.PendingYouToElse:
|
||||
holder_name = ""
|
||||
if self._baton_status and self._baton_status.holder:
|
||||
holder_name = self._baton_status.holder.username
|
||||
text = f"Session: {holder_name or 'Other'} (⏳ Waiting)"
|
||||
else:
|
||||
text = "Session: Vacant"
|
||||
|
||||
@@ -289,9 +296,16 @@ class StatusBar(QStatusBar):
|
||||
def show_session_menu(self):
|
||||
menu = QMenu(self)
|
||||
is_busy = self.__status and self.__status.busy
|
||||
is_vacant = self.__status and self.__status.session.session == SessionsStateEnum.Vacant
|
||||
is_yours = self.__status and self.__status.session.session == SessionsStateEnum.OwnedByYou
|
||||
is_other = self.__status and self.__status.session.session == SessionsStateEnum.OwnedByElse
|
||||
session_state = self.__status.session.session if self.__status else SessionsStateEnum.Vacant
|
||||
# Determine if we are the holder or waiting for baton
|
||||
is_yours = session_state in (SessionsStateEnum.OwnedByYou, SessionsStateEnum.PendingElseToYou)
|
||||
# Check baton status for fallback if status.session is not yet updated
|
||||
if not is_yours and self._baton_status:
|
||||
is_yours = self._baton_status.you_are_holder or self._baton_status.incoming_request
|
||||
|
||||
is_vacant = session_state == SessionsStateEnum.Vacant
|
||||
is_other = session_state in (SessionsStateEnum.OwnedByElse, SessionsStateEnum.PendingYouToElse)
|
||||
has_pending = session_state == SessionsStateEnum.PendingYouToElse
|
||||
|
||||
# Determine holder info from baton status
|
||||
holder_is_staff = (
|
||||
@@ -308,7 +322,7 @@ class StatusBar(QStatusBar):
|
||||
action_grab.triggered.connect(self._on_grab_clicked)
|
||||
elif is_other:
|
||||
# Someone else has it
|
||||
if self._has_pending_request:
|
||||
if has_pending:
|
||||
# Already have a pending request - show cancel option
|
||||
action_cancel = menu.addAction("Cancel Request")
|
||||
action_cancel.triggered.connect(self._on_cancel_request_clicked)
|
||||
@@ -332,14 +346,18 @@ class StatusBar(QStatusBar):
|
||||
elif is_yours:
|
||||
# You have it - show release option
|
||||
action_release = menu.addAction("Release")
|
||||
action_release.setEnabled(not is_busy)
|
||||
action_release.setEnabled(True) # Always allow release
|
||||
action_release.triggered.connect(self._on_release_clicked)
|
||||
|
||||
if session_state == SessionsStateEnum.PendingElseToYou:
|
||||
action_accept = menu.addAction("Accept Request")
|
||||
action_accept.triggered.connect(self._on_baton_dialog_accepted)
|
||||
|
||||
menu.addSeparator()
|
||||
|
||||
# --- END SESSION (cleanup) ---
|
||||
action_end = menu.addAction("End Session")
|
||||
action_end.setEnabled(bool((is_yours and not is_busy) or self.__is_staff))
|
||||
action_end.setEnabled(bool(is_yours or self.__is_staff))
|
||||
action_end.triggered.connect(self.end_session_clicked)
|
||||
|
||||
# --- STAFF: FORCE GRAB (emergency) ---
|
||||
@@ -472,9 +490,8 @@ class StatusBar(QStatusBar):
|
||||
pgroups=pgroups,
|
||||
parent=self,
|
||||
)
|
||||
|
||||
selected_pgroup = self._pgroup_dialog_for_baton.get_input()
|
||||
if self._pgroup_dialog_for_baton.exec() == QDialog.DialogCode.Accepted:
|
||||
selected_pgroup = self._pgroup_dialog_for_baton.get_input()
|
||||
if selected_pgroup:
|
||||
self.set_pgroup.emit(selected_pgroup)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user