Skip to content

Commit

Permalink
Jump immediately to object info on goto from pos_server
Browse files Browse the repository at this point in the history
  • Loading branch information
brickbots committed Feb 2, 2025
1 parent ed84e78 commit b5ca8de
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 13 deletions.
3 changes: 2 additions & 1 deletion python/PiFinder/pos_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def handle_goto_command(shared_state, ra_parsed, dec_parsed):
)
logger.debug("handle_goto_command: Pushing object: %s", obj)
shared_state.ui_state().add_recent(obj)
shared_state.ui_state().set_new_pushto(True)
ui_queue.put("push_object")
return "1"

Expand Down Expand Up @@ -239,7 +240,7 @@ def run_server(shared_state, p_ui_queue, log_queue):
logger.info("SkySafari server started and listening")
while True:
client_socket, address = server_socket.accept()
logger.info("New connection from %s", address)
logger.debug("New connection from %s", address)
handle_client(client_socket, shared_state)
except Exception:
logger.exception("Unexpected server error")
Expand Down
11 changes: 11 additions & 0 deletions python/PiFinder/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def __init__(self):
self.__message_timeout = 0
self.__hint_timeout = 0
self.__show_fps = False
# Set to true when an object is pushed
# to the recent list from the pos_server
# proccess (i.e. skysafari goto). Used
# to jump from object list to object details
self.__new_pushto = False

def observing_list(self):
return self.__observing_list
Expand All @@ -65,6 +70,12 @@ def recent_list(self) -> List[CompositeObject]:
def add_recent(self, v: CompositeObject):
self.__recent.append(v)

def set_new_pushto(self, v: bool):
self.__new_pushto = v

def new_pushto(self) -> bool:
return self.__new_pushto

def target(self):
return self.__target

Expand Down
13 changes: 13 additions & 0 deletions python/PiFinder/ui/menu_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ def message(self, message: str, timeout: float) -> None:
self.stack[-1].message(message, timeout) # type: ignore[arg-type]

def jump_to_label(self, label: str) -> None:
# to prevent many recent/object UI modules
# being added to the list upon repeated object
# pushes, check for existing 'recent' in the
# stack and jump to that, rather than adding
# a new one
if label in ["recent"]:
for stack_index, ui_module in enumerate(self.stack):
if ui_module.item_definition.get("label", "") == label:
self.stack = self.stack[: stack_index + 1]
self.stack[-1].active() # type: ignore[call-arg]
return
# either this is not a special case, or we didn't find
# the label already in the stack
menu_to_jump = find_menu_by_label(label)
if menu_to_jump is not None:
self.add_to_stack(menu_to_jump)
Expand Down
3 changes: 3 additions & 0 deletions python/PiFinder/ui/object_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ def active(self):

def _check_catalog_initialised(self):
code = self.object.catalog_code
if code == "PUSH":
# Special code for objects pushed from sky-safari
return True
catalog = self.catalogs.get_catalog_by_code(code)
return catalog and catalog.initialised

Expand Down
36 changes: 25 additions & 11 deletions python/PiFinder/ui/object_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,14 @@ def line_position(self, line_number, title_offset=20):
def active(self):
# trigger refilter
super().active()
self.refresh_object_list()

# check for new push_to
if self.ui_state.new_pushto():
self.refresh_object_list(force_update=True)
self.ui_state.set_new_pushto(False)
self.show_object_details(0)
else:
self.refresh_object_list()

def update(self, force: bool = False) -> None:
self.clear_screen()
Expand Down Expand Up @@ -585,6 +592,22 @@ def marking_menu_right(self):
self._marking_menu_items[3].selected = False
self.sort()

def show_object_details(self, object_index):
"""
Adds the object details UI module for the object
at object_index to the top of the stack.
"""
_menu_item = self._menu_items_sorted[object_index]

object_item_definition = {
"name": _menu_item.display_name,
"class": UIObjectDetails,
"object": _menu_item,
"object_list": self._menu_items_sorted,
"label": "object_details",
}
self.add_to_stack(object_item_definition)

def key_right(self):
"""
When right is pressed, move to
Expand All @@ -599,16 +622,7 @@ def key_right(self):
self.jump_input_display = False
self.jump_to_number.reset_number()

_menu_item = self._menu_items_sorted[self._current_item_index]

object_item_definition = {
"name": _menu_item.display_name,
"class": UIObjectDetails,
"object": _menu_item,
"object_list": self._menu_items_sorted,
"label": "object_details",
}
self.add_to_stack(object_item_definition)
self.show_object_details(self._current_item_index)

def key_number(self, number):
self.jump_to_number.append_number(number)
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_sys_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ def test_wpa_supplicant_parsing():


except ImportError:
pass
pass

0 comments on commit b5ca8de

Please sign in to comment.