예제 #1
0
 def renameLibrary(self):
     name = self.form.TableList.itemWidget(self.form.TableList.currentItem()).getTableName()
     newName, ok = QtGui.QInputDialog.getText(None, translate(
         "TooltableEditor", "Rename Tooltable"), translate(
             "TooltableEditor", "Enter Name:"), QtGui.QLineEdit.Normal, name)
     if ok and newName:
         os.rename(PathPreferences.lastPathToolLibrary() + '/' + name, PathPreferences.lastPathToolLibrary() + '/' + newName)
         self.libraryOpen(filedialog=False)
    def loadData(self, path=None):
        PathLog.track(path)
        self.toolTableView.setUpdatesEnabled(False)
        self.form.TableList.setUpdatesEnabled(False)

        if path is None:
            path, loc = self.libPaths()

            self.toolModel.clear()
            self.listModel.clear()
            self.factory.libraryOpen(self.toolModel, lib=path)
            self.factory.findLibraries(self.listModel)

        else:
            self.toolModel.clear()
            self.factory.libraryOpen(self.toolModel, lib=path)

        self.path = path
        self.form.setWindowTitle("{}".format(PathPreferences.lastPathToolLibrary()))
        self.toolModel.setHorizontalHeaderLabels(self.columnNames())
        self.listModel.setHorizontalHeaderLabels(['Library'])

        # Select the current library in the list of tables
        curIndex = None
        for i in range(self.listModel.rowCount()):
            item = self.listModel.item(i)
            if item.data(_PathRole) == path:
                curIndex = self.listModel.indexFromItem(item)

        if curIndex:
            sm = self.form.TableList.selectionModel()
            sm.select(curIndex, PySide.QtCore.QItemSelectionModel.Select)

        self.toolTableView.setUpdatesEnabled(True)
        self.form.TableList.setUpdatesEnabled(True)
예제 #3
0
 def tableSelected(self, index):
     ''' loads the tools for the selected tool table '''
     name = self.form.TableList.itemWidget(
         self.form.TableList.itemFromIndex(index)).getTableName()
     self.libraryLoad(PathPreferences.lastPathToolLibrary() + '/' + name)
     self.form.ButtonRemoveToolTable.setEnabled(True)
     self.form.ButtonRenameToolTable.setEnabled(True)
예제 #4
0
    def librarySaveAs(self, path):

        TooltableTypeJSON = translate("Path_ToolBit",
                                      "Tooltable JSON (*.fctl)")
        TooltableTypeLinuxCNC = translate("Path_ToolBit",
                                          "LinuxCNC tooltable (*.tbl)")
        TooltableTypeCamotics = translate("Path_ToolBit",
                                          "Camotics tooltable (*.json)")

        filename = PySide.QtGui.QFileDialog.getSaveFileName(
            self.form,
            translate("Path_ToolBit", "Save toolbit library"),
            PathPreferences.lastPathToolLibrary(),
            "{};;{};;{}".format(TooltableTypeJSON, TooltableTypeLinuxCNC,
                                TooltableTypeCamotics),
        )
        if filename and filename[0]:
            if filename[1] == TooltableTypeLinuxCNC:
                path = (filename[0] if filename[0].endswith(".tbl") else
                        "{}.tbl".format(filename[0]))
                self.libararySaveLinuxCNC(path)
            elif filename[1] == TooltableTypeCamotics:
                path = (filename[0] if filename[0].endswith(".json") else
                        "{}.json".format(filename[0]))
                self.libararySaveCamotics(path)
            else:
                path = (filename[0] if filename[0].endswith(".fctl") else
                        "{}.fctl".format(filename[0]))
                self.path = path
                self.librarySave()
                self.updateToolbar()
