Пример #1
0
 def method_6(self, string_0, treeNodeCollection_0):
     value = None
     # using (TextWriter streamWriter = new StreamWriter(string_0, false, Encoding.Unicode))
     streamWriter = open(string_0, 'w')
     stringBuilder = StringBuilder()
     QARecord.smethod_0(self.fileNameQA, stringBuilder)
     streamWriter.write(stringBuilder.ToString())
     fileInfo = QFileInfo(string_0)
     directoryName = fileInfo.path()
     num = 1
     for treeNodeCollection0 in treeNodeCollection_0:
         tag = treeNodeCollection0.Tag# as QAReportEntry
         stringBuilder = StringBuilder()
         stringBuilder.AppendLine("<p align=\"left\"><H2><br>{0}. {1}<br></H2></p>".format(str(treeNodeCollection0.Index + 1), treeNodeCollection0.Text))
         if (tag.Value != None):
             value = tag.Value
             if (value.Type != QARecordType.Snapshot):
                 value.method_6(stringBuilder, None, False, False)
             else:
                 value._class_ = QASnapshot
                 num = value.method_12(stringBuilder, value, directoryName, num)
         else:
             for node in treeNodeCollection0.Nodes:
                 tag = node.Tag# as QAReportEntry
                 stringBuilder.AppendLine("<p align=\"left\"><H3><br>{0}.{1} {2}<br></H3></p>".format(str(treeNodeCollection0.Index + 1), str(node.Index + 1), node.Text))
                 value = tag.Value
                 if (value.Type != QARecordType.Snapshot):
                     value.method_6(stringBuilder, None, False, False)
                 else:
                     value._class_ = QASnapshot
                     num = value.method_12(stringBuilder, value, directoryName, num)
         streamWriter.write(stringBuilder.ToString())
     stringBuilder = StringBuilder()
     QARecord.smethod_1(stringBuilder)
     streamWriter.write(stringBuilder.ToString())
Пример #2
0
    def export(self):
        if self.__path is not None:
            default_export_path = self.__path
        else:
            default_export_path = PlotSettingsModel().getDefaultPlotPath()

        dialog = QFileDialog(self.__active_plot_panel)
        dialog.setFileMode(QFileDialog.AnyFile)
        # dialog.setNameFilter("Image (*.png);; PDF (*.pdf)")
        dialog.setNameFilter("Image (*.png)")
        dialog.setWindowTitle("Export plot")
        dialog.setDirectory(default_export_path)
        dialog.setOption(QFileDialog.DontUseNativeDialog, True)
        dialog.setLabelText(QFileDialog.FileType, "Select file type: ")
        dialog.setAcceptMode(QFileDialog.AcceptSave)
        dialog.selectFile(self.getDefaultFileName())

        if dialog.exec_():
            result = dialog.selectedFiles()
            assert isinstance(result, QStringList)
            if len(result) == 1:
                file_info = QFileInfo(result[0])
                self.__file_name = file_info.fileName()
                self.__path = file_info.path()
                self.__selected_file_type = dialog.selectedNameFilter()
            name = self.__active_plot_panel.getName()
            url = self.__active_plot_panel.getUrl()

            web_page = PlotWebPage("export - %s" % name)
            web_page.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
            web_page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
            web_page.setViewportSize(QSize(self.__width, self.__height))
            self.__bridge = PlotBridge(web_page, url)
            self.__bridge.plotReady.connect(self.plotReady)
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
Пример #3
0
def setLastUsedDir(filePath):
    settings = QSettings()
    fileInfo = QFileInfo(filePath)
    if fileInfo.isDir():
      dirPath = fileInfo.filePath()
    else:
      dirPath = fileInfo.path()
    settings.setValue( "/GdalTools/lastUsedDir", dirPath )
