Пример #1
0
class DataSetShowGroupBox(QGroupBox):
    """Group box widget showing a read-only DataSet"""
    def __init__(self, label, klass, wordwrap=False, **kwargs):
        QGroupBox.__init__(self, label)
        self.klass = klass
        self.dataset = klass(**kwargs)
        self.layout = QVBoxLayout()
        if self.dataset.get_comment():
            label = QLabel(self.dataset.get_comment())
            label.setWordWrap(wordwrap)
            self.layout.addWidget(label)
        self.grid_layout = QGridLayout()
        self.layout.addLayout(self.grid_layout)
        self.setLayout(self.layout)
        self.edit = self.get_edit_layout()
        
    def get_edit_layout(self):
        """Return edit layout"""
        return DataSetShowLayout(self, self.dataset, self.grid_layout) 

    def get(self):
        """Update group box contents from data item values"""
        for widget in self.edit.widgets:
            widget.build_mode = True
            widget.get()
            widget.build_mode = False
Пример #2
0
    def __init__(self, wintitle):
        super(Window, self).__init__()
        self.default_tool = None
        self.plots = []
        self.itemlist = PlotItemList(None)
        self.contrast = ContrastAdjustment(None)
        self.xcsw = XCrossSection(None)
        self.ycsw = YCrossSection(None)

        self.manager = PlotManager(self)
        self.toolbar = QToolBar(_("Tools"), self)
        self.manager.add_toolbar(self.toolbar, "default")
        self.toolbar.setMovable(True)
        self.toolbar.setFloatable(True)
        self.addToolBar(Qt.TopToolBarArea, self.toolbar)

        frame = QFrame(self)
        self.setCentralWidget(frame)
        self.layout = QGridLayout()
        layout = QVBoxLayout(frame)
        frame.setLayout(layout)
        layout.addLayout(self.layout)
        self.frame = frame

        self.setWindowTitle(wintitle)
        self.setWindowIcon(get_icon('plotpy.svg'))
Пример #3
0
    def __init__(self, wintitle):
        super(Window, self).__init__()
        self.default_tool = None
        self.plots = []
        self.itemlist = PlotItemList(None)
        self.contrast = ContrastAdjustment(None)
        self.xcsw = XCrossSection(None)
        self.ycsw = YCrossSection(None)
        
        self.manager = PlotManager(self)
        self.toolbar = QToolBar(_("Tools"), self)
        self.manager.add_toolbar(self.toolbar, "default")
        self.toolbar.setMovable(True)
        self.toolbar.setFloatable(True)
        self.addToolBar(Qt.TopToolBarArea, self.toolbar)

        frame = QFrame(self)
        self.setCentralWidget(frame)
        self.layout = QGridLayout()
        layout = QVBoxLayout(frame)
        frame.setLayout(layout)
        layout.addLayout(self.layout)
        self.frame = frame

        self.setWindowTitle(wintitle)
        self.setWindowIcon(get_icon('plotpy.svg'))
Пример #4
0
class DataSetShowGroupBox(QGroupBox):
    """Group box widget showing a read-only DataSet"""
    def __init__(self, label, klass, wordwrap=False, **kwargs):
        QGroupBox.__init__(self, label)
        self.klass = klass
        self.dataset = klass(**kwargs)
        self.layout = QVBoxLayout()
        if self.dataset.get_comment():
            label = QLabel(self.dataset.get_comment())
            label.setWordWrap(wordwrap)
            self.layout.addWidget(label)
        self.grid_layout = QGridLayout()
        self.layout.addLayout(self.grid_layout)
        self.setLayout(self.layout)
        self.edit = self.get_edit_layout()

    def get_edit_layout(self):
        """Return edit layout"""
        return DataSetShowLayout(self, self.dataset, self.grid_layout)

    def get(self):
        """Update group box contents from data item values"""
        for widget in self.edit.widgets:
            widget.build_mode = True
            widget.get()
            widget.build_mode = False
Пример #5
0
 def __init__(self, label, klass, wordwrap=False, **kwargs):
     QGroupBox.__init__(self, label)
     self.klass = klass
     self.dataset = klass(**kwargs)
     self.layout = QVBoxLayout()
     if self.dataset.get_comment():
         label = QLabel(self.dataset.get_comment())
         label.setWordWrap(wordwrap)
         self.layout.addWidget(label)
     self.grid_layout = QGridLayout()
     self.layout.addLayout(self.grid_layout)
     self.setLayout(self.layout)
     self.edit = self.get_edit_layout()