예제 #5
0
    def libraryOpen(self, path=None,  filedialog=True):
        import glob
        PathLog.track()

        # Load default search path
        path = PathPreferences.lastPathToolLibrary()

        if filedialog or len(path) == 0:
            path = PySide.QtGui.QFileDialog.getExistingDirectory(self.form, 'Tool Library Path', PathPreferences.lastPathToolLibrary())
            if len(path) > 0:
                PathPreferences.setLastPathToolLibrary(path)
            else:
                return

        # Clear view
        self.form.TableList.clear()
        self.LibFiles.clear()
        self.form.lineLibPath.clear()
        self.form.lineLibPath.insert(path)

        # Find all tool tables in directory
        for file in glob.glob(path + '/*.fctl'):
            self.LibFiles.append(file)

        self.LibFiles.sort()

        # Add all tables to list
        for table in self.LibFiles:
            listWidgetItem = QtGui.QListWidgetItem()
            listItem = ToolTableListWidgetItem()
            listItem.setTableName(os.path.basename(table))
            listItem.setIcon(QtGui.QPixmap(':/icons/Path-ToolTable.svg'))
            listWidgetItem.setSizeHint(QtCore.QSize(0, 40))
            self.form.TableList.addItem(listWidgetItem)
            self.form.TableList.setItemWidget(listWidgetItem, listItem)

        self.path = []
        self.form.ButtonRemoveToolTable.setEnabled(False)
        self.form.ButtonRenameToolTable.setEnabled(False)

        self.toolTableView.setUpdatesEnabled(False)
        self.model.clear()
        self.model.setHorizontalHeaderLabels(self.columnNames())
        self.toolTableView.resizeColumnsToContents()
        self.toolTableView.setUpdatesEnabled(True)

        # Search last selected table
        if len(self.LibFiles) > 0:
            for idx in range(len(self.LibFiles)):
                if PathPreferences.lastPathToolTable() == os.path.basename(self.LibFiles[idx]):
                    break
            # Not found, select first entry
            if idx >= len(self.LibFiles):
                idx = 0

            # Load selected table
            self.libraryLoad(self.LibFiles[idx])
            self.form.TableList.setCurrentRow(idx)
            self.form.ButtonRemoveToolTable.setEnabled(True)
            self.form.ButtonRenameToolTable.setEnabled(True)
예제 #6
0
    def librarySaveAs(self):
        TooltableTypeJSON = translate("PathToolLibraryManager",
                                      "Tooltable JSON (*.fctl)")
        TooltableTypeLinuxCNC = translate("PathToolLibraryManager",
                                          "LinuxCNC tooltable (*.tbl)")

        filename = PySide.QtGui.QFileDialog.getSaveFileName(
            self.form,
            translate("TooltableEditor", "Save toolbit library", None),
            PathPreferences.lastPathToolLibrary(),
            "{};;{}".format(TooltableTypeJSON, TooltableTypeLinuxCNC))
        # filename = PySide.QtGui.QFileDialog.getSaveFileName(self.form, \
        #        'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl')
        if filename and filename[0]:
            if filename[1] == TooltableTypeLinuxCNC:
                path = filename[0] if filename[0].endswith(
                    '.tbl') else "{}.tbl".format(filename[0])
                self.libararySaveLinuxCNC(path)
            else:
                path = filename[0] if filename[0].endswith(
                    '.fctl') else "{}.fctl".format(filename[0])
                PathPreferences.setLastPathToolLibrary(os.path.dirname(path))
                self.path = path
                self.librarySave()
                self.updateToolbar()
                PathPreferences.setLastPathToolTable(os.path.basename(path))
                self.libraryOpen(None, False)
예제 #7
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
 def libraryOpen(self):
     PathLog.track()
     foo = PySide.QtGui.QFileDialog.getOpenFileName(
         self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(),
         '*.fctl')
     if foo and foo[0]:
         path = foo[0]
         PathPreferences.setLastPathToolLibrary(os.path.dirname(path))
         self.libraryLoad(path)