Пример #4
0
 def method_5(self, string_0, qaexportType_0):
     resultStr = ""
     stringBuilder = StringBuilder()
     fileInfo = QFileInfo(string_0)
     QARecord.smethod_0(self.fileNameQA, stringBuilder)
     streamWriter = open(string_0, 'w')
     resultStr += stringBuilder.ToString() + "\n"
     # streamWriter.write(stringBuilder.ToString())
     directoryName = fileInfo.path()
     num = 1
     num1 = 1
     for i in range(len(self.sessions)):
         item = self.sessions[i]
         if (qaexportType_0 == QAExportType.QA):
             stringBuilder = StringBuilder()
             str0 = Extensions.smethod_19(item.Stamp)
             if (item.SessionType != QASessionType.Started):
                 stringBuilder.AppendLine(
                     "<p align=\"left\"><H2><br>{0} {1} ({2})<br></H2></p>".
                     format(str(i + 1), Captions.QA_OPENED, str0))
             else:
                 stringBuilder.AppendLine(
                     "<p align=\"left\"><H2><br>{0} {1} ({2})<br></H2></p>".
                     format(str(i + 1), Captions.QA_STARTED, str0))
             item.method_6(stringBuilder, None, False, False)
             resultStr += stringBuilder.ToString() + "\n"
             # streamWriter.write(stringBuilder.ToString())
         for j in range(len(item.Children)):
             qARecord = item.Children[j]
             if (qARecord.Type != QARecordType.Session):
                 stringBuilder = StringBuilder()
                 if (qaexportType_0 != QAExportType.QA):
                     stringBuilder.AppendLine(
                         "<p align=\"left\"><H2><br>{0}. {1}<br></H2></p>".
                         format(str(num1), qARecord.Heading))
                 else:
                     longTimeString = qARecord.Stamp.ToLongTimeString()
                     heading = [
                         i + 1, j + 1, qARecord.Heading, longTimeString
                     ]
                     stringBuilder.AppendLine(
                         "<p align=\"left\"><H3><br>{0}.{1} {2} ({3})<br></H3></p>"
                         .format(str(i + 1), str(j + 1), qARecord.Heading,
                                 longTimeString))
                 if (qARecord.Type != QARecordType.Snapshot):
                     qARecord.method_6(stringBuilder, None, False, False)
                 else:
                     qARecord._class_ = QASnapshot
                     num = qARecord.method_12(stringBuilder, qARecord,
                                              directoryName, num)
                 resultStr += stringBuilder.ToString() + "\n"
                 # streamWriter.write(stringBuilder.ToString())
                 num1 += 1
     stringBuilder = StringBuilder()
     QARecord.smethod_1(stringBuilder)
     resultStr += stringBuilder.ToString() + "\n"
     streamWriter.write(resultStr)
