コード例 #1
0
ファイル: ColorBox.py プロジェクト: yehan0223/Slicer
    def addRow(self, c):
        name = self.colorNode.GetColorName(c)
        lut = self.colorNode.GetLookupTable()
        rgb = lut.GetTableValue(c)
        brush = qt.QBrush()
        self.brushes.append(brush)
        color = qt.QColor()
        color.setRgb(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255)
        brush.setColor(color)

        # index
        item = qt.QStandardItem()
        item.setText(str(c))
        self.model.setItem(self.row, 0, item)
        self.items.append(item)
        # color
        item = qt.QStandardItem()
        item.setData(color, 1)
        self.model.setItem(self.row, 1, item)
        self.items.append(item)
        # name
        item = qt.QStandardItem()
        item.setText(self.colorNode.GetColorName(c))
        self.model.setItem(self.row, 2, item)
        self.items.append(item)
        self.row += 1
コード例 #2
0
def make():
    # create a plot with a white canvas
    demo = Qwt.QwtPlot(Qwt.QwtText("Errorbar Demonstation"))
    demo.setCanvasBackground(qt.Qt.white)
    demo.plotLayout().setAlignCanvasToScales(True)

    grid = Qwt.QwtPlotGrid()
    grid.attach(demo)
    grid.setPen(qt.QPen(qt.Qt.black, 0, qt.Qt.DotLine))

    # calculate data and errors for a curve with error bars
    x = arange(0, 10.1, 0.5, Float)
    y = sin(x)
    dy = 0.2 * abs(y)
    # dy = (0.15 * abs(y), 0.25 * abs(y)) # uncomment for asymmetric error bars
    dx = 0.2  # all error bars the same size
    errorOnTop = False  # uncomment to draw the curve on top of the error bars
    # errorOnTop = True # uncomment to draw the error bars on top of the curve
    curve = ErrorBarPlotCurve(
        x=x,
        y=y,
        dx=dx,
        dy=dy,
        curvePen=qt.QPen(qt.Qt.black, 2),
        curveSymbol=Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse, qt.QBrush(qt.Qt.red),
                                  qt.QPen(qt.Qt.black, 2), qt.QSize(9, 9)),
        errorPen=qt.QPen(qt.Qt.blue, 2),
        errorCap=10,
        errorOnTop=errorOnTop,
    )
    curve.attach(demo)
    demo.resize(400, 300)
    demo.show()
    return demo
コード例 #3
0
 def drawContents(self, *args):
     if len(args)==1:
         return apply(qt.QFrame.drawContents, (self,)+args)
     else:
         painter, clipx, clipy, clipw, cliph = args
     color = self.eraseColor()
     painter.fillRect(clipx, clipy, clipw, cliph, qt.QBrush(color))
     qt.QScrollView.drawContents(self, painter, clipx, clipy, clipw, cliph)
コード例 #4
0
    def __init__(self, *args):
        qt.QMainWindow.__init__(self, *args)

        self.plot = Qwt.QwtPlot(self)
        self.plot.setTitle("A Simple Map Demonstration")
        self.plot.setCanvasBackground(qt.Qt.white)
        self.plot.setAxisTitle(Qwt.QwtPlot.xBottom, "x")
        self.plot.setAxisTitle(Qwt.QwtPlot.yLeft, "y")    
        self.plot.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, 1.0)
        self.plot.setAxisScale(Qwt.QwtPlot.yLeft, 0.0, 1.0)
        self.setCentralWidget(self.plot)

        # Initialize map data
        self.count = self.i = 1000
        self.xs = zeros(self.count, Float)
        self.ys = zeros(self.count, Float)

        self.kappa = 0.2

        self.curve = Qwt.QwtPlotCurve("Map")
        self.curve.attach(self.plot)

        self.curve.setSymbol(Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse,
                                           qt.QBrush(qt.Qt.red),
                                           qt.QPen(qt.Qt.blue),
                                           qt.QSize(5, 5)))

        self.curve.setPen(qt.QPen(qt.Qt.cyan))

        toolBar = qt.QToolBar(self)

        qt.QLabel("Count:", toolBar)
        sizeCounter = Qwt.QwtCounter(toolBar)
        toolBar.addSeparator()
        sizeCounter.setRange(0, 1000000, 100)
        sizeCounter.setValue(self.count)
        sizeCounter.setNumButtons(3)
        self.connect(
            sizeCounter, qt.SIGNAL('valueChanged(double)'), self.setCount)

        qt.QLabel("Ticks (ms):", toolBar)
        tickCounter = Qwt.QwtCounter(toolBar)
        toolBar.addSeparator()
        # 1 tick = 1 ms, 10 ticks = 10 ms (Linux clock is 100 Hz)
        self.ticks = 10
        tickCounter.setRange(0, 1000, 1)
        tickCounter.setValue(self.ticks)
        tickCounter.setNumButtons(3)
        self.connect(
            tickCounter, qt.SIGNAL('valueChanged(double)'), self.setTicks)
        self.tid = self.startTimer(self.ticks)

        self.timer_tic = None
        self.user_tic = None
        self.system_tic = None
        
        self.plot.replot()
