コード例 #1
0
ファイル: auxwindows.py プロジェクト: ess-dmsc/nicos
    def __init__(self, item, window, menuwindow, parent):
        from nicos.clients.gui.panels.utils import createWindowItem
        QMainWindow.__init__(self, parent)
        self.user_color = window.user_color
        self.mainwindow = window.mainwindow
        self.log = NicosLogger('AuxiliarySubWindow')
        self.log.parent = self.mainwindow.log

        self.panels = []

        # we have to nest one step to get consistent layout spacing
        # around the central widget
        central = QWidget(self)
        layout = QVBoxLayout()
        # only keep margin at the top (below the tabs)
        layout.setContentsMargins(0, 6, 0, 0)
        if len(item) == 1:
            (subitem, setupSpec) = item + (None, )
        else:
            (subitem, setupSpec) = item
        it = createWindowItem(subitem, window, menuwindow, self, self.log)
        if it:
            if isinstance(it, (
                    Panel,
                    QSplitter,
            )):
                if isinstance(it, Panel):
                    it.hideTitle()
                # if tab has its own setups overwrite panels setups
                if setupSpec:
                    it.setSetups(setupSpec)
                it.setWidgetVisible.connect(parent.setWidgetVisibleSlot)
            layout.addWidget(it)
            central.setLayout(layout)
            self.setCentralWidget(central)
コード例 #2
0
ファイル: display.py プロジェクト: ess-dmsc/nicos
 def __init__(self, parent=None, designMode=False, **kwds):
     QWidget.__init__(self, parent, **kwds)
     NicosWidget.__init__(self)
     self._last_mtime = None
     self.namelabel = QLabel(self)
     self.namelabel.setAlignment(Qt.AlignHCenter)
     self.piclabel = QLabel(self)
     self.piclabel.setScaledContents(True)
     layout = QVBoxLayout()
     layout.setContentsMargins(0, 0, 0, 0)
     layout.addWidget(self.piclabel, 1)
     self.setLayout(layout)
コード例 #3
0
class MultiList(NicosWidget, QWidget):
    """A list of entries, where each entry is a frame loaded from a UI file."""

    designer_description = 'A list (with add/remove controls) of .ui entries'

    uifile = PropDef('uifile', str, '', 'UI file to use for the entries')

    entryAdded = pyqtSignal(object)
    entryRemoved = pyqtSignal(object)

    def __init__(self, parent, designMode=False, **kwds):
        QWidget.__init__(self, parent, **kwds)
        NicosWidget.__init__(self)
        self._entries = []
        self._vlayout = QVBoxLayout()
        self._vlayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self._vlayout)
        self._add()
        self._designer = designMode

    def registerKeys(self):
        pass

    def propertyUpdated(self, pname, value):
        if pname == 'uifile':
            self.clear()
        NicosWidget.propertyUpdated(self, pname, value)

    def entry(self, i):
        return self._entries[i].subwidget

    def entries(self):
        return [e.subwidget for e in self._entries]

    def count(self):
        return len(self._entries)

    def clear(self):
        for entry in self._entries[::-1]:
            self._remove(entry)
        self._add()

    def _remove(self, entry):
        self._entries.remove(entry)
        self._vlayout.removeWidget(entry)
        self.entryRemoved.emit(entry.subwidget)
        entry.deleteLater()
        if self._entries:
            self._entries[-1].setButton('+')

    def _add(self):
        new_frame = MultiEntry(self, self._client, self.props['uifile'])
        new_frame.addOrRemove.connect(self._addRemove)
        if self._entries:
            self._entries[-1].setButton('-')
        self._entries.append(new_frame)
        self._vlayout.addWidget(new_frame)
        self.entryAdded.emit(self._entries[-1].subwidget)

    def _addRemove(self):
        if not self._entries or self.sender() is self._entries[-1]:
            self._add()
        else:
            self._remove(self.sender())
