def initialize_loading_page(self):
        svg_container = QGraphicsScene(self.window().loading_svg_view)
        svg_item = QGraphicsSvgItem()

        svg = QSvgRenderer(get_image_path("loading_animation.svg"))
        svg.repaintNeeded.connect(svg_item.update)
        svg_item.setSharedRenderer(svg)
        svg_container.addItem(svg_item)

        self.window().loading_svg_view.setScene(svg_container)
        self.window().core_manager.events_manager.upgrader_tick.connect(self.set_loading_text)
        self.window().core_manager.events_manager.upgrader_started.connect(
            lambda: self.set_loading_text("Upgrading..."))
        self.window().core_manager.events_manager.upgrader_finished.connect(lambda: self.loading_label.hide())

        # Create a loading label that displays the status during upgrading
        self.loading_label = QLabel(self)
        self.loading_label.setStyleSheet("color: #ddd; font-size: 22px;")
        self.loading_label.setAlignment(Qt.AlignCenter)

        self.on_window_resize()
        self.loading_label.hide()

        # Hide the force shutdown button initially. Should be triggered by shutdown timer from main window.
        self.window().force_shutdown_btn.hide()
Beispiel #2
0
class Vectorgraphic(DesignItem):
    def __init__(self, filename, scene):
        super(Vectorgraphic, self).__init__(scene)
        self.renderer = QSvgRenderer()
        self.renderer.load(filename)
        self.svg = QGraphicsSvgItem(self)
        self.svg.setSharedRenderer(self.renderer)
        self.setRect(0, 0,
                     self.svg.boundingRect().width(),
                     self.svg.boundingRect().height())

    def typeName(self):
        return "Vectorgraphic"

    def paint(self, paint, option, widget):
        if option.state & QStyle.State_Selected:
            self.drawHighlightSelected(paint, option)

    def scaleObjects(self):
        self.xscale = self.rect.width() / self.svg.boundingRect().width()
        self.yscale = self.rect.height() / self.svg.boundingRect().height()
        trans = QTransform()
        trans.scale(self.xscale, self.yscale)
        self.svg.setTransform(trans)

    def setScale(self, x, y):
        self.xscale = x
        self.yscale = y
        trans = QTransform()
        trans.scale(self.xscale, self.yscale)
        self.svg.setTransform(trans)
        self.setRect(0, 0,
                     self.svg.boundingRect().width() * x,
                     self.svg.boundingRect().height() * y)
Beispiel #3
0
class Compass(QWidget):
    def __init__(self, parent):
        super().__init__(parent)
        self.uas = None
        svgRenderer = QSvgRenderer('res/compass.svg')
        self.compass = QGraphicsSvgItem()
        self.compass.setSharedRenderer(svgRenderer)
        self.compass.setCacheMode(QGraphicsItem.NoCache)
        self.compass.setElementId('needle')

        center = self.compass.boundingRect().center()
        self.compass.setTransformOriginPoint(center.x(), center.y())

        bkgnd = QGraphicsSvgItem()
        bkgnd.setSharedRenderer(svgRenderer)
        bkgnd.setCacheMode(QGraphicsItem.NoCache)
        bkgnd.setElementId('background')

        self.compass.setPos(
            bkgnd.boundingRect().width() / 2 -
            self.compass.boundingRect().width() / 2,
            bkgnd.boundingRect().height() / 2 -
            self.compass.boundingRect().height() / 2)

        self.compass.setTransformOriginPoint(
            self.compass.boundingRect().width() / 2,
            self.compass.boundingRect().height() / 2)

        fregnd = QGraphicsSvgItem()
        fregnd.setSharedRenderer(svgRenderer)
        fregnd.setCacheMode(QGraphicsItem.NoCache)
        fregnd.setElementId('foreground')

        scene = QGraphicsScene()
        scene.addItem(bkgnd)
        scene.addItem(self.compass)
        scene.addItem(fregnd)
        scene.setSceneRect(bkgnd.boundingRect())

        view = QGraphicsView(scene)
        view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        layout = QVBoxLayout()
        layout.addWidget(view)
        super().setLayout(layout)

    def setHeading(self, hdr):
        if math.isnan(hdr) == False:
            hdr *= 180.0 / math.pi
            self.compass.setRotation(360.0 - hdr)

    def updateAttitude(self, sourceUAS, timestamp, roll, pitch, yaw):
        unused(sourceUAS, timestamp, roll, pitch)
        self.setHeading(yaw)

    def setActiveUAS(self, uas):
        uas.updateAttitudeSignal.connect(self.updateAttitude)
        self.uas = uas
