Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _updatePrinter(self):
"""Resize :attr:`page`, :attr:`scene` and :attr:`view` to :attr:`printer`
width and height."""
printer = self.printer
assert printer is not None, \
"_updatePrinter should not be called unless a printer is defined"
if self.scene is None:
self.scene = qt.QGraphicsScene()
self.scene.setBackgroundBrush(qt.QColor(qt.Qt.lightGray))
self.scene.setSceneRect(qt.QRectF(0, 0, printer.width(), printer.height()))
if self.page is None:
self.page = qt.QGraphicsRectItem(0, 0, printer.width(), printer.height())
self.page.setBrush(qt.QColor(qt.Qt.white))
self.scene.addItem(self.page)
self.scene.setSceneRect(qt.QRectF(0, 0, printer.width(), printer.height()))
self.page.setPos(qt.QPointF(0.0, 0.0))
self.page.setRect(qt.QRectF(0, 0, printer.width(), printer.height()))
if self.view is None:
self.view = qt.QGraphicsView(self.scene)
self.mainLayout.addWidget(self.view)
self._buildStatusBar()
# self.view.scale(1./self._viewScale, 1./self._viewScale)
self.view.fitInView(self.page.rect(), qt.Qt.KeepAspectRatio)
self._viewScale = 1.00
self._updateTargetLabel()
itemId = matchDict['itemId']
# TODO : delegate the deserialization to the serialized items
if itemId == 'IsoSurfaces':
argsMatch = isoSurfaceArgsRegex.match(matchDict['args'])
if not argsMatch:
# TODO : explicit error
raise ValueError('Failed to parse args "{0}".'
''.format(matchDict['args']))
argsDict = argsMatch.groupdict()
nIso = int(argsDict['nIso'])
if nIso:
for surface in self.getIsosurfaces():
self.removeIsosurface(surface)
for isoIdx in range(nIso):
color = qt.QColor()
stream >> color
level = stream.readDouble()
visible = stream.readBool()
surface = self.addIsosurface(level, color=color)
surface.setVisible(visible)
elif itemId == 'Style':
background = qt.QColor()
foreground = qt.QColor()
highlight = qt.QColor()
stream >> background >> foreground >> highlight
self.setBackgroundColor(background)
self.setForegroundColor(foreground)
self.setHighlightColor(highlight)
else:
raise ValueError('Unknown entry tag {0}.'
''.format(itemId))
def getColor(self):
"""Returns the color used for the profile and ROI
:rtype: QColor
"""
return qt.QColor.fromRgbF(*self._color)
''.format(matchDict['args']))
argsDict = argsMatch.groupdict()
nIso = int(argsDict['nIso'])
if nIso:
for surface in self.getIsosurfaces():
self.removeIsosurface(surface)
for isoIdx in range(nIso):
color = qt.QColor()
stream >> color
level = stream.readDouble()
visible = stream.readBool()
surface = self.addIsosurface(level, color=color)
surface.setVisible(visible)
elif itemId == 'Style':
background = qt.QColor()
foreground = qt.QColor()
highlight = qt.QColor()
stream >> background >> foreground >> highlight
self.setBackgroundColor(background)
self.setForegroundColor(foreground)
self.setHighlightColor(highlight)
else:
raise ValueError('Unknown entry tag {0}.'
''.format(itemId))
def markerColorList(self):
colormap = self.getRawColormap()
name = colormap['name']
if name not in self.__markerColors:
style = self.getCurrentStyle()
if "markers" in style:
colors = []
for c in style["markers"]:
c = qt.QColor(c[0], c[1], c[2])
colors.append(c)
else:
colors = self.createMarkerColors()
self.__markerColors[name] = colors
else:
colors = self.__markerColors[name]
return colors
r, g, b = self._fgcolors[selection][0:3]
if self._fgcolors.shape[-1] == 3:
return qt.QColor(r, g, b)
if self._fgcolors.shape[-1] == 4:
a = self._fgcolors[selection][3]
return qt.QColor(r, g, b, a)
# no fg color given, use black or white
# based on luminosity threshold
elif self._bgcolors is not None:
r, g, b = self._bgcolors[selection][0:3]
lum = 0.21 * r + 0.72 * g + 0.07 * b
if lum < 128:
return qt.QColor(qt.Qt.white)
else:
return qt.QColor(qt.Qt.black)
def disabledMarkerColor(self):
style = self.getCurrentStyle()
color = style.get("disabled-marker", None)
if color is None:
color = [128, 128, 128]
return qt.QColor(*color)
def icon(self):
pixmap = qt.QPixmap(2, 2)
painter = qt.QPainter(pixmap)
painter.setPen(qt.QColor(255, 0, 0))
painter.drawPoint(qt.QPoint(0, 0))
painter.setPen(qt.QColor(255, 255, 0))
painter.drawPoint(qt.QPoint(1, 0))
painter.setPen(qt.QColor(0, 255, 0))
painter.drawPoint(qt.QPoint(0, 1))
painter.setPen(qt.QColor(0, 255, 255))
painter.drawPoint(qt.QPoint(1, 1))
painter.end()
pixmap = pixmap.scaled(32, 32, qt.Qt.IgnoreAspectRatio, qt.Qt.FastTransformation)
return qt.QIcon(pixmap)
def _updateColorGradient(self):
"""Compute the color gradient"""
colormap = self.getColormap()
if colormap is None:
return
indices = numpy.linspace(0., 1., self._NB_CONTROL_POINTS)
colors = colormap.getNColors(nbColors=self._NB_CONTROL_POINTS)
self._gradient = qt.QLinearGradient(0, 1, 0, 0)
self._gradient.setCoordinateMode(qt.QGradient.StretchToDeviceMode)
self._gradient.setStops(
[(i, qt.QColor(*color)) for i, color in zip(indices, colors)]
)
def getForegroundColor(self):
"""Return color used for bounding box
:rtype: QColor
"""
return qt.QColor.fromRgbF(*self._foregroundColor)