Ejemplo n.º 1
0
    def _create_control(self):
        ctrl = QGraphicsView()
        ctrl.setRenderHints(QPainter.Antialiasing)
        scene = QGraphicsScene()
        ctrl.setScene(scene)

        scene.setBackgroundBrush(QBrush(QColor(237, 237, 237)))

        ctrl.setStyleSheet("border: 0px")

        w, h = 150, 150
        ctrl.setMinimumHeight(h + 22)
        ctrl.setMinimumWidth(w + 22)

        cx, cy = w / 2, h / 2.
        ex, ey = cx, cy + 20
        pen = QPen()
        pen.setStyle(Qt.NoPen)
        # pen.setColor(QColor(237, 237, 237))
        bounding_rect = scene.addRect(0, 0, w, h, pen=pen)
        bounding_rect.setFlag(QGraphicsItem.ItemClipsChildrenToShape)

        self.animation = QSequentialAnimationGroup()
        self._add_laser_logo(scene, bounding_rect, ex, ey, cx, cy, w, h)
        self._add_bullet(scene, bounding_rect, ex, ey, cx, cy)
        self._add_fragments(scene, bounding_rect, ex, ey)

        self.animation.setLoopCount(-1)

        return ctrl
Ejemplo n.º 2
0
    def _create_control(self):
        ctrl = QGraphicsView()
        ctrl.setRenderHints(QPainter.Antialiasing)
        scene = QGraphicsScene()
        ctrl.setScene(scene)

        scene.setBackgroundBrush(QBrush(QColor(237, 237, 237)))

        ctrl.setStyleSheet("border: 0px")

        w, h = 150, 150
        ctrl.setMinimumHeight(h + 22)
        ctrl.setMinimumWidth(w + 22)

        cx, cy = w / 2, h / 2.
        ex, ey = cx, cy + 20
        pen = QPen()
        pen.setStyle(Qt.NoPen)
        # pen.setColor(QColor(237, 237, 237))
        bounding_rect = scene.addRect(0, 0, w, h, pen=pen)
        bounding_rect.setFlag(QGraphicsItem.ItemClipsChildrenToShape)

        self.animation = QSequentialAnimationGroup()
        self._add_laser_logo(scene, bounding_rect, ex, ey, cx, cy, w, h)
        self._add_bullet(scene, bounding_rect,ex, ey, cx, cy)
        self._add_fragments(scene, bounding_rect, ex, ey)

        self.animation.setLoopCount(-1)

        return ctrl
Ejemplo n.º 3
0
    def _create_control(self):
        ctrl = QGraphicsView()
        scene = QGraphicsScene()
        ctrl.setScene(scene)

        scene.setBackgroundBrush(QBrush(QColor(237, 237, 237)))
        ctrl.setStyleSheet("border: 0px")
        md = self._dimension * 3 + self._spacing * 4
        ctrl.setMaximumWidth(md)
        ctrl.setMaximumHeight(md)

        layout = QVBoxLayout()

        layout.addWidget(ctrl)
        self._scene = scene
        self.control = QWidget()
        self.control.setLayout(layout)
