Exemplo n.º 1
0
    def setupUi(self, parent):
        self.resize(275, 172)
        self.setWindowTitle('Convert units')
        self.layout = QVBoxLayout(parent)
        self.layout.setSizeConstraint(QLayout.SetFixedSize)
        align = (Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter)

        self.layout1 = QHBoxLayout()
        self.label1 = QLabel()
        self.label1.setMinimumSize(QSize(100, 0))
        self.label1.setText('Convert from:')
        self.label1.setAlignment(align)

        self.layout1.addWidget(self.label1)
        self.source_units = QLineEdit()
        self.source_units.setReadOnly(True)
        self.layout1.addWidget(self.source_units)

        self.layout.addLayout(self.layout1)

        self.layout2 = QHBoxLayout()
        self.label2 = QLabel()
        self.label2.setMinimumSize(QSize(100, 0))
        self.label2.setText('to:')
        self.label2.setAlignment(align)
        self.layout2.addWidget(self.label2)

        self.destination_units = QLineEdit()
        self.layout2.addWidget(self.destination_units)

        self.layout.addLayout(self.layout2)

        self.message = QLabel()
        self.message.setText('')
        self.message.setAlignment(Qt.AlignCenter)

        self.layout.addWidget(self.message)

        self.buttonBox = QDialogButtonBox()
        self.buttonBox.setOrientation(Qt.Horizontal)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Ok)
        self.layout.addWidget(self.buttonBox)
        self.buttonBox.setEnabled(False)

        self.buttonBox.accepted.connect(self.accept)
        self.destination_units.textChanged.connect(self.check)

        self.setLayout(self.layout)
        self.destination_units.setFocus()
Exemplo n.º 2
0
    def __init__( self, parent ):
        QScrollArea.__init__(self, parent)

        self.setFrameShape(QScrollArea.NoFrame)
        self.setAutoFillBackground(False)
        self.setWidgetResizable(True)
        self.setMouseTracking(True)
        #self.verticalScrollBar().setMaximumWidth(10)

        widget = QWidget(self)

        # define custom properties
        self._rolloutStyle = AccordionWidget.Rounded
        self._dragDropMode = AccordionWidget.NoDragDrop
        self._scrolling = False
        self._scrollInitY = 0
        self._scrollInitVal = 0
        self._itemClass = AccordionItem

        layout = QVBoxLayout()
        layout.setContentsMargins(2, 2, 2, 2)
        layout.setSpacing(2)
        layout.addStretch(1)

        widget.setLayout(layout)

        self.setWidget(widget)
Exemplo n.º 3
0
    def __init__( self, accordion, title, widget ):
        QGroupBox.__init__(self, accordion)

        # create the layout
        layout = QVBoxLayout()
        layout.setContentsMargins(6, 6, 6, 6)
        layout.setSpacing(0)
        layout.addWidget(widget)

        self._accordianWidget = accordion
        self._rolloutStyle = 2
        self._dragDropMode = 0

        self.setAcceptDrops(True)
        self.setLayout(layout)
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.showMenu)

        # create custom properties
        self._widget = widget
        self._collapsed = False
        self._collapsible = True
        self._clicked = False
        self._customData = {}

        # set common properties
        self.setTitle(title)