コード例 #5
0
ファイル: confirm_dialog.py プロジェクト: lgadea/mxcube
    def set_items(self, checked_items):
        self.sample_items = []
        self.files_to_be_written = []
        self.checked_items = checked_items
        collection_items = []
        current_sample_item = None
        num_images = 0

        self.dialog_layout_widget.file_list_view.clear()

        for item in checked_items:
            if isinstance(item, queue_item.SampleQueueItem):
                self.sample_items.append(item)
                current_sample_item = item

            path_template = item.get_model().get_path_template()

            if path_template:
                #                 if item.get_model().is_executed():
                #                     self.item_run_number_list.append((item, path_template.run_number))

                #                     # Increase the run-number for re-collect
                #                     new_run_number = self.queue_model_hwobj.\
                #                                      get_next_run_number(path_template,
                #                                                          exclude_current = False)
                #                     item.get_model().set_number(new_run_number)
                #                     path_template.run_number = new_run_number

                collection_items.append(item)
                file_paths = path_template.get_files_to_be_written()
                num_images += len(file_paths)

                for fp in file_paths:
                    (dir_name, f_name) = os.path.split(fp)
                    sample_name = current_sample_item.get_model(
                    ).get_display_name()

                    if sample_name is '':
                        sample_name = current_sample_item.get_model().loc_str

                    last_item = self.dialog_layout_widget.child(
                        'file_list_view').lastItem()
                    fl = FileListViewItem(
                        self.dialog_layout_widget.file_list_view, last_item,
                        sample_name, dir_name, f_name)

                    if os.path.isfile(fp):
                        fl.set_brush(qt.QBrush(qt.Qt.red))

        num_samples = len(self.sample_items)
        num_collections = len(collection_items)

        self.dialog_layout_widget.\
            summary_label.setText("Collecting " + str(num_collections) + \
                                  " collection(s) on " + str(num_samples) + \
                                  " sample(s) resulting in " + \
                                  str(num_images) + " image(s).")
コード例 #6
0
def _newItemPlaceholderItem(parent):
    palette = parent.palette
    color = qt.QColor(palette.text().color())
    color.setAlphaF(0.5)

    item = qt.QTreeWidgetItem()
    item.setText(0, "(New item)")
    item.setForeground(0, qt.QBrush(color))

    return item
コード例 #7
0
    def paintEvent(self, event):
        p = qt.QPainter()
        p.begin(self)

        n = int(math.sqrt(self.nccds))
        w = self.width()
        h = self.height()
        step_x = w / n
        step_y = h / n
        #logging.getLogger().info("%s", self.temp_list)

        for i in range(n):
            x = step_x * i
            y = step_y * i

            for j in range(n):
                t = self.temp_list[j * 3 + i]
                if t is None:
                    c_b = 255
                    c_g = 255
                    c_r = 255
                else:
                    #logging.getLogger().info("%d", j*3+i)
                    c_b = 255 - int((255 / 40.0) * t + 255)
                    if c_b > 255:
                        c_b = 255
                    elif c_b < 0:
                        c_b = 0
                    c_g = int((255 / 40.0) * t + 255)
                    if c_g > 255:
                        c_g = 0
                    elif c_g < 0:
                        c_g = 0
                    if c_g > 0 and c_b > 0:
                        c_r = 0
                    else:
                        c_r = 255 - c_b
                c = qt.QColor(c_r, c_g, c_b)
                brush = qt.QBrush(c)
                p.fillRect(x + 1, j * step_y + 1, x + step_x - 1,
                           (j + 1) * step_y - 1, brush)

            p.setPen(qt.QPen(qt.QColor(0, 0, 0)))
            #logging.getLogger().info("%d %d", x, y)
            p.drawLine(x, 0, x, h)
            p.drawLine(0, y, w, y)

        p.end()
        return qt.QWidget.paintEvent(self, event)
