Exemple #1
0
    def clickBox(self, state):
        CURRENT_CONFIG = getConfigs()

        if state == QtCore.Qt.Checked:
            CURRENT_CONFIG["additional"]["startup-message"] = False
            with open(os.path.join(APP_PATH, "globalConfig.json"), "w") as f:
                json.dump(CURRENT_CONFIG, f, indent=4)
        elif state == QtCore.Qt.Unchecked:
            CURRENT_CONFIG["additional"]["startup-message"] = True
            with open(os.path.join(APP_PATH, "globalConfig.json"), "w") as f:
                json.dump(CURRENT_CONFIG, f, indent=4)
Exemple #2
0
    def closeWindow(self):
        CURRENT_CONFIG = getConfigs()

        if CURRENT_CONFIG["additional"]["changed-settings"]:
            CURRENT_CONFIG["additional"]["changed-settings"] = False

            with open(os.path.join(APP_PATH, "globalConfig.json"), "w") as f:
                print(os.path.join(APP_PATH, "globalConfig.json"))
                json.dump(CURRENT_CONFIG, f, indent=4)

            if CURRENT_CONFIG["additional"]["message-box"]:
                dialog = warningDialog()
                dialog.exec_()

        self.close()
 def addPixmap(self):
     #path = QtCore.QFileInfo(self.w_parent.filename).path() if self.w_parent.filename else "."
     path = getConfigs()["common-path"]["pixmap"]
     fname, _ = QtWidgets.QFileDialog.getOpenFileName(
         self.w_parent,
         "Page Designer - Add Pixmap",
         path,
         "Pixmap Files (*.bmp *.jpg *.jpeg *.png)",
         options=QtWidgets.QFileDialog.DontUseNativeDialog)
     pixmap = pixmapItem(self.a_pos(), 0, 1, fname, QtGui.QMatrix(),
                         self.p_scene, self.a_snap)
     self.p_scene.clearSelection()
     self.p_scene.addItem(pixmap)
     global RAW
     RAW = True
def save(scene, parent):
    if not parent.filename:
        path = getConfigs()["common-path"]["project"]
        fname, _ = QtWidgets.QFileDialog.getSaveFileName(
            parent,
            "Page Designer -- Save As",
            path,
            "Page Designer Files (*.pgd)",
            options=QtWidgets.QFileDialog.DontUseNativeDialog)
        if not fname:
            return
        if not fname.endswith(".pgd"):
            fname += ".pgd"
        parent.filename = fname
    fh = None
    try:
        fh = QtCore.QFile(parent.filename)
        if not fh.open(QtCore.QIODevice.WriteOnly):
            raise IOError(fh.errorString())
        scene.clearSelection()
        stream = QtCore.QDataStream(fh)
        stream.setVersion(QtCore.QDataStream.Qt_5_11)
        stream.writeInt32(MAGICK_NUM)
        stream.writeInt16(FILE_VERSION)
        items = scene.items()
        writeItemToBuffer(stream, items)
    except IOError as e:
        QtWidgets.QMessageBox.warning(
            parent, "Page Designer -- Save Error",
            "Failed to save {}: {}".format(parent.filename, e))
    finally:
        if fh is not None:
            fh.close()

    global RAW
    RAW = False
    def openFile(self, snap=None):
        checkRawState(self.p_scene, self.w_parent)

        if snap.isChecked():
            snap.click()

        #path = QtCore.QFileInfo(self.w_parent.filename).path() if self.w_parent.filename else "."
        path = getConfigs()["common-path"]["project"]
        fname, _ = QtWidgets.QFileDialog.getOpenFileName(
            self.w_parent,
            "Page Designer - Open",
            path,
            "Page Designer Files (*.pgd)",
            options=QtWidgets.QFileDialog.DontUseNativeDialog)
        if not fname:
            return
        self.w_parent.filename = fname
        fh = None
        try:
            fh = QtCore.QFile(self.w_parent.filename)
            if not fh.open(QtCore.QIODevice.ReadOnly):
                raise IOError(fh.errorString())

            items = self.p_scene.items()
            while items:
                item = items.pop()
                #print(item)
                self.p_scene.removeItem(item)
                del item

            self.addBorders()

            stream = QtCore.QDataStream(fh)
            stream.setVersion(QtCore.QDataStream.Qt_5_12)
            magic = stream.readInt32()

            if magic != MAGICK_NUM:
                raise IOError("not a valid .pgd file")

            fileVersion = stream.readInt16()
            if fileVersion != FILE_VERSION:
                raise IOError("unrecognised .pgd file version")

            while not fh.atEnd():
                readItemsFromBuffer(stream,
                                    self.p_scene,
                                    self.w_parent,
                                    flag="open",
                                    snap=self.a_snap)

        except IOError as e:
            QtWidgets.QMessageBox.warning(
                self.w_parent, "Page Designer -- Open Error",
                "Failed to open {}: {}".format(self.w_parent.filename, e))
        finally:
            if fh is not None:
                fh.close()
            #snap.click()

        global RAW
        RAW = False