示例#1
0
文件: label.py 项目: mindw/guiqwt
 def get_legend_items(self):
     plot = self.plot()
     if plot is None:
         return []
     text_items = []
     for item in plot.get_items():
         if not isinstance(item, CurveItem) or not self.include_item(item):
             continue
         text = QTextDocument()
         text.setDefaultFont(self.font)
         text.setDefaultStyleSheet('div { color: %s; }' % self.color)
         text.setHtml("<div>%s</div>" % item.curveparam.label)
         text_items.append((text, item.pen(), item.brush(), item.symbol()))
     return text_items
示例#2
0
文件: label.py 项目: stonebig/guiqwt
 def get_legend_items(self):
     plot = self.plot()
     if plot is None:
         return []
     text_items = []
     for item in plot.get_items():
         if not isinstance(item, CurveItem) or not self.include_item(item):
             continue
         text = QTextDocument()
         text.setDefaultFont(self.font)
         text.setDefaultStyleSheet("div { color: %s; }" % self.color)
         text.setHtml("<div>%s</div>" % item.curveparam.label)
         text_items.append((text, item.pen(), item.brush(), item.symbol()))
     return text_items
示例#3
0
文件: label.py 项目: stonebig/guiqwt
 def __init__(self, text=None, labelparam=None):
     self.text_string = "" if text is None else text
     self.text = QTextDocument()
     super(LabelItem, self).__init__(labelparam)
示例#4
0
文件: label.py 项目: stonebig/guiqwt
class LabelItem(AbstractLabelItem):
    __implements__ = (IBasePlotItem, ISerializableType)

    def __init__(self, text=None, labelparam=None):
        self.text_string = "" if text is None else text
        self.text = QTextDocument()
        super(LabelItem, self).__init__(labelparam)

    def __reduce__(self):
        return (self.__class__, (self.text_string, self.labelparam))

    def serialize(self, writer):
        """Serialize object to HDF5 writer"""
        super(LabelItem, self).serialize(writer)
        writer.write(self.text_string, group_name="text")

    def deserialize(self, reader):
        """Deserialize object from HDF5 reader"""
        super(LabelItem, self).deserialize(reader)
        self.set_text(reader.read("text", func=reader.read_unicode))

    def types(self):
        return (IShapeItemType, ISerializableType)

    def set_pos(self, x, y):
        self.G = x, y
        self.labelparam.xg, self.labelparam.yg = x, y

    def get_plain_text(self):
        return to_text_string(self.text.toPlainText())

    def set_text(self, text=None):
        if text is not None:
            self.text_string = text
        self.text.setHtml("<div>%s</div>" % self.text_string)

    def set_text_style(self, font=None, color=None):
        if font is not None:
            self.text.setDefaultFont(font)
        if color is not None:
            self.text.setDefaultStyleSheet("div { color: %s; }" % color)
        self.set_text()

    def get_text_rect(self):
        sz = self.text.size()
        return QRectF(0, 0, sz.width(), sz.height())

    def update_text(self):
        pass

    def draw(self, painter, xMap, yMap, canvasRect):
        self.update_text()
        x, y = self.get_top_left(xMap, yMap, canvasRect)
        x0, y0 = self.get_origin(xMap, yMap, canvasRect)
        painter.save()
        self.marker.draw(painter, x0, y0)
        painter.restore()
        sz = self.text.size()
        self.draw_frame(painter, x, y, sz.width(), sz.height())
        painter.setPen(QPen(QColor(self.labelparam.color)))
        painter.translate(x, y)
        self.text.drawContents(painter)
示例#5
0
文件: label.py 项目: mindw/guiqwt
 def __init__(self, text=None, labelparam=None):
     self.text_string = '' if text is None else text
     self.text = QTextDocument()
     super(LabelItem, self).__init__(labelparam)
示例#6
0
文件: label.py 项目: mindw/guiqwt
class LabelItem(AbstractLabelItem):
    __implements__ = (IBasePlotItem, ISerializableType)

    def __init__(self, text=None, labelparam=None):
        self.text_string = '' if text is None else text
        self.text = QTextDocument()
        super(LabelItem, self).__init__(labelparam)
    
    def __reduce__(self):
        return (self.__class__, (self.text_string, self.labelparam))
    
    def serialize(self, writer):
        """Serialize object to HDF5 writer"""
        super(LabelItem, self).serialize(writer)
        writer.write(self.text_string, group_name='text')
    
    def deserialize(self, reader):
        """Deserialize object from HDF5 reader"""
        super(LabelItem, self).deserialize(reader)
        self.set_text(reader.read('text', func=reader.read_unicode))

    def types(self):
        return (IShapeItemType, ISerializableType)

    def set_pos(self, x, y):
        self.G = x, y
        self.labelparam.xg, self.labelparam.yg = x, y
        
    def get_plain_text(self):
        return to_text_string(self.text.toPlainText())
        
    def set_text(self, text=None):
        if text is not None:
            self.text_string = text
        self.text.setHtml("<div>%s</div>" % self.text_string)
        
    def set_text_style(self, font=None, color=None):
        if font is not None:
            self.text.setDefaultFont(font)
        if color is not None:
            self.text.setDefaultStyleSheet('div { color: %s; }' % color)
        self.set_text()

    def get_text_rect(self):
        sz = self.text.size()
        return QRectF(0, 0, sz.width(), sz.height())

    def update_text(self):
        pass

    def draw(self, painter, xMap, yMap, canvasRect):
        self.update_text()
        x, y = self.get_top_left(xMap, yMap, canvasRect)
        x0, y0 = self.get_origin(xMap, yMap, canvasRect)
        painter.save()
        self.marker.drawSymbols(painter, [QPointF(x0, y0)])
        painter.restore()
        sz = self.text.size()
        self.draw_frame(painter, x, y, sz.width(), sz.height())
        painter.setPen(QPen(QColor(self.labelparam.color)))
        painter.translate(x, y)
        self.text.drawContents(painter)