コード例 #8
0
    def drawShape(self, painter):
        self.__painter = painter
        rect = self.rect()

        self.__num_cells = 0
        num_rows = (rect.bottom() - rect.top()) / self.__cell_height
        num_colls = (rect.right() - rect.left()) / self.__cell_width

        for i in range(0, num_rows + 1):
            offset = i * self.__cell_height
            self.__height = offset
            painter.drawLine(rect.left(),
                             rect.top() + offset, rect.right(),
                             rect.top() + offset)

        for i in range(0, num_colls + 1):
            offset = i * self.__cell_width
            self.__width = offset
            painter.drawLine(rect.left() + offset, rect.top(),
                             rect.left() + offset, rect.bottom())

        for i in range(0, num_rows):
            row_offset = i * self.__cell_height
            for k in range(0, num_colls):
                coll_offset = k * self.__cell_width
                self.__num_cells += 1
                if not self.__has_data:
                    self.__grid_data[self.__num_cells] = (self.__num_cells,
                                                          (0, 0, 255))

                color = self.__grid_data[self.__num_cells][1]

                painter.setBrush(
                    qt.QBrush(qt.QColor(*color), qt.Qt.Dense4Pattern))
                painter.drawEllipse(rect.left() + coll_offset,
                                    rect.top() + row_offset, self.__beam_width,
                                    self.__beam_height)

                tr = qt.QRect(rect.left() + coll_offset,
                              rect.top() + row_offset, self.__cell_width,
                              self.__cell_height)
                painter.drawText(tr, qt.Qt.AlignCenter, str(self.__num_cells))
コード例 #9
0
    def __init__(self, canvas, parent =None, name ="PrintCanvas", fl =0):
        """
        """
        qtcanvas.QCanvasView.__init__(self, canvas, parent, name, fl)

        self.setAcceptDrops(1)

        self.canvas().setBackgroundColor(qt.QColor(qt.Qt.lightGray))
        self.marginSize = (0, 0)
        self.marginItem = qtcanvas.QCanvasRectangle(0, 0, 0, 0, self.canvas())
        self.marginItem.setBrush(qt.QBrush(qt.Qt.white, qt.Qt.SolidPattern))
        self.marginItem.show()

        self.viewScale = 1

        self.activePen = qt.QPen(qt.Qt.red, 1)

        self.__active_item = None
        self.__moving_start = None
        self.__moving_scale = 0
コード例 #10
0
    def drawShape(self, painter):
        """
        Overloads the QCanvasRectangle drawShape. Performs the drawing of the
        grid.

        :param painter: The QPainter object to use when drawing.
        :type painter: QPainter
        """
        self.__painter = painter
        rect = self.rect()

        self.__num_cells = 0
        num_rows = (rect.bottom() - rect.top()) / self.__cell_height
        num_colls = (rect.right() - rect.left()) / self.__cell_width

        if self.__highlighted:
            painter.setPen(qt.QPen(qt.Qt.green, 0, qt.Qt.SolidLine))
        else:
            painter.setPen(qt.QPen(qt.Qt.black, 0, qt.Qt.DotLine))

        for i in range(0, num_rows + 1):
            offset = i * self.__cell_height
            self.__height = offset
            painter.drawLine(rect.left(),
                             rect.top() + offset, rect.right(),
                             rect.top() + offset)

        for i in range(0, num_colls + 1):
            offset = i * self.__cell_width
            self.__width = offset
            painter.drawLine(rect.left() + offset, rect.top(),
                             rect.left() + offset, rect.bottom())

        for i in range(0, num_rows):
            row_offset = i * self.__cell_height
            for k in range(0, num_colls):
                coll_offset = k * self.__cell_width
                self.__num_cells += 1
                if not self.__has_data:
                    if self.__num_cells % 2:
                        self.__grid_data[self.__num_cells] = (self.__num_cells,
                                                              (0, 0, 150))
                    else:
                        self.__grid_data[self.__num_cells] = (self.__num_cells,
                                                              (0, 0, 150))

                painter.setPen(qt.QPen(qt.Qt.black, 0, qt.Qt.SolidLine))

                color = self.__grid_data[self.__num_cells][1]

                #if self.__highlighted:
                painter.setBrush(
                    qt.QBrush(qt.QColor(*color), qt.Qt.Dense4Pattern))
                #else:
                #    painter.setBrush(qt.QBrush(qt.QColor(*color), qt.Qt.Dense6Pattern))

                beam_hspacing = (self.__cell_width - self.__beam_width) / 2
                beam_vspacing = (self.__cell_height - self.__beam_height) / 2

                painter.drawEllipse(rect.left() + coll_offset + beam_hspacing,
                                    rect.top() + row_offset + beam_vspacing,
                                    self.__beam_width, self.__beam_height)

                painter.setPen(qt.QPen(qt.Qt.black, 1, qt.Qt.SolidLine))
                tr = qt.QRect(rect.left() + coll_offset,
                              rect.top() + row_offset, self.__cell_width,
                              self.__cell_height)

                score = self.__grid_data[self.__num_cells][0]

                if score:
                    painter.drawText(tr, qt.Qt.AlignCenter, str(score))

            if self.__label and self.__highlighted:
                #painter.setPen(qt.QPen(qt.Qt.green, 0, qt.Qt.SolidLine))
                painter.drawText(rect.right() + 2,
                                 rect.top() - 5, self.__label)

        self.__num_rows = num_rows
        self.__num_colls = num_colls
