mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-03-06 17:02:50 +01:00
refactor(black): black 26 applied
This commit is contained in:
@@ -147,8 +147,7 @@ class LaunchTile(RoundedFrame):
|
||||
|
||||
# Action button
|
||||
self.action_button = QPushButton("Open")
|
||||
self.action_button.setStyleSheet(
|
||||
"""
|
||||
self.action_button.setStyleSheet("""
|
||||
QPushButton {
|
||||
background-color: #007AFF;
|
||||
border: none;
|
||||
@@ -160,8 +159,7 @@ class LaunchTile(RoundedFrame):
|
||||
QPushButton:hover {
|
||||
background-color: #005BB5;
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
self.layout.addWidget(self.action_button, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
def _fit_label_to_width(self, label: QLabel, max_width: int, min_pt: int = 10):
|
||||
|
||||
@@ -127,12 +127,10 @@ class NavigationItem(QWidget):
|
||||
self._icon_size_expanded = QtCore.QSize(26, 26)
|
||||
self.icon_btn.setIconSize(self._icon_size_collapsed)
|
||||
# Remove QToolButton hover/pressed background/outline
|
||||
self.icon_btn.setStyleSheet(
|
||||
"""
|
||||
self.icon_btn.setStyleSheet("""
|
||||
QToolButton:hover { background: transparent; border: none; }
|
||||
QToolButton:pressed { background: transparent; border: none; }
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# Mini label below icon
|
||||
self.mini_lbl = QLabel(self._mini_text, self)
|
||||
|
||||
@@ -31,7 +31,7 @@ logger = bec_logger.logger
|
||||
class DeviceManagerOphydValidationDialog(QtWidgets.QDialog):
|
||||
"""Popup dialog to test Ophyd device configurations interactively."""
|
||||
|
||||
def __init__(self, parent=None, config: dict | None = None): # type:ignore
|
||||
def __init__(self, parent=None, config: dict | None = None): # type: ignore
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle("Device Manager Ophyd Test")
|
||||
self._config_status = ConfigStatus.UNKNOWN.value
|
||||
@@ -133,7 +133,7 @@ class DeviceFormDialog(QtWidgets.QDialog):
|
||||
# validated: config_status, connection_status
|
||||
accepted_data = QtCore.Signal(dict, int, int, str, str)
|
||||
|
||||
def __init__(self, parent=None, add_btn_text: str = "Add Device"): # type:ignore
|
||||
def __init__(self, parent=None, add_btn_text: str = "Add Device"): # type: ignore
|
||||
super().__init__(parent)
|
||||
# Track old device name if config is edited
|
||||
self._old_device_name: str = ""
|
||||
|
||||
@@ -103,16 +103,14 @@ class CustomBusyWidget(QWidget):
|
||||
button_width = int(button_height * aspect_ratio)
|
||||
self.cancel_button.setFixedSize(button_width, button_height)
|
||||
color = get_accent_colors()
|
||||
self.cancel_button.setStyleSheet(
|
||||
f"""
|
||||
self.cancel_button.setStyleSheet(f"""
|
||||
QPushButton {{
|
||||
background-color: {color.emergency.name()};
|
||||
color: white;
|
||||
font-weight: 600;
|
||||
border-radius: 6px;
|
||||
}}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# Layout
|
||||
content_layout = QVBoxLayout(self)
|
||||
@@ -128,12 +126,10 @@ class CustomBusyWidget(QWidget):
|
||||
bg_color = color._colors.get("BG", None)
|
||||
if bg_color is None: # Fallback if missing
|
||||
bg_color = QColor(50, 50, 50, 255)
|
||||
self.setStyleSheet(
|
||||
f"""
|
||||
self.setStyleSheet(f"""
|
||||
background-color: {bg_color.name()};
|
||||
border-radius: 12px;
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
def _ui_scale(self) -> int:
|
||||
parent = self.parent()
|
||||
|
||||
@@ -20,15 +20,13 @@ class BECLogin(QWidget):
|
||||
|
||||
title = QLabel("Sign in", parent=self)
|
||||
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
title.setStyleSheet(
|
||||
"""
|
||||
title.setStyleSheet("""
|
||||
#QLabel
|
||||
{
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
self.username = QLineEdit(parent=self)
|
||||
self.username.setPlaceholderText("Username")
|
||||
@@ -57,13 +55,11 @@ class BECLogin(QWidget):
|
||||
|
||||
self.username.setFocus()
|
||||
|
||||
self.setStyleSheet(
|
||||
"""
|
||||
self.setStyleSheet("""
|
||||
QLineEdit {
|
||||
padding: 8px;
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
def _clear_password(self):
|
||||
"""Clear the password field."""
|
||||
|
||||
@@ -67,15 +67,13 @@ class TutorialOverlay(QWidget):
|
||||
box = QFrame(self)
|
||||
app = QApplication.instance()
|
||||
bg_color = app.palette().window().color()
|
||||
box.setStyleSheet(
|
||||
f"""
|
||||
box.setStyleSheet(f"""
|
||||
QFrame {{
|
||||
background-color: {bg_color.name()};
|
||||
border-radius: 8px;
|
||||
padding: 8px;
|
||||
}}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
layout = QVBoxLayout(box)
|
||||
|
||||
# Top layout with close button (left) and step indicator (right)
|
||||
|
||||
@@ -69,13 +69,11 @@ class RoundedFrame(QFrame):
|
||||
"""
|
||||
Update the style of the frame based on the background color.
|
||||
"""
|
||||
self.setStyleSheet(
|
||||
f"""
|
||||
self.setStyleSheet(f"""
|
||||
QFrame#roundedFrame {{
|
||||
border-radius: {self._radius}px;
|
||||
}}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
self.apply_plot_widget_style()
|
||||
|
||||
def apply_plot_widget_style(self, border: str = "none"):
|
||||
|
||||
@@ -599,16 +599,14 @@ class ExpandableMenuAction(ToolBarAction):
|
||||
button.setIcon(QIcon(self.icon_path))
|
||||
button.setText(self.tooltip)
|
||||
button.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup)
|
||||
button.setStyleSheet(
|
||||
"""
|
||||
button.setStyleSheet("""
|
||||
QToolButton {
|
||||
font-size: 14px;
|
||||
}
|
||||
QMenu {
|
||||
font-size: 14px;
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
menu = QMenu(button)
|
||||
for action_container in self.actions.values():
|
||||
action: QAction = action_container.action
|
||||
|
||||
@@ -106,8 +106,7 @@ class ResizableSpacer(QWidget):
|
||||
|
||||
self.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
|
||||
|
||||
self.setStyleSheet(
|
||||
"""
|
||||
self.setStyleSheet("""
|
||||
ResizableSpacer {
|
||||
background-color: transparent;
|
||||
margin: 0px;
|
||||
@@ -117,8 +116,7 @@ class ResizableSpacer(QWidget):
|
||||
ResizableSpacer:hover {
|
||||
background-color: rgba(100, 100, 200, 80);
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
self.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
|
||||
@@ -291,8 +291,7 @@ class ModularToolBar(QToolBar):
|
||||
menu = QMenu(self)
|
||||
theme = get_theme_name()
|
||||
if theme == "dark":
|
||||
menu.setStyleSheet(
|
||||
"""
|
||||
menu.setStyleSheet("""
|
||||
QMenu {
|
||||
background-color: rgba(50, 50, 50, 0.9);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
@@ -300,12 +299,10 @@ class ModularToolBar(QToolBar):
|
||||
QMenu::item:selected {
|
||||
background-color: rgba(0, 0, 255, 0.2);
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
else:
|
||||
# Light theme styling
|
||||
menu.setStyleSheet(
|
||||
"""
|
||||
menu.setStyleSheet("""
|
||||
QMenu {
|
||||
background-color: rgba(255, 255, 255, 0.9);
|
||||
border: 1px solid rgba(0, 0, 0, 0.2);
|
||||
@@ -313,8 +310,7 @@ class ModularToolBar(QToolBar):
|
||||
QMenu::item:selected {
|
||||
background-color: rgba(0, 0, 255, 0.2);
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
for ii, bundle in enumerate(self.shown_bundles):
|
||||
self.handle_bundle_context_menu(menu, bundle)
|
||||
if ii < len(self.shown_bundles) - 1:
|
||||
|
||||
@@ -46,7 +46,7 @@ class AutoUpdates(BECMainWindow):
|
||||
self.setCentralWidget(self.dock_area)
|
||||
self._auto_update_selected_device: str | None = None
|
||||
|
||||
self._default_dock = None # type:ignore
|
||||
self._default_dock = None # type: ignore
|
||||
self.current_widget: BECWidget | None = None
|
||||
self.dock_name = None
|
||||
self._enabled = True
|
||||
@@ -63,7 +63,7 @@ class AutoUpdates(BECMainWindow):
|
||||
Disconnect all connections for the auto updates.
|
||||
"""
|
||||
self.bec_dispatcher.disconnect_slot(
|
||||
self._on_scan_status, MessageEndpoints.scan_status() # type:ignore
|
||||
self._on_scan_status, MessageEndpoints.scan_status() # type: ignore
|
||||
)
|
||||
|
||||
@property
|
||||
@@ -244,10 +244,10 @@ class AutoUpdates(BECMainWindow):
|
||||
wf = self.set_dock_to_widget("Waveform")
|
||||
|
||||
# Get the scan report devices reported by the scan
|
||||
dev_x = info.scan_report_devices[0] # type:ignore
|
||||
dev_x = info.scan_report_devices[0] # type: ignore
|
||||
|
||||
# For the y axis, get the selected device
|
||||
dev_y = self.get_selected_device(info.readout_priority["monitored"]) # type:ignore
|
||||
dev_y = self.get_selected_device(info.readout_priority["monitored"]) # type: ignore
|
||||
if not dev_y:
|
||||
return
|
||||
|
||||
@@ -279,8 +279,8 @@ class AutoUpdates(BECMainWindow):
|
||||
scatter = self.set_dock_to_widget("ScatterWaveform")
|
||||
|
||||
# Get the scan report devices reported by the scan
|
||||
dev_x, dev_y = info.scan_report_devices[0], info.scan_report_devices[1] # type:ignore
|
||||
dev_z = self.get_selected_device(info.readout_priority["monitored"]) # type:ignore
|
||||
dev_x, dev_y = info.scan_report_devices[0], info.scan_report_devices[1] # type: ignore
|
||||
dev_z = self.get_selected_device(info.readout_priority["monitored"]) # type: ignore
|
||||
|
||||
if None in (dev_x, dev_y, dev_z):
|
||||
return
|
||||
@@ -309,8 +309,8 @@ class AutoUpdates(BECMainWindow):
|
||||
# If the scan report devices are empty, there is nothing we can do
|
||||
if not info.scan_report_devices:
|
||||
return
|
||||
dev_x = info.scan_report_devices[0] # type:ignore
|
||||
dev_y = self.get_selected_device(info.readout_priority["monitored"]) # type:ignore
|
||||
dev_x = info.scan_report_devices[0] # type: ignore
|
||||
dev_y = self.get_selected_device(info.readout_priority["monitored"]) # type: ignore
|
||||
if not dev_y:
|
||||
return
|
||||
|
||||
|
||||
@@ -101,14 +101,12 @@ class Explorer(BECWidget, QWidget):
|
||||
palette = get_theme_palette()
|
||||
separator_color = palette.mid().color()
|
||||
|
||||
self.splitter.setStyleSheet(
|
||||
f"""
|
||||
self.splitter.setStyleSheet(f"""
|
||||
QSplitter::handle {{
|
||||
height: 0.1px;
|
||||
background-color: rgba({separator_color.red()}, {separator_color.green()}, {separator_color.blue()}, 60);
|
||||
}}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
def _update_spacer(self) -> None:
|
||||
"""Update the spacer size based on section states"""
|
||||
|
||||
@@ -134,15 +134,13 @@ class NotificationToast(QFrame):
|
||||
bg.setAlphaF(0.30)
|
||||
icon_bg = bg.name(QtGui.QColor.HexArgb)
|
||||
icon_btn.setFixedSize(40, 40)
|
||||
icon_btn.setStyleSheet(
|
||||
f"""
|
||||
icon_btn.setStyleSheet(f"""
|
||||
QToolButton {{
|
||||
background: {icon_bg};
|
||||
border: none;
|
||||
border-radius: 20px; /* perfect circle */
|
||||
}}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
title_lbl = QtWidgets.QLabel(self._title)
|
||||
|
||||
@@ -327,15 +325,13 @@ class NotificationToast(QFrame):
|
||||
bg = QtGui.QColor(SEVERITY[value.value]["color"])
|
||||
bg.setAlphaF(0.30)
|
||||
icon_bg = bg.name(QtGui.QColor.HexArgb)
|
||||
self._icon_btn.setStyleSheet(
|
||||
f"""
|
||||
self._icon_btn.setStyleSheet(f"""
|
||||
QToolButton {{
|
||||
background: {icon_bg};
|
||||
border: none;
|
||||
border-radius: 20px;
|
||||
}}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
self.apply_theme(self._theme)
|
||||
# keep injected gradient in sync
|
||||
if getattr(self, "_hg_enabled", False):
|
||||
@@ -391,8 +387,7 @@ class NotificationToast(QFrame):
|
||||
card_bg.setAlphaF(0.88)
|
||||
btn_hover = self._accent_color.name()
|
||||
|
||||
self.setStyleSheet(
|
||||
f"""
|
||||
self.setStyleSheet(f"""
|
||||
#NotificationToast {{
|
||||
background: {card_bg.name(QtGui.QColor.HexArgb)};
|
||||
border-radius: 12px;
|
||||
@@ -406,18 +401,15 @@ class NotificationToast(QFrame):
|
||||
font-size: 14px;
|
||||
}}
|
||||
#NotificationToast QPushButton:hover {{ color: {btn_hover}; }}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
# traceback panel colours
|
||||
trace_bg = "#1e1e1e" if theme == "dark" else "#f0f0f0"
|
||||
self.trace_view.setStyleSheet(
|
||||
f"""
|
||||
self.trace_view.setStyleSheet(f"""
|
||||
background:{trace_bg};
|
||||
color:{palette['body']};
|
||||
border:none;
|
||||
border-radius:8px;
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# icon glyph vs badge background: darker badge, lighter icon in light mode
|
||||
icon_fg = "#ffffff" if theme == "light" else self._accent_color.name()
|
||||
@@ -438,15 +430,13 @@ class NotificationToast(QFrame):
|
||||
else:
|
||||
badge_bg.setAlphaF(0.30)
|
||||
icon_bg = badge_bg.name(QtGui.QColor.HexArgb)
|
||||
self._icon_btn.setStyleSheet(
|
||||
f"""
|
||||
self._icon_btn.setStyleSheet(f"""
|
||||
QToolButton {{
|
||||
background: {icon_bg};
|
||||
border: none;
|
||||
border-radius: 20px;
|
||||
}}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# stronger accent wash in light mode, slightly stronger in dark too
|
||||
self._accent_alpha = 110 if theme == "light" else 60
|
||||
@@ -593,8 +583,7 @@ class NotificationCentre(QScrollArea):
|
||||
self.setWidgetResizable(True)
|
||||
# transparent background so only the toast cards are visible
|
||||
self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
|
||||
self.setStyleSheet(
|
||||
"""
|
||||
self.setStyleSheet("""
|
||||
#NotificationCentre { background: transparent; }
|
||||
#NotificationCentre QScrollBar:vertical {
|
||||
background: transparent;
|
||||
@@ -610,8 +599,7 @@ class NotificationCentre(QScrollArea):
|
||||
#NotificationCentre QScrollBar::sub-line:vertical { height: 0; }
|
||||
#NotificationCentre QScrollBar::add-page:vertical,
|
||||
#NotificationCentre QScrollBar::sub-page:vertical { background: transparent; }
|
||||
"""
|
||||
)
|
||||
""")
|
||||
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||
self.setFrameShape(QtWidgets.QFrame.NoFrame)
|
||||
self.setFixedWidth(fixed_width)
|
||||
@@ -958,8 +946,7 @@ class NotificationIndicator(QWidget):
|
||||
self._group.buttonToggled.connect(self._button_toggled)
|
||||
|
||||
# minimalistic look: no frames or backgrounds on the buttons
|
||||
self.setStyleSheet(
|
||||
"""
|
||||
self.setStyleSheet("""
|
||||
QToolButton {
|
||||
border: none;
|
||||
background: transparent;
|
||||
@@ -970,8 +957,7 @@ class NotificationIndicator(QWidget):
|
||||
background: rgba(255, 255, 255, 40);
|
||||
font-weight: 600;
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# initial state: none checked (auto‑dismiss behaviour)
|
||||
for k in kinds:
|
||||
|
||||
@@ -51,8 +51,7 @@ class _DeviceEntryWidget(QFrame):
|
||||
self.setToolTip(self._rich_text())
|
||||
|
||||
def _rich_text(self):
|
||||
return dedent(
|
||||
f"""
|
||||
return dedent(f"""
|
||||
<b><u><h2> {self._device_spec.name}: </h2></u></b>
|
||||
<table>
|
||||
<tr><td> description: </td><td><i> {self._device_spec.description} </i></td></tr>
|
||||
@@ -60,8 +59,7 @@ class _DeviceEntryWidget(QFrame):
|
||||
<tr><td> enabled: </td><td><i> {self._device_spec.enabled} </i></td></tr>
|
||||
<tr><td> read only: </td><td><i> {self._device_spec.readOnly} </i></td></tr>
|
||||
</table>
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
def setup_title_layout(self, device_spec: HashableDevice):
|
||||
self._title_layout = QHBoxLayout()
|
||||
|
||||
@@ -275,12 +275,10 @@ class LMFitDialog(BECWidget, QWidget):
|
||||
button.setEnabled(True)
|
||||
else:
|
||||
button.setEnabled(False)
|
||||
button.setStyleSheet(
|
||||
f"""
|
||||
button.setStyleSheet(f"""
|
||||
QPushButton:enabled {{ background-color: {self._accent_colors.success.name()};color: white; }}
|
||||
QPushButton:disabled {{ background-color: grey;color: white; }}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
self.action_buttons[param_name] = button
|
||||
layout = QVBoxLayout()
|
||||
layout.addWidget(self.action_buttons[param_name])
|
||||
|
||||
@@ -47,15 +47,13 @@ class BECJupyterConsole(RichJupyterWidget): # pragma: no cover:
|
||||
)
|
||||
|
||||
def _init_bec_kernel(self):
|
||||
self.execute(
|
||||
"""
|
||||
self.execute("""
|
||||
from bec_ipython_client.main import BECIPythonClient
|
||||
bec = BECIPythonClient()
|
||||
bec.start()
|
||||
dev = bec.device_manager.devices if bec else None
|
||||
scans = bec.scans if bec else None
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
def _cleanup_bec(self):
|
||||
if getattr(self, "ipyclient", None) is not None and self.inprocess is True:
|
||||
|
||||
@@ -362,8 +362,7 @@ if __name__ == "__main__": # pragma: no cover
|
||||
widget.set_language("python")
|
||||
widget.set_theme("vs-dark")
|
||||
widget.editor.set_minimap_enabled(False)
|
||||
widget.set_text(
|
||||
"""
|
||||
widget.set_text("""
|
||||
import numpy as np
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
@@ -380,8 +379,7 @@ if TYPE_CHECKING:
|
||||
# This is a comment
|
||||
def hello_world():
|
||||
print("Hello, world!")
|
||||
"""
|
||||
)
|
||||
""")
|
||||
widget.set_highlighted_lines(1, 3)
|
||||
widget.show()
|
||||
qapp.exec_()
|
||||
|
||||
@@ -44,14 +44,12 @@ class RingCardWidget(QFrame):
|
||||
self.setObjectName("RingCardWidget")
|
||||
|
||||
bg = self._get_theme_color("BORDER")
|
||||
self.setStyleSheet(
|
||||
f"""
|
||||
self.setStyleSheet(f"""
|
||||
#RingCardWidget {{
|
||||
border: 1px solid {bg.name() if bg else '#CCCCCC'};
|
||||
border-radius: 4px;
|
||||
}}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(8, 8, 8, 8)
|
||||
|
||||
@@ -289,14 +289,12 @@ class BECQueue(BECWidget, CompactPopupWidget):
|
||||
abort_button.button.setIcon(
|
||||
material_icon("cancel", color="#cc181e", filled=True, convert_to_pixmap=False)
|
||||
)
|
||||
abort_button.setStyleSheet(
|
||||
"""
|
||||
abort_button.setStyleSheet("""
|
||||
QPushButton {
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
return abort_button
|
||||
|
||||
|
||||
@@ -227,13 +227,11 @@ class IDEExplorer(BECWidget, QWidget):
|
||||
try:
|
||||
# Create the file with a basic template
|
||||
with open(file_path, "w", encoding="utf-8") as f:
|
||||
f.write(
|
||||
f"""
|
||||
f.write(f"""
|
||||
\"\"\"
|
||||
{filename} - Created at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
||||
\"\"\"
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
except Exception as e:
|
||||
# Show error if file creation failed
|
||||
@@ -281,8 +279,7 @@ class IDEExplorer(BECWidget, QWidget):
|
||||
try:
|
||||
# Create the file with a macro function template
|
||||
with open(file_path, "w", encoding="utf-8") as f:
|
||||
f.write(
|
||||
f'''"""
|
||||
f.write(f'''"""
|
||||
{function_name} macro - Created at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
||||
"""
|
||||
|
||||
@@ -296,8 +293,7 @@ def {function_name}():
|
||||
print("Executing macro: {function_name}")
|
||||
# TODO: Add your macro code here
|
||||
pass
|
||||
'''
|
||||
)
|
||||
''')
|
||||
|
||||
# Refresh the macro tree to show the new function
|
||||
macro_dir_section.content_widget.refresh()
|
||||
|
||||
@@ -38,8 +38,7 @@ def developer_view(qtbot, mocked_client):
|
||||
def temp_python_file():
|
||||
"""Create a temporary Python file for testing."""
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
|
||||
f.write(
|
||||
"""# Test Python file
|
||||
f.write("""# Test Python file
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -48,8 +47,7 @@ def test_function():
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(test_function())
|
||||
"""
|
||||
)
|
||||
""")
|
||||
temp_file_path = f.name
|
||||
|
||||
yield temp_file_path
|
||||
|
||||
@@ -88,8 +88,7 @@ def test_client_generator_with_black_formatting():
|
||||
generator.generate_client(container)
|
||||
|
||||
# Format the expected output with black to ensure it matches the generator output
|
||||
expected_output = dedent(
|
||||
'''\
|
||||
expected_output = dedent('''\
|
||||
# This file was automatically generated by generate_cli.py
|
||||
# type: ignore
|
||||
|
||||
@@ -174,8 +173,7 @@ def test_client_generator_with_black_formatting():
|
||||
"""
|
||||
Set the amplitude of the waveform.
|
||||
"""
|
||||
'''
|
||||
)
|
||||
''')
|
||||
|
||||
expected_output_formatted = black.format_str(
|
||||
expected_output, mode=black.FileMode(line_length=100)
|
||||
|
||||
@@ -68,21 +68,17 @@ def test_shared_macros_section_with_files(ide_explorer, tmpdir):
|
||||
"""Test that shared macros section is created when plugin directory has files"""
|
||||
# Create dummy shared macro files
|
||||
shared_macros_dir = tmpdir.mkdir("shared_macros")
|
||||
shared_macros_dir.join("shared_macro1.py").write(
|
||||
"""
|
||||
shared_macros_dir.join("shared_macro1.py").write("""
|
||||
def shared_function1():
|
||||
return "shared1"
|
||||
|
||||
def shared_function2():
|
||||
return "shared2"
|
||||
"""
|
||||
)
|
||||
shared_macros_dir.join("utilities.py").write(
|
||||
"""
|
||||
""")
|
||||
shared_macros_dir.join("utilities.py").write("""
|
||||
def utility_function():
|
||||
return "utility"
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
with mock.patch.object(ide_explorer, "_get_plugin_dir") as mock_get_plugin_dir:
|
||||
mock_get_plugin_dir.return_value = str(shared_macros_dir)
|
||||
|
||||
@@ -20,8 +20,7 @@ def temp_macro_files(tmpdir):
|
||||
|
||||
# Create a simple macro file with functions
|
||||
macro_file1 = macro_dir / "test_macros.py"
|
||||
macro_file1.write_text(
|
||||
'''
|
||||
macro_file1.write_text('''
|
||||
def test_macro_function():
|
||||
"""A test macro function."""
|
||||
return "test"
|
||||
@@ -34,13 +33,11 @@ class TestClass:
|
||||
"""This class should be ignored."""
|
||||
def method(self):
|
||||
pass
|
||||
'''
|
||||
)
|
||||
''')
|
||||
|
||||
# Create another macro file
|
||||
macro_file2 = macro_dir / "utils_macros.py"
|
||||
macro_file2.write_text(
|
||||
'''
|
||||
macro_file2.write_text('''
|
||||
def utility_function():
|
||||
"""A utility function."""
|
||||
pass
|
||||
@@ -48,37 +45,30 @@ def utility_function():
|
||||
def deprecated_function():
|
||||
"""Old function."""
|
||||
return None
|
||||
'''
|
||||
)
|
||||
''')
|
||||
|
||||
# Create a file with no functions (should be ignored)
|
||||
empty_file = macro_dir / "empty.py"
|
||||
empty_file.write_text(
|
||||
"""
|
||||
empty_file.write_text("""
|
||||
# Just a comment
|
||||
x = 1
|
||||
y = 2
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# Create a file starting with underscore (should be ignored)
|
||||
private_file = macro_dir / "_private.py"
|
||||
private_file.write_text(
|
||||
"""
|
||||
private_file.write_text("""
|
||||
def private_function():
|
||||
return "private"
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# Create a file with syntax errors
|
||||
error_file = macro_dir / "error_file.py"
|
||||
error_file.write_text(
|
||||
"""
|
||||
error_file.write_text("""
|
||||
def broken_function(
|
||||
# Missing closing parenthesis and colon
|
||||
pass
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
return macro_dir
|
||||
|
||||
@@ -406,13 +396,11 @@ class TestMacroTreeRefresh:
|
||||
|
||||
# Add a new macro file
|
||||
new_file = temp_macro_files / "new_macros.py"
|
||||
new_file.write_text(
|
||||
'''
|
||||
new_file.write_text('''
|
||||
def new_function():
|
||||
"""A new function."""
|
||||
return "new"
|
||||
'''
|
||||
)
|
||||
''')
|
||||
|
||||
# Refresh the tree
|
||||
macro_tree.refresh()
|
||||
@@ -439,14 +427,12 @@ def new_function():
|
||||
|
||||
# Modify the file to add a new function
|
||||
with open(test_file_path, "a") as f:
|
||||
f.write(
|
||||
'''
|
||||
f.write('''
|
||||
|
||||
def newly_added_function():
|
||||
"""A newly added function."""
|
||||
return "added"
|
||||
'''
|
||||
)
|
||||
''')
|
||||
|
||||
# Refresh just this file
|
||||
macro_tree.refresh_file_item(test_file_path)
|
||||
|
||||
Reference in New Issue
Block a user