Esempio n. 1
0
 def columnCount(self, parent=QtCore.QModelIndex()):
     return len(self._header)
Esempio n. 2
0
    def setRootTagRef(self, rootTagRef, keepExpanded=False):
        if rootTagRef is self.rootTagRef:
            return
        self.rootTagRef = rootTagRef
        if rootTagRef is None:
            self.treeView.setModel(None)
            self.model = None
            return

        self.model = NBTTreeModel(rootTagRef.rootTag,
                                  self.editorSession.worldEditor.blocktypes)
        expanded = []
        current = None
        if keepExpanded and self.proxyModel:
            current = self.proxyModel.data(self.treeView.currentIndex(),
                                           NBTTreeModel.NBTPathRole)

            def addExpanded(parentIndex):
                for row in range(self.proxyModel.rowCount(parentIndex)):
                    index = self.proxyModel.index(row, 0, parentIndex)
                    if self.treeView.isExpanded(index):
                        expanded.append(
                            self.proxyModel.data(index,
                                                 NBTTreeModel.NBTPathRole))
                        addExpanded(index)

            addExpanded(QtCore.QModelIndex())

        self.model.dataChanged.connect(self.dataDidChange)
        self.model.rowsInserted.connect(self.rowsDidInsert)
        self.model.rowsRemoved.connect(self.rowsDidRemove)

        self.proxyModel = NBTFilterProxyModel(self)
        self.proxyModel.setSourceModel(self.model)
        # self.proxyModel.setDynamicSortFilter(True)

        self.treeView.setModel(self.proxyModel)
        header = self.treeView.header()
        header.setStretchLastSection(False)
        header.setResizeMode(1, header.ResizeMode.Stretch)
        header.setResizeMode(2, header.ResizeMode.Fixed)
        header.setResizeMode(3, header.ResizeMode.Fixed)

        if keepExpanded:
            for path in expanded:
                matches = self.proxyModel.match(
                    self.proxyModel.index(0, 0, QtCore.QModelIndex()),
                    NBTTreeModel.NBTPathRole,
                    path,
                    flags=Qt.MatchExactly | Qt.MatchRecursive)
                for i in matches:
                    self.treeView.setExpanded(i, True)
            if current is not None:
                matches = self.proxyModel.match(
                    self.proxyModel.index(0, 0, QtCore.QModelIndex()),
                    NBTTreeModel.NBTPathRole,
                    current,
                    flags=Qt.MatchExactly | Qt.MatchRecursive)
                if len(matches):
                    self.treeView.setCurrentIndex(matches[0])
        else:
            self.treeView.expandToDepth(0)
        self.treeView.sortByColumn(0, Qt.AscendingOrder)
        self.treeView.resizeColumnToContents(0)
        self.treeView.resizeColumnToContents(1)
        self.treeView.resizeColumnToContents(2)
        self.treeView.resizeColumnToContents(3)
Esempio n. 3
0
 def rowCount(self, index=QtCore.QModelIndex()):
     count = 1
     node = index.internalPointer()
     if node is not None:
         count = len(node.child)
     return count
Esempio n. 4
0
    def rowCount(self, parent=QtCore.QModelIndex()):
        parentItem = self.getItem(parent)

        return parentItem.childCount()
Esempio n. 5
0
 def reset(self):
     self.beginRemoveRows(QtCore.QModelIndex(), 0, len(self.file_names) - 1)
     self.file_names = []
     self.file_info = []
     self.endRemoveRows()
Esempio n. 6
0
 def rowCount(self, index=QtCore.QModelIndex()):
     return len(self.ships)
Esempio n. 7
0
 def columnCount(self, parent=QtCore.QModelIndex()):        
     return 3
Esempio n. 8
0
 def parent(self, index):
     node = self.getNode(index)
     parent_node = node.parent()
     if parent_node == self.root_node:
         return QtCore.QModelIndex()
     return self.createIndex(parent_node.row(), 0, parent_node)