コード例 #11
0
    def __init__(self, *args):
        Qt.QFrame.__init__(self, *args)

        self.xMap = Qwt.QwtScaleMap()
        self.xMap.setScaleInterval(-0.5, 10.5)
        self.yMap = Qwt.QwtScaleMap()
        self.yMap.setScaleInterval(-1.1, 1.1)

        # frame style
        self.setFrameStyle(Qt.QFrame.Box | Qt.QFrame.Raised)
        self.setLineWidth(2)
        self.setMidLineWidth(3)

        # calculate values
        self.x = arange(0, 10.0, 10.0 / 27)
        self.y = sin(self.x) * cos(2 * self.x)

        # make curves with different styles
        self.curves = []
        self.titles = []
        # curve 0
        self.titles.append('Style: Lines/Fitted, Symbol: Cross')
        curve = Qwt.QwtPlotCurve()
        curve.setPen(Qt.QPen(Qt.Qt.darkGreen))
        curve.setStyle(Qwt.QwtPlotCurve.Lines)
        curve.setCurveAttribute(Qwt.QwtPlotCurve.Fitted)
        curve.setSymbol(
            Qwt.QwtSymbol(Qwt.QwtSymbol.Cross, Qt.QBrush(),
                          Qt.QPen(Qt.Qt.black), Qt.QSize(5, 5)))
        self.curves.append(curve)
        # curve 1
        self.titles.append('Style: Sticks, Symbol: Ellipse')
        curve = Qwt.QwtPlotCurve()
        curve.setPen(Qt.QPen(Qt.Qt.red))
        curve.setStyle(Qwt.QwtPlotCurve.Sticks)
        curve.setSymbol(
            Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse, Qt.QBrush(Qt.Qt.yellow),
                          Qt.QPen(Qt.Qt.blue), Qt.QSize(5, 5)))
        self.curves.append(curve)
        # curve 2
        self.titles.append('Style: Lines, Symbol: None')
        curve = Qwt.QwtPlotCurve()
        curve.setPen(Qt.QPen(Qt.Qt.darkBlue))
        curve.setStyle(Qwt.QwtPlotCurve.Lines)
        self.curves.append(curve)
        # curve 3
        self.titles.append('Style: Steps, Symbol: None')
        curve = Qwt.QwtPlotCurve()
        curve.setPen(Qt.QPen(Qt.Qt.darkCyan))
        curve.setStyle(Qwt.QwtPlotCurve.Steps)
        self.curves.append(curve)
        # curve 4
        self.titles.append('Style: NoCurve, Symbol: XCross')
        curve = Qwt.QwtPlotCurve()
        curve.setStyle(Qwt.QwtPlotCurve.NoCurve)
        curve.setSymbol(
            Qwt.QwtSymbol(Qwt.QwtSymbol.XCross, Qt.QBrush(),
                          Qt.QPen(Qt.Qt.darkMagenta), Qt.QSize(5, 5)))
        self.curves.append(curve)

        # attach data, using Numeric
        for curve in self.curves:
            curve.setData(self.x, self.y)
