Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktBurger committed Apr 8, 2024
1 parent 6249935 commit 8aa7cd3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pyleco_extras_CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ jobs:
- name: Python version
run: python --version
- name: Install pyleco extras
run: pip install -e .
run: pip install .
- name: Install mypy
run: pip install mypy
- name: Run mypy
run: mypy .
run: mypy -p pyleco_extras

test:
name: Python ${{ matrix.python-version }}, ${{ matrix.os }}
Expand Down
27 changes: 17 additions & 10 deletions pyleco_extras/gui/data_logger/data_logger_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class DataLoggerRemote(DataLoggerBase):
"""

remote_length: int = 0
director: DataLoggerDirector

def __init__(self, name: str = "DataLoggerRemote", host: str = "localhost", **kwargs) -> None:
# Use initialization of parent class QMainWindow.
Expand Down Expand Up @@ -100,7 +101,9 @@ def read_configuration(self) -> dict[str, Any]:
config = self.communicator.ask_rpc(receiver=self.remote, method="get_configuration")
length = self.communicator.ask_rpc(receiver=self.remote, method="get_list_length")
except ServerError as exc:
self.statusBar().showMessage(f"Communication error: {exc.rpc_error.message}", 10000) # type: ignore
self.statusBar().showMessage( # type: ignore
f"Communication error: {exc.rpc_error.message}", 10000
)
return {}
except Exception as exc:
log.exception("Getting configuration failed.", exc_info=exc)
Expand All @@ -109,7 +112,7 @@ def read_configuration(self) -> dict[str, Any]:
self.remote_length = length
return config

def reset(self):
def reset(self) -> None:
"""Reset the local values to the remote one and reset the locally stored data points."""
self.restore_configuration()
self.current_units = self.units
Expand All @@ -121,15 +124,17 @@ def set_properties(self, properties: dict[str, Any]) -> None:
receiver=self.remote, method="set_configuration", configuration=properties
)
except ServerError as exc:
self.statusBar().showMessage(f"Communication error: {exc.rpc_error.message}", 3000) # type: ignore
self.statusBar().showMessage( # type: ignore
f"Communication error: {exc.rpc_error.message}", 3000
)
except (ConnectionError, TimeoutError) as exc:
log.exception("set property communication error", exc_info=exc)

def set_property(self, name: str, value: Any) -> None:
"""Set a property remotely."""
self.set_properties(properties={name: value})

def setSettings(self):
def setSettings(self) -> None:
"""Apply settings."""
super().setSettings()
settings = QtCore.QSettings()
Expand Down Expand Up @@ -182,7 +187,7 @@ def setVariable(self, value: str) -> None:

# Controls
@pyqtSlot()
def start(self):
def start(self) -> None:
"""Start a measurement."""
self.director.start_collecting(
variables=self.variables, # type: ignore
Expand All @@ -196,17 +201,19 @@ def start(self):
self.reset()

@pyqtSlot(bool)
def pause(self, checked: bool):
def pause(self, checked: bool) -> None:
"""Pause a measurement."""
self.set_property("pause", checked)

@pyqtSlot()
def saveDataClicked(self):
def saveDataClicked(self) -> None:
"""Save the data and store the filename in the clipboard."""
try:
value = self.director.save_data()
except ServerError as exc:
self.statusBar().showMessage(f"Communication error: {exc.rpc_error.message}", 3000) # type: ignore
self.statusBar().showMessage( # type: ignore
f"Communication error: {exc.rpc_error.message}", 3000
)
except Exception as exc:
log.exception("saveDataClicked", exc_info=exc)
else:
Expand All @@ -232,7 +239,7 @@ def toggleRepeat(self, state: int) -> None:

# Text area
@pyqtSlot()
def set_header(self):
def set_header(self) -> None:
text = self.leHeader.toPlainText()
self.set_property("header", text)

Expand All @@ -251,7 +258,7 @@ def _add_datapoint_to_lists(self, datapoint: dict[str, Any]) -> None:
except KeyError:
self._lists[key] = [value]

def _handle_new_data_point(self, datapoint: dict[str, Any], remote_length: int):
def _handle_new_data_point(self, datapoint: dict[str, Any], remote_length: int) -> None:
self._add_datapoint_to_lists(datapoint=datapoint)
self.show_data_point(datapoint)
self.lbRemoteCount.setText(f"Remote data points: {remote_length}")
Expand Down
18 changes: 7 additions & 11 deletions pyleco_extras/gui/starter_gui/tasks/example_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

import logging

from devices.pyleco_addons import motor_controller

# TODO Only needed for simulation, remove in real code
from devices.pyTrinamicTest import ConnectionManager
motor_controller.ConnectionManager = ConnectionManager # replace with Testing version.
from pyleco_extras.actors.tmc_motor_actor import TMCMotorActor

log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
Expand Down Expand Up @@ -59,20 +55,20 @@ def task(stop_event):
"""The task which is run by the starter."""
# Initialize
try:
controller = motor_controller.MotorController(name, card, motorDict, log=log)
actor = TMCMotorActor(name, card, motorDict, log=log)
except Exception as exc:
log.exception(f"Creation of {name} at card {card} failed.", exc_info=exc)
return
for config in configs:
controller.configure_motor(config)
actor.configure_motor(config)

log.debug("Motor configured.")
# Continuos loop
controller.listen(stop_event)
# Continuous loop
actor.listen(stop_event)

# Finish
controller.disconnect()
controller.close()
actor.disconnect()
actor.close()


if __name__ == "__main__":
Expand Down
11 changes: 6 additions & 5 deletions pyleco_extras/gui/starter_gui/tasks/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pymeasure.instruments import Instrument
from pymeasure.adapters import ProtocolAdapter

from devices import controller
from pyleco.actors.actor import Actor


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -68,12 +68,13 @@ def readout(device, publisher):
def task(stop_event):
"""The task which is run by the starter."""
# Initialize
c = controller.InstrumentController("instrument", FantasyInstrument, periodic_reading=interval,
auto_connect={'adapter': True})
c._readout = readout
c = Actor(
"instrument", FantasyInstrument, periodic_reading=interval, auto_connect={"adapter": True}
)
c.read_publish = readout
c.start_timer()

# Continuos loop
# Continuous loop
c.listen(stop_event)


Expand Down
6 changes: 3 additions & 3 deletions pyleco_extras/gui/starter_gui/tasks/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

import logging

from devices import controller
from pyleco.utils.message_handler import MessageHandler


log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())


class Handler(controller.MessageHandler):
class Handler(MessageHandler):
def handle_command(self, command, content=None):
print(command, content)
return ["A"]
Expand All @@ -24,7 +24,7 @@ def task(stop_event):
# Initialize
c = Handler("printer")

# Continuos loop
# Continuous loop
c.listen(stop_event)

# Finish
Expand Down

0 comments on commit 8aa7cd3

Please sign in to comment.