Пример #6
0
 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)
Пример #7
0
 def __init__(self, item, parent_layout):
     super(ChoiceWidget, self).__init__(item, parent_layout)
     self._first_call = True
     self.is_radio = item.get_prop_value("display", "radio")
     self.store = self.item.get_prop("display", "store", None)
     if self.is_radio:
         self.group = QGroupBox()
         self.group.setToolTip(item.get_help())
         self.vbox = QVBoxLayout()
         self.group.setLayout(self.vbox)
         self._buttons = []
     else:
         self.combobox = self.group = QComboBox()
         self.combobox.setToolTip(item.get_help())
         self.combobox.currentIndexChanged.connect(self.index_changed)
Пример #8
0
 def setup_widget(self, title):
     #---Create the plot widget:
     self.plot = CurvePlot(self)
     self.curve_item = make.curve([], [], color='b')
     self.plot.add_item(self.curve_item)
     self.plot.set_antialiasing(True)
     #---
     
     button = QPushButton("Test filter: %s" % title)
     button.clicked.connect(self.process_data)
     vlayout = QVBoxLayout()
     vlayout.addWidget(self.plot)
     vlayout.addWidget(button)
     self.setLayout(vlayout)
     
     self.update_curve()
Пример #9
0
 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)
Пример #10
0
    def __init__(self,
                 instance,
                 icon='',
                 parent=None,
                 apply=None,
                 wordwrap=True,
                 size=None):
        QDialog.__init__(self, parent)
        self.wordwrap = wordwrap
        self.apply_func = apply
        self.layout = QVBoxLayout()
        if instance.get_comment():
            label = QLabel(instance.get_comment())
            label.setWordWrap(wordwrap)
            self.layout.addWidget(label)
        self.instance = instance
        self.edit_layout = []

        self.setup_instance(instance)

        if apply is not None:
            apply_button = QDialogButtonBox.Apply
        else:
            apply_button = QDialogButtonBox.NoButton
        bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel
                                | apply_button)
        self.bbox = bbox
        bbox.accepted.connect(self.accept)
        bbox.rejected.connect(self.reject)
        bbox.clicked.connect(self.button_clicked)
        self.layout.addWidget(bbox)

        self.setLayout(self.layout)

        if parent is None:
            if not isinstance(icon, QIcon):
                icon = get_icon(icon, default="plotpy.svg")
            self.setWindowIcon(icon)

        self.setModal(True)
        self.setWindowTitle(instance.get_title())

        if size is not None:
            if isinstance(size, QSize):
                self.resize(size)
            else:
                self.resize(*size)
Пример #11
0
 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)
     
     if CodeEditor is None:
         self.editor = QTextEdit(self)
         self.editor.setFont(font)
     else:
         self.editor = CodeEditor(self)
         self.editor.setup_editor(linenumbers=True, font=font)
         self.editor.set_color_scheme("Spyder")
     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)
Пример #12
0
    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)
Пример #13
0
 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)
Пример #14
0
 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'))
Пример #15
0
 def __init__(self, label, klass, wordwrap=False, **kwargs):
     QGroupBox.__init__(self, label)
     self.klass = klass
     self.dataset = klass(**kwargs)
     self.layout = QVBoxLayout()
     if self.dataset.get_comment():
         label = QLabel(self.dataset.get_comment())
         label.setWordWrap(wordwrap)
         self.layout.addWidget(label)
     self.grid_layout = QGridLayout()
     self.layout.addLayout(self.grid_layout)
     self.setLayout(self.layout)
     self.edit = self.get_edit_layout()
Пример #16
0
 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'))
Пример #17
0
 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)
Пример #18
0
 def __init__(self, item, parent_layout):
     super(ChoiceWidget, self).__init__(item, parent_layout)
     self._first_call = True
     self.is_radio = item.get_prop_value("display", "radio")
     self.store = self.item.get_prop("display", "store", None)
     if self.is_radio:
         self.group = QGroupBox()
         self.group.setToolTip(item.get_help())
         self.vbox = QVBoxLayout()
         self.group.setLayout(self.vbox)
         self._buttons = []
     else:
         self.combobox = self.group = QComboBox()
         self.combobox.setToolTip(item.get_help())
         self.combobox.currentIndexChanged.connect(self.index_changed)
Пример #19
0
 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)