コード例 #12
0
class QueueItem(qt.QCheckListItem):
    """
    Use this class to create a new type of item for the collect tree/queue.
    """

    normal_brush = qt.QBrush(qt.Qt.black)
    highlighted_brush = qt.QBrush(qt.QColor(128, 128, 128))
    normal_pen = qt.QPen(qt.Qt.black)
    highlighted_pen = qt.QPen(qt.QColor(128, 128, 128))
    bg_brush = qt.QBrush(qt.QColor(0, 128, 0))
    bg_normal_brush = qt.QBrush(qt.Qt.white)

    def __init__(self, *args, **kwargs):
        # All subclasses should have the following
        # data attributes.
        self.deletable = kwargs.pop('deletable', False)
        controller = kwargs.pop('controller', None)
        args = args + (controller, )

        #qt.QCheckListItem.__init__(self, *args, **kwargs)
        #IK Python version
        qt.QCheckListItem.__init__(self, *args)

        self.pen = QueueItem.normal_pen
        self.brush = QueueItem.normal_brush
        self.bg_brush = QueueItem.bg_normal_brush
        self.previous_bg_brush = QueueItem.bg_normal_brush
        self._queue_entry = None
        self._data_model = None
        self._checkable = True
        self._font_is_bold = False

    def activate(self):
        """
         Inherited from QCheckListitem, called whenever the user presses the 
         mouse on this item or presses Space on it. 
         """
        if self._checkable:
            qt.QCheckListItem.activate(self)

    def stateChange(self, state):
        if self._checkable:
            qt.QCheckListItem.stateChange(self, state)
            # The QCheckListItem is somewhat tricky:
            # state = 0     The item is unchecked.
            #
            # state = 1     The item is checked but
            #               not all of the children
            #
            # state = 2     The item and all its children are
            #               checked.
            #
            # However the state passed by stateChanged are a boolean
            # we have to use the state() member to get the actual state.
            # Great !

            if self._queue_entry:
                if self.state() > 0:
                    self._queue_entry.set_enabled(True)
                else:
                    self._queue_entry.set_enabled(False)

            if self._data_model:
                if self.state() > 0:
                    self._data_model.set_enabled(True)
                else:
                    self._data_model.set_enabled(False)
        else:
            self.setOn(False)

    def paintCell(self, painter, color_group, column, width, align):
        """
        Inherited from QCheckListItem, called before this item is drawn
        on the screen.

        The qt3 documentation has more information about this method that
        can be worth reading.
        """
        try:
            painter.save()
            f = painter.font()
            f.setBold(self._font_is_bold)
            painter.setFont(f)
            color_group = qt.QColorGroup(color_group)
            color_group.setColor(qt.QColorGroup.Text, self.brush.color())
            color_group.setBrush(qt.QColorGroup.Text, self.brush)
            color_group.setColor(qt.QColorGroup.Base, self.bg_brush.color())

            qt.QCheckListItem.paintCell(self, painter, color_group, column,
                                        width, align)
        finally:
            painter.restore()

    def paintFocus(self, painter, color_group, rect):
        """
        Inherited from QCheckListItem, called when the item get focus.

        The qt3 documentation has more information about this method that
        can be worth reading.
        """

        color_group.setColor(qt.QColorGroup.Text, self.brush.color())
        color_group.setBrush(qt.QColorGroup.Text, self.brush)

        qt.QCheckListItem.paintFocus(self, painter, color_group, rect)

        color_group.setColor(qt.QColorGroup.Text, self.normal_brush.color())
        color_group.setBrush(qt.QColorGroup.Text, self.normal_brush)

    def moveItem(self, after):
        qt.QCheckListItem.moveItem(self, after)
        container_qe = self.get_queue_entry().get_container()
        after_qe = after.get_queue_entry()
        container_qe.swap(after_qe, self.get_queue_entry())

    def setHighlighted(self, enable):
        """
        Controls highlighting of the list item.

        :param enable: Highlighted True, or not highlighted False.  
        :type enable: bool
        """
        if enable:
            self.pen = QueueItem.highlighted_pen
            self.brush = QueueItem.highlighted_brush
        else:
            self.pen = QueueItem.normal_pen
            self.brush = QueueItem.normal_brush

        if self.listView():
            self.listView().triggerUpdate()

    def setBackgroundColor(self, color):
        self.previous_bg_brush = self.bg_brush
        self.bg_brush = qt.QBrush(color)

    def restoreBackgroundColor(self):
        self.bg_brush = self.previous_bg_brush

    def setFontBold(self, state):
        self._font_is_bold = state

    def reset_style(self):
        self.setBackgroundColor(widget_colors.WHITE)
        self.setFontBold(False)
        self.setHighlighted(False)

    def lastItem(self):
        """
        :returns: The last item of this child.
        :rtype: QueueItem
        """
        sibling = self.firstChild()
        last_child = None

        while (sibling):
            last_child = sibling
            sibling = sibling.nextSibling()

        return last_child

    def setOn(self, state):
        if self._checkable:
            qt.QCheckListItem.setOn(self, state)

            if self._queue_entry:
                self._queue_entry.set_enabled(state)

            if self._data_model:
                self._data_model.set_enabled(state)
        else:
            qt.QCheckListItem.setOn(self, False)

    def set_checkable(self, state):
        self._checkable = state

    def set_queue_entry(self, queue_entry):
        self._queue_entry = queue_entry

    def get_queue_entry(self):
        return self._queue_entry

    def get_model(self):
        return self._data_model

    def set_background_color(self, color_index):
        self.setBackgroundColor(widget_colors.QUEUE_ENTRY_COLORS[color_index])