Пример #5
0
    def export(self):
        if self.__path is not None:
            default_export_path = self.__path
        else:
            default_export_path = PlotSettingsModel().getDefaultPlotPath()

        dialog = QFileDialog(self.__active_plot_panel)
        dialog.setFileMode(QFileDialog.AnyFile)
        #dialog.setNameFilter("Image (*.png);; PDF (*.pdf)")
        dialog.setNameFilter("Image (*.png)")
        dialog.setWindowTitle("Export plot")
        dialog.setDirectory(default_export_path)
        dialog.setOption(QFileDialog.DontUseNativeDialog, True)
        dialog.setLabelText(QFileDialog.FileType, "Select file type: ")
        dialog.setAcceptMode(QFileDialog.AcceptSave)
        dialog.selectFile(self.getDefaultFileName())

        if dialog.exec_():
            result = dialog.selectedFiles()
            assert isinstance(result, QStringList)
            if len(result) == 1:
                file_info = QFileInfo(result[0])
                self.__file_name = file_info.fileName()
                self.__path = file_info.path()
                self.__selected_file_type = dialog.selectedNameFilter()
            name = self.__active_plot_panel.getName()
            url = self.__active_plot_panel.getUrl()

            web_page = PlotWebPage("export - %s" % name)
            web_page.mainFrame().setScrollBarPolicy(Qt.Vertical,
                                                    Qt.ScrollBarAlwaysOff)
            web_page.mainFrame().setScrollBarPolicy(Qt.Horizontal,
                                                    Qt.ScrollBarAlwaysOff)
            web_page.setViewportSize(QSize(self.__width, self.__height))
            self.__bridge = PlotBridge(web_page, url)
            self.__bridge.plotReady.connect(self.plotReady)
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
Пример #6
0
    def __init__(self, IMC, parent=None):
        super(QDialog, self).__init__(parent)
        self.IMC = IMC
        self.setModal(True)
        self.setSizeGripEnabled(True)
        bookinfo = QFileInfo(IMC.bookPath)
        self.setWindowTitle("Properties of {0}".format(bookinfo.fileName()))
        # Our layout is a vertical stack of widgets and hboxes
        vlayout = QVBoxLayout()
        # Add the path information field
        fplb = QLabel("Path: {0}".format(unicode(bookinfo.path())))
        fplb.setFrameStyle(QFrame.Sunken)
        fplb.setToolTip(QString("Full path to document"))
        vlayout.addWidget(fplb)
        # Add the write-encoding choice, setting the buttons to reflect
        # the current value. We build this up from the inside out.
        # Two radio buttons. As they will be exclusive we need connect
        # the toggled() signal from only one of them.
        self.saveEncoding = self.IMC.bookSaveEncoding
        rb_enc_utf = QRadioButton(QString("UTF-8"))
        rb_enc_utf.setChecked(self.saveEncoding == rb_enc_utf.text())
        rb_enc_utf.toggled.connect(self.encodingChange)
        rb_enc_ltn = QRadioButton(QString("Latin-1"))
        rb_enc_ltn.setChecked(self.saveEncoding != rb_enc_utf.text())
        # put the buttons in a layout because groupbox doesn't act as one
        hb_enc_btns = QHBoxLayout()
        hb_enc_btns.addWidget(rb_enc_utf)
        hb_enc_btns.addWidget(rb_enc_ltn)
        # add to groupbox to get exclusivity on the buttons
        gb_enc = QGroupBox()
        gb_enc.setLayout(hb_enc_btns)
        # put in horizontal box with descriptive label, and add to the dialog
        hb_enc = QHBoxLayout()
        lb_enc = QLabel("Write Encoding")
        lb_enc.setToolTip("Character encoding when writing the document")
        hb_enc.addWidget(lb_enc)
        hb_enc.addWidget(gb_enc)
        vlayout.addLayout(hb_enc)

        # Next get a QStringList of available dicts from pqSpell
        # and create a combobox with that content.
        dictlist = IMC.spellCheck.dictList()
        dictlist.sort()
        self.maintag = self.IMC.bookMainDict
        if self.maintag.isEmpty():
            self.maintag = self.IMC.spellCheck.mainTag
        current = dictlist.indexOf(QString(self.maintag))  # index of current dict or -1
        self.cb_dic = QComboBox()
        self.cb_dic.addItems(dictlist)
        if current >= 0:
            self.cb_dic.setCurrentIndex(current)
        self.cb_dic.activated.connect(self.dictChange)

        hb_dic = QHBoxLayout()
        hb_dic.addWidget(QLabel("Main Dictionary"))
        hb_dic.addStretch()
        hb_dic.addWidget(self.cb_dic)
        vlayout.addLayout(hb_dic)

        # create the [ apply cancel ] buttons, but apply == accept
        apply_button = QPushButton("Apply")
        cancel_button = QPushButton("Cancel")
        cancel_button.setDefault(True)
        bbox = QDialogButtonBox()
        bbox.addButton(cancel_button, QDialogButtonBox.RejectRole)
        bbox.addButton(apply_button, QDialogButtonBox.AcceptRole)
        bbox.accepted.connect(self.applyButtonHit)
        bbox.rejected.connect(self.cancelButtonHit)
        vlayout.addWidget(bbox)

        self.setLayout(vlayout)