Пример #20
0
    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)

        if CodeEditor is None:
            self.editor = QTextEdit(self)
            self.editor.setFont(font)
        else:
            self.editor = CodeEditor(self)
            self.editor.setup_editor(linenumbers=True, font=font)
            self.editor.set_color_scheme("Spyder")
        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)
Пример #21
0
    def __init__(self, instance, icon='', parent=None, apply=None,
                 wordwrap=True, size=None):
        QDialog.__init__(self, parent)
        self.wordwrap = wordwrap
        self.apply_func = apply
        self.layout = QVBoxLayout()
        if instance.get_comment():
            label = QLabel(instance.get_comment())
            label.setWordWrap(wordwrap)
            self.layout.addWidget(label)
        self.instance = instance
        self.edit_layout = [  ]

        self.setup_instance( instance )

        if apply is not None:
            apply_button = QDialogButtonBox.Apply
        else:
            apply_button = QDialogButtonBox.NoButton
        bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel
                                | apply_button )
        self.bbox = bbox
        bbox.accepted.connect(self.accept)
        bbox.rejected.connect(self.reject)
        bbox.clicked.connect(self.button_clicked)
        self.layout.addWidget(bbox)
        
        self.setLayout(self.layout)
        
        if parent is None:
            if not isinstance(icon, QIcon):
                icon = get_icon(icon, default="plotpy.svg")
            self.setWindowIcon(icon)
        
        self.setModal(True)
        self.setWindowTitle(instance.get_title())
        
        if size is not None:
            if isinstance(size, QSize):
                self.resize(size)
            else:
                self.resize(*size)
Пример #22
0
    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)
Пример #23
0
    def setup_widget(self, title):
        #---Create the plot widget:
        self.plot = CurvePlot(self)
        self.curve_item = make.curve([], [], color='b')
        self.plot.add_item(self.curve_item)
        self.plot.set_antialiasing(True)
        #---

        button = QPushButton("Test filter: %s" % title)
        button.clicked.connect(self.process_data)
        vlayout = QVBoxLayout()
        vlayout.addWidget(self.plot)
        vlayout.addWidget(button)
        self.setLayout(vlayout)

        self.update_curve()
Пример #24
0
    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)
Пример #25
0
 def setup_instance(self, instance):
     """Override DataSetEditDialog method"""
     from plotpy.dataset.datatypes import DataSetGroup
     assert isinstance(instance, DataSetGroup)
     tabs = QTabWidget()
     #        tabs.setUsesScrollButtons(False)
     self.layout.addWidget(tabs)
     for dataset in instance.datasets:
         layout = QVBoxLayout()
         layout.setAlignment(Qt.AlignTop)
         if dataset.get_comment():
             label = QLabel(dataset.get_comment())
             label.setWordWrap(self.wordwrap)
             layout.addWidget(label)
         grid = QGridLayout()
         self.edit_layout.append(self.layout_factory(dataset, grid))
         layout.addLayout(grid)
         page = QWidget()
         page.setLayout(layout)
         if dataset.get_icon():
             tabs.addTab(page, get_icon(dataset.get_icon()),
                         dataset.get_title())
         else:
             tabs.addTab(page, dataset.get_title())
Пример #26
0
    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)
Пример #27
0
    def setup_instance(self, instance):
        """Override DataSetEditDialog method"""
        from plotpy.dataset.datatypes import DataSetGroup
        assert isinstance(instance, DataSetGroup)
        tabs = QTabWidget()
#        tabs.setUsesScrollButtons(False)
        self.layout.addWidget(tabs)
        for dataset in instance.datasets:
            layout = QVBoxLayout()
            layout.setAlignment(Qt.AlignTop)
            if dataset.get_comment():
                label = QLabel(dataset.get_comment())
                label.setWordWrap(self.wordwrap)
                layout.addWidget(label)
            grid = QGridLayout()
            self.edit_layout.append( self.layout_factory(dataset, grid) )
            layout.addLayout(grid)
            page = QWidget()
            page.setLayout(layout)
            if dataset.get_icon():
                tabs.addTab( page, get_icon(dataset.get_icon()),
                             dataset.get_title() )
            else:
                tabs.addTab( page, dataset.get_title() )
