コード例 #1
0
 def SaveDialog(cls, job, dialog):
     foo = QtGui.QFileDialog.getSaveFileName(QtGui.QApplication.activeWindow(),
             "Path - Job Template",
             PathPreferences.filePath(),
             "job_*.json")[0]
     if foo: 
         cls.Execute(job, foo, dialog)
コード例 #2
0
 def SaveDialog(cls, job, dialog):
     foo = QtGui.QFileDialog.getSaveFileName(QtGui.QApplication.activeWindow(),
             "Path - Job Template",
             PathPreferences.filePath(),
             "job_*.json")[0]
     if foo: 
         cls.Execute(job, foo, dialog)
コード例 #3
0
    def checkWorkingDir(self):
        # users shouldn't use the example toolbits and libraries.
        # working directory should be writable
        PathLog.track()

        workingdir = os.path.dirname(PathPreferences.lastPathToolLibrary())
        defaultdir = os.path.dirname(PathPreferences.pathDefaultToolsPath())

        dirOK = lambda: workingdir != defaultdir and (os.access(
            workingdir, os.W_OK))

        if dirOK():
            return True

        qm = PySide.QtGui.QMessageBox
        ret = qm.question(
            None, '', "Toolbit working directory not set up. Do that now?",
            qm.Yes | qm.No)

        if ret == qm.No:
            return False

        msg = translate("Path", "Choose a writable location for your toolbits",
                        None)
        while not dirOK():
            workingdir = PySide.QtGui.QFileDialog.getExistingDirectory(
                None, msg, PathPreferences.filePath())

        PathPreferences.setLastPathToolLibrary("{}/Library".format(workingdir))

        subdirlist = ['Bit', 'Library', 'Shape']
        mode = 0o777
        for dir in subdirlist:
            subdir = "{}/{}".format(workingdir, dir)
            if not os.path.exists(subdir):
                qm = PySide.QtGui.QMessageBox
                ret = qm.question(
                    None, '',
                    "Toolbit Working directory {} should contain a '{}' subdirectory. Create it?"
                    .format(workingdir, dir), qm.Yes | qm.No)

                if ret == qm.Yes:
                    os.mkdir(subdir, mode)
                    qm = PySide.QtGui.QMessageBox
                    ret = qm.question(
                        None, '',
                        "Copy example files to new {} directory?".format(dir),
                        qm.Yes | qm.No)
                    if ret == qm.Yes:
                        src = "{}/{}".format(defaultdir, dir)
                        src_files = os.listdir(src)
                        for file_name in src_files:
                            full_file_name = os.path.join(src, file_name)
                            if os.path.isfile(full_file_name):
                                shutil.copy(full_file_name, subdir)

        return True
コード例 #4
0
ファイル: PathJobCmd.py プロジェクト: yangshihit/FreeCAD
 def Activated(self):
     job = self.GetJob()
     dialog = DlgJobTemplateExport(job)
     if dialog.exec_() == 1:
         foo = QtGui.QFileDialog.getSaveFileName(
             QtGui.QApplication.activeWindow(), "Path - Job Template",
             PathPreferences.filePath(), "job_*.json")[0]
         if foo:
             self.Execute(job, foo, dialog)
コード例 #5
0
ファイル: PathJobCmd.py プロジェクト: zhangli1049/FreeCAD
 def SaveDialog(cls, job, dialog):
     foo = QtGui.QFileDialog.getSaveFileName(QtGui.QApplication.activeWindow(),
             "Path - Job Template",
             PathPreferences.filePath(),
             "job_*.json")[0]
     if foo:
         if not os.path.basename(foo).startswith('job_'):
             foo = os.path.join(os.path.dirname(foo), 'job_' + os.path.basename(foo))
         if not foo.endswith('.json'):
             foo = foo + '.json'
         cls.Execute(job, foo, dialog)
コード例 #6
0
ファイル: PathJobCmd.py プロジェクト: josephmokenela/FreeCAD
 def SaveDialog(cls, job, dialog):
     foo = QtGui.QFileDialog.getSaveFileName(
         QtGui.QApplication.activeWindow(), "Path - Job Template",
         PathPreferences.filePath(), "job_*.json")[0]
     if foo:
         s = '/'
         splitList = foo.split(s)
         li = len(splitList) - 1
         if splitList[li][-5:] == '.json':
             if splitList[li][:4] != 'job_' and splitList[li][:4] != 'Job_':
                 splitList[li] = 'Job_' + splitList[li]
                 foo = s.join(splitList)
         cls.Execute(job, foo, dialog)
コード例 #7
0
def GetToolShapeFile(parent=None):
    if parent is None:
        parent = QtGui.QApplication.activeWindow()

    location = PathPreferences.lastPathToolShape()
    if os.path.isfile(location):
        location = os.path.split(location)[0]
    elif not os.path.isdir(location):
        location = PathPreferences.filePath()

    fname = QtGui.QFileDialog.getOpenFileName(parent, 'Select Tool Shape',
                                              location, '*.fcstd')
    if fname and fname[0]:
        if fname != location:
            PathPreferences.setLastPathToolShape(location)
        return fname[0]
    else:
        return None
コード例 #8
0
def checkWorkingDir():
    # users shouldn't use the example toolbits and libraries.
    # working directory should be writable
    PathLog.track()

    workingdir = os.path.dirname(PathPreferences.lastPathToolLibrary())
    defaultdir = os.path.dirname(PathPreferences.pathDefaultToolsPath())

    PathLog.debug("workingdir: {} defaultdir: {}".format(
        workingdir, defaultdir))

    dirOK = lambda: workingdir != defaultdir and (os.access(
        workingdir, os.W_OK))

    if dirOK():
        return True

    qm = PySide.QtGui.QMessageBox
    ret = qm.question(None, "",
                      "Toolbit working directory not set up. Do that now?",
                      qm.Yes | qm.No)

    if ret == qm.No:
        return False

    msg = translate("Path_ToolBit",
                    "Choose a writable location for your toolbits")
    while not dirOK():
        workingdir = PySide.QtGui.QFileDialog.getExistingDirectory(
            None, msg, PathPreferences.filePath())

    if workingdir[-8:] == os.path.sep + "Library":
        workingdir = workingdir[:
                                -8]  # trim off trailing /Library if user chose it

    PathPreferences.setLastPathToolLibrary("{}{}Library".format(
        workingdir, os.path.sep))
    PathPreferences.setLastPathToolBit("{}{}Bit".format(
        workingdir, os.path.sep))
    PathLog.debug("setting workingdir to: {}".format(workingdir))

    # Copy only files of default Path\Tools folder to working directory (targeting the README.md help file)
    src_toolfiles = os.listdir(defaultdir)
    for file_name in src_toolfiles:
        if file_name in ["README.md"]:
            full_file_name = os.path.join(defaultdir, file_name)
            if os.path.isfile(full_file_name):
                shutil.copy(full_file_name, workingdir)

    # Determine which subdirectories are missing
    subdirlist = ["Bit", "Library", "Shape"]
    mode = 0o777
    for dir in subdirlist.copy():
        subdir = "{}{}{}".format(workingdir, os.path.sep, dir)
        if os.path.exists(subdir):
            subdirlist.remove(dir)

    # Query user for creation permission of any missing subdirectories
    if len(subdirlist) >= 1:
        needed = ", ".join([str(d) for d in subdirlist])
        qm = PySide.QtGui.QMessageBox
        ret = qm.question(
            None,
            "",
            "Toolbit Working directory {} needs these sudirectories:\n {} \n Create them?"
            .format(workingdir, needed),
            qm.Yes | qm.No,
        )

        if ret == qm.No:
            return False
        else:
            # Create missing subdirectories if user agrees to creation
            for dir in subdirlist:
                subdir = "{}{}{}".format(workingdir, os.path.sep, dir)
                os.mkdir(subdir, mode)
                # Query user to copy example files into subdirectories created
                if dir != "Shape":
                    qm = PySide.QtGui.QMessageBox
                    ret = qm.question(
                        None,
                        "",
                        "Copy example files to new {} directory?".format(dir),
                        qm.Yes | qm.No,
                    )
                    if ret == qm.Yes:
                        src = "{}{}{}".format(defaultdir, os.path.sep, dir)
                        src_files = os.listdir(src)
                        for file_name in src_files:
                            full_file_name = os.path.join(src, file_name)
                            if os.path.isfile(full_file_name):
                                shutil.copy(full_file_name, subdir)

    # if no library is set, choose the first one in the Library directory
    if PathPreferences.lastFileToolLibrary() is None:
        libFiles = [
            f for f in glob.glob(PathPreferences.lastPathToolLibrary() +
                                 os.path.sep + "*.fctl")
        ]
        PathPreferences.setLastFileToolLibrary(libFiles[0])

    return True