コード例 #13
0
 def setBackgroundColor(self, color):
     self.previous_bg_brush = self.bg_brush
     self.bg_brush = qt.QBrush(color)
コード例 #14
0
    def __init__(self, *args):
        Qwt.QwtPlot.__init__(self, *args)

        self.setTitle('Frequency Response of a 2<sup>nd</sup>-order System')
        self.setCanvasBackground(Qt.Qt.darkBlue)

        # legend
        legend = Qwt.QwtLegend()
        legend.setFrameStyle(Qt.QFrame.Box | Qt.QFrame.Sunken)
        legend.setItemMode(Qwt.QwtLegend.ClickableItem)
        self.insertLegend(legend, Qwt.QwtPlot.BottomLegend)

        # grid
        self.grid = Qwt.QwtPlotGrid()
        self.grid.enableXMin(True)
        self.grid.setMajPen(Qt.QPen(Qt.Qt.white, 0, Qt.Qt.DotLine))
        self.grid.setMinPen(Qt.QPen(Qt.Qt.gray, 0 , Qt.Qt.DotLine))
        self.grid.attach(self)

        # axes
        self.enableAxis(Qwt.QwtPlot.yRight)
        self.setAxisTitle(Qwt.QwtPlot.xBottom, u'\u03c9/\u03c9<sub>0</sub>')
        self.setAxisTitle(Qwt.QwtPlot.yLeft, 'Amplitude [dB]')
        self.setAxisTitle(Qwt.QwtPlot.yRight, u'Phase [\u00b0]')

        self.setAxisMaxMajor(Qwt.QwtPlot.xBottom, 6)
        self.setAxisMaxMinor(Qwt.QwtPlot.xBottom, 10)
        self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine())

        # curves
        self.curve1 = Qwt.QwtPlotCurve('Amplitude')
        self.curve1.setPen(Qt.QPen(Qt.Qt.yellow))
        self.curve1.setYAxis(Qwt.QwtPlot.yLeft)
        self.curve1.attach(self)
        
        self.curve2 = Qwt.QwtPlotCurve('Phase')
        self.curve2.setPen(Qt.QPen(Qt.Qt.cyan))
        self.curve2.setYAxis(Qwt.QwtPlot.yRight)
        self.curve2.attach(self)

        # alias
        fn = self.fontInfo().family()

        # marker
        self.dB3Marker = m = Qwt.QwtPlotMarker()
        m.setValue(0.0, 0.0)
        m.setLineStyle(Qwt.QwtPlotMarker.VLine)
        m.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignBottom)
        m.setLinePen(Qt.QPen(Qt.Qt.green, 2, Qt.Qt.DashDotLine))
        text = Qwt.QwtText('')
        text.setColor(Qt.Qt.green)
        text.setBackgroundBrush(Qt.QBrush(Qt.Qt.red))
        text.setFont(Qt.QFont(fn, 12, Qt.QFont.Bold))
        m.setLabel(text)
        m.attach(self)

        self.peakMarker = m = Qwt.QwtPlotMarker()
        m.setLineStyle(Qwt.QwtPlotMarker.HLine)
        m.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignBottom)
        m.setLinePen(Qt.QPen(Qt.Qt.red, 2, Qt.Qt.DashDotLine))
        text = Qwt.QwtText('')
        text.setColor(Qt.Qt.red)
        text.setBackgroundBrush(Qt.QBrush(self.canvasBackground()))
        text.setFont(Qt.QFont(fn, 12, Qt.QFont.Bold))
        
        m.setLabel(text)
        m.setSymbol(Qwt.QwtSymbol(Qwt.QwtSymbol.Diamond,
                                  Qt.QBrush(Qt.Qt.yellow),
                                  Qt.QPen(Qt.Qt.green),
                                  Qt.QSize(7,7)))
        m.attach(self)

        # text marker
        m = Qwt.QwtPlotMarker()
        m.setValue(0.1, -20.0)
        m.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignBottom)
        text = Qwt.QwtText(
            u'[1-(\u03c9/\u03c9<sub>0</sub>)<sup>2</sup>+2j\u03c9/Q]'
            '<sup>-1</sup>'
            )
        text.setFont(Qt.QFont(fn, 12, Qt.QFont.Bold))
        text.setColor(Qt.Qt.blue)
        text.setBackgroundBrush(Qt.QBrush(Qt.Qt.yellow))
        text.setBackgroundPen(Qt.QPen(Qt.Qt.red, 2))
        m.setLabel(text)
        m.attach(self)

        self.setDamp(0.01)