Ejemplo n.º 4
0
    def init(self, parent):
        """
        """
        rad = self.factory.radius

        if not rad:
            rad = 20

        if self.control is None:

            scene = QGraphicsScene()

            # system background color
            scene.setBackgroundBrush(QBrush(QColor(237, 237, 237)))

            x, y = 10, 10
            cx = x + rad / DIAMETER_SCALAR
            cy = y + rad / DIAMETER_SCALAR

            self.colors = [QColor(ci) for ci in self.factory.colors]
            brush = get_gradient(self.colors[self.value], cx, cy, rad / 2)
            pen = QPen()
            pen.setWidth(0)
            self._led_ellipse = scene.addEllipse(x, y, rad, rad, pen=pen, brush=brush)

            ctrl = LEDGraphicsView(rad, scene)

            layout = QVBoxLayout()
            layout.addWidget(ctrl)
            layout.setAlignment(ctrl, Qt.AlignHCenter)

            if self.factory.label:
                txt = QLabel(self.factory.label)
                layout.addWidget(txt)
                layout.setAlignment(txt, Qt.AlignHCenter)

            self.control = QWidget()
            self.control.setLayout(layout)
    def __init__(self, parent=None):
        super(UniverseWidget, self).__init__(parent)

        self.universe_graphics_scene = UniverseScene(self)
        self.universe_graphics_view = QGraphicsView(self.universe_graphics_scene)
        self.universe_graphics_view.setRenderHint(QPainter.Antialiasing)

        self.game_scene_widget = GameSceneWidget()
        self.game_scene_widget.visualization.universe = self.universe_graphics_scene.universe_item.universe

        self.middle_container_widget = QTabWidget()
        self.middle_container_widget.addTab(self.universe_graphics_view, "Elements relations")
        self.middle_container_widget.addTab(self.game_scene_widget, "Game scene")

        self.matters_stencils_scene = QGraphicsScene()
        self.matters_stencils_view = QGraphicsView(self.matters_stencils_scene)
        self.matters_stencils_scene.addItem(MatterToolboxItem())

        self.atoms_stencils_scene = QGraphicsScene()
        self.atoms_stencils_view = QGraphicsView(self.atoms_stencils_scene)
        self.atoms_stencils_scene.addItem(AtomToolboxItem())

        self.forces_stencils_scene = QGraphicsScene()
        self.forces_stencils_view = QGraphicsView(self.forces_stencils_scene)

        radial_force_toolbox_item = RadialForceToolboxItem()
        expression_based_force_toolbox_item = ExpressionBasedForceToolboxItem()
        bitmap_force_toolbox_item = BitmapForceToolboxItem()

        self.forces_stencils_scene.addItem(radial_force_toolbox_item)
        self.forces_stencils_scene.addItem(expression_based_force_toolbox_item)
        self.forces_stencils_scene.addItem(bitmap_force_toolbox_item)

        force_stencils_container_graphics_layout = QGraphicsLinearLayout(Qt.Vertical)
        force_stencils_container_graphics_layout.addItem(radial_force_toolbox_item)
        force_stencils_container_graphics_layout.addItem(expression_based_force_toolbox_item)
        force_stencils_container_graphics_layout.addItem(bitmap_force_toolbox_item)

        force_stencils_container_graphics_widget = QGraphicsWidget()
        force_stencils_container_graphics_widget.setLayout(force_stencils_container_graphics_layout)

        self.forces_stencils_scene.addItem(force_stencils_container_graphics_widget)

        self.natural_laws_stencils_scene = QGraphicsScene()
        self.natural_laws_stencils_view = QGraphicsView(self.natural_laws_stencils_scene)
        self.natural_laws_stencils_scene.addItem(NaturalLawToolboxItem())

        self.agents_stencils_scene = QGraphicsScene()
        self.agents_stencils_view = QGraphicsView(self.agents_stencils_scene)
        self.agents_stencils_scene.addItem(AgentToolboxItem())

        self.sensors_stencils_scene = QGraphicsScene()
        self.sensors_stencils_view = QGraphicsView(self.sensors_stencils_scene)
        self.sensors_stencils_scene.addItem(SensorToolboxItem())

        self.tool_box = QToolBox()
        self.tool_box.addItem(self.matters_stencils_view, "Matters")
        self.tool_box.addItem(self.atoms_stencils_view, "Atoms")
        self.tool_box.addItem(self.forces_stencils_view, "Forces")
        self.tool_box.addItem(self.natural_laws_stencils_view, "Natural laws")
        self.tool_box.addItem(self.agents_stencils_view, "Agents")
        self.tool_box.addItem(self.sensors_stencils_view, "Sensors")

        self.properties_widget = PropertiesWidget(self.game_scene_widget.visualization.universe)

        main_layout = QHBoxLayout()
        main_layout.addWidget(self.tool_box, 1)
        main_layout.addWidget(self.middle_container_widget, 3)
        main_layout.addWidget(self.properties_widget, 1)
        self.setCentralWidget(QWidget())
        self.centralWidget().setLayout(main_layout)

        self.universe_graphics_scene.properties_bindings_update_required.connect(
            self.update_properties_bindings)
        self.universe_graphics_scene.properties_bindings_disconnect_required.connect(
            self.disconnect_graphics_item_from_properties_widget)

        self.create_actions()
        self.setup_toolbar()
