def __init__(self, parent): super(SvgViewer, self).__init__(parent) self.mainwindow = None self.scene = QtWidgets.QGraphicsScene(self) self.renderer = QtSvg.QSvgRenderer() self.setScene(self.scene) # a "state" I would like to avoid, between mouse "down" and mouse "up" self.in_dnd = False # the content of the svf file as string self.svg = None # and the extra tabs contained in the job description self.tabs = [] # dictionnay path id -> path d def for all path definition in the svg self.svg_path_d = {} # when loading a svg with shapes that are not <path> self.svg_shapes = {} # path id -> circle, ellipse, rect, polygon, etc # the graphical items in the view self.items: List[SvgItem] = [] # ordered list of selected items self.selected_items: List[SvgItem] = [] #self.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) self.setViewportUpdateMode(QtWidgets.QGraphicsView.FullViewportUpdate) # keep zoom factor (used when reloading augmented svg: zoom should be kept) self.currentZoom = self.zoomFactor()
def intrinsicSize(self, doc, posInDocument, format): renderer = QtSvg.QSvgRenderer(format.property(Window.SvgData).toByteArray()) size = renderer.defaultSize() if size.height() > 25: size *= 25.0 / size.height() return QtCore.QSizeF(size)
def __init__(self, parent, persepolis_setting): super().__init__(parent) self.persepolis_setting = persepolis_setting # set ui direction ui_direction = self.persepolis_setting.value('ui_direction') if ui_direction == 'rtl': self.setLayoutDirection(Qt.RightToLeft) elif ui_direction in 'ltr': self.setLayoutDirection(Qt.LeftToRight) # set size self.resize(QSize(400, 80)) self.setFixedWidth(400) # show this widget as ToolTip widget self.setWindowFlags(Qt.ToolTip) # find bottom right position bottom_right_screen = QDesktopWidget().availableGeometry().bottomRight( ) bottom_right_notification = QRect(QPoint(0, 0), QSize(410, 120)) bottom_right_notification.moveBottomRight(bottom_right_screen) self.move(bottom_right_notification.topLeft()) # get persepolis icon path icons = ':/' + \ str(self.persepolis_setting.value('settings/icons')) + '/' notification_horizontalLayout = QHBoxLayout(self) # persepolis icon svgWidget = QtSvg.QSvgWidget(':/persepolis.svg') svgWidget.setFixedSize(QSize(64, 64)) notification_horizontalLayout.addWidget(svgWidget) notification_verticalLayout = QVBoxLayout() # 2 labels for notification messages self.label1 = QLabel(self) self.label1.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) self.label1.setStyleSheet("font-weight: bold") self.label1.setWordWrap(True) self.label2 = QLabel(self) self.label2.setWordWrap(True) self.label2.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) notification_verticalLayout.addWidget(self.label1) notification_verticalLayout.addWidget(self.label2) notification_horizontalLayout.addLayout(notification_verticalLayout)
def _render_splashscreen(self, pngpath: str) -> None: # Render SVG to PNG (qt's svg renderer has issues with blurred elements) iconpath = os.path.join(str(vxpy.__path__[0]), 'vxpy_icon.svg') renderer = QtSvg.QSvgRenderer(iconpath) image = QtGui.QImage(512, 512, QtGui.QImage.Format.Format_RGBA64) painter = QtGui.QPainter(image) image.fill(QtGui.QColor(0, 0, 0, 0)) renderer.render(painter) image.save(pngpath) painter.end()
def clearWindow(self): self.current_file = None self.solution = None self.svg_renderer.deleteLater() self.svg_renderer = qtsvg.QSvgRenderer() self.svg_item.setSharedRenderer(self.svg_renderer) while self.input_list.count() > 1: self.input_list.takeAt(0).widget().deleteLater() self.output_show_box.setItem(None) self.output_show_box.setIcon(OUTPUT_ICON)
def __init__(self, args): super().__init__(args) self.game_data = game_parse.get_docs() self.item_lookup = { item.display: item for item in self.game_data.items.values() } self.solution = None self.current_file = None self.windows = [] self.w = qtw.QMainWindow() self.central_widget = qtw.QWidget() self.w.setCentralWidget(self.central_widget) self.w.setWindowTitle("Satisfactory Solver") self.w.resize(900, 600) self.center_layout = qtw.QHBoxLayout() self.central_widget.setLayout(self.center_layout) self.input_layout = qtw.QVBoxLayout() self.center_layout.addLayout(self.input_layout) self.input_search_box = ItemSearchWidget( 'Add Input', self.item_lookup, qtg.QShortcut(qtg.QKeySequence(qtc.Qt.CTRL | qtc.Qt.Key_I), self.w)) self.input_layout.addWidget(self.input_search_box) self.input_scroll = qtw.QScrollArea() self.input_scroll.setWidgetResizable(True) self.input_scroll.setHorizontalScrollBarPolicy( qtc.Qt.ScrollBarAlwaysOff) self.input_layout.addWidget(self.input_scroll) self.input_scroll_holdee = WidthAnchor(self.input_scroll) self.input_scroll.setFocusProxy(self.input_scroll_holdee) self.input_list = qtw.QVBoxLayout(self.input_scroll_holdee) self.input_scroll_holdee.setLayout(self.input_list) self.input_list.insertStretch(-1) self.input_list.setSpacing(0) self.input_scroll.setWidget(self.input_scroll_holdee) self.input_search_box.callback = self.add_input self.output_search = ItemSearchWidget( 'Set Target', self.item_lookup, qtg.QShortcut(qtg.QKeySequence(qtc.Qt.CTRL | qtc.Qt.Key_T), self.w)) self.input_layout.addWidget(self.output_search) self.go_box = qtw.QPushButton("Go!") self.output_show_box = SchematicInputWidget(None, self.go_box, self.open_recipe_window, self.game_data, False) self.output_show_box.setIcon(OUTPUT_ICON) self.input_layout.addWidget(self.output_show_box) self.output_search.callback = self.output_show_box.setItem self.svg_scene = qtw.QGraphicsScene() self.svg_view = ZoomingGraphicsView(self.svg_scene) self.svg_item = qtsvgw.QGraphicsSvgItem() self.svg_renderer = qtsvg.QSvgRenderer() self.svg_item.setSharedRenderer(self.svg_renderer) self.svg_scene.addItem(self.svg_item) self.center_layout.addWidget(self.svg_view, 1) self.go_box.clicked.connect(self.go_fn) self.go_box.setShortcut(qtg.QKeySequence(qtc.Qt.CTRL | qtc.Qt.Key_G)) self.recipe_window = AlternateRecipeWindow(self.game_data) self.set_tab_order() self.setup_menu() if len(args) > 1: self.current_file = args[1] self.open_plan(True)
def drawObject(self, painter, rect, doc, posInDocument, format): renderer = QtSvg.QSvgRenderer(format.property(Window.SvgData).toByteArray()) renderer.render(painter, rect)