def drawButton(self, down): """ drawButton(down: bool) -> None Custom draw function """ self.picture = QtGui.QPicture() painter = QtGui.QPainter() painter.begin(self.picture) painter.setRenderHints(QtGui.QPainter.Antialiasing, False) pen = QtGui.QPen(QtCore.Qt.SolidLine) pen.setWidth(1) pen.setCapStyle(QtCore.Qt.RoundCap) brush = QtGui.QBrush(QtCore.Qt.NoBrush) if (down): pen.setColor(QtGui.QColor(150, 150, 150, 150)) else: pen.setColor(QtGui.QColor(0, 0, 0, 255)) painter.setPen(pen) painter.setBrush(brush) painter.drawRect(0, 0, 8, 8) painter.drawLine(QtCore.QLine(4, 2, 4, 6)) painter.drawLine(QtCore.QLine(2, 4, 6, 4)) painter.end() self.setPicture(self.picture)
def resizeEvent(self, event=None): chart_widget_base.ChartWidgetBase.resizeEvent(self, event) ur8root = self.teeth[1].root ul8root = self.teeth[16].root lr8root = self.teeth[17].root ll8root = self.teeth[32].root #this next calulation gives a value for a 1mm depth self.perio_mm = ur8root.rect.height() * 0.035 self.upper_perio_lines, self.lower_perio_lines = [], [] for row_no in range(1, 9): offset = row_no * self.perio_mm * 2 line = QtCore.QLine(ur8root.rect.x(), ur8root.rect.y() + offset, ul8root.rect.topRight().x(), ul8root.rect.topRight().y() + offset) self.upper_perio_lines.append(line) line = QtCore.QLine(ll8root.rect.x(), ll8root.rect.bottomLeft().y() - offset, lr8root.rect.topRight().x(), lr8root.rect.bottomRight().y() - offset) self.lower_perio_lines.append(line)
def paintMe(self, qp, position): if (self.selected): qp.setPen(QtGui.QColor('red')) else: qp.setPen(QtGui.QPen(QtCore.Qt.blue, 4, QtCore.Qt.SolidLine)) p1, p2 = self.luk.additional_line p1, p2 = self.tmp_convert2(p1), self.tmp_convert2(p2) pos1x, pos1y = position.deg2num(p1[0], p1[1]) pos2x, pos2y = position.deg2num(p2[0], p2[1]) arcx, arcy = self.luk.arc_center arc1x, arc1y = position.deg2num( *self.tmp_convert2((arcx - self.luk.arc_radius, arcy - self.luk.arc_radius))) arc2x, arc2y = position.deg2num( *self.tmp_convert2((arcx + self.luk.arc_radius, arcy + self.luk.arc_radius))) arcx, rx = min(arc1x, arc2x), max(arc1x, arc2x) - min(arc1x, arc2x) arcy, ry = min(arc1y, arc2y), max(arc1y, arc2y) - min(arc1y, arc2y) rect = QtCore.QRectF(arcx, arcy, rx, ry) qline = QtCore.QLine(pos1x, pos1y, pos2x, pos2y) qp.drawLine(qline) foo, k1, k2 = self.luk.get_pygame_arc() qp.drawArc(rect, k1 / 3.142 * 180 * -16, LLuk.right3(k1, k2) / 3.142 * 180 * -16) #print(k1/3.142*180) #print(LLuk.right3(k1,k2)/3.142*180) qp.setPen(QtGui.QColor('black')) qp.setPen(1)
def paintEvent(self, event): retval = super(PMXCodeEdit, self).paintEvent(event) font_metrics = QtGui.QFontMetrics(self.document().defaultFont()) if self.multiEditMode: painter = QtGui.QPainter(self.viewport()) extraSelections = [] for cursor in self.cursors: if cursor.hasSelection(): selection = QtGui.QTextEdit.ExtraSelection() selection.format.setBackground(QtCore.Qt.gray) selection.format.setProperty( QtGui.QTextFormat.FullWidthSelection, True) selection.cursor = cursor extraSelections.append(selection) rec = self.cursorRect(cursor) cursor = QtCore.QLine( rec.x(), rec.y(), rec.x(), rec.y() + font_metrics.ascent() + font_metrics.descent()) painter.setPen(QtGui.QPen(QtCore.Qt.blue)) painter.drawLine(cursor) self.setExtraSelections(extraSelections) if self.cursors.isDragCursor: pen = QtGui.QPen(QtCore.Qt.blue) pen.setWidth(2) painter.setPen(pen) color = QtGui.QColor(QtCore.Qt.yellow) color.setAlpha(128) painter.setBrush(QtGui.QBrush(color)) painter.setOpacity(0.2) painter.drawRect(self.cursors.getDragCursorRect()) painter.end() return retval
def paintObject(self, p): p.setBrush(QtGui.QColor("Black")) if self.port & self.LEFT: p.drawRect(0, 43, 10, 5) if self.port & self.RIGHT: p.drawRect(80, 43, 10, 5) if self.port & self.TOP: p.drawRect(43, 0, 5, 10) p.setBrush(self.statusc[self.status]) r = 35 p.setPen(QtGui.QPen(QtGui.QColor("Black"), 2)) p.drawEllipse(10, 10, r * 2, r * 2) a = (10 + r) + (r * math.sin(10 * math.pi / 180)) b = (10 + r) + (r * math.cos(10 * math.pi / 180)) c = (10 + r) + (r * math.sin(100 * math.pi / 180)) d = (10 + r) + (r * math.cos(100 * math.pi / 180)) p.drawLine(a, b, c, d) a = (10 + r) + (r * math.sin(-10 * math.pi / 180)) b = (10 + r) + (r * math.cos(-10 * math.pi / 180)) c = (10 + r) + (r * math.sin(-100 * math.pi / 180)) d = (10 + r) + (r * math.cos(-100 * math.pi / 180)) p.drawLine(a, b, c, d) if self.type == self.ION: # Ion pump # Three arrows from center arrow = QtGui.QPolygon(3) line = QtCore.QLine(0, 0, 0, 20) matrix = QtGui.QMatrix() arrow.setPoints(-5, -5, 5, -5, 0, 5) arrow.translate(0, 20) for i in range(3): matrix.rotate(120) a = matrix.map(arrow) b = matrix.map(line) a.translate(10 + r, 10 + r) b.translate(10 + r, 10 + r) p.setPen(QtGui.QPen(QtGui.QColor("Black"), 1)) p.setBrush(QtGui.QColor("Black")) p.drawPolygon(a) p.setPen(QtGui.QPen(QtGui.QColor("Black"), 2)) p.drawLine(b) elif self.type == self.TURBO: p.drawEllipse(10 + r / 2, 10 + r / 2, r, r) p.drawEllipse(10 + (r * 3 / 4), 10 + (r * 3 / 4), r / 2, r / 2) elif self.type == self.ROUGH: p.drawEllipse(10 + r / 2, 10 + r / 2, r, r) b = QtGui.QPolygon(3) b.setPoints(0, 0, 6, 6, 0, 12) b.translate(7 + r, 5 + r / 2) p.setBrush(QtGui.QColor("Black")) p.drawPolygon(b)
def __init__(self, option, index): radius = option.rect.height() / 2 center_x = option.rect.width() - radius center_y = option.rect.height() * index.row() + option.rect.height() / 2 rect_x = center_x - radius rect_y = center_y - radius rect_width = radius * 2 rect_height = radius * 2 self.rect = QtCore.QRect(rect_x, rect_y, rect_width, rect_height) x1 = center_x - float(radius) / math.sqrt(2) y1 = center_y - float(radius) / math.sqrt(2) x2 = center_x + float(radius) / math.sqrt(2) y2 = center_y + float(radius) / math.sqrt(2) line1 = QtCore.QLine(x1, y1, x2, y2) line2 = QtCore.QLine(x2, y1, x1, y2) self.lines = [line1, line2] self.start_angle = 0 self.span_angle = 0
def paint(self, painter, option, index): row = index.row() col = index.column() #Vertical Lines if col == 2: p1 = option.rect.topRight() p2 = option.rect.bottomRight() line = QtCore.QLine(p1, p2) painter.setPen(QtCore.Qt.black) painter.drawLine(line) #Horizontal Lines--------------------------------- #Month/Year/Week if row in self.weekLines: p1 = option.rect.bottomLeft() p2 = option.rect.bottomRight() line = QtCore.QLine(p1, p2) painter.setPen(QtCore.Qt.black) painter.drawLine(line) #Day elif col != 0 and (row in self.dayLines): painter.setPen( QtGui.QPen(QtGui.QBrush(QtCore.Qt.gray), 1.5, QtCore.Qt.DotLine)) p1 = option.rect.bottomLeft() p2 = option.rect.bottomRight() line = QtCore.QLine(p1, p2) painter.drawLine(line) #Draw Text painter.setPen(QtCore.Qt.black) if col == 3 or col == 2: return super(TableDelegate, self).paint(painter, option, index) elif col == 0 and (row in self.middleWeek): painter.drawText(option.rect, QtCore.Qt.AlignVCenter, index.data()) elif col == 0 and (row in self.middleWeekOdd): rowHeight = self.sizeHint(option, index).height() // 2 + 5 option.rect.translate(0, rowHeight) painter.drawText(option.rect, QtCore.Qt.AlignVCenter, index.data()) elif col == 1 and (row in self.middleDay): painter.drawText(option.rect, QtCore.Qt.AlignVCenter, index.data()) elif col == 1 and (row in self.middleDayOdd): rowHeight = self.sizeHint(option, index).height() // 2 + 7 option.rect.translate(0, rowHeight) painter.drawText(option.rect, QtCore.Qt.AlignVCenter, index.data())
def paintMe(self, qp, position): if (self.selected): qp.setPen( QtGui.QPen(QtGui.QColor('red'), self.stroke, QtCore.Qt.SolidLine)) else: qp.setPen(QtGui.QPen(self.color, self.stroke, QtCore.Qt.SolidLine)) qline = QtCore.QLine(*self.getCanvasCoordinates(position)) qp.drawLine(qline) qp.setPen(QtGui.QColor('black'))
def resizeEvent(self, event=None): canvas_width = self.width() - self.left_margin.width canvas_height = self.height() - self.top_margin.height self.left_margin.reset_height(canvas_height) self.top_margin.reset_width(canvas_width) self.canvas_rect = QtCore.QRectF(0, self.top_margin.height, self.width(), canvas_height) self.verticals = [] if self.no_main_cols > 0: x = self.left_margin.width col_width = canvas_width / self.no_main_cols while x < self.width(): self.verticals.append(QtCore.QLine(x, 0, x, self.height())) x += col_width self.horizontals = [] if self.no_rows > 0: y = self.top_margin.height row_height = canvas_height / self.no_rows while y < self.height(): y += row_height self.horizontals.append(QtCore.QLine(0, y, self.width(), y)) self.day_cells = [] for row in range(self.no_rows): for col in range(self.no_main_cols): rect = QtCore.QRectF(col * col_width + self.left_margin.width, row * row_height + self.top_margin.height, col_width, row_height) cell = DayCell(rect.adjusted(2, 2, -2, -2)) self.day_cells.append(cell) self.set_cell_dates() if self._style in (self.DAY, self.FOUR_DAY, self.WEEK): self.get_time_cells() self.is_resized = True self.emit(QtCore.SIGNAL("resized"))
def drawLines(self, io_image, start_xy_line, end_xy_line, color=QtGui.QColor("red")): pen = QtGui.QPen(color) painter = QtGui.QPainter(io_image) pen.setWidth(0.25) painter.setPen(pen) lines = [ QtCore.QLine(start_xy_line[n, 0], start_xy_line[n, 1], end_xy_line[n, 0], end_xy_line[n, 1]) for n in range(0, len(start_xy_line)) ] painter.drawLines(lines)
class Blobber(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.pixmap=QtGui.QPixmap() self.bar=QtGui.QPixmap() self.setGeometry(QtCore.QRect(107,17,225,23)) self.pixmap.load("Resources/blobs/blob-revert.png"); self.bar.load("Resources/bar.png"); self.multiselect=True self.selected1=0 self.selected2=0 self.content=["nothing","nothing","nothing","me","me","anon","nothing","nothing","nothing","nothing","nothing","nothing","nothing","nothing","nothing"] self.blobs={ "anon":QtGui.QPixmap("Resources/blobs/blob-anon.png"), "blanked":QtGui.QPixmap("Resources/blobs/blob-blanked.png"), "blank":QtGui.QPixmap("Resources/blobs/blob-blank.png"), "blocked":QtGui.QPixmap("Resources/blobs/blob-blocked.png"), "blocknote":QtGui.QPixmap("Resources/blobs/blob-blocknote.png"), "bot":QtGui.QPixmap("Resources/blobs/blob-bot.png"), "ignored":QtGui.QPixmap("Resources/blobs/blob-ignored.png"), "me":QtGui.QPixmap("Resources/blobs/blob-me.png"), "message":QtGui.QPixmap("Resources/blobs/blob-message.png"), "new":QtGui.QPixmap("Resources/blobs/blob-new.png"), "none":QtGui.QPixmap("Resources/blobs/blob-none.png"), "nothing":QtGui.QPixmap("Resources/blobs/nothing.png"), "redirect":QtGui.QPixmap("Resources/blobs/blob-redirect.png"), "replaced":QtGui.QPixmap("Resources/blobs/blob-replaced.png"), "reported":QtGui.QPixmap("Resources/blobs/blob-reported.png"), "report":QtGui.QPixmap("Resources/blobs/blob-report.png"), "reverted":QtGui.QPixmap("Resources/blobs/blob-reverted.png"), "revert":QtGui.QPixmap("Resources/blobs/blob-revert.png"), "tag":QtGui.QPixmap("Resources/blobs/blob-tag.png"), "warn-1":QtGui.QPixmap("Resources/blobs/blob-warn-1.png"), "warn-2":QtGui.QPixmap("Resources/blobs/blob-warn-2.png"), "warn-3":QtGui.QPixmap("Resources/blobs/blob-warn-3.png"), "warn-4":QtGui.QPixmap("Resources/blobs/blob-warn-4.png"), "warning":QtGui.QPixmap("Resources/blobs/blob-warning.png") } def paintEvent(self, event): paint = QtGui.QPainter() line=QtCore.QLine(0,0,10,10) paint.begin(self) paint.setPen(QtGui.QColor(255, 0, 0))
def paintEvent(self, event): super(LabelExt, self).paintEvent(event) linePen = QtGui.QPen(QtCore.Qt.yellow) linePen.setCapStyle(QtCore.Qt.RoundCap) linePen.setWidth(3) qp = QtGui.QPainter() qp.begin(self) qp.setRenderHint(QtGui.QPainter.Antialiasing, True) imgIdx = self.image.numInSeries - 1 qp.setPen(linePen) qp.setBrush(QtCore.Qt.yellow) for pt in self.pointSets[imgIdx]: # rect = QtCore.QRect(pt[0]-3, pt[1]-3, 7, 7) # qp.drawArc(rect, 0, 16*360) qp.drawEllipse(pt[0] - 3, pt[1] - 3, 7, 7) if self.show_lines: linePen.setWidth(2) qp.setPen(linePen) for pt1, pt2 in zip( self.pointSets[imgIdx], self.pointSets[imgIdx][1:] + self.pointSets[imgIdx][:1]): line = QtCore.QLine(pt1[0], pt1[1], pt2[0], pt2[1]) qp.drawLine(line) qp.end()
def viz_tensor(self, dimmin, dimmax): """Visualize a Tensor.""" # compute total size and offsets h, w, d = dimmax hoff, woff = self.setsize(h + d // 2 + 1, w + d // 2 + 1) # maximum h, w, d = dimmax points = [[[QtCore.QPoint(woff + x + z // 2, hoff + y + (d - z) // 2) for z in (0, d)] for x in (0, w)] for y in (0, h)] self.polygonmax = QtGui.QPolygon([ points[0][0][0], points[1][0][0], points[1][1][0], points[1][1][1], points[0][1][1], points[0][0][1], ]) self.linesmaxfront = [ QtCore.QLine(points[0][0][0], points[0][0][1]), # / QtCore.QLine(points[0][1][0], points[0][1][1]), # / QtCore.QLine(points[1][1][0], points[1][1][1]), # / QtCore.QLine(points[0][0][0], points[0][1][0]), # - QtCore.QLine(points[0][0][1], points[0][1][1]), # - QtCore.QLine(points[1][0][0], points[1][1][0]), # - QtCore.QLine(points[0][0][0], points[1][0][0]), # | QtCore.QLine(points[0][1][0], points[1][1][0]), # | QtCore.QLine(points[0][1][1], points[1][1][1]), # | ] self.linesmaxback = [ QtCore.QLine(points[1][0][0], points[1][0][1]), # / QtCore.QLine(points[1][0][1], points[1][1][1]), # - QtCore.QLine(points[0][0][1], points[1][0][1]), # | ] if d != 0: self.linesmaxback = [] # minimum h, w, d = dimmin points = [[[QtCore.QPoint(woff + x + z // 2, hoff + y + (d - z) // 2) for z in (0, d)] for x in (0, w)] for y in (0, h)] self.polygonmin = QtGui.QPolygon([ points[0][0][0], points[1][0][0], points[1][1][0], points[1][1][1], points[0][1][1], points[0][0][1], ]) self.linesminfront = [ QtCore.QLine(points[0][0][0], points[0][0][1]), # / QtCore.QLine(points[0][1][0], points[0][1][1]), # / QtCore.QLine(points[1][1][0], points[1][1][1]), # / QtCore.QLine(points[0][0][0], points[0][1][0]), # - QtCore.QLine(points[0][0][1], points[0][1][1]), # - QtCore.QLine(points[1][0][0], points[1][1][0]), # - QtCore.QLine(points[0][0][0], points[1][0][0]), # | QtCore.QLine(points[0][1][0], points[1][1][0]), # | QtCore.QLine(points[0][1][1], points[1][1][1]), # | ] self.linesminback = [ QtCore.QLine(points[1][0][0], points[1][0][1]), # / QtCore.QLine(points[1][0][1], points[1][1][1]), # - QtCore.QLine(points[0][0][1], points[1][0][1]), # | ]
def paintEvent(self, event=None): ''' draws the widget - recalled at any point by instance.update() ''' if len(self.dents) == 0: return # blank widget if no dents working self.dragLine = None painter = QtGui.QPainter(self) painter.setBrush(BGCOLOR) currentSlot = 0 self.font.setPointSize(localsettings.appointmentFontSize) fm = QtGui.QFontMetrics(self.font) painter.setFont(self.font) self.timeOffset = fm.width(" 88:88 ") self.headingHeight = fm.height() self.slotHeight = ( self.height() - self.headingHeight) / self.slotCount columnCount = len(self.dents) if columnCount == 0: columnCount = 1 # avoid division by zero!! columnWidth = (self.width() - self.timeOffset) / columnCount dragWidth = columnWidth # put the times down the side while currentSlot < self.slotCount: # offset the first time. if (currentSlot + 2) % self.textDetail == 0: y = 0.8 * self.headingHeight + currentSlot * self.slotHeight trect = QtCore.QRect( 0, y, self.timeOffset, self.textDetail * self.slotHeight ) painter.setPen(BLACK_PEN) painter.drawText(trect, QtCore.Qt.AlignHCenter, localsettings.humanTime( self.startTime + (currentSlot * self.slotLength))) currentSlot += 1 col = 0 for dent in self.dents: leftx = self.timeOffset + col * columnWidth rightx = self.timeOffset + (col + 1) * columnWidth # headings painter.setPen(BLACK_PEN) painter.setBrush(APPTCOLORS["HEADER"]) rect = QtCore.QRect(leftx, 0, columnWidth, self.headingHeight) painter.drawRect(rect) initials = localsettings.apptix_reverse.get(dent.ix) if dent.memo != "": initials = "*%s*" % initials painter.drawText(rect, QtCore.Qt.AlignHCenter, initials) # dentist start/finish painter.setBrush(BGCOLOR) startcell = ((self.daystart[dent.ix] - self.startTime) / self.slotLength) length = self.dayend[dent.ix] - self.daystart[dent.ix] startY = startcell * self.slotHeight + self.headingHeight endY = (length / self.slotLength) * self.slotHeight rect = QtCore.QRectF(leftx, startY, columnWidth, endY) if self.flagDict[dent.ix]: # don't draw a white canvas if dentist is out of office # a white canvas painter.save() painter.drawRect(rect) # grey lines painter.setPen(GREYLINE_PEN) y = startY while y < startY + endY: painter.drawLine(leftx, y, rightx, y) y += self.slotHeight / 2 painter.restore() painter.setPen(BLACK_PEN) # emergencies for appt in self.eTimes[dent.ix]: painter.save() if (self.daystart[dent.ix] <= appt.mpm < self.dayend[dent.ix]): startcell = (appt.mpm - self.startTime ) / self.slotLength rect = QtCore.QRectF(leftx, startcell * self.slotHeight + self.headingHeight, columnWidth, (appt.length / self.slotLength) * self.slotHeight) if self.mode == self.SCHEDULING_MODE: painter.setBrush(APPTCOLORS["BUSY"]) painter.setPen(GREY_PEN) elif appt.isEmergency: painter.setBrush(APPTCOLORS["EMERGENCY"]) elif appt.name.upper() in APPTCOLORS: painter.setBrush(APPTCOLORS[appt.name.upper()]) elif appt.cset in APPTCOLORS: painter.setBrush(APPTCOLORS[appt.cset]) else: painter.setBrush(APPTCOLORS["default"]) painter.drawRect(rect) text = appt.name[:5] if len(text) < len(appt.name): text += ".." painter.drawText(rect, QtCore.Qt.AlignLeft, text) painter.restore() painter.save() painter.setBrush(APPTCOLORS["LUNCH"]) for appt in self.lunches[dent.ix]: if (self.daystart[dent.ix] <= appt.mpm < self.dayend[dent.ix]): startcell = (appt.mpm - self.startTime ) / self.slotLength rect = QtCore.QRectF(leftx, startcell * self.slotHeight + self.headingHeight, columnWidth, (appt.length / self.slotLength) * self.slotHeight) if self.mode == self.SCHEDULING_MODE: painter.setPen(GREY_PEN) else: painter.setPen(BLACK_PEN) painter.drawRect(rect) painter.drawText(rect, QtCore.Qt.AlignCenter, "Lunch") painter.restore() # appts for appt in self.appts[dent.ix]: if (self.om_gui.pt and appt.serialno == self.om_gui.pt.serialno): painter.setBrush(APPTCOLORS["current_patient"]) elif self.mode == self.SCHEDULING_MODE: painter.setPen(GREY_PEN) painter.setBrush(APPTCOLORS["BUSY"]) elif appt.name.upper() in APPTCOLORS: painter.setBrush(APPTCOLORS[appt.name.upper()]) elif appt.cset in APPTCOLORS: painter.setBrush(APPTCOLORS[appt.cset]) else: painter.setBrush(APPTCOLORS["BUSY"]) startcell = (appt.mpm - self.startTime) / self.slotLength rect = QtCore.QRectF( leftx, startcell * self.slotHeight + self.headingHeight, columnWidth, (appt.length / self.slotLength) * self.slotHeight ) painter.drawRect(rect) text = appt.trt[:5] if len(text) < len(appt.trt): text += ".." painter.drawText(rect, QtCore.Qt.AlignLeft, text) # slots painter.save() painter.setPen(GREY_PEN) for slot in self.freeslots[dent.ix]: slotstart = localsettings.pyTimeToMinutesPastMidnight( slot.date_time.time()) startcell = ( slotstart - self.startTime) / self.slotLength rect = QtCore.QRectF(leftx, startcell * self.slotHeight + self.headingHeight, columnWidth, (slot.length / self.slotLength) * self.slotHeight) painter.save() if slot in self.active_slots: if self.blink_on: painter.setBrush( APPTCOLORS["ACTIVE_SLOT_BOLD"]) else: painter.setBrush(APPTCOLORS["ACTIVE_SLOT"]) painter.setPen(RED_PEN) else: if slot.dent in self.enabled_clinicians: painter.setOpacity(1) else: painter.setOpacity(0.4) painter.setBrush(APPTCOLORS["SLOT"]) painter.drawRect(rect) painter.setPen(RED_PEN) painter.drawText(rect, QtCore.Qt.AlignCenter, "%s" % slot.length) painter.restore() painter.restore() # drag drop if (self.is_dragging and self.mouse_drag_rect[0] == dent.ix): painter.save() rect = self.mouse_drag_rect[1] painter.setBrush(APPTCOLORS["ACTIVE_SLOT"]) painter.drawRect(rect) painter.setPen(RED_PEN) height = (self.drag_appt.length / self.slotLength) \ * self.slotHeight rect = QtCore.QRectF(leftx, self.dropPos.y(), columnWidth - 1, height) painter.drawRect(rect) self.dragLine = QtCore.QLine(0, self.dropPos.y(), self.width(), self.dropPos.y()) trect = QtCore.QRectF(0, self.dropPos.y(), self.timeOffset, height) painter.drawRect(trect) painter.drawText(trect, QtCore.Qt.AlignHCenter, localsettings.humanTime(self.drop_time())) painter.restore() if col > 0: painter.save() painter.setPen(BLACK_PEN) painter.drawLine(leftx, 0, leftx, self.height()) painter.restore() col += 1 if self.highlightedRect is not None: painter.setPen(RED_PEN) painter.setBrush(TRANSPARENT) painter.drawRect(self.highlightedRect) if self.dragLine: painter.setPen(RED_PEN) painter.drawLine(self.dragLine)
def draw_cross(self, x, y, context): lines = []; lines.append( QtCore.QLine(x-6, y-6, x+6, y+6) ) lines.append( QtCore.QLine(x-6, y+6, x+6, y-6) ) context.drawLines(lines)
def viz_triangular(self, dimmin, dimmax, properties): """Visualize a triangular matrix.""" # compute total size and offsets h, w = dimmax hoff, woff = self.setsize(h + 1, w + 1) # maximum h, w = dimmax points = [[QtCore.QPoint(woff + x, hoff + y) for x in (0, w)] for y in (0, h)] if "lower" in properties: self.polygonmax = QtGui.QPolygon([ points[0][0], points[1][0], points[1][1], points[0][0], ]) self.linesmaxfront = [ QtCore.QLine(points[0][0], points[1][0]), # | QtCore.QLine(points[1][0], points[1][1]), # - QtCore.QLine(points[1][1], points[0][0]), # \ ] else: self.polygonmax = QtGui.QPolygon([ points[0][0], points[1][1], points[0][1], points[0][0], ]) self.linesmaxfront = [ QtCore.QLine(points[0][0], points[1][1]), # \ QtCore.QLine(points[1][1], points[0][1]), # | QtCore.QLine(points[0][1], points[0][0]), # - ] self.linesmaxback = [] if "symm" in properties or "herm" in properties: self.linesmaxback = [ QtCore.QLine(points[0][0], points[1][0]), # | QtCore.QLine(points[1][0], points[1][1]), # - QtCore.QLine(points[1][1], points[0][1]), # | QtCore.QLine(points[0][1], points[0][0]), # - ] # minimum h, w = dimmin points = [[QtCore.QPoint(woff + x, hoff + y) for x in (0, w)] for y in (0, h)] if "lower" in properties: self.polygonmin = QtGui.QPolygon([ points[0][0], points[1][0], points[1][1], points[0][0], ]) self.linesminfront = [ QtCore.QLine(points[0][0], points[1][0]), # | QtCore.QLine(points[1][0], points[1][1]), # - QtCore.QLine(points[1][1], points[0][0]), # \ ] else: self.polygonmin = QtGui.QPolygon([ points[0][0], points[1][1], points[0][1], points[0][0], ]) self.linesminfront = [ QtCore.QLine(points[0][0], points[1][1]), # \ QtCore.QLine(points[1][1], points[0][1]), # | QtCore.QLine(points[0][1], points[0][0]), # - ] self.linesminback = [] if "symm" in properties or "herm" in properties: self.linesminback = [ QtCore.QLine(points[0][0], points[1][0]), # | QtCore.QLine(points[1][0], points[1][1]), # - QtCore.QLine(points[1][1], points[0][1]), # | QtCore.QLine(points[0][1], points[0][0]), # - ]
def display_image(self): if self.dbtype == "XML": self.img_number.setText("%d/%d" % (self.cnt, len(self.files))) self.slider.setSliderPosition(self.cnt) pixmap_t = QPixmap(self.folder + self.files[self.cnt]) painter = QPainter(pixmap_t) line = QLine(0.0, 240.0, 640.0, 240.0) painter.drawLine(line) if False: pixmap = pixmap_t.transformed(QTransform().scale( -1, -1)) # flip image else: pixmap = pixmap_t #spixmap = pixmap.scaled(self.img.size(), QtCore.Qt.KeepAspectRatio) spixmap = pixmap self.img.setPixmap(spixmap) self.img.show() elif self.dbtype == "SQLite": self.img_number.setText("%d/%d" % (self.cnt, len(self.frames))) self.slider.setSliderPosition(self.cnt) print "Opening image file: %s" % (self.folder + self.frames[self.cnt].img_uri) pixmap_t = QPixmap(self.folder + self.frames[self.cnt].img_uri) # draw annotations painter = QPainter(pixmap_t) for a in self.ml.annotCars[self.cnt]: if a.brakelight == 0: painter.setPen(QtGui.QColor(255, 255, 255)) else: painter.setPen(QtGui.QColor(255, 0, 0)) ul = (a.bbox_ul_x, a.bbox_ul_y) lr = (a.bbox_lr_x, a.bbox_lr_y) line = QtCore.QLine(ul[0], ul[1], lr[0], ul[1]) # upper horiz line painter.drawLine(line) line = QtCore.QLine(ul[0], lr[1], lr[0], lr[1]) # lower horiz line painter.drawLine(line) line = QtCore.QLine(ul[0], ul[1], ul[0], lr[1]) # left vertical painter.drawLine(line) line = QtCore.QLine(lr[0], ul[1], lr[0], lr[1]) # right vertical painter.drawLine(line) if False: pixmap = pixmap_t.transformed(QTransform().scale( -1, -1)) # flip image else: pixmap = pixmap_t #spixmap = pixmap.scaled(self.img.size(), QtCore.Qt.KeepAspectRatio) spixmap = pixmap self.img.setPixmap(spixmap) self.img.show() else: print "DisplayImage: do not recognize dbtype ", self.dbtype #tmp = cv2.imread(self.folder + self.files[self.cnt]) # check if already labeled self.updateMeta()