コード例 #15
0
 def __init__(self, *args, **kwargs):
     qt.QListViewItem.__init__(self, *args)
     self.brush = qt.QBrush(qt.Qt.black)
     self.__normal_brush = qt.QBrush(qt.Qt.black)
コード例 #16
0
ファイル: MarkupEditor.py プロジェクト: pieper/SlicerMorph
    def editMarkups(self, selectOption, fiducialsNode, curveNode, viewNode):

        layoutManager = slicer.app.layoutManager()
        threeDWidget = layoutManager.viewWidget(viewNode)
        threeDView = threeDWidget.threeDView()
        aspectRatio = threeDWidget.width / threeDWidget.height
        className = "vtkMRMLMarkupsDisplayableManager"
        markupsDisplayableManager = threeDView.displayableManagerByClassName(
            className)
        fiducialsWidget = markupsDisplayableManager.GetWidget(
            fiducialsNode.GetDisplayNode())
        fiducialsRepresentation = fiducialsWidget.GetRepresentation()

        cameraNode = slicer.modules.cameras.logic().GetViewActiveCameraNode(
            viewNode)
        camera = cameraNode.GetCamera()
        raswToXYZW = vtk.vtkMatrix4x4()
        modelView = camera.GetModelViewTransformMatrix()
        projection = camera.GetProjectionTransformMatrix(
            aspectRatio, 1, 100)  # near/far are arbitrary
        raswToXYZW.Multiply4x4(projection, modelView, raswToXYZW)

        def rasToColumnRow(ras):
            rasw = *ras, 1
            xyzw = raswToXYZW.MultiplyPoint(rasw)
            x, y = [xyzw[0], xyzw[1]]
            if viewNode.GetRenderMode() == viewNode.Perspective:
                x, y = [x / xyzw[3], y / xyzw[3]]
            column = (x + 1) / 2 * threeDWidget.width
            row = (1 - (y + 1) / 2) * threeDWidget.height
            return column, row

        selectionPolygon = qt.QPolygonF()
        for index in range(curveNode.GetNumberOfControlPoints()):
            ras = [0] * 3
            curveNode.GetNthControlPointPositionWorld(index, ras)
            column, row = rasToColumnRow(ras)
            point = qt.QPointF(column, row)
            selectionPolygon.push_back(point)

        pickImage = qt.QImage(threeDWidget.width, threeDWidget.height,
                              qt.QImage().Format_ARGB32)
        backgroundColor = qt.QColor("#ffffffff")
        pickImage.fill(backgroundColor)

        painter = qt.QPainter()
        painter.begin(pickImage)
        painterPath = qt.QPainterPath()
        painterPath.addPolygon(selectionPolygon)
        brush = qt.QBrush(qt.Qt.SolidPattern)
        painter.setBrush(brush)
        painter.drawPath(painterPath)
        painter.end()

        debugging = False
        if debugging:
            pixmap = qt.QPixmap().fromImage(pickImage)
            slicer.modules.label = qt.QLabel()
            slicer.modules.label.setPixmap(pixmap)
            slicer.modules.label.show()

        visibleCount = 0
        pickedCount = 0
        for index in range(fiducialsNode.GetNumberOfControlPoints()):
            pointVisible = fiducialsRepresentation.GetNthControlPointViewVisibility(
                index)
            if pointVisible:
                visibleCount += 1
            ras = [0] * 3
            fiducialsNode.GetNthControlPointPositionWorld(index, ras)
            column, row = rasToColumnRow(ras)
            if (column >= 0 and column < pickImage.width and row >= 0
                    and row < pickImage.height):
                pickColor = pickImage.pixelColor(column, row)
                picked = (pickColor != backgroundColor)
                if picked:
                    pickedCount += 1
                if selectOption == "set":
                    if pointVisible:
                        fiducialsNode.SetNthControlPointSelected(index, picked)
                    else:
                        fiducialsNode.SetNthControlPointSelected(index, False)
                elif selectOption == "add":
                    if picked and pointVisible:
                        fiducialsNode.SetNthControlPointSelected(index, True)
                elif selectOption == "unset":
                    if picked and pointVisible:
                        fiducialsNode.SetNthControlPointSelected(index, False)
                else:
                    logging.error(f"Unknown selectOption {selectOption}")