Beispiel #4
0
def load_gears_animation():
    svg_container = QGraphicsScene()
    svg_item = QGraphicsSvgItem()

    svg = QSvgRenderer(get_image_path("loading_animation.svg"))
    svg.repaintNeeded.connect(svg_item.update)
    svg_item.setSharedRenderer(svg)

    svg_container.addItem(svg_item)
    return svg_container
Beispiel #5
0
 def loadSvgContent(self, content):
     s = self.scene()
     s.clear()
     self.resetTransform()
     item = QGraphicsSvgItem()
     item.setSharedRenderer(QSvgRenderer(content))
     item.setFlags(QGraphicsItem.ItemClipsToShape)
     item.setCacheMode(QGraphicsItem.NoCache)
     item.setZValue(0)
     s.addItem(item)
Beispiel #6
0
    def initialize_discovering_page(self):
        svg_container = QGraphicsScene(self.window().discovering_svg_view)
        svg_item = QGraphicsSvgItem()

        svg = QSvgRenderer(get_image_path("loading_animation.svg"))
        svg.repaintNeeded.connect(svg_item.update)
        svg_item.setSharedRenderer(svg)
        svg_container.addItem(svg_item)

        self.window().discovering_svg_view.setScene(svg_container)

        self.window().core_manager.events_manager.discovered_channel.connect(self.on_discovered_channel)
Beispiel #7
0
    def initialize_discovering_page(self):
        svg_container = QGraphicsScene(self.window().discovering_svg_view)
        svg_item = QGraphicsSvgItem()

        svg = QSvgRenderer(get_image_path("loading_animation.svg"))
        connect(svg.repaintNeeded, svg_item.update)
        svg_item.setSharedRenderer(svg)
        svg_container.addItem(svg_item)

        self.window().discovering_svg_view.setScene(svg_container)

        connect(self.window().core_manager.events_manager.discovered_channel,
                self.on_discovered_channel)
Beispiel #8
0
    def __init__(self, parent):
        super().__init__(parent)
        self.uas = None
        svgRenderer = QSvgRenderer('res/barometer.svg')

        bkgnd = QGraphicsSvgItem()
        bkgnd.setSharedRenderer(svgRenderer)
        bkgnd.setCacheMode(QGraphicsItem.NoCache)
        bkgnd.setElementId('background')

        scene = QGraphicsScene()
        scene.addItem(bkgnd)
        scene.setSceneRect(bkgnd.boundingRect())

        self.needle = QGraphicsSvgItem()
        self.needle.setSharedRenderer(svgRenderer)
        self.needle.setCacheMode(QGraphicsItem.NoCache)
        self.needle.setElementId('needle')
        self.needle.setParentItem(bkgnd)
        self.needle.setPos(
            bkgnd.boundingRect().width() / 2 -
            self.needle.boundingRect().width() / 2,
            bkgnd.boundingRect().height() / 2 -
            self.needle.boundingRect().height() / 2)
        self.needle.setTransformOriginPoint(
            self.needle.boundingRect().width() / 2,
            self.needle.boundingRect().height() / 2)
        # textElement = svgRenderer.boundsOnElement('needle-text')
        self.digitalBaro = QGraphicsTextItem()
        self.digitalBaro.setDefaultTextColor(QColor(255, 255, 255))
        self.digitalBaro.document().setDefaultTextOption(
            QTextOption(Qt.AlignCenter))
        self.digitalBaro.setFont(QFont('monospace', 13, 60))
        self.digitalBaro.setParentItem(bkgnd)

        txm = QTransform()
        txm.translate(
            bkgnd.boundingRect().center().x(),
            bkgnd.boundingRect().height() -
            1.5 * self.digitalBaro.document().size().height())
        self.digitalBaro.setTransform(txm, False)

        view = QGraphicsView(scene)
        view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        layout = QVBoxLayout()
        layout.addWidget(view)
        self.setLayout(layout)
        self.setBarometer(1000)
