Skip to content

Commit

Permalink
Merge pull request #23 from Ledger-Donjon/ui-enhancements
Browse files Browse the repository at this point in the history
UI enhancements
  • Loading branch information
mmouchous-ledger authored Nov 27, 2024
2 parents 85d6196 + d20320f commit 976d755
Show file tree
Hide file tree
Showing 23 changed files with 142 additions and 111 deletions.
11 changes: 6 additions & 5 deletions config_schema/camera.schema.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"$id": "camera.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"allOf": [
{
"$ref": "instrument.schema.json"
}
],
"title": "Camera",
"type": "object",
"properties": {
"enable": {
"type": "boolean",
"description": "If the device is enabled or not."
},
"width": {
"type": "integer",
"description": "Image width, in pixel."
Expand Down Expand Up @@ -73,4 +74,4 @@
"required": [
"type"
]
}
}
10 changes: 7 additions & 3 deletions config_schema/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@
"type": "object",
"properties": {
"camera": {
"$ref": "camera.schema.json"
"$ref": "camera.schema.json",
"description": "The main camera of the setup."
},
"stage": {
"$ref": "stage.schema.json"
"$ref": "stage.schema.json",
"description": "The main stage of the setup."
},
"lasers": {
"type": "array",
"description": "The list of laser devices.",
"items": {
"$ref": "laser.schema.json"
}
},
"probes": {
"type": "array",
"description": "The list of probes.",
"items": {
"$ref": "probe.schema.json"
}
}
}
}
}
14 changes: 14 additions & 0 deletions config_schema/instrument.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$id": "instrument.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"label": {
"type": "string",
"description": "The instrument personalized label."
},
"enable": {
"type": "boolean",
"description": "If the instrument is enabled or not."
}
}
}
12 changes: 5 additions & 7 deletions config_schema/laser.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Laser",
"type": "object",
"description": "A Laser device.",
"$ref": "probe.schema.json",
"properties": {
"enable": {
"type": "boolean",
"description": "If the device is enabled or not."
"description": "A Laser generator device.",
"allOf": [
{
"$ref": "probe.schema.json"
}
},
],
"oneOf": [
{
"properties": {
Expand Down
13 changes: 7 additions & 6 deletions config_schema/probe.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Probe",
"type": "object",
"allOf": [
{
"$ref": "instrument.schema.json"
}
],
"description": "A Probe device.",
"properties": {
"enable": {
"type": "boolean",
"description": "If the device is enabled or not."
},
"fixed_pos": {
"type": "array",
"description": "The index of the PDM device",
"description": "The relative position of the probe, in micrometers.",
"items": {
"type": "integer"
}
}
}
}
}
5 changes: 4 additions & 1 deletion config_schema/rest.schema.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"$id": "rest.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"host": {
"type": "string",
Expand All @@ -16,4 +19,4 @@
"required": [
"api_command"
]
}
}
5 changes: 4 additions & 1 deletion config_schema/serial.schema.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"$id": "serial.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"oneOf": [
{
"properties": {
Expand Down Expand Up @@ -61,4 +64,4 @@
"required": [
"dev"
]
}
}
11 changes: 6 additions & 5 deletions config_schema/stage.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"title": "Stage",
"type": "object",
"description": "A Stage.",
"allOf": [
{
"$ref": "instrument.schema.json"
}
],
"properties": {
"enable": {
"type": "boolean",
"description": "If the device is enabled or not."
},
"unit_factors": {
"type": "array",
"items": {
Expand Down Expand Up @@ -58,4 +59,4 @@
"required": [
"type"
]
}
}
15 changes: 11 additions & 4 deletions laserstudio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import sys
import yaml
import os.path
from .utils.util import resource_path
import logging
import argparse
from .utils.util import resource_path
from .utils.colors import LedgerColors

if __name__ == "__main__":
app = QApplication(sys.argv)
Expand Down Expand Up @@ -42,12 +43,12 @@
palette = QPalette()
palette.setColor(QPalette.ColorRole.Window, QColor(25, 25, 25))
palette.setColor(QPalette.ColorRole.WindowText, QColor(240, 240, 240))
palette.setColor(QPalette.ColorRole.Base, QColor(40, 40, 40))
palette.setColor(QPalette.ColorRole.Base, QColor(50, 50, 50))
palette.setColor(QPalette.ColorRole.AlternateBase, Qt.GlobalColor.red)
palette.setColor(QPalette.ColorRole.ToolTipBase, QColor(25, 25, 25))
palette.setColor(QPalette.ColorRole.ToolTipText, Qt.GlobalColor.white)
palette.setColor(QPalette.ColorRole.Text, Qt.GlobalColor.lightGray)
palette.setColor(QPalette.ColorRole.Button, QColor(40, 40, 40))
palette.setColor(QPalette.ColorRole.Button, QColor(45, 45, 45))
palette.setColor(
QPalette.ColorGroup.Disabled, QPalette.ColorRole.Button, QColor(30, 30, 30)
)
Expand All @@ -59,9 +60,15 @@
)
palette.setColor(QPalette.ColorRole.BrightText, Qt.GlobalColor.red)
palette.setColor(QPalette.ColorRole.Link, Qt.GlobalColor.red)
palette.setColor(QPalette.ColorRole.Highlight, QColor(40, 120, 233))
palette.setColor(QPalette.ColorRole.Highlight, LedgerColors.SafetyOrange.value)
palette.setColor(QPalette.ColorRole.HighlightedText, QColor(255, 255, 255))
app.setPalette(palette)
app.setStyleSheet("QToolBar { "
"border: 1px solid #252525;"
"border-radius: 4px;"
"margin: 3px;"
"padding: 6px;"
"background-color: #252525 }")

QLocale.setDefault(QLocale.c())

Expand Down
2 changes: 1 addition & 1 deletion laserstudio/instruments/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, config: dict):
"""
:param config: YAML configuration object
"""
super().__init__()
super().__init__(config=config)

# To refresh image regularly, in real-time
self.refresh_interval = cast(int, config.get("refresh_interval_ms", 200))
Expand Down
4 changes: 4 additions & 0 deletions laserstudio/instruments/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
class Instrument(QObject):
# Signal emitted when the instrument has a parameter which changed in another way than UI interface
parameter_changed = pyqtSignal(str, QVariant)

def __init__(self, config: dict):
super().__init__()
self.label = config.get("label")
2 changes: 1 addition & 1 deletion laserstudio/instruments/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class ProbeInstrument(Instrument):
def __init__(self, config: dict):
super().__init__()
super().__init__(config=config)
# Set manual position relative to the center position
# of the camera, eg in the StageSight coordinates.
self._fixed_pos: Optional[tuple[float, float]] = None
Expand Down
2 changes: 1 addition & 1 deletion laserstudio/instruments/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, config: dict):
"""
:param config: YAML configuration object
"""
super().__init__()
super().__init__(config=config)

device_type = config.get("type")
# To refresh stage position in the view, in real-time
Expand Down
22 changes: 6 additions & 16 deletions laserstudio/laserstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
QMainWindow,
QButtonGroup,
)
from typing import Optional, Any
from typing import Optional, Any, Union