Пример #7
0
Файл: scj.py Проект: Ptaah/SCJ
class SCJ(QThread):
    lock = QMutex()
    def __init__(self, file=None, format=None, createDir=False):
        super(SCJ, self).__init__()
        self.format = format
        self.filename = file
        self.file = QFileInfo(self.filename)
        self.file.makeAbsolute()
        self.suffix = self.file.suffix()
        if createDir:
            self.outputdir = u"%s-%s" % (self.file.path(), self.format)
        else:
            self.outputdir = self.file.path()
        self.output = u"%s%c%s.%s" % ( self.outputdir,
                                       QDir.separator().unicode(),
                                       self.file.completeBaseName(),
                                       self.format)
        if self.format != "mp3":
            self.command = [ u"/usr/bin/sox", u"-S", u"%s" % self.filename,
                             u"-t", u"%s" % self.format, u"%s" % self.output ]
            self.pipecmd = None
        else:
            self.command = [ u"/usr/bin/sox", u"-S", u"%s" % self.filename,
                             u"-t", u"wav", u"-" ]
            self.pipecmd = [ u"/usr/bin/ffmpeg", u"-y", u"-i", u"-",
                             u"-f", u"%s" % self.format, u"%s" % self.output ]
        self.value = 0
        self.process = None
        self.retCode = None
        self.running = False
        self.log = QString(u"")

    def setProgress(self, value):
        self.value = value
        self.emit(SIGNAL("progress(int)"), self.value)

    def mkdir(self, path):
        directory = QDir(path)
        SCJ.lock.lock()
        if not directory.exists() :
            if not directory.mkpath(path) :
                self.emit(SIGNAL("error(QString)"),
                          QString(self.trUtf8("Cannot create %s" % path)))
        SCJ.lock.unlock()

    def run(self):
        self.running = True
        self.mkdir(self.outputdir)
        self.process = Process( self.command,
                                    stdinput = None)
        if self.pipecmd :
            self.pipe = Process( self.pipecmd, stdinput = self.process.stdout)
            self.process.stdout.close()
        self.emit(SIGNAL("void started()"))
        while self.retCode == None :
            try:
                self.progression()
            except IOError as e:
                pass

            self.retCode = self.process.poll()
            self.usleep(10)
        self.running = False
        self.end()

    def resume(self):
        if self.process :
            try :
                self.process.send_signal(signal.SIGCONT)
            except OSError :
                pass

    def stop(self):
        if self.process :
            try :
                self.process.send_signal(signal.SIGSTOP)
            except OSError :
                pass

    def cancel(self):
        if self.process :
            try :
                try:
                    self.process.terminate()
                    self.process.wait()
                except Exception as e:
                    self.process.kill()
            except OSError as e :
                pass
        self.running = False

    def end(self):
        if self.retCode != 0 :
            self.emit(SIGNAL("error(QString)"), self.trUtf8("Code de retour sox : %d\n%s" %
                             (self.retCode, self.log)))
        else:
            if mp3tags : self.set_tags()
            self.setProgress(100)
        self.emit(SIGNAL("finished()"))

    def progression(self):
        """
        Recupération de la progression du process en cours
        """
        line = self.process.stderr.readline()
        if re.match(u'^In:.*', line):
            val = re.findall(u"[\.\d]+%", line)[0]
            self.setProgress(float(val[:-1]))
        else :
            self.log.append(line)

    def set_tags(self):
        """
        Update audio file metadata (Id3 tags...)
        """
        if self.format != "mp3":
            return
        tags =  mutagen.File(u"%s" % self.filename, easy = True)
        audio = EasyID3(u"%s" % self.output)
        for key in tags.keys():
            # Ugly hack to have the year in the mp3 metadata
            if key == "year":
                audio["date"] = tags[key]
            else:
                if key in audio.valid_keys :
                    audio[key] = tags[key]
        audio.save()
