def __init__(self, parent, fname=None, rst=None, name=None): """ Parameters ---------- parent: QWidget The parent widget fname: str The name of the rst file. If None, specify the `rst` directly rst: str The restructured text to render when this button is clicked. If None, the `fname` has to be provided name: str The name to use for the document in the help_explorer """ if fname is None and rst is None: raise ValueError("Either `fname` or `rst` must be specified!") elif fname is not None and rst is not None: raise ValueError("Either `fname` or `rst` must be specified! " "Not both!") elif rst is not None and name is None: raise ValueError("A title must be specified for the rst document!") self.fname = fname self.rst = rst self.files = doc_files self.name = name QToolButton.__init__(self, parent) self.setIcon(QIcon(get_psy_icon('info.png'))) self.clicked.connect(self.show_docs)
def setup_line_selection(self) -> None: """Setup the row for selecting new lines.""" self.combo_lines = QtWidgets.QComboBox() self.combo_lines.setEditable(False) self.combo_lines.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) self.combo_lines.currentIndexChanged.connect(self.trigger_refresh) self.btn_add = utils.add_pushbutton(QtGui.QIcon(get_psy_icon('plus')), lambda: self.add_line(), "Add a line to the plot", icon=True) self.btn_del = utils.add_pushbutton(QtGui.QIcon(get_psy_icon('minus')), self.remove_line, "Add a line to the plot", icon=True)
def __init__(self, *args, **kwargs): from straditize.widgets.menu_actions import StraditizerMenuActions from straditize.widgets.progress_widget import ProgressWidget from straditize.widgets.data import DigitizingControl from straditize.widgets.selection_toolbar import SelectionToolbar from straditize.widgets.marker_control import MarkerControl from straditize.widgets.plots import PlotControl from straditize.widgets.axes_translations import AxesTranslations from straditize.widgets.image_correction import (ImageRotator, ImageRescaler) from straditize.widgets.colnames import ColumnNamesManager self._straditizers = [] super(StraditizerWidgets, self).__init__(*args, **kwargs) self.tree = QTreeWidget(parent=self) self.tree.setSelectionMode(QTreeWidget.NoSelection) self.refresh_button = QToolButton(self) self.refresh_button.setIcon(QIcon(get_psy_icon('refresh.png'))) self.refresh_button.setToolTip('Refresh from the straditizer') self.apply_button = EnableButton('Apply', parent=self) self.cancel_button = EnableButton('Cancel', parent=self) self.attrs_button = QPushButton('Attributes', parent=self) self.tutorial_button = QPushButton('Tutorial', parent=self) self.tutorial_button.setCheckable(True) self.error_msg = PyErrorMessage(self) self.stradi_combo = QComboBox() self.btn_open_stradi = QToolButton() self.btn_open_stradi.setIcon(QIcon(get_psy_icon('run_arrow.png'))) self.btn_close_stradi = QToolButton() self.btn_close_stradi.setIcon(QIcon(get_psy_icon('invalid.png'))) self.btn_reload_autosaved = QPushButton("Reload") self.btn_reload_autosaved.setToolTip( "Close the straditizer and reload the last autosaved project") # --------------------------------------------------------------------- # --------------------------- Tree widgets ---------------------------- # --------------------------------------------------------------------- self.tree.setHeaderLabels(['', '']) self.tree.setColumnCount(2) self.progress_item = QTreeWidgetItem(0) self.progress_item.setText(0, 'ToDo list') self.progress_widget = ProgressWidget(self, self.progress_item) self.menu_actions_item = QTreeWidgetItem(0) self.menu_actions_item.setText(0, 'Images import/export') self.tree.addTopLevelItem(self.menu_actions_item) self.menu_actions = StraditizerMenuActions(self) self.digitizer_item = item = QTreeWidgetItem(0) item.setText(0, 'Digitization control') self.digitizer = DigitizingControl(self, item) self.col_names_item = item = QTreeWidgetItem(0) item.setText(0, 'Column names') self.colnames_manager = ColumnNamesManager(self, item) self.add_info_button(item, 'column_names.rst') self.axes_translations_item = item = QTreeWidgetItem(0) item.setText(0, 'Axes translations') self.axes_translations = AxesTranslations(self, item) self.image_transform_item = item = QTreeWidgetItem(0) item.setText(0, 'Transform source image') self.image_rescaler = ImageRescaler(self, item) self.image_rotator_item = item = QTreeWidgetItem(0) item.setText(0, 'Rotate image') self.image_rotator = ImageRotator(self) self.image_transform_item.addChild(item) self.image_rotator.setup_children(item) self.plot_control_item = item = QTreeWidgetItem(0) item.setText(0, 'Plot control') self.plot_control = PlotControl(self, item) self.add_info_button(item, 'plot_control.rst') self.marker_control_item = item = QTreeWidgetItem(0) item.setText(0, 'Marker control') self.marker_control = MarkerControl(self, item) self.add_info_button(item, 'marker_control.rst') # --------------------------------------------------------------------- # ----------------------------- Toolbars ------------------------------ # --------------------------------------------------------------------- self.selection_toolbar = SelectionToolbar(self, 'Selection toolbar') # --------------------------------------------------------------------- # ----------------------------- InfoButton ---------------------------- # --------------------------------------------------------------------- self.info_button = InfoButton(self, get_doc_file('straditize.rst')) # --------------------------------------------------------------------- # --------------------------- Layouts --------------------------------- # --------------------------------------------------------------------- stradi_box = QHBoxLayout() stradi_box.addWidget(self.stradi_combo, 1) stradi_box.addWidget(self.btn_open_stradi) stradi_box.addWidget(self.btn_close_stradi) attrs_box = QHBoxLayout() attrs_box.addWidget(self.attrs_button) attrs_box.addStretch(0) attrs_box.addWidget(self.tutorial_button) btn_box = QHBoxLayout() btn_box.addWidget(self.refresh_button) btn_box.addWidget(self.info_button) btn_box.addStretch(0) btn_box.addWidget(self.apply_button) btn_box.addWidget(self.cancel_button) reload_box = QHBoxLayout() reload_box.addWidget(self.btn_reload_autosaved) reload_box.addStretch(0) vbox = QVBoxLayout() vbox.addLayout(stradi_box) vbox.addWidget(self.tree) vbox.addLayout(attrs_box) vbox.addLayout(btn_box) vbox.addLayout(reload_box) self.setLayout(vbox) self.apply_button.setEnabled(False) self.cancel_button.setEnabled(False) self.tree.expandItem(self.progress_item) self.tree.expandItem(self.digitizer_item) # --------------------------------------------------------------------- # --------------------------- Connections ----------------------------- # --------------------------------------------------------------------- self.stradi_combo.currentIndexChanged.connect(self.set_current_stradi) self.refresh_button.clicked.connect(self.refresh) self.attrs_button.clicked.connect(self.edit_attrs) self.tutorial_button.clicked.connect(self.start_tutorial) self.open_external.connect(self._create_straditizer_from_args) self.btn_open_stradi.clicked.connect( self.menu_actions.open_straditizer) self.btn_close_stradi.clicked.connect(self.close_straditizer) self.btn_reload_autosaved.clicked.connect(self.reload_autosaved) self.refresh() header = self.tree.header() header.setStretchLastSection(False) header.setSectionResizeMode(0, QHeaderView.Stretch)
return osp.join(osp.dirname(__file__), 'docs', fname) def read_doc_file(fname): """Return the content of a rst documentation file""" with open(get_doc_file(fname)) as f: return f.read() def get_icon(fname): """Return the path of an icon""" return osp.join(osp.dirname(__file__), 'icons', fname) doc_files = glob.glob(get_doc_file('*.rst')) + glob.glob( get_psy_icon('*.png')) + glob.glob(get_doc_file('*.png')) + \ glob.glob(get_icon('*.png')) class EnableButton(QPushButton): """A `QPushButton` that emits a signal when enabled""" #: A signal that is emitted with a boolean whether if the button is #: enabled or disabled enabled = QtCore.pyqtSignal(bool) def setEnabled(self, b): """Reimplemented to emit the :attr:`enabled` signal""" if b is self.isEnabled(): return super(EnableButton, self).setEnabled(b)
import datetime as dt from PyQt5 import QtWidgets, QtGui, QtCore import numpy as np import pandas as pd from psyplot_gui.common import get_icon as get_psy_icon from straditize.widgets import StraditizerControlBase, get_doc_file, doc_files from collections import OrderedDict from straditize.widgets.data import get_reader_name, int_list2str ALL_TASKS = 'all' DONE = 'done' NOTYET = 'not yet ready' TASK_TODO = 'todo' icons = { DONE: get_psy_icon('valid.png'), NOTYET: get_psy_icon('warning.png'), TASK_TODO: get_psy_icon('invalid.png'), } class ProgressTask(QtWidgets.QListWidgetItem): """The base class for an item that should be shown in the ProgressWidget""" @property def is_finished(self): """A property that is True, when the task is finished""" return True @property def try_finished(self): """Same as :attr:`is_finished` but catches every exception"""
'docs', '*.png')), glob.glob( osp.join(osp.dirname(__file__), '..', 'straditize', 'widgets', 'icons', '*.png'))) for f in files: shutil.copyfile(f, osp.join(gui_dir, osp.basename(f))) tutorial_dir = osp.join(osp.dirname(__file__), 'tutorial') for base in ['beginner', 'hoya-del-castillo']: if not osp.exists(osp.join(tutorial_dir, base)): os.mkdir(osp.join(tutorial_dir, base)) files = chain( glob.glob( osp.join(osp.dirname(__file__), '..', 'straditize', 'widgets', 'tutorial', base, '*.rst')), glob.glob(get_psy_icon('*.png')), glob.glob( osp.join(osp.dirname(__file__), '..', 'straditize', 'widgets', 'tutorial', base, '*.png')), glob.glob( osp.join(osp.dirname(__file__), '..', 'straditize', 'widgets', 'docs', '*.png')), glob.glob( osp.join(osp.dirname(__file__), '..', 'straditize', 'widgets', 'icons', '*.png'))) for f in files: shutil.copyfile(f, osp.join(tutorial_dir, base, osp.basename(f))) with open(osp.join('tutorial', base, base + '-tutorial-intro.rst')) as f: s = f.read() with open(osp.join('tutorial', base, base + '-tutorial-intro.rst'),