예제 #9
0
    def libraryPath(self):
        PathLog.track()
        path = PySide.QtGui.QFileDialog.getExistingDirectory(
            self.form, "Tool Library Path",
            PathPreferences.lastPathToolLibrary())
        if len(path) == 0:
            return

        PathPreferences.setLastPathToolLibrary(path)
        self.loadData()
예제 #10
0
    def Activated(self):
        import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui
        library = PathToolBitLibraryGui.ToolBitLibrary()

        lastlib = PathPreferences.lastPathToolLibrary()

        if PathPreferences.toolsOpenLastLibrary():
            library.open(lastlib)
        else:
            library.open()
    def Activated(self):
        import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui
        dock = PathToolBitLibraryGui.ToolBitSelector()

        lastlib = PathPreferences.lastPathToolLibrary()

        if PathPreferences.toolsOpenLastLibrary():
            dock.open(lastlib)
        else:
            dock.open()
 def librarySaveAs(self):
     foo = PySide.QtGui.QFileDialog.getSaveFileName(
         self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(),
         '*.fctl')
     if foo and foo[0]:
         path = foo[0] if foo[0].endswith('.fctl') else "{}.fctl".format(
             foo[0])
         PathPreferences.setLastPathToolLibrary(os.path.dirname(path))
         self.path = path
         self.librarySave()
         self.updateToolbar()
예제 #13
0
    def libraryNew(self):
        TooltableTypeJSON = translate("PathToolLibraryManager", "Tooltable JSON (*.fctl)")

        filename = PySide.QtGui.QFileDialog.getSaveFileName(self.form,
                translate("TooltableEditor", "Save toolbit library", None),
                PathPreferences.lastPathToolLibrary(), "{}".format(TooltableTypeJSON))

        if not (filename and filename[0]):
            self.loadData()

        path = filename[0] if filename[0].endswith('.fctl') else "{}.fctl".format(filename[0])
        library = {}
        tools = []
        library['version'] = 1
        library['tools'] = tools
        with open(path, 'w') as fp:
            json.dump(library, fp, sort_keys=True, indent=2)

        self.loadData()
예제 #14
0
    def findLibraries(self, model):
        '''
        Finds all the fctl files in a location
        Returns a QStandardItemModel
        '''
        PathLog.track()
        path = PathPreferences.lastPathToolLibrary()

        if os.path.isdir(path):  # opening all tables in a directory
            libFiles = [f for f in glob.glob(path + '/*.fctl')]
            libFiles.sort()
            for libFile in libFiles:
                loc, fnlong = os.path.split(libFile)
                fn, ext = os.path.splitext(fnlong)
                libItem = QtGui.QStandardItem(fn)
                libItem.setToolTip(loc)
                libItem.setData(libFile, _PathRole)
                libItem.setIcon(QtGui.QPixmap(':/icons/Path_ToolTable.svg'))
                model.appendRow(libItem)

        PathLog.debug('model rows: {}'.format(model.rowCount()))
        return model
예제 #15
0
    def libraryNew(self):
        TooltableTypeJSON = translate("Path_ToolBit",
                                      "Tooltable JSON (*.fctl)")

        filename = PySide.QtGui.QFileDialog.getSaveFileName(
            self.form,
            translate("Path_ToolBit", "Save toolbit library"),
            PathPreferences.lastPathToolLibrary(),
            "{}".format(TooltableTypeJSON),
        )

        if not (filename and filename[0]):
            self.loadData()

        path = (filename[0] if filename[0].endswith(".fctl") else
                "{}.fctl".format(filename[0]))
        library = {}
        tools = []
        library["version"] = 1
        library["tools"] = tools
        with open(path, "w") as fp:
            json.dump(library, fp, sort_keys=True, indent=2)

        self.loadData()
예제 #16
0
    def libPaths(self):
        lib = PathPreferences.lastFileToolLibrary()
        loc = PathPreferences.lastPathToolLibrary()

        PathLog.track("lib: {} loc: {}".format(lib, loc))
        return lib, loc
예제 #17
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
예제 #18
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