Exemplo n.º 4
0
    def __init__(self,
                 argspec,
                 parent=None,
                 window_title='Function arguments',
                 doc=None):
        super().__init__(parent)

        vlayout = QVBoxLayout(self)

        layout = QFormLayout()

        widgets = []

        defaults = argspec.defaults if argspec.defaults else ()
        defaults = ('', ) * (len(argspec.args[1:]) - len(defaults)) + defaults

        self.arguments = {}
        for arg, default in zip(argspec.args[1:], defaults):
            wid = QLineEdit(self)
            wid.setObjectName(arg)
            wid.setText(json.dumps(default))
            self.arguments[arg] = default

            layout.addRow(arg, wid)
            widgets.append(wid)
            wid.textChanged.connect(self.on_widget_change(wid))
            if doc and arg in doc:
                wid.setToolTip(doc[arg])

        self.widgets = widgets

        buttonBox = QDialogButtonBox()
        buttonBox.setOrientation(Qt.Horizontal)
        buttonBox.setStandardButtons(QDialogButtonBox.Ok)
        buttonBox.setEnabled(True)
        buttonBox.accepted.connect(self.accept)

        vlayout.addLayout(layout)

        label = QLabel()
        label.setText('Values are decoded from text using as JSON.')
        vlayout.addWidget(label)

        vlayout.addWidget(buttonBox)

        self.buttonBox = buttonBox
        self.valid = {wid.objectName(): True for wid in self.widgets}

        self.setWindowTitle(window_title)
Exemplo n.º 5
0
    def setupUi(self, parent):
        self.resize(275, 172)
        self.setWindowTitle('Convert units')
        self.layout = QVBoxLayout(parent)
        self.layout.setSizeConstraint(QLayout.SetFixedSize)
        align = (Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter)

        self.layout1 = QHBoxLayout()
        self.label1 = QLabel()
        self.label1.setMinimumSize(QSize(100, 0))
        self.label1.setText('Convert from:')
        self.label1.setAlignment(align)

        self.layout1.addWidget(self.label1)
        self.source_units = QLineEdit()
        self.source_units.setReadOnly(True)
        self.layout1.addWidget(self.source_units)

        self.layout.addLayout(self.layout1)

        self.layout2 = QHBoxLayout()
        self.label2 = QLabel()
        self.label2.setMinimumSize(QSize(100, 0))
        self.label2.setText('to:')
        self.label2.setAlignment(align)
        self.layout2.addWidget(self.label2)

        self.destination_units = QLineEdit()
        self.layout2.addWidget(self.destination_units)

        self.layout.addLayout(self.layout2)

        self.message = QLabel()
        self.message.setText('')
        self.message.setAlignment(Qt.AlignCenter)

        self.layout.addWidget(self.message)

        self.buttonBox = QDialogButtonBox()
        self.buttonBox.setOrientation(Qt.Horizontal)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Ok)
        self.layout.addWidget(self.buttonBox)
        self.buttonBox.setEnabled(False)

        self.buttonBox.accepted.connect(self.accept)
        self.destination_units.textChanged.connect(self.check)

        self.setLayout(self.layout)
        self.destination_units.setFocus()
Exemplo n.º 6
0
    def __init__( self, parent ):
        QDialog.__init__( self, parent )

        # enable minimize button
        # testing to make sure key events are processed
        # correctly when minimized
        self.setWindowFlags(self.windowFlags() |
            QtCore.Qt.WindowMinimizeButtonHint )
        
        self.setGeometry( 100, 100, 200, 100 )
        self.setWindowTitle( "Hello World" )
        self.setToolTip( "This is a <b>QWidget</b> widget" )
        
        self.btn = QPushButton( "Log Text", self )
        self.btn.setToolTip( "This is a <b>QPushButton</b> widget" )
        self.btn.resize( self.btn.sizeHint() )
        self.btn.clicked.connect( self.logText )

        self.lineedit = QLineEdit( "Hello World", self )
        self.lineedit.setToolTip( "Type Something" )
        
        layout = QVBoxLayout( self )
        layout.addWidget( self.lineedit )
        layout.addWidget( self.btn )