コード例 #4
0
class ItemsWidget(QScrollArea):

    valueModified = pyqtSignal()
    valueChosen = pyqtSignal(object)

    allow_reorder = True

    def __init__(self, parent, nmin, allow_enter=False):
        QScrollArea.__init__(self, parent)
        self.setWidgetResizable(True)
        self.frame = QFrame(self)
        self.layout = QVBoxLayout()
        self.layout.setContentsMargins(2, 2, 2, 2)
        self.addBtn = QPushButton(QIcon(':/add'), '', self.frame)
        self.addBtn.clicked.connect(self.on_addBtn_clicked)
        self.addBtn.setSizePolicy(
            QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred))
        self.layout.addWidget(self.addBtn)
        self.layout.addStretch()
        self.frame.setLayout(self.layout)
        self.setWidget(self.frame)
        self.items = []
        self.nmin = nmin
        self.allow_enter = allow_enter

    def insertItem(self, *widgets):
        item = QWidget(self.frame)
        item._widgets = widgets
        layout = QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        for widget in widgets:
            layout.addWidget(widget)
        if self.allow_reorder:
            btn = QPushButton(QIcon(':/up'), '', item)
            btn._item = item
            btn.clicked.connect(self.on_upBtn_clicked)
            layout.addWidget(btn)
            btn = QPushButton(QIcon(':/down'), '', item)
            btn._item = item
            btn.clicked.connect(self.on_downBtn_clicked)
            layout.addWidget(btn)
        btn = QPushButton(QIcon(':/remove'), '', item)
        btn._item = item
        btn.clicked.connect(self.on_removeBtn_clicked)
        layout.addWidget(btn)
        item.setLayout(layout)
        self.layout.insertWidget(self.layout.count() - 2, item)
        self.items.append(item)

    def on_addBtn_clicked(self):
        self.insertItem(*self.createItem())
        self.valueModified.emit()

    def on_removeBtn_clicked(self):
        if len(self.items) <= self.nmin:
            return
        item = self.sender()._item
        index = self.items.index(item)
        del self.items[index]
        self.layout.takeAt(index).widget().deleteLater()
        self.valueModified.emit()

    def on_upBtn_clicked(self):
        item = self.sender()._item
        index = self.items.index(item)
        if index <= 0:
            return
        self._swapItems(index - 1)

    def on_downBtn_clicked(self):
        item = self.sender()._item
        index = self.items.index(item)
        if index >= len(self.items) - 1:
            return
        self._swapItems(index)

    def _swapItems(self, firstindex):
        item1 = self.items[firstindex]
        item2 = self.items[firstindex + 1]
        self.layout.takeAt(firstindex)
        self.layout.takeAt(firstindex)  # moved up one
        self.items[firstindex:firstindex + 2] = [item2, item1]
        self.layout.insertWidget(firstindex, item2)
        self.layout.insertWidget(firstindex + 1, item1)
        self.valueModified.emit()
コード例 #5
0
class BaseDev(QWidget):
    base_address = 0
    has_target = False
    has_status = False
    offset = 1

    def __init__(self,
                 model,
                 name,
                 index,
                 addr,
                 has_status=False,
                 target=None,
                 value_offset=1):
        QWidget.__init__(self)
        self.index = index
        self.name = name
        self.model = model

        self.offset = value_offset
        self.has_status = has_status
        self.has_target = target is not None
        self.base_address = addr

        self._namelabel = QLabel(name)
        self._namelabel.setMinimumWidth(120)
        self._namelabel.setMaximumWidth(120)
        # self._groupbox = QGroupBox(name)
        self._groupbox = QFrame()
        # self._groupbox.setFlat(False)
        # self._groupbox.setCheckable(False)
        self._hlayout = QHBoxLayout()
        self._hlayout.addWidget(self._namelabel)
        self._hlayout.addWidget(self._groupbox)
        self._hlayout.setSpacing(0)

        # inside of the groupbox there is a vbox with 1 or 2 hboxes
        self._inner_vbox = QVBoxLayout()
        self._groupbox.setLayout(self._inner_vbox)

        # upper inner hbox
        self._inner_hbox1 = QHBoxLayout()
        self._inner_vbox.addLayout(self._inner_hbox1)

        # fill upper hbox
        self.valueWidget = QLineEdit('0b123456789abcdef0')
        self.valueWidget.setMaximumWidth(120)
        self._inner_hbox1.addWidget(self.valueWidget)

        if self.has_target:
            self.targetWidget = QLineEdit()
            self.targetWidget.setPlaceholderText(target)
            self.targetWidget.setMaximumWidth(120)
            self.targetWidget.returnPressed.connect(lambda *a: model.targeter(
                index,
                (self.targetWidget.text(), self.targetWidget.setText(''))[0]))
            self._inner_hbox1.addWidget(self.targetWidget)
            self.goButton = QPushButton('Go')
            self.goButton.clicked.connect(lambda *a: model.targeter(
                index,
                (self.targetWidget.text(), self.targetWidget.setText(''))[0]))
            self._inner_hbox1.addWidget(self.goButton)
            self.stopButton = QPushButton('Stop')
            self.stopButton.clicked.connect(lambda *a: model.stopper(index))
            self._inner_hbox1.addWidget(self.stopButton)

        # now (conditionally) the second hbox
        if has_status:
            self._inner_hbox2 = QHBoxLayout()
            self._inner_vbox.addLayout(self._inner_hbox2)

            self.statvalueWidget = QLineEdit('statval')
            self.statvalueWidget.setMaximumWidth(120)
            self._inner_hbox2.addWidget(self.statvalueWidget)
            self.statusWidget = QLineEdit('Statusstring if available')
            self.statusWidget.setMaximumWidth(10000)
            self._inner_hbox2.addWidget(self.statusWidget)
            self.resetButton = QPushButton('Reset')
            self.resetButton.clicked.connect(lambda *a: model.resetter(index))
            self._inner_hbox1.addWidget(self.resetButton)
            # self._inner_hbox2.addStretch(0.1)

        # allow space for resizing
        self._inner_hbox1.addStretch(1)

        self._inner_vbox.setSpacing(0)
        self._inner_vbox.setContentsMargins(0, 0, 0, 0)

        self._hlayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self._hlayout)
        self.show()