Beispiel #9
0
    def __init__(self, parent):
        super().__init__(parent)
        self.uas = None
        svgRenderer = QSvgRenderer('res/compass.svg')
        self.compass = QGraphicsSvgItem()
        self.compass.setSharedRenderer(svgRenderer)
        self.compass.setCacheMode(QGraphicsItem.NoCache)
        self.compass.setElementId('needle')

        center = self.compass.boundingRect().center()
        self.compass.setTransformOriginPoint(center.x(), center.y())

        bkgnd = QGraphicsSvgItem()
        bkgnd.setSharedRenderer(svgRenderer)
        bkgnd.setCacheMode(QGraphicsItem.NoCache)
        bkgnd.setElementId('background')

        self.compass.setPos(
            bkgnd.boundingRect().width() / 2 -
            self.compass.boundingRect().width() / 2,
            bkgnd.boundingRect().height() / 2 -
            self.compass.boundingRect().height() / 2)

        self.compass.setTransformOriginPoint(
            self.compass.boundingRect().width() / 2,
            self.compass.boundingRect().height() / 2)

        fregnd = QGraphicsSvgItem()
        fregnd.setSharedRenderer(svgRenderer)
        fregnd.setCacheMode(QGraphicsItem.NoCache)
        fregnd.setElementId('foreground')

        scene = QGraphicsScene()
        scene.addItem(bkgnd)
        scene.addItem(self.compass)
        scene.addItem(fregnd)
        scene.setSceneRect(bkgnd.boundingRect())

        view = QGraphicsView(scene)
        view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        layout = QVBoxLayout()
        layout.addWidget(view)
        super().setLayout(layout)
Beispiel #10
0
    def initialize_loading_page(self):
        svg_container = QGraphicsScene(self.window().loading_svg_view)
        svg_item = QGraphicsSvgItem()

        svg = QSvgRenderer(get_image_path("loading_animation.svg"))
        svg.repaintNeeded.connect(svg_item.update)
        svg_item.setSharedRenderer(svg)
        svg_container.addItem(svg_item)

        self.window().loading_svg_view.setScene(svg_container)
        self.window().core_manager.events_manager.upgrader_tick.connect(
            self.on_upgrader_tick)
        self.window().core_manager.events_manager.upgrader_finished.connect(
            self.upgrader_finished)
        self.window().skip_conversion_btn.hide()

        # Hide the force shutdown button initially. Should be triggered by shutdown timer from main window.
        self.window().force_shutdown_btn.hide()
Beispiel #11
0
class SymbolItem(QGraphicsItemGroup):
    _cache = {}

    def __init__(self, symbol, parent=None, cache_dir=None):
        super().__init__(parent)

        self._symbol = symbol

        try:
            renderer, svg_symbol = self._cache[self._symbol]
        except KeyError:
            path = os.path.join(DATA_DIR, 'symbols', '%s.svg' % self._symbol)
            svg_symbol = SvgSymbol(path, cache_dir=cache_dir)
            renderer = QSvgRenderer(svg_symbol.get_xml())
            self._cache[self._symbol] = (renderer, svg_symbol)

        self.grp = QGraphicsItemGroup(self)
        origin_x, origin_y = svg_symbol.get_origin()
        self.grp.setPos(-origin_x, -origin_y)

        self.body = QGraphicsSvgItem(self.grp)
        self.body.setSharedRenderer(renderer)
Beispiel #12
0
class Barometer(QWidget):
    def __init__(self, parent):
        super().__init__(parent)
        self.uas = None
        svgRenderer = QSvgRenderer('res/barometer.svg')

        bkgnd = QGraphicsSvgItem()
        bkgnd.setSharedRenderer(svgRenderer)
        bkgnd.setCacheMode(QGraphicsItem.NoCache)
        bkgnd.setElementId('background')

        scene = QGraphicsScene()
        scene.addItem(bkgnd)
        scene.setSceneRect(bkgnd.boundingRect())

        self.needle = QGraphicsSvgItem()
        self.needle.setSharedRenderer(svgRenderer)
        self.needle.setCacheMode(QGraphicsItem.NoCache)
        self.needle.setElementId('needle')
        self.needle.setParentItem(bkgnd)
        self.needle.setPos(
            bkgnd.boundingRect().width() / 2 -
            self.needle.boundingRect().width() / 2,
            bkgnd.boundingRect().height() / 2 -
            self.needle.boundingRect().height() / 2)
        self.needle.setTransformOriginPoint(
            self.needle.boundingRect().width() / 2,
            self.needle.boundingRect().height() / 2)
        # textElement = svgRenderer.boundsOnElement('needle-text')
        self.digitalBaro = QGraphicsTextItem()
        self.digitalBaro.setDefaultTextColor(QColor(255, 255, 255))
        self.digitalBaro.document().setDefaultTextOption(
            QTextOption(Qt.AlignCenter))
        self.digitalBaro.setFont(QFont('monospace', 13, 60))
        self.digitalBaro.setParentItem(bkgnd)

        txm = QTransform()
        txm.translate(
            bkgnd.boundingRect().center().x(),
            bkgnd.boundingRect().height() -
            1.5 * self.digitalBaro.document().size().height())
        self.digitalBaro.setTransform(txm, False)

        view = QGraphicsView(scene)
        view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        layout = QVBoxLayout()
        layout.addWidget(view)
        self.setLayout(layout)
        self.setBarometer(1000)

    def setBarometer(self, hbar):
        deg = ((hbar - 950) * 3 + 210) % 360
        self.needle.setRotation(deg)
        self.digitalBaro.setPlainText('{:.1f}'.format(hbar))
        self.digitalBaro.adjustSize()
        self.digitalBaro.setX(0 - self.digitalBaro.textWidth() / 2)

    def updateAirPressure(self, sourceUAS, timestamp, absPressure,
                          diffPressure, temperature):
        unused(sourceUAS, timestamp, diffPressure, temperature)
        self.setBarometer(absPressure)

    def setActiveUAS(self, uas):
        uas.updateAirPressureSignal.connect(self.updateAirPressure)
        self.uas = uas