Exemplo n.º 7
0
    def __init__(self, argspec, parent=None, window_title='Function arguments', doc=None):
        super().__init__(parent)

        vlayout = QVBoxLayout(self)

        layout = QFormLayout()

        widgets = []

        defaults = argspec.defaults if argspec.defaults else ()
        defaults = ('', ) * (len(argspec.args[1:]) - len(defaults)) + defaults

        self.arguments = {}
        for arg, default in zip(argspec.args[1:], defaults):
            wid = QLineEdit(self)
            wid.setObjectName(arg)
            wid.setText(json.dumps(default))
            self.arguments[arg] = default

            layout.addRow(arg, wid)
            widgets.append(wid)
            wid.textChanged.connect(self.on_widget_change(wid))
            if doc and arg in doc:
                wid.setToolTip(doc[arg])


        self.widgets = widgets

        buttonBox = QDialogButtonBox()
        buttonBox.setOrientation(Qt.Horizontal)
        buttonBox.setStandardButtons(QDialogButtonBox.Ok)
        buttonBox.setEnabled(True)
        buttonBox.accepted.connect(self.accept)

        vlayout.addLayout(layout)

        label = QLabel()
        label.setText('Values are decoded from text using as JSON.')
        vlayout.addWidget(label)

        vlayout.addWidget(buttonBox)

        self.buttonBox = buttonBox
        self.valid = {wid.objectName(): True for wid in self.widgets}

        self.setWindowTitle(window_title)
Exemplo n.º 8
0
    def __init__(self, parent):
        QDialog.__init__(self, parent)

        # enable minimize button
        # testing to make sure key events are processed
        # correctly when minimized
        self.setWindowFlags(self.windowFlags()
                            | QtCore.Qt.WindowMinimizeButtonHint)

        self.setGeometry(100, 100, 200, 100)
        self.setWindowTitle("Hello World")
        self.setToolTip("This is a <b>QWidget</b> widget")

        self.btn = QPushButton("Log Text", self)
        self.btn.setToolTip("This is a <b>QPushButton</b> widget")
        self.btn.resize(self.btn.sizeHint())
        self.btn.clicked.connect(self.logText)

        self.lineedit = QLineEdit("Hello World", self)
        self.lineedit.setToolTip("Type Something")

        layout = QVBoxLayout(self)
        layout.addWidget(self.lineedit)
        layout.addWidget(self.btn)
Exemplo n.º 9
0
    def __init__(self, parent, target):
        super().__init__(parent)
        self._lantz_target = target

        layout = QVBoxLayout(self)

        label = QLabel()
        label.setText(str(target))
        layout.addWidget(label)

        recall = QPushButton()
        recall.setText('Refresh')
        recall.clicked.connect(lambda x: target.refresh())

        update = QPushButton()
        update.setText('Update')
        update.clicked.connect(
            lambda x: target.update(self.widgets_values_as_dict()))

        auto = QCheckBox()
        auto.setText('Update on change')
        auto.setChecked(True)
        auto.stateChanged.connect(self.update_on_change)

        hlayout = QHBoxLayout()
        hlayout.addWidget(recall)
        hlayout.addWidget(update)
        hlayout.addWidget(auto)

        layout.addLayout(hlayout)

        self.writable_widgets = []
        self.widgets = []

        # Feat
        for feat_name, feat in sorted(target.feats.items()):
            try:
                feat_widget = LabeledFeatWidget(self, target, feat)

                self.widgets.append(feat_widget)
                if feat_widget.writable:
                    self.writable_widgets.append(feat_widget)

                layout.addWidget(feat_widget)
            except Exception as ex:
                logger.debug('Could not create control for {}: {}'.format(
                    feat_name, ex))
                #import traceback
                #traceback.print_exc()

        # Actions
        line = QFrame(self)
        #self.line.setGeometry(QtCore.QRect(110, 80, 351, 31))
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)
        layout.addWidget(line)

        actions_label = QLabel(self)
        actions_label.setText('Actions:')
        actions_label.setFixedWidth(120)

        self.actions_combo = QComboBox(self)
        self.actions_combo.addItems(list(target.actions.keys()))

        actions_button = QPushButton(self)
        actions_button.setFixedWidth(60)
        actions_button.setText('Run')
        actions_button.clicked.connect(self.on_run_clicked)

        alayout = QHBoxLayout()
        alayout.addWidget(actions_label)
        alayout.addWidget(self.actions_combo)
        alayout.addWidget(actions_button)

        layout.addLayout(alayout)