コード例 #9
0
 def bestGuessForFilePath(self):
     path = self.form.leDefaultFilePath.text()
     if not path:
         path = PathPreferences.filePath()
     return path
コード例 #10
0
def checkWorkingDir():
    # users shouldn't use the example toolbits and libraries.
    # working directory should be writable
    PathLog.track()

    workingdir = os.path.dirname(PathPreferences.lastPathToolLibrary())
    defaultdir = os.path.dirname(PathPreferences.pathDefaultToolsPath())

    PathLog.debug('workingdir: {} defaultdir: {}'.format(
        workingdir, defaultdir))

    dirOK = lambda: workingdir != defaultdir and (os.access(
        workingdir, os.W_OK))

    if dirOK():
        return True

    qm = PySide.QtGui.QMessageBox
    ret = qm.question(None, '',
                      "Toolbit working directory not set up. Do that now?",
                      qm.Yes | qm.No)

    if ret == qm.No:
        return False

    msg = translate("Path", "Choose a writable location for your toolbits",
                    None)
    while not dirOK():
        workingdir = PySide.QtGui.QFileDialog.getExistingDirectory(
            None, msg, PathPreferences.filePath())

    if workingdir[-8:] == os.path.sep + 'Library':
        workingdir = workingdir[:
                                -8]  # trim off trailing /Library if user chose it

    PathPreferences.setLastPathToolLibrary("{}{}Library".format(
        workingdir, os.path.sep))
    PathPreferences.setLastPathToolBit("{}{}Bit".format(
        workingdir, os.path.sep))
    PathLog.debug('setting workingdir to: {}'.format(workingdir))

    subdirlist = ['Bit', 'Library', 'Shape']
    mode = 0o777
    for dir in subdirlist.copy():
        subdir = "{}{}{}".format(workingdir, os.path.sep, dir)
        if os.path.exists(subdir):
            subdirlist.remove(dir)

    if len(subdirlist) >= 1:
        needed = ', '.join([str(d) for d in subdirlist])
        qm = PySide.QtGui.QMessageBox
        ret = qm.question(
            None, '',
            "Toolbit Working directory {} needs these sudirectories:\n {} \n Create them?"
            .format(workingdir, needed), qm.Yes | qm.No)

        if ret == qm.No:
            return False
        else:
            for dir in subdirlist:
                subdir = "{}{}{}".format(workingdir, os.path.sep, dir)
                os.mkdir(subdir, mode)
                if dir != 'Shape':
                    qm = PySide.QtGui.QMessageBox
                    ret = qm.question(
                        None, '',
                        "Copy example files to new {} directory?".format(dir),
                        qm.Yes | qm.No)
                    if ret == qm.Yes:
                        src = "{}{}{}".format(defaultdir, os.path.sep, dir)
                        src_files = os.listdir(src)
                        for file_name in src_files:
                            full_file_name = os.path.join(src, file_name)
                            if os.path.isfile(full_file_name):
                                shutil.copy(full_file_name, subdir)

    # if no library is set, choose the first one in the Library directory
    if PathPreferences.lastFileToolLibrary() is None:
        libFiles = [
            f for f in glob.glob(PathPreferences.lastPathToolLibrary() +
                                 os.path.sep + '*.fctl')
        ]
        PathPreferences.setLastFileToolLibrary(libFiles[0])

    return True
コード例 #11
0
 def bestGuessForFilePath(self):
     path = self.form.leDefaultFilePath.text()
     if not path:
         path = PathPreferences.filePath()
     return path