Example #1
0
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)    
Example #2
0
class DataSetShowWidget(AbstractDataSetWidget):
    """Read-only base widget"""
    READ_ONLY = True
    def __init__(self, item, parent_layout):
        AbstractDataSetWidget.__init__(self, item, parent_layout)
        self.group = QLabel()
        wordwrap = item.get_prop_value("display", "wordwrap", False)
        self.group.setWordWrap(wordwrap)
        self.group.setToolTip(item.get_help())
        self.group.setStyleSheet( LABEL_CSS )
        self.group.setTextInteractionFlags(Qt.TextSelectableByMouse)
        #self.group.setEnabled(False)

    def get(self):
        """Override AbstractDataSetWidget method"""
        self.set_state()
        text = self.item.get_string_value()
        self.group.setText(text)

    def set(self):
        """Read only..."""
        pass
Example #3
0
class DataSetShowWidget(AbstractDataSetWidget):
    """Read-only base widget"""
    READ_ONLY = True
    def __init__(self, item, parent_layout):
        AbstractDataSetWidget.__init__(self, item, parent_layout)
        self.group = QLabel()
        wordwrap = item.get_prop_value("display", "wordwrap", False)
        self.group.setWordWrap(wordwrap)
        self.group.setToolTip(item.get_help())
        self.group.setStyleSheet( LABEL_CSS )
        self.group.setTextInteractionFlags(Qt.TextSelectableByMouse)
        #self.group.setEnabled(False)

    def get(self):
        """Override AbstractDataSetWidget method"""
        self.set_state()
        text = self.item.get_string_value()
        self.group.setText(text)

    def set(self):
        """Read only..."""
        pass
Example #4
0
class AbstractDataSetWidget(object):
    """
    Base class for 'widgets' handled by `DataSetEditLayout` and it's derived 
    classes.
    
    This is a generic representation of an input (or display) widget that
    has a label and one or more entry field.
    
    `DataSetEditLayout` uses a registry of *Item* to *Widget* mapping in order 
    to automatically create a GUI for a `DataSet` structure
    """
    READ_ONLY = False
    def __init__(self, item, parent_layout):
        """Derived constructors should create the necessary widgets
        The base class keeps a reference to item and parent 
        """
        self.item = item
        self.parent_layout = parent_layout
        self.group = None # Layout/Widget grouping items
        self.label = None
        self.build_mode = False

    def place_label(self, layout, row, column):
        """
        Place item label on layout at specified position (row, column)
        """
        label_text = self.item.get_prop_value("display", "label")
        unit = self.item.get_prop_value("display", "unit", '')
        if unit and not self.READ_ONLY:
            label_text += (' (%s)' % unit)
        self.label = QLabel(label_text)
        self.label.setToolTip(self.item.get_help())
        layout.addWidget(self.label, row, column)

    def place_on_grid(self, layout, row, label_column, widget_column,
                      row_span=1, column_span=1):
        """
        Place widget on layout at specified position
        """
        self.place_label(layout, row, label_column)
        layout.addWidget(self.group, row, widget_column, row_span, column_span)
    
    def is_active(self):
        """
        Return True if associated item is active
        """
        return self.item.get_prop_value("display", "active", True)
    
    def check(self):
        """
        Item validator
        """
        return True
    
    def set(self):
        """
        Update data item value from widget contents
        """
        # XXX: consider using item.set instead of item.set_from_string...
        self.item.set_from_string(self.value())
    
    def get(self):
        """
        Update widget contents from data item value
        """
        pass

    def value(self):
        """
        Returns the widget's current value
        """
        return None

    def set_state(self):
        """
        Update the visual status of the widget
        """
        active = self.is_active()
        if self.group:
            self.group.setEnabled(active)
        if self.label:
            self.label.setEnabled(active)