コード例 #6
0
ファイル: live.py プロジェクト: ess-dmsc/nicos
 def __init__(self, title, parent=None):
     QGroupBox.__init__(self, title=title, parent=parent)
     self.setContentsMargins(0, 0, 0, 0)
     vbox = QVBoxLayout()
     vbox.setContentsMargins(0, 0, 0, 0)
     self.setLayout(vbox)
コード例 #7
0
class BaseDev(QWidget):
    has_target = False
    has_status = False

    def __init__(self, model, name, addr):
        super(BaseDev, self).__init__()
        self.name = name
        self.model = model
        self.addr = addr

        self._namelabel = QLabel(name)
        self._namelabel.setMinimumWidth(120)
        self._namelabel.setMaximumWidth(120)
        # self._groupbox = QGroupBox(name)
        self._groupbox = QFrame()
        # self._groupbox.setFlat(False)
        # self._groupbox.setCheckable(False)
        self._hlayout = QHBoxLayout()
        self._hlayout.addWidget(self._namelabel)
        self._hlayout.addWidget(self._groupbox)
        self._hlayout.setSpacing(0)

        # inside of the groupbox there is a vbox with 1 or 2 hboxes
        self._inner_vbox = QVBoxLayout()
        self._groupbox.setLayout(self._inner_vbox)

        # upper inner hbox
        self._inner_hbox1 = QHBoxLayout()
        self._inner_vbox.addLayout(self._inner_hbox1)

        # fill upper hbox
        self.valueWidget = QLineEdit('0b123456789abcdef0')
        self.valueWidget.setMaximumWidth(120)
        self._inner_hbox1.addWidget(self.valueWidget)

        if self.has_target:
            self.targetWidget = QLineEdit()
            self.targetWidget.setPlaceholderText('')
            self.targetWidget.setMaximumWidth(120)
            self.targetWidget.returnPressed.connect(self._go_clicked)
            self._inner_hbox1.addWidget(self.targetWidget)
            self.goButton = QPushButton('Go')
            self.goButton.clicked.connect(self._go_clicked)
            self._inner_hbox1.addWidget(self.goButton)
            self.stopButton = QPushButton('Stop')
            self.stopButton.clicked.connect(self._stop_clicked)
            self._inner_hbox1.addWidget(self.stopButton)

        # now (conditionally) the second hbox
        if self.has_status:
            self._inner_hbox2 = QHBoxLayout()
            self._inner_vbox.addLayout(self._inner_hbox2)

            self.statvalueWidget = QLineEdit('statval')
            self.statvalueWidget.setMaximumWidth(120)
            self._inner_hbox2.addWidget(self.statvalueWidget)
            self.statusWidget = QLineEdit('Statusstring if available')
            self.statusWidget.setMaximumWidth(10000)
            self._inner_hbox2.addWidget(self.statusWidget)
            self.resetButton = QPushButton('Reset')
            self.resetButton.clicked.connect(self._reset_clicked)
            self._inner_hbox1.addWidget(self.resetButton)
            # self._inner_hbox2.addStretch(0.1)

        # allow space for resizing
        self._inner_hbox1.addStretch(1)

        self._inner_vbox.setSpacing(0)
        self._inner_vbox.setContentsMargins(0, 0, 0, 0)

        self._hlayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self._hlayout)
        self.show()

    def _go_clicked(self):
        self.model.targeter(self.index, self.targetWidget.text())
        self.targetWidget.setText('')

    def _stop_clicked(self):
        self.model.stopper(self.index)

    def _reset_clicked(self):
        self.resetter(self.index)

    def _update(self):
        pass

    def _str2bin(self, value):
        return int(value)

    def _bin2str(self, value):
        return str(value)

    def _status(self, value):
        return "no status decoder implemented"