当前位置: 首页>>代码示例>>Python>>正文


Python QGraphicsScene.height方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsScene.height方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsScene.height方法的具体用法?Python QGraphicsScene.height怎么用?Python QGraphicsScene.height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QGraphicsScene的用法示例。


在下文中一共展示了QGraphicsScene.height方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: UMLDialog

# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import height [as 别名]

#.........这里部分代码省略.........
        @param filename name of the file to write to (string)
        """
        if not filename:
            fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
                self,
                self.tr("Save Diagram"),
                "",
                self.tr("Eric Graphics File (*.e5g);;All Files (*)"),
                "",
                E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
            if not fname:
                return
            ext = QFileInfo(fname).suffix()
            if not ext:
                ex = selectedFilter.split("(*")[1].split(")")[0]
                if ex:
                    fname += ex
            if QFileInfo(fname).exists():
                res = E5MessageBox.yesNo(
                    self,
                    self.tr("Save Diagram"),
                    self.tr("<p>The file <b>{0}</b> already exists."
                            " Overwrite it?</p>").format(fname),
                    icon=E5MessageBox.Warning)
                if not res:
                    return
            filename = fname
        
        lines = [
            "version: 1.0",
            "diagram_type: {0} ({1})".format(
                self.__diagramType, self.__diagramTypeString()),
            "scene_size: {0};{1}".format(self.scene.width(),
                                         self.scene.height()),
        ]
        persistenceData = self.builder.getPersistenceData()
        if persistenceData:
            lines.append("builder_data: {0}".format(persistenceData))
        lines.extend(self.umlView.getPersistenceData())
        
        try:
            f = open(filename, "w", encoding="utf-8")
            f.write("\n".join(lines))
            f.close()
        except (IOError, OSError) as err:
            E5MessageBox.critical(
                self,
                self.tr("Save Diagram"),
                self.tr(
                    """<p>The file <b>{0}</b> could not be saved.</p>"""
                    """<p>Reason: {1}</p>""").format(filename, str(err)))
            return
        
        self.__fileName = filename
    
    def load(self):
        """
        Public method to load a diagram from a file.
        
        @return flag indicating success (boolean)
        """
        filename = E5FileDialog.getOpenFileName(
            self,
            self.tr("Load Diagram"),
            "",
            self.tr("Eric Graphics File (*.e5g);;All Files (*)"))
开发者ID:Darriall,项目名称:eric,代码行数:70,代码来源:UMLDialog.py

示例2: GuiAnalysisVisualization

# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import height [as 别名]

#.........这里部分代码省略.........
        text_label = self.ui.label_distance
        value = slider.value()
        self.current_distance = float(value) / slider.maximum() * self.max_distance
        text_label.setText("%.2f" % self.current_distance)
        self.set_graph_component()
        self.main_gui.set_distance_pointer(self.current_distance)
        pass

    def setSceneSize(self):
        pass

    def setScene(self):
        self.scene = QGraphicsScene()
        # self.scene.setSceneRect(0, 0, 600, 1000)
        pass

    def add_toolbar(self, toolbar_name):
        _toolbar = self.addToolBar(toolbar_name)
        self._toolbars[toolbar_name] = _toolbar

    def add_fuction_to_toolbar(self, toolbar_name, _callable):
        assert callable(_callable), "the function supplied is not callable"
        try:
            _action = QtWidgets.QAction(_callable.__name__.replace('_', ' ').lower(), self)
            _action.triggered.connect(_callable)
            self._toolbars[toolbar_name].addSeparator()
            self._toolbars[toolbar_name].addAction(_action)
        except KeyError:
            raise ValueError("the value %s toolbar does not exist" % toolbar_name)

    def setup_toolbar(self):
        self.add_toolbar("Main Toolbar")
        self.add_fuction_to_toolbar("Main Toolbar", self.add_clearance_width_graph)
        self.add_fuction_to_toolbar("Main Toolbar", self.add_clearance_height_graph)
        self.add_fuction_to_toolbar("Main Toolbar", self.add_surface_graph)
        self.add_fuction_to_toolbar("Main Toolbar", self.export_image)

    def export_image(self):
        # print f.Export("tetesdrf.svg", Graphic3d_EF_SVG)
        '''root = Tk()
        root.withdraw()
        file_name = tkinter.filedialog.asksaveasfile(filetypes=[("PNG files", "*.png")])
        name = str(file_name)+".png"
        root.destroy()'''
        self.scene.setSceneRect(self.scene.itemsBoundingRect())
        image = QImage(self.scene.sceneRect().size().toSize(), QImage.Format_RGB32)
        painter = QPainter(image)
        painter.setRenderHint(QPainter.Antialiasing)
        self.scene.render(painter)
        print(image.save("0002_export_analysis.png"))



    def add_clearance_width_graph(self):
        y_pos = self.get_y_pos()
        x_pos = 0
        clearance_width_graph = ClearanceWidthGraph(self, x_pos, y_pos, "dimension width")
        self.graphics.append(clearance_width_graph)
        # self.scene.addItem(clearance_width_graph)
        for item in clearance_width_graph.items:
            self.scene.addItem(item)
        print("clearance_weight_graph_added")

    def add_clearance_height_graph(self):
        y_pos = self.get_y_pos()
        x_pos = 0
开发者ID:johanesmikhael,项目名称:ContinuityAnalysis,代码行数:70,代码来源:analysis_visualization_gui.py

示例3: MapPainter

# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import height [as 别名]
class MapPainter(object):
    def __init__(self, parent, view, displayCities, displayConnections, displayBestUnit):
        super().__init__()
        self.view = view
        self.displayCities = displayCities
        self.displayConnections = displayConnections
        self.displayBestUnit = displayBestUnit
        self.problemMap = None
        self.bestUnit = None

        self.scene = QGraphicsScene(parent)
        self.resizeScene()

        self.view.setScene(self.scene)
        self.view.fitInView(self.scene.sceneRect(), Qt.KeepAspectRatio)

    def resizeScene(self):
        height = self.view.size().height()
        width = self.view.size().width()
        self.scene.setSceneRect(0.0, 0.0, width, height)

    def setProblemMap(self, problemMap):
        self.problemMap = problemMap

    def setBestUnit(self, unit):
        self.bestUnit = unit

    def setDisplayCities(self, enabled = False):
        self.displayCities = bool(enabled)

    def setDisplayConnections(self, enabled = False):
        self.displayConnections = bool(enabled)

    def setDisplayBestUnit(self, enabled = False):
        self.displayBestUnit = bool(enabled)

    def repaint(self):
        if self.problemMap is None:
            return

        self.scene.clear()
        self.resizeScene()
        height = self.scene.height()
        width = self.scene.width()

        if self.displayCities:
            cityBrush = QBrush(QColor(0, 0, 0), Qt.SolidPattern)
            cityPen = QPen(cityBrush, 5.0)
            for city in self.problemMap.cities:
                x = width * city.positionX
                y = height * city.positionY
                self.scene.addEllipse(x, y, 4, 4, cityPen, cityBrush)

        if self.displayConnections:
            connectionBrush = QBrush(QColor(0, 0, 255), Qt.SolidPattern)
            connectionPen = QPen(connectionBrush, 1.0)
            for city in self.problemMap.cities:
                for neighbour in city.connections:
                    x = width * city.positionX
                    y = height * city.positionY
                    x2 = width * self.problemMap.cities[neighbour].positionX
                    y2 = height * self.problemMap.cities[neighbour].positionY
                    self.scene.addLine(x, y, x2, y2, connectionPen)

        if self.displayBestUnit and self.bestUnit is not None:
            bestUnitBrush = QBrush(QColor(255, 0, 0), Qt.SolidPattern)
            bestUnitPen = QPen(bestUnitBrush, 2.0)
            for i in range(-1, len(self.bestUnit.path)-1):
                currCity = self.problemMap.cities[self.bestUnit.path[i]]
                nextCity = self.problemMap.cities[self.bestUnit.path[i+1]]
                x = width * currCity.positionX
                y = height * currCity.positionY
                x2 = width * nextCity.positionX
                y2 = height * nextCity.positionY
                self.scene.addLine(x, y, x2, y2, bestUnitPen)

        self.view.fitInView(self.scene.sceneRect())
开发者ID:akkenoth,项目名称:TSPGen,代码行数:79,代码来源:MapPainter.py


注:本文中的PyQt5.QtWidgets.QGraphicsScene.height方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。