def itemChange(self, change, value): if change == QtWidgets.QGraphicsItem.ItemSelectedHasChanged: self.setPen( QtGui.QColor(0, 255, 0, 255) if self.isSelected() else QtGui. QColor(0, 0, 0, 255)) return super(Marker, self).itemChange(change, value)
def __init__(self, *args, **kwargs): super(GapItem, self).__init__(*args, **kwargs) self.setBrush(QtGui.QBrush(QtGui.QColor(100, 100, 100, 255))) self.source_name_label.setText('GAP')
def __init__(self, *args, **kwargs): super(NestedItem, self).__init__(*args, **kwargs) self.setBrush(QtGui.QBrush(QtGui.QColor(255, 113, 91, 255))) self.source_name_label.setText(self.item.name)
def get_color(self): temp_color = self.get_attribute_value(self.shape_name, "color")[0] return QtGui.QColor(temp_color[0] * 255, temp_color[1] * 255, temp_color[2] * 255)
def data(self, index, role): """Get item data.""" if not index.isValid(): return # Get the tree node. node = index.internalPointer() parent = node.parent if role == QtCore.Qt.DisplayRole: # or role == QtCore.Qt.EditRole: # If the item is an AOV who has an explicit channel set # then display the channel as well. if isinstance(node, AOVNode): aov = node.item if aov.channel: return "{0} ({1})".format(aov.variable, aov.channel) return node.name if role == QtCore.Qt.DecorationRole: return node.icon if role == QtCore.Qt.ToolTipRole: return node.tooltip() if role == QtCore.Qt.FontRole: # Italicize AOVs inside groups. if isinstance(parent, AOVGroupNode): font = QtGui.QFont() font.setItalic(True) return font return if role == QtCore.Qt.ForegroundRole: brush = QtGui.QBrush() # Grey out installed AOVs. if self.isInstalled(node): brush.setColor(QtGui.QColor(131, 131, 131)) return brush # Grey out AOVs inside groups. if isinstance(parent, AOVGroupNode): brush.setColor(QtGui.QColor(131, 131, 131)) return brush return if role == BaseAOVTreeModel.filterRole: if isinstance(node, FolderNode): return True if isinstance(node, AOVGroupNode): return node.name if isinstance(node.parent, AOVGroupNode): return True if isinstance(node, AOVNode): return node.name return True if role == self.sortRole: if isinstance(node, AOVBaseNode): return node.name
def __init__(self, *args, **kwargs): self.points = [] self.color = QtGui.QColor(255,0,0)
def __init_pixmap(self): painter = QtGui.QPainter(self.pixmap) painter.setBrush(QtGui.QBrush(QtGui.QColor(0,0,0), QtCore.Qt.SolidPattern)) painter.fillRect(self.pixmap.rect(), QtGui.QColor(0,0,0)) painter.end()
def simulation(self): """ It plots the simulation of all the periods in experiment """ if hasattr(self, 'exp') and len(self.exp.experiment) > 0: self.control = Controller(self.exp.experiment) simStartTime = QtCore.QDateTime() simStartTime.setDate(self.exp.experiment[0].dateStartTime) simEndTime = QtCore.QDateTime() simEndTime.setDate(self.exp.experiment[-1].dateEndTime) simEndTime = simEndTime.addDays(1).addSecs(6) interval = simStartTime.secsTo(simEndTime) / 3600. if interval == 0: interval = 24 #simulate at least 24 hours self.control.simulateExperiment(simStartTime, interval) futureLightHistory = self.control.getFutureLightHistory() f = open('daylight', 'w') f.write('{0}\r'.format(simStartTime.toString('dd.MM.yyyy hh:mm'))) l = int(len(futureLightHistory) / 30) for i in range(0, l): t = simStartTime.addSecs(1800 * i) f.write("{1} 00000{0}\r".format(futureLightHistory[30 * i][0], t.toString('yyyyMMdd hhmm'))) f.close self.graph.clear() pen = QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine) self.label.setText("Simulation") i = 0 for item in futureLightHistory: x = item[6] y = 0 heigh = 20 if item[0] == 0: self.graph.addLine(x, y, x, heigh) elif item[0] == 1: R = 255 if item[1] > 0 else 0 G = 255 if item[2] > 0 else 0 B = 255 if item[3] > 0 else 0 W = 0 if item[4] > 0 else 255 colourPen = QtGui.QColor(R, G, B, W) pen.setColor(colourPen) self.graph.addLine(x, y, x, heigh, pen) self.graph.addLine(x, y, x, y) self.graph.addLine(x, heigh, x, heigh) if item[5] > 0: self.graph.addLine(x, y, x, (1 - item[5]) * heigh) elif item[0] == -1: self.graph.addLine(x, -20, x, heigh) endTime = self.control.getEndExperimentTime() endTime = endTime.toString("dd.MM.yy hh:mm") text = self.graph.addText("Ends on {0}".format(endTime)) text.setPos(x, -22) break ##initialize prevItem if i == 0: prevItem = item[0] self.graph.addLine(x, y, x, heigh) startTime = simStartTime.toString("dd.MM.yy hh:mm") text = self.graph.addText( "Starts on {0}".format(startTime)) text.setPos(-160, 0) ##add the hour when the condition change if prevItem != item[0]: self.graph.addLine(x, y, x, heigh) hour = simStartTime.addSecs(i * 60) hour = hour.toString("dd.MM.yy hh:mm") text = self.graph.addText("{0}".format(hour)) text.setPos(x, -22) prevItem = item[0] i += 1 self.graphicsView.setScene(self.graph) self.graphicsView.show() def closeEvent(self, event): if self.exp.getIsExperimentRunning() == True: event.ignore() else: event.accept() else: self.label.setText("No Periods, please add one.")
import sys import math app = QtWidgets.QApplication(sys.argv) QtCore.qsrand(QtCore.QTime(0, 0, 0).secsTo(QtCore.QTime.currentTime())) scene = QtWidgets.QGraphicsScene(-200, -200, 400, 400) for i in range(10): item = ColorItem() angle = i * 6.28 / 10.0 item.setPos(math.sin(angle) * 150, math.cos(angle) * 150) scene.addItem(item) robot = Robot() robot.setTransform(QtGui.QTransform().scale(1.2, 1.2)) robot.setPos(0, -20) scene.addItem(robot) view = QtWidgets.QGraphicsView(scene) view.setRenderHint(QtGui.QPainter.Antialiasing) view.setViewportUpdateMode( QtWidgets.QGraphicsView.BoundingRectViewportUpdate) view.setBackgroundBrush(QtGui.QColor(230, 200, 167)) view.setWindowTitle("Drag and Drop Robot") view.show() sys.exit(app.exec_())
def __init__(self, color=QtCore.Qt.white, parent=None): super(CustomColorButton, self).__init__(parent) self._color = QtGui.QColor( ) #private variable, empty color - invalid for now self.set_size(50, 14) self.set_color(color)
def drawCurrentPeriod(self): period = self.control.getRunningPeriod() pastLightHistory = self.control.getPastLightHistory() futureLightHistory = self.control.getFutureLightHistory() actualTime = QtCore.QDateTime.currentDateTime() self.graph.clear() try: self.label.setText("{0}->Period Running = {1}".format( self.incubatorName, period + 1)) pen = QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine) except Exception as e: logging.error(e) self.label.setText("Experiment Ended") pen = QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine) i = 0 heigh = 20 startTime = self.control.getStartExperimentTime() endTime = self.control.getEndExperimentTime() for item in pastLightHistory: x = int(item[6]) y = 0 if item[0] == 0: self.graph.addLine(x, y, x, heigh) elif item[0] == 1: R = 255 if item[1] > 0 else 0 G = 255 if item[2] > 0 else 0 B = 255 if item[3] > 0 else 0 W = 0 if item[4] > 0 else 255 colourPen = QtGui.QColor(R, G, B, W) pen.setColor(colourPen) self.graph.addLine(x, y, x, heigh, pen) self.graph.addLine(x, y, x, y) self.graph.addLine(x, heigh, x, heigh) if item[5] > 0: self.graph.addLine(x, y, x, (1 - item[5]) * heigh) elif item[0] == -1: self.graph.addLine(x, y, x, heigh) endTime = endTime.toString("dd.MM.yy hh:mm") text = self.graph.addText("Ends on {0}".format(endTime)) text.setPos(x, -22) break ##initialize prevItem if i == 0: prevItem = item[0] self.graph.addLine(x, y, x, heigh) startedTime = startTime.toString("dd.MM.yy hh:mm") self.updatedText = self.graph.addText( "Updated on {0}".format(startedTime)) self.updatedText.setPos(-170, 0) ##add the hour when the condition change if prevItem != item[0]: self.graph.addLine(x, -20, x, heigh) hour = startTime.addSecs(x * 60) hour = hour.toString("dd.MM.yy hh:mm") text = self.graph.addText("{0}".format(hour)) text.setPos(x, 0) prevItem = item[0] i += 1 self.nowLine = self.graph.addLine(x, -20, x, heigh) self.nowText = self.graph.addText("Now") self.nowText.setPos(x, -22) startTime = self.control.getStartExperimentTime() endTime = self.control.getEndExperimentTime() now_counter = x for item in futureLightHistory: x = int(item[6]) y = 0 heigh = 20 if item[0] == 0: self.graph.addLine(x, y, x, heigh) elif item[0] == 1: R = 255 if item[1] > 0 else 0 G = 255 if item[2] > 0 else 0 B = 255 if item[3] > 0 else 0 W = 0 if item[4] > 0 else 255 colourPen = QtGui.QColor(R, G, B, W) pen.setColor(colourPen) self.graph.addLine(x, y, x, heigh, pen) self.graph.addLine(x, y, x, y) self.graph.addLine(x, heigh, x, heigh) if item[5] > 0: self.graph.addLine(x, y, x, (1 - item[5]) * heigh) elif item[0] == -1: self.graph.addLine(x, y, x, heigh) endTime = endTime.toString("dd.MM.yy hh:mm") text = self.graph.addText("Ends on {0}".format(endTime)) text.setPos(x, 0) break ##initialize prevItem ##add the hour when the condition change if prevItem != item[0]: self.graph.addLine(x, -20, x, heigh) hour = startTime.addSecs(x * 60) hour = hour.toString("dd.MM.yy hh:mm") text = self.graph.addText("{0}".format(hour)) text.setPos(x, -22) prevItem = item[0] i += 1 self.graphicsView.setScene(self.graph) self.graphicsView.show() if self.control.getIsExperimentRunning() == False: logging.debug("Stopped in updatecurrentperiod") self.stopExperiment()
def generateHighlightingRules(): # # The following keywords have been obtained from the KDE syntax-highlight framework (c syntax): # https://github.com/KDE/syntax-highlighting/blob/master/data/syntax/c.xml # control_flow = """ break, case, continue, default, do, else, for, goto, if, return, switch, while """ keywords = """ enum, extern, inline, sizeof, struct, typedef, union, _Alignas, _Alignof, _Atomic, _Noreturn, _Static_assert, _Thread_local """ types = """ auto, char, const, double, float, int, long, register, restrict, short, signed, static, unsigned, void, volatile, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, int_least8_t, int_least16_t, int_least32_t, int_least64_t, uint_least8_t, uint_least16_t, uint_least32_t, uint_least64_t, int_fast8_t, int_fast16_t, int_fast32_t, int_fast64_t, uint_fast8_t, uint_fast16_t, uint_fast32_t, uint_fast64_t, size_t, ssize_t, wchar_t, intptr_t, uintptr_t, intmax_t, uintmax_t, ptrdiff_t, sig_atomic_t, wint_t, _Bool, bool, _Complex, complex, _Imaginary, imaginary, _Generic, va_list, FILE, fpos_t, time_t, max_align_t """ highlightingRules = [] # Add highlighting rules and format for C control flow directives controlFlowFormat = QtGui.QTextCharFormat() controlFlowFormat.setForeground(QtGui.QColor('black')) controlFlowFormat.setFontWeight(QtGui.QFont.Bold) pattern = '({})\\b'.format('|'.join( control_flow.replace('\n', '').replace(' ', '').replace('.', '').split(','))) highlightingRules.append( HighlightingRule(QtCore.QRegExp(pattern), controlFlowFormat)) # Add highlighting rules and format for C keywords keywordsFormat = QtGui.QTextCharFormat() keywordsFormat.setForeground(QtGui.QColor('darkBlue')) keywordsFormat.setFontWeight(QtGui.QFont.Bold) pattern = '({})\\b'.format('|'.join( keywords.replace('\n', '').replace(' ', '').replace('.', '').split(','))) highlightingRules.append( HighlightingRule(QtCore.QRegExp(pattern), keywordsFormat)) # Add highlighting rules and format for C types typesFormat = QtGui.QTextCharFormat() typesFormat.setForeground(QtGui.QColor('darkBlue')) pattern = '({})\\b'.format('|'.join( types.replace('\n', '').replace(' ', '').replace('.', '').split(','))) highlightingRules.append( HighlightingRule(QtCore.QRegExp(pattern), typesFormat)) # Add highlighting rules and format for numbers numbersFormat = QtGui.QTextCharFormat() numbersFormat.setForeground(QtGui.QColor('darkOrange')) pattern = '\\b[0-9]+\\b' highlightingRules.append( HighlightingRule(QtCore.QRegExp(pattern), numbersFormat)) # Add highlighting rules and format for #define defineFormat = QtGui.QTextCharFormat() defineFormat.setForeground(QtGui.QColor('green')) pattern = '#define.*$' highlightingRules.append( HighlightingRule(QtCore.QRegExp(pattern), defineFormat)) # Add highlighting rules and format for C comments commentsFormat = QtGui.QTextCharFormat() commentsFormat.setForeground(QtGui.QColor('gray')) pattern = '//.*$' highlightingRules.append( HighlightingRule(QtCore.QRegExp(pattern), commentsFormat)) return highlightingRules
else: DEBUG = False DEFAULT_WORK_TIME = 25 * 60 # s DEFAULT_REST_TIME = 5 * 60 # s DEFAULT_TARGET_TIME = 3 * 60 * 60 # s if DEBUG: DEFAULT_WORK_TIME = 3 # s DEFAULT_REST_TIME = 3 # s DEFAULT_TARGET_TIME = 10 # s MIN_WORTH_SAVING = 30 # s if DEBUG: MIN_WORTH_SAVING = 1 # s RED_BACKGROUND = QtGui.QColor(255, 150, 150) GREEN_BACKGROUND = QtGui.QColor(150, 255, 150) BLUE_BACKGROUND = QtGui.QColor(200, 200, 255) WHITE_BACKGROUND = QtGui.QColor(255, 255, 255) START_ALARM_PATH = "start.wav" END_ALARM_PATH = "end.wav" ALERTS = { 'happy': QtMultimedia.QSound(END_ALARM_PATH), 'sad': QtMultimedia.QSound(START_ALARM_PATH) } DELTA_T = 0.01
def setupUi(self, LRCSNet): LRCSNet.setObjectName("LRCSNet") LRCSNet.resize(1156, 900) sizePolicy = QtWidgets.QSizePolicy( QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(LRCSNet.sizePolicy().hasHeightForWidth()) LRCSNet.setSizePolicy(sizePolicy) self.centralwidget = QtWidgets.QWidget(LRCSNet) self.centralwidget.setObjectName("centralwidget") self.gridLayout = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout.setObjectName("gridLayout") self.verticalLayout_2 = QtWidgets.QVBoxLayout() self.verticalLayout_2.setObjectName("verticalLayout_2") self.tuto_button = QtWidgets.QPushButton(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy( QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.tuto_button.sizePolicy().hasHeightForWidth()) self.tuto_button.setSizePolicy(sizePolicy) self.tuto_button.setText("") icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap("../img/tuto.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tuto_button.setIcon(icon) self.tuto_button.setIconSize(QtCore.QSize(1000, 155)) self.tuto_button.setCheckable(False) self.tuto_button.setAutoDefault(False) self.tuto_button.setDefault(False) self.tuto_button.setFlat(True) self.tuto_button.setObjectName("tuto_button") self.verticalLayout_2.addWidget(self.tuto_button) self.horizontalLayout_2 = QtWidgets.QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.start_button = QtWidgets.QPushButton(self.centralwidget) self.start_button.setMinimumSize(QtCore.QSize(0, 36)) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap("../img/play-button.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.start_button.setIcon(icon1) self.start_button.setObjectName("start_button") self.horizontalLayout_2.addWidget(self.start_button) self.loop_button = QtWidgets.QPushButton(self.centralwidget) self.loop_button.setMinimumSize(QtCore.QSize(0, 36)) icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap("../img/exchange_2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon2.addPixmap(QtGui.QPixmap("../img/exchange.png"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.loop_button.setIcon(icon2) self.loop_button.setCheckable(True) self.loop_button.setObjectName("loop_button") self.horizontalLayout_2.addWidget(self.loop_button) self.stop_button = QtWidgets.QPushButton(self.centralwidget) self.stop_button.setMinimumSize(QtCore.QSize(0, 36)) icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap("stop.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon3.addPixmap(QtGui.QPixmap("../img/stop.png"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.stop_button.setIcon(icon3) self.stop_button.setObjectName("stop_button") self.horizontalLayout_2.addWidget(self.stop_button) self.add_button = QtWidgets.QPushButton(self.centralwidget) self.add_button.setMinimumSize(QtCore.QSize(0, 36)) icon4 = QtGui.QIcon() icon4.addPixmap(QtGui.QPixmap("plus.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon4.addPixmap(QtGui.QPixmap("../img/plus.png"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.add_button.setIcon(icon4) self.add_button.setObjectName("add_button") self.horizontalLayout_2.addWidget(self.add_button) self.clean_button = QtWidgets.QPushButton(self.centralwidget) self.clean_button.setMinimumSize(QtCore.QSize(0, 36)) icon5 = QtGui.QIcon() icon5.addPixmap(QtGui.QPixmap("minus.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon5.addPixmap(QtGui.QPixmap("../img/minus.png"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.clean_button.setIcon(icon5) self.clean_button.setObjectName("clean_button") self.horizontalLayout_2.addWidget(self.clean_button) self.forward_button = QtWidgets.QPushButton(self.centralwidget) self.forward_button.setMinimumSize(QtCore.QSize(0, 36)) icon6 = QtGui.QIcon() icon6.addPixmap(QtGui.QPixmap("reply.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon6.addPixmap(QtGui.QPixmap("../img/reply.png"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.forward_button.setIcon(icon6) self.forward_button.setObjectName("forward_button") self.horizontalLayout_2.addWidget(self.forward_button) self.pushButton = QtWidgets.QPushButton(self.centralwidget) self.pushButton.setMinimumSize(QtCore.QSize(0, 36)) icon7 = QtGui.QIcon() icon7.addPixmap(QtGui.QPixmap("resume.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon7.addPixmap(QtGui.QPixmap("../img/resume.png"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.pushButton.setIcon(icon7) self.pushButton.setObjectName("pushButton") self.horizontalLayout_2.addWidget(self.pushButton) self.line = QtWidgets.QFrame(self.centralwidget) self.line.setFrameShape(QtWidgets.QFrame.VLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.line.setObjectName("line") self.horizontalLayout_2.addWidget(self.line) self.predict_button = QtWidgets.QPushButton(self.centralwidget) self.predict_button.setMinimumSize(QtCore.QSize(0, 36)) icon8 = QtGui.QIcon() icon8.addPixmap(QtGui.QPixmap("rubik.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon8.addPixmap(QtGui.QPixmap("../img/rubik.png"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.predict_button.setIcon(icon8) self.predict_button.setIconSize(QtCore.QSize(20, 20)) self.predict_button.setObjectName("predict_button") self.horizontalLayout_2.addWidget(self.predict_button) self.dashboard_button = QtWidgets.QPushButton(self.centralwidget) self.dashboard_button.setMinimumSize(QtCore.QSize(0, 36)) icon9 = QtGui.QIcon() icon9.addPixmap(QtGui.QPixmap("speedometer.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon9.addPixmap(QtGui.QPixmap("../img/speedometer.png"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.dashboard_button.setIcon(icon9) self.dashboard_button.setIconSize(QtCore.QSize(20, 20)) self.dashboard_button.setObjectName("dashboard_button") self.horizontalLayout_2.addWidget(self.dashboard_button) self.verticalLayout_2.addLayout(self.horizontalLayout_2) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setSizeConstraint( QtWidgets.QLayout.SetMaximumSize) self.horizontalLayout.setObjectName("horizontalLayout") self.tableWidget = QtWidgets.QTableWidget(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.tableWidget.sizePolicy().hasHeightForWidth()) self.tableWidget.setSizePolicy(sizePolicy) self.tableWidget.setMinimumSize(QtCore.QSize(801, 601)) self.tableWidget.setMaximumSize(QtCore.QSize(16777215, 16777215)) self.tableWidget.setDragEnabled(False) self.tableWidget.setRowCount(28) self.tableWidget.setColumnCount(2) self.tableWidget.setObjectName("tableWidget") self.tableWidget.setColumnCount(2) self.tableWidget.setRowCount(28) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(0, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(1, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(2, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(3, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(4, 0, item) brush = QtGui.QBrush(QtGui.QColor(128, 255, 7)) brush.setStyle(QtCore.Qt.NoBrush) item = QtWidgets.QTableWidgetItem() item.setBackground(brush) self.tableWidget.setItem(5, 0, item) brush = QtGui.QBrush(QtGui.QColor(128, 255, 7)) brush.setStyle(QtCore.Qt.NoBrush) item = QtWidgets.QTableWidgetItem() item.setBackground(brush) self.tableWidget.setItem(6, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(7, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(8, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(9, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(10, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(11, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(12, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(13, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(14, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(15, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(16, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(17, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(18, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(19, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(20, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(21, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(22, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(23, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(24, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(25, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(26, 0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setItem(27, 0, item) self.tableWidget.horizontalHeader().setDefaultSectionSize(100) self.tableWidget.horizontalHeader().setMinimumSectionSize(18) self.horizontalLayout.addWidget(self.tableWidget) self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.label = QtWidgets.QLabel(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.label.sizePolicy().hasHeightForWidth()) self.label.setSizePolicy(sizePolicy) self.label.setMaximumSize(QtCore.QSize(181, 16777215)) self.label.setObjectName("label") self.verticalLayout.addWidget(self.label) self.AvailableGPUs = QtWidgets.QListWidget(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.AvailableGPUs.sizePolicy().hasHeightForWidth()) self.AvailableGPUs.setSizePolicy(sizePolicy) self.AvailableGPUs.setMaximumSize(QtCore.QSize(181, 16777215)) self.AvailableGPUs.setObjectName("AvailableGPUs") self.verticalLayout.addWidget(self.AvailableGPUs) self.label_2 = QtWidgets.QLabel(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.label_2.sizePolicy().hasHeightForWidth()) self.label_2.setSizePolicy(sizePolicy) self.label_2.setMaximumSize(QtCore.QSize(181, 16777215)) self.label_2.setObjectName("label_2") self.verticalLayout.addWidget(self.label_2) self.ongoing_process = QtWidgets.QListWidget(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.ongoing_process.sizePolicy().hasHeightForWidth()) self.ongoing_process.setSizePolicy(sizePolicy) self.ongoing_process.setMaximumSize(QtCore.QSize(181, 16777215)) self.ongoing_process.setObjectName("ongoing_process") self.verticalLayout.addWidget(self.ongoing_process) self.horizontalLayout.addLayout(self.verticalLayout) self.verticalLayout_2.addLayout(self.horizontalLayout) self.gridLayout.addLayout(self.verticalLayout_2, 0, 0, 1, 1) LRCSNet.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar() self.menubar.setGeometry(QtCore.QRect(0, 0, 1156, 22)) self.menubar.setObjectName("menubar") self.menuMenu = QtWidgets.QMenu(self.menubar) self.menuMenu.setEnabled(True) self.menuMenu.setObjectName("menuMenu") self.menuPlugin = QtWidgets.QMenu(self.menubar) self.menuPlugin.setObjectName("menuPlugin") self.menuVisualization = QtWidgets.QMenu(self.menubar) self.menuVisualization.setObjectName("menuVisualization") self.menuHands_off = QtWidgets.QMenu(self.menubar) self.menuHands_off.setObjectName("menuHands_off") LRCSNet.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(LRCSNet) self.statusbar.setObjectName("statusbar") LRCSNet.setStatusBar(self.statusbar) self.About_us = QtWidgets.QAction(LRCSNet) self.About_us.setObjectName("About_us") self.Activations = QtWidgets.QAction(LRCSNet) self.Activations.setObjectName("Activations") self.Exit = QtWidgets.QAction(LRCSNet) self.Exit.setObjectName("Exit") self.Loss_Landscape = QtWidgets.QAction(LRCSNet) self.Loss_Landscape.setObjectName("Loss_Landscape") self.Random_Forest = QtWidgets.QAction(LRCSNet) self.Random_Forest.setObjectName("Random_Forest") self.Metrics = QtWidgets.QAction(LRCSNet) self.Metrics.setObjectName("Metrics") self.Preferences = QtWidgets.QAction(LRCSNet) self.Preferences.setObjectName("Preferences") self.ActViewer = QtWidgets.QAction(LRCSNet) self.ActViewer.setObjectName("ActViewer") self.Volumes_Viewer = QtWidgets.QAction(LRCSNet) self.Volumes_Viewer.setObjectName("Volumes_Viewer") self.AugViewer = QtWidgets.QAction(LRCSNet) self.AugViewer.setObjectName("AugViewer") self.GradViewer = QtWidgets.QAction(LRCSNet) self.GradViewer.setObjectName("GradViewer") self.Thresholding = QtWidgets.QAction(LRCSNet) self.Thresholding.setObjectName("Thresholding") self.actionGrid_Search = QtWidgets.QAction(LRCSNet) self.actionGrid_Search.setObjectName("actionGrid_Search") self.actionGassian_Process = QtWidgets.QAction(LRCSNet) self.actionGassian_Process.setObjectName("actionGassian_Process") self.actionExtract_Result = QtWidgets.QAction(LRCSNet) self.actionExtract_Result.setObjectName("actionExtract_Result") self.menuMenu.addAction(self.About_us) self.menuMenu.addSeparator() self.menuMenu.addAction(self.Preferences) self.menuMenu.addAction(self.Exit) self.menuPlugin.addAction(self.Activations) self.menuPlugin.addAction(self.Loss_Landscape) self.menuPlugin.addAction(self.Random_Forest) self.menuPlugin.addAction(self.Metrics) self.menuPlugin.addAction(self.Thresholding) self.menuPlugin.addAction(self.actionExtract_Result) self.menuVisualization.addAction(self.ActViewer) self.menuVisualization.addAction(self.Volumes_Viewer) self.menuVisualization.addAction(self.AugViewer) self.menuVisualization.addAction(self.GradViewer) self.menuHands_off.addAction(self.actionGrid_Search) self.menuHands_off.addAction(self.actionGassian_Process) self.menubar.addAction(self.menuMenu.menuAction()) self.menubar.addAction(self.menuVisualization.menuAction()) self.menubar.addAction(self.menuPlugin.menuAction()) self.menubar.addAction(self.menuHands_off.menuAction()) self.retranslateUi(LRCSNet) QtCore.QMetaObject.connectSlotsByName(LRCSNet)
def readInfo(self, resource, dir_): categoriesFile = QtCore.QFile(resource) document = QtXml.QDomDocument() document.setContent(categoriesFile) documentElement = document.documentElement() categoryNodes = documentElement.elementsByTagName("category") self.categories['[main]'] = {} self.categories['[main]']['examples'] = [] self.categories['[main]']['color'] = QtGui.QColor("#f0f0f0") self.readCategoryDescription(dir_, '[main]') self.qtLogo.load(self.imagesDir.absoluteFilePath(":/images/qt4-logo.png")) self.rbLogo.load(self.imagesDir.absoluteFilePath(":/images/rb-logo.png")) for i in range(categoryNodes.length()): elem = categoryNodes.item(i).toElement() categoryName = QtCore.QString(elem.attribute("name")) categoryDirName = QtCore.QString(elem.attribute("dirname")) categoryDocName = QtCore.QString(elem.attribute("docname")) categoryColor = QtGui.QColor(elem.attribute("color", "#f0f0f0")) categoryDir = QtCore.QDir(dir_) if categoryDir.cd(categoryDirName): self.categories[categoryName] = {} self.readCategoryDescription(categoryDir, categoryName) self.categories[categoryName]['examples'] = [] exampleNodes = elem.elementsByTagName("example") self.maximumLabels = max(self.maximumLabels, exampleNodes.length()) # Only add those examples we can find. for j in range(exampleNodes.length()): exampleDir = QtCore.QDir(categoryDir) exampleNode = exampleNodes.item(j) element = exampleNode.toElement() exampleName = element.attribute("name") exampleFileName = element.attribute("filename") uniqueName = categoryName + "-" + exampleName self.examples[uniqueName] = {} if not categoryDocName.isEmpty(): docName = categoryDocName + "-" + exampleFileName + ".html" else: docName = categoryDirName + "-" + exampleFileName + ".html" self.examples[uniqueName]['name'] = exampleName self.examples[uniqueName]['document path'] = "" self.findDescriptionAndImages(uniqueName, docName) self.examples[uniqueName]['changedirectory'] = element.attribute("changedirectory", "true") self.examples[uniqueName]['color'] = QtGui.QColor(element.attribute("color", "#f0f0f0")) if element.attribute("executable", "true") != "true": del self.examples[uniqueName] continue examplePath = None if sys.platform == "win32": examplePyName = exampleFileName + ".pyw" else: examplePyName = exampleFileName + ".py" if exampleDir.exists(examplePyName): examplePath = exampleDir.absoluteFilePath(examplePyName) elif exampleDir.cd(exampleFileName): if exampleDir.exists(examplePyName): examplePath = exampleDir.absoluteFilePath(examplePyName) if examplePath and not examplePath.isNull(): self.examples[uniqueName]['absolute path'] = exampleDir.absolutePath() self.examples[uniqueName]['path'] = examplePath self.categories[categoryName]['examples'].append(exampleName) else: del self.examples[uniqueName] self.categories[categoryName]['color'] = categoryColor return len(self.categories)
def combineColors(c1, c2): c3 = QtGui.QColor() c3.setRed((c1.red() + c2.red()) // 2) c3.setGreen((c1.green() + c2.green()) // 2) c3.setBlue((c1.blue() + c2.blue()) // 2) return c3
def paint(self, painter, option, widget): painter.fillRect(widget.rect(), QtGui.QBrush(QtGui.QColor(0,0,0,0), QtCore.Qt.SolidPattern)) painter.drawPixmap(0, 0, self.pixels.Width*self.scale, self.pixels.Height*self.scale, self.pixmap)
def setMainProdutos(self, ct_MainProdutos): ct_MainProdutos.setObjectName("ct_MainProdutos") ct_MainProdutos.resize(1000, 600) ct_MainProdutos.setStyleSheet("border:none") self.frameMainProdutos = QtWidgets.QFrame(ct_MainProdutos) self.frameMainProdutos.setGeometry(QtCore.QRect(0, 0, 1000, 600)) self.frameMainProdutos.setObjectName("frameMainProdutos") self.fr_TopoMenuProdutos = QtWidgets.QFrame(self.frameMainProdutos) self.fr_TopoMenuProdutos.setGeometry(QtCore.QRect(0, 60, 1000, 40)) self.fr_TopoMenuProdutos.setStyleSheet("background:#E1DFE0;\n" "border: none;") self.fr_TopoMenuProdutos.setObjectName("fr_TopoMenuProdutos") self.bt_BuscaProduto = QtWidgets.QPushButton(self.fr_TopoMenuProdutos) self.bt_BuscaProduto.setGeometry(QtCore.QRect(830, 5, 30, 30)) font = QtGui.QFont() font.setFamily("Arial") self.bt_BuscaProduto.setFont(font) self.bt_BuscaProduto.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.bt_BuscaProduto.setFocusPolicy(QtCore.Qt.NoFocus) self.bt_BuscaProduto.setContextMenuPolicy(QtCore.Qt.NoContextMenu) self.bt_BuscaProduto.setText("") self.bt_BuscaProduto.setObjectName("bt_BuscaProduto") self.bt_AddNovoProduto = QtWidgets.QPushButton( self.fr_TopoMenuProdutos) self.bt_AddNovoProduto.setGeometry(QtCore.QRect(900, 0, 100, 40)) self.bt_AddNovoProduto.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.bt_AddNovoProduto.setFocusPolicy(QtCore.Qt.NoFocus) self.bt_AddNovoProduto.setContextMenuPolicy( QtCore.Qt.ActionsContextMenu) self.bt_AddNovoProduto.setStyleSheet("QPushButton {\n" "background-color: #7AB32E;\n" " }\n" "QPushButton:hover{\n" "background-color: #40a286\n" "}") self.bt_AddNovoProduto.setText("") self.bt_AddNovoProduto.setObjectName("bt_AddNovoProduto") self.tx_BuscaProduto = QtWidgets.QLineEdit(self.fr_TopoMenuProdutos) self.tx_BuscaProduto.setGeometry(QtCore.QRect(0, 5, 830, 30)) font = QtGui.QFont() font.setFamily("Arial") self.tx_BuscaProduto.setFont(font) self.tx_BuscaProduto.setFocusPolicy(QtCore.Qt.ClickFocus) self.tx_BuscaProduto.setStyleSheet("QLineEdit {\n" "color: #000\n" "}\n" "") self.tx_BuscaProduto.setObjectName("tx_BuscaProduto") self.bt_PrintRelatProdutos = QtWidgets.QPushButton( self.fr_TopoMenuProdutos) self.bt_PrintRelatProdutos.setGeometry(QtCore.QRect(870, 5, 30, 30)) font = QtGui.QFont() font.setFamily("Arial") self.bt_PrintRelatProdutos.setFont(font) self.bt_PrintRelatProdutos.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.bt_PrintRelatProdutos.setFocusPolicy(QtCore.Qt.NoFocus) self.bt_PrintRelatProdutos.setContextMenuPolicy( QtCore.Qt.NoContextMenu) self.bt_PrintRelatProdutos.setText("") self.bt_PrintRelatProdutos.setObjectName("bt_PrintRelatProdutos") self.ct_containerProdutos = QtWidgets.QFrame(self.frameMainProdutos) self.ct_containerProdutos.setGeometry(QtCore.QRect(0, 100, 1000, 500)) self.ct_containerProdutos.setStyleSheet("border: none") self.ct_containerProdutos.setObjectName("ct_containerProdutos") self.tb_produtos = QtWidgets.QTableWidget(self.ct_containerProdutos) self.tb_produtos.setGeometry(QtCore.QRect(0, 0, 1000, 500)) self.tb_produtos.viewport().setProperty( "cursor", QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.tb_produtos.setFocusPolicy(QtCore.Qt.WheelFocus) self.tb_produtos.setStyleSheet("QTableView{\n" "color: #797979;\n" "font-weight: bold;\n" "font-size: 13px;\n" "background: #FFF;\n" "padding: 0 0 0 5px;\n" "}\n" "QHeaderView:section{\n" "background: #FFF;\n" "padding: 5px 0 ;\n" "font-size: 12px;\n" "font-family: \"Arial\";\n" "font-weight: bold;\n" "color: #797979;\n" "border: none;\n" "border-bottom: 2px solid #CCC;\n" "text-transform: uppercase\n" "}\n" "QTableView::item {\n" "border-bottom: 2px solid #CCC;\n" "padding: 2px;\n" "}\n" "\n" "") self.tb_produtos.setFrameShape(QtWidgets.QFrame.NoFrame) self.tb_produtos.setFrameShadow(QtWidgets.QFrame.Plain) self.tb_produtos.setAutoScrollMargin(20) self.tb_produtos.setEditTriggers( QtWidgets.QAbstractItemView.NoEditTriggers) self.tb_produtos.setSelectionMode( QtWidgets.QAbstractItemView.NoSelection) self.tb_produtos.setSelectionBehavior( QtWidgets.QAbstractItemView.SelectRows) self.tb_produtos.setShowGrid(False) self.tb_produtos.setGridStyle(QtCore.Qt.NoPen) self.tb_produtos.setRowCount(0) self.tb_produtos.setObjectName("tb_produtos") self.tb_produtos.setColumnCount(8) item = QtWidgets.QTableWidgetItem() self.tb_produtos.setHorizontalHeaderItem(0, item) item = QtWidgets.QTableWidgetItem() self.tb_produtos.setHorizontalHeaderItem(1, item) item = QtWidgets.QTableWidgetItem() item.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter | QtCore.Qt.AlignCenter) font = QtGui.QFont() font.setFamily("Segoe UI") font.setPointSize(10) font.setBold(True) font.setWeight(75) item.setFont(font) item.setBackground(QtGui.QColor(0, 0, 0, 0)) brush = QtGui.QBrush(QtGui.QColor(80, 79, 79)) brush.setStyle(QtCore.Qt.SolidPattern) item.setForeground(brush) self.tb_produtos.setHorizontalHeaderItem(2, item) item = QtWidgets.QTableWidgetItem() item.setTextAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) font = QtGui.QFont() font.setFamily("Segoe UI") font.setPointSize(10) font.setBold(True) font.setWeight(75) item.setFont(font) brush = QtGui.QBrush(QtGui.QColor(80, 79, 79)) brush.setStyle(QtCore.Qt.SolidPattern) item.setForeground(brush) self.tb_produtos.setHorizontalHeaderItem(3, item) item = QtWidgets.QTableWidgetItem() item.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter | QtCore.Qt.AlignCenter) font = QtGui.QFont() font.setFamily("Segoe UI") font.setPointSize(10) font.setBold(True) font.setWeight(75) item.setFont(font) brush = QtGui.QBrush(QtGui.QColor(80, 79, 79)) brush.setStyle(QtCore.Qt.SolidPattern) item.setForeground(brush) self.tb_produtos.setHorizontalHeaderItem(4, item) item = QtWidgets.QTableWidgetItem() item.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter | QtCore.Qt.AlignCenter) font = QtGui.QFont() font.setFamily("Segoe UI") font.setPointSize(10) font.setBold(True) font.setWeight(75) item.setFont(font) brush = QtGui.QBrush(QtGui.QColor(80, 79, 79)) brush.setStyle(QtCore.Qt.SolidPattern) item.setForeground(brush) self.tb_produtos.setHorizontalHeaderItem(5, item) item = QtWidgets.QTableWidgetItem() item.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter | QtCore.Qt.AlignCenter) font = QtGui.QFont() font.setFamily("Segoe UI") font.setPointSize(10) font.setBold(True) font.setWeight(75) item.setFont(font) brush = QtGui.QBrush(QtGui.QColor(80, 79, 79)) brush.setStyle(QtCore.Qt.SolidPattern) item.setForeground(brush) self.tb_produtos.setHorizontalHeaderItem(6, item) item = QtWidgets.QTableWidgetItem() item.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter | QtCore.Qt.AlignCenter) font = QtGui.QFont() font.setFamily("Segoe UI") font.setPointSize(10) font.setBold(True) font.setWeight(75) item.setFont(font) self.tb_produtos.setHorizontalHeaderItem(7, item) self.tb_produtos.horizontalHeader().setDefaultSectionSize(120) self.tb_produtos.horizontalHeader().setHighlightSections(False) self.tb_produtos.horizontalHeader().setStretchLastSection(True) self.tb_produtos.verticalHeader().setVisible(False) self.tb_produtos.verticalHeader().setDefaultSectionSize(50) self.fr_TituloProdutos = QtWidgets.QFrame(self.frameMainProdutos) self.fr_TituloProdutos.setGeometry(QtCore.QRect(0, 0, 1000, 60)) self.fr_TituloProdutos.setStyleSheet("border: none") self.fr_TituloProdutos.setObjectName("fr_TituloProdutos") self.lb_tituloProdutos = QtWidgets.QLabel(self.fr_TituloProdutos) self.lb_tituloProdutos.setGeometry(QtCore.QRect(10, 15, 200, 30)) font = QtGui.QFont() font.setFamily("DejaVu Sans") font.setPointSize(18) font.setBold(True) font.setWeight(75) self.lb_tituloProdutos.setFont(font) self.lb_tituloProdutos.setStyleSheet("color: #FFF") self.lb_tituloProdutos.setObjectName("lb_tituloProdutos") self.ct_containerProdutos.raise_() self.fr_TopoMenuProdutos.raise_() self.fr_TituloProdutos.raise_() self.tradMainProdutos(ct_MainProdutos) QtCore.QMetaObject.connectSlotsByName(ct_MainProdutos)
def __init__(self, *args, **kwargs): super(self.__class__, self).__init__(*args, **kwargs) self.size = 16 self.scale = 32 self.colors = [QtGui.QColor(196,196,196,255), QtGui.QColor(232,232,232,255)]
def __init__(self, items=None): ''' Base custom QMenu ''' QtWidgets.QMenu.__init__(self) # Window self.transparent = False self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint | QtCore.Qt.NoDropShadowWindowHint) if self.transparent: self.setAttribute(QtCore.Qt.WA_TranslucentBackground) # Ratio for different screen sizes self.screenRatio, self.screenFontRatio = getScreenRatio() # Dimensions self.width = 1000 * self.screenRatio self.height = 2000 * self.screenRatio self.setFixedSize(self.width, self.height) # Timer for gestures self.timer = QtCore.QTimer() self.timer.setTimerType(QtCore.Qt.PreciseTimer) self.timer.timeout.connect(self.trackCursor) self.timer.setInterval(2) # Turns off when the cursor stops moving self.gesture = True # Main painter self.painter = QtGui.QPainter() # Mask painter self.painterMask = QtGui.QPainter() self.maskPixmap = QtGui.QPixmap(self.width, self.height) self.maskPixmap.fill(QtCore.Qt.white) # Radius of origin circle self.originRadius = 8.0 * self.screenRatio # Right click widget - Stores the mouse press event of the widget # the menu is opened from when right clicked self.rightClickWidgetMousePressEvent = None # Stores which item is active self.activeItem = None # Pens gray = QtGui.QColor(128, 128, 128, 255) self.penOrigin = QtGui.QPen(gray, 5, QtCore.Qt.SolidLine) self.penCursorLine = QtGui.QPen(gray, 3, QtCore.Qt.SolidLine) self.penBlack = QtGui.QPen(QtCore.Qt.black, 2, QtCore.Qt.SolidLine) self.penActive = QtGui.QPen(QtCore.Qt.red, 20, QtCore.Qt.SolidLine) self.penWhite = QtGui.QPen(QtCore.Qt.white, 5, QtCore.Qt.SolidLine) self.transparentPen = QtGui.QPen(QtCore.Qt.transparent, 5000) ########################################################## # Items ########################################################## self.itemHeight = 40.0 * self.screenFontRatio self.items = list() # Events sent to items to highlight them self.leaveButtonEvent = QtCore.QEvent(QtCore.QEvent.Leave) self.enterButtonEvent = QtCore.QEvent(QtCore.QEvent.Enter) # Radial item positions relative to center of radial menu r = self.screenRatio self.position_xy = { 'N': [0 * r, -90 * r], 'S': [0 * r, 90 * r], 'E': [120 * r, 0 * r], 'W': [-120 * r, 0 * r], 'NE': [85 * r, -45 * r], 'NW': [-85 * r, -45 * r], 'SE': [85 * r, 45 * r], 'SW': [-85 * r, 45 * r] } # Slices - Each number represents a 22.5 degree slice, so each # position gets a 45 degree slice of the pie self.slices = { 'E': [15, 0], 'SE': [1, 2], 'S': [3, 4], 'SW': [5, 6], 'W': [7, 8], 'NW': [9, 10], 'N': [11, 12], 'NE': [13, 14] } # Column widget self.column_widget = QtWidgets.QWidget() self.column_widget.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents) self.column_widget.setParent(self) self.column_widget.items = list() self.column_widget.rects = list() # Draw radial menu and its mask self.column_widget_rect = None self.paintMask()
def __init__(self, parent=None): super(UI, self).__init__(parent) # Set self._glob_pos = QtCore.QPoint() # Set attributes self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint) self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setMinimumSize(1000, 600) # Set Attributes self.radius = 2 self.background = QtGui.QColor(51, 51, 51) self.foreground = QtGui.QColor(51, 51, 51) # Main Layout m_layout = QtWidgets.QVBoxLayout() self.setLayout(m_layout) # Header _header = header.Header(title='SVG To Qt - Convert') m_layout.addWidget(_header) # Seperator seperator = QtWidgets.QSplitter() m_layout.addWidget(seperator) # Left widget left_wid = QtWidgets.QWidget() seperator.addWidget(left_wid) left_lay = QtWidgets.QVBoxLayout() left_wid.setLayout(left_lay) # Build browser self._qt_build = qt_root_browser.QtRootBrowser() left_lay.addWidget(self._qt_build) # Output out_wid = QtWidgets.QWidget() out_lay = QtWidgets.QGridLayout() out_wid.setLayout(out_lay) left_lay.addWidget(out_wid) out_icon = QtGui.QIcon(':file-upload.png') out_btn = QtWidgets.QPushButton() out_btn.clicked.connect(self._out_browse) out_btn.setFixedSize(35, 35) out_btn.setIcon(out_icon) out_btn.setIconSize(QtCore.QSize(30, 30)) output_label = QtWidgets.QLabel('Output Folder : ') self._out_edit = QtWidgets.QLineEdit() out_lay.addWidget(output_label, 0, 0) out_lay.addWidget(self._out_edit, 0, 1) out_lay.addWidget(out_btn, 0, 2) # Color self._color = color.Color() left_lay.addWidget(self._color) # Type self._rcc_type = rcc_type.RCC_Type() left_lay.addWidget(self._rcc_type) # Browser _browser = browser.Browser() left_lay.addWidget(_browser) # List self._list = listview.ListView() _browser.gotFiles.connect(self._list.set_items) left_lay.addWidget(self._list) # Add add = addbutton.AddButton() add.gotFiles.connect(self._list.set_items) seperator.addWidget(add) # Footer footer = QtWidgets.QWidget() footer.setFixedHeight(60) footer_lay = QtWidgets.QHBoxLayout() footer_lay.setAlignment(QtCore.Qt.AlignCenter) footer.setLayout(footer_lay) m_layout.addWidget(footer) # Convert convert_btn = QtWidgets.QPushButton('Convert to PNG') convert_btn.clicked.connect(self._convert) convert_btn.setFixedSize(200, 50) footer_lay.addWidget(convert_btn) # Make rcc rcc_btn = QtWidgets.QPushButton('Make Qt RCC') rcc_btn.clicked.connect(self._make_rcc) rcc_btn.setFixedSize(200, 50) footer_lay.addWidget(rcc_btn)
def __init__(self, parent, points, callback, callback_data, back_color, text_color, line_color): self.textColor = QtGui.QColor(255, 0, 0) self.backColor = QtGui.QColor(0, 255, 0) self.lineColor = QtGui.QColor(255, 255, 0) self.textColor = text_color self.backColor = back_color self.lineColor = line_color self.callback = callback self.callback_data = callback_data #self.fig = Figure(figsize=(width, height), facecolor='grey') #self.fig = Figure(facecolor='grey') self.fig = Figure(facecolor=( self.backColor.redF(), self.backColor.greenF(), self.backColor.blueF())) self.axes = self.fig.add_subplot(1, 1, 1) self.fig.tight_layout(pad=2) self.fig.subplots_adjust(right=0.99, top=0.99) #self.fig.subplots_adjust(right=0.99, left=0.01, bottom=0.01, top=0.99) self.axes.set_facecolor( (self.backColor.redF(), self.backColor.greenF(), self.backColor.blueF())) self.axes.set_xlim(-3, 103) self.axes.set_ylim(-5, 105) self.axes.grid(which="both", color=( self.textColor.redF(), self.textColor.greenF(), self.textColor.blueF()), clip_on=False, alpha=1, fillstyle='none') self.axes.spines['top'].set_visible(False) self.axes.spines['bottom'].set_visible(False) self.axes.spines['right'].set_visible(False) self.axes.spines['left'].set_visible(False) self.axes.xaxis.label.set_color(( self.textColor.redF(), self.textColor.greenF(), self.textColor.blueF())) self.axes.yaxis.label.set_color(( self.textColor.redF(), self.textColor.greenF(), self.textColor.blueF())) for tic in self.axes.xaxis.get_major_ticks(): tic.tick1line.set_visible(False) tic.tick2line.set_visible(False) for tic in self.axes.yaxis.get_major_ticks(): tic.tick1line.set_visible(False) tic.tick2line.set_visible(False) self.axes.grid(True) super().__init__(self.fig) self.setParent(parent) self.axes.tick_params(axis='both', pad=0.0) self.axes.set_xticks([0, 20, 40, 60, 80, 100]) self.axes.set_yticks([0, 20, 40, 60, 80, 100]) for item in (self.axes.get_xticklabels() + self.axes.get_yticklabels()): item.set_fontsize(7.5) item.set_color(( self.textColor.redF(), self.textColor.greenF(), self.textColor.blueF())) FigureCanvas.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) FigureCanvas.updateGeometry(self) self._line = None self._dragging_point = None self._pointsX, self._pointsY = to_x_y_arrays(points) self._pointsX, self._pointsY = fix_and_clean_x_y( self._pointsX, self._pointsY) self._update_plot() self.fig.canvas.mpl_connect('button_press_event', self._on_click) self.fig.canvas.mpl_connect( 'button_release_event', self._on_release) self.fig.canvas.mpl_connect('motion_notify_event', self._on_motion)
data = int(temp) expenditure = expenditure + data result = cur.execute('SELECT * FROM MoneyManagement WHERE Year=(?)', condition) for row_number, row_data in enumerate(result): for column_number, data in enumerate(row_data): self.tableWidget.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data))) con.close() self.label_3.setText(QtWidgets.QApplication.translate("self.centralwidget", "Your Income this year is: {}".format(str(income)), None, -1)) self.label_4.setText(QtWidgets.QApplication.translate("self.centralwidget", "Your Expenditure this year is: {}".format(str(expenditure)), None, -1)) if(__name__ == '__main__'): app = QtWidgets.QApplication(sys.argv) app.setStyle("Fusion") palette = QtGui.QPalette() palette.setColor(QtGui.QPalette.Window, QtGui.QColor(50,50,50)) palette.setColor(QtGui.QPalette.WindowText, QtGui.QColor(60,224,238)) palette.setColor(QtGui.QPalette.Base, QtGui.QColor(0,0,0)) palette.setColor(QtGui.QPalette.ToolTipBase, QtCore.Qt.white) palette.setColor(QtGui.QPalette.ToolTipText, QtCore.Qt.white) palette.setColor(QtGui.QPalette.Text, QtCore.Qt.white) palette.setColor(QtGui.QPalette.Button, QtGui.QColor(53,53,53)) palette.setColor(QtGui.QPalette.ButtonText, QtGui.QColor(60,224,238)) app.setPalette(palette) app.setWindowIcon(QtGui.QIcon('./icon.jpg')) window = MainWidget() window.show() sys.exit(app.exec_())
def showCategories(self): self.newPage() self.fadeShapes() self.currentCategory = "" self.currentExample = "" # Sort the category names excluding any "Qt" prefix. def csort(c1, c2): if c1.startsWith("Qt "): c1 = c1[3:] if c2.startsWith("Qt "): c2 = c2[3:] return cmp(c1, c2) categories = [c for c in self.categories.keys() if c != "[main]"] categories.sort(csort) horizontalMargin = 0.025*self.width() verticalMargin = 0.025*self.height() title = TitleShape(self.tr("PyQt Examples and Demos"), self.titleFont, QtGui.QPen(QtGui.QColor("#a6ce39")), QtCore.QPointF(), QtCore.QSizeF(0.5*self.width(), 4*verticalMargin)) title.setPosition(QtCore.QPointF(self.width() / 2 - title.rect().width() / 2, -title.rect().height())) title.setTarget(QtCore.QPointF(title.position().x(), verticalMargin)) self.display.appendShape(title) topMargin = 6*verticalMargin bottomMargin = self.height() - 3.2*verticalMargin space = bottomMargin - topMargin step = min(title.rect().height() / self.fontRatio, space/self.maximumLabels ) textHeight = self.fontRatio * step startPosition = QtCore.QPointF(0.0, topMargin) maxSize = QtCore.QSizeF(10.8*horizontalMargin, textHeight) maxWidth = 0.0 newShapes = [] for category in categories: caption = TitleShape(category, self.font(), QtGui.QPen(), QtCore.QPointF(startPosition), QtCore.QSizeF(maxSize)) caption.setPosition(QtCore.QPointF(-caption.rect().width(), caption.position().y())) caption.setTarget(QtCore.QPointF(2*horizontalMargin, caption.position().y())) newShapes.append(caption) startPosition += QtCore.QPointF(0.0, step) maxWidth = max(maxWidth, caption.rect().width() ) exitButton = TitleShape(self.tr("Exit"), self.font(), QtGui.QPen(QtCore.Qt.white), QtCore.QPointF(startPosition), QtCore.QSizeF(maxSize)) exitButton.setTarget(QtCore.QPointF(2*horizontalMargin, exitButton.position().y())) newShapes.append(exitButton) startPosition = QtCore.QPointF(self.width(), topMargin ) extra = (step - textHeight)/4 backgroundPath = QtGui.QPainterPath() backgroundPath.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight + 2*extra) for category in categories: background = PanelShape(backgroundPath, QtGui.QBrush(self.categories[category]['color']), QtGui.QBrush(QtGui.QColor("#e0e0ff")), QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition), QtCore.QSizeF(maxWidth + 4*extra, textHeight + 2*extra)) background.metadata["category"] = category background.setInteractive(True) background.setTarget(QtCore.QPointF(2*horizontalMargin, background.position().y())) self.display.insertShape(0, background) startPosition += QtCore.QPointF(0.0, step) exitPath = QtGui.QPainterPath() exitPath.moveTo(-2*extra, -extra) exitPath.lineTo(-8*extra, textHeight/2) exitPath.lineTo(-extra, textHeight + extra) exitPath.lineTo(maxWidth + 2*extra, textHeight + extra) exitPath.lineTo(maxWidth + 2*extra, -extra) exitPath.closeSubpath() exitBackground = PanelShape(exitPath, QtGui.QBrush(QtGui.QColor("#a6ce39")), QtGui.QBrush(QtGui.QColor("#c7f745")), QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition), QtCore.QSizeF(maxWidth + 10*extra, textHeight + 2*extra)) exitBackground.metadata["action"] = "exit" exitBackground.setInteractive(True) exitBackground.setTarget(QtCore.QPointF(2*horizontalMargin, exitBackground.position().y())) self.display.insertShape(0, exitBackground) for caption in newShapes: position = caption.target() size = caption.rect().size() caption.setPosition(QtCore.QPointF(-maxWidth, position.y())) self.display.appendShape(caption) leftMargin = 3*horizontalMargin + maxWidth rightMargin = self.width() - 3*horizontalMargin description = DocumentShape(self.categories['[main]']['description'], self.documentFont, QtCore.QPointF(leftMargin, topMargin), QtCore.QSizeF(rightMargin - leftMargin, space)) description.metadata["fade"] = 10 self.display.appendShape(description) imageHeight = title.rect().height() + verticalMargin qtLength = min(imageHeight, title.rect().left()-3*horizontalMargin) qtMaxSize = QtCore.QSizeF(qtLength, qtLength) qtShape = ImageShape(self.qtLogo, QtCore.QPointF(2*horizontalMargin-extra, -imageHeight), qtMaxSize, 0, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) qtShape.metadata["fade"] = 15 qtShape.setTarget(QtCore.QPointF(qtShape.rect().x(), verticalMargin)) self.display.insertShape(0, qtShape) trolltechMaxSize = QtCore.QSizeF( self.width()-3*horizontalMargin-title.rect().right(), imageHeight) trolltechShape = ImageShape(self.rbLogo, QtCore.QPointF(self.width()-2*horizontalMargin-trolltechMaxSize.width()+extra, -imageHeight), trolltechMaxSize, 0, QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) trolltechShape.metadata["fade"] = 15 trolltechShape.setTarget(QtCore.QPointF(trolltechShape.rect().x(), verticalMargin)) self.display.insertShape(0, trolltechShape) self.addVersionAndCopyright(QtCore.QRectF(2*horizontalMargin, self.height() - verticalMargin - textHeight, self.width() - 4*horizontalMargin, textHeight))
def createCurveIcons(self): pix = QtGui.QPixmap(self.m_iconSize) painter = QtGui.QPainter() gradient = QtGui.QLinearGradient(0, 0, 0, self.m_iconSize.height()) gradient.setColorAt(0.0, QtGui.QColor(240, 240, 240)) gradient.setColorAt(1.0, QtGui.QColor(224, 224, 224)) brush = QtGui.QBrush(gradient) # The original C++ code uses undocumented calls to get the names of the # different curve types. We do the Python equivalant (but without # cheating) curve_types = [(n, c) for n, c in QtCore.QEasingCurve.__dict__.items() if isinstance(c, QtCore.QEasingCurve.Type) \ and c != QtCore.QEasingCurve.Custom \ and c != QtCore.QEasingCurve.NCurveTypes] curve_types.sort(key=lambda ct: ct[1]) painter.begin(pix) for curve_name, curve_type in curve_types: painter.fillRect( QtCore.QRect(QtCore.QPoint(0, 0), self.m_iconSize), brush) curve = QtCore.QEasingCurve(curve_type) painter.setPen(QtGui.QColor(0, 0, 255, 64)) xAxis = self.m_iconSize.height() / 1.5 yAxis = self.m_iconSize.width() / 3.0 painter.drawLine(0, xAxis, self.m_iconSize.width(), xAxis) painter.drawLine(yAxis, 0, yAxis, self.m_iconSize.height()) curveScale = self.m_iconSize.height() / 2.0 painter.setPen(QtCore.Qt.NoPen) # Start point. painter.setBrush(QtCore.Qt.red) start = QtCore.QPoint( yAxis, xAxis - curveScale * curve.valueForProgress(0)) painter.drawRect(start.x() - 1, start.y() - 1, 3, 3) # End point. painter.setBrush(QtCore.Qt.blue) end = QtCore.QPoint(yAxis + curveScale, xAxis - curveScale * curve.valueForProgress(1)) painter.drawRect(end.x() - 1, end.y() - 1, 3, 3) curvePath = QtGui.QPainterPath() curvePath.moveTo(QtCore.QPointF(start)) t = 0.0 while t <= 1.0: to = QtCore.QPointF( yAxis + curveScale * t, xAxis - curveScale * curve.valueForProgress(t)) curvePath.lineTo(to) t += 1.0 / curveScale painter.setRenderHint(QtGui.QPainter.Antialiasing, True) painter.strokePath(curvePath, QtGui.QColor(32, 32, 32)) painter.setRenderHint(QtGui.QPainter.Antialiasing, False) item = QtGui.QListWidgetItem() item.setIcon(QtGui.QIcon(pix)) item.setText(curve_name) self.m_ui.easingCurvePicker.addItem(item) painter.end()
def showExamples(self, category): self.newPage() self.fadeShapes() self.currentCategory = category self.currentExample = "" horizontalMargin = 0.025*self.width() verticalMargin = 0.025*self.height() title = self.addTitle(category, verticalMargin) self.addTitleBackground(title) topMargin = 6*verticalMargin bottomMargin = self.height() - 3.2*verticalMargin space = bottomMargin - topMargin step = min(title.rect().height() / self.fontRatio, space/self.maximumLabels ) textHeight = self.fontRatio * step startPosition = QtCore.QPointF(2*horizontalMargin, self.height()+topMargin) finishPosition = QtCore.QPointF(2*horizontalMargin, topMargin) maxSize = QtCore.QSizeF(32*horizontalMargin, textHeight) maxWidth = 0.0 for example in self.categories[self.currentCategory]['examples']: caption = TitleShape(example, self.font(), QtGui.QPen(), QtCore.QPointF(startPosition), QtCore.QSizeF(maxSize)) caption.setTarget(QtCore.QPointF(finishPosition)) self.display.appendShape(caption) startPosition += QtCore.QPointF(0.0, step) finishPosition += QtCore.QPointF(0.0, step) maxWidth = max(maxWidth, caption.rect().width() ) menuButton = TitleShape(self.tr("Main Menu"), self.font(), QtGui.QPen(QtCore.Qt.white), QtCore.QPointF(startPosition), QtCore.QSizeF(maxSize)) menuButton.setTarget(QtCore.QPointF(finishPosition)) self.display.appendShape(menuButton) startPosition = QtCore.QPointF(self.width(), topMargin ) extra = (step - textHeight)/4 for example in self.categories[self.currentCategory]['examples']: uniquename = self.currentCategory + "-" + example path = QtGui.QPainterPath() path.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight+2*extra) background = PanelShape(path, QtGui.QBrush(self.examples[uniquename]['color']), QtGui.QBrush(QtGui.QColor("#e0e0ff")), QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition), QtCore.QSizeF(maxWidth + 4*extra, textHeight + 2*extra)) background.metadata["example"] = uniquename background.setInteractive(True) background.setTarget(QtCore.QPointF(2*horizontalMargin, background.position().y())) self.display.insertShape(0, background) startPosition += QtCore.QPointF(0.0, step) backPath = QtGui.QPainterPath() backPath.moveTo(-2*extra, -extra) backPath.lineTo(-8*extra, textHeight/2) backPath.lineTo(-extra, textHeight + extra) backPath.lineTo(maxWidth + 2*extra, textHeight + extra) backPath.lineTo(maxWidth + 2*extra, -extra) backPath.closeSubpath() buttonBackground = PanelShape(backPath, QtGui.QBrush(QtGui.QColor("#a6ce39")), QtGui.QBrush(QtGui.QColor("#c7f745")), QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition), QtCore.QSizeF(maxWidth + 10*extra, textHeight + 2*extra)) buttonBackground.metadata["action"] = "parent" buttonBackground.setInteractive(True) buttonBackground.setTarget(QtCore.QPointF(2*horizontalMargin, buttonBackground.position().y())) self.display.insertShape(0, buttonBackground) leftMargin = 3*horizontalMargin + maxWidth rightMargin = self.width() - 3*horizontalMargin description = DocumentShape(self.categories[self.currentCategory]['description'], self.documentFont, QtCore.QPointF(leftMargin, topMargin), QtCore.QSizeF(rightMargin - leftMargin, space), 0) description.metadata["fade"] = 10 self.display.appendShape(description) self.addVersionAndCopyright(QtCore.QRectF(2*horizontalMargin, self.height() - verticalMargin - textHeight, self.width() - 4*horizontalMargin, textHeight))
def __init__(self, *args, **kwargs): super(ClipItem, self).__init__(*args, **kwargs) self.setBrush(QtGui.QBrush(QtGui.QColor(168, 197, 255, 255))) self.source_name_label.setText(self.item.name)
def showExampleSummary(self, uniquename): self.newPage() self.fadeShapes() self.currentExample = uniquename horizontalMargin = 0.025*self.width() verticalMargin = 0.025*self.height() title = self.addTitle(self.examples[uniquename]['name'], verticalMargin) titleBackground = self.addTitleBackground(title) topMargin = 2*verticalMargin + titleBackground.rect().bottom() bottomMargin = self.height() - 8*verticalMargin space = bottomMargin - topMargin step = min(title.rect().height() / self.fontRatio, ( bottomMargin + 4.8*verticalMargin - topMargin )/self.maximumLabels ) footerTextHeight = self.fontRatio * step leftMargin = 3*horizontalMargin rightMargin = self.width() - 3*horizontalMargin if self.examples[self.currentExample].has_key('description'): description = DocumentShape( self.examples[self.currentExample]['description'], self.documentFont, QtCore.QPointF(leftMargin, topMargin), QtCore.QSizeF(rightMargin-leftMargin, space), 0 ) description.metadata["fade"] = 10 description.setPosition(QtCore.QPointF(description.position().x(), 0.8*self.height()-description.rect().height())) self.display.appendShape(description) space = description.position().y() - topMargin - 2*verticalMargin if self.examples[self.currentExample].has_key('image files'): image = QtGui.QImage(self.examples[self.currentExample]['image files'][0]) imageMaxSize = QtCore.QSizeF(self.width() - 8*horizontalMargin, space) self.currentFrame = ImageShape( image, QtCore.QPointF(self.width()-imageMaxSize.width()/2, topMargin), QtCore.QSizeF(imageMaxSize )) self.currentFrame.metadata["fade"] = 15 self.currentFrame.setTarget(QtCore.QPointF(self.width()/2-imageMaxSize.width()/2, topMargin)) self.display.appendShape(self.currentFrame) if len(self.examples[self.currentExample]['image files']) > 1: self.connect(self.slideshowTimer, QtCore.SIGNAL("timeout()"), self.updateExampleSummary) self.slideshowFrame = 0 self.slideshowTimer.start() maxSize = QtCore.QSizeF(0.3*self.width(),2*verticalMargin) leftMargin = 0.0 rightMargin = 0.0 backButton = TitleShape(self.currentCategory, self.font(), QtGui.QPen(QtCore.Qt.white), QtCore.QPointF(0.1*self.width(), self.height()), QtCore.QSizeF(maxSize), QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) backButton.setTarget(QtCore.QPointF(backButton.position().x(), self.height() - 5.2*verticalMargin)) self.display.appendShape(backButton) maxWidth = backButton.rect().width() textHeight = backButton.rect().height() extra = (3*verticalMargin - textHeight)/4 path = QtGui.QPainterPath() path.moveTo(-extra, -extra) path.lineTo(-4*extra, textHeight/2) path.lineTo(-extra, textHeight + extra) path.lineTo(maxWidth + 2*extra, textHeight + extra) path.lineTo(maxWidth + 2*extra, -extra) path.closeSubpath() buttonBackground = PanelShape(path, QtGui.QBrush(QtGui.QColor("#a6ce39")), QtGui.QBrush(QtGui.QColor("#c7f745")), QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(backButton.position()), QtCore.QSizeF(maxWidth + 6*extra, textHeight + 2*extra)) buttonBackground.metadata["category"] = self.currentCategory buttonBackground.setInteractive(True) buttonBackground.setTarget(QtCore.QPointF(backButton.target())) self.display.insertShape(0, buttonBackground) leftMargin = buttonBackground.rect().right() if self.examples[self.currentExample].has_key('absolute path'): launchCaption = TitleShape(self.tr("Launch"), self.font(), QtGui.QPen(QtCore.Qt.white), QtCore.QPointF(0.0, 0.0), QtCore.QSizeF(maxSize), QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) launchCaption.setPosition(QtCore.QPointF( 0.9*self.width() - launchCaption.rect().width(), self.height())) launchCaption.setTarget(QtCore.QPointF(launchCaption.position().x(), self.height() - 5.2*verticalMargin)) self.display.appendShape(launchCaption) maxWidth = launchCaption.rect().width() textHeight = launchCaption.rect().height() extra = (3*verticalMargin - textHeight)/4 path = QtGui.QPainterPath() path.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight + 2*extra) backgroundColor = QtGui.QColor("#a63e39") highlightedColor = QtGui.QColor("#f95e56") background = PanelShape(path, QtGui.QBrush(backgroundColor), QtGui.QBrush(highlightedColor), QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(launchCaption.position()), QtCore.QSizeF(maxWidth + 4*extra, textHeight + 2*extra)) background.metadata["fade minimum"] = 120 background.metadata["launch"] = self.currentExample background.setInteractive(True) background.setTarget(QtCore.QPointF(launchCaption.target())) if self.currentExample in self.runningExamples: background.metadata["highlight"] = True background.metadata["highlight scale"] = 0.99 background.animate() background.metadata["fade"] = -135 self.slideshowTimer.stop() self.display.insertShape(0, background) rightMargin = background.rect().left() if self.examples[self.currentExample]['document path']: documentCaption = TitleShape(self.tr("Show Documentation"), self.font(), QtGui.QPen(QtCore.Qt.white), QtCore.QPointF(0.0, 0.0), QtCore.QSizeF(maxSize), QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) if rightMargin == 0.0: documentCaption.setPosition(QtCore.QPointF( 0.9*self.width() - documentCaption.rect().width(), self.height())) else: documentCaption.setPosition(QtCore.QPointF( leftMargin/2 + rightMargin/2 - documentCaption.rect().width()/2, self.height())) documentCaption.setTarget(QtCore.QPointF(documentCaption.position().x(), self.height() - 5.2*verticalMargin)) self.display.appendShape(documentCaption) maxWidth = documentCaption.rect().width() textHeight = documentCaption.rect().height() extra = (3*verticalMargin - textHeight)/4 path = QtGui.QPainterPath() path.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight + 2*extra) background = PanelShape(path, QtGui.QBrush(QtGui.QColor("#9c9cff")), QtGui.QBrush(QtGui.QColor("#cfcfff")), QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(documentCaption.position()), QtCore.QSizeF(maxWidth + 4*extra, textHeight + 2*extra)) background.metadata["fade minimum"] = 120 background.metadata["documentation"] = self.currentExample background.setInteractive(True) background.setTarget(QtCore.QPointF(documentCaption.target())) self.display.insertShape(0, background) self.addVersionAndCopyright(QtCore.QRectF(2*horizontalMargin, self.height() - verticalMargin - footerTextHeight, self.width() - 4*horizontalMargin, footerTextHeight))
def __init__(self, track, *args, **kwargs): super(Track, self).__init__(*args, **kwargs) self.track = track self.setBrush(QtGui.QBrush(QtGui.QColor(43, 52, 59, 255))) self._populate()
class AbstractDelegate(QtWidgets.QItemDelegate): """Handles drawing of items for the TreeWidget. Provides special handling for selected jobs in order to still display background color.""" __colorInvalid = QtGui.QColor() __brushSelected = QtGui.QBrush(QtCore.Qt.Dense4Pattern) __colorUsed = QtGui.QColor(255, 0, 0) __colorFree = QtGui.QColor(0, 255, 0) def __init__(self, parent, jobProgressBarColumn = None, *args): QtWidgets.QItemDelegate.__init__(self, parent, *args) def paint(self, painter, option, index): if option.state & QtWidgets.QStyle.State_Selected: # If selected cell self._paintSelected(painter, option, index) else: # Everything else QtWidgets.QItemDelegate.paint(self, painter, option, index) def _paintDifferenceBar(self, painter, option, index, used, total): if not total: return painter.save() try: self._drawBackground(painter, option, index) rect = option.rect.adjusted(2, 6, -2, -6) ratio = rect.width() / float(total) length = int(ceil(ratio * (used))) painter.fillRect(rect, self.__colorUsed) painter.fillRect(rect.adjusted(length, 0, 0, 0), self.__colorFree) if option.state & QtWidgets.QStyle.State_Selected: self._drawSelectionOverlay(painter, option) finally: painter.restore() del painter def _drawProgressBar(self, painter, rect, frameStateTotals): """Returns the list that defines the column. @type painter: QPainter @param painter: The painter to draw with @type rect: QRect @param rect: The area to draw in @type frameStateTotals: dict @param frameStateTotals: Dictionary of frame states and their amount""" ratio = rect.width() / float(sum(frameStateTotals.values())) for frameState in FRAME_STATES: length = int(ceil(ratio * frameStateTotals[frameState])) if length > 0: rect.setWidth(length) painter.fillRect(rect, RGB_FRAME_STATE[frameState]) rect.setX(rect.x() + length) def _paintSelected(self, painter, option, index): painter.save() try: self._drawBackground(painter, option, index) # Draw the selection overlay self._drawSelectionOverlay(painter, option) # Draw the icon, if any value = index.data(QtCore.Qt.DecorationRole) if value is not None: icon = QtGui.QIcon(value) icon.paint(painter, option.rect.adjusted(3, 1, -1, -1), QtCore.Qt.AlignLeft) option.rect.adjust(22, 0, 0, 0) # Draw the text painter.setPen(QtGui.QColor(index.data(QtCore.Qt.ForegroundRole))) painter.drawText(option.rect.adjusted(3, -1, -3, 0), QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, str(index.data(QtCore.Qt.DisplayRole))) finally: painter.restore() del painter def _drawBackground(self, painter, option, index): # Draw the background color painter.setPen(NO_PEN) role = index.data(QtCore.Qt.BackgroundRole) if role is not None: painter.setBrush(QtGui.QBrush(role)) else: painter.setBrush(NO_BRUSH) painter.drawRect(option.rect) def _drawSelectionOverlay(self, painter, option): # Draw the selection if option.rect.width() > 0: selectionPen = QtGui.QPen(self.__colorInvalid) selectionPen.setWidth(0) painter.setPen(selectionPen) painter.setBrush(self.__brushSelected) painter.drawRect(option.rect)