Пример #28
0
class DataSetEditDialog(QDialog):
    """
    Dialog box for DataSet editing
    """
    def __init__(self,
                 instance,
                 icon='',
                 parent=None,
                 apply=None,
                 wordwrap=True,
                 size=None):
        QDialog.__init__(self, parent)
        self.wordwrap = wordwrap
        self.apply_func = apply
        self.layout = QVBoxLayout()
        if instance.get_comment():
            label = QLabel(instance.get_comment())
            label.setWordWrap(wordwrap)
            self.layout.addWidget(label)
        self.instance = instance
        self.edit_layout = []

        self.setup_instance(instance)

        if apply is not None:
            apply_button = QDialogButtonBox.Apply
        else:
            apply_button = QDialogButtonBox.NoButton
        bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel
                                | apply_button)
        self.bbox = bbox
        bbox.accepted.connect(self.accept)
        bbox.rejected.connect(self.reject)
        bbox.clicked.connect(self.button_clicked)
        self.layout.addWidget(bbox)

        self.setLayout(self.layout)

        if parent is None:
            if not isinstance(icon, QIcon):
                icon = get_icon(icon, default="plotpy.svg")
            self.setWindowIcon(icon)

        self.setModal(True)
        self.setWindowTitle(instance.get_title())

        if size is not None:
            if isinstance(size, QSize):
                self.resize(size)
            else:
                self.resize(*size)

    def button_clicked(self, button):
        role = self.bbox.buttonRole(button)
        if role == QDialogButtonBox.ApplyRole and self.apply_func is not None:
            if self.check():
                for edl in self.edit_layout:
                    edl.accept_changes()
                self.apply_func(self.instance)

    def setup_instance(self, instance):
        """Construct main layout"""
        grid = QGridLayout()
        grid.setAlignment(Qt.AlignTop)
        self.layout.addLayout(grid)
        self.edit_layout.append(self.layout_factory(instance, grid))

    def layout_factory(self, instance, grid):
        """A factory method that produces instances of DataSetEditLayout
        
        or derived classes (see DataSetShowDialog)
        """
        return DataSetEditLayout(self, instance, grid)

    def child_title(self, item):
        """Return data item title combined with QApplication title"""
        app_name = QApplication.applicationName()
        if not app_name:
            app_name = self.instance.get_title()
        return "%s - %s" % (app_name, item.label())

    def check(self):
        is_ok = True
        for edl in self.edit_layout:
            if not edl.check_all_values():
                is_ok = False
        if not is_ok:
            QMessageBox.warning(self, self.instance.get_title(),
                        _("Some required entries are incorrect")+"\n"+\
                        _("Please check highlighted fields."))
            return False
        return True

    def accept(self):
        """Validate inputs"""
        if self.check():
            for edl in self.edit_layout:
                edl.accept_changes()
            QDialog.accept(self)
Пример #29
0
class DataSetEditDialog(QDialog):
    """
    Dialog box for DataSet editing
    """
    def __init__(self, instance, icon='', parent=None, apply=None,
                 wordwrap=True, size=None):
        QDialog.__init__(self, parent)
        self.wordwrap = wordwrap
        self.apply_func = apply
        self.layout = QVBoxLayout()
        if instance.get_comment():
            label = QLabel(instance.get_comment())
            label.setWordWrap(wordwrap)
            self.layout.addWidget(label)
        self.instance = instance
        self.edit_layout = [  ]

        self.setup_instance( instance )

        if apply is not None:
            apply_button = QDialogButtonBox.Apply
        else:
            apply_button = QDialogButtonBox.NoButton
        bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel
                                | apply_button )
        self.bbox = bbox
        bbox.accepted.connect(self.accept)
        bbox.rejected.connect(self.reject)
        bbox.clicked.connect(self.button_clicked)
        self.layout.addWidget(bbox)
        
        self.setLayout(self.layout)
        
        if parent is None:
            if not isinstance(icon, QIcon):
                icon = get_icon(icon, default="plotpy.svg")
            self.setWindowIcon(icon)
        
        self.setModal(True)
        self.setWindowTitle(instance.get_title())
        
        if size is not None:
            if isinstance(size, QSize):
                self.resize(size)
            else:
                self.resize(*size)

    def button_clicked(self, button):
        role = self.bbox.buttonRole(button)
        if role==QDialogButtonBox.ApplyRole and self.apply_func is not None:
            if self.check():
                for edl in self.edit_layout:
                    edl.accept_changes()
                self.apply_func(self.instance)
    
    def setup_instance(self, instance):
        """Construct main layout"""
        grid = QGridLayout()
        grid.setAlignment(Qt.AlignTop)
        self.layout.addLayout(grid)
        self.edit_layout.append( self.layout_factory( instance, grid) )
        
    def layout_factory(self, instance, grid ):
        """A factory method that produces instances of DataSetEditLayout
        
        or derived classes (see DataSetShowDialog)
        """
        return DataSetEditLayout( self, instance, grid )

    def child_title(self, item):
        """Return data item title combined with QApplication title"""
        app_name = QApplication.applicationName()
        if not app_name:
            app_name = self.instance.get_title()
        return "%s - %s" % ( app_name, item.label() )

    def check(self):
        is_ok = True
        for edl in self.edit_layout:
            if not edl.check_all_values():
                is_ok = False
        if not is_ok:
            QMessageBox.warning(self, self.instance.get_title(),
                        _("Some required entries are incorrect")+"\n"+\
                        _("Please check highlighted fields."))
            return False
        return True

    def accept(self):
        """Validate inputs"""
        if self.check():
            for edl in self.edit_layout:
                edl.accept_changes()
            QDialog.accept(self)