class UniverseWidget(QMainWindow):
    """
    This widget is used to configure Universe
    """
    def __init__(self, parent=None):
        super(UniverseWidget, self).__init__(parent)

        self.universe_graphics_scene = UniverseScene(self)
        self.universe_graphics_view = QGraphicsView(self.universe_graphics_scene)
        self.universe_graphics_view.setRenderHint(QPainter.Antialiasing)

        self.game_scene_widget = GameSceneWidget()
        self.game_scene_widget.visualization.universe = self.universe_graphics_scene.universe_item.universe

        self.middle_container_widget = QTabWidget()
        self.middle_container_widget.addTab(self.universe_graphics_view, "Elements relations")
        self.middle_container_widget.addTab(self.game_scene_widget, "Game scene")

        self.matters_stencils_scene = QGraphicsScene()
        self.matters_stencils_view = QGraphicsView(self.matters_stencils_scene)
        self.matters_stencils_scene.addItem(MatterToolboxItem())

        self.atoms_stencils_scene = QGraphicsScene()
        self.atoms_stencils_view = QGraphicsView(self.atoms_stencils_scene)
        self.atoms_stencils_scene.addItem(AtomToolboxItem())

        self.forces_stencils_scene = QGraphicsScene()
        self.forces_stencils_view = QGraphicsView(self.forces_stencils_scene)

        radial_force_toolbox_item = RadialForceToolboxItem()
        expression_based_force_toolbox_item = ExpressionBasedForceToolboxItem()
        bitmap_force_toolbox_item = BitmapForceToolboxItem()

        self.forces_stencils_scene.addItem(radial_force_toolbox_item)
        self.forces_stencils_scene.addItem(expression_based_force_toolbox_item)
        self.forces_stencils_scene.addItem(bitmap_force_toolbox_item)

        force_stencils_container_graphics_layout = QGraphicsLinearLayout(Qt.Vertical)
        force_stencils_container_graphics_layout.addItem(radial_force_toolbox_item)
        force_stencils_container_graphics_layout.addItem(expression_based_force_toolbox_item)
        force_stencils_container_graphics_layout.addItem(bitmap_force_toolbox_item)

        force_stencils_container_graphics_widget = QGraphicsWidget()
        force_stencils_container_graphics_widget.setLayout(force_stencils_container_graphics_layout)

        self.forces_stencils_scene.addItem(force_stencils_container_graphics_widget)

        self.natural_laws_stencils_scene = QGraphicsScene()
        self.natural_laws_stencils_view = QGraphicsView(self.natural_laws_stencils_scene)
        self.natural_laws_stencils_scene.addItem(NaturalLawToolboxItem())

        self.agents_stencils_scene = QGraphicsScene()
        self.agents_stencils_view = QGraphicsView(self.agents_stencils_scene)
        self.agents_stencils_scene.addItem(AgentToolboxItem())

        self.sensors_stencils_scene = QGraphicsScene()
        self.sensors_stencils_view = QGraphicsView(self.sensors_stencils_scene)
        self.sensors_stencils_scene.addItem(SensorToolboxItem())

        self.tool_box = QToolBox()
        self.tool_box.addItem(self.matters_stencils_view, "Matters")
        self.tool_box.addItem(self.atoms_stencils_view, "Atoms")
        self.tool_box.addItem(self.forces_stencils_view, "Forces")
        self.tool_box.addItem(self.natural_laws_stencils_view, "Natural laws")
        self.tool_box.addItem(self.agents_stencils_view, "Agents")
        self.tool_box.addItem(self.sensors_stencils_view, "Sensors")

        self.properties_widget = PropertiesWidget(self.game_scene_widget.visualization.universe)

        main_layout = QHBoxLayout()
        main_layout.addWidget(self.tool_box, 1)
        main_layout.addWidget(self.middle_container_widget, 3)
        main_layout.addWidget(self.properties_widget, 1)
        self.setCentralWidget(QWidget())
        self.centralWidget().setLayout(main_layout)

        self.universe_graphics_scene.properties_bindings_update_required.connect(
            self.update_properties_bindings)
        self.universe_graphics_scene.properties_bindings_disconnect_required.connect(
            self.disconnect_graphics_item_from_properties_widget)

        self.create_actions()
        self.setup_toolbar()

    def update_properties_bindings(self):
        for graphics_item in self.universe_graphics_scene.graphics_items:
            graphics_item.clicked.connect(self.properties_widget.process_item_clicked)

        self.properties_widget.invalidate()

    def disconnect_graphics_item_from_properties_widget(self, graphics_item):
        graphics_item.clicked.disconnect(self.properties_widget.process_item_clicked)
        self.properties_widget.process_item_clicked(None)

    def create_actions(self):
        self.compile_action = QAction(QIcon(":/images/compile.png"), "Compile", self)
        self.run_action = QAction(QIcon(":/images/run.png"), "Run", self)
        self.abort_action = QAction(QIcon(":/images/abort.png"), "Abort", self)

        self.compile_action.triggered.connect(self.compile)
        self.run_action.triggered.connect(self.run)
        self.abort_action.triggered.connect(self.abort)

    def setup_toolbar(self):
        toolbar = QToolBar(self)
        toolbar.addAction(self.compile_action)
        toolbar.addAction(self.run_action)
        toolbar.addAction(self.abort_action)
        self.addToolBar(toolbar)

    def compile(self):
        """
        This method compiles Universe. It is not possible
        to evaluate Universe along the time without compilation.
        """
        print "compile"

    def run(self):
        """
        This methods start procedure of evaluation of universe along the time.
        """
        print "run"

    def abort(self):
        """
        This method resets positions of matters and number of atoms to initial state,
        which is saved right before evaluation started.
        """
        print "abort"