Beispiel #13
0
class Text(DesignItem):
    def __init__(self, text, scene):
        super(Text, self).__init__(scene)
        self.font = QFont("Arial")
        self.font.setPointSize(14)
        self.font.setStyleName("Standard")
        self.text = text
        self.textcolor = QColor(Qt.black)

        self.data = str.encode(self.getSvg())
        self.renderer = QSvgRenderer()
        self.renderer.load(self.data)
        self.svg = QGraphicsSvgItem(self)
        self.svg.setSharedRenderer(self.renderer)
        self.setRect(0, 0,
                     self.svg.boundingRect().width(),
                     self.svg.boundingRect().height())

    def typeName(self):
        return "Text"

    def paint(self, paint, option, widget):
        if option.state & QStyle.State_Selected:
            self.drawHighlightSelected(paint, option)

    def getTextTag(self, id):
        fm = QFontMetrics(self.font)
        svg = "<text "
        if id:
            svg += "id=\"" + id + "\" "
        svg += "x=\"0\" y=\"" + str(fm.ascent()) + "\" "
        svg += "font-family=\"" + self.font.family() + "\" "
        svg += "font-size=\"" + str(self.font.pointSize() * 1.25) + "px\" "
        if self.font.bold():
            svg += "font-weight=\"bold\" "
        if self.font.italic():
            svg += "font-style=\"italic\" "
        svg += "fill=\"" + self.textcolor.name() + "\" "
        svg += "opacity=\"" + str(self.opacity()) + "\" "
        svg += ">"
        svg += self.text
        svg += "</text>"
        return svg

    def getSvg(self):
        font = QFont(self.font.family())
        font.setBold(self.font.bold())
        font.setItalic(self.font.italic())
        font.setPixelSize(self.font.pointSize() * 1.25)
        fm = QFontMetrics(font)
        self.width = fm.width(self.text) + 2
        self.height = fm.height()

        svg = "<svg width=\"" + str(self.width) + "\" "
        svg += "height=\"" + str(self.height) + "\" >"
        svg += self.getTextTag("")
        svg += "</svg>"
        return svg

    def setScale(self, x, y):
        self.xscale = x
        self.yscale = y
        trans = QTransform()
        trans.scale(self.xscale, self.yscale)
        self.svg.setTransform(trans)
        self.setRect(0, 0,
                     self.svg.boundingRect().width() * x,
                     self.svg.boundingRect().height() * y)

    def scaleObjects(self):
        self.xscale = self.rect.width() / self.svg.boundingRect().width()
        self.yscale = self.rect.height() / self.svg.boundingRect().height()
        trans = QTransform()
        trans.scale(self.xscale, self.yscale)
        self.svg.setTransform(trans)