Пример #30
0
class ChoiceWidget(AbstractDataSetWidget):
    """
    Choice item widget
    """
    def __init__(self, item, parent_layout):
        super(ChoiceWidget, self).__init__(item, parent_layout)
        self._first_call = True
        self.is_radio = item.get_prop_value("display", "radio")
        self.store = self.item.get_prop("display", "store", None)
        if self.is_radio:
            self.group = QGroupBox()
            self.group.setToolTip(item.get_help())
            self.vbox = QVBoxLayout()
            self.group.setLayout(self.vbox)
            self._buttons = []
        else:
            self.combobox = self.group = QComboBox()
            self.combobox.setToolTip(item.get_help())
            self.combobox.currentIndexChanged.connect(self.index_changed)

    def index_changed(self, index):
        if self.store:
            self.store.set(self.item.instance, self.item.item, self.value())
            self.parent_layout.refresh_widgets()
        cb = self.item.get_prop_value("display", "callback", None)
        if cb is not None:
            if self.build_mode:
                self.set()
            else:
                self.parent_layout.update_dataitems()
            cb(self.item.instance, self.item.item, self.value())
            self.parent_layout.update_widgets(except_this_one=self)

    def initialize_widget(self):
        if self.is_radio:
            for button in self._buttons:
                button.toggled.disconnect(self.index_changed)
                self.vbox.removeWidget(button)
                button.deleteLater()
            self._buttons = []
        else:
            self.combobox.blockSignals(True)
            while self.combobox.count():
                self.combobox.removeItem(0)
        _choices = self.item.get_prop_value("data", "choices")
        for key, lbl, img in _choices:
            if self.is_radio:
                button = QRadioButton(lbl, self.group)
            if img:
                if is_text_string(img):
                    if not osp.isfile(img):
                        img = get_image_file_path(img)
                    img = QIcon(img)
                elif isinstance(img, collections.Callable):
                    img = img(key)
                if self.is_radio:
                    button.setIcon(img)
                else:
                    self.combobox.addItem(img, lbl)
            elif not self.is_radio:
                self.combobox.addItem(lbl)
            if self.is_radio:
                self._buttons.append(button)
                self.vbox.addWidget(button)
                button.toggled.connect(self.index_changed)
        if not self.is_radio:
            self.combobox.blockSignals(False)

    def set_widget_value(self, idx):
        if self.is_radio:
            for button in self._buttons:
                button.blockSignals(True)
            self._buttons[idx].setChecked(True)
            for button in self._buttons:
                button.blockSignals(False)
        else:
            self.combobox.blockSignals(True)
            self.combobox.setCurrentIndex(idx)
            self.combobox.blockSignals(False)

    def get_widget_value(self):
        if self.is_radio:
            for index, widget in enumerate(self._buttons):
                if widget.isChecked():
                    return index
        else:
            return self.combobox.currentIndex()

    def get(self):
        """Override AbstractDataSetWidget method"""
        self.initialize_widget()
        value = self.item.get()
        if value is not None:
            idx = 0
            _choices = self.item.get_prop_value("data", "choices")
            for key, _val, _img in _choices:
                if key == value:
                    break
                idx += 1
            self.set_widget_value(idx)
            if self._first_call:
                self.index_changed(idx)
                self._first_call = False

    def set(self):
        """Override AbstractDataSetWidget method"""
        try:
            value = self.value()
        except IndexError:
            return
        self.item.set(value)

    def value(self):
        index = self.get_widget_value()
        choices = self.item.get_prop_value("data", "choices")
        return choices[index][0]
