def overlay_text( self, message: str, color: int, size: int, x: int, y: int, timeout: int, font_name: str, centered: bool, shadow: bool, ): gfx = QGraphicsTextItem(message) gfx.setDefaultTextColor(decode_color(color)) font = QFont(font_name, min(50, size)) font.setStyleHint(QFont.SansSerif) gfx.setFont(font) if shadow: effect = QGraphicsDropShadowEffect(gfx) effect.setBlurRadius(0) effect.setColor(Qt.GlobalColor.black) effect.setOffset(1, 1) gfx.setGraphicsEffect(effect) if centered: # The provided x, y is at the center of the text bound = gfx.boundingRect() gfx.setPos(x - (bound.width() / 2), y - (bound.height() / 2)) else: gfx.setPos(x, y) self._finalize_gfx(gfx, timeout)
def _create_meas(self, name, layout, row, col, temp): label = QLabel(name, self) font = label.font() font.setPointSize(8) font.setBold(True) label.setFont(font) layout.addWidget(label, row, col) layout.setAlignment(label, Qt.AlignRight) meas_value = QLineEdit(self) meas_value.setReadOnly(True) meas_value.setMaximumSize(65, 32) font = QFont('Monospace') font.setStyleHint(QFont.TypeWriter) font.setPointSize(10) meas_value.setFont(font) meas_value.setAlignment(Qt.AlignCenter) if temp: meas_value.setText('0.00 C') else: meas_value.setText('0.00 V') layout.addWidget(meas_value, row, col + 1) layout.setAlignment(meas_value, Qt.AlignLeft) return meas_value
def qt_util_init_text_edit(qw_text_edit): qw_text_edit.clear() qw_text_edit.setReadOnly(False) qw_text_edit.setFontPointSize(14) fixed_font = QFont("Monaco") fixed_font.setStyleHint(QFont.Helvetica) qw_text_edit.setFont(fixed_font) qw_text_edit.setTextColor(QColor(0, 0, 0, 255))
def setup_editor(self, font_size): font = QFont("Courier New") self.font_size = font_size font.setStyleHint(QFont.Monospace) font.setPointSize(self.font_size) self.lineNumberArea.setFont(font) self.char_width = self.fontMetrics().boundingRectChar('9').width() self.update_line_number_area_width(0)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) font = QFont('monospace', 8) font.setStyleHint(QFont.Monospace) self.setFont(font) self.setShowGrid(False) self.horizontalHeader().hide() self.verticalHeader().setSectionResizeMode( QtWidgets.QHeaderView.Fixed) self.verticalHeader().setHighlightSections(False) self.horizontalHeader().setHighlightSections(False) self.verticalHeader().setSectionsClickable(False) # Don't let the user edit the table cells. self.setEditTriggers(self.NoEditTriggers) self.setSelectionBehavior(QAbstractItemView.SelectItems) self.setSelectionMode(QAbstractItemView.ContiguousSelection) self.setModel(QStandardItemModel(1, 33)) # This will store the raw data that is displayed in the hex view. self.hex_data = None # Determine how wide ASCII columns should be. self.ascii_width = self.fontMetrics().width('m') # HACK: Get how much space a hex item needs by asking temporarily creating one, and then asking Qt, # because self.fontMetrics().width('mm') isn't enough, apparently, unlike above. self.model().setItem(0, 0, QStandardItem('mm')) self.resizeColumnToContents(0) self.hex_width = self.visualRect(self.model().createIndex( 0, 0)).width() # Default to 16 hex columns, with 16 ASCII columns, and one separator column, for a total of 33. self._set_bytes_per_row(16) # HACK: Get how much space is needed for 16 bytes per row by # getting the left and right bound of the left-most and right-most items, respectively. start = self.visualRect(self.model().createIndex(0, 0)).left() end = self.visualRect(self.model().createIndex(0, 32)).right() self.full_width = end - start # Record the default background color for items, since apparently that's platform dependent. # Note: Normally we can only get the default background color if there's actually an item there, # but we made one earlier to determine the value for self.hex_width, so we don't need to do it again. self.default_background_color = self.model().item(0, 0).background() self.model().setRowCount(0) self.selectionModel().selectionChanged.connect( self._selection_changed)
def _setup_ui(self, color): # Set up our basic layout layout = QHBoxLayout(self) self.setLayout(layout) layout.setSpacing(3) layout.setMargin(1) # Construct register groups for EB, FEXT, FB, and S eb_frame, self._eb_box = self._create_reg(self._eb_inds, 'EBANK', 3, color) fext_frame, self._fext_box = self._create_reg(self._fext_inds, 'FEXT', 3, color) fb_frame, self._fb_box = self._create_reg(self._fb_inds, 'FBANK', 5, color) s_frame, self._s_box = self._create_reg(self._s_inds, '', 12, color) layout.addWidget(eb_frame) layout.addWidget(fext_frame) layout.addWidget(fb_frame) layout.addWidget(s_frame) # Create a grouping widget for the S label and decoded octal value box label_value = QWidget(self) label_value.setMinimumWidth(100) lv_layout = QHBoxLayout(label_value) lv_layout.setSpacing(3) lv_layout.setMargin(1) lv_layout.setContentsMargins(0, 32, 0, 0) label_value.setLayout(lv_layout) layout.addWidget(label_value) # Create a value box for displaying the overall decoded address self._addr_value = QLineEdit(label_value) self._addr_value.setReadOnly(True) self._addr_value.setMaximumSize(65, 32) self._addr_value.setText('0000') font = QFont('Monospace') font.setStyleHint(QFont.TypeWriter) font.setPointSize(10) self._addr_value.setFont(font) self._addr_value.setAlignment(Qt.AlignCenter) lv_layout.addWidget(self._addr_value) # Create a label to show 'S' label = QLabel('S', label_value) font = label.font() font.setPointSize(14) font.setBold(True) label.setFont(font) lv_layout.addWidget(label) # Add some spacing to account for lack of parity indicators layout.addSpacing(36)
def create_node(self, position=list, text=str, size=int, textColor=QColor, bgColor=QColor, items=list, shape=PickShape.SQUARE): ''' Create a new PickNode. Parameters ---------- position: (list) List of x and y location. text: (str) Name of the text. size: (int) Size of the text. textColor: (QColor) Color of the text. bgColor: (QColor) Background Color of the node. items: (list) List of selected Maya object. Return ------ out: (PickNode) Reference of created Node. ''' textNode = PickNode() font = QFont("SansSerif", size) font.setStyleHint(QFont.Helvetica) textNode.setFont(font) textNode.setDefaultTextColor(textColor) textNode.setFlag(QGraphicsItem.ItemIsMovable, self.editMode) textNode.setFlag(QGraphicsItem.ItemIsSelectable) # textNode.setFlag(QGraphicsItem.ItemIsFocusable, self.editMode) textNode.Background = bgColor textNode.Items = items textNode.Shape = shape textNode.onSelected.connect(lambda: self.onSelection.emit(textNode)) textNode.onAddToStack.connect(lambda: self.add_stack(textNode)) textNode.onRemoveFromStack.connect(lambda: self.remove_stack(textNode)) textNode.setPos(position) textNode.setPlainText(text) self._scene.addItem(textNode) return textNode
def findMonospaceFont(): def isFixedPitch(font): return QFontInfo(font).fixedPitch() font = QFont('monospace') if isFixedPitch(font): return font font.setStyleHint(QFont.Monospace) if isFixedPitch(font): return font font.setStyleHint(QFont.TypeWriter) if isFixedPitch(font): return font font.setFamily("courier") if isFixedPitch(font): return font return font
def __init__(self, comms): super().__init__() self.setReadOnly(True) self.setLineWrapMode(QPlainTextEdit.NoWrap) self.setCenterOnScroll(True) font = QFont("Monospace") font.setStyleHint(QFont.TypeWriter) self.setFont(font) if _isCommArray(comms): for comm in comms: comm.logMessage.connect(self.logMessage) else: comms.logMessage.connect(self.logMessage)
def create_button(self, position=list, text=str, size=int, textColor=QColor, bgColor=QColor, cmd=str, cmdType=str): ''' Create a new ButtonNode. Parameters ---------- position: (list) List of x and y location. text: (str) Name of the text. size: (int) Size of the text. textColor: (QColor) Color of the text. bgColor: (QColor) Background Color of the node. cmd: (str) Command to run when it's pressed. cmdType: (str) Type of command.("python"/"mel") ''' btnNode = ButtonNode() font = QFont("SansSerif", size) font.setStyleHint(QFont.Helvetica) btnNode.setFont(font) btnNode.setDefaultTextColor(textColor) btnNode.setFlag(QGraphicsItem.ItemIsMovable, self.editMode) btnNode.setFlag(QGraphicsItem.ItemIsSelectable) btnNode.Background = bgColor btnNode.CommandsType = cmdType btnNode.Command = cmd # btnNode.onSelected.connect(lambda: self.onSelection.emit(textNode)) btnNode.onSelected.connect(lambda: self.onSelection.emit(btnNode)) btnNode.onClicked.connect(self.scriptJob) btnNode.setPos(position) btnNode.setPlainText(text) self._scene.addItem(btnNode)
def __init__(self, parent, log_name): super(DlgLog, self).__init__(parent) self.ui = Ui_DlgLog() self.ui.setupUi(self) font = QFont() font.setFamily("Courier") font.setStyleHint(QFont.Monospace) font.setFixedPitch(True) font.setPointSize(10) self.ui.txtEdit.setCurrentFont(font) # opens the log file with open(log_name, 'r') as f: str_res = f.read() # puts the content to text box self.ui.txtEdit.setPlainText(str_res)
def __init__(self, comm): super().__init__() layout = QVBoxLayout() self.plainText = QPlainTextEdit() self.plainText.setReadOnly(True) self.plainText.setLineWrapMode(QPlainTextEdit.NoWrap) self.plainText.setCenterOnScroll(True) font = QFont("Monospace") font.setStyleHint(QFont.TypeWriter) self.plainText.setFont(font) layout.addWidget(self.plainText) self.setLayout(layout) comm.errorCode.connect(self.errorCode)
def __init__(self, parent=None, size=basic_size): super(AnalogClock, self).__init__(parent) self._time = QTime.currentTime() self.setAttribute(Qt.WA_TranslucentBackground) if size is None: size = basic_size self.resize(size, size) else: if size < basic_size: size = basic_size self.resize(size, size) font = QFont() font.setStyleHint(QFont.SansSerif) font.setFamily('monospace') font.setPointSize(12) self.font = font
def _setup_ui(self): # Set up our basic layout layout = QHBoxLayout(self) self.setLayout(layout) layout.setSpacing(3) layout.setMargin(1) bit_frame = QFrame(self) layout.addWidget(bit_frame) bit_layout = QGridLayout(bit_frame) bit_layout.setSpacing(1) bit_layout.setMargin(0) bit_frame.setLayout(bit_layout) bit_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) col = 0 col = self._create_reg(bit_frame, bit_layout, col, 16, self._w_cmp_switches, self._w_ign_switches, self._update_val_box, self._send_ign_val) sep = QFrame(bit_frame) sep.setFrameStyle(QFrame.VLine | QFrame.Raised) bit_layout.addWidget(sep, 0, col, 2, 1) self._create_reg(bit_frame, bit_layout, col + 1, 2, self._par_cmp_switches, self._par_ign_switches, self._send_parity, self._send_parity) # Create a value box for displaying the overall decoded valess self._val_box = QLineEdit(self) layout.addWidget(self._val_box) self._val_box.setMaximumSize(52, 32) self._val_box.setText('00000') self._val_box.setValidator(RegValidator(0o77777)) self._val_box.returnPressed.connect(self._update_cmp_switches) font = QFont('Monospace') font.setStyleHint(QFont.TypeWriter) font.setPointSize(10) self._val_box.setFont(font) self._val_box.setAlignment(Qt.AlignCenter) # Add some spacing to account for lack of parity indicators layout.addSpacing(40)
def _setup_ui(self): # Set up our basic layout layout = QHBoxLayout(self) self.setLayout(layout) layout.setSpacing(3) layout.setMargin(1) # Construct register groups for BR, ST, and SQ self._br_cmp_box, self._br_ign_box = self._create_reg( layout, 2, self._br_cmp_switches, self._br_ign_switches) self._st_cmp_box, self._st_ign_box = self._create_reg( layout, 3, self._st_cmp_switches, self._st_ign_switches) self._sq_cmp_box, self._sq_ign_box = self._create_reg( layout, 7, self._sq_cmp_switches, self._sq_ign_switches) self._create_status_lights(layout) # Create a value box for displaying the overall decoded instruction inst_widget = QWidget(self) layout.addWidget(inst_widget) inst_widget.setMinimumWidth(100) inst_layout = QHBoxLayout(inst_widget) inst_layout.setSpacing(3) inst_layout.setMargin(1) inst_layout.setContentsMargins(0, 32, 0, 0) self._inst_value = QLineEdit(inst_widget) self._inst_value.setReadOnly(True) self._inst_value.setMaximumSize(65, 32) self._inst_value.setText('TC0') font = QFont('Monospace') font.setStyleHint(QFont.TypeWriter) font.setPointSize(10) self._inst_value.setFont(font) self._inst_value.setAlignment(Qt.AlignCenter) inst_layout.addWidget(self._inst_value) inst_layout.setAlignment(Qt.AlignLeft) # Add some spacing to account for lack of parity indicators layout.addSpacing(23)
def __init__(self): ptrs.append(self) self.windowMain = wrapInstance(long(OpenMayaUI_v1.MQtUtil.mainWindow()), QMainWindow) super(ToolSeq_Formula, self).__init__(self.windowMain) self.window = ToolSeq_Formula.qUiLoader.load(ToolSeq_Formula.userScriptDir + 'ToolSeq_Formula.ui', self) self.window.destroyed.connect(lambda: ptrs_remove(self)) self.window.setWindowFlags(self.window.windowFlags() & ~Qt.WindowMinMaxButtonsHint) self.window.setAttribute(Qt.WA_DeleteOnClose) for qComboBox in self.window.findChildren(QComboBox): qComboBox.setItemDelegate(QStyledItemDelegate(qComboBox)) with open(ToolSeq_Formula.userScriptDir + 'ToolSeq.qss', 'r') as fileStyleSheet: self.window.setStyleSheet(fileStyleSheet.read()) font = QFont('Consolas', 9) font.setStyleHint(QFont.Monospace) self.window.Text_PreFormula.setFont(font) self.window.Text_Formula.setFont(font) fontTab = QFontMetricsF(font).horizontalAdvance(' ') * 4 self.window.Text_PreFormula.setTabStopDistance(fontTab) self.window.Text_Formula.setTabStopDistance(fontTab) self.window.Text_PreFormula.setPlainText(ToolSeq_Formula.preFormulas[11]) self.window.Text_Formula.setPlainText(ToolSeq_Formula.formulas[11]) self.window.Widget_Shape.installEventFilter(self) self.window.Check_VariableN.toggled.connect(self.Event_VariableN) self.window.Button_Fill.installEventFilter(self) self.window.Button_Formulate.installEventFilter(self) self.window.show() wMax = max(self.window.Label_1.width(), self.window.Label_2.width()) self.window.Label_1.setFixedWidth(wMax) self.window.Label_2.setFixedWidth(wMax) maya_cmds.loadPlugin('ToolSeq_Formula.py', quiet=True)
def _create_reg(self, width, cmp_switches, ign_switches): # Create a widget to hold the register's bits reg_widget = QWidget(self) reg_layout = QVBoxLayout(reg_widget) reg_widget.setLayout(reg_layout) reg_layout.setSpacing(0) reg_layout.setMargin(0) # Create a widget to hold the register's value and ignore textboxes values = QWidget(reg_widget) v_layout = QHBoxLayout(values) values.setLayout(v_layout) v_layout.setSpacing(1) v_layout.setMargin(0) reg_layout.addWidget(values) reg_layout.setAlignment(values, Qt.AlignRight) # Create textboxes to show the register's value and ignore mask in octal n_digits = int((width + 2) / 3) if n_digits == 1: value_width = 25 elif n_digits == 2: value_width = 30 else: value_width = 45 reg_value = QLineEdit(values) reg_value.setMaximumSize(value_width, 32) reg_value.setText(n_digits * '0') reg_value.setAlignment(Qt.AlignCenter) reg_value.setValidator(RegValidator(2**width - 1)) reg_value.setMaxLength(n_digits) reg_value.returnPressed.connect( lambda b=reg_value, s=cmp_switches: self._update_switches(b, s)) v_layout.addWidget(reg_value) ign_value = QLineEdit(values) ign_value.setMaximumSize(value_width, 32) ign_value.setText(n_digits * '0') ign_value.setAlignment(Qt.AlignCenter) ign_value.setValidator(RegValidator(2**width - 1)) ign_value.setMaxLength(n_digits) ign_value.returnPressed.connect( lambda b=ign_value, s=ign_switches: self._update_switches(b, s)) v_layout.addWidget(ign_value) font = QFont('Monospace') font.setStyleHint(QFont.TypeWriter) font.setPointSize(10) reg_value.setFont(font) ign_value.setFont(font) # Create a frame to hold the register's bits bit_frame = QFrame(reg_widget) bit_layout = QGridLayout(bit_frame) bit_layout.setSpacing(1) bit_layout.setMargin(0) bit_frame.setLayout(bit_layout) bit_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) # Add indicators for each bit in the register, from MSB to LSB col = 0 for i in range(width, 0, -1): check = QCheckBox(bit_frame) check.setFixedSize(20, 20) check.setStyleSheet( 'QCheckBox::indicator{subcontrol-position:center;}') check.stateChanged.connect( lambda state, b=reg_value, s=cmp_switches: self. _update_reg_box(state, b, s)) bit_layout.addWidget(check, 0, col) bit_layout.setAlignment(check, Qt.AlignCenter) cmp_switches.append(check) check = QCheckBox(bit_frame) check.setFixedSize(20, 20) check.setStyleSheet( 'QCheckBox::indicator{subcontrol-position:center;}') check.stateChanged.connect( lambda state, b=ign_value, s=ign_switches: self. _update_reg_box(state, b, s)) bit_layout.addWidget(check, 1, col) bit_layout.setAlignment(check, Qt.AlignCenter) ign_switches.append(check) col += 1 # Add separators between each group of 3 bits if (i > 1) and ((i % 3) == 1): sep = QFrame(bit_frame) sep.setFrameStyle(QFrame.VLine | QFrame.Raised) bit_layout.addWidget(sep, 0, col, 2, 1) col += 1 reg_layout.addWidget(bit_frame) return reg_widget, reg_value, ign_value
class QtPythonEditor(QPlainTextEdit): HIGHLIGHT_COLOR = Qt.lightGray HIGHLIGHTER_CLASS = QtPythonHighlighter DEFAULT_FONT_FAMILY = "Courier" DEFAULT_FONT_SIZE = 10 DEFAULT_LINE_WRAP_MODE = QPlainTextEdit.NoWrap TAB_STOP = 4 _font = None _font_size = DEFAULT_FONT_SIZE def __init__(self, parent=None): QPlainTextEdit.__init__(self, parent) self._highlighter = self.HIGHLIGHTER_CLASS(self.document()) self._line_number_widget = QtLineNumberArea(self) self.setLineWrapMode(self.DEFAULT_LINE_WRAP_MODE) self._initTextAttrs() self._initEvents() def _initEvents(self): self.blockCountChanged.connect(self.updateLineNumberAreaWidth) self.updateRequest.connect(self.updateLineNumberArea) #self.cursorPositionChanged.connect(self.highlightCurrentLine) self.updateLineNumberAreaWidth() def _initTextAttrs(self): self.font = QFont() self.font.setFamily(self.DEFAULT_FONT_FAMILY) self.font.setStyleHint(QFont.Monospace) self.font.setFixedPitch(True) self.font.setPointSize(self._font_size) self.setFont(self.font) self.setTabStopWidth(self.TAB_STOP * QFontMetrics(self.font).width(" ")) def resizeEvent(self, event): super(QtPythonEditor, self).resizeEvent(event) cr = self.contentsRect() self._line_number_widget.setGeometry( QRect(cr.left(), cr.top(), self.lineNumberAreaWidth(), cr.height())) def eventFilter(self, obj, event): """ Implemented here to enable standard text editor ctrl+scroll_wheel text zooming """ if event.type() == QEvent.Wheel: if event.modifiers() == Qt.ControlModifier: if event.delta() > 0: self._font_size = max(self._font_size - 2, self.DEFAULT_FONT_SIZE) #self.zoomIn(2) else: self._font_size = max(self._font_size + 2, self.DEFAULT_FONT_SIZE) #self.zoomOut(2) self.font.setPointSize(self._font_size) self.setFont(self.font) self.setTabStopWidth(self.TAB_STOP * QFontMetrics(self.font).width(" ")) return True return False def lineNumberAreaWidth(self): digits = 1 count = max(1, self.blockCount()) while count >= 10: count /= 10 digits += 1 space = 3 + self.fontMetrics().width("9") * digits return space def updateLineNumberArea(self, rect, dy): if dy: self._line_number_widget.scroll(0, dy) else: self._line_number_widget.update(0, rect.y(), self._line_number_widget.width(), rect.height()) if rect.contains(self.viewport().rect()): self.updateLineNumberAreaWidth() def updateLineNumberAreaWidth(self): self.setViewportMargins(self.lineNumberAreaWidth(), 0, 0, 0) def highlightCurrentLine(self): extraSelections = [] if not self.isReadOnly(): selection = QTextEdit.ExtraSelection() lineColor = QColor(self.HIGHLIGHT_COLOR).lighter(160) selection.format.setBackground(lineColor) selection.format.setProperty(QTextFormat.FullWidthSelection, True) selection.cursor = self.textCursor() selection.cursor.clearSelection() extraSelections.append(selection) self.setExtraSelections(extraSelections) def lineNumberAreaPaintEvent(self, event): mypainter = QPainter(self._line_number_widget) mypainter.fillRect(event.rect(), Qt.lightGray) block = self.firstVisibleBlock() blockNumber = block.blockNumber() top = self.blockBoundingGeometry(block).translated( self.contentOffset()).top() bottom = top + self.blockBoundingRect(block).height() # Just to make sure I use the right font height = self.fontMetrics().height() while block.isValid() and (top <= event.rect().bottom()): if block.isVisible() and (bottom >= event.rect().top()): number = str(blockNumber + 1) mypainter.setPen(Qt.black) mypainter.drawText(0, top, self._line_number_widget.width(), height, Qt.AlignRight, number) block = block.next() top = bottom bottom = top + self.blockBoundingRect(block).height() blockNumber += 1 def getHighlighter(self): return self._highlighter def setFontSize(self, size): font = self.font() font.setPointSize(size) self.setFont(font)
def _setup_ui(self, color): # Set up our basic layout layout = QHBoxLayout(self) self.setLayout(layout) layout.setSpacing(3) layout.setMargin(1) # Construct register groups for BR, ST, and SQ br_frame, self._br_value = self._create_reg(self._br_inds, 'BR', 2, color) st_frame, self._st_value = self._create_reg(self._st_inds, 'ST', 3, color) sq_frame, self._sq_value = self._create_reg(self._sq_inds, 'SQ', 7, color) layout.addWidget(br_frame) layout.addWidget(st_frame) layout.addWidget(sq_frame) stat_group = QWidget(self) layout.addWidget(stat_group) stat_layout = QGridLayout(stat_group) stat_layout.setMargin(0) stat_layout.setSpacing(0) col = 0 for name, label in STATUS_INDS.items(): self._status_inds[name] = self._create_status_light( label, stat_group, stat_layout, col) col += 1 # Create a grouping widget for the I label and decoded instruction value box label_value = QWidget(self) lv_layout = QHBoxLayout(label_value) lv_layout.setSpacing(3) lv_layout.setMargin(1) lv_layout.setContentsMargins(0, 32, 0, 0) label_value.setLayout(lv_layout) layout.addWidget(label_value) # Create a value box for displaying the overall decoded instruction self._inst_value = QLineEdit(label_value) self._inst_value.setReadOnly(True) self._inst_value.setMaximumSize(65, 32) self._inst_value.setText('TC0') font = QFont('Monospace') font.setStyleHint(QFont.TypeWriter) font.setPointSize(10) self._inst_value.setFont(font) self._inst_value.setAlignment(Qt.AlignCenter) lv_layout.addWidget(self._inst_value) # Create a label to show 'I' label = QLabel('I', label_value) font = label.font() font.setPointSize(14) font.setBold(True) label.setFont(font) lv_layout.addWidget(label) # Add some spacing to account for lack of parity indicators layout.addSpacing(52)
class SequenceRecordsWindow(QWidget): def __init__(self, parent): super(SequenceRecordsWindow, self).__init__(parent) self.grid_layout = QGridLayout() self.grid_layout.setContentsMargins(0, 0, 0, 0) self.grid_layout.setSpacing(0) self.setLayout(self.grid_layout) self.seq_font = QFont() self.seq_font.setFamily("Noto Sans Mono") self.seq_font.setPointSize(12) self.seq_font.setFixedPitch(True) self.seq_font.setStyleHint(QFont.Monospace) self.seq_h_scroll_bar = QScrollBar(self, self.parent()) self.seq_h_scroll_bar.setOrientation(Qt.Horizontal) self.seq_h_scroll_bar.setMinimum(0) self.seq_h_scroll_bar.setMaximum(self.longest_seq_len - self.char_nb) self.seq_h_scroll_bar.valueChanged.connect(self.move_seqs) self.grid_layout.addWidget(self.seq_h_scroll_bar, self.grid_layout.rowCount(), 5) self.lower_spacer_item = QSpacerItem(1, 1, QSizePolicy.Minimum, QSizePolicy.MinimumExpanding) self.grid_layout.addItem(self.lower_spacer_item) self.seq_record_items = [] def sizeHint(self): # Workaroud QTBUG-70305 return self.parent().parent().size() def populate(self, seq_records): self.grid_layout.removeWidget(self.seq_h_scroll_bar) self.grid_layout.removeItem(self.lower_spacer_item) for seq_record in seq_records: new_row = self.grid_layout.rowCount() self.seq_record_items.append( SequenceRecordItem(self, seq_record, self.seq_font)) for widget_index in range(0, len(self.seq_record_items[-1].widgets)): col = widget_index self.seq_record_items[-1].seqLabel.installEventFilter(self) self.grid_layout.addWidget( self.seq_record_items[-1].widgets[widget_index], new_row, col) if len(seq_record) > self.longest_seq_len: self.longest_seq_len = len(seq_record) self.update_char_nb() self.grid_layout.addWidget(self.seq_h_scroll_bar, self.grid_layout.rowCount(), 5) self.grid_layout.addItem(self.lower_spacer_item) self.display_all_seq() def clear(self): # TODO pass def eventFilter(self, watched, event): if event.type() == QEvent.Resize: self.update_char_nb() self.update_scrollbar() self.display_all_seq() return super(SequenceRecordsWindow, self).eventFilter(watched, event) def display_all_seq(self): for seq_record_item in self.seq_record_items: seq_record_item.seqLabel.display_seq( seq_record_item.seq_record.seq, self.display_begin, self.char_nb) def update_char_nb(self): font_metrics = QFontMetrics(self.seq_font) px_wide_char = font_metrics.width("A") label_width = self.seq_record_items[0].seqLabel.width( ) # width of first seq label = all seq labels approx_char_nb = label_width // px_wide_char test_str = "A" * approx_char_nb while font_metrics.width( test_str) < label_width: # fontMetrics not precise at all... test_str += "A" while font_metrics.width( test_str) >= label_width: # fontMetrics not precise at all... test_str = test_str[:-1] self.char_nb = len(test_str) def update_scrollbar(self): self.seq_h_scroll_bar.setMaximum(self.longest_seq_len - self.char_nb + 12) def move_seqs(self, value): print(value) self.display_begin = value self.display_all_seq() char_nb = 0 longest_seq_len = 0 display_begin = 0
def __init__(self, parent=None, graph=None): super(MainWindow, self).__init__(parent) plugin_settings = PluginSettings() self.plugin_settings = plugin_settings self.graph = graph self.ui = sexeditor.Ui_MainWindow() self.ui.setupUi(self) self.ui.code_editor.setup_editor(plugin_settings["editor_font_size"]) self.ui.render_view.setup_editor(plugin_settings["editor_font_size"]) self.ui.code_editor.tab_spaces = plugin_settings["tab_spaces"] button_font = self.ui.compile.font() button_font.setPointSize(plugin_settings["button_font_size"]) self.ui.compile.setFont(button_font) tab_font = self.ui.tabs.font() tab_font.setPointSize(plugin_settings["tab_font_size"]) self.ui.tabs.setFont(tab_font) # tab_font = self.ui.render_tab.font() # tab_font.setPointSize(plugin_settings["tab_font_size"]) # self.ui.render_tab.setFont(tab_font) self.ui.compile.clicked.connect(self.create_nodes) self.ui.tabs.currentChanged.connect(self.tab_change) self.ui.code_editor.init_code_completion(parser.keywords + self.get_package_inputs()) self.frame_object: sd.api.SDGraphObjectFrame = None self.highlighter = sexsyntax.SexHighlighter(self.ui.code_editor.document()) self.view_highlighter = sexsyntax.SexHighlighter(self.ui.render_view.document()) font = QFont("Courier New") font.setStyleHint(QFont.Monospace) font.setPointSize(plugin_settings["console_font_size"]) self.ui.console_output.setFont(font) self.ui.console_output.setReadOnly(True) font = QFont("Courier New") font.setStyleHint(QFont.Monospace) font.setPointSize(plugin_settings["editor_font_size"]) QApplication.setFont(font, "CodeEditor") width = plugin_settings["window_size"][0] height = plugin_settings["window_size"][1] pos_x = plugin_settings["window_pos"][0] pos_y = plugin_settings["window_pos"][1] #self.setGeometry(pos_x, pos_y, width, height) self.move(pos_x, pos_y) self.resize(width, height) builtin_functions = ([*sexparser.function_node_map] + [*sexparser.vectors_map] + [*parser.imported_functions] + [*sexparser.samplers_map] + ["range"]) builtin_types = [*sexparser.constants_map] + [*sexparser.get_variable_map] + [*sexparser.casts_map] self.highlighter.setup_rules(builtin_functions, builtin_types) self.view_highlighter.setup_rules(builtin_functions, builtin_types) self.setWindowTitle("Expression Editor")
def main(gamePath: Optional[str] = None, configPath: Optional[str] = None, startupMode: StartupMode = StartupMode.Main) -> NoReturn: from w3modmanager.util.util import getRuntimePath from w3modmanager.core.model import Model from w3modmanager.core.errors import OtherInstanceError, InvalidGamePath, InvalidConfigPath from w3modmanager.ui.graphical.mainwindow import MainWindow from w3modmanager.domain.system.permissions import \ getWritePermissions, setWritePermissions from PySide2.QtCore import Qt, QSettings from PySide2.QtWidgets import QApplication, QMessageBox from PySide2.QtGui import QIcon, QPalette, QFont from asyncqt import QEventLoop # noqa QApplication.setOrganizationName(w3modmanager.ORG_NAME) QApplication.setOrganizationDomain(w3modmanager.ORG_URL) QApplication.setApplicationName(w3modmanager.TITLE) QApplication.setApplicationVersion(w3modmanager.VERSION) QApplication.setApplicationDisplayName('') QApplication.setAttribute(Qt.AA_NativeWindows) QApplication.setAttribute(Qt.AA_DisableWindowContextHelpButton) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QApplication.setHighDpiScaleFactorRoundingPolicy( Qt.HighDpiScaleFactorRoundingPolicy.RoundPreferFloor) app = QApplication(sys.argv) app.setStyleSheet(''' Link { text-decoration: none; } ''') eventloop = QEventLoop(app) asyncio.set_event_loop(eventloop) palette = QPalette(QApplication.palette()) palette.setColor(QPalette.Link, Qt.red) palette.setColor(QPalette.LinkVisited, Qt.red) app.setPalette(palette) font = QFont('Segoe UI') font.setStyleHint(QFont.System) font.setWeight(QFont.Normal) font.setStyleStrategy(QFont.PreferDevice) font.setPointSize(9) app.setFont(font) icon = QIcon() icon.addFile(str(getRuntimePath('resources/icons/w3b.ico'))) app.setWindowIcon(icon) # configure startup overrides settings = QSettings() if gamePath: settings.setValue('gamePath', gamePath) if configPath: settings.setValue('configPath', configPath) if startupMode == StartupMode.About: MainWindow.showAboutDialog(None).exec_() sys.exit() if startupMode == StartupMode.Settings: MainWindow.showSettingsDialog(None).exec_() sys.exit() def createModel(ignorelock: bool = False) -> Model: nonlocal settings return Model( Path(str(settings.value('gamePath'))), Path(str(settings.value('configPath'))), Path( appdirs.user_data_dir(w3modmanager.NAME, w3modmanager.ORG_NAME)), ignorelock) try: # try to initialize the mod management model try: model = createModel() # if another instance is already open, inform and ask to open anyway except OtherInstanceError as e: if MainWindow.showOtherInstanceDialog( None).exec_() == QMessageBox.Yes: model = createModel(True) else: raise e # if game path or config path is invalid or not set, # show a special settings dialog and retry except (InvalidGamePath, InvalidConfigPath): MainWindow.showSettingsDialog(None, True).exec_() model = createModel() # check for write access to the game and config directories for path in ( model.gamepath, model.configpath, model.cachepath, ): if not getWritePermissions(path): if MainWindow.showInvalidPermissionsDialog(None, path).exec_() != QMessageBox.Yes \ or not setWritePermissions(path): raise PermissionError(f'Not enough permissions for {path}') window = MainWindow(model) app.setActiveWindow(window) def show_exception_hook(exctype, value, tb) -> None: # noqa nonlocal window MainWindow.showCritcalErrorDialog( window, value, ''.join(traceback.format_exception(exctype, value, tb))).exec_() exception_hook(exctype, value, tb) sys.excepthook = show_exception_hook with eventloop: sys.exit(eventloop.run_forever()) except OtherInstanceError as e: sys.exit(f'error: {str(e)}') except (InvalidGamePath, InvalidConfigPath) as e: MainWindow.showInvalidConfigErrorDialog(None).exec_() sys.exit(f'error: {str(e)}') except PermissionError as e: MainWindow.showInvalidPermissionsErrorDialog(None).exec_() sys.exit(f'error: {str(e)}') except Exception as e: MainWindow.showCritcalErrorDialog(None, str(e)).exec_() raise e sys.exit()
def _add_process(self): process_groupbox = QGroupBox("Process") process_groupbox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) process_layout = QVBoxLayout() process_layout.setSpacing(0) process_groupbox.setLayout(process_layout) pbar_frame = QFrame() pbar_frame.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) pbar_hbox = QHBoxLayout() pbar_hbox.setContentsMargins(QtCore.QMargins(0, 0, 0, 16)) pbar_hbox.setSpacing(16) # Run and stop buttons hbox = QHBoxLayout() hbox.setSpacing(8) self.run_button = QPushButton() # is only enabled when validation passes self.run_button.setEnabled(False) self.run_button.setText("Run") self.run_button.setFixedWidth(100) run_icon = qta.icon('fa.play', color='green') self.run_button.setIcon(run_icon) self.run_button.clicked.connect(self._click_run) hbox.addWidget(self.run_button) self.stop_button = QPushButton() self.stop_button.setEnabled(False) self.stop_button.setText("Stop") self.stop_button.setFixedWidth(100) stop_icon = qta.icon('fa.stop', color='red') self.stop_button.setIcon(stop_icon) self.stop_button.clicked.connect(self._click_stop) hbox.addWidget(self.stop_button) self.progress_bar = QProgressBar() self.progress_bar.setTextVisible(True) self.progress_bar.setAlignment(QtCore.Qt.AlignCenter) self.progress_bar.setValue(0) self.progress_bar.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) pbar_hbox.addLayout(hbox) pbar_hbox.addWidget(self.progress_bar) pbar_frame.setLayout(pbar_hbox) process_layout.addWidget(pbar_frame) self.warning_frame = QFrame() self.warning_frame.setVisible(False) self.warning_frame.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) hbox = QHBoxLayout() warning_icon_widget = qta.IconWidget('fa.warning', color='red') warning_icon_widget.setIconSize(QtCore.QSize(48, 48)) warning_icon_widget.update() hbox.addWidget(warning_icon_widget) warning_label = QLabel( "Grid Transformer did not complete successfully. Please refer to " "log output.") warning_label.setStyleSheet("QLabel { color: red; }") warning_label.setWordWrap(True) warning_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) hbox.addWidget(warning_label) self.warning_frame.setLayout(hbox) process_layout.addWidget(self.warning_frame) self.success_frame = QFrame() self.success_frame.setVisible(False) self.success_frame.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) hbox = QHBoxLayout() success_icon_widget = qta.IconWidget('fa.check', color='green') success_icon_widget.setIconSize(QtCore.QSize(48, 48)) success_icon_widget.update() hbox.addWidget(success_icon_widget) success_label = QLabel("Grid Transformer completed successfully.") success_label.setStyleSheet("QLabel { color: green; }") success_label.setWordWrap(True) success_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) hbox.addWidget(success_label) self.success_frame.setLayout(hbox) process_layout.addWidget(self.success_frame) log_layout = QVBoxLayout() log_layout.setSpacing(4) log_label = QLabel("Log messages") log_label.setStyleSheet("QLabel { color: grey; }") log_layout.addWidget(log_label) self.log_messages = QPlainTextEdit() log_font = QFont("monospace") log_font.setStyleHint(QFont.TypeWriter) self.log_messages.setFont(log_font) self.log_messages.setReadOnly(True) self.log_messages.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # self.log_messages.sizePolicy.setVerticalStretch(1) log_layout.addWidget(self.log_messages) process_layout.addLayout(log_layout) self.layout.addWidget(process_groupbox)
def _setup_ui(self, name, color): # Set up the overall horizontal layout layout = QHBoxLayout(self) self.setLayout(layout) layout.setSpacing(3) layout.setMargin(1) # Construct a frame to hold the 16 indicators bit_frame = QFrame(self) bit_layout = QHBoxLayout(bit_frame) bit_layout.setSpacing(1) bit_layout.setMargin(0) bit_frame.setLayout(bit_layout) bit_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) layout.addWidget(bit_frame) # Add the 16 bit indicators to the frame, from 16 to 1. for i in range(16, 0, -1): ind = Indicator(bit_frame, color) ind.setFixedSize(20, 32) bit_layout.addWidget(ind) self._indicators.insert(0, ind) # Add separators between every group of 3 bits (except between # bits 15 and 16). if (i < 16) and (i > 1) and ((i % 3) == 1): sep = QFrame(bit_frame) sep.setFrameStyle(QFrame.VLine | QFrame.Raised) bit_layout.addWidget(sep) # Add sensed and generated parity bits, if this register has them if self._has_parity: sep = QFrame(bit_frame) sep.setFrameStyle(QFrame.VLine | QFrame.Raised) bit_layout.addWidget(sep) for i in range(2, 0, -1): ind = Indicator(bit_frame, QColor(220, 240, 0)) ind.setFixedSize(20, 32) bit_layout.addWidget(ind) self._parity_inds.insert(0, ind) # Add a box to display the octal decoded value in self._value_box = QLineEdit() self._value_box.setMaximumSize(52, 32) self._value_box.setReadOnly(True) self._value_box.setAlignment(Qt.AlignCenter) self._value_box.setText('00000') font = QFont('Monospace') font.setStyleHint(QFont.TypeWriter) font.setPointSize(10) self._value_box.setFont(font) layout.addWidget(self._value_box) # Add a label showing the name of the register label = QLabel(name, self) font = label.font() font.setPointSize(14) font.setBold(True) label.setFont(font) label.setMinimumWidth(20) layout.addWidget(label) # If parity was not included, fill up the equivalent space if not self._has_parity: layout.addSpacing(62) else: layout.addSpacing(17)
def __init__(self, parent, task): ''' Params: ------- parent: FrmMainWindow task : MirrorTask ''' super(DlgPending, self).__init__(parent) # init UI self.ui = Ui_dlgPendng() self.ui.setupUi(self) # removes the help button self.setWindowFlags(Qt.Dialog | Qt.WindowTitleHint | Qt.WindowCloseButtonHint) # connect slots self.ui.btnOK.clicked.connect(lambda: self.Btn_Clicked(self.ui.btnOK)) self.ui.btnCancel.clicked.connect( lambda: self.Btn_Clicked(self.ui.btnCancel)) # get task params cmd, src, dst = task.GetParams() # append '/l' switch cmd.append('/l') # prepare subprocess proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) # get output of result stdout = proc.communicate()[0].decode('utf-8') str_msg = stdout # make font so each character's width is same font = QFont() font.setFamily("Courier") font.setStyleHint(QFont.Monospace) font.setFixedPitch(True) font.setPointSize(10) self.ui.textEdit.setCurrentFont(font) self.ui.textEdit.setText(str_msg) # parse the pending result # ex: dirs[1,5,0] means 1 out of 5 info = {'dirs': [], 'files': [], 'bytes': []} try: # split each line for line in stdout.split('\r\n'): # if current line is for directory if 'Dirs :' in line: tmp = [ a for a in line.split(':')[1].split(' ') if len(a) > 0 ] # noqa if len(tmp) == 6: info['dirs'] = tmp # if current line is for files elif 'Files :' in line: tmp = [ a for a in line.split(':')[1].split(' ') if len(a) > 0 ] # noqa if len(tmp) == 6: info['files'] = tmp # if current line is for bytes elif 'Bytes :' in line: tmp = [ a for a in line.split(':')[1].split(' ') if len(a) > 0 ] # noqa if len(tmp) == 6: info['bytes'] = tmp # check out pending result is valid if len(info['dirs']) == 0: self.ui.btnOK.setEnabled(False) return # sets the anaylsis numbers # dir copy self.ui.lbl_copyFolder.setText( f"{info['dirs'][1]} out of {info['dirs'][0]}") # dir del self.ui.lbl_delFolders.setText(f"{info['dirs'][5]}") # file copy self.ui.lbl_copyFile.setText( f"{info['files'][1]} out of {info['files'][0]}") # dir del self.ui.lbl_delFile.setText(f"{info['files'][5]}") # bytes copy self.ui.lbl_copyBytes.setText( f"{info['bytes'][1]}bytes out of {info['bytes'][0]}bytes") # bytes del self.ui.lbl_delBytes.setText(f"{info['bytes'][5]}bytes") except Exception as e: print(f'Pending dlg err:{e}')
'ax', 'cx', 'dx', 'bx', 'sp', 'bp', 'si', 'di', 'ah', 'al', 'ch', 'cl', 'dh', 'dl', 'bh', 'bl', 'ss', 'cs', 'ds', 'es' ] } arch_to_reserved['thumb2'] = arch_to_reserved['armv7'] arch_to_reserved['thumb2eb'] = arch_to_reserved['thumb2'] arch_to_reserved['armv7eb'] = arch_to_reserved['armv7'] arch_to_reserved['mipsel32'] = arch_to_reserved['mips32'] arch_to_reserved['ppc64_le'] = arch_to_reserved['ppc64'] arch_to_reserved['x86'] = arch_to_reserved['x86_16'] + \ ['eax', 'ecx', 'edx', 'ebx', 'esp', 'ebp', 'esi', 'edi', 'fs', 'gs'] arch_to_reserved['x86_64'] = arch_to_reserved['x86'] + \ ['rax', 'rcx', 'rdx', 'rbx', 'rsp', 'rbp', 'rsi', 'rdi'] font_mono = QFont('Courier New') font_mono.setStyleHint(QFont.TypeWriter) #------------------------------------------------------------------------------ # utilities #------------------------------------------------------------------------------ # test if given address is valid binaryview address, by searching sections def is_valid_addr(bview, addr): for sname in bview.sections: section = bview.sections[sname] start = section.start end = section.start + len(section) if addr >= start and addr < end: return True return False
def _create_reg(self, ind_list, name, width, color): # Create a widget to hold the register's bits reg_widget = QWidget(self) reg_layout = QVBoxLayout(reg_widget) reg_widget.setLayout(reg_layout) reg_layout.setSpacing(0) reg_layout.setMargin(0) # Create a widget to hold the register's label and value textbox label_value = QWidget(reg_widget) lv_layout = QHBoxLayout(label_value) label_value.setLayout(lv_layout) lv_layout.setSpacing(1) lv_layout.setMargin(0) reg_layout.addWidget(label_value) # Create a label to show the register's name reg_label = QLabel(name, label_value) reg_label.setAlignment(Qt.AlignCenter) font = reg_label.font() font.setPointSize(8) reg_label.setFont(font) lv_layout.addWidget(reg_label) # Create a textbox to show the register's value in octal n_digits = int((width + 2) / 3) if n_digits == 1: value_width = 25 elif n_digits == 2: value_width = 30 else: value_width = 45 reg_value = QLineEdit(label_value) reg_value.setReadOnly(True) reg_value.setMaximumSize(value_width, 32) reg_value.setText(n_digits * '0') font = QFont('Monospace') font.setStyleHint(QFont.TypeWriter) font.setPointSize(10) reg_value.setFont(font) reg_value.setAlignment(Qt.AlignCenter) lv_layout.addWidget(reg_value) # Create a frame to hold the register's bits bit_frame = QFrame(reg_widget) bit_layout = QHBoxLayout(bit_frame) bit_layout.setSpacing(1) bit_layout.setMargin(0) bit_frame.setLayout(bit_layout) bit_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) # Add indicators for each bit in the register, from MSB to LSB for i in range(width, 0, -1): ind = Indicator(bit_frame, color) ind.setFixedSize(20, 32) bit_layout.addWidget(ind) ind_list.insert(0, ind) # Add separators between each group of 3 bits if (i > 1) and ((i % 3) == 1): sep = QFrame(bit_frame) sep.setFrameStyle(QFrame.VLine | QFrame.Raised) bit_layout.addWidget(sep) reg_layout.addWidget(bit_frame) return reg_widget, reg_value
def initialize(self, num_dimensions: int, target_function: Callable[[np.ndarray], float], upper_bound: np.ndarray, lower_bound: np.ndarray, maximum_value: float, minimum_value: float, labels: Sequence[str] = [], show_values: bool = False, resolution: int = 200, visualization_minimum_width: int = 200, visualization_minimum_height: int = 32) -> None: assert num_dimensions == upper_bound.shape[0] assert num_dimensions == lower_bound.shape[0] assert maximum_value > minimum_value assert len(labels) == 0 or len(labels) == num_dimensions has_labels = len(labels) != 0 # Initialize the widget layout grid_layout = QGridLayout() self.setLayout(grid_layout) # Instantiate widgets for dimension in range(num_dimensions): # Instantiate a slider and set a callback slider = QSlider(Qt.Horizontal, self) slider.valueChanged.connect(self.__sliders_manipulated_via_gui) self.__sliders.append(slider) grid_layout.addWidget(slider, dimension * 2, 1) # Instantiate a visualization widget visualization_widget = _VisualizationWidget( dimension, self, visualization_minimum_width, visualization_minimum_height) self.__visualization_widgets.append(visualization_widget) grid_layout.addWidget(visualization_widget, dimension * 2 + 1, 1) # Instantiate a parameter label widget (if requested) if has_labels: grid_layout.addWidget(QLabel(labels[dimension]), dimension * 2, 0) # Instantiate a value label widget (if requested) if show_values: font = QFont() font.setStyleHint(QFont.Monospace) line_edit = QLineEdit() line_edit.setReadOnly(True) line_edit.setFixedWidth(46) line_edit.setMaxLength(5) line_edit.setFont(font) self.__value_labels.append(line_edit) grid_layout.addWidget(line_edit, dimension * 2, 2) # Change the slider's resolution (this needs to be done after adding all the widgets) slider.setMaximum(slider.width()) self.num_dimensions = num_dimensions self.target_function = target_function self.upper_bound = upper_bound self.lower_bound = lower_bound self.maximum_value = maximum_value self.minimum_value = minimum_value self.resolution = resolution self.callback = None self.set_argument_and_update_sliders(0.5 * (upper_bound + lower_bound))
print("erro ao enviar m_SG") def __init__(self): super().__init__() self.timer = QTimer(self) self.timer.timeout.connect(self.onTimer) self.initUI() self.connected = False def on_btnConnect_clicked(self): if (self.connected): self.timer.stop() self.btnConnect.setText("Conectar") self.connected = False return host = self.hostTxt.text() port = self.portTxt.text() global url url = 'http://' + str(host) + ':' + str(port) + '/' if not self.timer.isActive(): self.timer.start(timerInterval) # 500 milissegundos if __name__ == "__main__": app = QApplication(sys.argv) font = QFont("Arial", 10, 0) font.setStyleHint(QFont.Monospace) app.setFont(font) win = MainWindow() win.show() app.exec_()
def _setup_ui(self, num): # Set up our basic layout layout = QHBoxLayout(self) self.setLayout(layout) layout.setSpacing(3) layout.setMargin(1) # Construct register groups for EB, FEXT, FB, and S self._eb_cmp_switches = [] self._eb_ign_switches = [] self._fext_cmp_switches = [] self._fext_ign_switches = [] self._fb_cmp_switches = [] self._fb_ign_switches = [] self._s_cmp_switches = [] self._s_ign_switches = [] self._updating_switches = False self._eb = 0 self._eb_ign = 0 self._fext = 0 self._fext_ign = 0 self._fb = 0 self._fb_ign = 0 self._s = 0 self._s_ign = 0 eb, self._eb_cmp_box, self._eb_ign_box = self._create_reg( 3, self._eb_cmp_switches, self._eb_ign_switches) fext, self._fext_cmp_box, self._fext_ign_box = self._create_reg( 3, self._fext_cmp_switches, self._fext_ign_switches) fb, self._fb_cmp_box, self._fb_ign_box = self._create_reg( 5, self._fb_cmp_switches, self._fb_ign_switches) s, self._s_cmp_box, self._s_ign_box = self._create_reg( 12, self._s_cmp_switches, self._s_ign_switches) layout.addWidget(eb) layout.addWidget(fext) layout.addWidget(fb) layout.addWidget(s) # Create a grouping widget for the Sn label and decoded octal value box label_value = QWidget(self) label_value.setMinimumWidth(100) lv_layout = QHBoxLayout(label_value) lv_layout.setSpacing(3) lv_layout.setMargin(1) lv_layout.setContentsMargins(0, 32, 0, 0) label_value.setLayout(lv_layout) layout.addWidget(label_value) # Create a value box for displaying the overall decoded address self._addr_box = QLineEdit(label_value) self._addr_box.setReadOnly(True) self._addr_box.setMaximumSize(65, 32) self._addr_box.setText('0000') font = QFont('Monospace') font.setStyleHint(QFont.TypeWriter) font.setPointSize(10) self._addr_box.setFont(font) self._addr_box.setAlignment(Qt.AlignCenter) lv_layout.addWidget(self._addr_box) # Create a label to show 'S' label = QLabel('S%u' % num, label_value) font = label.font() font.setPointSize(14) font.setBold(True) label.setFont(font) lv_layout.addWidget(label)