class FitDialog(QDialog, FitWidgetMixin): def __init__(self, wintitle=None, icon="guiqwt.svg", edit=True, toolbar=False, options=None, parent=None, panels=None, param_cols=1, legend_anchor='TR', auto_fit=False): QDialog.__init__(self, parent) self.edit = edit self.button_layout = None FitWidgetMixin.__init__(self, wintitle, icon, toolbar, options, panels, param_cols, legend_anchor, auto_fit) self.setWindowFlags(Qt.Window) def setup_widget_layout(self): FitWidgetMixin.setup_widget_layout(self) if self.edit: self.install_button_layout() def install_button_layout(self): bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()")) self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()")) self.button_list += [bbox.button(QDialogButtonBox.Ok)] self.button_layout = QHBoxLayout() self.button_layout.addStretch() self.button_layout.addWidget(bbox) vlayout = self.layout() vlayout.addSpacing(10) vlayout.addLayout(self.button_layout)
def setup_widget_layout(self): vlayout = QVBoxLayout(self) vlayout.addWidget(self.toolbar) vlayout.addLayout(self.plot_layout) self.setLayout(vlayout) if self.edit: self.button_layout = QHBoxLayout() self.install_button_layout() vlayout.addLayout(self.button_layout)
class CurveDialog(QDialog, CurveWidgetMixin): """ Construct a CurveDialog object: plotting dialog box with integrated plot manager * wintitle: window title * icon: window icon * edit: editable state * toolbar: show/hide toolbar * options: options sent to the :py:class:`guiqwt.curve.CurvePlot` object (dictionary) * parent: parent widget * panels (optional): additionnal panels (list, tuple) """ def __init__(self, wintitle="guiqwt plot", icon="guiqwt.svg", edit=False, toolbar=False, options=None, parent=None, panels=None): if not PYQT5: QDialog.__init__(self, parent) self.edit = edit self.button_box = None self.button_layout = None if PYQT5: super(CurveDialog, self).__init__(parent, wintitle=wintitle, icon=icon, toolbar=toolbar, options=options, panels=panels) else: CurveWidgetMixin.__init__(self, wintitle=wintitle, icon=icon, toolbar=toolbar, options=options, panels=panels) self.setWindowFlags(Qt.Window) def setup_widget_layout(self): vlayout = QVBoxLayout(self) vlayout.addWidget(self.toolbar) vlayout.addLayout(self.plot_layout) self.setLayout(vlayout) if self.edit: self.button_layout = QHBoxLayout() self.install_button_layout() vlayout.addLayout(self.button_layout) def install_button_layout(self): """ Install standard buttons (OK, Cancel) in dialog button box layout (:py:attr:`guiqwt.plot.CurveDialog.button_layout`) This method may be overriden to customize the button box """ bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bbox.accepted.connect(self.accept) bbox.rejected.connect(self.reject) self.button_layout.addWidget(bbox) self.button_box = bbox
def install_button_layout(self): bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bbox.accepted.connect(self.accept) bbox.rejected.connect(self.reject) self.button_list += [bbox.button(QDialogButtonBox.Ok)] self.button_layout = QHBoxLayout() self.button_layout.addStretch() self.button_layout.addWidget(bbox) vlayout = self.layout() vlayout.addSpacing(10) vlayout.addLayout(self.button_layout)
def install_button_layout(self): bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()")) self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()")) self.button_list += [bbox.button(QDialogButtonBox.Ok)] self.button_layout = QHBoxLayout() self.button_layout.addStretch() self.button_layout.addWidget(bbox) vlayout = self.layout() vlayout.addSpacing(10) vlayout.addLayout(self.button_layout)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.layout = QHBoxLayout() self.widgets = [] for i, label_text in enumerate(["start", "stop", "step"]): label = QLabel(label_text) argument_widget = QLineEdit() self.layout.addWidget(label) self.layout.addWidget(argument_widget) self.widgets.append(argument_widget) self.setLayout(self.layout) self.slice = slice(None)
class FitDialog(QDialog, FitWidgetMixin): def __init__(self, wintitle=None, icon="guiqwt.svg", edit=True, toolbar=False, options=None, parent=None, panels=None, param_cols=1, legend_anchor='TR', auto_fit=False): if not PYQT5: QDialog.__init__(self, parent) self.edit = edit self.button_layout = None if PYQT5: super(FitDialog, self).__init__(parent, wintitle=wintitle, icon=icon, toolbar=toolbar, options=options, panels=panels, param_cols=param_cols, legend_anchor=legend_anchor, auto_fit=auto_fit) else: FitWidgetMixin.__init__(self, wintitle, icon, toolbar, options, panels, param_cols, legend_anchor, auto_fit) self.setWindowFlags(Qt.Window) def setup_widget_layout(self): FitWidgetMixin.setup_widget_layout(self) if self.edit: self.install_button_layout() def install_button_layout(self): bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bbox.accepted.connect(self.accept) bbox.rejected.connect(self.reject) self.button_list += [bbox.button(QDialogButtonBox.Ok)] self.button_layout = QHBoxLayout() self.button_layout.addStretch() self.button_layout.addWidget(bbox) vlayout = self.layout() vlayout.addSpacing(10) vlayout.addLayout(self.button_layout)
def get_image_layout(imagename, text="", tooltip="", alignment=Qt.AlignLeft): """ Construct a QHBoxLayout including image from the file with specified name, left-aligned text [with specified tooltip] Return (layout, label) """ layout = QHBoxLayout() if alignment in (Qt.AlignCenter, Qt.AlignRight): layout.addStretch() layout.addWidget(get_image_label(imagename)) label = QLabel(text) label.setToolTip(tooltip) layout.addWidget(label) if alignment in (Qt.AlignCenter, Qt.AlignLeft): layout.addStretch() return (layout, label)
def setup_widget_layout(self): self.fit_layout = QHBoxLayout() self.params_layout = QGridLayout() params_group = create_groupbox(self, _("Fit parameters"), layout=self.params_layout) if self.auto_fit_enabled: auto_group = self.create_autofit_group() self.fit_layout.addWidget(auto_group) self.fit_layout.addWidget(params_group) self.plot_layout.addLayout(self.fit_layout, 1, 0) vlayout = QVBoxLayout(self) vlayout.addWidget(self.toolbar) vlayout.addLayout(self.plot_layout) self.setLayout(vlayout)
def __init__(self, parent=None, tdms_file=None, group_label="Data group", channel_labels=["X channel", "Y channel", "Z channel", "Z2 channel", ]): """ Params ====== twin_z : bool Allow to select two Z (data) channels group_label : str: Label text for group combo box channel_labels : list of str Label texts for channel combo boxes """ QWidget.__init__(self, parent) self.widget_layout = QVBoxLayout() self.group_widgets = [] self.channel_widgets = [] for i, label_text in enumerate([group_label] + channel_labels): label = QLabel(label_text) channel_widget = QComboBox() channel_widget.addItem(label_text) channel_widget.setMinimumWidth(250) channel_widget.setDisabled(True) group_widget = QComboBox() group_widget.addItem(label_text) group_widget.setMinimumWidth(250) group_widget.setDisabled(True) layout = QHBoxLayout() layout.addWidget(label) layout.addWidget(group_widget) if i != 0: layout.addWidget(channel_widget) self.widget_layout.addLayout(layout) if i == 0: self.group_combo = group_widget self.group_combo.currentIndexChanged.connect(self.change_sub_channels) else: self.group_widgets.append(group_widget) self.channel_widgets.append(channel_widget) group_widget.currentIndexChanged.connect(self._populate_channels) self.setLayout(self.widget_layout) self.tdms_file = tdms_file
def __init__(self, parent=None): super(ContrastAdjustment, self).__init__(parent) self.local_manager = None # local manager for the histogram plot self.manager = None # manager for the associated image plot # Storing min/max markers for each active image self.min_markers = {} self.max_markers = {} # Select point tools self.min_select_tool = None self.max_select_tool = None style = "<span style=\'color: #444444\'><b>%s</b></span>" layout, _label = get_image_layout(self.PANEL_ICON, style % self.PANEL_TITLE, alignment=Qt.AlignCenter) layout.setAlignment(Qt.AlignCenter) vlayout = QVBoxLayout() vlayout.addLayout(layout) self.local_manager = PlotManager(self) self.histogram = LevelsHistogram(parent) vlayout.addWidget(self.histogram) self.local_manager.add_plot(self.histogram) hlayout = QHBoxLayout() self.setLayout(hlayout) hlayout.addLayout(vlayout) self.toolbar = toolbar = QToolBar(self) toolbar.setOrientation(Qt.Vertical) # toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) hlayout.addWidget(toolbar) # Add standard plot-related tools to the local manager lman = self.local_manager lman.add_tool(SelectTool) lman.add_tool(BasePlotMenuTool, "item") lman.add_tool(BasePlotMenuTool, "axes") lman.add_tool(BasePlotMenuTool, "grid") lman.add_tool(AntiAliasingTool) lman.get_default_tool().activate() self.outliers_param = EliminateOutliersParam(self.PANEL_TITLE)
def __init__(self): QMainWindow.__init__(self) self.setWindowTitle("Test") a = 600 self.resize(int(a), int(a / 1.338)) hlayout = QHBoxLayout() central_widget = QWidget(self) central_widget.setLayout(hlayout) self.setCentralWidget(central_widget)
def _generateFrame(self): ''' Return the frame containing the presentation, check if the frame was created, otherwise it is created :return: ''' # generate the frame if necessary if self._frame is None: # Generate frame and define the layout based on the frame self._frame = QFrame(self._parentFrame) _layout = QVBoxLayout() self._frame.setLayout(_layout) # Add the "Main" group box for this view, if present. It is rendered in foreground if self._generateGroupBox() is not None: _layout.addWidget(self._groupbox) else: self._frame.setFrameStyle(QFrame.Panel|QFrame.Raised) self._frame.setLineWidth(1) # Add to layout eventually the other subview if self._viewtype == 'Tabs': _tabs = QTabWidget() _layout.addWidget(_tabs) elif self._viewtype == 'Splitter': _splitter =QSplitter() _layout.addWidget(_splitter) else: _sub_frame = QFrame() _sub_frame_layout = QHBoxLayout() _sub_frame.setLayout(_sub_frame_layout) _layout.addWidget(_sub_frame) # Add all the sub view as sub frames in the layout for sw in self._subViewDictionary.values(): sw.setParentView(self._frame) if self._viewtype == 'Tabs': _tabs.addTab(sw.getFrame(), sw.viewname) elif self._viewtype == 'Splitter': _splitter.addWidget(sw.getFrame()) else: _sub_frame_layout.addWidget(sw.getFrame()) return self._frame
def __init__(self, parent): super(FileUi, self).__init__(Qt.Vertical, parent) layoutWidget = QWidget() layout = QVBoxLayout() layoutWidget.setLayout(layout) self.comment = QPlainTextEdit() self.fileName = None self.saveTxtCheck = QCheckBox('Save Txt') self.saveHdfCheck = QCheckBox('Save HDF5') self.saveTxtBtn = QPushButton('Save Txt') self.saveHdfBtn = QPushButton('Save HDF5') ############# # stream group streamGroup = QGroupBox('Stream data to file:') streamGroup.setFlat(True) streamGroupLayout = QHBoxLayout() streamGroupLayout.addWidget(self.saveTxtCheck) streamGroupLayout.addWidget(self.saveHdfCheck) streamGroup.setLayout(streamGroupLayout) ############## # save static file saveGroup = QGroupBox('Save now to file:') saveGroup.setFlat(True) saveGroupLayout = QHBoxLayout() saveGroupLayout.addWidget(self.saveTxtBtn) saveGroupLayout.addWidget(self.saveHdfBtn) saveGroup.setLayout(saveGroupLayout) ############## # put layout together layout.addWidget(QLabel('Comment:')) layout.addWidget(self.comment) layout.addWidget(streamGroup) layout.addWidget(saveGroup) self.addWidget(layoutWidget) ############## # connnect stuff for functionality self.saveTxtCheck.stateChanged.connect(self.__makeFileName) self.saveHdfCheck.stateChanged.connect(self.__makeFileName) ############## # thread for streaming data to file #self.updateCurrPos.connect(self.__updateCurrPos) self.stream_thread = QThread() # create the QThread self.stream_thread.start() self.stream_worker = GenericWorker(self.__streamFile) self.stream_worker.moveToThread(self.stream_thread)
def __init__(self): QMainWindow.__init__(self) self.setWindowTitle("Signal filtering 2 (guiqwt)") self.setWindowIcon(get_icon('guiqwt.svg')) hlayout = QHBoxLayout() central_widget = QWidget(self) central_widget.setLayout(hlayout) self.setCentralWidget(central_widget) #---guiqwt plot manager self.manager = PlotManager(self)
def __init__(self, parent): super(MakeNicerWidget, self).__init__(parent) self.data = np.array([]) # array which holds data # Time domain plot self.tdWidget = DockablePlotWidget(self, CurveWidget) self.tdWidget.calcFun.addFun('fs', lambda x: x, lambda x: x) self.tdWidget.calcFun.addFun('µm', lambda x: x * fsDelay * 1e3, lambda x: x / fsDelay * 1e-3) self.tdWidget.calcFun.addFun('mm', lambda x: x * fsDelay, lambda x: x / fsDelay) tdPlot = self.tdWidget.get_plot() self.tdSignal = SignalFT(self, plot=tdPlot) self.tdFit = SignalFT(self, plot=tdPlot, col='r') # Frequency domain plot self.fdWidget = DockablePlotWidget(self, CurveWidget) self.fdWidget.calcFun.addFun('PHz', lambda x: x, lambda x: x) self.fdWidget.calcFun.addFun('THz', lambda x: x * 1e3, lambda x: x * 1e-3) self.fdWidget.calcFun.addFun('µm', lambda x: c0 / x * 1e-9, lambda x: c0 / x * 1e-9) self.fdWidget.calcFun.addFun('eV', lambda x: x, lambda x: x) fdplot = self.fdWidget.get_plot() self.fdSignal = SignalFT(self, plot=fdplot) self.fdFit = SignalFT(self, plot=fdplot, col='r') self.smoothNum = QSpinBox() # gives number of smoothin points self.smoothNum.setMinimum(1) self.smoothNum.setSingleStep(2) # Put things together in layouts buttonLayout = QGridLayout() plotLayout = QVBoxLayout() layout = QHBoxLayout() plotLayout.addWidget(self.tdWidget) plotLayout.addWidget(self.fdWidget) buttonLayout.addWidget(QLabel('Fitting function'), 0, 0) buttonLayout.addWidget( QLineEdit("lambda x,A,f,phi: np.sin(2*np.pi*f*x+phi)"), 1, 0, 1, 2) buttonLayout.addWidget(QLabel('Smooth'), 2, 0) buttonLayout.addWidget(self.smoothNum, 2, 1) buttonLayout.setRowStretch(3, 20) layout.addLayout(buttonLayout) layout.addLayout(plotLayout) self.setLayout(layout) # connect signals self.updateTdPlot.connect(self.tdSignal.updatePlot) self.updateTdFitPlot.connect(self.tdFit.updatePlot) self.updateFdPlot.connect(lambda data: self.fdSignal.updatePlot( self.fdSignal.computeFFT(data))) self.updateFdFitPlot.connect( lambda data: self.fdFit.updatePlot(self.fdFit.computeFFT(data))) self.smoothNum.valueChanged.connect(self.smoothData) self.setData()
def __init__(self): QWidget.__init__(self) self.setWindowTitle( 'Biofeedback' ) self.button_start = QPushButton() self.button_start.setText("START") self.button_stop = QPushButton() self.button_stop.setText("STOP") layout = QHBoxLayout(self) layout.addWidget(self.button_start) layout.addWidget(self.button_stop) self.connect(self.button_start, SIGNAL("clicked(bool)"), self.start_session) self.connect(self.button_stop, SIGNAL("clicked(bool)"), self.stop_session) self.setLayout(layout) self.setGeometry(300,100,250,100) self.show() #self.datastorage = DataStorage() #settings = {'db_host':'amber','db_user':'******','db_pwd':'dbrootpass','db_dbname':'biodb'} #self.datastorage.enableDbStorage(settings) self.thread = ConnectionThread()
def __init__(self, parent): QWidget.__init__(self, parent) layout = QHBoxLayout() row_nb = 14 cindex = 0 for child in dir(QStyle): if child.startswith('SP_'): if cindex == 0: col_layout = QVBoxLayout() icon_layout = QHBoxLayout() icon = get_std_icon(child) label = QLabel() label.setPixmap(icon.pixmap(32, 32)) icon_layout.addWidget(label) icon_layout.addWidget(QLineEdit(child.replace('SP_', ''))) col_layout.addLayout(icon_layout) cindex = (cindex + 1) % row_nb if cindex == 0: layout.addLayout(col_layout) self.setLayout(layout) self.setWindowTitle('Standard Platform Icons') self.setWindowIcon(get_std_icon('TitleBarMenuButton'))
def __init__(self, parent, options=None): QWidget.__init__(self, parent=parent) if options is None: options = {} self.imagewidget = ImageWidget(self, **options) self.imagewidget.register_all_image_tools() hlayout = QHBoxLayout() self.add_buttons_to_layout(hlayout) vlayout = QVBoxLayout() vlayout.addWidget(self.imagewidget) vlayout.addLayout(hlayout) self.setLayout(vlayout)
class QSliceInput(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.layout = QHBoxLayout() self.widgets = [] for i, label_text in enumerate(["start", "stop", "step"]): label = QLabel(label_text) argument_widget = QLineEdit() self.layout.addWidget(label) self.layout.addWidget(argument_widget) self.widgets.append(argument_widget) self.setLayout(self.layout) self.slice = slice(None) def setSlice(self, slice): if slice is None: return False self.widgets[0].setText(str(slice.start)) self.widgets[1].setText(str(slice.stop)) self.widgets[2].setText(str(slice.step)) def getSlice(self): return slice(*[int(w.text()) for w in self.widgets])
def __init__(self, parent): QWidget.__init__(self, parent) layout = QHBoxLayout() row_nb = 14 cindex = 0 for child in dir(QStyle): if child.startswith('SP_'): if cindex == 0: col_layout = QVBoxLayout() icon_layout = QHBoxLayout() icon = get_std_icon(child) label = QLabel() label.setPixmap(icon.pixmap(32, 32)) icon_layout.addWidget( label ) icon_layout.addWidget( QLineEdit(child.replace('SP_', '')) ) col_layout.addLayout(icon_layout) cindex = (cindex+1) % row_nb if cindex == 0: layout.addLayout(col_layout) self.setLayout(layout) self.setWindowTitle('Standard Platform Icons') self.setWindowIcon(get_std_icon('TitleBarMenuButton'))
def __init__(self, parent): QWidget.__init__(self, parent) font = QFont(get_family(MONOSPACE), 10, QFont.Normal) info_icon = QLabel() icon = get_std_icon('MessageBoxInformation').pixmap(24, 24) info_icon.setPixmap(icon) info_icon.setFixedWidth(32) info_icon.setAlignment(Qt.AlignTop) self.desc_label = QLabel() self.desc_label.setWordWrap(True) self.desc_label.setAlignment(Qt.AlignTop) self.desc_label.setFont(font) group_desc = QGroupBox(_("Description"), self) layout = QHBoxLayout() layout.addWidget(info_icon) layout.addWidget(self.desc_label) group_desc.setLayout(layout) self.editor = CodeEditor(self) self.editor.setup_editor(linenumbers=True, font=font) self.editor.setReadOnly(True) group_code = QGroupBox(_("Source code"), self) layout = QVBoxLayout() layout.addWidget(self.editor) group_code.setLayout(layout) self.run_button = QPushButton(get_icon("apply.png"), _("Run this script"), self) self.quit_button = QPushButton(get_icon("exit.png"), _("Quit"), self) hlayout = QHBoxLayout() hlayout.addWidget(self.run_button) hlayout.addStretch() hlayout.addWidget(self.quit_button) vlayout = QVBoxLayout() vlayout.addWidget(group_desc) vlayout.addWidget(group_code) vlayout.addLayout(hlayout) self.setLayout(vlayout)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.widget_layout = QVBoxLayout() title_layout = QHBoxLayout() title_layout.addStretch() style = "<span style=\'color: #444444\'><b>%s</b></span>" title = QLabel(style % "Operations") title_layout.addWidget(title) title_layout.addStretch() self.widget_layout.addLayout(title_layout) # Create ListWidget and add 10 items to move around. self.list_widget = QListWidget() # self.list_widget.setDragDropMode(QAbstractItemView.InternalMove) self.list_widget.setSelectionMode(QAbstractItemView.ExtendedSelection) self.list_widget.setSortingEnabled(False) self.list_widget.currentItemChanged.connect(self._populate_settings_update) self.widget_layout.addWidget(self.list_widget) otitle_layout = QHBoxLayout() otitle_layout.addStretch() otitle = QLabel(style % "Operation settings") otitle_layout.addWidget(otitle) otitle_layout.addStretch() self.widget_layout.addLayout(otitle_layout) self.operations_combo = QComboBox() self.operations_combo.currentIndexChanged.connect(self._populate_settings_add) self.widget_layout.addWidget(self.operations_combo) self.operation_settings = GenericOperationWidget() self.widget_layout.addWidget(self.operation_settings) self.toolbar = QToolBar() self.toolbar.addAction(get_icon('apply.png'), "Apply/Replace", self._change_operation) self.toolbar.addAction(get_icon('editors/edit_add.png'), "Add after", self._add_operation) self.toolbar.addAction(get_icon('trash.png'), "Remove", self._remove_operation) self.widget_layout.addWidget(self.toolbar) self.setLayout(self.widget_layout)
def setup_widget(self): layout = QHBoxLayout() layout.addWidget(self.cs_plot) layout.addWidget(self.toolbar) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout)
def __init__(self, parent): QWidget.__init__(self, parent) font = QFont(get_family(MONOSPACE), 10, QFont.Normal) info_icon = QLabel() icon = get_std_icon('MessageBoxInformation').pixmap(24, 24) info_icon.setPixmap(icon) info_icon.setFixedWidth(32) info_icon.setAlignment(Qt.AlignTop) self.service_status_label = QLabel() self.service_status_label.setWordWrap(True) self.service_status_label.setAlignment(Qt.AlignTop) self.service_status_label.setFont(font) self.desc_label = QLabel() self.desc_label.setWordWrap(True) self.desc_label.setAlignment(Qt.AlignTop) self.desc_label.setFont(font) self.group_desc = QGroupBox("Description", self) layout = QHBoxLayout() layout.addWidget(info_icon) layout.addWidget(self.desc_label) layout.addStretch() layout.addWidget(self.service_status_label) self.group_desc.setLayout(layout) self.editor = CodeEditor(self) self.editor.setup_editor(linenumbers=True, font=font) self.editor.setReadOnly(False) self.group_code = QGroupBox("Source code", self) layout = QVBoxLayout() layout.addWidget(self.editor) self.group_code.setLayout(layout) self.enable_button = QPushButton(get_icon("apply.png"), "Enable", self) self.save_button = QPushButton(get_icon("filesave.png"), "Save", self) self.disable_button = QPushButton(get_icon("delete.png"), "Disable", self) self.refresh_button = QPushButton(get_icon("restart.png"), "Refresh", self) hlayout = QHBoxLayout() hlayout.addWidget(self.save_button) hlayout.addWidget(self.enable_button) hlayout.addWidget(self.disable_button) hlayout.addWidget(self.refresh_button) vlayout = QVBoxLayout() vlayout.addWidget(self.group_desc) vlayout.addWidget(self.group_code) self.html_window = HTMLWindow() vlayout.addWidget(self.html_window) vlayout.addLayout(hlayout) self.setLayout(vlayout) self.current_file = None
def __init__(self, parent): QWidget.__init__(self, parent) font = QFont(get_family(MONOSPACE), 10, QFont.Normal) info_icon = QLabel() icon = get_std_icon('MessageBoxInformation').pixmap(24, 24) info_icon.setPixmap(icon) info_icon.setFixedWidth(32) info_icon.setAlignment(Qt.AlignTop) self.service_status_label = QLabel() self.service_status_label.setWordWrap(True) self.service_status_label.setAlignment(Qt.AlignTop) self.service_status_label.setFont(font) self.desc_label = QLabel() self.desc_label.setWordWrap(True) self.desc_label.setAlignment(Qt.AlignTop) self.desc_label.setFont(font) group_desc = QGroupBox("Description", self) layout = QHBoxLayout() layout.addWidget(info_icon) layout.addWidget(self.desc_label) layout.addStretch() layout.addWidget(self.service_status_label ) group_desc.setLayout(layout) self.editor = CodeEditor(self) self.editor.setup_editor(linenumbers=True, font=font) self.editor.setReadOnly(False) group_code = QGroupBox("Source code", self) layout = QVBoxLayout() layout.addWidget(self.editor) group_code.setLayout(layout) self.enable_button = QPushButton(get_icon("apply.png"), "Enable", self) self.save_button = QPushButton(get_icon("filesave.png"), "Save", self) self.edit_datadog_conf_button = QPushButton(get_icon("edit.png"), "Edit agent settings", self) self.disable_button = QPushButton(get_icon("delete.png"), "Disable", self) self.view_log_button = QPushButton(get_icon("txt.png"), "View log", self) self.menu_button = QPushButton(get_icon("settings.png"), "Manager", self) hlayout = QHBoxLayout() hlayout.addWidget(self.save_button) hlayout.addStretch() hlayout.addWidget(self.enable_button) hlayout.addStretch() hlayout.addWidget(self.disable_button) hlayout.addStretch() hlayout.addWidget(self.edit_datadog_conf_button) hlayout.addStretch() hlayout.addWidget(self.view_log_button) hlayout.addStretch() hlayout.addWidget(self.menu_button) vlayout = QVBoxLayout() vlayout.addWidget(group_desc) vlayout.addWidget(group_code) vlayout.addLayout(hlayout) self.setLayout(vlayout) self.current_file = None
def __init__(self, parent): QWidget.__init__(self, parent) font = QFont(get_family(MONOSPACE), 10, QFont.Normal) info_icon = QLabel() icon = get_std_icon("MessageBoxInformation").pixmap(24, 24) info_icon.setPixmap(icon) info_icon.setFixedWidth(32) info_icon.setAlignment(Qt.AlignTop) self.service_status_label = QLabel() self.service_status_label.setWordWrap(True) self.service_status_label.setAlignment(Qt.AlignTop) self.service_status_label.setFont(font) self.desc_label = QLabel() self.desc_label.setWordWrap(True) self.desc_label.setAlignment(Qt.AlignTop) self.desc_label.setFont(font) self.group_desc = QGroupBox("Description", self) layout = QHBoxLayout() layout.addWidget(info_icon) layout.addWidget(self.desc_label) layout.addStretch() layout.addWidget(self.service_status_label) self.group_desc.setLayout(layout) self.editor = CodeEditor(self) self.editor.setup_editor(linenumbers=True, font=font) self.editor.setReadOnly(False) self.group_code = QGroupBox("Source code", self) layout = QVBoxLayout() layout.addWidget(self.editor) self.group_code.setLayout(layout) self.enable_button = QPushButton(get_icon("apply.png"), "Enable", self) self.save_button = QPushButton(get_icon("filesave.png"), "Save", self) self.disable_button = QPushButton(get_icon("delete.png"), "Disable", self) self.refresh_button = QPushButton(get_icon("restart.png"), "Refresh", self) hlayout = QHBoxLayout() hlayout.addWidget(self.save_button) hlayout.addWidget(self.enable_button) hlayout.addWidget(self.disable_button) hlayout.addWidget(self.refresh_button) vlayout = QVBoxLayout() vlayout.addWidget(self.group_desc) vlayout.addWidget(self.group_code) self.html_window = HTMLWindow() vlayout.addWidget(self.html_window) vlayout.addLayout(hlayout) self.setLayout(vlayout) self.current_file = None
def __init__(self): QWidget.__init__(self) self.setWindowTitle("Signal filtering (guiqwt)") self.setWindowIcon(get_icon('guiqwt.svg')) hlayout = QHBoxLayout() self.setLayout(hlayout)
def addWidget(self, widget): QHBoxLayout.addWidget(self, widget) self.widgets.append(widget)
def __init__(self): QHBoxLayout.__init__(self) self.widgets = []
class FitWidgetMixin(CurveWidgetMixin): def __init__(self, wintitle="guiqwt plot", icon="guiqwt.svg", toolbar=False, options=None, panels=None, param_cols=1, legend_anchor='TR', auto_fit=True): if wintitle is None: wintitle = _('Curve fitting') self.x = None self.y = None self.fitfunc = None self.fitargs = None self.fitkwargs = None self.fitparams = None self.autofit_prm = None self.data_curve = None self.fit_curve = None self.legend = None self.legend_anchor = legend_anchor self.xrange = None self.show_xrange = False self.param_cols = param_cols self.auto_fit_enabled = auto_fit self.button_list = [] # list of buttons to be disabled at startup self.fit_layout = None self.params_layout = None CurveWidgetMixin.__init__(self, wintitle=wintitle, icon=icon, toolbar=toolbar, options=options, panels=panels) self.refresh() # QWidget API -------------------------------------------------------------- def resizeEvent(self, event): QWidget.resizeEvent(self, event) self.get_plot().replot() # CurveWidgetMixin API ----------------------------------------------------- def setup_widget_layout(self): self.fit_layout = QHBoxLayout() self.params_layout = QGridLayout() params_group = create_groupbox(self, _("Fit parameters"), layout=self.params_layout) if self.auto_fit_enabled: auto_group = self.create_autofit_group() self.fit_layout.addWidget(auto_group) self.fit_layout.addWidget(params_group) self.plot_layout.addLayout(self.fit_layout, 1, 0) vlayout = QVBoxLayout(self) vlayout.addWidget(self.toolbar) vlayout.addLayout(self.plot_layout) self.setLayout(vlayout) def create_plot(self, options): CurveWidgetMixin.create_plot(self, options) for plot in self.get_plots(): plot.SIG_RANGE_CHANGED.connect(self.range_changed) # Public API --------------------------------------------------------------- def set_data(self, x, y, fitfunc=None, fitparams=None, fitargs=None, fitkwargs=None): if self.fitparams is not None and fitparams is not None: self.clear_params_layout() self.x = x self.y = y if fitfunc is not None: self.fitfunc = fitfunc if fitparams is not None: self.fitparams = fitparams if fitargs is not None: self.fitargs = fitargs if fitkwargs is not None: self.fitkwargs = fitkwargs self.autofit_prm = AutoFitParam(title=_("Automatic fitting options")) self.autofit_prm.xmin = x.min() self.autofit_prm.xmax = x.max() self.compute_imin_imax() if self.fitparams is not None and fitparams is not None: self.populate_params_layout() self.refresh() def set_fit_data(self, fitfunc, fitparams, fitargs=None, fitkwargs=None): if self.fitparams is not None: self.clear_params_layout() self.fitfunc = fitfunc self.fitparams = fitparams self.fitargs = fitargs self.fitkwargs = fitkwargs self.populate_params_layout() self.refresh() def clear_params_layout(self): for i, param in enumerate(self.fitparams): for widget in param.get_widgets(): if widget is not None: self.params_layout.removeWidget(widget) widget.hide() def populate_params_layout(self): add_fitparam_widgets_to(self.params_layout, self.fitparams, self.refresh, param_cols=self.param_cols) def create_autofit_group(self): auto_button = QPushButton(get_icon('apply.png'), _("Run"), self) auto_button.clicked.connect(self.autofit) autoprm_button = QPushButton(get_icon('settings.png'), _("Settings"), self) autoprm_button.clicked.connect(self.edit_parameters) xrange_button = QPushButton(get_icon('xrange.png'), _("Bounds"), self) xrange_button.setCheckable(True) xrange_button.toggled.connect(self.toggle_xrange) auto_layout = QVBoxLayout() auto_layout.addWidget(auto_button) auto_layout.addWidget(autoprm_button) auto_layout.addWidget(xrange_button) self.button_list += [auto_button, autoprm_button, xrange_button] return create_groupbox(self, _("Automatic fit"), layout=auto_layout) def get_fitfunc_arguments(self): """Return fitargs and fitkwargs""" fitargs = self.fitargs if self.fitargs is None: fitargs = [] fitkwargs = self.fitkwargs if self.fitkwargs is None: fitkwargs = {} return fitargs, fitkwargs def refresh(self, slider_value=None): """Refresh Fit Tool dialog box""" # Update button states enable = self.x is not None and self.y is not None \ and self.x.size > 0 and self.y.size > 0 \ and self.fitfunc is not None and self.fitparams is not None \ and len(self.fitparams) > 0 for btn in self.button_list: btn.setEnabled(enable) if not enable: # Fit widget is not yet configured return fitargs, fitkwargs = self.get_fitfunc_arguments() yfit = self.fitfunc(self.x, [p.value for p in self.fitparams], *fitargs, **fitkwargs) plot = self.get_plot() if self.legend is None: self.legend = make.legend(anchor=self.legend_anchor) plot.add_item(self.legend) if self.xrange is None: self.xrange = make.range(0., 1.) plot.add_item(self.xrange) self.xrange.set_range(self.autofit_prm.xmin, self.autofit_prm.xmax) self.xrange.setVisible(self.show_xrange) if self.data_curve is None: self.data_curve = make.curve([], [], _("Data"), color="b", linewidth=2) plot.add_item(self.data_curve) self.data_curve.set_data(self.x, self.y) if self.fit_curve is None: self.fit_curve = make.curve([], [], _("Fit"), color="r", linewidth=2) plot.add_item(self.fit_curve) self.fit_curve.set_data(self.x, yfit) plot.replot() plot.disable_autoscale() def range_changed(self, xrange_obj, xmin, xmax): self.autofit_prm.xmin, self.autofit_prm.xmax = xmin, xmax self.compute_imin_imax() def toggle_xrange(self, state): self.xrange.setVisible(state) plot = self.get_plot() plot.replot() if state: plot.set_active_item(self.xrange) self.show_xrange = state def edit_parameters(self): if self.autofit_prm.edit(parent=self): self.xrange.set_range(self.autofit_prm.xmin, self.autofit_prm.xmax) plot = self.get_plot() plot.replot() self.compute_imin_imax() def compute_imin_imax(self): self.i_min = self.x.searchsorted(self.autofit_prm.xmin) self.i_max = self.x.searchsorted(self.autofit_prm.xmax, side='right') def errorfunc(self, params): x = self.x[self.i_min:self.i_max] y = self.y[self.i_min:self.i_max] fitargs, fitkwargs = self.get_fitfunc_arguments() return y - self.fitfunc(x, params, *fitargs, **fitkwargs) def autofit(self): meth = self.autofit_prm.method x0 = np.array([p.value for p in self.fitparams]) if meth == "lq": x = self.autofit_lq(x0) elif meth == "simplex": x = self.autofit_simplex(x0) elif meth == "powel": x = self.autofit_powel(x0) elif meth == "bfgs": x = self.autofit_bfgs(x0) elif meth == "l_bfgs_b": x = self.autofit_l_bfgs(x0) elif meth == "cg": x = self.autofit_cg(x0) else: return for v, p in zip(x, self.fitparams): p.value = v self.refresh() for prm in self.fitparams: prm.update() def get_norm_func(self): prm = self.autofit_prm err_norm = eval(prm.err_norm) def func(params): err = np.linalg.norm(self.errorfunc(params), err_norm) return err return func def autofit_simplex(self, x0): prm = self.autofit_prm from scipy.optimize import fmin x = fmin(self.get_norm_func(), x0, xtol=prm.xtol, ftol=prm.ftol) return x def autofit_powel(self, x0): prm = self.autofit_prm from scipy.optimize import fmin_powell x = fmin_powell(self.get_norm_func(), x0, xtol=prm.xtol, ftol=prm.ftol) return x def autofit_bfgs(self, x0): prm = self.autofit_prm from scipy.optimize import fmin_bfgs x = fmin_bfgs(self.get_norm_func(), x0, gtol=prm.gtol, norm=eval(prm.norm)) return x def autofit_l_bfgs(self, x0): prm = self.autofit_prm bounds = [(p.min, p.max) for p in self.fitparams] from scipy.optimize import fmin_l_bfgs_b x, _f, _d = fmin_l_bfgs_b(self.get_norm_func(), x0, pgtol=prm.gtol, approx_grad=1, bounds=bounds) return x def autofit_cg(self, x0): prm = self.autofit_prm from scipy.optimize import fmin_cg x = fmin_cg(self.get_norm_func(), x0, gtol=prm.gtol, norm=eval(prm.norm)) return x def autofit_lq(self, x0): prm = self.autofit_prm def func(params): err = self.errorfunc(params) return err from scipy.optimize import leastsq x, _ier = leastsq(func, x0, xtol=prm.xtol, ftol=prm.ftol) return x def get_values(self): """Convenience method to get fit parameter values""" return [param.value for param in self.fitparams]
class FitWidgetMixin(CurveWidgetMixin): def __init__(self, wintitle="guiqwt plot", icon="guiqwt.svg", toolbar=False, options=None, panels=None, param_cols=1, legend_anchor='TR', auto_fit=True): if wintitle is None: wintitle = _('Curve fitting') self.x = None self.y = None self.fitfunc = None self.fitargs = None self.fitkwargs = None self.fitparams = None self.autofit_prm = None self.data_curve = None self.fit_curve = None self.legend = None self.legend_anchor = legend_anchor self.xrange = None self.show_xrange = False self.param_cols = param_cols self.auto_fit_enabled = auto_fit self.button_list = [] # list of buttons to be disabled at startup self.fit_layout = None self.params_layout = None CurveWidgetMixin.__init__(self, wintitle=wintitle, icon=icon, toolbar=toolbar, options=options, panels=panels) self.refresh() # QWidget API -------------------------------------------------------------- def resizeEvent(self, event): QWidget.resizeEvent(self, event) self.get_plot().replot() # CurveWidgetMixin API ----------------------------------------------------- def setup_widget_layout(self): self.fit_layout = QHBoxLayout() self.params_layout = QGridLayout() params_group = create_groupbox(self, _("Fit parameters"), layout=self.params_layout) if self.auto_fit_enabled: auto_group = self.create_autofit_group() self.fit_layout.addWidget(auto_group) self.fit_layout.addWidget(params_group) self.plot_layout.addLayout(self.fit_layout, 1, 0) vlayout = QVBoxLayout(self) vlayout.addWidget(self.toolbar) vlayout.addLayout(self.plot_layout) self.setLayout(vlayout) def create_plot(self, options): CurveWidgetMixin.create_plot(self, options) for plot in self.get_plots(): plot.SIG_RANGE_CHANGED.connect(self.range_changed) # Public API --------------------------------------------------------------- def set_data(self, x, y, fitfunc=None, fitparams=None, fitargs=None, fitkwargs=None): if self.fitparams is not None and fitparams is not None: self.clear_params_layout() self.x = x self.y = y if fitfunc is not None: self.fitfunc = fitfunc if fitparams is not None: self.fitparams = fitparams if fitargs is not None: self.fitargs = fitargs if fitkwargs is not None: self.fitkwargs = fitkwargs self.autofit_prm = AutoFitParam(title=_("Automatic fitting options")) self.autofit_prm.xmin = x.min() self.autofit_prm.xmax = x.max() self.compute_imin_imax() if self.fitparams is not None and fitparams is not None: self.populate_params_layout() self.refresh() def set_fit_data(self, fitfunc, fitparams, fitargs=None, fitkwargs=None): if self.fitparams is not None: self.clear_params_layout() self.fitfunc = fitfunc self.fitparams = fitparams self.fitargs = fitargs self.fitkwargs = fitkwargs self.populate_params_layout() self.refresh() def clear_params_layout(self): for i, param in enumerate(self.fitparams): for widget in param.get_widgets(): if widget is not None: self.params_layout.removeWidget(widget) widget.hide() def populate_params_layout(self): add_fitparam_widgets_to(self.params_layout, self.fitparams, self.refresh, param_cols=self.param_cols) def create_autofit_group(self): auto_button = QPushButton(get_icon('apply.png'), _("Run"), self) auto_button.clicked.connect(self.autofit) autoprm_button = QPushButton(get_icon('settings.png'), _("Settings"), self) autoprm_button.clicked.connect(self.edit_parameters) xrange_button = QPushButton(get_icon('xrange.png'), _("Bounds"), self) xrange_button.setCheckable(True) xrange_button.toggled.connect(self.toggle_xrange) auto_layout = QVBoxLayout() auto_layout.addWidget(auto_button) auto_layout.addWidget(autoprm_button) auto_layout.addWidget(xrange_button) self.button_list += [auto_button, autoprm_button, xrange_button] return create_groupbox(self, _("Automatic fit"), layout=auto_layout) def get_fitfunc_arguments(self): """Return fitargs and fitkwargs""" fitargs = self.fitargs if self.fitargs is None: fitargs = [] fitkwargs = self.fitkwargs if self.fitkwargs is None: fitkwargs = {} return fitargs, fitkwargs def refresh(self, slider_value=None): """Refresh Fit Tool dialog box""" # Update button states enable = self.x is not None and self.y is not None \ and self.x.size > 0 and self.y.size > 0 \ and self.fitfunc is not None and self.fitparams is not None \ and len(self.fitparams) > 0 for btn in self.button_list: btn.setEnabled(enable) if not enable: # Fit widget is not yet configured return fitargs, fitkwargs = self.get_fitfunc_arguments() yfit = self.fitfunc(self.x, [p.value for p in self.fitparams], *fitargs, **fitkwargs) plot = self.get_plot() if self.legend is None: self.legend = make.legend(anchor=self.legend_anchor) plot.add_item(self.legend) if self.xrange is None: self.xrange = make.range(0., 1.) plot.add_item(self.xrange) self.xrange.set_range(self.autofit_prm.xmin, self.autofit_prm.xmax) self.xrange.setVisible(self.show_xrange) if self.data_curve is None: self.data_curve = make.curve([], [], _("Data"), color="b", linewidth=2) plot.add_item(self.data_curve) self.data_curve.set_data(self.x, self.y) if self.fit_curve is None: self.fit_curve = make.curve([], [], _("Fit"), color="r", linewidth=2) plot.add_item(self.fit_curve) self.fit_curve.set_data(self.x, yfit) plot.replot() plot.disable_autoscale() def range_changed(self, xrange_obj, xmin, xmax): self.autofit_prm.xmin, self.autofit_prm.xmax = xmin, xmax self.compute_imin_imax() def toggle_xrange(self, state): self.xrange.setVisible(state) plot = self.get_plot() plot.replot() if state: plot.set_active_item(self.xrange) self.show_xrange = state def edit_parameters(self): if self.autofit_prm.edit(parent=self): self.xrange.set_range(self.autofit_prm.xmin, self.autofit_prm.xmax) plot = self.get_plot() plot.replot() self.compute_imin_imax() def compute_imin_imax(self): self.i_min = self.x.searchsorted(self.autofit_prm.xmin) self.i_max = self.x.searchsorted(self.autofit_prm.xmax, side='right') def errorfunc(self, params): x = self.x[self.i_min:self.i_max] y = self.y[self.i_min:self.i_max] fitargs, fitkwargs = self.get_fitfunc_arguments() return y - self.fitfunc(x, params, *fitargs, **fitkwargs) def autofit(self): meth = self.autofit_prm.method x0 = np.array([p.value for p in self.fitparams]) if meth == "lq": x = self.autofit_lq(x0) elif meth=="simplex": x = self.autofit_simplex(x0) elif meth=="powel": x = self.autofit_powel(x0) elif meth=="bfgs": x = self.autofit_bfgs(x0) elif meth=="l_bfgs_b": x = self.autofit_l_bfgs(x0) elif meth=="cg": x = self.autofit_cg(x0) else: return for v, p in zip(x, self.fitparams): p.value = v self.refresh() for prm in self.fitparams: prm.update() def get_norm_func(self): prm = self.autofit_prm err_norm = eval(prm.err_norm) def func(params): err = np.linalg.norm(self.errorfunc(params), err_norm) return err return func def autofit_simplex(self, x0): prm = self.autofit_prm from scipy.optimize import fmin x = fmin(self.get_norm_func(), x0, xtol=prm.xtol, ftol=prm.ftol) return x def autofit_powel(self, x0): prm = self.autofit_prm from scipy.optimize import fmin_powell x = fmin_powell(self.get_norm_func(), x0, xtol=prm.xtol, ftol=prm.ftol) return x def autofit_bfgs(self, x0): prm = self.autofit_prm from scipy.optimize import fmin_bfgs x = fmin_bfgs(self.get_norm_func(), x0, gtol=prm.gtol, norm=eval(prm.norm)) return x def autofit_l_bfgs(self, x0): prm = self.autofit_prm bounds = [(p.min, p.max) for p in self.fitparams] from scipy.optimize import fmin_l_bfgs_b x, _f, _d = fmin_l_bfgs_b(self.get_norm_func(), x0, pgtol=prm.gtol, approx_grad=1, bounds=bounds) return x def autofit_cg(self, x0): prm = self.autofit_prm from scipy.optimize import fmin_cg x = fmin_cg(self.get_norm_func(), x0, gtol=prm.gtol, norm=eval(prm.norm)) return x def autofit_lq(self, x0): prm = self.autofit_prm def func(params): err = self.errorfunc(params) return err from scipy.optimize import leastsq x, _ier = leastsq(func, x0, xtol=prm.xtol, ftol=prm.ftol) return x def get_values(self): """Convenience method to get fit parameter values""" return [param.value for param in self.fitparams]