Skip to content

Commit

Permalink
Flake8, black, and isort.
Browse files Browse the repository at this point in the history
  • Loading branch information
canismarko committed Jun 3, 2024
1 parent 8a657a3 commit 92d9a2a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 31 deletions.
67 changes: 48 additions & 19 deletions src/firefly/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from PyQt5.QtWidgets import QStyleFactory
from qtpy import QtCore, QtWidgets
from qtpy.QtCore import Signal
from qtpy.QtWidgets import QAction
from qtpy.QtGui import QKeySequence
from qtpy.QtWidgets import QAction

from haven import load_config
from haven import load_instrument as load_haven_instrument
Expand Down Expand Up @@ -130,7 +130,9 @@ def __del__(self):
self._queue_thread.wait(msecs=5000)
assert not self._queue_thread.isRunning()

def _setup_window_action(self, action_name: str, text: str, slot: QtCore.Slot, shortcut=None, icon=None):
def _setup_window_action(
self, action_name: str, text: str, slot: QtCore.Slot, shortcut=None, icon=None
):
action = QtWidgets.QAction(self)
action.setObjectName(action_name)
action.setText(text)
Expand Down Expand Up @@ -355,20 +357,49 @@ def setup_runengine_actions(self):
# Navbar actions for controlling the run engine
actions = [
# (action_name, text, icon, shortcut, tooltip)
("pause_runengine_action", "Pause", "fa5s.stopwatch", None,
"Pause the current plan at the next checkpoint."),
("pause_runengine_now_action", "Pause Now", "fa5s.pause", "Ctrl+C",
"Pause the run engine now."),
("resume_runengine_action", "Resume", "fa5s.play", None,
"Resume the previously-paused run engine at the last checkpoint."),
("stop_runengine_action", "Stop", "fa5s.stop", None,
"End the current plan, marking as success."),
("abort_runengine_action", "Abort", "fa5s.eject", None,
"End the current plan, marking as failure."),
("halt_runengine_action", "Halt", "fa5s.ban", None,
"End the current plan immediately, do not clean up."),
("start_queue_action", "Start", "fa5s.play", None,
"Start the queue."),
(
"pause_runengine_action",
"Pause",
"fa5s.stopwatch",
None,
"Pause the current plan at the next checkpoint.",
),
(
"pause_runengine_now_action",
"Pause Now",
"fa5s.pause",
"Ctrl+C",
"Pause the run engine now.",
),
(
"resume_runengine_action",
"Resume",
"fa5s.play",
None,
"Resume the previously-paused run engine at the last checkpoint.",
),
(
"stop_runengine_action",
"Stop",
"fa5s.stop",
None,
"End the current plan, marking as success.",
),
(
"abort_runengine_action",
"Abort",
"fa5s.eject",
None,
"End the current plan, marking as failure.",
),
(
"halt_runengine_action",
"Halt",
"fa5s.ban",
None,
"End the current plan immediately, do not clean up.",
),
("start_queue_action", "Start", "fa5s.play", None, "Start the queue."),
]
self.queue_action_group = QtWidgets.QActionGroup(self)
for name, text, icon_name, shortcut, tooltip in actions:
Expand Down Expand Up @@ -683,9 +714,7 @@ def show_device_window(

def show_status_window(self, stylesheet_path=None):
"""Instantiate a new main window for this application."""
self.show_window(
PlanMainWindow, ui_dir / "status.py", name="beamline_status"
)
self.show_window(PlanMainWindow, ui_dir / "status.py", name="beamline_status")

@QtCore.Slot()
def show_run_browser_window(self):
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import qtawesome as qta
from pydm import data_plugins
from pydm.main_window import PyDMMainWindow
from qtpy import QtCore, QtGui, QtWidgets
from qtpy import QtGui, QtWidgets

from haven import load_config

Expand Down
14 changes: 9 additions & 5 deletions src/firefly/queue_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import time
import warnings
from typing import Optional, Mapping
from typing import Mapping, Optional

from bluesky_queueserver_api import comm_base
from bluesky_queueserver_api.zmq.aio import REManagerAPI
Expand Down Expand Up @@ -111,7 +111,7 @@ async def add_queue_item(self, item):
await self.check_queue_status(force=True)
else:
await self.check_queue_status(force=False)

@asyncSlot(bool)
async def toggle_autostart(self, enable: bool):
log.debug(f"Toggling auto-start: {enable}")
Expand Down Expand Up @@ -181,7 +181,6 @@ def check_result(self, result: Mapping, task: str = "control queue server"):
log.error(msg)
raise RuntimeError(msg)


@asyncSlot()
async def check_queue_status(self, force=False, *args, **kwargs):
"""Get an update queue status from queue server and notify slots.
Expand Down Expand Up @@ -228,8 +227,13 @@ async def _check_queue_status(self, force: bool = False):
"""
new_status = await self.api.status()
# Add a new key for whether the queue is busy (length > 0 or running)
has_queue = new_status['items_in_queue'] > 0
is_running = new_status['manager_state'] in ["paused", "starting_queue", "executing_queue", "executing_task"]
has_queue = new_status["items_in_queue"] > 0
is_running = new_status["manager_state"] in [
"paused",
"starting_queue",
"executing_queue",
"executing_task",
]
new_status.setdefault("in_use", has_queue or is_running)
# Check individual components of the status if they've changed
signals_to_check = [
Expand Down
6 changes: 2 additions & 4 deletions src/firefly/tests/test_queue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def test_autostart_changed(client, ffapp):
# qtbot.wait(1000)
# client.api.queue_start.assert_called_once()


@pytest.mark.asyncio
async def test_stop_queue(client, qtbot):
"""Test how queuing a plan starts the runengine."""
Expand All @@ -350,17 +351,14 @@ async def test_stop_queue(client, qtbot):


def test_queue_stopped(client, ffapp):
"""Does the action respond to changes in the queue stopped pending?
"""
"""Does the action respond to changes in the queue stopped pending?"""
assert not ffapp.queue_stop_action.isChecked()
client.queue_stop_changed.emit(True)
assert ffapp.queue_stop_action.isChecked()
client.queue_stop_changed.emit(False)
assert not ffapp.queue_stop_action.isChecked()



@pytest.mark.asyncio
async def test_check_queue_status(client, qtbot):
# Check that the queue length is changed
Expand Down
3 changes: 1 addition & 2 deletions src/haven/instrument/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def load_motors(
prefix = config["prefix"]
num_motors = config["num_motors"]
log.info(
f"Preparing {num_motors} motors from IOC: "
f"{section_name} ({prefix})"
f"Preparing {num_motors} motors from IOC: " f"{section_name} ({prefix})"
)
for idx in range(num_motors):
motor_prefix = f"{prefix}m{idx+1}"
Expand Down

0 comments on commit 92d9a2a

Please sign in to comment.