From 7342c05e5059ad6dbfa9788a5d36d01dcae82e90 Mon Sep 17 00:00:00 2001 From: Ximenes Rocha Resende Date: Thu, 30 Oct 2025 11:18:01 -0300 Subject: [PATCH 1/2] Remove notebook, conditional imports in dialog --- lnls/__init__.py | 12 +++--- lnls/dialog.py | 110 ++++++++++++++++++++++++++++++++--------------- lnls/notebook.py | 35 --------------- 3 files changed, 82 insertions(+), 75 deletions(-) delete mode 100644 lnls/notebook.py diff --git a/lnls/__init__.py b/lnls/__init__.py index ae36f79..abe532f 100644 --- a/lnls/__init__.py +++ b/lnls/__init__.py @@ -1,11 +1,11 @@ +""".""" import os as _os -from lnls.timer import * -from . import ids -from . import utils -from . import rotating_coil -from . import notebook -__all__ = ['utils', 'rotating_coil', 'ids', 'dialog','notebook'] +from lnls.timer import Timer, TimerError + +from . import dialog, ids, rotating_coil, utils + +__all__ = ['utils', 'rotating_coil', 'ids', 'dialog'] with open(_os.path.join(__path__[0], 'VERSION'), 'r') as _f: __version__ = _f.read().strip() diff --git a/lnls/dialog.py b/lnls/dialog.py index 98358b0..8fd28c6 100644 --- a/lnls/dialog.py +++ b/lnls/dialog.py @@ -1,16 +1,50 @@ import warnings + warnings.filterwarnings('ignore') import os as _os -from PyQt5.QtWidgets import QApplication, QFileDialog, QWidget, QDesktopWidget -from PyQt5.QtWidgets import QListView, QTreeView, QFileSystemModel, QGridLayout -from PyQt5.QtWidgets import QPushButton, QLabel, QLineEdit, QButtonGroup, QRadioButton -from PyQt5.QtWidgets import QAbstractItemView -from PyQt5.QtCore import QCoreApplication + +try: + from PyQt5.QtWidgets import ( + QApplication, + QFileDialog, + QWidget, + QDesktopWidget, + ) + from PyQt5.QtWidgets import ( + QListView, + QTreeView, + QFileSystemModel, + QGridLayout, + ) + from PyQt5.QtWidgets import ( + QPushButton, + QLabel, + QLineEdit, + QRadioButton, + ) + from PyQt5.QtWidgets import QAbstractItemView + from PyQt5.QtCore import QCoreApplication +except ImportError: + QApplication, + QFileDialog, + QWidget, + QDesktopWidget = [None, ] * 4 + QListView, + QTreeView, + QFileSystemModel, + QGridLayout = [None, ] * 4 + QPushButton, + QLabel, + QLineEdit, + QRadioButton = [None, ] * 4 + CURDIR = _os.path.abspath(_os.path.curdir) -def directories_dialog(path=None,name='Select Directories'): + +def directories_dialog(path=None, name='Select Directories'): ok = True + def _pressed_cancel(): nonlocal ok Fi.close() @@ -31,9 +65,9 @@ def _pressed_cancel(): Fi.setFileMode(Fi.DirectoryOnly) Fi.setDirectory(path) - for view in Fi.findChildren((QListView,QTreeView)): + for view in Fi.findChildren((QListView, QTreeView)): if isinstance(view.model(), QFileSystemModel): - view.setSelectionMode(QAbstractItemView.MultiSelection) + view.setSelectionMode(QAbstractItemView.MultiSelection) for view in Fi.findChildren(QPushButton): if view.text().lower().startswith('&cancel'): view.clicked.connect(_pressed_cancel) @@ -52,22 +86,28 @@ def _pressed_cancel(): return ok, list(sel_files2) -def input_dialog(prompt,def_answer=None,name='Type Parameters'): + +def input_dialog(prompt, def_answer=None, name='Type Parameters'): ok = False + def _pressed_ok(): nonlocal ok w.close() app.quit() ok |= True + def _pressed_cancel(): nonlocal ok w.close() app.quit() ok &= False - if isinstance(prompt,str): prompt = [prompt] - if def_answer is None: def_answer = len(prompt)*[''] - if isinstance(def_answer,str): def_answer = [def_answer] + if isinstance(prompt, str): + prompt = [prompt] + if def_answer is None: + def_answer = len(prompt) * [''] + if isinstance(def_answer, str): + def_answer = [def_answer] if len(prompt) != len(def_answer): raise IndexError("'prompt' and 'def_answer' must be the same length.") @@ -79,25 +119,26 @@ def _pressed_cancel(): grid.setSpacing(10) edit = [] for i in range(len(prompt)): - title = QLabel(prompt[i]) - edit += [QLineEdit()] - if def_answer is not None: edit[i].setText(def_answer[i]) - grid.addWidget(title, 2*i, 0,1,2)# title, row,col,spanrow,spancol - grid.addWidget(edit[i], 2*i+1, 0,1,2) - #Ok Button + title = QLabel(prompt[i]) + edit += [QLineEdit()] + if def_answer is not None: + edit[i].setText(def_answer[i]) + grid.addWidget(title, 2 * i, 0, 1, 2) # title, row,col,spanrow,spancol + grid.addWidget(edit[i], 2 * i + 1, 0, 1, 2) + # Ok Button qbtn = QPushButton('Ok', w) qbtn.clicked.connect(_pressed_ok) qbtn.resize(qbtn.sizeHint()) - grid.addWidget(qbtn, 2*(i+1), 0) - #Cancel Button + grid.addWidget(qbtn, 2 * (i + 1), 0) + # Cancel Button qbtn = QPushButton('Cancel', w) qbtn.clicked.connect(_pressed_cancel) qbtn.resize(qbtn.sizeHint()) - grid.addWidget(qbtn, 2*(i+1), 1) + grid.addWidget(qbtn, 2 * (i + 1), 1) - #Defining the layout of the window: + # Defining the layout of the window: w.setLayout(grid) - w.resize(50, i*50) + w.resize(50, i * 50) qr = w.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) @@ -111,14 +152,16 @@ def _pressed_cancel(): text += [ed.text()] return ok, text -def radio_dialog(options, name='Selection', default_idx=0): +def radio_dialog(options, name='Selection', default_idx=0): ok = False + def _pressed_ok(): nonlocal ok w.close() app.quit() ok |= True + def _pressed_cancel(): nonlocal ok w.close() @@ -137,24 +180,22 @@ def _pressed_cancel(): if i == default_idx: r.setChecked(True) edit.append(r) - grid.addWidget(r,0,i) - - + grid.addWidget(r, 0, i) - #Ok Button + # Ok Button qbtn = QPushButton('Ok', w) qbtn.clicked.connect(_pressed_ok) qbtn.resize(qbtn.sizeHint()) - grid.addWidget(qbtn, 2*(i+1), 0) - #Cancel Button + grid.addWidget(qbtn, 2 * (i + 1), 0) + # Cancel Button qbtn = QPushButton('Cancel', w) qbtn.clicked.connect(_pressed_cancel) qbtn.resize(qbtn.sizeHint()) - grid.addWidget(qbtn, 2*(i+1), 1) + grid.addWidget(qbtn, 2 * (i + 1), 1) - #Defining the layout of the window: + # Defining the layout of the window: w.setLayout(grid) - w.resize(50, i*50) + w.resize(50, i * 50) qr = w.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) @@ -164,5 +205,6 @@ def _pressed_cancel(): app.exec_() for r in edit: - if r.isChecked(): text = r.text() + if r.isChecked(): + text = r.text() return ok, text diff --git a/lnls/notebook.py b/lnls/notebook.py deleted file mode 100644 index a95dd49..0000000 --- a/lnls/notebook.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python3 - -from IPython.display import HTML as _HTML - -def turn_code_on_off_html(): - string = ''' - -The raw code for this IPython notebook is by default hidden for easier reading. -
''' - return _HTML(string) From 74af636bba8b3bd35573b03f6be10b485d95b6a9 Mon Sep 17 00:00:00 2001 From: Ximenes Rocha Resende Date: Thu, 30 Oct 2025 11:21:49 -0300 Subject: [PATCH 2/2] Remove flatten function --- lnls/utils.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lnls/utils.py b/lnls/utils.py index 7bd11c5..9955d16 100644 --- a/lnls/utils.py +++ b/lnls/utils.py @@ -40,17 +40,6 @@ def files_get_matches(folder=None, recursive=True, strs_in=None, strs_out=None): return files -def flatten(l): - try: - l[0] - r = [] - for e in l: - r.extend(flatten(e)) - return r - except: - return [l] - - def save_pickle(filename, **kwargs): """Save variables in gzip compressed pickle format as a dictionary. INPUTS: