Exemplo n.º 1
0
    def _select_item(self, item):
        """Select the given item by drawing a colored circle beneath the
        selected item (so it looks like a ring around it.
        Also emits the timepointSelected signal."""

        # The selection_item used to signal the selection of a timepoint
        # is always the same and is only moved.
        if self._selection_item is None:
            self._selection_item = QGraphicsEllipseItem(
                0, 0, self.SELECTION_DIAMETER, self.SELECTION_DIAMETER)

            # The used color is a cubical to the time point color
            self._selection_item.setBrush(QBrush(QColor(0x70, 0xbb, 0x00)))
            self._selection_item.setPen(QPen(0))
            self.scene().addItem(self._selection_item)

        # center position of the timepoint circle
        center_x = item.pos().x() + self.TIMEPOINT_DIAMETER / 2
        center_y = item.pos().y() + self.TIMEPOINT_DIAMETER / 2

        # move selection item
        self._selection_item.setPos(center_x - self.SELECTION_DIAMETER / 2,
                                    center_y - self.SELECTION_DIAMETER / 2)

        # store the selection_item like a timepoint item (using the timepoint
        # of the selected item)
        self._time_point_items[self._selection_item] = \
            self._time_point_items[item]

        # emit signal at the end to ensure a valid internal state before
        # anything can react to it
        self.timepointSelected.emit(self._time_point_items[item])
Exemplo n.º 2
0
    def _add_time_point(self, center_x, center_y, time_point):
        """Add a single time point item."""
        x = center_x - (self.TIMEPOINT_DIAMETER / 2)
        y = center_y - (self.TIMEPOINT_DIAMETER / 2)

        # Create the acutal time point item
        time_point_item = QGraphicsEllipseItem(0, 0, self.TIMEPOINT_DIAMETER,
                                               self.TIMEPOINT_DIAMETER)

        # The used color is the strongest one of the FRM II colors.
        time_point_item.setBrush(QBrush(QColor(0x00, 0x71, 0xbb)))
        time_point_item.setPen(QPen(0))

        self.scene().addItem(time_point_item)
        time_point_item.setPos(x, y)

        # place the time point item above the timeline and the selection item
        time_point_item.setZValue(2)

        # Create the label of the time point showing the time in the
        # defined strftime format on the right side of the time point item.
        label = QGraphicsTextItem(time_point.strftime(self.STRFTIME_FMT))
        label.setFont(QFont('Monospace'))
        label_height = label.boundingRect().height()

        # minor height adjustment
        label_y = y - label_height / 6

        self.scene().addItem(label)
        label.setPos(x + self.SELECTION_DIAMETER + self.LABEL_SPACING, label_y)

        # store references to the item and the timepoint in the same dict
        # to be able to use it for forward and reverse lookup
        self._time_point_items[time_point] = time_point_item
        self._time_point_items[time_point_item] = time_point
Exemplo n.º 3
0
    def _add_timeline(self):
        """Draw the timeline."""

        # height is either the necessary space to display all items or the
        # maximal available display size, so it's looks nicely in larger
        # windows and enables scrolling in smaller ones.
        height = self.TIMEPOINT_DIAMETER * len(self._time_points)
        height += self.TIMEPOINT_SPACING * len(self._time_points)
        height = max(height, self.viewport().height())

        # draw the timeline left aligned with enough space to draw the items
        # and the selection ring.
        x = self.MARGIN_HORIZONTAL + (self.SELECTION_DIAMETER / 2)

        # position the line on the left side of the item
        item = QGraphicsLineItem(0, 0, 0, height)

        # The used color for the timeline is the lightest one of the FRM II
        # colors
        item.setPen(QPen(QBrush(QColor(0xa3, 0xc1, 0xe7)),
                         self.TIMELINE_WIDTH))

        self.scene().addItem(item)

        # move the whole item to the desired timeline position
        item.setPos(x, 0)
        return item
Exemplo n.º 4
0
 def __init__(self, x, y, size=20, parent=None, scene=None):
     if parent:
         self._color = parent._color
     TableBase.__init__(self, x, y, size, parent, scene)
     if not self._pencolor:
         self._pencolor = QColor('#666666')
     self._pen = QPen(self._pencolor, 1)
     self._pen.setBrush(QBrush(self._pencolor))
     sz = size / 3
     self._polygon = QGraphicsRectItem(
         QRectF(-QPointF(sz, sz), QPointF(sz, sz)), self)
     self._polygon.setBrush(QBrush(self._pencolor))
     self._l1 = QGraphicsLineItem(-size, 0, size, 0, self)
     self._l1.setPen(self._pen)
     self._l2 = QGraphicsLineItem(0, -size, 0, size, self)
     self._l2.setPen(self._pen)
Exemplo n.º 5
0
 def __init__(self, width=10, parent=None, scene=None):
     QGraphicsPathItem.__init__(self, parent)
     self._width = width
     self.setPath(self.shape())
     if not parent and scene:
         scene.addItem(self)
     self.setBrush(QBrush(statuscolor[status.OK]))
     self.setPen(QPen(statuscolor[status.OK], width))
Exemplo n.º 6
0
    def on_readWKT_clicked(self):

        self.noredrawblack = True
        self.tf.setForeground(QBrush(Qt.red))
        self.wktText.setCurrentCharFormat(self.tf)
        arg = 'ROI'+str(self.polylistindex - 1)
        jcurwkt = self.client.eval(self.ldevname+".roi('"+arg+"')")
        if not jcurwkt:
            self.wktText.setPlainText('')
        else:
            curwkt = json.loads(jcurwkt)
            self.wktText.setPlainText(curwkt[0])

        self.polylist[self.polylistindex - 1].readWKT(self.wktText.toPlainText())
        self.tf.setForeground(QBrush(Qt.black))
        self.noredrawblack = False
        self.wktText.update()
Exemplo n.º 7
0
    def __init__(self, parent):
        QWidget.__init__(self, parent)
        NicosWidget.__init__(self)

        self.p_black = QPen(QColor('black'))
        self.p_red = QPen(QColor('red'))

        self.br_back = QBrush(QColor(190, 190, 190))
        self.br_empty = QBrush(QColor(255, 255, 255))

        self.col_led = [QColor(0, 0, 255), QColor(255, 255, 0)]
        self.br_led = [QBrush(self.col_led[0]), QBrush(self.col_led[1])]
        self.br_seg = QBrush(QColor(211, 211, 211))

        self.devs = ['diagnostics/value', 'diag_switches/value',
                     'mb_arm_raw/value', 'mtt_raw/value', 'n_blocks_cw/value']
        self.values = [0, 0, 0, 0, 0]
Exemplo n.º 8
0
 def __init__(self, parent=None, scene=None):
     QGraphicsRectItem.__init__(self, 0, 0, 10, 45, parent)
     transform = QTransform()
     transform.translate(0, 5)
     self.setTransform(transform)
     self.setBrush(QBrush(QColor('#00FF00')))
     if not parent and scene:
         scene.addItem(self)
     self._halo = DetectorHalo(5, self, scene)
Exemplo n.º 9
0
 def __init__(self, x, y, size=60, width=10, parent=None, scene=None):
     self._width = width
     s = size + width / 2
     QGraphicsEllipseItem.__init__(self, QRectF(-QPoint(s, s),
                                   QSizeF(2 * s, 2 * s)), parent)
     self.setBrush(QBrush(statuscolor[status.OK]))
     if not parent and scene:
         scene.addItem(self)
     self.setPos(x, y)
     self.setState(status.OK)
Exemplo n.º 10
0
 def __init__(self, x, y, size=20, parent=None, scene=None):
     TableBase.__init__(self, x, y, size, parent, scene)
     self._halowidth = max(size / 4, 10)
     self._halo = Halo(x, y, size, self._halowidth, self, scene)
     self._tuberadius = size / 5
     p = QPointF(self._tuberadius, self._tuberadius)
     s = QSizeF(2 * self._tuberadius, 2 * self._tuberadius)
     self._tube = QGraphicsEllipseItem(QRectF(-p, s), self)
     self._tube.setPen(QPen(QColor('black'), 3))
     self._tube.setBrush(QBrush(QColor('white')))
     self._tube.setZValue(20)
Exemplo n.º 11
0
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)
        DlgUtils.__init__(self, 'Live data')
        self.panel = parent
        layout1 = QVBoxLayout()
        self.plot = QwtPlot(self)
        layout1.addWidget(self.plot)
        self.curve = QwtPlotCurve()
        self.curve.setRenderHint(QwtPlotCurve.RenderAntialiased)
        self.curve.attach(self.plot)
        self.marker = QwtPlotMarker()
        self.marker.attach(self.plot)
        self.markerpen = QPen(Qt.red)
        self.marker.setSymbol(
            QwtSymbol(QwtSymbol.Ellipse, QBrush(), self.markerpen, QSize(7,
                                                                         7)))
        self.zoomer = QwtPlotZoomer(self.plot.canvas())
        self.zoomer.setMousePattern(QwtPlotZoomer.MouseSelect3, Qt.NoButton)
        self.picker = QwtPlotPicker(self.plot.canvas())
        self.picker.setSelectionFlags(QwtPlotPicker.PointSelection
                                      | QwtPlotPicker.ClickSelection)
        self.picker.setMousePattern(QwtPlotPicker.MouseSelect1, Qt.MidButton)
        self.picker.selected.connect(self.pickerSelected)
        layout2 = QHBoxLayout()
        layout2.addWidget(QLabel('Scale:', self))
        self.scale = QComboBox(self)
        self.scale.addItems([
            'Single detectors, sorted by angle',
            'Scattering angle 2theta (deg)', 'Q value (A-1)'
        ])
        self.scale.currentIndexChanged[int].connect(self.scaleChanged)
        layout2.addWidget(self.scale)
        layout2.addStretch()
        self.scaleframe = QFrame(self)
        self.scaleframe.setLayout(layout2)
        self.scaleframe.setVisible(False)
        layout1.addWidget(self.scaleframe)
        mainframe = QFrame(self)
        mainframe.setLayout(layout1)
        self.setCentralWidget(mainframe)
        self.setContentsMargins(6, 6, 6, 6)
        plotfont = scaledFont(self.font(), 0.7)
        self.plot.setAxisFont(QwtPlot.xBottom, plotfont)
        self.plot.setAxisFont(QwtPlot.yLeft, plotfont)
        self.plot.setCanvasBackground(Qt.white)
        self.resize(800, 200)

        self._detinfo = None
        self._anglemap = None
        self._infowindow = None
        self._infolabel = None
        self._xs = self._ys = None
        self._type = None
Exemplo n.º 12
0
 def __init__(self, x, y, size=40, parent=None, scene=None):
     self._origin = QPoint(x, y)
     self._size = size
     self._radius = size / 2
     if not self._color:
         self._color = QColor('white')
     QGraphicsEllipseItem.__init__(self, QRectF(-QPoint(size, size),
                                   QSizeF(2 * size, 2 * size)), parent)
     if not parent and scene:
         scene.addItem(self)
     self.setPos(x, y)
     self.setBrush(QBrush(self._color))
Exemplo n.º 13
0
 def __init__(self, width, parent=None, scene=None):
     w = width + 2
     if parent and isinstance(parent, QGraphicsRectItem):
         rect = parent.rect()
         size = rect.size()
         size += QSizeF(w, w)
         rect.setSize(size)
     else:
         rect = QRectF()
     QGraphicsRectItem.__init__(self, rect, parent)
     transform = QTransform()
     transform.translate(-w / 2, -w / 2)
     self.setTransform(transform)
     self.setBrush(QBrush(statuscolor[status.OK]))
     self.setPen(QPen(statuscolor[status.OK], width))
Exemplo n.º 14
0
    def __init__(self, parent=None):
        scene = QGraphicsScene()
        QGraphicsView.__init__(self, scene)
        self.setRenderHints(QPainter.Antialiasing)

        self._tube = Tube(scene=scene)
        self._tube.setRotation(1)
        self._yoke = Yoke(scene=scene)
        t1 = QTransform()
        t1.translate(500, 0)
        self._yoke.setTransform(t1)
        self._pivotline = QGraphicsLineItem(-200, 0, 700, 0)
        scene.addItem(self._pivotline)
        self._pivot = QGraphicsRectItem(0, 0, 6, 10)
        t2 = QTransform()
        t2.translate(-3, -10)
        self._pivot.setTransform(t2)
        self._pivot.setBrush(QBrush(QColor('#1F1F1F')))
        scene.addItem(self._pivot)
        for i in range(13):
            txt = '%d' % (i + 1)
            self.t = QGraphicsTextItem(txt)
            bw = self.t.boundingRect().size().width()
            chrwidth = bw / (len(txt) + 1)
            x = (i - 9) * self.pivotdist - chrwidth / 2 + bw / len(txt)
            self.t.setX(x)
            scene.addItem(self.t)
        self._det = Detector(parent=self._tube, scene=scene)

        self.values = {
            'tubeangle': -1.0,
            'pivot': 1,
            'detpos': 620,
        }
        self.targets = self.values.copy()
        self.status = {
            'tubeangle': status.OK,
            'pivot': status.OK,
            'detpos': status.OK,
        }
Exemplo n.º 15
0
    def __init__(self):
        loadUi(self, 'panels/history.ui')

        self.user_color = Qt.white
        self.user_font = QFont('Monospace')

        self.views = []
        # stack of views to display
        self.viewStack = []
        # maps watched keys to their views
        self.keyviews = {}
        # current plot object
        self.currentPlot = None
        self.fitclass = LinearFitter
        self.fitfuncmap = {}

        self.enablePlotActions(False)

        self.presetmenu = QMenu('&Presets', self)

        for (name, view) in self.last_views:
            item = QListWidgetItem(name, self.viewList)
            item.setForeground(QBrush(QColor('#aaaaaa')))
            item.setData(Qt.UserRole, view)

        self.menus = None
        self.bar = None

        # NOTE: for this class, automatic connections don't work on PyQt4 >=
        # 4.12 since this class is not derived from QObject. But on older PyQt4
        # and PyQt5, they do work, so we change use the usual naming scheme
        # slightly to avoid double connections.
        self.viewList.currentItemChanged.connect(
            self.on__viewList_currentItemChanged)
        self.viewList.itemClicked.connect(self.on__viewList_itemClicked)
        self.viewList.itemDoubleClicked.connect(
            self.on__viewList_itemDoubleClicked)
        self.actionNew.triggered.connect(self.on__actionNew_triggered)
        self.actionEditView.triggered.connect(
            self.on__actionEditView_triggered)
        self.actionCloseView.triggered.connect(
            self.on__actionCloseView_triggered)
        self.actionResetView.triggered.connect(
            self.on__actionResetView_triggered)
        self.actionDeleteView.triggered.connect(
            self.on__actionDeleteView_triggered)
        self.actionSavePlot.triggered.connect(
            self.on__actionSavePlot_triggered)
        self.actionPrint.triggered.connect(self.on__actionPrint_triggered)
        self.actionUnzoom.triggered.connect(self.on__actionUnzoom_triggered)
        self.actionLogScale.toggled.connect(self.on__actionLogScale_toggled)
        self.actionAutoScale.toggled.connect(self.on__actionAutoScale_toggled)
        self.actionScaleX.toggled.connect(self.on__actionScaleX_toggled)
        self.actionScaleY.toggled.connect(self.on__actionScaleY_toggled)
        self.actionLegend.toggled.connect(self.on__actionLegend_toggled)
        self.actionSymbols.toggled.connect(self.on__actionSymbols_toggled)
        self.actionLines.toggled.connect(self.on__actionLines_toggled)
        self.actionSaveData.triggered.connect(
            self.on__actionSaveData_triggered)
        self.actionFitPeak.triggered.connect(self.on__actionFitPeak_triggered)
        self.actionFitArby.triggered.connect(self.on__actionFitArby_triggered)
        self.actionFitPeakGaussian.triggered.connect(
            self.on__actionFitPeakGaussian_triggered)
        self.actionFitPeakLorentzian.triggered.connect(
            self.on__actionFitPeakLorentzian_triggered)
        self.actionFitPeakPV.triggered.connect(
            self.on__actionFitPeakPV_triggered)
        self.actionFitPeakPVII.triggered.connect(
            self.on__actionFitPeakPVII_triggered)
        self.actionFitTc.triggered.connect(self.on__actionFitTc_triggered)
        self.actionFitCosine.triggered.connect(
            self.on__actionFitCosine_triggered)
        self.actionFitSigmoid.triggered.connect(
            self.on__actionFitSigmoid_triggered)
        self.actionFitLinear.triggered.connect(
            self.on__actionFitLinear_triggered)
        self.actionFitExponential.triggered.connect(
            self.on__actionFitExponential_triggered)
Exemplo n.º 16
0
# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Module authors:
#   Enrico Faulhaber <*****@*****.**>
#
# *****************************************************************************
"""Special widgets for the SANS1 statusmonitor."""


from nicos.core.status import BUSY, DISABLED, ERROR, NOTREACHED, OK, UNKNOWN, \
    WARN
from nicos.guisupport.qt import QBrush, QColor, QPainter, QPen, QSize, Qt, \
    QWidget
from nicos.guisupport.widget import NicosWidget, PropDef

_magenta = QBrush(QColor('#A12F86'))
_yellow = QBrush(QColor('yellow'))
_white = QBrush(QColor('white'))
_grey = QBrush(QColor('lightgrey'))
_black = QBrush(QColor('black'))
_blue = QBrush(QColor('blue'))
_red = QBrush(QColor('red'))
_olive = QBrush(QColor('olive'))
_orange = QBrush(QColor('#ffa500'))

statusbrush = {
    BUSY: _yellow,
    WARN: _orange,
    ERROR: _red,
    NOTREACHED: _red,
    DISABLED: _white,
Exemplo n.º 17
0
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Module authors:
#   Georg Brandl <*****@*****.**>
#
# *****************************************************************************

from nicos.core.status import BUSY, DISABLED, ERROR, NOTREACHED, OK, UNKNOWN, \
    WARN
from nicos.guisupport.qt import QBrush, QColor, QPainter, QPen, QSize, Qt, \
    QWidget
from nicos.guisupport.utils import scaledFont
from nicos.guisupport.widget import NicosWidget, PropDef

_yellow = QBrush(QColor('yellow'))
_white = QBrush(QColor('white'))
_grey = QBrush(QColor('lightgrey'))
_red = QBrush(QColor('red'))
_olive = QBrush(QColor('olive'))
_orange = QBrush(QColor('#ffa500'))
_black = QBrush(QColor('black'))
_blue = QBrush(QColor('blue'))
_green = QBrush(QColor('#00cc00'))

statusbrush = {
    BUSY: _yellow,
    WARN: _orange,
    ERROR: _red,
    NOTREACHED: _red,
    DISABLED: _white,
Exemplo n.º 18
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setBrush(QBrush(self.color))
        painter.setRenderHint(QPainter.Antialiasing)

        fontscale = float(self._scale)
        h = self.props['height'] * fontscale
        w = self.props['width'] * fontscale
        posscale = (w - 100) / self.props['posscale']

        # Draw name above tube
        if self.props['name']:
            painter.setFont(self.font())
            painter.drawText(5, 0, w, fontscale * 2.5, Qt.AlignCenter,
                             self.props['name'])
            yoff = fontscale * 2.5
        elif self.props['smalldet']:
            yoff = 50
        else:
            yoff = 0

        # Draw tube
        painter.setPen(self.color)
        painter.drawEllipse(5, 5 + yoff, 50, h)
        painter.drawRect(30, 5 + yoff, w - 50, h)
        painter.setPen(QColor('black'))
        painter.drawArc(5, 5 + yoff, 50, h, 1440, 2880)
        painter.drawLine(30, 5 + yoff, w - 25, 5 + yoff)
        painter.drawLine(30, 5 + yoff + h, w - 25, 5 + yoff + h)
        painter.drawEllipse(w - 45, 5 + yoff, 50, h)

        if self.props['smalldet']:
            sw = 20
            sx = 30 + self.props['smalldet'] * posscale
            painter.setPen(self.color)
            painter.drawRect(sx - sw, 2, 2 * sw, yoff + 10)
            painter.setPen(QColor('black'))
            painter.drawLine(sx - sw, 5 + yoff, sx - sw, 2)
            painter.drawLine(sx - sw, 2, sx + sw, 2)
            painter.drawLine(sx + sw, 2, sx + sw, 5 + yoff)

        # draw detector
        pos_val = self._curval[0]
        if pos_val is not None:
            pos_status = self._curstatus[0]
            pos_str = self._curstr[0]
            x_val = self._curval[1]
            x_status = self._curstatus[1]
            x_str = '%.1f x' % x_val
            y_val = self._curval[2]
            y_status = self._curstatus[2]
            y_str = '%.1f y' % y_val

            stat = max(pos_status, x_status, y_status)
            painter.setBrush(statusbrush[stat])
            painter.setFont(self.valueFont)
            painter.resetTransform()
            # Translate to detector position
            xp = 30 + pos_val * posscale
            painter.translate(xp + fontscale / 2., 15 + yoff + (h - 20) / 2.)
            painter.drawRect(-fontscale / 2., -(h - 20) / 2., fontscale,
                             h - 20)
            painter.resetTransform()
            # Put X/Y values left or right of detector depending on position
            if pos_val < 14:
                xoff = 2 * fontscale
            else:
                xoff = -8.5 * fontscale
            # X translation
            painter.drawText(xp + xoff, yoff + 2 * fontscale, 7 * fontscale,
                             2 * fontscale, Qt.AlignRight, x_str)
            # Y translation
            painter.drawText(xp + xoff, yoff + 3.5 * fontscale, 7 * fontscale,
                             2 * fontscale, Qt.AlignRight, y_str)
            # Z position
            minx = max(0, xp + 5 - 4 * fontscale)
            painter.drawText(minx, h + 10 + yoff, 8 * fontscale, 30,
                             Qt.AlignCenter, pos_str)

            # draw beamstop
            if self.props['beamstop']:
                painter.setPen(QPen(_blue.color()))
                painter.drawRect(xp - 8,
                                 yoff + 15 + posscale / 350 * (1100 - y_val),
                                 2, 10)

        # draw small detector
        if self.props['smalldet'] and self._curval[4] is not None:
            x_status = self._curstatus[3]
            x_str = '%4.1f x' % self._curval[3]
            y_status = self._curstatus[4]
            y_val = self._curval[4]
            y_str = '%4.0f y' % y_val
            stat = max(x_status, y_status)

            painter.setBrush(statusbrush[stat])
            painter.setPen(QPen(_black.color()))
            painter.setFont(self.valueFont)
            sy = 10 + y_val * posscale / 250
            painter.drawRect(sx - fontscale / 2., sy, fontscale, 30)

            painter.drawText(sx - 10.5 * fontscale, sy, 8 * fontscale,
                             2 * fontscale, Qt.AlignRight, x_str)
            painter.drawText(sx - 10.5 * fontscale, sy + 1.5 * fontscale,
                             8 * fontscale, 2 * fontscale, Qt.AlignRight,
                             y_str)
Exemplo n.º 19
0
from nicos.utils.loggers import ACTION, INPUT

levels = {
    DEBUG: 'DEBUG',
    INFO: 'INFO',
    WARNING: 'WARNING',
    ERROR: 'ERROR',
    FATAL: 'FATAL'
}

# text formats for the output view

std = QTextCharFormat()

grey = QTextCharFormat()
grey.setForeground(QBrush(QColor('grey')))

red = QTextCharFormat()
red.setForeground(QBrush(QColor('red')))

magenta = QTextCharFormat()
magenta.setForeground(QBrush(QColor('#C000C0')))

bold = QTextCharFormat()
bold.setFontWeight(QFont.Bold)

redbold = QTextCharFormat()
redbold.setForeground(QBrush(QColor('red')))
redbold.setFontWeight(QFont.Bold)

# REs for hyperlinks
Exemplo n.º 20
0
 def __init__(self, x, y, size=50, parent=None, scene=None):
     TableBase.__init__(self, x, y, size, parent, scene)
     self.setBrush(QBrush())
     pen = QPen(QColor('black'))
     pen.setStyle(Qt.DashLine)
     self.setPen(pen)
Exemplo n.º 21
0
#
# *****************************************************************************

from __future__ import absolute_import, division, print_function

from nicos.core.status import OK
from nicos.guisupport.qt import QBrush, QColor, QPainter, QPen, QPointF, \
    QPolygonF, QSize, Qt, QWidget
from nicos.guisupport.widget import NicosWidget, PropDef
from nicos.utils import readonlylist

from nicos_mlz.refsans.gui.refsansview import RefsansView
from nicos_mlz.refsans.gui.timedistancewidget import TimeDistanceWidget
from nicos_mlz.sans1.gui.monitorwidgets import CollimatorTable

_yellow = QBrush(QColor('yellow'))
_white = QBrush(QColor('white'))
_red = QBrush(QColor('#FF3333'))
_nobrush = QBrush()

nopen = QPen(QColor('white'))
defaultpen = QPen(QColor('black'))
beampen = QPen(QColor('blue'))
monopen = QPen(QColor('black'))
monopen.setWidth(3)
beambackgroundpen = QPen(QColor('white'))
beambackgroundpen.setWidth(4)
samplepen = QPen(QColor('#006600'))
samplepen.setWidth(2)
samplebrush = QBrush(QColor('#006600'))
samplecoordpen = QPen(QColor('#666666'))
Exemplo n.º 22
0
from nicos.clients.gui.dialogs.error import ErrorDialog
from nicos.clients.gui.panels import Panel, showPanel
from nicos.clients.gui.utils import ScriptExecQuestion, dialogFromUi, loadUi
from nicos.core.status import BUSY, DISABLED, ERROR, NOTREACHED, OK, UNKNOWN, \
    WARN
from nicos.guisupport.qt import QBrush, QByteArray, QColor, QComboBox, \
    QCursor, QDialog, QDialogButtonBox, QFont, QIcon, QInputDialog, QMenu, \
    QMessageBox, QPalette, QPushButton, QRegExp, Qt, QTreeWidgetItem, \
    pyqtSignal, pyqtSlot, sip
from nicos.guisupport.typedvalue import DeviceParamEdit, DeviceValueEdit
from nicos.protocols.cache import OP_TELL, cache_dump, cache_load
from nicos.pycompat import iteritems, itervalues, srepr, string_types
from nicos.utils import AttrDict

foregroundBrush = {
    OK: QBrush(QColor('#00aa00')),
    WARN: QBrush(Qt.black),
    BUSY: QBrush(Qt.black),
    NOTREACHED: QBrush(Qt.black),
    DISABLED: QBrush(Qt.black),
    ERROR: QBrush(Qt.black),
    UNKNOWN: QBrush(QColor('#cccccc')),
}

backgroundBrush = {
    OK: QBrush(),
    WARN: QBrush(QColor('#ffa500')),
    BUSY: QBrush(Qt.yellow),
    NOTREACHED: QBrush(QColor('#ff6655')),
    DISABLED: QBrush(QColor('#bbbbbb')),
    ERROR: QBrush(QColor('#ff6655')),
Exemplo n.º 23
0
 def formatMessage(self, message, actions=True):
     # message is a sequence:
     # (logger, time, levelno, message, exc_text, reqid)
     fmt = None
     levelno = message[2]
     if message[0] == 'nicos':
         name = ''
     else:
         name = '%-10s: ' % message[0]
     if message[5] == '0':  # simulation result started by console
         name = '(sim) ' + name
     if levelno == ACTION:
         if actions and self._actionlabel:
             action = message[3].strip()
             if action:
                 self._actionlabel.setText('Status: ' + action)
                 self._actionlabel.show()
             else:
                 self._actionlabel.hide()
         return '', None
     elif levelno <= DEBUG:
         text = name + message[3]
         fmt = grey
     elif levelno <= INFO:
         if message[3].startswith('  > '):
             fmt = QTextCharFormat(bold)
             fmt.setAnchor(True)
             command = to_utf8(message[3][4:].strip())
             fmt.setAnchorHref('exec:' + urllib.parse.quote(command))
             return name + message[3], fmt
         text = name + message[3]
     elif levelno == INPUT:
         m = command_re.match(message[3])
         if m:
             fmt = QTextCharFormat(bold)
             fmt.setAnchor(True)
             command = to_utf8(m.group(2))
             fmt.setAnchorHref('exec:' + urllib.parse.quote(command))
             if m.group(1) != self._currentuser:
                 fmt.setForeground(QBrush(QColor('#0000C0')))
             return message[3], fmt
         m = script_re.match(message[3])
         if m:
             fmt = QTextCharFormat(bold)
             if m.group(2):
                 command = to_utf8(m.group(2))
                 fmt.setAnchor(True)
                 fmt.setAnchorHref('edit:' + urllib.parse.quote(command))
             if m.group(1) != self._currentuser:
                 fmt.setForeground(QBrush(QColor('#0000C0')))
             return message[3], fmt
         m = update_re.match(message[3])
         if m:
             fmt = QTextCharFormat(bold)
             if m.group(2):
                 command = to_utf8(m.group(2))
                 fmt.setAnchor(True)
                 fmt.setAnchorHref('edit:' + urllib.parse.quote(command))
             if m.group(1) != self._currentuser:
                 fmt.setForeground(QBrush(QColor('#006090')))
             else:
                 fmt.setForeground(QBrush(QColor('#00A000')))
             return message[3], fmt
         return message[3], bold
     elif levelno <= WARNING:
         text = levels[levelno] + ': ' + name + message[3]
         fmt = magenta
     else:
         text = levels[levelno] + self.formatImportantTime(message[1]) + \
             name + message[3]
         fmt = redbold
     if message[4] and fmt:
         # need to construct a new unique object for this
         fmt = QTextCharFormat(fmt)
         # show traceback info on click
         fmt.setAnchor(True)
         tbinfo = to_utf8(message[4])
         fmt.setAnchorHref('trace:' + urllib.parse.quote(tbinfo))
     return text, fmt
Exemplo n.º 24
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setBrush(QBrush(self.color))
        painter.setRenderHint(QPainter.Antialiasing)

        fontscale = float(self._scale)
        h = self.props['height'] * fontscale
        w = self.props['width'] * fontscale
        posscale = (w - 120) / self.props['posscale']

        if self.props['name']:
            painter.setFont(self.font())
            painter.drawText(5, 0, w, fontscale * 2.5, Qt.AlignCenter,
                             self.props['name'])
            yoff = fontscale * 2.5
        else:
            yoff = 0

        painter.setPen(self.color)
        painter.drawEllipse(5, 5 + yoff, 50, h)
        painter.drawRect(30, 5 + yoff, w - 50, h)
        painter.setPen(QColor('black'))
        painter.drawArc(5, 5 + yoff, 50, h, 1440, 2880)
        painter.drawLine(30, 5 + yoff, w - 25, 5 + yoff)
        painter.drawLine(30, 5 + yoff + h, w - 25, 5 + yoff + h)
        painter.drawEllipse(w - 45, 5 + yoff, 50, h)

        # draw Detector 1
        minx = 0
        pos_val = self._curval[0]
        if pos_val is not None:
            pos_status = self._curstatus[0]
            pos_str = self._curstr[0]
            shift_val = self._curval[1]
            shift_status = self._curstatus[1]
            shift_str = self._curstr[1]
            if shift_val > 0:
                shift_str += ' ↓'
            elif shift_val < 0:
                shift_str += ' ↑'
            # Not used at the moment, prepared for later use
            tilt_val = self._curval[2]
            tilt_status = self._curstatus[2]
            tilt_str = self._curstr[2]
            if tilt_str.endswith('deg'):
                tilt_str = tilt_str[:-3] + '°'

            stat = max(pos_status, shift_status, tilt_status)
            painter.setBrush(statusbrush[stat])
            # tf = QTransform()
            # tf.rotate(tilt_val)
            painter.resetTransform()
            painter.translate(60 + pos_val * posscale + fontscale / 2.,
                              15 + yoff + shift_val * posscale + (h - 20) / 2.)
            painter.rotate(-tilt_val)
            painter.drawRect(-fontscale / 2., -(h - 20) / 2., fontscale,
                             h - 20)  # XXX tilt ???
            painter.resetTransform()
            painter.setFont(self.valueFont)
            painter.drawText(
                60 + pos_val * posscale - 10.5 * fontscale,
                -5 + yoff + h - fontscale,  # + (shift_val - 4) * posscale,
                9.5 * fontscale,
                2 * fontscale,
                Qt.AlignRight,
                tilt_str)
            painter.drawText(
                60 + pos_val * posscale - 6.5 * fontscale,
                yoff + fontscale,  # + (shift_val - 4) * posscale,
                9.5 * fontscale,
                2 * fontscale,
                Qt.AlignLeft,
                shift_str)
            minx = max(minx, 60 + pos_val * posscale + 5 - 4 * fontscale)
            painter.drawText(minx, h + 10 + yoff, 8 * fontscale, 30,
                             Qt.AlignCenter, pos_str)
            minx = minx + 8 * fontscale
Exemplo n.º 25
0
 def __init__(self, offset, view):
     QStyledItemDelegate.__init__(self, view)
     self._icon_offset = offset
     self._margin_offset = 0
     self._pen = QPen(QBrush(QColor('grey')), 1)