Exemplo n.º 10
0
class UnitInputDialog(QDialog):
    """Dialog to select new units. Checks compatibility while typing
    and does not allow to continue if incompatible.

    Returns None if cancelled.

    :param units: current units.
    :param parent: parent widget.

    >>> new_units = UnitInputDialog.get_units('ms')
    """
    def __init__(self, units, parent=None):
        super().__init__(parent)
        self.setupUi(parent)
        self.units = units
        self.source_units.setText(str(units))

    def setupUi(self, parent):
        self.resize(275, 172)
        self.setWindowTitle('Convert units')
        self.layout = QVBoxLayout(parent)
        self.layout.setSizeConstraint(QLayout.SetFixedSize)
        align = (Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter)

        self.layout1 = QHBoxLayout()
        self.label1 = QLabel()
        self.label1.setMinimumSize(QSize(100, 0))
        self.label1.setText('Convert from:')
        self.label1.setAlignment(align)

        self.layout1.addWidget(self.label1)
        self.source_units = QLineEdit()
        self.source_units.setReadOnly(True)
        self.layout1.addWidget(self.source_units)

        self.layout.addLayout(self.layout1)

        self.layout2 = QHBoxLayout()
        self.label2 = QLabel()
        self.label2.setMinimumSize(QSize(100, 0))
        self.label2.setText('to:')
        self.label2.setAlignment(align)
        self.layout2.addWidget(self.label2)

        self.destination_units = QLineEdit()
        self.layout2.addWidget(self.destination_units)

        self.layout.addLayout(self.layout2)

        self.message = QLabel()
        self.message.setText('')
        self.message.setAlignment(Qt.AlignCenter)

        self.layout.addWidget(self.message)

        self.buttonBox = QDialogButtonBox()
        self.buttonBox.setOrientation(Qt.Horizontal)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Ok)
        self.layout.addWidget(self.buttonBox)
        self.buttonBox.setEnabled(False)

        self.buttonBox.accepted.connect(self.accept)
        self.destination_units.textChanged.connect(self.check)

        self.setLayout(self.layout)
        self.destination_units.setFocus()

    def check(self):
        units = self.destination_units.text().strip()
        if not units:
            return
        try:
            new_units = Q_(1, units)
            factor = self.units.to(new_units).magnitude
        except LookupError or SyntaxError:
            self.message.setText('Cannot parse units')
            self.buttonBox.setEnabled(False)
        except ValueError:
            self.message.setText('Incompatible units')
            self.buttonBox.setEnabled(False)
        else:
            self.message.setText('factor {:f}'.format(factor))
            self.buttonBox.setEnabled(True)

    @staticmethod
    def get_units(units):
        """Creates and display a UnitInputDialog and return new units.

        Return None if the user cancelled.

        """
        dialog = UnitInputDialog(Q_(1, units.units))
        if dialog.exec_():
            return dialog.destination_units.text()
        return None