コード例 #17
0
ファイル: plot.py プロジェクト: pocketfool/FinancialAnalytics
class StrategyCurve(SeriesCurve):
    """ StrategyCurve(parent, series) -> series curve for drawing a strategy

    """
    Long = base.Directions.Long 
    Short = base.Directions.Short 
    Rev = 1
    NoRev = 0

    signalRes = {
        (Long, NoRev): \
            (qwt.QwtSymbol.UTriangle, 
             qt.QBrush(qt.Qt.green, qt.Qt.SolidPattern), 
             qt.QPen(qt.QColor('white')), qt.QSize(10, 10)),

        (Long, Rev): \
            (qwt.QwtSymbol.UTriangle, 
             qt.QBrush(qt.Qt.green, qt.Qt.SolidPattern), 
             qt.QPen(qt.QColor('black')), qt.QSize(10, 10)),

        (Short, NoRev) : \
            (qwt.QwtSymbol.DTriangle, 
             qt.QBrush(qt.Qt.red, qt.Qt.SolidPattern), 
             qt.QPen(qt.QColor('white')), qt.QSize(10, 10)),

        (Short, Rev) : \
            (qwt.QwtSymbol.DTriangle, 
             qt.QBrush(qt.Qt.red, qt.Qt.SolidPattern), 
             qt.QPen(qt.QColor('black')), qt.QSize(10, 10)),
    }

    def draw(self, painter, xMap, yMap, start, stop):
        """ draw(...) -> called to draw the curve

        """
        plot = self.parentPlot()
        records = [record[0:4] for record in self.series.history]

        for xpos, ypos, sig, rev in records:
            if (not sig) and (not rev):
                continue
            marker = qwt.QwtPlotMarker(plot)
            markerid = plot.insertMarker(marker)
            self.markers.append(marker)
            plot.setMarkerPos(markerid, xpos, ypos)
            sigsym = qwt.QwtSymbol(*self.signalRes[(sig, rev)])
            plot.setMarkerSymbol(markerid, sigsym)

            # brain dead and/or broken
            if 0:
                gridmarkerpen = qt.QPen(
                    qt.QColor(BasePlot.majorGrid[0]), 0, qt.Qt.SolidLine)
                ## horizontal line
                symyline = plot.insertLineMarker("", qwt.QwtPlot.yLeft)
                plot.setMarkerPen(symyline, gridmarkerpen)
                plot.setMarkerYPos(symyline, ypos)
                self.markers.append(plot.marker(symyline))
                ## vertical line
                symxline = plot.insertLineMarker("", qwt.QwtPlot.xTop)
                plot.setMarkerPen(symxline, gridmarkerpen)
                plot.setMarkerXPos(symxline, xpos)
                self.markers.append(plot.marker(symxline))

    def setEnabled(self, checked):
        """ setEnabled(checked) -> toggle this curve and its markers

        """
        for marker in self.markers:
            marker.setEnabled(checked)
        qwt.QwtPlotCurve.setEnabled(self, checked)