def _init_widgets(self): if self._state.am_none(): return layout = QVBoxLayout() area = QScrollArea() area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) area.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) area.setWidgetResizable(True) table = QTableWidget(0, 0) table.setColumnCount(len(self.COLUMNS)) table.setHorizontalHeaderLabels(self.COLUMNS) self.table = table layout.addWidget(table) # common ones layout.setSpacing(0) layout.addStretch(0) layout.setContentsMargins(2, 2, 2, 2) # the container container = QFrame() container.setAutoFillBackground(True) palette = container.palette() palette.setColor(container.backgroundRole(), Qt.white) container.setPalette(palette) container.setLayout(layout) area.setWidget(container) base_layout = QVBoxLayout() base_layout.addWidget(area) self.setLayout(base_layout)
def _init_widgets(self): if self._state.am_none(): return if self._state.arch.name not in self.ARCH_REGISTERS: l.error( "Architecture %s is not listed in QRegisterViewer.ARCH_REGISTERS.", self._state.arch.name) return layout = QVBoxLayout() area = QScrollArea() area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) area.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) area.setWidgetResizable(True) regs = self.ARCH_REGISTERS[self._state.arch.name] # common ones common_regs = regs['common'] for reg_name in common_regs: sublayout = QHBoxLayout() lbl_reg_name = QLabel(self) lbl_reg_name.setProperty('class', 'reg_viewer_label') lbl_reg_name.setText(reg_name) lbl_reg_name.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sublayout.addWidget(lbl_reg_name) sublayout.addSpacing(10) reg_value = QASTViewer(None, parent=self, workspace=self.workspace) self._registers[reg_name] = reg_value sublayout.addWidget(reg_value) layout.addLayout(sublayout) layout.setSpacing(0) layout.addStretch(0) layout.setContentsMargins(2, 2, 2, 2) # the container container = QFrame() container.setAutoFillBackground(True) palette = container.palette() palette.setColor(container.backgroundRole(), Qt.white) container.setPalette(palette) container.setLayout(layout) area.setWidget(container) base_layout = QVBoxLayout() base_layout.addWidget(area) self.setLayout(base_layout)
def init_logging(self, collapsible): self.logger = QPushButton("Start Logging", self) self.logger.setFont(QFont("Times", 14, QFont.Bold)) self.logger.clicked.connect(lambda: self.display_log_data()) self.logger.setStyleSheet("background-color: white") #self.filterLayout = QtWidgets.QHBoxLayout() self.logFilterLabel = QLabel('Filter', self) self.logFilterLabel.setFont(QFont("Times", 14, QFont.Bold)) self.logFilterLabel.setPalette(get_white_color_text()) self.logFilterLabel.setFixedWidth(60) self.logFilter = QLineEdit(self) self.logFilter.setPalette(get_white_color()) self.logFilter.setStyleSheet("background-color: white") self.logFilter.setFixedWidth(200) #self.filterLayout.addWidget(self.logFilterLabel, QtCore.Qt.AlignLeft) #self.filterLayout.addWidget(self.logFilter, QtCore.Qt.AlignLeft) self.serialList = QComboBox() ports = get_available_serial_ports() if (len(ports) == 1): self.serialList.addItem(ports[0]) self.thread.set_comport(self.serialList.currentText()) else: self.serialList.addItem("Select") for port in ports: self.serialList.addItem(port) self.serialList.currentIndexChanged.connect( lambda: self.set_serial_port()) self.serialList.setStyleSheet("background-color: white") self.clear = QPushButton("Clear Log File", self) self.clear.setStyleSheet("background-color: white") self.clear.setFont(QFont("Times", 14, QFont.Bold)) self.clear.clicked.connect(lambda: self.clear_data()) widget = QFrame(collapsible.get_tree()) widget.setPalette(get_verifone_color()) title = "Logging" self.loggerGrid = QGridLayout(widget) self.loggerGrid.addWidget(self.logger, 0, 0, 1, 2) self.loggerGrid.addWidget(self.logFilterLabel, 1, 0, 1, 1) self.loggerGrid.addWidget(self.logFilter, 1, 1, 1, 1) self.loggerGrid.addWidget(self.serialList, 2, 0, 1, 2) self.loggerGrid.addWidget(self.clear, 3, 0, 1, 2) collapsible.include_section(title, widget)
def _load_tmps(self): state = self.state.am_obj layout = QVBoxLayout() self._tmps.clear() if state is None: tmps = {} else: tmps = state.scratch.temps # tmps for tmp_id, tmp_value in tmps.items(): sublayout = QHBoxLayout() lbl_tmp_name = QLabel(self) lbl_tmp_name.setProperty('class', 'reg_viewer_label') lbl_tmp_name.setText("tmp_%d" % tmp_id) lbl_tmp_name.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sublayout.addWidget(lbl_tmp_name) sublayout.addSpacing(10) tmp_viewer = QASTViewer(tmp_value, workspace=self.workspace, parent=self) self._tmps[tmp_id] = tmp_viewer sublayout.addWidget(tmp_viewer) layout.addLayout(sublayout) layout.setSpacing(0) layout.addStretch(0) layout.setContentsMargins(2, 2, 2, 2) # the container container = QFrame() container.setAutoFillBackground(True) palette = container.palette() palette.setColor(container.backgroundRole(), Qt.white) container.setPalette(palette) container.setLayout(layout) self._area.setWidget(container)
class DisplayWidgetGroup(QWidget): def __init__(self, parent, id): super().__init__(parent) self.displays = [] self.groupID = id self.displayArea = parent self.minX = 1000000 self.minY = 1000000 self.maxX = 0 self.maxY = 0 self.labelFrame = QFrame(self) self.labelFrame.setFrameShape(QFrame.Box) self.labelFrame.setAutoFillBackground(True) p = self.labelFrame.palette() p.setColor(self.backgroundRole(), QColor(80, 80, 200, 20)) self.labelFrame.setPalette(p) self.label = QLabel(self.labelFrame) self.label.setText(self.groupID) self.label.setFont(QFont("arial", 32)) self.label.setAlignment(Qt.AlignCenter) self.globalBounds = [0, 0, self.width(), self.height()] self.widgetBounds = [0, 0, self.width(), self.height()] def AddDisplay(self, displayInfo): display = DisplayWidget(self, displayInfo) self.displays.append(display) dimensions = displayInfo["bounds"] self.minX = min(self.minX, dimensions[0]) self.minY = min(self.minY, dimensions[1]) self.maxX = max(self.maxX, (dimensions[2] + dimensions[0])) self.maxY = max(self.maxY, (dimensions[3] + dimensions[1])) self.labelFrame.raise_() self.UpdateDisplaysGroupBounds() def resizeEvent(self, event): self.labelFrame.setGeometry(0, 0, self.width(), self.height()) self.label.setGeometry(0, 0, self.width(), self.height()) f = QFont("ariel", self.FontSizeForWidth()) self.label.setFont(f) for display in self.displays: display.SetWidgetBounds([0, 0, self.width(), self.height()]) display.UpdateGeometry() return super().resizeEvent(event) def FontSizeForWidth(self): text = self.label.text() textSize = len(text) f = self.label.font() metrics = QFontMetrics(f) width = metrics.width(text) myWidth = self.label.width() size = 0 if width < myWidth: direction = 1 else: direction = -1 while (True): f = QFont("Ariel", size + 1) mf = QFontMetrics(f) self.label.setFont(f) width = mf.width(text) if direction > 0: if width >= myWidth: break else: if width <= myWidth: break size = f.pointSize() + direction return size def UpdateGlobalBounds(self, bounds): self.globalBounds = bounds.copy() def SetWidgetBounds(self, bounds): self.widgetBounds = bounds.copy() for display in self.displays: display.SetWidgetBounds([0, 0, self.width(), self.height()]) display.UpdateGeometry() def UpdateGeometry(self): scaleX = (self.widgetBounds[2] - self.widgetBounds[0]) / ( self.globalBounds[2] - self.globalBounds[0]) scaleY = (self.widgetBounds[3] - self.widgetBounds[1]) / ( self.globalBounds[3] - self.globalBounds[1]) posX = ( (self.minX - self.globalBounds[0]) * scaleX) + self.widgetBounds[0] posY = ( (self.minY - self.globalBounds[1]) * scaleY) + self.widgetBounds[1] width = (self.maxX - self.minX) * scaleX height = (self.maxY - self.minY) * scaleY self.setGeometry(posX, posY, width, height) def UpdateDisplaysGroupBounds(self): bounds = [ self.minX, self.minY, self.maxX - self.minX, self.maxY - self.minY ] for display in self.displays: display.SetGroupBounds(bounds) def GetGlobalOffset(self): scaleX = (self.globalBounds[2] - self.globalBounds[0]) / ( self.widgetBounds[2] - self.widgetBounds[0]) scaleY = (self.globalBounds[3] - self.globalBounds[0]) / ( self.widgetBounds[3] - self.widgetBounds[0]) posX = ((self.pos().x() - self.widgetBounds[0]) * scaleX) + self.globalBounds[0] posY = ((self.pos().y() - self.widgetBounds[1]) * scaleY) + self.globalBounds[1] return [posX, posY] def CollidesWith(self, widget): bounds = [ self.x(), self.y(), self.x() + self.width(), self.y() + self.height() ] other = [ widget.x(), widget.y(), widget.x() + widget.width(), widget.y() + widget.height() ] return not (other[0] > bounds[2] or other[2] < bounds[0] or\ other[1] > bounds[3] or other[3] < bounds[1]) def mouseMoveEvent(self, event): if self.oldPos: deltaPos = (event.globalPos() - self.oldPos) self.move(self.x() + deltaPos.x(), self.y() + deltaPos.y()) if self.displayArea.CheckCollision(self): self.move(self.x() - deltaPos.x(), self.y() - deltaPos.y()) self.oldPos = event.globalPos() return super().mouseMoveEvent(event) def mousePressEvent(self, event): self.oldPos = event.globalPos() return super().mousePressEvent(event) def mouseReleaseEvent(self, event): self.oldPos = None return super().mouseReleaseEvent(event)