Esempio n. 9
0
	def myClearSelection(self):
		self.widget.selectionModel().setCurrentIndex(QtCore.QModelIndex(), QtGui.QItemSelectionModel.Clear)
Esempio n. 10
0
 def insertRow(self, position, parent=QtCore.QModelIndex(), tagID=None):
     return self.insertRows(position, 1, parent, tagID)
Esempio n. 11
0
 def removeRow(self, position, parent=QtCore.QModelIndex()):
     self.removeRows(position, 1, parent)
Esempio n. 12
0
    def rowCount(self, parent=QtCore.QModelIndex()):
        if not parent.isValid():
            return 1
        parentItem = self.getItem(parent)

        return parentItem.childCount()
Esempio n. 13
0
 def data(self, index=QtCore.QModelIndex(), role=QtCore.Qt.DisplayRole):
     return None
Esempio n. 14
0
 def flags(self, index=QtCore.QModelIndex()):
     return QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled
Esempio n. 15
0
 def parent(self, index):
     return QtCore.QModelIndex()
Esempio n. 16
0
 def rowCount(self, index=QtCore.QModelIndex()):
     return len(self.data_list)
Esempio n. 17
0
 def rowCount(self, parent=QtCore.QModelIndex()):
     if parent.isValid():
         return 0
     return len(self.properties)
Esempio n. 18
0
 def addElem(self, msg):
     self.beginInsertRows(QtCore.QModelIndex(), len(self.data_list)\
             , len(self.data_list))
     self.data_list.append(ListItem(msg))
     self.endInsertRows()
Esempio n. 19
0
 def rowCount(self, parent=QtCore.QModelIndex()):        
     return len(self.columns)    
Esempio n. 20
0
 def removeCustomBlocks(self):
     self.beginRemoveRows(QtCore.QModelIndex(), len(self.blocktypes),
                          len(self.blocktypes) + len(self.customBlocks) - 1)
     self.customBlocks = []
     self.endRemoveRows()
Esempio n. 21
0
 def columnCount(self, parent=QtCore.QModelIndex()):
     return self.rootItem.columnCount()