Пример #8
0
    def __init__(self, IMC, parent=None):
        super(QDialog, self).__init__(parent)
        self.IMC = IMC
        self.setModal(True)
        self.setSizeGripEnabled(True)
        bookinfo = QFileInfo(IMC.bookPath)
        self.setWindowTitle(u"Properties of {0}".format(bookinfo.fileName()))
        # Our layout is a vertical stack of widgets and hboxes
        vlayout = QVBoxLayout()
        # Add the path information field
        fplb = QLabel(u"Path: {0}".format(unicode(bookinfo.path())))
        fplb.setFrameStyle(QFrame.Sunken)
        fplb.setToolTip(QString(u'Full path to document'))
        vlayout.addWidget(fplb)
        # Add the write-encoding choice, setting the buttons to reflect
        # the current value. We build this up from the inside out.
        # Two radio buttons. As they will be exclusive we need connect
        # the toggled() signal from only one of them.
        self.saveEncoding = self.IMC.bookSaveEncoding
        rb_enc_utf = QRadioButton(QString(u'UTF-8'))
        rb_enc_utf.setChecked(self.saveEncoding == rb_enc_utf.text())
        rb_enc_utf.toggled.connect(self.encodingChange)
        rb_enc_ltn = QRadioButton(QString(u'Latin-1'))
        rb_enc_ltn.setChecked(self.saveEncoding != rb_enc_utf.text())
        # put the buttons in a layout because groupbox doesn't act as one
        hb_enc_btns = QHBoxLayout()
        hb_enc_btns.addWidget(rb_enc_utf)
        hb_enc_btns.addWidget(rb_enc_ltn)
        # add to groupbox to get exclusivity on the buttons
        gb_enc = QGroupBox()
        gb_enc.setLayout(hb_enc_btns)
        # put in horizontal box with descriptive label, and add to the dialog
        hb_enc = QHBoxLayout()
        lb_enc = QLabel(u'Write Encoding')
        lb_enc.setToolTip('Character encoding when writing the document')
        hb_enc.addWidget(lb_enc)
        hb_enc.addWidget(gb_enc)
        vlayout.addLayout(hb_enc)

        # Next get a QStringList of available dicts from pqSpell
        # and create a combobox with that content.
        dictlist = IMC.spellCheck.dictList()
        dictlist.sort()
        self.maintag = self.IMC.bookMainDict
        if self.maintag.isEmpty():
            self.maintag = self.IMC.spellCheck.mainTag
        current = dictlist.indexOf(QString(
            self.maintag))  # index of current dict or -1
        self.cb_dic = QComboBox()
        self.cb_dic.addItems(dictlist)
        if current >= 0: self.cb_dic.setCurrentIndex(current)
        self.cb_dic.activated.connect(self.dictChange)

        hb_dic = QHBoxLayout()
        hb_dic.addWidget(QLabel(u'Main Dictionary'))
        hb_dic.addStretch()
        hb_dic.addWidget(self.cb_dic)
        vlayout.addLayout(hb_dic)

        # create the [ apply cancel ] buttons, but apply == accept
        apply_button = QPushButton("Apply")
        cancel_button = QPushButton("Cancel")
        cancel_button.setDefault(True)
        bbox = QDialogButtonBox()
        bbox.addButton(cancel_button, QDialogButtonBox.RejectRole)
        bbox.addButton(apply_button, QDialogButtonBox.AcceptRole)
        bbox.accepted.connect(self.applyButtonHit)
        bbox.rejected.connect(self.cancelButtonHit)
        vlayout.addWidget(bbox)

        self.setLayout(vlayout)
Пример #9
0
'''
QGIS Processing script
(c) 2017 Andreas Plesch
save style in qml file
'''
##X3D=group
##save_raster_style=name
##input_raster=raster
##style_file=output file

import shutil
from PyQt4.QtCore import QFile, QFileInfo, QDir

#saveNamedStyle always writes to .qml
fileInfo = QFileInfo(style_file)
style_file = fileInfo.path() + QDir.separator() + fileInfo.completeBaseName() + ".qml"

file=QFile(style_file)
#touch, create since saveStyle only writes file if it exists
file.open(QFile.ReadWrite)
file.close()

r = processing.getObject(input_raster)
print(r.saveNamedStyle(style_file))
#saveNamedStyle always writes to .qml
#copy back
#fileInfo = QFileInfo(style_file)
#style_file = fileInfo.path() + QDir.separator() + fileInfo.completeBaseName() + ".qml"
#shutil.copy(qml, style_file)