Beispiel #14
0
class RCPGWindow(DockWidget):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Rogudator's comic panel generator")

        mainLayout = QVBoxLayout()

        #l means label
        #b means push button
        #sp means spinbox
        #sl means slider
        #cb means combobox

        l_preview = QLabel(self)
        l_preview.setText("Preview:")
        mainLayout.addWidget(l_preview)

        self.rcpg_object = RCPG()
        self.rcpg_object.refresh_svg_renderer()

        renderer = self.rcpg_object.svg_renderer
        self.svg_item = QGraphicsSvgItem()
        self.svg_item.setSharedRenderer(renderer)

        self.preview = Page_preview()
        self.preview.scene().addItem(self.svg_item)
        mainLayout.addWidget(self.preview)

        self.set_clickable_gutters()

        l_generate = QLabel(self)
        l_generate.setText("Generate as:")
        mainLayout.addWidget(l_generate)

        b_layer = QPushButton(self)
        b_layer.setText("Layer")

        b_file = QPushButton(self)
        b_file.setText("File")

        file_and_layer = QHBoxLayout(self)
        file_and_layer.addWidget(b_layer)
        file_and_layer.addWidget(b_file)
        mainLayout.addLayout(file_and_layer)

        l_num_rows = QLabel(self)
        l_num_rows.setText("Number of rows:")
        mainLayout.addWidget(l_num_rows)

        self.sp_num_rows = QSpinBox(self)
        self.sp_num_rows.setValue(2)
        self.sp_num_rows.setMinimum(1)

        self.sl_num_rows = QSlider(self)
        self.sl_num_rows.setMinimum(1)
        self.sl_num_rows.setMaximum(6)
        self.sl_num_rows.setOrientation(Qt.Horizontal)
        self.sl_num_rows.setTickPosition(1)
        self.sl_num_rows.setTickInterval(1)
        self.sl_num_rows.setMinimumWidth(100)
        self.sl_num_rows.setValue(2)

        num_rows = QHBoxLayout(self)
        num_rows.addWidget(self.sp_num_rows)
        num_rows.addWidget(self.sl_num_rows)
        mainLayout.addLayout(num_rows)

        l_num_columns = QLabel(self)
        l_num_columns.setText("Numer of columns:")
        mainLayout.addWidget(l_num_columns)

        self.sp_num_columns = QSpinBox(self)
        self.sp_num_columns.setValue(2)
        self.sp_num_columns.setMinimum(1)

        self.sl_num_columns = QSlider(self)
        self.sl_num_columns.setMinimum(1)
        self.sl_num_columns.setMaximum(6)
        self.sl_num_columns.setOrientation(Qt.Horizontal)
        self.sl_num_columns.setTickPosition(1)
        self.sl_num_columns.setTickInterval(1)
        self.sl_num_columns.setMinimumWidth(100)
        self.sl_num_columns.setValue(2)

        num_columns = QHBoxLayout(self)
        num_columns.addWidget(self.sp_num_columns)
        num_columns.addWidget(self.sl_num_columns)
        mainLayout.addLayout(num_columns)

        l_gutter = QLabel(self)
        l_gutter.setText("Gutters")
        mainLayout.addWidget(l_gutter)

        self.cb_gutter_equal = QCheckBox(self)
        self.cb_gutter_equal.setText(
            "Horizontal and vertical gutters are equal")
        self.cb_gutter_equal.setChecked(True)
        mainLayout.addWidget(self.cb_gutter_equal)

        l_hgutter = QLabel(self)
        l_hgutter.setText("Size of a horizontal gutter:")
        mainLayout.addWidget(l_hgutter)

        self.hgutter_updated = True

        self.hgutter_max = int(self.rcpg_object.height_page /
                               (self.rcpg_object.rows + 1))

        self.sp_hgutter = QSpinBox(self)
        self.sp_hgutter.setValue(30)
        self.sp_hgutter.setMinimum(1)
        self.sp_hgutter.setMaximum(self.hgutter_max)

        self.sl_hgutter = QSlider(self)
        self.sl_hgutter.setMaximum(1)
        self.sl_hgutter.setMaximum(self.hgutter_max)
        self.sl_hgutter.setOrientation(Qt.Horizontal)
        self.sl_hgutter.setTickInterval(1)
        self.sl_hgutter.setMinimumWidth(100)
        self.sl_hgutter.setValue(30)

        hgutter = QHBoxLayout(self)
        hgutter.addWidget(self.sp_hgutter)
        hgutter.addWidget(self.sl_hgutter)
        mainLayout.addLayout(hgutter)

        l_vgutter = QLabel(self)
        l_vgutter.setText("Size of a vertical gutter:")
        mainLayout.addWidget(l_vgutter)

        self.vgutter_updated = True

        self.vgutter_max = int(self.rcpg_object.width_page /
                               (self.rcpg_object.columns + 1))

        self.sp_vgutter = QSpinBox(self)
        self.sp_vgutter.setValue(30)
        self.sp_vgutter.setMinimum(1)
        self.sp_vgutter.setMaximum(self.vgutter_max)

        self.sl_vgutter = QSlider(self)
        self.sl_vgutter.setMaximum(1)
        self.sl_vgutter.setMaximum(self.vgutter_max)
        self.sl_vgutter.setOrientation(Qt.Horizontal)
        self.sl_vgutter.setTickInterval(1)
        self.sl_vgutter.setMinimumWidth(100)
        self.sl_vgutter.setValue(30)

        vgutter = QHBoxLayout(self)
        vgutter.addWidget(self.sp_vgutter)
        vgutter.addWidget(self.sl_vgutter)
        mainLayout.addLayout(vgutter)

        l_cgutter = QLabel(self)
        l_cgutter.setText("Color of the gutter:")
        mainLayout.addWidget(l_cgutter)

        self.l_color_gutter = QLabel(self)
        self.l_color_gutter.setText("#000000")

        b_color_gutter = QPushButton(self)
        b_color_gutter.setText("Change")

        color_of_gutter = QHBoxLayout(self)
        color_of_gutter.addWidget(self.l_color_gutter)
        color_of_gutter.addWidget(b_color_gutter)
        mainLayout.addLayout(color_of_gutter)

        l_outline = QLabel(self)
        l_outline.setText("Size of panel outline:")
        mainLayout.addWidget(l_outline)

        self.sp_outline = QSpinBox(self)
        self.sp_outline.setValue(6)
        self.sp_outline.setMinimum(0)

        self.sl_outline = QSlider(self)
        self.sl_outline.setMinimum(0)
        self.sl_outline.setMaximum(98)
        self.sl_outline.setOrientation(Qt.Horizontal)
        self.sl_outline.setTickInterval(1)
        self.sl_outline.setMinimumWidth(100)
        self.sl_outline.setValue(6)

        outline = QHBoxLayout(self)
        outline.addWidget(self.sp_outline)
        outline.addWidget(self.sl_outline)
        mainLayout.addLayout(outline)

        l_color_outline = QLabel(self)
        l_color_outline.setText("Color of panel outline:")
        mainLayout.addWidget(l_color_outline)

        self.l_color_outline = QLabel(self)
        self.l_color_outline.setText("#ffffff")

        b_color_outline = QPushButton(self)
        b_color_outline.setText("Change")

        color_of_outline = QHBoxLayout(self)
        color_of_outline.addWidget(self.l_color_outline)
        color_of_outline.addWidget(b_color_outline)
        mainLayout.addLayout(color_of_outline)

        self.scrollMainLayout = QScrollArea(self)
        self.scrollMainLayout.setWidgetResizable(True)
        self.scrollMainLayout.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)

        b_file.clicked.connect(self.b_file_create)
        b_layer.clicked.connect(self.b_layer_create)
        self.sp_num_rows.valueChanged.connect(self.upd_sp_num_rows)
        self.sl_num_rows.valueChanged.connect(self.upd_sl_num_rows)
        self.sp_num_columns.valueChanged.connect(self.upd_sp_num_columns)
        self.sl_num_columns.valueChanged.connect(self.upd_sl_num_columns)
        self.sp_hgutter.valueChanged.connect(self.upd_sp_hgutter)
        self.sl_hgutter.valueChanged.connect(self.upd_sl_hgutter)
        self.sp_vgutter.valueChanged.connect(self.upd_sp_vgutter)
        self.sl_vgutter.valueChanged.connect(self.upd_sl_vgutter)
        b_color_gutter.clicked.connect(self.color_gutter_dialog)
        self.sp_outline.valueChanged.connect(self.upd_sp_outline)
        self.sl_outline.valueChanged.connect(self.upd_sl_outline)
        b_color_outline.clicked.connect(self.color_outline_dialog)

        self.window = QWidget(self)
        self.window.setLayout(mainLayout)
        self.scrollMainLayout.setWidget(self.window)
        self.setWidget(self.scrollMainLayout)
        self.show()

    def b_file_create(self):
        temp_dir = tempfile.gettempdir() + "/rcpg10.svg"
        body = self.rcpg_object.get_svg_string()
        with open(temp_dir, 'w', encoding='utf-8') as f:
            f.write(body)
        file = Krita.instance().openDocument(temp_dir)
        Krita.instance().activeWindow().addView(file)
        file.refreshProjection()

    def b_layer_create(self):
        temp_dir = tempfile.gettempdir() + "/rcpg10.svg"
        body = self.rcpg_object.get_svg_string()
        with open(temp_dir, 'w', encoding='utf-8') as f:
            f.write(body)
        app = Krita.instance()
        doc = app.activeDocument()
        if doc != None:
            root = doc.rootNode()
            layer = doc.createNode("Panels", "paintLayer")
            img = QImage(temp_dir)
            img = img.scaled(doc.width(),
                             doc.height(),
                             aspectRatioMode=Qt.KeepAspectRatio,
                             transformMode=Qt.SmoothTransformation)
            if not img.isNull():
                img.convertToFormat(QImage.Format_RGBA8888)
                ptr = img.constBits()
                ptr.setsize(img.byteCount())
                layer.setPixelData(bytes(ptr.asarray()), 0, 0, img.width(),
                                   img.height())
            root.addChildNode(layer, None)
            doc.refreshProjection()

    def upd_sp_num_rows(self):
        self.preview.scene().clear()
        rows = self.sp_num_rows.value()
        if rows > 0 and rows < 7:
            self.sl_num_rows.setValue(rows)

        self.hgutter_max = int(self.rcpg_object.height_page / (rows + 1))
        self.sp_hgutter.setMaximum(self.hgutter_max)
        self.sl_hgutter.setMaximum(self.hgutter_max)

        self.rcpg_object.rows = rows
        self.rcpg_object.upd_everything()
        self.rcpg_object.standard_grid()
        self.rcpg_object.refresh_svg_renderer()
        self.svg_item = QGraphicsSvgItem()
        self.svg_item.setSharedRenderer(self.rcpg_object.svg_renderer)
        self.preview.scene().addItem(self.svg_item)
        self.set_clickable_gutters()
        self.svg_item.update()

    def upd_sl_num_rows(self):
        self.sp_num_rows.setValue(self.sl_num_rows.value())

    def upd_sp_num_columns(self):
        self.preview.scene().clear()
        columns = self.sp_num_columns.value()
        if columns > 0 and columns < 7:
            self.sl_num_columns.setValue(columns)

        self.vgutter_max = int(self.rcpg_object.width_page / (columns + 1))
        self.sp_vgutter.setMaximum(self.vgutter_max)
        self.sl_vgutter.setMaximum(self.vgutter_max)

        self.rcpg_object.columns = columns
        self.rcpg_object.upd_everything()
        self.rcpg_object.standard_grid()
        self.rcpg_object.refresh_svg_renderer()
        self.svg_item = QGraphicsSvgItem()
        self.svg_item.setSharedRenderer(self.rcpg_object.svg_renderer)
        self.preview.scene().addItem(self.svg_item)
        self.set_clickable_gutters()
        self.svg_item.update()

    def upd_sl_num_columns(self):
        self.sp_num_columns.setValue(self.sl_num_columns.value())

    def upd_sp_hgutter(self):
        horizontal_gutter = self.sp_hgutter.value()
        if horizontal_gutter > 0 and horizontal_gutter < self.hgutter_max:
            self.sl_hgutter.setValue(horizontal_gutter)
        self.rcpg_object.horizontal_gutter = horizontal_gutter

        if self.cb_gutter_equal.isChecked() == True:
            self.hgutter_updated = False
            self.sp_vgutter.setValue(horizontal_gutter)
            if horizontal_gutter > 0 and horizontal_gutter < self.vgutter_max:
                self.sl_vgutter.setValue(horizontal_gutter)
            self.rcpg_object.vertical_gutter = horizontal_gutter

        if self.hgutter_updated == True:
            self.preview.scene().clear()
            self.rcpg_object.upd_everything()
            self.rcpg_object.standard_grid()
            self.rcpg_object.refresh_svg_renderer()
            self.svg_item = QGraphicsSvgItem()
            self.svg_item.setSharedRenderer(self.rcpg_object.svg_renderer)
            self.preview.scene().addItem(self.svg_item)
            self.set_clickable_gutters()
            self.svg_item.update()
        else:
            self.hgutter_updated = True

    def upd_sl_hgutter(self):
        horizontal_gutter = self.sl_hgutter.value()
        self.sp_hgutter.setValue(horizontal_gutter)
        self.rcpg_object.horizontal_gutter = horizontal_gutter

        if self.cb_gutter_equal.isChecked() == True:
            self.sp_vgutter.setValue(horizontal_gutter)
            if horizontal_gutter > 0 and horizontal_gutter < self.vgutter_max:
                self.sl_vgutter.setValue(horizontal_gutter)
            self.rcpg_object.vertical_gutter = horizontal_gutter

    def upd_sp_vgutter(self):
        vertical_gutter = self.sp_vgutter.value()
        if vertical_gutter > 0 and vertical_gutter < self.vgutter_max:
            self.sl_vgutter.setValue(vertical_gutter)
        self.rcpg_object.vertical_gutter = vertical_gutter

        if self.cb_gutter_equal.isChecked() == True:
            self.hgutter_updated = False
            self.sp_hgutter.setValue(vertical_gutter)
            if vertical_gutter > 0 and vertical_gutter < self.hgutter_max:
                self.sl_hgutter.setValue(vertical_gutter)
            self.rcpg_object.horizontal_gutter = vertical_gutter

        if self.vgutter_updated == True:
            self.preview.scene().clear()
            self.rcpg_object.upd_everything()
            self.rcpg_object.standard_grid()
            self.rcpg_object.refresh_svg_renderer()
            self.svg_item = QGraphicsSvgItem()
            self.svg_item.setSharedRenderer(self.rcpg_object.svg_renderer)
            self.preview.scene().addItem(self.svg_item)
            self.set_clickable_gutters()
            self.svg_item.update()
        else:
            self.vgutter_max = True

    def upd_sl_vgutter(self):
        vertical_gutter = self.sl_vgutter.value()
        self.sp_vgutter.setValue(vertical_gutter)
        self.rcpg_object.vertical_gutter = vertical_gutter

        if self.cb_gutter_equal.isChecked() == True:
            self.sp_hgutter.setValue(vertical_gutter)
            if vertical_gutter > 0 and vertical_gutter < self.hgutter_max:
                self.sl_hgutter.setValue(vertical_gutter)
            self.rcpg_object.vertical_gutter = vertical_gutter

    def color_gutter_dialog(self):
        color = QColorDialog.getColor(QColor(self.l_color_gutter.text()))
        self.l_color_gutter.setText(color.name())
        self.rcpg_object.gutter_color = self.l_color_gutter.text()
        self.rcpg_object.refresh_svg_renderer()
        self.svg_item.update()
        self.update()

    def upd_sp_outline(self):
        self.preview.scene().clear()
        outline = self.sp_outline.value()
        self.rcpg_object.outline = outline

        self.rcpg_object.upd_everything()
        self.rcpg_object.standard_grid()
        self.rcpg_object.refresh_svg_renderer()
        self.svg_item = QGraphicsSvgItem()
        self.svg_item.setSharedRenderer(self.rcpg_object.svg_renderer)
        self.preview.scene().addItem(self.svg_item)
        self.set_clickable_gutters()
        self.svg_item.update()

    def upd_sl_outline(self):
        outline = self.sl_outline.value()
        self.sp_outline.setValue(outline)

    def color_outline_dialog(self):
        color = QColorDialog.getColor(QColor(self.l_color_outline.text()))
        self.l_color_outline.setText(color.name())
        self.rcpg_object.outline_color = self.l_color_outline.text()
        self.rcpg_object.refresh_svg_renderer()
        self.svg_item.update()
        self.update()

    def set_clickable_gutters(self):
        for i in range(self.rcpg_object.rows_vertices - 1):
            for j in range(self.rcpg_object.columns_vertices - 1):
                x = self.rcpg_object.vertex_coordinate_x[j]
                y = self.rcpg_object.vertex_coordinate_y[i]
                width = self.rcpg_object.vertex_coordinate_x[
                    j + 1] - self.rcpg_object.vertex_coordinate_x[j]
                height = self.rcpg_object.vertex_coordinate_y[
                    i + 1] - self.rcpg_object.vertex_coordinate_y[i]
                gutter_plane = Clickable_gutter(x, y, width, height)
                gutter_plane.setAcceptHoverEvents(True)
                gutter_plane.setRCPGObject(self.rcpg_object, i, j)
                gutter_plane.setFlag(QGraphicsItem.ItemIsSelectable)
                self.preview.scene().addItem(gutter_plane)
        self.preview.get_rcpg_object_id(
            (self.rcpg_object.rows_vertices - 1) *
            (self.rcpg_object.columns_vertices - 1))

    def canvasChanged(self, canvas):
        app = Krita.instance()
        doc = app.activeDocument()
        if doc != None:
            self.preview.scene().clear()
            self.rcpg_object.height_page = doc.height()
            self.rcpg_object.width_page = doc.width()
            self.rcpg_object.upd_everything()
            self.rcpg_object.standard_grid()
            self.rcpg_object.refresh_svg_renderer()
            self.svg_item = QGraphicsSvgItem()
            self.svg_item.setSharedRenderer(self.rcpg_object.svg_renderer)
            self.preview.scene().addItem(self.svg_item)
            self.set_clickable_gutters()
            self.svg_item.update()
            iii = self.preview.scene().sceneRect()
            if doc.height() > doc.width():
                iii.setHeight(doc.height())
            else:
                iii.setHeight(doc.height())
                iii.setWidth(doc.width())
            self.preview.scene().setSceneRect(iii)
            self.preview.updateView()