Пример #31
0
    def __init__(self,
                 parent,
                 new_size,
                 old_size,
                 text="",
                 keep_original_size=False):
        QDialog.__init__(self, parent)

        intfunc = lambda tup: [int(val) for val in tup]
        if intfunc(new_size) == intfunc(old_size):
            self.keep_original_size = True
        else:
            self.keep_original_size = keep_original_size
        self.width, self.height = new_size
        self.old_width, self.old_height = old_size
        self.ratio = self.width / self.height

        layout = QVBoxLayout()
        self.setLayout(layout)

        formlayout = QFormLayout()
        layout.addLayout(formlayout)

        if text:
            label = QLabel(text)
            label.setAlignment(Qt.AlignHCenter)
            formlayout.addRow(label)

        self.w_edit = w_edit = QLineEdit(self)
        w_valid = QIntValidator(w_edit)
        w_valid.setBottom(1)
        w_edit.setValidator(w_valid)

        self.h_edit = h_edit = QLineEdit(self)
        h_valid = QIntValidator(h_edit)
        h_valid.setBottom(1)
        h_edit.setValidator(h_valid)

        zbox = QCheckBox(_("Original size"), self)

        formlayout.addRow(_("Width (pixels)"), w_edit)
        formlayout.addRow(_("Height (pixels)"), h_edit)
        formlayout.addRow('', zbox)

        formlayout.addRow(_("Original size:"), QLabel("%d x %d" % old_size))
        self.z_label = QLabel()
        formlayout.addRow(_("Zoom factor:"), self.z_label)

        # Button box
        self.bbox = bbox = QDialogButtonBox(QDialogButtonBox.Ok
                                            | QDialogButtonBox.Cancel)
        bbox.accepted.connect(self.accept)
        bbox.rejected.connect(self.reject)
        layout.addWidget(bbox)

        self.w_edit.setText(str(self.width))
        self.h_edit.setText(str(self.height))
        self.update_widgets()

        self.setWindowTitle(_("Resize"))

        w_edit.textChanged.connect(self.width_changed)
        h_edit.textChanged.connect(self.height_changed)
        zbox.toggled.connect(self.toggled_no_zoom)
        zbox.setChecked(self.keep_original_size)
Пример #32
0
    def __init__(self, parent, new_size, old_size, text="",
                 keep_original_size=False):
        QDialog.__init__(self, parent)
        
        intfunc = lambda tup: [int(val) for val in tup]
        if intfunc(new_size) == intfunc(old_size):
            self.keep_original_size = True
        else:
            self.keep_original_size = keep_original_size
        self.width, self.height = new_size
        self.old_width, self.old_height = old_size
        self.ratio = self.width/self.height

        layout = QVBoxLayout()
        self.setLayout(layout)
        
        formlayout = QFormLayout()
        layout.addLayout(formlayout)
        
        if text:
            label = QLabel(text)
            label.setAlignment(Qt.AlignHCenter)
            formlayout.addRow(label)
        
        self.w_edit = w_edit = QLineEdit(self)
        w_valid = QIntValidator(w_edit)
        w_valid.setBottom(1)
        w_edit.setValidator(w_valid)
                     
        self.h_edit = h_edit = QLineEdit(self)
        h_valid = QIntValidator(h_edit)
        h_valid.setBottom(1)
        h_edit.setValidator(h_valid)
        
        zbox = QCheckBox(_("Original size"), self)

        formlayout.addRow(_("Width (pixels)"), w_edit)
        formlayout.addRow(_("Height (pixels)"), h_edit)
        formlayout.addRow('', zbox)
        
        formlayout.addRow(_("Original size:"), QLabel("%d x %d" % old_size))
        self.z_label = QLabel()
        formlayout.addRow(_("Zoom factor:"), self.z_label)
        
        # Button box
        self.bbox = bbox = QDialogButtonBox(QDialogButtonBox.Ok|
                                            QDialogButtonBox.Cancel)
        bbox.accepted.connect(self.accept)
        bbox.rejected.connect(self.reject)
        layout.addWidget(bbox)

        self.w_edit.setText(str(self.width))
        self.h_edit.setText(str(self.height))
        self.update_widgets()
        
        self.setWindowTitle(_("Resize"))
        
        w_edit.textChanged.connect(self.width_changed)
        h_edit.textChanged.connect(self.height_changed)
        zbox.toggled.connect(self.toggled_no_zoom)
        zbox.setChecked(self.keep_original_size)
