Example #1
0
def add_tile(workspace):
    """ Adds a tile to the current file being edited
        Parameters
            workspace: The current workspace widget

    """
    new_tile = tile(workspace.currentWidget(), workspace.currentWidget().numOfChildren, 30, 30)
    new_tile.drawConnection.connect(workspace.currentWidget().drawArrow)

    workspace.currentWidget().numOfChildren += 1
    workspace.update()
Example #2
0
    def add_file(self, file_path, index=0):

        """ Adds a file in the workspace, and allows editing via the drag
            and drop or text based editing windows

            file_path: The path to the file, with the extension
            index: The location of the tab to be inserted. If index
                   is equal to 0, the tab is added onto the end.
        """

        # Extract the extension and title from the file_path
        # If the file does not have an extension, both the title and extension
        # are equal to the name
        extension = file_path.split('.', 1)[-1]
        name = file_path.split('/')[-1]

        # Don't replicate the default name for a new, blank file
        if "untitled" in name:
            name = (name.split('.')[0] +
                                    str(self.num_of_untitled) + '.' + extension)
            self.num_of_untitled += 1

        # Open text based files
        if extension in ('txt', 'py', 'upl'):
            added_file = TextEditor(name, extension, file_path)

            # Add a checker and updater to check for changes (saved vs. unsaved)
            added_file.textChanged.connect(lambda: self.save_state_change(False))

            if index:
                self.insertTab(index, added_file, added_file.fileName)
                self.setCurrentIndex(index)
            else:
                self.addTab(added_file, added_file.fileName)
                self.setCurrentIndex(self.count() - 1)

        # Open drag and drop based files
        elif extension == "pro":
            added_file = DragDropEditor(name, extension, file_path)
            added_file.isSaved = True
            # Add as a tab, at a certain index if indicated
            if index:
                self.insertTab(index, added_file, added_file.fileName)
                self.setCurrentIndex(index)
            else:
                self.addTab(added_file, added_file.fileName)
                self.setCurrentIndex(self.count() - 1)

            if "untitled" not in file_path:
                f = open(file_path)
                for line in f:
                    if line[0] == 'L':
                        line = line.strip("\n")
                        path = line.split(" ")
                        self.add_library(path[1])
                    elif line[0] == "#":
                        added_file.numOfChildren += 1
                        line = line.strip("\n")
                        params = line.split(" ")
                        new_tile = tile(added_file, int(params[1]), int(params[2]), int(params[3]))
                        if params[4] != "None":
                            new_tile.func_dict['FunctionReference'] = params[4]
                            for v in added_file.libs:
                                if v['FunctionReference'] == new_tile.func_dict['FunctionReference']:
                                    new_tile.func_dict = v
                                    new_tile.setToolTip(v['ToolTip'])
                                    new_tile.setText(v['FunctionName'])
                            new_tile.set_value = params[5]
                        new_tile.drawConnection.connect(added_file.drawArrow)
                        new_tile.fileChange.connect(lambda: self.save_state_change(False))
                    elif line[0] == ">":
                        line = line.strip("\n")
                        params = line.split(" ")
                        new_arrow = arrow(int(params[1]), int(params[2]), int(params[3]), int(params[4]), int(params[5]), int(params[6]), params[7] + ' ' + params[8])
                        new_arrow.setParent(added_file)
                        new_arrow.lower()
                        new_arrow.show()
                        new_arrow.fileChange.connect(lambda: self.save_state_change(False))
                        tiles = added_file.findChildren(tile)
                        for i in tiles:
                            if i.ref == int(params[5]) or i.ref == int(params[6]):
                                i.arrows.append(new_arrow)



        # Open new, untitled files
        elif extension == "untitled":
            added_file = TextEditor(name)
        else:
            QtGui.QMessageBox.question(self, 'Message',
                                       "Cannot open file")
            return None