Skip to content

Commit d327ce8

Browse files
committed
Moved convert_str_to_bool to utils.py
1 parent 7dea6cc commit d327ce8

3 files changed

Lines changed: 20 additions & 19 deletions

File tree

microscope/plugins/grid_plugin.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from microscope.widgets.rubberband import ResizableRubberBand
1515
from microscope.widgets.color_button import ColorButton
1616
from microscope.plugins.base_plugin import BasePlugin
17+
from microscope.utils import convert_str_bool
1718
from qtpy.QtGui import QMouseEvent
1819
from collections import defaultdict
1920

@@ -50,19 +51,6 @@ def __init__(self, parent: "Optional[Microscope]" = None):
5051
self._x_divs = 5
5152
self._y_divs = 5
5253

53-
def convert_str_bool(self, val):
54-
"""Converts a string representation of a boolean to a boolean value.
55-
56-
Args:
57-
val (str): The string representation of the boolean.
58-
59-
Returns:
60-
bool: The boolean value.
61-
"""
62-
if isinstance(val, str):
63-
return True if val.lower() == "true" else False
64-
return val
65-
6654
def read_settings(self, settings: Dict[str, Any]):
6755
"""Reads the plugin's settings from a dictionary.
6856
@@ -72,13 +60,13 @@ def read_settings(self, settings: Dict[str, Any]):
7260
self._grid_color = settings.get("color", QColor.fromRgb(0, 255, 0))
7361
self.start = settings.get("start", QPoint(0, 0))
7462
self.end = settings.get("end", QPoint(1, 1))
75-
self.plugin_state["grid_hidden"] = self.convert_str_bool(
63+
self.plugin_state["grid_hidden"] = convert_str_bool(
7664
settings.get("grid_hidden", False)
7765
)
78-
self.plugin_state["selector_hidden"] = self.convert_str_bool(
66+
self.plugin_state["selector_hidden"] = convert_str_bool(
7967
settings.get("selector_hidden", False)
8068
)
81-
self.plugin_state["grid_defined"] = self.convert_str_bool(
69+
self.plugin_state["grid_defined"] = convert_str_bool(
8270
settings.get("grid_defined", False)
8371
)
8472
self._x_divs = int(settings.get("x_divs", 5))

microscope/plugins/record_plugin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from qtpy.QtGui import QImage, QPainter, QPen, QFont, QColor
1414
from microscope.plugins.base_plugin import BaseImagePlugin
1515
from microscope.widgets.color_button import ColorButton
16+
from microscope.utils import convert_str_bool
1617
from qtpy.QtGui import QMouseEvent
1718
from qtpy.QtCore import QThread, Signal, QObject, Qt, QTimer
1819
import cv2 as cv
@@ -329,14 +330,14 @@ def read_settings(self, settings: Dict[str, Any]):
329330
)
330331
self.hours_per_file = int(settings.get("hours_per_file", 1))
331332
self.number_of_files = int(settings.get("number_of_files", 1))
332-
self.raw_image = True if settings.get("raw_image", "true") == "true" else False
333-
self.timestamp = True if settings.get("timestamp", "true") == "true" else False
333+
self.raw_image = convert_str_bool(settings.get("raw_image", True))
334+
self.timestamp = convert_str_bool(settings.get("timestamp", False))
334335
self.timestamp_color = settings.get(
335336
"timestamp_color", QColor.fromRgb(0, 255, 0)
336337
)
337338
self.timestamp_font_size = int(settings.get("timestamp_font_size", 12))
338339
self.width = int(settings.get("image_width", 480))
339-
self.use_epics_pv = bool(settings.get("use_epics", False))
340+
self.use_epics_pv = convert_str_bool(settings.get("use_epics", True))
340341
self.epics_pv_name = str(settings.get("epics_pv", ""))
341342
self.setup_epics()
342343

microscope/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def convert_str_bool(val):
2+
"""Converts a string representation of a boolean to a boolean value.
3+
4+
Args:
5+
val (str): The string representation of the boolean.
6+
7+
Returns:
8+
bool: The boolean value.
9+
"""
10+
if isinstance(val, str):
11+
return True if val.lower() == "true" else False
12+
return val

0 commit comments

Comments
 (0)