Esempio n. 22
0
    def printImage(self):
        if self.model.rowCount(QtCore.QModelIndex()) * self.model.columnCount(QtCore.QModelIndex()) > 90000:
            answer = QtGui.QMessageBox.question(self, "Large Image Size",
                    "The printed image may be very large. Are you sure that "
                    "you want to print it?",
                    QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
            if answer == QtGui.QMessageBox.No:
                return

        printer = QtGui.QPrinter(QtGui.QPrinter.HighResolution)

        dlg = QtGui.QPrintDialog(printer, self)
        dlg.setWindowTitle("Print Image")

        if dlg.exec_() != QtGui.QDialog.Accepted:
            return

        painter = QtGui.QPainter()
        painter.begin(printer)

        rows = self.model.rowCount(QtCore.QModelIndex())
        columns = self.model.columnCount(QtCore.QModelIndex())
        sourceWidth = (columns+1) * ItemSize
        sourceHeight = (rows+1) * ItemSize

        painter.save()

        xscale = printer.pageRect().width() / float(sourceWidth)
        yscale = printer.pageRect().height() / float(sourceHeight)
        scale = min(xscale, yscale)

        painter.translate(printer.pageRect().x()+printer.pageRect().width()/2,
                          printer.pageRect().y()+printer.pageRect().height()/2)
        painter.scale(scale, scale)
        painter.translate(-sourceWidt/2, -sourceHeight/2)

        option = QtGui.QStyleOptionViewItem()
        parent = QtCore.QModelIndex()

        progress = QtGui.QProgressDialog("Printing...", "Cancel", 0, rows,
                self)
        y = ItemSize / 2.0

        for row in range(rows):
            progress.setValue(row)
            QtGui.qApp.processEvents()
            if progress.wasCanceled():
                break

            x = ItemSize / 2.0

            for col in range(columns):
                option.rect = QtCore.QRect(x, y, ItemSize, ItemSize)
                self.view.itemDelegate.paint(painter, option,
                        self.model.index(row, column, parent))
                x = x + ItemSize

            y = y + ItemSize

        progress.setValue(rows)

        painter.restore()
        painter.end()

        if progress.wasCanceled():
            QtGui.QMessageBox.information(self, "Printing canceled",
                    "The printing process was canceled.",
                    QtGui.QMessageBox.Cancel)
Esempio n. 23
0
    def insertColumns(self, position, columns, parent=QtCore.QModelIndex()):
        self.beginInsertColumns(parent, position, position + columns - 1)
        success = self.rootItem.insertColumns(position, columns)
        self.endInsertColumns()

        return success
class LaunchListModel(QtCore.QAbstractListModel):
    '''
  The model to manage the files with launch files.
  '''

    NOT_FOUND = -1
    NOTHING = 0
    RECENT_FILE = 1
    LAUNCH_FILE = 2
    FOLDER = 3
    PACKAGE = 4
    STACK = 5

    RECENT_LENGTH = 5

    def __init__(self):
        '''
    Creates a new list model. Loads the required icons.
    '''
        QtCore.QAbstractListModel.__init__(self)
        self.icons = {
            LaunchListModel.FOLDER:
            QtGui.QIcon(":/icons/crystal_clear_folder.png"),
            LaunchListModel.STACK:
            QtGui.QIcon(":/icons/crystal_clear_stack.png"),
            LaunchListModel.PACKAGE:
            QtGui.QIcon(":/icons/crystal_clear_package.png"),
            LaunchListModel.LAUNCH_FILE:
            QtGui.QIcon(":/icons/crystal_clear_launch_file.png"),
            LaunchListModel.RECENT_FILE:
            QtGui.QIcon(":/icons/crystal_clear_launch_file_recent.png")
        }
        self.items = []
        self.currentPath = None
        self.load_history = self._getLoadHistory()
        self.root_paths = [
            os.path.normpath(p)
            for p in os.getenv("ROS_PACKAGE_PATH").split(':')
        ]
        self._setNewList(self._moveUp(None))

    def _getRootItems(self):
        result = list(self.load_history)
        result[len(result):] = self.root_paths
        return result

    #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    #%%%%%%%%%%%%%              Overloaded methods                    %%%%%%%%
    #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    def rowCount(self, parent=QtCore.QModelIndex()):
        '''
    Tell the view how many rows we have present in our data.
    @param parent: parent of the list
    @type parent: L{QtCore.QModelIndex}
    '''
        return len(self.items)

    def data(self, index, role=QtCore.Qt.DisplayRole):
        '''
    The view asks us for all sorts of information about our data...
    @param index: parent of the list
    @type index: L{QtCore.QModelIndex}
    @param role: the art of the data
    @type role: L{QtCore.Qt.DisplayRole}
    @see: U{http://www.pyside.org/docs/pyside-1.0.1/PySide/QtCore/Qt.html}
    '''
        if role == QtCore.Qt.DisplayRole:
            # return the displayed item name
            pathItem, path, pathId = self.items[index.row()]
            if pathId == LaunchListModel.RECENT_FILE:
                return ''.join([
                    pathItem, '   [',
                    str(LaunchConfig.packageName(os.path.dirname(path))[0]),
                    ']'
                ]).decode(sys.getfilesystemencoding())
            else:
                return pathItem
        elif role == QtCore.Qt.ToolTipRole:
            # return the tooltip of the item
            pathItem, path, pathId = self.items[index.row()]
            return path
        elif role == QtCore.Qt.DecorationRole:
            # return the showed icon
            pathItem, path, pathId = self.items[index.row()]

            if pathId > LaunchListModel.NOTHING and self.icons.has_key(pathId):
                return self.icons[pathId]
            return None
        else:
            # We don't care about anything else, so return None
            return None

    def flags(self, index):
        '''
    Make the only selectable
    @param index: parent of the list
    @type index: L{QtCore.QModelIndex}
    @return: Flag or the requestet item
    @rtype: L{PySide.QtCore.Qt.ItemFlag}
    @see: U{http://www.pyside.org/docs/pyside-1.0.1/PySide/QtCore/Qt.html}
    '''
        return QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled

    #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    #%%%%%%%%%%%%%              External usage                        %%%%%%%%
    #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    def reloadCurrentPath(self):
        '''
    Reloads the current path.
    '''
        if self.currentPath is None:
            self._setNewList(self._moveUp(self.currentPath))
        else:
            self._setNewList(self._moveDown(self.currentPath))

    def isLaunchFile(self, row):
        '''
    Tests for the given row whether it is a launch file or not.
    @return: C{True} if it is a launch file
    @rtype: C{boolean}
    '''
        if row >= 0 and row < len(self.items):
            pathItem, path, pathId = self.items[row]
            return not path is None and os.path.isfile(path) and path.endswith(
                '.launch')
        return False

    def getFilePath(self, item):
        '''
    Returns for the given item the file path if this is a file. Otherwise the 
    folder will be expanded and None will be returned.
    @param item: the list item
    @type item: C{str}
    @return: path of the launch file or None
    @rtype: C{str} or C{None}
    '''
        for pathItem, path, id in self.items:
            if item == pathItem:
                if item == '..':
                    root_path, items = self._moveUp(os.path.dirname(path))
                elif os.path.isfile(path):
                    return path
                else:
                    root_path, items = self._moveDown(path)
                self._setNewList((root_path, items))
        return None

    def setPath(self, path):
        '''
    Shows the new path in the launch configuration view. Only if the new path
    is in ros package paths
    @param path: new path
    @type path: C{str}
    '''
        if self._is_in_ros_packages(path):
            self._setNewList(self._moveDown(path))

    def add2LoadHistory(self, file):
        try:
            self.load_history.remove(file)
        except:
            pass
        self.load_history.append(file)
        if len(self.load_history) > self.RECENT_LENGTH:
            self.load_history.pop(0)
        self._storeLoadHistory(self.load_history)

    #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    #%%%%%%%%%%%%%              Functionality                         %%%%%%%%
    #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    def _setNewList(self, (root_path, items)):
        '''
    Sets the list to the given path and insert the items. If the root path is not
    None the additional item '..' to go up will be inserted. The items parameter 
    is a tupel with three values (the displayed name, the path of the item, the id
    of the item). 
    @see: L{LaunchListModel._addPathToList()}
    @param root_path: the root directory
    @type root_path: C{str}
    @param items: the list with characterized items
    @type items: C{[(item, path, id)]}
    '''
        self.beginRemoveRows(QtCore.QModelIndex(), 0, len(self.items))
        del self.items[:]
        self.endRemoveRows()
        # add new items
        if not root_path is None:
            self._addPathToList('..', root_path, LaunchListModel.NOTHING)
        for item_name, item_path, item_id in items:
            self._addPathToList(item_name, item_path, item_id)
        self.currentPath = root_path
Esempio n. 25
0
 def refresh(self):
     self.model.dataChanged.emit(QtCore.QModelIndex(), QtCore.QModelIndex())
Esempio n. 26
0
 def mousePressEvent(self, event):
     if not self.indexAt(event.pos()).isValid():
         self.clearSelection()
         self.clearFocus()
         self.setCurrentIndex(QtCore.QModelIndex())
     QtGui.QTreeView.mousePressEvent(self, event)
Esempio n. 27
0
 def rowCount(self, parent=QtCore.QModelIndex()):
     return len(self._detviews)
Esempio n. 28
0
    def index(self, row, column, parent=QtCore.QModelIndex()):
        if parent.isValid():
            return QtCore.QModelIndex()

        return self.createIndex(row, column, None)
Esempio n. 29
0
 def columnCount(self, index=QtCore.QModelIndex()):
     return 1
Esempio n. 30
0
	def rowCount(self, index=QtCore.QModelIndex()):
		return len(self.translations)