Exemplo n.º 11
0
    def __init__(self, parent, target):
        super().__init__(parent)
        self._lantz_target = target

        layout = QVBoxLayout(self)

        label = QLabel()
        label.setText(str(target))
        layout.addWidget(label)

        recall = QPushButton()
        recall.setText('Refresh')
        recall.clicked.connect(lambda x: target.refresh())

        update = QPushButton()
        update.setText('Update')
        update.clicked.connect(lambda x: target.update(self.widgets_values_as_dict()))

        auto = QCheckBox()
        auto.setText('Update on change')
        auto.setChecked(True)
        auto.stateChanged.connect(self.update_on_change)

        hlayout = QHBoxLayout()
        hlayout.addWidget(recall)
        hlayout.addWidget(update)
        hlayout.addWidget(auto)

        layout.addLayout(hlayout)

        self.writable_widgets = []
        self.widgets = []

        # Feat
        for feat_name, feat in sorted(target.feats.items()):
            try:
                feat_widget = LabeledFeatWidget(self, target, feat)

                self.widgets.append(feat_widget)
                if feat_widget.writable:
                    self.writable_widgets.append(feat_widget)

                layout.addWidget(feat_widget)
            except Exception as ex:
                logger.debug('Could not create control for {}: {}'.format(feat_name, ex))
                #import traceback
                #traceback.print_exc()

        # Actions
        line = QFrame(self)
        #self.line.setGeometry(QtCore.QRect(110, 80, 351, 31))
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)
        layout.addWidget(line)


        actions_label = QLabel(self)
        actions_label.setText('Actions:')
        actions_label.setFixedWidth(120)

        self.actions_combo = QComboBox(self)
        self.actions_combo.addItems(list(target.actions.keys()))

        actions_button = QPushButton(self)
        actions_button.setFixedWidth(60)
        actions_button.setText('Run')
        actions_button.clicked.connect(self.on_run_clicked)

        alayout = QHBoxLayout()
        alayout.addWidget(actions_label)
        alayout.addWidget(self.actions_combo)
        alayout.addWidget(actions_button)

        layout.addLayout(alayout)
Exemplo n.º 12
0
class UnitInputDialog(QDialog):
    """Dialog to select new units. Checks compatibility while typing
    and does not allow to continue if incompatible.

    Returns None if cancelled.

    :param units: current units.
    :param parent: parent widget.

    >>> new_units = UnitInputDialog.get_units('ms')
    """

    def __init__(self, units, parent=None):
        super().__init__(parent)
        self.setupUi(parent)
        self.units = units
        self.source_units.setText(str(units))

    def setupUi(self, parent):
        self.resize(275, 172)
        self.setWindowTitle('Convert units')
        self.layout = QVBoxLayout(parent)
        self.layout.setSizeConstraint(QLayout.SetFixedSize)
        align = (Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter)

        self.layout1 = QHBoxLayout()
        self.label1 = QLabel()
        self.label1.setMinimumSize(QSize(100, 0))
        self.label1.setText('Convert from:')
        self.label1.setAlignment(align)

        self.layout1.addWidget(self.label1)
        self.source_units = QLineEdit()
        self.source_units.setReadOnly(True)
        self.layout1.addWidget(self.source_units)

        self.layout.addLayout(self.layout1)

        self.layout2 = QHBoxLayout()
        self.label2 = QLabel()
        self.label2.setMinimumSize(QSize(100, 0))
        self.label2.setText('to:')
        self.label2.setAlignment(align)
        self.layout2.addWidget(self.label2)

        self.destination_units = QLineEdit()
        self.layout2.addWidget(self.destination_units)

        self.layout.addLayout(self.layout2)

        self.message = QLabel()
        self.message.setText('')
        self.message.setAlignment(Qt.AlignCenter)

        self.layout.addWidget(self.message)

        self.buttonBox = QDialogButtonBox()
        self.buttonBox.setOrientation(Qt.Horizontal)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Ok)
        self.layout.addWidget(self.buttonBox)
        self.buttonBox.setEnabled(False)

        self.buttonBox.accepted.connect(self.accept)
        self.destination_units.textChanged.connect(self.check)

        self.setLayout(self.layout)
        self.destination_units.setFocus()

    def check(self):
        units = self.destination_units.text().strip()
        if not units:
            return
        try:
            new_units = Q_(1, units)
            factor = self.units.to(new_units).magnitude
        except LookupError or SyntaxError:
            self.message.setText('Cannot parse units')
            self.buttonBox.setEnabled(False)
        except ValueError:
            self.message.setText('Incompatible units')
            self.buttonBox.setEnabled(False)
        else:
            self.message.setText('factor {:f}'.format(factor))
            self.buttonBox.setEnabled(True)

    @staticmethod
    def get_units(units):
        """Creates and display a UnitInputDialog and return new units.

        Return None if the user cancelled.

        """
        dialog = UnitInputDialog(Q_(1, units.units))
        if dialog.exec_():
            return dialog.destination_units.text()
        return None