Beispiel #1
0
    def exportMarkdown(self):
        dir = QFileDialog.getExistingDirectory(self, 'Select output folder',
                                               './doc')
        path = os.path.join(dir, 'summary.md')
        assets = os.path.join(dir, 'assets')
        os.makedirs(assets, exist_ok=True)

        line = lambda it: f"|{'|'.join(it)}|\n"

        with open(path, 'w', encoding='utf8') as f:
            f.write('## Error Summary\n\n')
            f.write(f'> Auto generated from {self.conf_name}.\n\n')
            # table title
            f.write(line(DiagBag.header()))
            f.write(line([':-:'] * len(DiagBag.header())))
            # content
            for i in range(len(self.raw)):
                d = self.raw[self.ui.tblDiag.item(i, 0).text()]
                if int(d.pm > self.thresh) != d.ym or (d.yb is not None and
                                                       argmax(d.pb) != d.yb):
                    pic = self.solver.pid2path(d.pid)
                    QFile.copy(pic, os.path.join(assets,
                                                 os.path.split(pic)[-1]))
                    f.write(line(self.rich(d)))

        self.ui.statusbar.showMessage(f'{path} saved.', 3000)
    def savePackageAs(self):
        fileName = QFileDialog.getSaveFileName(self, "Save File", "/Packages/",
                                               "Packages (*.ezpak)")[0]
        if fileName != "":
            myDir = QDir()
            myDir.mkpath(fileName)
            for file in self.uselistmodel.metadataList:
                QFile.copy(file, fileName + "/" + file.split("/")[-1])

            oldtemplate = open(self.templateFilePath, 'r')
            oldtemplatelist = oldtemplate.readline()
            filetype = oldtemplate.readline()
            oldtemplate.readline()
            oldlist = oldtemplate.readline()
            oldtree = oldtemplate.readline()
            oldtemplate.close()
            with open(fileName + "/" + self.currentTemplate, 'w') as outfile:
                outfile.write(oldtemplatelist)
                outfile.write(filetype)
                json.dump(self.editableKeys, outfile)
                outfile.write("\n")
                outfile.write(oldlist)
                outfile.write(oldtree)

            with open(fileName + "/" + self.currentTemplate + "pak",
                      'w') as outfile:
                json.dump(fileName + "/" + self.currentTemplate, outfile)
                outfile.write("\n")
                json.dump(self.ui.otherDataFileLineEdit.text(), outfile)
                outfile.write("\n")
                json.dump(self.uselistmodel.metadataList, outfile)
Beispiel #3
0
def organize_files():
    separator = window.cmb_separator.currentText()

    target_dir = QDir(window.edit_target_dir.text())
    list_target_dirs = target_dir.entryList()

    progress = progress_window()
    progress.set_max(window.list_files.count())

    for index in range(window.list_files.count()):
        progress.set_value(index)

        #
        # STEP 1: Create target directory if necessary
        #

        # Get folder name for file
        fn_src = window.list_files.item(index).text()
        progress.set_text("Processing \"{0}\"".format(fn_src))

        md = pyexiv2.ImageMetadata(fn_src)

        image_ts = datetime.date
        try:
            md.read()
            image_ts = md['Exif.Photo.DateTimeOriginal'].value

        except:
            print("Cannot open file \"{0}\"".format(fn_src))
            continue

        # Makes sure the day and month are always two digits
        def correct_format(number):
            if number < 10:
                return "0" + str(number)
            else:
                return str(number)

        folder_name_trg = str(image_ts.year) + separator + correct_format(
            image_ts.month) + separator + correct_format(image_ts.day)
        dir_name_trg = target_dir.absolutePath() + QDir.separator(
        ) + folder_name_trg

        # Create folder for day if necessary
        target_folder = QDir(dir_name_trg)
        if not target_folder.exists():
            QDir.mkdir(target_dir, dir_name_trg)
            print("Created directory \"{0}\"".format(dir_name_trg))

        #
        # STEP 2: Move file
        #

        # absolute file name of the new file
        fn_trg_abs = dir_name_trg + QDir.separator() + fn_src.split(
            QDir.separator())[-1]
        file_trg = QFile(fn_trg_abs)

        # Don't overwrite existing files
        if file_trg.exists():
            print("Skipping file \"{0}\"".format(file_trg.fileName()))
            continue

        QFile.copy(fn_src, fn_trg_abs)
        print("Copied file from \"{0}\" to \"{1}\"".format(fn_src, fn_trg_abs))

    print("Finished!")
Beispiel #4
0
from PySide2.QtWebChannel import QWebChannel
from PySide2.QtWebSockets import QWebSocketServer

from dialog import Dialog
from core import Core
from websocketclientwrapper import WebSocketClientWrapper

if __name__ == '__main__':
    app = QApplication(sys.argv)
    if not QSslSocket.supportsSsl():
        print('The example requires SSL support.')
        sys.exit(-1)
    cur_dir = os.path.dirname(os.path.abspath(__file__))
    jsFileInfo = QFileInfo(cur_dir + "/qwebchannel.js")
    if not jsFileInfo.exists():
        QFile.copy(":/qtwebchannel/qwebchannel.js",
                   jsFileInfo.absoluteFilePath())

    # setup the QWebSocketServer
    server = QWebSocketServer("QWebChannel Standalone Example Server",
                              QWebSocketServer.NonSecureMode)
    if not server.listen(QHostAddress.LocalHost, 12345):
        print("Failed to open web socket server.")
        sys.exit(-1)

    # wrap WebSocket clients in QWebChannelAbstractTransport objects
    clientWrapper = WebSocketClientWrapper(server)

    # setup the channel
    channel = QWebChannel()
    clientWrapper.clientConnected.connect(channel.connectTo)