Пример #33
0
 def setup_widget(self):
     toolbar = self.toolbar
     toolbar.setOrientation(Qt.Horizontal)
     layout = QVBoxLayout()
     if self.xsection_pos == "top":
         layout.addSpacerItem(self.spacer)
     layout.addWidget(toolbar)
     layout.addWidget(self.cs_plot)
     if self.xsection_pos == "bottom":
         layout.addSpacerItem(self.spacer)
     layout.setContentsMargins(0, 0, 0, 0)
     self.setLayout(layout)
Пример #34
0
class ChoiceWidget(AbstractDataSetWidget):
    """
    Choice item widget
    """
    def __init__(self, item, parent_layout):
        super(ChoiceWidget, self).__init__(item, parent_layout)
        self._first_call = True
        self.is_radio = item.get_prop_value("display", "radio")
        self.store = self.item.get_prop("display", "store", None)
        if self.is_radio:
            self.group = QGroupBox()
            self.group.setToolTip(item.get_help())
            self.vbox = QVBoxLayout()
            self.group.setLayout(self.vbox)
            self._buttons = []
        else:
            self.combobox = self.group = QComboBox()
            self.combobox.setToolTip(item.get_help())
            self.combobox.currentIndexChanged.connect(self.index_changed)
        
    def index_changed(self, index):
        if self.store:
            self.store.set(self.item.instance, self.item.item, self.value())
            self.parent_layout.refresh_widgets()
        cb = self.item.get_prop_value("display", "callback", None)
        if cb is not None:
            if self.build_mode:
                self.set()
            else:
                self.parent_layout.update_dataitems()
            cb(self.item.instance, self.item.item, self.value())
            self.parent_layout.update_widgets(except_this_one=self)
    
    def initialize_widget(self):
        if self.is_radio:
            for button in self._buttons:
                button.toggled.disconnect(self.index_changed)
                self.vbox.removeWidget(button)
                button.deleteLater()
            self._buttons = []
        else:
            self.combobox.blockSignals(True)
            while self.combobox.count():
                self.combobox.removeItem(0)
        _choices = self.item.get_prop_value("data", "choices")
        for key, lbl, img in _choices:
            if self.is_radio:
                button = QRadioButton(lbl, self.group)
            if img:
                if is_text_string(img):
                    if not osp.isfile(img):
                        img = get_image_file_path(img)
                    img = QIcon(img)
                elif isinstance(img, collections.Callable):
                    img = img(key)
                if self.is_radio:
                    button.setIcon(img)
                else:
                    self.combobox.addItem(img, lbl)
            elif not self.is_radio:
                self.combobox.addItem(lbl)
            if self.is_radio:
                self._buttons.append(button)
                self.vbox.addWidget(button)
                button.toggled.connect(self.index_changed)
        if not self.is_radio:
            self.combobox.blockSignals(False)

    def set_widget_value(self, idx):
        if self.is_radio:
            for button in self._buttons:
                button.blockSignals(True)
            self._buttons[idx].setChecked(True)
            for button in self._buttons:
                button.blockSignals(False)
        else:
            self.combobox.blockSignals(True)
            self.combobox.setCurrentIndex(idx)
            self.combobox.blockSignals(False)
    
    def get_widget_value(self):
        if self.is_radio:
            for index, widget in enumerate(self._buttons):
                if widget.isChecked():
                    return index
        else:
            return self.combobox.currentIndex()

    def get(self):
        """Override AbstractDataSetWidget method"""
        self.initialize_widget()
        value = self.item.get()
        if value is not None:
            idx = 0
            _choices = self.item.get_prop_value("data", "choices")
            for key, _val, _img in _choices:
                if key == value:
                    break
                idx += 1
            self.set_widget_value(idx)
            if self._first_call:
                self.index_changed(idx)
                self._first_call = False
        
    def set(self):
        """Override AbstractDataSetWidget method"""
        try:
            value = self.value()
        except IndexError:
            return
        self.item.set(value)

    def value(self):
        index = self.get_widget_value()
        choices = self.item.get_prop_value("data", "choices")
        return choices[index][0]