Skip to content

Commit

Permalink
Gui now shows which devices are being processed at any one moment
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSekavcnik committed Dec 15, 2023
1 parent a5c5d96 commit 99374ad
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 18 deletions.
1 change: 1 addition & 0 deletions quasi/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .generic_device import GenericDevice
from .generic_device import wait_input_compute
from .generic_device import ensure_output_compute
from .generic_device import coordinate_gui
#from .port import connect_ports
from .port import Port
from .beam_splitter import BeamSplitter
Expand Down
2 changes: 2 additions & 0 deletions quasi/devices/control/simple_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from quasi.devices import (GenericDevice,
wait_input_compute,
coordinate_gui,
ensure_output_compute)
from quasi.devices.port import Port
from quasi.signals import (GenericSignal,
Expand Down Expand Up @@ -35,6 +36,7 @@ class SimpleTrigger(GenericDevice):
reference = None

@ensure_output_compute
@coordinate_gui
@wait_input_compute
def compute_outputs(self, *args, **kwargs):
print("TRIGGERING")
Expand Down
30 changes: 26 additions & 4 deletions quasi/devices/generic_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def wait_input_compute(method):
computed before computing outputs.
"""
def wrapper(self, *args, **kwargs):
print(args)
print(kwargs)
for port in self.ports.keys():
port = self.ports[port]
if port.direction == "input":
Expand All @@ -35,11 +33,25 @@ def ensure_output_compute(method):
"""

def wrapper(self, *args, **kwargs):
print(args)
print(kwargs)
return method(self, *args, **kwargs)
return wrapper

def coordinate_gui(method):
"""
Wrapper funciton, informs the gui about the
status of the simulation
"""
def wrapper(self, *args, **kwargs):
if self.coordinator is not None:
self.coordinator.start_processing()
method(self, *args, **kwargs)
if self.coordinator is not None:
self.coordinator.processing_finished()

return wrapper




class GenericDevice(ABC): # pylint: disable=too-few-public-methods
"""
Expand All @@ -59,6 +71,7 @@ def __init__(self, name=None):
simulation = Simulation.get_instance()
ref = DeviceInformation(name,self)
simulation.register_device(ref)
self.coordinator = None


def register_signal(
Expand Down Expand Up @@ -92,6 +105,7 @@ def register_signal(
port.signal = signal

@wait_input_compute
@coordinate_gui
@abstractmethod
def compute_outputs(self):
"""
Expand Down Expand Up @@ -127,6 +141,14 @@ def reference(self):
"""
raise NotImplementedError("Can be set to None")

def set_coordinator(self, coordinator):
"""
Sets the coordinator
this is required to have feedback in the gui
"""
self.coordinator = coordinator



class NoPortException(Exception):
"""
Expand Down
2 changes: 2 additions & 0 deletions quasi/devices/investigation_devices/photon_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from quasi.devices import (GenericDevice,
wait_input_compute,
coordinate_gui,
ensure_output_compute)
from quasi.devices.port import Port
from quasi.signals import (GenericSignal,
Expand Down Expand Up @@ -39,6 +40,7 @@ class PhotonDistribution(GenericDevice):


@wait_input_compute
@coordinate_gui
def compute_outputs(self, *args, **kwargs):
mm = ModeManager()
m_id = self.ports["IN"].signal.mode_id
Expand Down
2 changes: 2 additions & 0 deletions quasi/devices/sources/ideal_single_photon_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from quasi.devices import (GenericDevice,
wait_input_compute,
coordinate_gui,
ensure_output_compute)
from quasi.devices.port import Port
from quasi.signals import (GenericSignal,
Expand Down Expand Up @@ -47,6 +48,7 @@ class IdealSinglePhotonSource(GenericDevice):
reference = None

@ensure_output_compute
@coordinate_gui
@wait_input_compute
def compute_outputs(self, *args, **kwargs):
mm = ModeManager()
Expand Down
4 changes: 2 additions & 2 deletions quasi/gui/board/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ def drag_accept(self, e: ft.DragUpdateEvent):
board=self,
top=(e.y-self.offset_y)/2,
left=(e.x-self.offset_x)/2,
device_class=dev_instance)
device_instance=dev_instance)

self.content.controls.append(d)
self.content.update()
self.sim_wrapper.add_device(dev_instance)
self.sim_wrapper.add_device(dev_instance, d.sim_gui_coordinator)
e.control.update()

def build(self) -> ft.Container():
Expand Down
74 changes: 63 additions & 11 deletions quasi/gui/board/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,65 @@ class Device(ft.UserControl):
control
"""
# pylint: disable=too-many-instance-attributes
def __init__(self, page: ft.Page, top: float, left: float, device_class, board):
def __init__(
self,
page: ft.Page,
top: float,
left: float,
device_instance,
board):
super().__init__()
# Display parameters
self.page = page
self.top = top
self.left = left
self.board = board
self.device_class = device_class
self.ports_out = None
self.ports_in = None
self.sim_device_instance = device_instance
self._compute_ports()
self._header_height = 10
self._device_height = self._calculate_height()
self._device_width = self._calculate_width()
self._device_width = self._calculate_width()
self._ports_width = 10

# Simulation Connection Components
self.sim_gui_coordinator = DeviceSimGuiCoordinator(self)
self.sim_device_instance.set_coordinator(
self.sim_gui_coordinator
)

# Gui Components
self.image = ft.Image(
src=self.device_class.gui_icon,
src=self.sim_device_instance.gui_icon,
width=self._device_width - 2 * self._ports_width,
height=self._device_height - self._header_height
)

self.processing = ft.Container(
top=2,
left=2,
height=5,
width=5,
visible=False,
content= ft.ProgressRing(
color="white",
stroke_width=2
)
)

self._header = ft.Container(
height=self._header_height,
width=self._device_width,
bgcolor="black",
content=ft.GestureDetector(
drag_interval=1,
on_vertical_drag_update=self.handle_device_move,
mouse_cursor=ft.MouseCursor.GRAB
content=ft.Stack(
controls = [
self.processing,
ft.GestureDetector(
drag_interval=1,
on_vertical_drag_update=self.handle_device_move,
mouse_cursor=ft.MouseCursor.GRAB
)]
)
)

Expand All @@ -64,7 +94,6 @@ def __init__(self, page: ft.Page, top: float, left: float, device_class, board):
)

self.contents = ft.Container(
bgcolor=ft.colors.GREEN_200,
width=self._device_width,
height=self._device_height,
top=self.top,
Expand All @@ -85,12 +114,12 @@ def _compute_ports(self) -> None:
self.ports_in = Ports(
device=self,
page=self.page,
device_cls=self.device_class,
device_cls=self.sim_device_instance,
direction="input")
self.ports_out = Ports(
device=self,
page=self.page,
device_cls=self.device_class,
device_cls=self.sim_device_instance,
direction="output")

def _calculate_height(self) -> float:
Expand Down Expand Up @@ -131,3 +160,26 @@ def handle_device_move(self, e):
self.contents.update()
self.board.content.update()
e.control.update()

def start_processing(self):
self.processing.visible = True
self.contents.update()

def stop_processing(self):
self.processing.visible = False
self.contents.update()

class DeviceSimGuiCoordinator():
"""
Manages the coordination between the
simulated device and the display device
"""

def __init__(self, gui_device: Device):
self.device = gui_device

def start_processing(self):
self.device.start_processing()

def processing_finished(self):
self.device.stop_processing()
2 changes: 1 addition & 1 deletion quasi/gui/simulation/simulation_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def execute(self):
print(self.signals)
self.simulation.run()

def add_device(self, device):
def add_device(self, device, coordinator):
self.devices.append(device)

def create_connection(self, sig,
Expand Down

0 comments on commit 99374ad

Please sign in to comment.