from .widgets.viewer import Viewer
from .instruments.instruments import (
Expand Down Expand Up @@ -65,9 +65,7 @@ def __init__(self, config: Optional[dict]):

# Create group of buttons for Viewer mode selection
self.viewer_buttons_group = group = QButtonGroup(self)
group.idClicked.connect(
lambda _id: self.viewer.__setattr__("mode", Viewer.Mode(_id))
)
group.idClicked.connect(lambda mode: self.viewer.select_mode(mode, True))
self.viewer.mode_changed.connect(self.update_buttons_mode)

# Toolbar: Main
Expand Down Expand Up @@ -120,23 +118,15 @@ def __init__(self, config: Optional[dict]):

# Create shortcuts
shortcut = QShortcut(Qt.Key.Key_Escape, self)
shortcut.activated.connect(
lambda: self.viewer.__setattr__("mode", Viewer.Mode.NONE)
)
shortcut.activated.connect(lambda: self.viewer.select_mode(Viewer.Mode.NONE))
shortcut = QShortcut(Qt.Key.Key_R, self)
shortcut.activated.connect(
lambda: self.viewer.__setattr__("mode", Viewer.Mode.ZONE)
)
shortcut.activated.connect(lambda: self.viewer.select_mode(Viewer.Mode.ZONE))
# shortcut = QShortcut(Qt.Key_T, self)
# shortcut.activated.connect(self.zone_rot_mode)
shortcut = QShortcut(Qt.Key.Key_M, self)
shortcut.activated.connect(
lambda: self.viewer.__setattr__("mode", Viewer.Mode.STAGE)
)
shortcut.activated.connect(lambda: self.viewer.select_mode(Viewer.Mode.STAGE))
shortcut = QShortcut(Qt.Key.Key_P, self)
shortcut.activated.connect(
lambda: self.viewer.__setattr__("mode", Viewer.Mode.PIN)
)
shortcut.activated.connect(lambda: self.viewer.select_mode(Viewer.Mode.PIN))
if (stage := self.instruments.stage) is not None:
shortcut = QShortcut(Qt.Key.Key_PageUp, self)
shortcut.activated.connect(
Expand Down
11 changes: 5 additions & 6 deletions laserstudio/widgets/keyboardbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ def __init__(self, stage: StageInstrument, *__args):
self.displacement_xy = 100.0

vbox = QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
self.setLayout(vbox)

grid = QGridLayout()
grid.setContentsMargins(0, 0, 0, 0)
if num_axis > 0:
w = QPushButton(Direction.left)
w.setFixedWidth(30)
Expand Down Expand Up @@ -75,16 +77,15 @@ def __init__(self, stage: StageInstrument, *__args):
w.setFixedWidth(30)
w.pressed.connect(lambda: self.move_stage(Direction.down))
grid.addWidget(w, 2, 2, alignment=Qt.AlignmentFlag.AlignCenter)
grid.setColumnStretch(2, 1)
if num_axis > 2:
w = QPushButton(Direction.zup)
w.setFixedWidth(30)
w.pressed.connect(lambda: self.move_stage(Direction.zup))
grid.addWidget(w, 1, 4)
grid.addWidget(w, 1, 4, alignment=Qt.AlignmentFlag.AlignCenter)
w = QPushButton(Direction.zdown)
w.setFixedWidth(30)
w.pressed.connect(lambda: self.move_stage(Direction.zdown))
grid.addWidget(w, 2, 4)
grid.addWidget(w, 2, 4, alignment=Qt.AlignmentFlag.AlignCenter)
grid.setColumnStretch(4, 1)

w = QDoubleSpinBox()
Expand All @@ -97,9 +98,7 @@ def __init__(self, stage: StageInstrument, *__args):
w.setSingleStep(10)
grid.addWidget(w, 3, 4)

w = QWidget()
w.setLayout(grid)
vbox.addWidget(w)
vbox.addLayout(grid)

self.setFocusPolicy(Qt.FocusPolicy.ClickFocus)

Expand Down
2 changes: 1 addition & 1 deletion laserstudio/widgets/return_line_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self):
self.returnPressed.connect(self.reset)

def highlight(self):
self.setStyleSheet("background: #344266;")
self.setStyleSheet("background: #b86a45;")

def reset(self):
self.setStyleSheet("")
Expand Down
1 change: 1 addition & 0 deletions laserstudio/widgets/toolbars/cameranittoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, laser_studio: "LaserStudio"):
hbox = QHBoxLayout()
vbox.addLayout(hbox)
hbox.addWidget(QLabel("Gain:"))
vbox.setContentsMargins(0, 0, 0, 0)
w = self.hist_low_input = ReturnSpinBox()
w.setMinimum(0)
w.setMaximum(0xFFFF)
Expand Down
Loading

0 comments on commit 976d755

Please sign in to comment.